[easytag/wip/application-window: 49/70] Use GAction for toolbar stop button



commit fcce44f9e4eb51c9f043d25113f089706458b729
Author: David King <amigadave amigadave com>
Date:   Sun Jul 13 22:42:50 2014 +0100

    Use GAction for toolbar stop button

 Makefile.am              |    1 -
 TODO                     |    1 -
 data/toolbar.ui          |   15 +++++++++
 src/application_window.c |   23 +++++++------
 src/bar.c                |   79 +---------------------------------------------
 src/bar.h                |   17 ----------
 src/easytag.c            |   30 +++++++++--------
 src/ui_manager.h         |   16 ---------
 8 files changed, 45 insertions(+), 137 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 75c235d..69cd36d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -128,7 +128,6 @@ easytag_headers = \
        src/scan_dialog.h \
        src/search_dialog.h \
        src/setting.h \
-       src/ui_manager.h \
        src/vcedit.h \
        src/wavpack_header.h \
        src/wavpack_tag.h \
diff --git a/TODO b/TODO
index 9be4c8a..f7b5fca 100644
--- a/TODO
+++ b/TODO
@@ -14,7 +14,6 @@ General tidying
 After GTK+ 3
 ------------
 
-* Port to GtkApplication
 * Use GtkAppChooserDialog for selecting applications
 
 Tagging features
diff --git a/data/toolbar.ui b/data/toolbar.ui
index 1a310a7..51a5daf 100644
--- a/data/toolbar.ui
+++ b/data/toolbar.ui
@@ -1,6 +1,9 @@
 <interface domain="easytag">
     <object class="GtkToolbar" id="main_toolbar">
         <property name="visible">True</property>
+        <style>
+            <class name="primary-toolbar"/>
+        </style>
         <child>
             <object class="GtkToolButton" id="first_button">
                 <property name="action-name">win.go-first</property>
@@ -150,5 +153,17 @@
                 <property name="visible">True</property>
             </object>
         </child>
+        <child>
+            <object class="GtkSeparatorToolItem" id="separator5"/>
+        </child>
+        <child>
+            <object class="GtkToolButton" id="stop_button">
+                <property name="action-name">win.stop</property>
+                <property name="icon-name">process-stop</property>
+                <property name="label" translatable="yes">Stop</property>
+                <property name="tooltip-text" translatable="yes">Stop the current action</property>
+                <property name="visible">True</property>
+            </object>
+        </child>
     </object>
 </interface>
diff --git a/src/application_window.c b/src/application_window.c
index 63e647d..f911d92 100644
--- a/src/application_window.c
+++ b/src/application_window.c
@@ -2866,6 +2866,14 @@ on_run_player_directory (GSimpleAction *action,
     Run_Audio_Player_Using_Directory ();
 }
 
+static void
+on_stop (GSimpleAction *action,
+         GVariant *variant,
+         gpointer user_data)
+{
+    Action_Main_Stop_Button_Pressed ();
+}
+
 static const GActionEntry actions[] =
 {
     /* File menu. */
@@ -2924,7 +2932,9 @@ static const GActionEntry actions[] =
     { "clear-log", on_clear_log },
     { "run-player-album", on_run_player_album },
     { "run-player-artist", on_run_player_artist },
-    { "run-player-directory", on_run_player_directory }
+    { "run-player-directory", on_run_player_directory },
+    /* Toolbar. */
+    { "stop", on_stop }
 };
 
 static void
@@ -2992,14 +3002,10 @@ et_application_window_init (EtApplicationWindow *self)
 
     /* Menu bar and tool bar. */
     {
-        GtkWidget *tool_area;
         GtkBuilder *builder;
         GError *error = NULL;
         GtkWidget *toolbar;
 
-        tool_area = create_main_toolbar (window);
-        gtk_box_pack_start (GTK_BOX (main_vbox), tool_area, FALSE, FALSE, 0);
-
         builder = gtk_builder_new ();
         gtk_builder_add_from_resource (builder,
                                        "/org/gnome/EasyTAG/toolbar.ui",
@@ -3439,7 +3445,6 @@ void
 et_application_window_update_actions (EtApplicationWindow *self)
 {
     GtkDialog *dialog;
-    GtkAction *uiaction;
 
     dialog = GTK_DIALOG (et_application_window_get_scan_dialog (self));
 
@@ -3452,8 +3457,7 @@ et_application_window_update_actions (EtApplicationWindow *self)
         et_application_window_tag_area_set_sensitive (self, FALSE);
 
         /* Tool bar buttons (the others are covered by the menu) */
-        uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-        g_object_set(uiaction, "sensitive", FALSE, NULL);
+        set_action_state (self, "stop", FALSE);
 
         /* Scanner Window */
         if (dialog)
@@ -3500,8 +3504,7 @@ et_application_window_update_actions (EtApplicationWindow *self)
         et_application_window_tag_area_set_sensitive (self, TRUE);
 
         /* Tool bar buttons */
-        uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-        g_object_set(uiaction, "sensitive", FALSE, NULL);
+        set_action_state (self, "stop", FALSE);
 
         /* Scanner Window */
         if (dialog)
diff --git a/src/bar.c b/src/bar.c
index ed39e62..c94e79f 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -17,23 +17,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
-#include "application_window.h"
 #include "bar.h"
-#include "easytag.h"
-#include "preferences_dialog.h"
-#include "setting.h"
-#include "browser.h"
-#include "scan_dialog.h"
-#include "cddb_dialog.h"
-#include "log.h"
-#include "misc.h"
 #include "charset.h"
-#include "ui_manager.h"
 #include "gtk2_compat.h"
 
 /***************
@@ -43,7 +33,6 @@ static GtkWidget *StatusBar = NULL;
 static guint StatusBarContext;
 static guint timer_cid;
 static guint StatusbarTimerId = 0;
-static GList *ActionPairsList = NULL;
 
 /**************
  * Prototypes *
@@ -55,72 +44,6 @@ static void Statusbar_Remove_Timer (void);
  * Functions o
  *************/
 
-GtkWidget *
-create_main_toolbar (GtkWindow *window)
-{
-    GtkWidget *toolbar;
-
-    /*
-     * Structure :
-     *  - name
-     *  - stock_id
-     *  - label
-     *  - accelerator
-     *  - tooltip
-     *  - callback
-     */
-    GtkActionEntry ActionEntries[] =
-    {
-        /*
-         * Following items are on toolbar but not on menu
-         */
-        { AM_STOP, GTK_STOCK_STOP, _("Stop the current action"), NULL, _("Stop the current action"), 
G_CALLBACK(Action_Main_Stop_Button_Pressed) },
-
-    };
-
-    GError *error = NULL;
-    guint num_menu_entries;
-    guint i;
-
-    /* Calculate number of items into the menu */
-    num_menu_entries = G_N_ELEMENTS(ActionEntries);
-
-    /* Populate quarks list with the entries */
-    for(i = 0; i < num_menu_entries; i++)
-    {
-        Action_Pair* ActionPair = g_malloc0(sizeof(Action_Pair));
-        ActionPair->action = ActionEntries[i].name;
-        ActionPair->quark  = g_quark_from_string(ActionPair->action);
-        ActionPairsList = g_list_prepend (ActionPairsList, ActionPair);
-    }
-
-    ActionPairsList = g_list_reverse (ActionPairsList);
-
-    /* UI Management */
-    ActionGroup = gtk_action_group_new("actions");
-    gtk_action_group_set_translation_domain (ActionGroup, GETTEXT_PACKAGE);
-    gtk_action_group_add_actions(ActionGroup, ActionEntries, num_menu_entries, window);
-
-    UIManager = gtk_ui_manager_new();
-
-    if (!gtk_ui_manager_add_ui_from_string(UIManager, ui_xml, -1, &error))
-    {
-        g_error(_("Could not merge UI, error was: %s\n"), error->message);
-        g_error_free(error);
-    }
-    gtk_ui_manager_insert_action_group(UIManager, ActionGroup, 0);
-    gtk_window_add_accel_group (window,
-                                gtk_ui_manager_get_accel_group (UIManager));
-
-    toolbar = gtk_ui_manager_get_widget (UIManager, "/ToolBar");
-    gtk_widget_show_all (toolbar);
-    gtk_style_context_add_class (gtk_widget_get_style_context (toolbar),
-                                 GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
-
-    return toolbar;
-}
-
-
 /*
  * Status bar functions
  */
diff --git a/src/bar.h b/src/bar.h
index af88452..193926a 100644
--- a/src/bar.h
+++ b/src/bar.h
@@ -26,28 +26,11 @@
  * Declaration *
  ***************/
 GtkWidget      *ProgressBar;
-GtkUIManager   *UIManager;
-GtkActionGroup *ActionGroup;
-
-#define POPUP_FILE              "FilePopup"
-#define POPUP_SUBMENU_SCANNER   "ScannerSubpopup"
-
-#define AM_OPEN_OPTIONS_WINDOW      "Preferences"
-#define AM_CDDB_SEARCH_FILE         "CDDBSearchFile"
-
-#define AM_STOP                     "Stop"
-
-typedef struct _Action_Pair Action_Pair;
-struct _Action_Pair {
-    const gchar *action;
-    GQuark quark;
-};
 
 /**************
  * Prototypes *
  **************/
 
-GtkWidget *create_main_toolbar (GtkWindow *window);
 GtkWidget *Create_Status_Bar   (void);
 void Statusbar_Message (const gchar *message, gboolean with_timer);
 GtkWidget *Create_Progress_Bar (void);
diff --git a/src/easytag.c b/src/easytag.c
index 5766101..7e7107b 100644
--- a/src/easytag.c
+++ b/src/easytag.c
@@ -528,7 +528,7 @@ Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files)
     File_Tag  *FileTag;
     File_Name *FileNameNew;
     double     fraction;
-    GtkAction *uiaction;
+    GAction *action;
     GtkWidget *widget_focused;
     GtkTreePath *currentPath = NULL;
 
@@ -603,8 +603,9 @@ Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files)
     SF_HideMsgbox_Rename_File = FALSE;
 
     Main_Stop_Button_Pressed = FALSE;
-    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop"); // Activate the stop button
-    g_object_set(uiaction, "sensitive", FALSE, NULL);
+    /* Activate the stop button. */
+    action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
 
     /*
      * Check if file was changed by an external program
@@ -708,8 +709,8 @@ Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files)
         msg = g_strdup (_("All files have been saved"));
 
     Main_Stop_Button_Pressed = FALSE;
-    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-    g_object_set(uiaction, "sensitive", FALSE, NULL);
+    action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
 
     /* Return to the saved position in the list */
     ET_Display_File_Data_To_UI(etfile_save_position);
@@ -1187,7 +1188,7 @@ gboolean Read_Directory (gchar *path_real)
     GList *FileList = NULL;
     GList *l;
     gint   progress_bar_index = 0;
-    GtkAction *uiaction;
+    GAction *action;
     EtApplicationWindow *window;
 
     g_return_val_if_fail (path_real != NULL, FALSE);
@@ -1250,9 +1251,9 @@ gboolean Read_Directory (gchar *path_real)
 
     /* Open the window to quit recursion (since 27/04/2007 : not only into recursion mode) */
     Set_Busy_Cursor();
-    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-    g_settings_bind (MainSettings, "browse-subdir", uiaction, "sensitive",
-                     G_SETTINGS_BIND_GET);
+    action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop");
+    g_settings_bind (MainSettings, "browse-subdir", G_SIMPLE_ACTION (action),
+                     "enabled", G_SETTINGS_BIND_GET);
     Open_Quit_Recursion_Function_Window();
 
     /* Read the directory recursively */
@@ -1304,8 +1305,8 @@ gboolean Read_Directory (gchar *path_real)
     /* Close window to quit recursion */
     Destroy_Quit_Recursion_Function_Window();
     Main_Stop_Button_Pressed = FALSE;
-    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-    g_object_set(uiaction, "sensitive", FALSE, NULL);
+    action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
 
     //ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__);
 
@@ -1534,10 +1535,11 @@ et_on_quit_recursion_response (GtkDialog *dialog, gint response_id,
  */
 void Action_Main_Stop_Button_Pressed (void)
 {
-    GtkAction *uiaction;
+    GAction *action;
+
+    action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop");
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
     Main_Stop_Button_Pressed = TRUE;
-    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
-    g_object_set(uiaction, "sensitive", FALSE, NULL);
 }
 
 /*


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