[Xfce4-commits] <parole:bluesabre/gtk3> Fix errors displayed with save-playlist dialog

Sean Davis noreply at xfce.org
Sun Sep 8 16:14:01 CEST 2013


Updating branch refs/heads/bluesabre/gtk3
         to 8c440ac6f3f1a9740ba2f2379fd18fa19844b1f8 (commit)
       from 73567b11927e9afc90d64e479eccc2603978ce4a (commit)

commit 8c440ac6f3f1a9740ba2f2379fd18fa19844b1f8
Author: Sean Davis <smd.seandavis at gmail.com>
Date:   Sun Sep 8 10:12:17 2013 -0400

    Fix errors displayed with save-playlist dialog

 data/interfaces/save-playlist.ui |    6 +--
 src/parole-medialist.c           |  107 ++++++++++++++++++++------------------
 2 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/data/interfaces/save-playlist.ui b/data/interfaces/save-playlist.ui
index 35ab6cd..259fabe 100644
--- a/data/interfaces/save-playlist.ui
+++ b/data/interfaces/save-playlist.ui
@@ -25,7 +25,6 @@
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_stock">True</property>
-                <signal name="clicked" handler="parole_media_list_close_save_dialog_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -42,7 +41,6 @@
                 <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
-                <signal name="clicked" handler="parole_media_list_save_playlist_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -117,8 +115,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="0">button1</action-widget>
-      <action-widget response="0">button2</action-widget>
+      <action-widget response="-6">button1</action-widget>
+      <action-widget response="-3">button2</action-widget>
     </action-widgets>
   </object>
   <object class="GtkListStore" id="liststore">
diff --git a/src/parole-medialist.c b/src/parole-medialist.c
index 4f62e1e..2acc4bc 100644
--- a/src/parole-medialist.c
+++ b/src/parole-medialist.c
@@ -64,7 +64,7 @@ typedef struct
     GtkWidget *chooser;
     GtkTreeSelection *sel;
     ParoleMediaList *list;
-    
+    gboolean closing;
 } ParolePlaylistSave;
 
 /* Playlist filetypes */
@@ -147,9 +147,6 @@ gboolean    parole_media_list_key_press             (GtkWidget *widget,
 void        
 parole_media_list_format_cursor_changed_cb          (GtkTreeView *view,
                                                      ParolePlaylistSave *data);
-                                
-void        parole_media_list_close_save_dialog_cb (GtkButton *button,
-                                                    ParolePlaylistSave *data);
                             
 void        parole_media_list_save_playlist_cb     (GtkButton *button,
                                                     ParolePlaylistSave *data);
@@ -580,12 +577,6 @@ parole_media_list_shuffle_toggled_cb (GtkToggleToolButton *button, ParoleMediaLi
     g_signal_emit (G_OBJECT (list), signals [SHUFFLE_TOGGLED], 0, toggled);
 }
 
-void parole_media_list_close_save_dialog_cb (GtkButton *button, ParolePlaylistSave *data)
-{
-    gtk_widget_destroy (GTK_WIDGET (data->chooser));
-    g_free (data);
-}
-
 /**
  * parole_media_list_get_first_selected_row:
  * @list: a #ParoleMediaList
@@ -650,53 +641,61 @@ parole_media_list_get_first_selected_file (ParoleMediaList *list)
     return file;
 }
 
-/* Callback to save the current playlist */
-void parole_media_list_save_playlist_cb (GtkButton *button, ParolePlaylistSave *data)
+static void
+parole_media_list_save_playlist_response_cb        (GtkDialog *dialog,
+                                                    gint response_id,
+                                                    ParolePlaylistSave *data)
 {
-    ParolePlFormat format = PAROLE_PL_FORMAT_UNKNOWN;
-    GSList *list = NULL;
-    GtkTreeModel *model;
-    GtkTreeIter iter;
-    gchar *filename;
-    gchar *dirname;
+    gchar *filename = NULL;
+    gchar *dirname = NULL;
     
-    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (data->chooser));
-    dirname = g_path_get_dirname (filename);
-    
-    if ( gtk_tree_selection_get_selected (data->sel, &model, &iter ) )
+    if (response_id == GTK_RESPONSE_ACCEPT)
     {
-        gtk_tree_model_get (model, &iter, 2, &format, -1);
-    }
-    
-    if ( g_access (dirname, W_OK) == -1 )
-    {
-        gchar *msg;
-        msg = g_strdup_printf ("%s %s", dirname, _("Permission denied"));
-        parole_dialog_error (GTK_WINDOW (gtk_widget_get_toplevel (data->list->priv->view)),
-                             _("Error saving playlist file"),
-                             msg);
-        g_free (msg);
-        goto out;
-    }
-    
-    if ( format == PAROLE_PL_FORMAT_UNKNOWN )
-    {
-        format = parole_pl_parser_guess_format_from_extension (filename);
-        if ( format == PAROLE_PL_FORMAT_UNKNOWN )
+        ParolePlFormat format = PAROLE_PL_FORMAT_UNKNOWN;
+        GSList *list = NULL;
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+        
+        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (data->chooser));
+        dirname = g_path_get_dirname (filename);
+        
+        if ( gtk_tree_selection_get_selected (data->sel, &model, &iter ) )
+        {
+            gtk_tree_model_get (model, &iter, 2, &format, -1);
+        }
+        
+        if ( g_access (dirname, W_OK) == -1 )
         {
-            parole_dialog_info (GTK_WINDOW (gtk_widget_get_toplevel (data->list->priv->view)),
-                                _("Unknown playlist format"),
-                                _("Please chooser a supported playlist format"));
+            gchar *msg;
+            msg = g_strdup_printf ("%s %s", dirname, _("Permission denied"));
+            parole_dialog_error (GTK_WINDOW (gtk_widget_get_toplevel (data->list->priv->view)),
+                                 _("Error saving playlist file"),
+                                 msg);
+            g_free (msg);
             goto out;
         }
+        
+        if ( format == PAROLE_PL_FORMAT_UNKNOWN )
+        {
+            format = parole_pl_parser_guess_format_from_extension (filename);
+            if ( format == PAROLE_PL_FORMAT_UNKNOWN )
+            {
+                parole_dialog_info (GTK_WINDOW (gtk_widget_get_toplevel (data->list->priv->view)),
+                                    _("Unknown playlist format"),
+                                    _("Please chooser a supported playlist format"));
+                goto out;
+            }
+        }
+        
+        list = parole_media_list_get_files (data->list);
+        
+        parole_pl_parser_save_from_files (list, filename, format);
+        g_slist_free (list);
+
     }
-    
-    list = parole_media_list_get_files (data->list);
-    
-    parole_media_list_close_save_dialog_cb (NULL, data);
-    
-    parole_pl_parser_save_from_files (list, filename, format);
-    g_slist_free (list);
+    data->closing = TRUE;
+    gtk_widget_destroy(GTK_WIDGET(dialog));
+    g_free(data);
 out:
     g_free (filename);
     g_free (dirname);
@@ -767,6 +766,10 @@ void parole_media_list_format_cursor_changed_cb (GtkTreeView *view, ParolePlayli
     gchar *filename;
     gchar *fbasename;
     
+    /* Workaround for bug where cursor-changed is emitted on destroy */
+    if (data->closing)
+        return;
+    
     // FIXME: replaces entered filename with Playlist.
     filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (data->chooser));
     if (filename)
@@ -807,7 +810,6 @@ void parole_media_list_save_cb (GtkWidget *widget, ParoleMediaList *list)
     data = g_new0 (ParolePlaylistSave, 1);
     
     builder = parole_builder_new_from_string (save_playlist_ui, save_playlist_ui_length);
-    
     chooser = GTK_WIDGET (gtk_builder_get_object (builder, "filechooserdialog"));
     store = GTK_LIST_STORE (gtk_builder_get_object (builder, "liststore"));
 
@@ -854,7 +856,10 @@ void parole_media_list_save_cb (GtkWidget *widget, ParoleMediaList *list)
 
     view = GTK_WIDGET (gtk_builder_get_object (builder, "treeview"));
     
+    g_signal_connect(G_OBJECT(chooser), "response", G_CALLBACK(parole_media_list_save_playlist_response_cb), data);
+    
     data->chooser = chooser;
+    data->closing = FALSE;
     data->sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
     data->list = list;
 


More information about the Xfce4-commits mailing list