[eog-plugins] postr: Port to GAction
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog-plugins] postr: Port to GAction
- Date: Sun, 15 Feb 2015 16:29:09 +0000 (UTC)
commit 52f3f94817b312a01c32115528d8fe9538c9c026
Author: Felix Riemann <friemann gnome org>
Date: Sun Feb 15 17:27:54 2015 +0100
postr: Port to GAction
https://bugzilla.gnome.org/show_bug.cgi?id=743885
plugins/postr/eog-postr-plugin.c | 110 +++++++++++++++++++-------------
plugins/postr/eog-postr-plugin.h | 2 -
plugins/postr/postr.plugin.desktop.in | 2 +-
3 files changed, 66 insertions(+), 48 deletions(-)
---
diff --git a/plugins/postr/eog-postr-plugin.c b/plugins/postr/eog-postr-plugin.c
index 8159480..cf25485 100644
--- a/plugins/postr/eog-postr-plugin.c
+++ b/plugins/postr/eog-postr-plugin.c
@@ -12,7 +12,8 @@
#include <eog/eog-image.h>
#include <eog/eog-window-activatable.h>
-#define MENU_PATH "/MainMenu/ToolsMenu/ToolsOps_2"
+#define EOG_POSTR_PLUGIN_MENU_ID "EogPluginPostr"
+#define EOG_POSTR_PLUGIN_ACTION "upload-with-postr"
enum {
PROP_O,
@@ -28,13 +29,21 @@ G_DEFINE_DYNAMIC_TYPE_EXTENDED (EogPostrPlugin, eog_postr_plugin,
eog_window_activatable_iface_init))
static void
-postr_cb (GtkAction *action,
- EogWindow *window)
+postr_cb (GSimpleAction *simple,
+ GVariant *parameter,
+ gpointer user_data)
{
- GtkWidget *thumbview = eog_window_get_thumb_view (window);
+ EogWindow *window;
+ GtkWidget *thumbview;
GList *images, *i;
gchar *cmd = g_strdup ("postr ");
+ eog_debug(DEBUG_PLUGINS);
+
+ g_return_if_fail (EOG_IS_WINDOW (user_data));
+
+ window = EOG_WINDOW (user_data);
+ thumbview = eog_window_get_thumb_view (window);
images = eog_thumb_view_get_selected_images (EOG_THUMB_VIEW (thumbview));
for (i = g_list_first (images); i; i = i->next) {
@@ -55,23 +64,11 @@ postr_cb (GtkAction *action,
g_spawn_command_line_async (cmd, NULL);
}
-static const GtkActionEntry action_entries[] =
-{
- { "RunPostr",
- "postr",
- N_("Upload to Flickr"),
- NULL,
- N_("Upload your pictures to Flickr"),
- G_CALLBACK (postr_cb) }
-};
static void
eog_postr_plugin_init (EogPostrPlugin *plugin)
{
eog_debug_message (DEBUG_PLUGINS, "EogPostrPlugin initializing");
-
- plugin->ui_action_group = NULL;
- plugin->ui_id = 0;
}
@@ -94,55 +91,78 @@ static void
impl_activate (EogWindowActivatable *activatable)
{
EogPostrPlugin *plugin = EOG_POSTR_PLUGIN (activatable);
- GtkUIManager *manager;
+ GMenu *model, *menu;
+ GMenuItem *item;
+ GSimpleAction *action;
eog_debug (DEBUG_PLUGINS);
g_return_if_fail (plugin->window != NULL);
- manager = eog_window_get_ui_manager (plugin->window);
+ model= eog_window_get_gear_menu_section (plugin->window,
+ "plugins-section");
+
+ g_return_if_fail (G_IS_MENU (model));
- plugin->ui_action_group = gtk_action_group_new ("EogPostrPluginActions");
+ /* Setup and inject action */
+ action = g_simple_action_new (EOG_POSTR_PLUGIN_ACTION, NULL);
+ g_signal_connect(action, "activate",
+ G_CALLBACK (postr_cb), plugin->window);
+ g_action_map_add_action (G_ACTION_MAP (plugin->window),
+ G_ACTION (action));
+ g_object_unref (action);
- 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);
+ /* Append entry to the window's gear menu */
+ menu = g_menu_new ();
+ g_menu_append (menu, _("Upload to Flickr"),
+ "win." EOG_POSTR_PLUGIN_ACTION);
- gtk_ui_manager_insert_action_group (manager,
- plugin->ui_action_group,
- -1);
+ item = g_menu_item_new_section (NULL, G_MENU_MODEL (menu));
+ g_menu_item_set_attribute (item, "id",
+ "s", EOG_POSTR_PLUGIN_MENU_ID);
+ g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON,
+ "s", "postr");
+ g_menu_append_item (model, item);
+ g_object_unref (item);
- plugin->ui_id = gtk_ui_manager_new_merge_id (manager);
+ g_object_unref (menu);
- gtk_ui_manager_add_ui (manager,
- plugin->ui_id,
- MENU_PATH,
- "RunPostr",
- "RunPostr",
- GTK_UI_MANAGER_MENUITEM,
- FALSE);
}
static void
impl_deactivate (EogWindowActivatable *activatable)
{
EogPostrPlugin *plugin = EOG_POSTR_PLUGIN (activatable);
- GtkUIManager *manager;
+ GMenu *menu;
+ GMenuModel *model;
+ gint i;
eog_debug (DEBUG_PLUGINS);
- manager = eog_window_get_ui_manager (plugin->window);
-
- gtk_ui_manager_remove_ui (manager,
- plugin->ui_id);
+ 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_POSTR_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_id = 0;
+ /* Finally remove action */
+ g_action_map_remove_action (G_ACTION_MAP (plugin->window),
+ EOG_POSTR_PLUGIN_ACTION);
}
static void
diff --git a/plugins/postr/eog-postr-plugin.h b/plugins/postr/eog-postr-plugin.h
index 7b51b6a..1b0fe87 100644
--- a/plugins/postr/eog-postr-plugin.h
+++ b/plugins/postr/eog-postr-plugin.h
@@ -33,8 +33,6 @@ struct _EogPostrPlugin
PeasExtensionBase parent_instance;
EogWindow *window;
- GtkActionGroup *ui_action_group;
- guint ui_id;
};
/*
diff --git a/plugins/postr/postr.plugin.desktop.in b/plugins/postr/postr.plugin.desktop.in
index a85c7f4..fe32a4d 100644
--- a/plugins/postr/postr.plugin.desktop.in
+++ b/plugins/postr/postr.plugin.desktop.in
@@ -1,6 +1,6 @@
[Plugin]
Module=postr
-IAge=2
+IAge=3
_Name=Flickr Uploader
Icon=postr
_Description=Upload your pictures to Flickr
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]