[Goodies-commits] r3955 - xfce4-mpc-plugin/trunk/panel-plugin

Landry Breuil landry at xfce.org
Fri Feb 15 22:53:12 CET 2008


Author: landry
Date: 2008-02-15 21:53:12 +0000 (Fri, 15 Feb 2008)
New Revision: 3955

Modified:
   xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c
Log:
- connect destroy signal to gtk_widget_destroyed to invalidate playlist pointer
- only create/show playlist window if != NULL, avoids multiple playlist at the same time


Modified: xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c
===================================================================
--- xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c	2008-02-15 02:36:00 UTC (rev 3954)
+++ xfce4-mpc-plugin/trunk/panel-plugin/xfce4-mpc-plugin.c	2008-02-15 21:53:12 UTC (rev 3955)
@@ -373,7 +373,7 @@
 show_playlist (t_mpc* mpc)
 {
    DBG("!");
-   GtkWidget *scrolledwin,*treeview;
+   GtkWidget *scrolledwin, *treeview;
    GtkListStore *liststore;
    GtkTreeIter iter;
    GtkTreePath *path_to_cur;
@@ -382,55 +382,60 @@
    int current;
    MpdData *mpd_data;
 
-   mpc->playlist = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-   gtk_window_set_default_size(GTK_WINDOW(mpc->playlist), 300, 530);
-   gtk_window_set_icon_name(GTK_WINDOW(mpc->playlist),"xfce-multimedia");
-   gtk_window_set_title(GTK_WINDOW(mpc->playlist),_("Mpd playlist"));
-   gtk_window_set_keep_above(GTK_WINDOW(mpc->playlist),TRUE); /* UGLY !!! */
-   scrolledwin = gtk_scrolled_window_new(NULL, NULL);
-   gtk_container_add(GTK_CONTAINER(mpc->playlist),GTK_WIDGET(scrolledwin));
+   if (NULL == mpc->playlist)
+   {
+      DBG ("Creating playlist window");
+      mpc->playlist = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+      gtk_window_set_default_size(GTK_WINDOW(mpc->playlist), 300, 530);
+      gtk_window_set_icon_name(GTK_WINDOW(mpc->playlist),"xfce-multimedia");
+      gtk_window_set_title(GTK_WINDOW(mpc->playlist),_("Mpd playlist"));
+      gtk_window_set_keep_above(GTK_WINDOW(mpc->playlist),TRUE); /* UGLY !!! */
+      g_signal_connect(mpc->playlist, "destroy", G_CALLBACK(gtk_widget_destroyed), &mpc->playlist);
+      scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+      gtk_container_add(GTK_CONTAINER(mpc->playlist),GTK_WIDGET(scrolledwin));
 
-   treeview = gtk_tree_view_new ();
-   gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
-   gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
-   g_signal_connect(treeview, "row-activated", G_CALLBACK(playlist_title_dblclicked), mpc);
-   gtk_container_add(GTK_CONTAINER(scrolledwin),treeview);
+      treeview = gtk_tree_view_new ();
+      gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
+      gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE);
+      g_signal_connect(treeview, "row-activated", G_CALLBACK(playlist_title_dblclicked), mpc);
+      gtk_container_add(GTK_CONTAINER(scrolledwin),treeview);
 
-   liststore = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
-   gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL(liststore));
+      liststore = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
+      gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), GTK_TREE_MODEL(liststore));
 
-   renderer = gtk_cell_renderer_pixbuf_new ();
-   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Icon", renderer, "stock-id", 0, NULL);
-   renderer = gtk_cell_renderer_text_new ();
-   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Title", renderer, "text", 1, NULL);
+      renderer = gtk_cell_renderer_pixbuf_new ();
+      gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Icon", renderer, "stock-id", 0, NULL);
+      renderer = gtk_cell_renderer_text_new ();
+      gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Title", renderer, "text", 1, NULL);
 
-   if (!mpc_plugin_reconnect(mpc))
-   {
-      gtk_widget_destroy(mpc->playlist);
-      return;
-   }
+      if (!mpc_plugin_reconnect(mpc))
+      {
+         gtk_widget_destroy(mpc->playlist);
+         return;
+      }
 
-   current = mpd_player_get_current_song_pos (mpc->mo);
-   DBG ("Current song pos in the list: %d", current);
-   mpd_data = mpd_playlist_get_changes (mpc->mo, -1);
-   DBG ("Got playlist, creating window");
-   do
-   {
-      g_sprintf(str,"%s - %s", mpd_data->song->artist, mpd_data->song->title);
+      current = mpd_player_get_current_song_pos (mpc->mo);
+      DBG ("Current song pos in the list: %d", current);
+      mpd_data = mpd_playlist_get_changes (mpc->mo, -1);
+      DBG ("Got playlist, filling treeview");
+      do
+      {
+         g_sprintf(str,"%s - %s", mpd_data->song->artist, mpd_data->song->title);
 
-      gtk_list_store_append (liststore, &iter);
-      if (current == mpd_data->song->pos)
-      {
-         gtk_list_store_set (liststore, &iter, 0, "gtk-media-play", 1, str, 2, mpd_data->song->pos, 3, mpd_data->song->id, -1);
-         path_to_cur = gtk_tree_model_get_path(GTK_TREE_MODEL(liststore), &iter);
-         gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path_to_cur, NULL, TRUE, 0.5, 0);
-         gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), path_to_cur, NULL, FALSE);
-         gtk_tree_path_free(path_to_cur);
-      }
-      else
-         gtk_list_store_set (liststore, &iter, 0, "gtk-cdrom", 1, str, 2, mpd_data->song->pos, 3, mpd_data->song->id, -1);
-   } while (NULL != (mpd_data = mpd_data_get_next (mpd_data)));
-   gtk_widget_show_all(mpc->playlist);
+         gtk_list_store_append (liststore, &iter);
+         if (current == mpd_data->song->pos)
+         {
+            gtk_list_store_set (liststore, &iter, 0, "gtk-media-play", 1, str, 2, mpd_data->song->pos, 3, mpd_data->song->id, -1);
+            path_to_cur = gtk_tree_model_get_path(GTK_TREE_MODEL(liststore), &iter);
+            gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(treeview), path_to_cur, NULL, TRUE, 0.5, 0);
+            gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview), path_to_cur, NULL, FALSE);
+            gtk_tree_path_free(path_to_cur);
+         }
+         else
+            gtk_list_store_set (liststore, &iter, 0, "gtk-cdrom", 1, str, 2, mpd_data->song->pos, 3, mpd_data->song->id, -1);
+      } while (NULL != (mpd_data = mpd_data_get_next (mpd_data)));
+      gtk_widget_show_all(mpc->playlist);
+   }
 }
 
 static void




More information about the Goodies-commits mailing list