2 * playlist.c -- GTK+ 2 omnplay
3 * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include <gdk/gdkkeysyms.h>
35 static void omnplay_library_load_file(playlist_item_t
* items
, int *pcount
, char* filename
)
42 /* allocate space for strings and items */
47 /* open and process file */
48 if((f
= fopen(filename
, "rt")))
52 char *s
, *sp_r
, *sp_b
;
55 memset(l
, 0, PATH_MAX
);
56 fgets(l
, PATH_MAX
, f
);
59 if( (s
= strchr(l
, '\n')) ) *s
= 0;
60 if( (s
= strchr(l
, '\r')) ) *s
= 0;
62 /* check for empty line */
63 if(l
[0] && l
[0] != '#')
65 memset(&item
, 0, sizeof(playlist_item_t
));
67 for(i
= 0, sp_b
= l
; (NULL
!= (sp_r
= strtok(sp_b
, "\t"))); i
++, sp_b
= NULL
)
71 case 0: strncpy(item
.id
, sp_r
, PATH_MAX
); break;
72 case 1: tc2frames(sp_r
, 25.0, &item
.in
); break;
73 case 2: tc2frames(sp_r
, 25.0, &item
.dur
); break;
74 case 3: strncpy(item
.title
, sp_r
, PATH_MAX
); break;
92 void omnplay_library_load(omnplay_instance_t
* app
)
94 pthread_mutex_lock(&app
->library
.lock
);
96 if(app
->library
.filename
[0])
97 omnplay_library_load_file(app
->library
.item
, &app
->library
.count
, app
->library
.filename
);
99 pthread_mutex_unlock(&app
->library
.lock
);
101 omnplay_library_draw(app
);
104 static void omnplay_library_save_file(playlist_item_t
* item
, int count
, char* filename
)
109 if((f
= fopen(filename
, "wt")))
111 char tc_in
[32], tc_dur
[32];
113 for(i
= 0; i
< count
; i
++)
114 fprintf(f
, "%s\t%s\t%s\t%s\n",
116 frames2tc(item
[i
].in
, 25.0, tc_in
),
117 frames2tc(item
[i
].dur
, 25.0, tc_dur
),
124 void omnplay_library_save(omnplay_instance_t
* app
)
126 pthread_mutex_lock(&app
->library
.lock
);
128 if(app
->library
.filename
[0])
129 omnplay_library_save_file(app
->library
.item
, app
->library
.count
,
130 app
->library
.filename
);
132 pthread_mutex_unlock(&app
->library
.lock
);
135 static void omnplay_get_content_cb(omnplay_instance_t
* app
, playlist_item_t
* item
, void* data
)
137 fprintf(stderr
, "requested: id=[%s]\n", item
->id
);
140 void omnplay_library_refresh(omnplay_instance_t
* app
)
143 playlist_item_t
* items
;
146 items
= (playlist_item_t
*)malloc(sizeof(playlist_item_t
) * MAX_LIBRARY_ITEMS
);
148 count
= omnplay_get_content(app
, items
, MAX_LIBRARY_ITEMS
, omnplay_get_content_cb
, NULL
);
153 void omnplay_library_draw(omnplay_instance_t
* app
)
157 GtkListStore
*list_store
;
160 list_store
= GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app
->library_grid
)));
161 gtk_list_store_clear(list_store
);
163 pthread_mutex_lock(&app
->library
.lock
);
165 for(i
= 0;i
< app
->library
.count
; i
++)
167 gtk_list_store_append(list_store
, &iter
);
169 gtk_list_store_set(list_store
, &iter
,
170 0, app
->library
.item
[i
].id
,
171 1, frames2tc(app
->playlist
.item
[i
].dur
, 25.0, tc
),
172 2, app
->library
.item
[i
].title
,
177 pthread_mutex_unlock(&app
->library
.lock
);