[gthumb] slideshow: removed use of GtkAction and GtkUIManager



commit 988662a127533f5471de287bc9483ed521ad6f83
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Oct 18 13:33:53 2013 +0200

    slideshow: removed use of GtkAction and GtkUIManager

 extensions/slideshow/actions.c   |   15 +----
 extensions/slideshow/actions.h   |    5 +-
 extensions/slideshow/callbacks.c |  117 ++++++-------------------------------
 gthumb/gth-browser.c             |   26 ++++++++-
 gthumb/gth-browser.h             |   10 +++-
 gthumb/gth-window.c              |   25 +++++++-
 gthumb/gth-window.h              |    6 ++-
 7 files changed, 84 insertions(+), 120 deletions(-)
---
diff --git a/extensions/slideshow/actions.c b/extensions/slideshow/actions.c
index 673db97..d5e6d72 100644
--- a/extensions/slideshow/actions.c
+++ b/extensions/slideshow/actions.c
@@ -29,9 +29,11 @@
 
 
 void
-gth_browser_activate_action_view_slideshow (GtkAction  *action,
-                                           GthBrowser *browser)
+gth_browser_activate_slideshow (GSimpleAction *action,
+                               GVariant      *parameter,
+                               gpointer       user_data)
 {
+       GthBrowser   *browser = user_data;
        GSettings    *settings;
        GList        *items;
        GList        *file_list;
@@ -138,12 +140,3 @@ gth_browser_activate_action_view_slideshow (GtkAction  *action,
        _g_object_list_unref (file_list);
        _gtk_tree_path_list_free (items);
 }
-
-
-void
-gth_browser_activate_slideshow (GSimpleAction *action,
-                               GVariant      *parameter,
-                               gpointer       user_data)
-{
-       gth_browser_activate_action_view_slideshow (NULL, GTH_BROWSER (user_data));
-}
diff --git a/extensions/slideshow/actions.h b/extensions/slideshow/actions.h
index da36076..6e26257 100644
--- a/extensions/slideshow/actions.h
+++ b/extensions/slideshow/actions.h
@@ -22,11 +22,8 @@
 #ifndef ACTIONS_H
 #define ACTIONS_H
 
-#include <gtk/gtk.h>
+#include <gthumb.h>
 
-#define DEFINE_ACTION(x) void x (GtkAction *action, gpointer data);
-
-DEFINE_ACTION(gth_browser_activate_action_view_slideshow)
 DEF_ACTION_CALLBACK (gth_browser_activate_slideshow)
 
 #endif /* ACTIONS_H */
diff --git a/extensions/slideshow/callbacks.c b/extensions/slideshow/callbacks.c
index b6c9385..5c972ae 100644
--- a/extensions/slideshow/callbacks.c
+++ b/extensions/slideshow/callbacks.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+       /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
 /*
  *  GThumb
@@ -30,123 +30,44 @@
 #include "preferences.h"
 
 
-#define BROWSER_DATA_KEY "slideshow-browser-data"
-
-
 static const GActionEntry actions[] = {
        { "slideshow", gth_browser_activate_slideshow }
 };
 
 
-static const char *ui_info =
-"<ui>"
-"  <menubar name='MenuBar'>"
-"    <menu name='View' action='ViewMenu'>"
-"      <placeholder name='View_Actions'>"
-"        <menuitem action='View_Slideshow'/>"
-"      </placeholder>"
-"    </menu>"
-"  </menubar>"
-"  <toolbar name='ToolBar'>"
-"      <placeholder name='BrowserCommands'>"
-"        <toolitem action='View_Fullscreen'/>"
-"        <toolitem action='View_Slideshow'/>"
-"      </placeholder>"
-"  </toolbar>"
-"</ui>";
-
-
-static GtkActionEntry action_entries[] = {
-       { "View_Slideshow", "x-office-presentation",
-         N_("_Slideshow"), "F5",
-         N_("View as a slideshow"),
-         G_CALLBACK (gth_browser_activate_action_view_slideshow) }
-};
-
-
-typedef struct {
-       GtkActionGroup *action_group;
-       guint           actions_merge_id;
-} BrowserData;
-
-
-static void
-browser_data_free (BrowserData *data)
-{
-       g_free (data);
-}
-
-
 void
 ss__gth_browser_construct_cb (GthBrowser *browser)
 {
-       BrowserData *data;
-       GError      *error = NULL;
-
        g_return_if_fail (GTH_IS_BROWSER (browser));
 
-       data = g_new0 (BrowserData, 1);
-
-       data->action_group = gtk_action_group_new ("Slideshow Action");
-       gtk_action_group_set_translation_domain (data->action_group, NULL);
-       gtk_action_group_add_actions (data->action_group,
-                                     action_entries,
-                                     G_N_ELEMENTS (action_entries),
-                                     browser);
-       gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
-
-       data->actions_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), 
ui_info, -1, &error);
-       if (data->actions_merge_id == 0) {
-               g_warning ("building menus failed: %s", error->message);
-               g_error_free (error);
-       }
-
-       g_action_map_add_action_entries (G_ACTION_MAP (browser), actions, G_N_ELEMENTS (actions), browser);
-
-       {
-               GtkWidget *button;
-
-               button = _gtk_image_button_new_for_header_bar ("view-presentation-symbolic");
-               gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.slideshow");
-               gtk_widget_show (button);
-               gtk_box_pack_start (GTK_BOX (gth_browser_get_headerbar_section (browser, 
GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW)), button, FALSE, FALSE, 0);
-
-               button = _gtk_image_button_new_for_header_bar ("view-presentation-symbolic");
-               gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.slideshow");
-               gtk_widget_show (button);
-               gtk_box_pack_start (GTK_BOX (gth_browser_get_headerbar_section (browser, 
GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW)), button, FALSE, FALSE, 0);
-       }
-
-       g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) 
browser_data_free);
-}
-
-
-static void
-set_action_sensitive (BrowserData *data,
-                     const char  *action_name,
-                     gboolean     sensitive)
-{
-       GtkAction *action;
-
-       action = gtk_action_group_get_action (data->action_group, action_name);
-       g_object_set (action, "sensitive", sensitive, NULL);
+       g_action_map_add_action_entries (G_ACTION_MAP (browser),
+                                        actions,
+                                        G_N_ELEMENTS (actions),
+                                        browser);
+
+       gth_browser_add_header_bar_button (browser,
+                                          GTH_BROWSER_HEADER_SECTION_BROWSER_VIEW,
+                                          "view-presentation-symbolic",
+                                          _("View as a slideshow"),
+                                          "win.slideshow",
+                                          "F5");
+       gth_browser_add_header_bar_button (browser,
+                                          GTH_BROWSER_HEADER_SECTION_VIEWER_VIEW,
+                                          "view-presentation-symbolic",
+                                          _("View as a slideshow"),
+                                          "win.slideshow",
+                                          "F5");
 }
 
 
 void
 ss__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 {
-       BrowserData  *data;
        GtkTreeModel *file_store;
        gboolean      sensitive;
 
-       data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
-       g_return_if_fail (data != NULL);
-
        file_store = gth_file_view_get_model (GTH_FILE_VIEW (gth_browser_get_file_list_view (browser)));
        sensitive = (gth_file_store_n_visibles (GTH_FILE_STORE (file_store)) > 0);
-       set_action_sensitive (data, "View_Slideshow", sensitive);
-
        g_object_set (g_action_map_lookup_action (G_ACTION_MAP (browser), "slideshow"), "enabled", sensitive, 
NULL);
 }
 
@@ -154,7 +75,7 @@ ss__gth_browser_update_sensitivity_cb (GthBrowser *browser)
 void
 ss__slideshow_cb (GthBrowser *browser)
 {
-       gth_browser_activate_action_view_slideshow (NULL, browser);
+       gth_browser_activate_slideshow (NULL, NULL, browser);
 }
 
 
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 3aa16d3..b705c66 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -596,7 +596,7 @@ gth_browser_update_title (GthBrowser *browser)
        if (title->len == 0)
                g_string_append (title, _("gThumb"));
 
-       _gth_window_set_title (GTH_WINDOW (browser), title->str, subtitle->str);
+       gth_window_set_title (GTH_WINDOW (browser), title->str, subtitle->str);
 
        g_string_free (title, TRUE);
        g_string_free (subtitle, TRUE);
@@ -5258,6 +5258,30 @@ gth_browser_get_headerbar_section (GthBrowser                    *browser,
 }
 
 
+void
+gth_browser_add_header_bar_button (GthBrowser                  *browser,
+                                  GthBrowserHeaderSection       section,
+                                  const char                   *icon_name,
+                                  const char                   *tooltip,
+                                  const char                   *action_name,
+                                  const char                   *accelerator)
+{
+       GtkWidget *button;
+
+       g_return_if_fail (icon_name != NULL);
+       g_return_if_fail (action_name != NULL);
+
+       button = _gtk_image_button_new_for_header_bar (icon_name);
+       gtk_actionable_set_action_name (GTK_ACTIONABLE (button),action_name);
+       if (tooltip != NULL)
+               gtk_widget_set_tooltip_text (button, tooltip);
+       if (accelerator != NULL)
+               gth_window_add_accelerator (GTH_WINDOW (browser), button, "activate", accelerator);
+       gtk_widget_show (button);
+       gtk_box_pack_start (GTK_BOX (gth_browser_get_headerbar_section (browser, section)), button, FALSE, 
FALSE, 0);
+}
+
+
 GthMenuManager *
 gth_browser_get_menu_manager (GthBrowser               *browser,
                              GthBrowserMenuManager      manager)
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index 09c8373..a21bbc3 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -128,8 +128,14 @@ GtkWidget *      gth_browser_get_browser_toolbar    (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_infobar            (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_statusbar          (GthBrowser       *browser);
 GtkWidget *      gth_browser_get_filterbar          (GthBrowser       *browser);
-GtkWidget *      gth_browser_get_headerbar_section  (GthBrowser       *browser,
-                                                    GthBrowserHeaderSection section);
+GtkWidget *      gth_browser_get_headerbar_section  (GthBrowser                        *browser,
+                                                    GthBrowserHeaderSection     section);
+void            gth_browser_add_header_bar_button  (GthBrowser                 *browser,
+                                                    GthBrowserHeaderSection     section,
+                                                    const char                 *icon_name,
+                                                    const char                 *tooltip,
+                                                    const char                 *action_name,
+                                                    const char                 *accelerator);
 GthMenuManager * gth_browser_get_menu_manager       (GthBrowser       *browser,
                                                     GthBrowserMenuManager
                                                                       manager);
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index 43489f4..523f7ea 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -51,6 +51,7 @@ struct _GthWindowPrivate {
        GtkWidget      **contents;
        GthWindowSize   *window_size;
        GtkWindowGroup  *window_group;
+       GtkAccelGroup   *accel_group;
 };
 
 
@@ -177,6 +178,7 @@ gth_window_finalize (GObject *object)
        g_free (window->priv->contents);
        g_free (window->priv->window_size);
        g_object_unref (window->priv->window_group);
+       g_object_unref (window->priv->accel_group);
 
        G_OBJECT_CLASS (gth_window_parent_class)->finalize (object);
 }
@@ -311,6 +313,9 @@ gth_window_init (GthWindow *window)
        window->priv->window_group = gtk_window_group_new ();
        gtk_window_group_add_window (window->priv->window_group, GTK_WINDOW (window));
 
+       window->priv->accel_group = gtk_accel_group_new ();
+       gtk_window_add_accel_group (GTK_WINDOW (window), window->priv->accel_group);
+
        gtk_window_set_application (GTK_WINDOW (window), Main_Application);
 }
 
@@ -553,9 +558,9 @@ gth_window_get_page_size (GthWindow *window,
 
 
 void
-_gth_window_set_title (GthWindow  *window,
-                      const char *title,
-                      const char *subtitle)
+gth_window_set_title (GthWindow  *window,
+                     const char *title,
+                     const char *subtitle)
 {
        if (window->priv->use_header_bar) {
                gtk_header_bar_set_title (GTK_HEADER_BAR (window->priv->headerbar), title);
@@ -574,3 +579,17 @@ _gth_window_set_title (GthWindow  *window,
                g_string_free (complete_title, TRUE);
        }
 }
+
+
+void
+gth_window_add_accelerator (GthWindow     *window,
+                           GtkWidget     *widget,
+                           const char    *accel_signal,
+                           const char    *accelerator)
+{
+       guint           accel_key;
+       GdkModifierType accel_mods;
+
+       gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
+       gtk_widget_add_accelerator (widget, accel_signal, window->priv->accel_group, accel_key, accel_mods, 
0);
+}
diff --git a/gthumb/gth-window.h b/gthumb/gth-window.h
index 6f83b7d..fa15679 100644
--- a/gthumb/gth-window.h
+++ b/gthumb/gth-window.h
@@ -100,9 +100,13 @@ gboolean       gth_window_get_page_size      (GthWindow     *window,
                                              int           *height);
 void           gth_window_clear_saved_size   (GthWindow     *window,
                                              int            page);
-void           _gth_window_set_title         (GthWindow     *window,
+void           gth_window_set_title          (GthWindow     *window,
                                              const char    *title,
                                              const char    *subtitle);
+void           gth_window_add_accelerator    (GthWindow     *window,
+                                             GtkWidget     *widget,
+                                             const char    *accel_signal,
+                                             const char    *accelerator);
 
 G_END_DECLS
 


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