[eog-plugins] send-by-mail: Port to GAction



commit 95cdb3d75272d0aa80efe97ecac88bff386b7923
Author: Felix Riemann <friemann gnome org>
Date:   Sun Feb 15 17:08:54 2015 +0100

    send-by-mail: Port to GAction
    
    https://bugzilla.gnome.org/show_bug.cgi?id=743885

 plugins/send-by-mail/eog-send-by-mail-plugin.c     |  125 +++++++++++---------
 plugins/send-by-mail/eog-send-by-mail-plugin.h     |    3 -
 .../send-by-mail/send-by-mail.plugin.desktop.in    |    4 +-
 3 files changed, 73 insertions(+), 59 deletions(-)
---
diff --git a/plugins/send-by-mail/eog-send-by-mail-plugin.c b/plugins/send-by-mail/eog-send-by-mail-plugin.c
index fab6a78..b63b2c4 100644
--- a/plugins/send-by-mail/eog-send-by-mail-plugin.c
+++ b/plugins/send-by-mail/eog-send-by-mail-plugin.c
@@ -31,6 +31,9 @@
 
 #include "eog-send-by-mail-plugin.h"
 
+#define EOG_SEND_BY_MAIL_PLUGIN_MENU_ID "EogPluginSendByMail"
+#define EOG_SEND_BY_MAIL_PLUGIN_ACTION "send-by-mail"
+
 
 static void
 eog_window_activatable_iface_init (EogWindowActivatableInterface *iface);
@@ -45,76 +48,85 @@ enum {
        PROP_WINDOW
 };
 
-static void send_by_mail_cb (GtkAction *action, EogWindow *window);
-
-static const gchar * const ui_definition =
-       "<ui><menubar name=\"MainMenu\">"
-       "<menu name=\"ToolsMenu\" action=\"Tools\">"
-       "<menuitem action=\"EogPluginSendByMail\"/>"
-       "</menu></menubar>"
-       "<popup name=\"ViewPopup\"><separator/>"
-        "<menuitem action=\"EogPluginSendByMail\"/><separator/>"
-        "</popup></ui>";
+static void send_by_mail_cb (GSimpleAction *simple,
+                            GVariant      *parameter,
+                            gpointer       user_data);
 
-static const GtkActionEntry action_entries[] =
-{
-       { "EogPluginSendByMail",
-         "mail-message-new",
-         N_("Send by Mail"),
-         NULL,
-         N_("Send the selected images by mail"),
-         G_CALLBACK (send_by_mail_cb) }
-};
 
 static void
 eog_send_by_mail_plugin_init (EogSendByMailPlugin *plugin)
 {
-       plugin->ui_action_group = NULL;
-       plugin->ui_menuitem_id = 0;
 }
 
 static void
 impl_activate (EogWindowActivatable *activatable)
 {
        EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (activatable);
-       GtkUIManager *manager;
-
-       manager = eog_window_get_ui_manager (plugin->window);
-
-       plugin->ui_action_group = gtk_action_group_new ("EogSendByMailPluginActions");
-
-       gtk_action_group_set_translation_domain (plugin->ui_action_group,
-                                                GETTEXT_PACKAGE);
-
-       gtk_action_group_add_actions (plugin->ui_action_group,
-                                     action_entries,
-                                     G_N_ELEMENTS (action_entries),
-                                     plugin->window);
-
-       gtk_ui_manager_insert_action_group (manager,
-                                           plugin->ui_action_group,
-                                           -1);
-
-       plugin->ui_menuitem_id = gtk_ui_manager_add_ui_from_string (manager,
-                                                                 ui_definition,
-                                                                 -1, NULL);
+       GMenu *model, *menu;
+       GMenuItem *item;
+       GSimpleAction *action;
+
+       model= eog_window_get_gear_menu_section (plugin->window,
+                                                "plugins-section");
+
+       g_return_if_fail (G_IS_MENU (model));
+
+       /* Setup and inject action */
+       action = g_simple_action_new (EOG_SEND_BY_MAIL_PLUGIN_ACTION, NULL);
+       g_signal_connect(action, "activate",
+                        G_CALLBACK (send_by_mail_cb), plugin->window);
+       g_action_map_add_action (G_ACTION_MAP (plugin->window),
+                                G_ACTION (action));
+       g_object_unref (action);
+
+       /* Append entry to the window's gear menu */
+       menu = g_menu_new ();
+       g_menu_append (menu, _("Send by Mail"),
+                      "win." EOG_SEND_BY_MAIL_PLUGIN_ACTION);
+
+       item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu));
+       g_menu_item_set_attribute (item, "id",
+                                  "s", EOG_SEND_BY_MAIL_PLUGIN_MENU_ID);
+       g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON,
+                                  "s", "mail-message-new");
+       g_menu_append_item (model, item);
+       g_object_unref (item);
+
+       g_object_unref (menu);
 }
 
 static void
 impl_deactivate        (EogWindowActivatable *activatable)
 {
        EogSendByMailPlugin *plugin = EOG_SEND_BY_MAIL_PLUGIN (activatable);
-       GtkUIManager *manager;
-
-       manager = eog_window_get_ui_manager (plugin->window);
-
-       gtk_ui_manager_remove_ui (manager,
-                                 plugin->ui_menuitem_id);
+       GMenu *menu;
+       GMenuModel *model;
+       gint i;
+
+       menu = eog_window_get_gear_menu_section (plugin->window,
+                                                "plugins-section");
+
+       g_return_if_fail (G_IS_MENU (menu));
+
+       /* Remove menu entry */
+       model = G_MENU_MODEL (menu);
+       for (i = 0; i < g_menu_model_get_n_items (model); i++) {
+               gchar *id;
+               if (g_menu_model_get_item_attribute (model, i, "id", "s", &id)) {
+                       const gboolean found =
+                               (g_strcmp0 (id, EOG_SEND_BY_MAIL_PLUGIN_MENU_ID) == 0);
+                       g_free (id);
+
+                       if (found) {
+                               g_menu_remove (menu, i);
+                               break;
+                       }
+               }
+       }
 
-       gtk_ui_manager_remove_action_group (manager,
-                                           plugin->ui_action_group);
-       plugin->ui_action_group = NULL;
-       plugin->ui_menuitem_id = 0;
+       /* Finally remove action */
+       g_action_map_remove_action (G_ACTION_MAP (plugin->window),
+                                   EOG_SEND_BY_MAIL_PLUGIN_ACTION);
 }
 
 static void
@@ -196,15 +208,20 @@ eog_window_activatable_iface_init (EogWindowActivatableInterface *iface)
 }
 
 static void
-send_by_mail_cb (GtkAction *action, EogWindow *window)
+send_by_mail_cb (GSimpleAction *simple,
+                GVariant      *parameter,
+                gpointer       user_data)
 {
+       EogWindow *window;
        GdkScreen *screen = NULL;
        GtkWidget *tview = NULL;
        GList *images = NULL, *image = NULL;
        GString *uri = NULL;
        gboolean first = TRUE;
 
-       g_return_if_fail (EOG_IS_WINDOW (window));
+       g_return_if_fail (EOG_IS_WINDOW (user_data));
+
+       window = EOG_WINDOW (user_data);
 
        if (gtk_widget_has_screen (GTK_WIDGET (window)))
                screen = gtk_widget_get_screen (GTK_WIDGET (window));
diff --git a/plugins/send-by-mail/eog-send-by-mail-plugin.h b/plugins/send-by-mail/eog-send-by-mail-plugin.h
index aa8c10a..a62aa2c 100644
--- a/plugins/send-by-mail/eog-send-by-mail-plugin.h
+++ b/plugins/send-by-mail/eog-send-by-mail-plugin.h
@@ -54,9 +54,6 @@ struct _EogSendByMailPlugin
        PeasExtensionBase parent_instance;
 
        EogWindow *window;
-       GtkActionGroup *ui_action_group;
-       guint           ui_menuitem_id;
-
 };
 
 /*
diff --git a/plugins/send-by-mail/send-by-mail.plugin.desktop.in 
b/plugins/send-by-mail/send-by-mail.plugin.desktop.in
index 541e27d..72ed8ba 100644
--- a/plugins/send-by-mail/send-by-mail.plugin.desktop.in
+++ b/plugins/send-by-mail/send-by-mail.plugin.desktop.in
@@ -1,8 +1,8 @@
 [Plugin]
 Module=send-by-mail
-IAge=2
+IAge=3
 _Name=Send By Mail
-Icon=mail-send
+Icon=mail-send-symbolic
 _Description=Sends an image attached to a new mail
 Authors=Felix Riemann <friemann gnome org>
 Copyright=Copyright © 2009 Felix Riemann


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