From 216de253be765b658191eea63fe6bb1566b10b46 Mon Sep 17 00:00:00 2001 From: Maksym Veremeyenko Date: Wed, 22 Jun 2011 13:17:40 +0300 Subject: [PATCH] library load/save support added --- src/library.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/omnplay.h | 1 + 2 files changed, 105 insertions(+), 0 deletions(-) diff --git a/src/library.c b/src/library.c index 27dabce..d36fa0a 100644 --- a/src/library.c +++ b/src/library.c @@ -34,12 +34,116 @@ void omnplay_library_load(omnplay_instance_t* app) { + int i; + FILE* f; + char *l; + playlist_item_t item; + + /* allocate space for strings and items */ + l = malloc(PATH_MAX); + + pthread_mutex_lock(&app->library.lock); + + app->library.count = 0; + + /* open and process file */ + if(app->library.filename[0] && (f = fopen(app->library.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 */ + app->library.item[app->library.count++] = item; + }; + } + + fclose(f); + } + + pthread_mutex_unlock(&app->library.lock); + + /* free data */ + free(l); + + omnplay_library_draw(app); }; void omnplay_library_save(omnplay_instance_t* app) { + int i; + FILE* f; + + pthread_mutex_lock(&app->library.lock); + + if(app->library.filename[0] && (f = fopen(app->library.filename, "wt"))) + { + char tc_in[32], tc_dur[32]; + + for(i = 0; i < app->library.count; i++) + fprintf(f, "%s\t%s\t%s\t%s\n", + app->library.item[i].id, + frames2tc(app->library.item[i].in, 25.0, tc_in), + frames2tc(app->library.item[i].dur, 25.0, tc_dur), + app->library.item[i].title); + + fclose(f); + }; + + 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); +}; diff --git a/src/omnplay.h b/src/omnplay.h index f94789d..9cceb61 100644 --- a/src/omnplay.h +++ b/src/omnplay.h @@ -162,6 +162,7 @@ void omnplay_playlist_draw_item_rem(omnplay_instance_t* app, int idx, char* rem) void omnplay_library_load(omnplay_instance_t* app); void omnplay_library_save(omnplay_instance_t* app); void omnplay_library_refresh(omnplay_instance_t* app); +void omnplay_library_draw(omnplay_instance_t* app); #ifdef __cplusplus }; -- 1.7.4.4