#include "ui.h"
#include "timecode.h"
+static void omnplay_library_load_file(playlist_item_t* items, int *pcount, char* filename)
+{
+ int i, c = 0;
+ FILE* f;
+ char *l;
+ playlist_item_t item;
+
+ /* allocate space for strings and items */
+ l = malloc(PATH_MAX);
+
+ *pcount = 0;
+
+ /* open and process file */
+ if((f = fopen(filename, "rt")))
+ {
+ while( !feof(f) )
+ {
+ char *s, *sp_r, *sp_b;
+
+ /* load string */
+ memset(l, 0, PATH_MAX);
+ fgets(l, PATH_MAX, f);
+
+ /* remove newlines */
+ if( (s = strchr(l, '\n')) ) *s = 0;
+ if( (s = strchr(l, '\r')) ) *s = 0;
+
+ /* check for empty line */
+ if(l[0] && l[0] != '#')
+ {
+ memset(&item, 0, sizeof(playlist_item_t));
+
+ for(i = 0, sp_b = l; (NULL != (sp_r = strtok(sp_b, "\t"))); i++, sp_b = NULL)
+ {
+ switch(i)
+ {
+ case 0: strncpy(item.id, sp_r, PATH_MAX); break;
+ case 1: tc2frames(sp_r, 25.0, &item.in); break;
+ case 2: tc2frames(sp_r, 25.0, &item.dur); break;
+ case 3: strncpy(item.title, sp_r, PATH_MAX); break;
+ };
+ };
+
+ /* insert item */
+ items[c++] = item;
+ };
+ }
+
+ fclose(f);
+ }
+
+ /* free data */
+ free(l);
+
+ *pcount = c;
+};
+
void omnplay_library_load(omnplay_instance_t* app)
{
+ pthread_mutex_lock(&app->library.lock);
+
+ if(app->library.filename[0])
+ omnplay_library_load_file(app->library.item, &app->library.count, app->library.filename);
+
+ pthread_mutex_unlock(&app->library.lock);
+
+ omnplay_library_draw(app);
+};
+
+static void omnplay_library_save_file(playlist_item_t* item, int count, char* filename)
+{
+ int i;
+ FILE* f;
+
+ if((f = fopen(filename, "wt")))
+ {
+ char tc_in[32], tc_dur[32];
+
+ for(i = 0; i < count; i++)
+ fprintf(f, "%s\t%s\t%s\t%s\n",
+ item[i].id,
+ frames2tc(item[i].in, 25.0, tc_in),
+ frames2tc(item[i].dur, 25.0, tc_dur),
+ item[i].title);
+
+ fclose(f);
+ };
};
void omnplay_library_save(omnplay_instance_t* app)
{
+ pthread_mutex_lock(&app->library.lock);
+
+ if(app->library.filename[0])
+ omnplay_library_save_file(app->library.item, app->library.count,
+ app->library.filename);
+
+ pthread_mutex_unlock(&app->library.lock);
};
void omnplay_library_refresh(omnplay_instance_t* app)
{
};
+
+void omnplay_library_draw(omnplay_instance_t* app)
+{
+ int i;
+ char tc[12];
+ GtkListStore *list_store;
+ GtkTreeIter iter;
+
+ list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->library_grid)));
+ gtk_list_store_clear(list_store);
+
+ pthread_mutex_lock(&app->library.lock);
+
+ for(i = 0;i < app->library.count; i++)
+ {
+ gtk_list_store_append(list_store, &iter);
+
+ gtk_list_store_set(list_store, &iter,
+ 0, app->library.item[i].id,
+ 1, frames2tc(app->playlist.item[i].dur, 25.0, tc),
+ 2, app->library.item[i].title,
+ 3, i,
+ -1 );
+ }
+
+ pthread_mutex_unlock(&app->library.lock);
+};