X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Flibrary.c;h=ff7307bf8ace98dc3783b84e33b8ff63a63a6c0d;hb=a12bc94bf9e1527448c8407c66ff6272212b2455;hp=eefce46050a53bd464a38b17e5db84623b3db8f1;hpb=a4397d674b2f7ea33653ff1137193835c668c7de;p=melted_gui diff --git a/src/library.c b/src/library.c index eefce46..ff7307b 100644 --- a/src/library.c +++ b/src/library.c @@ -48,8 +48,9 @@ playlist_item_t* omnplay_library_find(omnplay_instance_t* app, char* id) return item; }; -void omnplay_library_normalize_item(omnplay_instance_t* app, playlist_item_t* item) +int omnplay_library_normalize_item(omnplay_instance_t* app, playlist_item_t* item) { + int r = 0; playlist_item_t* lib; pthread_mutex_lock(&app->library.lock); @@ -62,18 +63,27 @@ void omnplay_library_normalize_item(omnplay_instance_t* app, playlist_item_t* it { if(!item->title[0]) + { strcpy(item->title, lib->title); + r = 1; + }; - if(!item->dur) + if(!item->dur || item->in < lib->in || (item->in + item->dur) > (lib->in + lib->dur)) { item->dur = lib->dur; item->in = lib->in; + r = 1; }; } else + { + r = 1; item->error = PLAYLIST_ITEM_ERROR_LIB; + }; pthread_mutex_unlock(&app->library.lock); + + return r; }; void omnplay_library_sort(omnplay_instance_t* app) @@ -209,21 +219,29 @@ void omnplay_library_save(omnplay_instance_t* app) static void omnplay_get_content_cb(omnplay_instance_t* app, playlist_item_t* item, void* data) { - fprintf(stderr, "requested: id=[%s]\n", item->id); + gdk_threads_enter(); + gtk_label_set_text(GTK_LABEL(app->library.refresh_ui[1]), item->id); + gdk_flush(); + gdk_threads_leave(); }; -void omnplay_library_refresh(omnplay_instance_t* app) +static void* omnplay_library_refresh_proc(void* data) { + omnplay_instance_t* app = (omnplay_instance_t*)data; int count, i; playlist_item_t* items; - items = (playlist_item_t*)malloc(sizeof(playlist_item_t) * MAX_LIBRARY_ITEMS); count = omnplay_get_content(app, items, MAX_LIBRARY_ITEMS, omnplay_get_content_cb, NULL); if(count > 0) { + gdk_threads_enter(); + gtk_label_set_text(GTK_LABEL(app->library.refresh_ui[1]), "Quering whois..."); + gdk_flush(); + gdk_threads_leave(); + if(app->library.whois[0]) omnplay_whois_list(app, items, &count); @@ -238,10 +256,34 @@ void omnplay_library_refresh(omnplay_instance_t* app) pthread_mutex_unlock(&app->library.lock); + gdk_threads_enter(); omnplay_library_draw(app); + gdk_flush(); + gdk_threads_leave(); }; free(items); + + gdk_threads_enter(); + omnplay_playlist_normalize(app); + gtk_widget_destroy(app->library.refresh_ui[0]); + gdk_flush(); + gdk_threads_leave(); + + return NULL; +}; + +void omnplay_library_refresh(omnplay_instance_t* app) +{ + if(app->library.refresh_ui[0]) + pthread_join(app->library.refresh_thread, NULL); + + /* create UI for monitoring update */ + ui_library_refresh(app, &app->library.refresh_ui[0], &app->library.refresh_ui[1]); + + pthread_create(&app->library.refresh_thread, NULL, + omnplay_library_refresh_proc, app); + }; void omnplay_library_draw(omnplay_instance_t* app)