move omneon status threads to GThread
[melted_gui] / src / library.c
index decaee7..d2e73f3 100644 (file)
@@ -225,31 +225,47 @@ void omnplay_library_save(omnplay_instance_t* app)
 static void omnplay_get_content_cb(omnplay_instance_t* app, playlist_item_t* item, void* data)
 {
     gdk_threads_enter();
-    gtk_label_set_text(GTK_LABEL(app->library.refresh_ui[1]), item->id);
+    gtk_label_set_text(GTK_LABEL(data), item->id);
     gdk_flush();
     gdk_threads_leave();
 };
 
 static void* omnplay_library_refresh_proc(void* data)
 {
+    GtkWidget *refresh_ui[2];
     omnplay_instance_t* app = (omnplay_instance_t*)data;
     int count, i;
     playlist_item_t* items;
 
+    gdk_threads_enter();
+
+    /* create UI for monitoring update */
+    ui_library_refresh(app, &refresh_ui[0], &refresh_ui[1]);
+    gtk_widget_show_all(refresh_ui[0]);
+    gtk_window_present(GTK_WINDOW(refresh_ui[0]));
+
+    gdk_flush();
+    gdk_threads_leave();
+
     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);
+    count = omnplay_get_content(app, items, MAX_LIBRARY_ITEMS, omnplay_get_content_cb, refresh_ui[1]);
 
     if(count > 0)
     {
         gdk_threads_enter();
-        gtk_label_set_text(GTK_LABEL(app->library.refresh_ui[1]), "Quering whois...");
+        gtk_label_set_text(GTK_LABEL(refresh_ui[1]), "Quering whois...");
         gdk_flush();
         gdk_threads_leave();
 
         if(app->library.whois[0])
             omnplay_whois_list(app, items, &count);
 
+        gdk_threads_enter();
+        gtk_label_set_text(GTK_LABEL(refresh_ui[1]), "Setting library...");
+        gdk_flush();
+        gdk_threads_leave();
+
         pthread_mutex_lock(&app->library.lock);
 
         for(i = 0; i < count; i++)
@@ -271,7 +287,11 @@ static void* omnplay_library_refresh_proc(void* data)
 
     gdk_threads_enter();
     omnplay_playlist_normalize(app);
-    gtk_widget_destroy(app->library.refresh_ui[0]);
+    gdk_flush();
+    gdk_threads_leave();
+
+    gdk_threads_enter();
+    gtk_widget_destroy(refresh_ui[0]);
     gdk_flush();
     gdk_threads_leave();
 
@@ -280,15 +300,11 @@ static void* omnplay_library_refresh_proc(void* data)
 
 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);
+    if(app->library.refresh_thread)
+        g_thread_join(app->library.refresh_thread);
 
+    app->library.refresh_thread = g_thread_create(
+        omnplay_library_refresh_proc, app, TRUE, NULL);
 };
 
 void omnplay_library_draw(omnplay_instance_t* app)