[sound-juicer] Close multiple album dialog on eject



commit 5f73c37947cb5f144e5d370d200336e6281cf993
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Mon Jul 27 14:03:16 2015 +0100

    Close multiple album dialog on eject
    
    If the disc is ejected while the multiple album dialog is visible the
    dialog should be closed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753509

 src/sj-main.c |   37 ++++++++++++++++++++++++-------------
 src/sj-main.h |    2 --
 2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/src/sj-main.c b/src/sj-main.c
index d65957d..10ff372 100644
--- a/src/sj-main.c
+++ b/src/sj-main.c
@@ -82,7 +82,7 @@ static GtkWidget *title_entry, *artist_entry, *composer_label, *composer_entry,
 static GtkWidget *entry_table; /* GtkTable containing composer_entry */
 static GtkTreeViewColumn *composer_column; /* Treeview column containing composers */
 static GtkWidget *track_listview, *extract_button, *play_button, *select_button;
-static GtkWidget *status_bar, *submit_button, *reload_button;
+static GtkWidget *multiple_album_dialog, *status_bar, *submit_button, *reload_button;
 GtkListStore *track_store;
 GtkCellRenderer *toggle_renderer, *title_renderer, *artist_renderer, *composer_renderer;
 
@@ -191,6 +191,10 @@ static void on_quit_activate (GSimpleAction *action, GVariant *parameter, gpoint
   }
 }
 
+enum {
+  SJ_RESPONSE_EJECTED = 1
+};
+
 static void
 disc_ejected_cb (void)
 {
@@ -198,6 +202,10 @@ disc_ejected_cb (void)
   stop_playback ();
   stop_ui_hack ();
   update_ui_for_album (NULL);
+  if (multiple_album_dialog != NULL &&
+      gtk_widget_get_mapped (multiple_album_dialog))
+    gtk_dialog_response (GTK_DIALOG (multiple_album_dialog),
+                         SJ_RESPONSE_EJECTED);
   set_action_state ("re-read(false)");
   set_action_enabled ("re-read", FALSE);
   set_action_enabled ("submit-tracks", FALSE);
@@ -929,9 +937,10 @@ static char *format_release_details (AlbumDetails *album)
 /**
  * Utility function for when there are more than one albums available
  */
-AlbumDetails* multiple_album_dialog(GList *albums)
+static AlbumDetails*
+choose_album(GList *albums)
 {
-  static GtkWidget *dialog = NULL, *albums_listview;
+  static GtkWidget *albums_listview;
   static GtkListStore *albums_store;
   static GtkTreeSelection *selection;
   AlbumDetails *album;
@@ -945,13 +954,14 @@ AlbumDetails* multiple_album_dialog(GList *albums)
     COLUMN_COUNT
   };
 
-  if (dialog == NULL) {
+  if (multiple_album_dialog == NULL) {
     GtkTreeViewColumn *column = gtk_tree_view_column_new ();
     GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
 
-    dialog = GET_WIDGET ("multiple_dialog");
-    g_assert (dialog != NULL);
-    gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (main_window));
+    multiple_album_dialog = GET_WIDGET ("multiple_dialog");
+    g_assert (multiple_album_dialog != NULL);
+    gtk_window_set_transient_for (GTK_WINDOW (multiple_album_dialog),
+                                  GTK_WINDOW (main_window));
     albums_listview = GET_WIDGET ("albums_listview");
     ok_button       = GET_WIDGET ("ok_button");
 
@@ -961,7 +971,7 @@ AlbumDetails* multiple_album_dialog(GList *albums)
                                         "markup", COLUMN_RELEASE);
 
     g_signal_connect (albums_listview, "row-activated",
-                      G_CALLBACK (album_row_activated), dialog);
+                      G_CALLBACK (album_row_activated), multiple_album_dialog);
 
     albums_store = gtk_list_store_new (COLUMN_COUNT,
                                        G_TYPE_STRING,
@@ -1016,11 +1026,12 @@ AlbumDetails* multiple_album_dialog(GList *albums)
     gtk_tree_selection_select_iter (selection, &iter);
   }
 
-  gtk_widget_show_all (dialog);
-  response = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_hide (dialog);
+  gtk_widget_show_all (multiple_album_dialog);
+  response = gtk_dialog_run (GTK_DIALOG (multiple_album_dialog));
+  gtk_widget_hide (multiple_album_dialog);
 
-  if (response == GTK_RESPONSE_DELETE_EVENT) {
+  if (response == GTK_RESPONSE_DELETE_EVENT ||
+      response == SJ_RESPONSE_EJECTED) {
     return NULL;
   }
 
@@ -1178,7 +1189,7 @@ metadata_cb (SjMetadataGetter *m, GList *albums, GError *error)
   /* Set the new current album pointer */
   if (albums != NULL) {
     if (albums->next != NULL) {
-      current_album = multiple_album_dialog (albums);
+      current_album = choose_album (albums);
       /* Concentrate here. We remove the album we want from the list, and then
          deep-free the list. */
       albums = g_list_remove (albums, current_album);
diff --git a/src/sj-main.h b/src/sj-main.h
index 01d3da7..62bce6e 100644
--- a/src/sj-main.h
+++ b/src/sj-main.h
@@ -27,8 +27,6 @@ void set_action_enabled (const char *name, gboolean enabled);
 
 G_MODULE_EXPORT void on_destroy_activate (GtkMenuItem *item, gpointer user_data);
 
-AlbumDetails* multiple_album_dialog (GList* albums);
-
 const char* prefs_get_default_device (void);
 
 G_MODULE_EXPORT void on_genre_edit_changed(GtkEditable *widget, gpointer user_data);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]