library refresh UI montor
authorMaksym Veremeyenko <verem@m1stereo.tv>
Thu, 23 Jun 2011 08:34:45 +0000 (11:34 +0300)
committerMaksym Veremeyenko <verem@m1stereo.tv>
Thu, 23 Jun 2011 08:34:45 +0000 (11:34 +0300)
src/library.c
src/omnplay.h
src/ui.c
src/ui.h

index 700d5bf..ff7307b 100644 (file)
@@ -219,11 +219,15 @@ 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;
 
@@ -233,6 +237,11 @@ void omnplay_library_refresh(omnplay_instance_t* app)
 
     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);
 
@@ -247,12 +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)
index fc6b1d8..4fc8392 100644 (file)
@@ -150,6 +150,8 @@ typedef struct omnplay_instance
         char filename[PATH_MAX];
         char whois[PATH_MAX];
         pthread_mutex_t lock;
+        pthread_t refresh_thread;
+        GtkWidget *refresh_ui[2];
     } library;
 } omnplay_instance_t;
 
index 988561b..6e3b915 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -680,3 +680,28 @@ int ui_playlist_item_dialog(omnplay_instance_t* app, playlist_item_t* item)
 
     return r;
 };
+
+void ui_library_refresh(omnplay_instance_t* app, GtkWidget **p_win, GtkWidget **p_label)
+{
+    GtkWidget *win, *box, *label;
+
+    win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_title(GTK_WINDOW(win), _("Library refreshing..."));
+    gtk_window_set_default_size(GTK_WINDOW(win), 250, 100);
+    gtk_window_set_modal(GTK_WINDOW(win), TRUE);
+    gtk_window_set_transient_for(GTK_WINDOW(win), GTK_WINDOW(app->window));
+
+    box = gtk_vbox_new(FALSE, 0);
+    gtk_widget_show(box);
+    gtk_container_add(GTK_CONTAINER(win), box);
+
+    label = create_label(NULL, "Requsting status...", NULL, 0),
+    gtk_widget_show(label);
+    gtk_box_pack_start (GTK_BOX(box), label, TRUE, TRUE, 0);
+
+    gtk_window_present(GTK_WINDOW(win));
+    gtk_widget_show(win);
+
+    *p_win = win;
+    *p_label = label;
+};
index 0e313a1..9890138 100644 (file)
--- a/src/ui.h
+++ b/src/ui.h
@@ -29,6 +29,7 @@ extern "C"
 
 GtkWidget* ui_omnplay(omnplay_instance_t* app);
 int ui_playlist_item_dialog(omnplay_instance_t* app, playlist_item_t* item);
+void ui_library_refresh(omnplay_instance_t* app, GtkWidget **p_win, GtkWidget **p_label);
 
 #ifdef __cplusplus
 };