[sound-juicer] Move submit infobar to ui file



commit ef3a21613197e60a1b765305d756448b84c6a5d1
Author: Phillip Wood <phillip wood dunelm org uk>
Date:   Thu Aug 14 11:29:45 2014 +0100

    Move submit infobar to ui file
    
    The infobar at is only ever used to prompt the user to submit an album
    to Musicbrainz so there is no need to keep creating and destroying
    it. Moving it definition to the ui file simplifies the code and
    removes code from GEdit which does not have an exception for
    proprietary codecs.
    
    The appearance of the infobar is changed slightly, there is no icon
    anymore and it now uses a symbolic close button which saves some
    space.
    
    Note that the buttons in the infobar are packed into their own box to
    stop the button box adding internal padding to the buttons which makes
    the close button look too wide.
    
    This raises the required Gtk version to 3.4 for GtkActionable

 configure.ac         |    2 +-
 data/sound-juicer.ui |  125 ++++++++++++++++++++++++++++++++++--
 src/sj-main.c        |  174 ++++++++++----------------------------------------
 3 files changed, 156 insertions(+), 145 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b5b1bcf..99f9cc8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ GNOME_COMPILE_WARNINGS([maximum])
 GNOME_DEBUG_CHECK
 GNOME_MAINTAINER_MODE_DEFINES
 
-GTK_REQUIRED=3.2.0
+GTK_REQUIRED=3.4.0
 GLIB_GSETTINGS
 
 AC_CHECK_FUNC(socket,,[AC_CHECK_LIB(socket,socket)])
diff --git a/data/sound-juicer.ui b/data/sound-juicer.ui
index c619d8a..04472e6 100644
--- a/data/sound-juicer.ui
+++ b/data/sound-juicer.ui
@@ -1,7 +1,6 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
-  <!-- interface-naming-policy project-wide -->
+  <requires lib="gtk+" version="3.4"/>
   <object class="GtkApplicationWindow" id="main_window">
     <property name="width_request">500</property>
     <property name="height_request">420</property>
@@ -12,14 +11,130 @@
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkEventBox" id="message_area_eventbox">
-            <property name="visible">True</property>
+          <object class="GtkInfoBar" id="submit_bar">
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <signal name="response" handler="submit_bar_response_cb"/>
+            <child internal-child="action_area">
+              <object class="GtkButtonBox" id="infobar-action_area1">
+                <property name="can_focus">False</property>
+                <property name="layout_style">end</property>
+                <child>
+                  <object class="GtkBox" id="box1">
+                    <property name="visible">True</property>
+                    <property name="halign">center</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkButton" id="submit_button">
+                        <property name="label" translatable="yes">S_ubmit Album</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="action_name">app.submit-tracks</property>
+                        <property name="use_underline">True</property>
+                        <accessibility>
+                          <relation type="labelled-by" target="submit_label"/>
+                          <relation type="labelled-by" target="submit_label_secondary"/>
+                        </accessibility>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="submit_bar_close_button">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <child>
+                          <object class="GtkImage" id="close_image">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="icon_name">window-close-symbolic</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <action-widgets>
+              <action-widget response="close">submit_bar_close_button</action-widget>
+            </action-widgets>
+            <child internal-child="content_area">
+              <object class="GtkBox" id="infobar-content_area1">
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="submit_label">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="valign">center</property>
+                    <property name="hexpand">True</property>
+                    <property name="xalign">0</property>
+                    <property name="wrap">True</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="submit_label_secondary">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="valign">center</property>
+                    <property name="hexpand">True</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">You can improve the MusicBrainz database by 
adding this album.</property>
+                    <property name="wrap">True</property>
+                    <attributes>
+                      <attribute name="scale" value="0.833333333333"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
             <child>
               <placeholder/>
             </child>
           </object>
           <packing>
             <property name="expand">False</property>
+            <property name="fill">False</property>
             <property name="position">1</property>
           </packing>
         </child>
diff --git a/src/sj-main.c b/src/sj-main.c
index 76cc4b1..61df38c 100644
--- a/src/sj-main.c
+++ b/src/sj-main.c
@@ -63,6 +63,7 @@ G_MODULE_EXPORT void on_title_edit_changed(GtkEditable *widget, gpointer user_da
 G_MODULE_EXPORT void on_person_edit_changed(GtkEditable *widget, gpointer user_data);
 G_MODULE_EXPORT void on_year_edit_changed(GtkEditable *widget, gpointer user_data);
 G_MODULE_EXPORT void on_disc_number_edit_changed(GtkEditable *widget, gpointer user_data);
+G_MODULE_EXPORT void submit_bar_response_cb (GtkInfoBar *infobar, int response_id, gpointer user_data);
 
 GtkBuilder *builder;
 
@@ -72,7 +73,7 @@ SjExtractor *extractor;
 GSettings *sj_settings;
 
 GtkWidget *main_window;
-static GtkWidget *message_area_eventbox;
+static GtkWidget *submit_bar, *submit_label;
 static GtkWidget *title_entry, *artist_entry, *composer_label, *composer_entry, *duration_label, 
*genre_entry, *year_entry, *disc_number_entry;
 static GtkWidget *entry_table; /* GtkTable containing composer_entry */
 static GtkTreeViewColumn *composer_column; /* Treeview column containing composers */
@@ -81,8 +82,6 @@ static GtkWidget *status_bar;
 GtkListStore *track_store;
 GtkCellRenderer *toggle_renderer, *title_renderer, *artist_renderer, *composer_renderer;
 
-GtkWidget *current_message_area;
-
 char *path_pattern, *file_pattern;
 GFile *base_uri;
 BraseroDrive *drive = NULL;
@@ -315,118 +314,37 @@ static void number_cell_icon_data_cb (GtkTreeViewColumn *tree_column,
   }
 }
 
-/* Taken from gedit */
-static void
-set_info_bar_text_and_icon (GtkInfoBar  *infobar,
-                            const gchar *icon_name,
-                            const gchar *primary_text,
-                            const gchar *secondary_text,
-                            GtkWidget   *button)
-{
-  GtkWidget *content_area;
-  GtkWidget *hbox_content;
-  GtkWidget *image;
-  GtkWidget *vbox;
-  gchar *primary_markup;
-  gchar *secondary_markup;
-  GtkWidget *primary_label;
-  GtkWidget *secondary_label;
-  AtkObject *ally_target;
-
-  ally_target = gtk_widget_get_accessible (button);
-
-  hbox_content = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8); 
-  gtk_widget_show (hbox_content);
-
-  image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_DIALOG);
-  gtk_widget_show (image);
-  gtk_box_pack_start (GTK_BOX (hbox_content), image, FALSE, FALSE, 0);
-  gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0);
-
-  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); 
-  gtk_widget_show (vbox);
-  gtk_box_pack_start (GTK_BOX (hbox_content), vbox, TRUE, TRUE, 0);
-
-  primary_markup = g_markup_printf_escaped ("<b>%s</b>", primary_text);
-  primary_label = gtk_label_new (primary_markup);
-  g_free (primary_markup);
-  gtk_widget_show (primary_label);
-  gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
-  gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
-  gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
-  gtk_misc_set_alignment (GTK_MISC (primary_label), 0, 0.5);
-  atk_object_add_relationship (ally_target,
-                               ATK_RELATION_LABELLED_BY,
-                               gtk_widget_get_accessible (primary_label));
-
-  if (secondary_text != NULL) {
-    secondary_markup = g_markup_printf_escaped ("<small>%s</small>",
-                                                secondary_text);
-    secondary_label = gtk_label_new (secondary_markup);
-    g_free (secondary_markup);
-    gtk_widget_show (secondary_label);
-    gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
-    gtk_label_set_use_markup (GTK_LABEL (secondary_label), TRUE);
-    gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
-    gtk_misc_set_alignment (GTK_MISC (secondary_label), 0, 0.5);
-    atk_object_add_relationship (ally_target,
-                                 ATK_RELATION_LABELLED_BY,
-                                 gtk_widget_get_accessible (secondary_label));
-  }
-
-  content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (infobar));
-  gtk_container_add (GTK_CONTAINER (content_area), hbox_content);
-}
-
-/* Taken from gedit */
 static void
-set_message_area (GtkWidget *container,
-                  GtkWidget *message_area)
+set_submit_text (const AlbumDetails *album)
 {
-  if (current_message_area == message_area)
-    return;
-
-  if (current_message_area != NULL)
-    gtk_widget_destroy (current_message_area);
-
-  current_message_area = message_area;
+  gchar *text;
 
-  if (message_area == NULL)
-    return;
-
-  gtk_container_add (GTK_CONTAINER (container), message_area);
-
-  g_object_add_weak_pointer (G_OBJECT (current_message_area),
-                             (gpointer)&current_message_area);
+  if (g_str_equal (album->title, _("Unknown Title"))) {
+    text = g_strdup (_("This album is not in the Musicbrainz database."));
+  } else {
+    text = g_strdup_printf (_("Could not find %s by %s on MusicBrainz."),
+                                    album->title, album->artist);
+  }
+  gtk_label_set_text (GTK_LABEL (submit_label), text);
+  g_free (text);
 }
 
-static GtkWidget*
-musicbrainz_submit_info_bar_new (char *title, char *artist)
+static void
+submit_tracks_enabled_changed_cb (GActionGroup *action_group,
+                                  gchar        *action_name,
+                                  gboolean      enabled,
+                                  gpointer      user_data)
 {
-  GtkWidget *infobar, *button;
-  char *primary_text;
-
-  g_return_val_if_fail (title != NULL, NULL);
-  g_return_val_if_fail (artist != NULL, NULL);
-
-  infobar = gtk_info_bar_new ();
-  button = gtk_info_bar_add_button (GTK_INFO_BAR (infobar),
-                                    _("S_ubmit Album"), GTK_RESPONSE_OK);
-  gtk_info_bar_add_button (GTK_INFO_BAR (infobar),
-                           _("Ca_ncel"), GTK_RESPONSE_CANCEL);
-
-  /* Translators: title, artist */
-  primary_text = g_strdup_printf (_("Could not find %s by %s on MusicBrainz."), title, artist);
-
-  set_info_bar_text_and_icon (GTK_INFO_BAR (infobar),
-                              "dialog-information",
-                              primary_text,
-                              _("You can improve the MusicBrainz database by adding this album."),
-                              button);
-
-  g_free (primary_text);
+  if (!enabled)
+    gtk_widget_hide (submit_bar);
+}
 
-  return infobar;
+G_MODULE_EXPORT void
+submit_bar_response_cb (GtkInfoBar *infobar,
+                        int         response_id,
+                        gpointer    user_data)
+{
+  gtk_widget_hide (GTK_WIDGET (infobar));
 }
 
 /**
@@ -454,6 +372,7 @@ static void on_submit_activate (GSimpleAction *action, GVariant *parameter, gpoi
       g_error_free (error);
     }
   }
+  gtk_widget_hide (GTK_WIDGET (submit_bar));
 }
 
 static void on_preferences_activate (GSimpleAction *action, GVariant *parameter, gpointer data)
@@ -493,18 +412,6 @@ static void on_duplicate_activate (GSimpleAction *action, GVariant *parameter, g
   }
 }
 
-static void
-musicbrainz_submit_info_bar_response (GtkInfoBar *infobar,
-                                      int         response_id,
-                                      gpointer    user_data)
-{
-  if (response_id == GTK_RESPONSE_OK) {
-    on_submit_activate (NULL, NULL, NULL);
-  }
-
-  set_message_area (message_area_eventbox, NULL);
-}
-
 #define TABLE_ROW_SPACING 6 /* spacing of rows in entry_table */
 
 /*
@@ -629,8 +536,6 @@ static void update_ui_for_album (AlbumDetails *album)
     set_action_enabled ("previous-track", FALSE);
     set_action_enabled ("next-track", FALSE);
     set_action_enabled ("duplicate", FALSE);
-
-    set_message_area (message_area_eventbox, NULL);
   } else {
     gtk_list_store_clear (track_store);
 
@@ -709,24 +614,10 @@ static void update_ui_for_album (AlbumDetails *album)
     } else {
       gtk_label_set_text (GTK_LABEL (duration_label), _("(unknown)"));
     }
-
     /* If album details don't come from MusicBrainz ask user to add them */
     if (album->metadata_source != SOURCE_MUSICBRAINZ) {
-      GtkWidget *infobar;
-
-      infobar = musicbrainz_submit_info_bar_new (album->title, album->artist);
-
-      set_message_area (message_area_eventbox, infobar);
-
-      g_signal_connect (infobar,
-                        "response",
-                        G_CALLBACK (musicbrainz_submit_info_bar_response),
-                        NULL);
-
-      gtk_info_bar_set_default_response (GTK_INFO_BAR (infobar),
-                                         GTK_RESPONSE_CANCEL);
-
-      gtk_widget_show (infobar);
+      set_submit_text (album);
+      gtk_widget_show (submit_bar);
     }
   }
 }
@@ -2046,7 +1937,8 @@ startup_cb (GApplication *app, gpointer user_data)
   gtk_builder_connect_signals (builder, NULL);
 
   main_window           = GET_WIDGET ("main_window");
-  message_area_eventbox = GET_WIDGET ("message_area_eventbox");
+  submit_bar            = GET_WIDGET ("submit_bar");
+  submit_label          = GET_WIDGET ("submit_label");
   title_entry           = GET_WIDGET ("title_entry");
   artist_entry          = GET_WIDGET ("artist_entry");
   composer_label        = GET_WIDGET ("composer_label");
@@ -2067,6 +1959,10 @@ startup_cb (GApplication *app, gpointer user_data)
   g_action_map_add_action_entries (G_ACTION_MAP (main_window),
                                    win_entries, G_N_ELEMENTS (win_entries),
                                    NULL);
+
+  g_signal_connect (app, "action-enabled-changed::submit-tracks",
+                    G_CALLBACK (submit_tracks_enabled_changed_cb), NULL);
+
   gtk_button_set_label(GTK_BUTTON(select_button), _("Select None"));
   gtk_actionable_set_action_name(GTK_ACTIONABLE(select_button), "win.deselect-all");
   gtk_actionable_set_action_name(GTK_ACTIONABLE(play_button), "win.play");


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