[gnome-panel] don't use deprecated GtkAction and GtkActionGroup



commit 138a674c2788bfe153f461f85df28ef1dce09ee1
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sat Jul 5 15:01:54 2014 +0300

    don't use deprecated GtkAction and GtkActionGroup

 applets/clock/clock-menu.xml                |   21 +++-
 applets/clock/clock.c                       |   69 +++++++------
 applets/fish/fish-menu.xml                  |    7 +-
 applets/fish/fish.c                         |   39 ++++---
 applets/wncklet/window-list-menu.xml        |    8 +-
 applets/wncklet/window-list.c               |   43 ++++----
 applets/wncklet/workspace-switcher-menu.xml |   10 +-
 applets/wncklet/workspace-switcher.c        |   43 ++++----
 libpanel-applet/panel-applet.c              |  152 +++++++++++++++------------
 libpanel-applet/panel-applet.h              |    9 +-
 libpanel-applet/test-dbus-applet.c          |   58 ++++++----
 11 files changed, 264 insertions(+), 195 deletions(-)
---
diff --git a/applets/clock/clock-menu.xml b/applets/clock/clock-menu.xml
index 2b44c97..27baa15 100644
--- a/applets/clock/clock-menu.xml
+++ b/applets/clock/clock-menu.xml
@@ -1,5 +1,16 @@
-<menuitem name="Clock Copy Time Item" action="ClockCopyTime" />
-<separator/>
-<menuitem name="Clock Configure Item" action="ClockConfig" />
-<menuitem name="Clock Preferences Item" action="ClockPreferences" />
-
+<section>
+       <item>
+               <attribute name="label" translatable="yes">Copy Date and _Time</attribute>
+               <attribute name="action">clock.copy-time</attribute>
+       </item>
+</section>
+<section>
+       <item>
+               <attribute name="label" translatable="yes">Ad_just Date &amp; Time</attribute>
+               <attribute name="action">clock.config</attribute>
+       </item>
+       <item>
+               <attribute name="label" translatable="yes">_Preferences</attribute>
+               <attribute name="action">clock.preferences</attribute>
+       </item>
+</section>
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 5eb23d3..a756de1 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -150,8 +150,9 @@ static void  update_panel_weather (ClockData *cd);
 static void set_atk_name_description (GtkWidget *widget,
                                       const char *name,
                                       const char *desc);
-static void verb_display_properties_dialog (GtkAction  *action,
-                                            ClockData  *cd);
+static void verb_display_properties_dialog (GSimpleAction *action,
+                                            GVariant      *parameter,
+                                            gpointer       user_data);
 
 static void display_properties_dialog (ClockData  *cd,
                                        gboolean    start_in_locations_page);
@@ -1051,9 +1052,11 @@ panel_button_change_pixel_size (GtkWidget     *widget,
 }
 
 static void
-copy_time (GtkAction *action,
-          ClockData *cd)
+copy_time (GSimpleAction *action,
+           GVariant      *parameter,
+          gpointer       user_data)
 {
+        ClockData *cd = (ClockData *) user_data;
        const char *time;
 
         time = gnome_wall_clock_get_clock (cd->wall_clock);
@@ -1127,23 +1130,18 @@ run_time_settings (GtkWidget *unused, ClockData *cd)
 }
 
 static void
-config_date (GtkAction *action,
-             ClockData *cd)
+config_date (GSimpleAction *action,
+             GVariant      *parameter,
+             gpointer       user_data)
 {
+        ClockData *cd = (ClockData *) user_data;
        run_time_settings (NULL, cd);
 }
 
-/* current timestamp */
-static const GtkActionEntry clock_menu_actions [] = {
-        { "ClockPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"),
-          NULL, NULL,
-          G_CALLBACK (verb_display_properties_dialog) },
-        { "ClockCopyTime", GTK_STOCK_COPY, N_("Copy Date and _Time"),
-          NULL, NULL,
-          G_CALLBACK (copy_time) },
-        { "ClockConfig", GTK_STOCK_PREFERENCES, N_("Ad_just Date & Time"),
-          NULL, NULL,
-          G_CALLBACK (config_date) }
+static const GActionEntry clock_menu_actions [] = {
+        { "preferences", verb_display_properties_dialog, NULL, NULL, NULL },
+        { "copy-time",   copy_time,                      NULL, NULL, NULL },
+        { "config",      config_date,                    NULL, NULL, NULL }
 };
 
 static void
@@ -1304,9 +1302,9 @@ load_cities (ClockData *cd)
 static gboolean
 fill_clock_applet (PanelApplet *applet)
 {
-       ClockData      *cd;
-        GtkActionGroup *action_group;
-        GtkAction      *action;
+       ClockData          *cd;
+        GSimpleActionGroup *action_group;
+        GAction            *action;
 
        panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
 
@@ -1357,24 +1355,27 @@ fill_clock_applet (PanelApplet *applet)
        panel_applet_set_background_widget (PANEL_APPLET (cd->applet),
                                            GTK_WIDGET (cd->applet));
 
-        action_group = gtk_action_group_new ("ClockApplet Menu Actions");
-        gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
-        gtk_action_group_add_actions (action_group,
-                                      clock_menu_actions,
-                                      G_N_ELEMENTS (clock_menu_actions),
-                                      cd);
+        action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        clock_menu_actions,
+                                        G_N_ELEMENTS (clock_menu_actions),
+                                        cd);
        panel_applet_setup_menu_from_resource (PANEL_APPLET (cd->applet),
                                               CLOCK_RESOURCE_PATH "clock-menu.xml",
-                                              action_group);
+                                              action_group,
+                                              GETTEXT_PACKAGE);
 
-       action = gtk_action_group_get_action (action_group, "ClockPreferences");
+        gtk_widget_insert_action_group (GTK_WIDGET (applet), "clock",
+                                       G_ACTION_GROUP (action_group));
+
+       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
        g_object_bind_property (cd->applet, "locked-down",
-                               action, "visible",
+                               action, "enabled",
                                G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
 
-       action = gtk_action_group_get_action (action_group, "ClockConfig");
+       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "config");
        g_object_bind_property (cd->applet, "locked-down",
-                               action, "visible",
+                               action, "enabled",
                                G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
         g_object_unref (action_group);
 
@@ -2078,9 +2079,11 @@ display_properties_dialog (ClockData *cd, gboolean start_in_locations_page)
 }
 
 static void
-verb_display_properties_dialog (GtkAction *action,
-                                ClockData *cd)
+verb_display_properties_dialog (GSimpleAction *action,
+                                GVariant      *parameter,
+                                gpointer       user_data)
 {
+        ClockData *cd = (ClockData *) user_data;
         display_properties_dialog (cd, FALSE);
 }
 
diff --git a/applets/fish/fish-menu.xml b/applets/fish/fish-menu.xml
index bf9aa7e..9af7059 100644
--- a/applets/fish/fish-menu.xml
+++ b/applets/fish/fish-menu.xml
@@ -1 +1,6 @@
-<menuitem name="Fish Preferences Item" action="FishPreferences"/>
+<section>
+       <item>
+               <attribute name="label" translatable="yes">Preferences</attribute>
+               <attribute name="action">fish.preferences</attribute>
+       </item>
+</section>
diff --git a/applets/fish/fish.c b/applets/fish/fish.c
index 58732af..684b648 100644
--- a/applets/fish/fish.c
+++ b/applets/fish/fish.c
@@ -259,9 +259,11 @@ handle_response (GtkWidget  *widget,
 }
 
 static void 
-display_preferences_dialog (GtkAction  *action,
-                           FishApplet *fish)
+display_preferences_dialog (GSimpleAction *action,
+                            GVariant      *parameter,
+                            gpointer       user_data)
 {
+       FishApplet *fish = FISH_APPLET (user_data);
        GtkBuilder *builder;
        GtkWidget  *box;
        GtkWidget  *name_entry;
@@ -1301,10 +1303,8 @@ setup_fish_widget (FishApplet *fish)
        gtk_widget_show_all (widget);
 }
 
-static const GtkActionEntry fish_menu_verbs [] = {
-       { "FishPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"),
-         NULL, NULL,
-         G_CALLBACK (display_preferences_dialog) }
+static const GActionEntry fish_menu_actions [] = {
+       { "preferences", display_preferences_dialog, NULL, NULL, NULL }
 };
 
 static void
@@ -1427,9 +1427,9 @@ fish_applet_settings_changed (GSettings  *settings,
 static gboolean
 fish_applet_fill (FishApplet *fish)
 {
-       PanelApplet    *applet = (PanelApplet *) fish;
-       GtkActionGroup *action_group;
-       GtkAction      *action;
+       PanelApplet        *applet = PANEL_APPLET (fish);
+       GSimpleActionGroup *action_group;
+       GAction            *action;
 
        fish->orientation = panel_applet_get_orient (applet);
 
@@ -1441,19 +1441,22 @@ fish_applet_fill (FishApplet *fish)
        /* NULL means we will update for all settings */
        fish_applet_settings_changed (fish->settings, NULL, fish);
 
-       action_group = gtk_action_group_new ("Fish Applet Actions");
-       gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
-       gtk_action_group_add_actions (action_group,
-                                     fish_menu_verbs,
-                                     G_N_ELEMENTS (fish_menu_verbs),
-                                     fish);
+       action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        fish_menu_actions,
+                                        G_N_ELEMENTS (fish_menu_actions),
+                                        fish);
        panel_applet_setup_menu_from_resource (applet,
                                               FISH_RESOURCE_PATH "fish-menu.xml",
-                                              action_group);
+                                              action_group,
+                                              GETTEXT_PACKAGE);
 
-       action = gtk_action_group_get_action (action_group, "FishPreferences");
+       gtk_widget_insert_action_group (GTK_WIDGET (applet), "fish",
+                                       G_ACTION_GROUP (action_group));
+
+       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
        g_object_bind_property (applet, "locked-down",
-                               action, "visible",
+                               action, "enabled",
                                G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
 
        g_object_unref (action_group);
diff --git a/applets/wncklet/window-list-menu.xml b/applets/wncklet/window-list-menu.xml
index 17109ec..f6c04b6 100644
--- a/applets/wncklet/window-list-menu.xml
+++ b/applets/wncklet/window-list-menu.xml
@@ -1,2 +1,6 @@
-<menuitem name="Tasklist Preferences Item" action="TasklistPreferences" />
-
+<section>
+       <item>
+               <attribute name="label" translatable="yes">_Preferences</attribute>
+               <attribute name="action">tasklist.preferences</attribute>
+       </item>
+</section>
diff --git a/applets/wncklet/window-list.c b/applets/wncklet/window-list.c
index cd114c6..99bb9b1 100644
--- a/applets/wncklet/window-list.c
+++ b/applets/wncklet/window-list.c
@@ -52,8 +52,9 @@ typedef struct {
         GSettings *settings;
 } TasklistData;
 
-static void display_properties_dialog (GtkAction    *action,
-                                      TasklistData *tasklist);
+static void display_properties_dialog (GSimpleAction *action,
+                                       GVariant      *parameter,
+                                       gpointer       user_data);
 
 static void
 tasklist_update (TasklistData *tasklist)
@@ -153,10 +154,8 @@ destroy_tasklist(GtkWidget * widget, TasklistData *tasklist)
         g_free (tasklist);
 }
 
-static const GtkActionEntry tasklist_menu_actions [] = {
-       { "TasklistPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"),
-         NULL, NULL,
-         G_CALLBACK (display_properties_dialog) }
+static const GActionEntry tasklist_menu_actions [] = {
+        { "preferences", display_properties_dialog, NULL, NULL, NULL },
 };
 
 static void
@@ -354,8 +353,8 @@ gboolean
 window_list_applet_fill (PanelApplet *applet)
 {
        TasklistData *tasklist;
-       GtkActionGroup *action_group;
-       GtkAction *action;
+       GSimpleActionGroup *action_group;
+       GAction *action;
 
        tasklist = g_new0 (TasklistData, 1);
 
@@ -422,19 +421,22 @@ window_list_applet_fill (PanelApplet *applet)
        panel_applet_set_background_widget (PANEL_APPLET (tasklist->applet),
                                            GTK_WIDGET (tasklist->applet));
 
-       action_group = gtk_action_group_new ("Tasklist Applet Actions");
-       gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
-       gtk_action_group_add_actions (action_group,
-                                     tasklist_menu_actions,
-                                     G_N_ELEMENTS (tasklist_menu_actions),
-                                     tasklist);
+       action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        tasklist_menu_actions,
+                                        G_N_ELEMENTS (tasklist_menu_actions),
+                                        tasklist);
        panel_applet_setup_menu_from_resource (PANEL_APPLET (tasklist->applet),
                                               WNCKLET_RESOURCE_PATH "window-list-menu.xml",
-                                              action_group);
+                                              action_group,
+                                              GETTEXT_PACKAGE);
 
-       action = gtk_action_group_get_action (action_group, "TasklistPreferences");
+       gtk_widget_insert_action_group (GTK_WIDGET (applet), "tasklist",
+                                       G_ACTION_GROUP (action_group));
+
+       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
        g_object_bind_property (tasklist->applet, "locked-down",
-                               action, "visible",
+                               action, "enabled",
                                G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
 
        g_object_unref (action_group);
@@ -577,9 +579,12 @@ setup_dialog (GtkBuilder   *builder,
 
 
 static void 
-display_properties_dialog (GtkAction    *action,
-                          TasklistData *tasklist)
+display_properties_dialog (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
 {
+       TasklistData *tasklist = (TasklistData *) user_data;
+
        if (tasklist->properties_dialog == NULL) {
                GtkBuilder *builder;
 
diff --git a/applets/wncklet/workspace-switcher-menu.xml b/applets/wncklet/workspace-switcher-menu.xml
index c500c22..090f25a 100644
--- a/applets/wncklet/workspace-switcher-menu.xml
+++ b/applets/wncklet/workspace-switcher-menu.xml
@@ -1,4 +1,6 @@
-<menuitem name="Pager Preferences Item" action="PagerPreferences" />
-
-
-
+<section>
+       <item>
+               <attribute name="label" translatable="yes">_Preferences</attribute>
+               <attribute name="action">ws.preferences</attribute>
+       </item>
+</section>
diff --git a/applets/wncklet/workspace-switcher.c b/applets/wncklet/workspace-switcher.c
index 8b86fa4..9676663 100644
--- a/applets/wncklet/workspace-switcher.c
+++ b/applets/wncklet/workspace-switcher.c
@@ -66,8 +66,9 @@ typedef struct {
         GSettings *settings;
 } PagerData;
 
-static void display_properties_dialog (GtkAction *action,
-                                      PagerData *pager);
+static void display_properties_dialog (GSimpleAction *action,
+                                       GVariant      *parameter,
+                                       gpointer       user_data);
 
 static void
 pager_update (PagerData *pager)
@@ -214,10 +215,8 @@ destroy_pager(GtkWidget * widget, PagerData *pager)
        g_free (pager);
 }
 
-static const GtkActionEntry pager_menu_actions [] = {
-        { "PagerPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"),
-          NULL, NULL,
-          G_CALLBACK (display_properties_dialog) }
+static const GActionEntry pager_menu_actions [] = {
+        { "preferences", display_properties_dialog, NULL, NULL, NULL },
 };
 
 static void
@@ -305,8 +304,8 @@ gboolean
 workspace_switcher_applet_fill (PanelApplet *applet)
 {
        PagerData *pager;
-        GtkActionGroup *action_group;
-       GtkAction *action;
+        GSimpleActionGroup *action_group;
+       GAction *action;
        gboolean display_names;
 
        pager = g_new0 (PagerData, 1);
@@ -375,19 +374,22 @@ workspace_switcher_applet_fill (PanelApplet *applet)
        panel_applet_set_background_widget (PANEL_APPLET (pager->applet),
                                            GTK_WIDGET (pager->applet));
 
-        action_group = gtk_action_group_new ("WorkspaceSwitcher Applet Actions");
-        gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
-        gtk_action_group_add_actions (action_group,
-                                      pager_menu_actions,
-                                      G_N_ELEMENTS (pager_menu_actions),
-                                      pager);
+        action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        pager_menu_actions,
+                                        G_N_ELEMENTS (pager_menu_actions),
+                                        pager);
        panel_applet_setup_menu_from_resource (PANEL_APPLET (pager->applet),
                                               WNCKLET_RESOURCE_PATH "workspace-switcher-menu.xml",
-                                              action_group);
+                                              action_group,
+                                              GETTEXT_PACKAGE);
 
-       action = gtk_action_group_get_action (action_group, "PagerPreferences");
+        gtk_widget_insert_action_group (GTK_WIDGET (applet), "ws",
+                                       G_ACTION_GROUP (action_group));
+
+       action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
        g_object_bind_property (pager->applet, "locked-down",
-                               action, "visible",
+                               action, "enabled",
                                G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
 
         g_object_unref (action_group);
@@ -773,9 +775,12 @@ setup_dialog (GtkBuilder *builder,
 }
 
 static void 
-display_properties_dialog (GtkAction *action,
-                          PagerData *pager)
+display_properties_dialog (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
 {
+        PagerData *pager = (PagerData *) user_data;
+
        if (pager->properties_dialog == NULL) {
                GtkBuilder *builder;
 
diff --git a/libpanel-applet/panel-applet.c b/libpanel-applet/panel-applet.c
index 76da741..40f4442 100644
--- a/libpanel-applet/panel-applet.c
+++ b/libpanel-applet/panel-applet.c
@@ -90,9 +90,9 @@ struct _PanelAppletPrivate {
        char              *settings_path;
        char              *prefs_key;
 
-       GtkUIManager      *ui_manager;
-       GtkActionGroup    *applet_action_group;
-       GtkActionGroup    *panel_action_group;
+       GtkBuilder         *builder;
+       GSimpleActionGroup *applet_action_group;
+       GSimpleActionGroup *panel_action_group;
 
        PanelAppletFlags   flags;
        PanelAppletOrient  orient;
@@ -137,36 +137,38 @@ enum {
 };
 
 static void       panel_applet_handle_background   (PanelApplet       *applet);
-static GtkAction *panel_applet_menu_get_action     (PanelApplet       *applet,
+static GAction   *panel_applet_menu_get_action     (PanelApplet       *applet,
                                                    const gchar       *action);
 static void       panel_applet_menu_update_actions (PanelApplet       *applet);
-static void       panel_applet_menu_cmd_remove     (GtkAction         *action,
-                                                   PanelApplet       *applet);
-static void       panel_applet_menu_cmd_move       (GtkAction         *action,
-                                                   PanelApplet       *applet);
+static void       panel_applet_menu_cmd_remove     (GSimpleAction     *action,
+                                                   GVariant      *parameter,
+                                                   gpointer       user_data);
+static void       panel_applet_menu_cmd_move       (GSimpleAction     *action,
+                                                   GVariant      *parameter,
+                                                   gpointer       user_data);
 static void       panel_applet_register_object     (PanelApplet       *applet);
 
 static const gchar panel_menu_ui[] =
-       "<ui>\n"
-       "  <popup name=\"PanelAppletPopup\" action=\"PopupAction\">\n"
-       "    <placeholder name=\"AppletItems\"/>\n"
-       "  </popup>\n"
-       "  <popup name=\"PanelAppletEditPopup\" action=\"PopupEditAction\">\n"
-       "    <menuitem name=\"MoveItem\" action=\"Move\"/>\n"
-       "    <menuitem name=\"RemoveItem\" action=\"Remove\"/>\n"
-       "  </popup>\n"
-       "</ui>\n";
-
-static const GtkActionEntry menu_entries[] = {
-       { "PopupAction", NULL, "Popup Action",
-         NULL, NULL,
-         NULL },
-       { "Remove", GTK_STOCK_REMOVE, N_("_Remove From Panel"),
-         NULL, NULL,
-         G_CALLBACK (panel_applet_menu_cmd_remove) },
-       { "Move", NULL, N_("_Move"),
-         NULL, NULL,
-         G_CALLBACK (panel_applet_menu_cmd_move) }
+       "<interface>\n"
+       " <menu id=\"panel-applet-popup\">"
+       " </menu>"
+       " <menu id=\"panel-applet-edit-popup\">"
+       "   <section>"
+       "     <item>"
+       "       <attribute name=\"label\" translatable=\"no\">%s</attribute>"
+       "       <attribute name=\"action\">libpanel-applet.remove</attribute>"
+       "     </item>"
+       "     <item>"
+       "       <attribute name=\"label\" translatable=\"no\">%s</attribute>"
+       "       <attribute name=\"action\">libpanel-applet.move</attribute>"
+       "     </item>"
+       "   </section>"
+       " </menu>"
+       "</interface>\n";
+
+static const GActionEntry menu_entries[] = {
+       { "remove", panel_applet_menu_cmd_remove, NULL, NULL, NULL },
+       { "move",   panel_applet_menu_cmd_move,   NULL, NULL, NULL }
 };
 
 G_DEFINE_TYPE (PanelApplet, panel_applet, GTK_TYPE_EVENT_BOX)
@@ -860,11 +862,12 @@ panel_applet_request_focus (PanelApplet    *applet,
                    &xev);
 }
 
-static GtkAction *
+static GAction *
 panel_applet_menu_get_action (PanelApplet *applet,
                              const gchar *action)
 {
-       return gtk_action_group_get_action (applet->priv->panel_action_group, action);
+       return g_action_map_lookup_action (G_ACTION_MAP (applet->priv->panel_action_group),
+                                          action);
 }
 
 static void
@@ -873,17 +876,19 @@ panel_applet_menu_update_actions (PanelApplet *applet)
        gboolean locked_down = applet->priv->locked_down;
 
        g_object_set (panel_applet_menu_get_action (applet, "Move"),
-                     "visible", !locked_down,
+                     "enabled", !locked_down,
                      NULL);
        g_object_set (panel_applet_menu_get_action (applet, "Remove"),
-                     "visible", !locked_down,
+                     "enabled", !locked_down,
                      NULL);
 }
 
 static void
-panel_applet_menu_cmd_remove (GtkAction   *action,
-                             PanelApplet *applet)
+panel_applet_menu_cmd_remove (GSimpleAction *action,
+                             GVariant      *parameter,
+                             gpointer       user_data)
 {
+       PanelApplet *applet = PANEL_APPLET (user_data);
        GError *error = NULL;
 
        if (!applet->priv->connection)
@@ -903,9 +908,11 @@ panel_applet_menu_cmd_remove (GtkAction   *action,
 }
 
 static void
-panel_applet_menu_cmd_move (GtkAction   *action,
-                           PanelApplet *applet)
+panel_applet_menu_cmd_move (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
 {
+       PanelApplet *applet = PANEL_APPLET (user_data);
        GError *error = NULL;
 
        if (!applet->priv->connection)
@@ -940,7 +947,8 @@ panel_applet_menu_cmd_move (GtkAction   *action,
 void
 panel_applet_setup_menu (PanelApplet    *applet,
                         const gchar    *xml,
-                        GtkActionGroup *action_group)
+                        GSimpleActionGroup *action_group,
+                        const gchar        *translation_domain)
 {
        gchar  *new_xml;
        GError *error = NULL;
@@ -951,16 +959,14 @@ panel_applet_setup_menu (PanelApplet    *applet,
        if (applet->priv->applet_action_group)
                return;
 
+       gtk_builder_set_translation_domain (applet->priv->builder, translation_domain);
+
        applet->priv->applet_action_group = g_object_ref (action_group);
-       gtk_ui_manager_insert_action_group (applet->priv->ui_manager,
-                                           action_group, 0);
 
-       new_xml = g_strdup_printf ("<ui><popup name=\"PanelAppletPopup\" action=\"AppletItems\">"
-                                  "<placeholder name=\"AppletItems\">%s\n</placeholder>\n"
-                                  "</popup></ui>\n", xml);
-       gtk_ui_manager_add_ui_from_string (applet->priv->ui_manager, new_xml, -1, &error);
+       new_xml = g_strdup_printf ("<interface><menu id=\"panel-applet-popup\">%s</menu></interface>\n", xml);
+       gtk_builder_add_from_string (applet->priv->builder, new_xml, -1, &error);
        g_free (new_xml);
-       gtk_ui_manager_ensure_update (applet->priv->ui_manager);
+
        if (error) {
                g_warning ("Error merging menus: %s\n", error->message);
                g_error_free (error);
@@ -984,13 +990,14 @@ panel_applet_setup_menu (PanelApplet    *applet,
 void
 panel_applet_setup_menu_from_file (PanelApplet    *applet,
                                   const gchar    *filename,
-                                  GtkActionGroup *action_group)
+                                  GSimpleActionGroup *action_group,
+                                  const gchar        *translation_domain)
 {
        gchar  *xml = NULL;
        GError *error = NULL;
 
        if (g_file_get_contents (filename, &xml, NULL, &error)) {
-               panel_applet_setup_menu (applet, xml, action_group);
+               panel_applet_setup_menu (applet, xml, action_group, translation_domain);
        } else {
                g_warning ("%s", error->message);
                g_error_free (error);
@@ -1018,7 +1025,8 @@ panel_applet_setup_menu_from_file (PanelApplet    *applet,
 void
 panel_applet_setup_menu_from_resource (PanelApplet    *applet,
                                       const gchar    *resource_path,
-                                      GtkActionGroup *action_group)
+                                      GSimpleActionGroup *action_group,
+                                      const gchar        *translation_domain)
 {
        GBytes *bytes;
        GError *error = NULL;
@@ -1030,7 +1038,8 @@ panel_applet_setup_menu_from_resource (PanelApplet    *applet,
        if (bytes) {
                panel_applet_setup_menu (applet,
                                         g_bytes_get_data (bytes, NULL),
-                                        action_group);
+                                        action_group,
+                                        translation_domain);
        } else {
                g_warning ("%s", error->message);
                g_error_free (error);
@@ -1074,9 +1083,9 @@ panel_applet_finalize (GObject *object)
                applet->priv->panel_action_group = NULL;
        }
 
-       if (applet->priv->ui_manager) {
-               g_object_unref (applet->priv->ui_manager);
-               applet->priv->ui_manager = NULL;
+       if (applet->priv->builder) {
+               g_object_unref (applet->priv->builder);
+               applet->priv->builder = NULL;
        }
 
        g_free (applet->priv->size_hints);
@@ -1197,11 +1206,14 @@ panel_applet_menu_popup (PanelApplet *applet,
                         guint32      time)
 {
        GtkWidget *menu;
+       GMenu     *gmenu;
        GList     *children, *l;
        gboolean   visible = FALSE;
 
-       menu = gtk_ui_manager_get_widget (applet->priv->ui_manager,
-                                         "/PanelAppletPopup");
+       gmenu = G_MENU (gtk_builder_get_object (applet->priv->builder, "panel-applet-popup"));
+       menu = gtk_menu_new_from_model (G_MENU_MODEL (gmenu));
+
+       gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (applet), NULL);
 
        children = gtk_container_get_children (GTK_CONTAINER (menu));
        for (l = children; l != NULL; l = l->next) {
@@ -1227,12 +1239,16 @@ panel_applet_edit_menu_popup (PanelApplet *applet,
                              guint32      time)
 {
        GtkWidget *menu;
+       GMenu     *gmenu;
 
        if (applet->priv->locked_down)
                return;
 
-       menu = gtk_ui_manager_get_widget (applet->priv->ui_manager,
-                                         "/PanelAppletEditPopup");
+       gmenu = G_MENU (gtk_builder_get_object (applet->priv->builder, "panel-applet-edit-popup"));
+       menu = gtk_menu_new_from_model (G_MENU_MODEL (gmenu));
+
+       gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (applet), NULL);
+
        gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (GTK_WIDGET (applet)));
        gtk_menu_popup (GTK_MENU (menu),
                        NULL, NULL,
@@ -2046,18 +2062,20 @@ panel_applet_init (PanelApplet *applet)
 
        applet->priv->client = gconf_client_get_default ();
 
-       applet->priv->panel_action_group = gtk_action_group_new ("PanelActions");
-       gtk_action_group_set_translation_domain (applet->priv->panel_action_group, GETTEXT_PACKAGE);
-       gtk_action_group_add_actions (applet->priv->panel_action_group,
-                                     menu_entries,
-                                     G_N_ELEMENTS (menu_entries),
-                                     applet);
-
-       applet->priv->ui_manager = gtk_ui_manager_new ();
-       gtk_ui_manager_insert_action_group (applet->priv->ui_manager,
-                                           applet->priv->panel_action_group, 1);
-       gtk_ui_manager_add_ui_from_string (applet->priv->ui_manager,
-                                          panel_menu_ui, -1, NULL);
+       applet->priv->panel_action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (applet->priv->panel_action_group),
+                                        menu_entries,
+                                        G_N_ELEMENTS (menu_entries),
+                                        applet);
+
+       applet->priv->builder = gtk_builder_new ();
+
+       gchar *xml = g_strdup_printf (panel_menu_ui, N_("_Remove From Panel"), N_("_Move"));
+       gtk_builder_add_from_string (applet->priv->builder, xml, -1, NULL);
+       g_free (xml);
+
+       gtk_widget_insert_action_group (GTK_WIDGET (applet), "libpanel-applet",
+                                       G_ACTION_GROUP (applet->priv->panel_action_group));
 
        applet->priv->plug = gtk_plug_new (0);
        g_signal_connect_swapped (G_OBJECT (applet->priv->plug), "embedded",
diff --git a/libpanel-applet/panel-applet.h b/libpanel-applet/panel-applet.h
index d4717a0..ff5e8ce 100644
--- a/libpanel-applet/panel-applet.h
+++ b/libpanel-applet/panel-applet.h
@@ -164,13 +164,16 @@ void               panel_applet_request_focus        (PanelApplet  *applet,
 
 void               panel_applet_setup_menu           (PanelApplet        *applet,
                                                      const gchar        *xml,
-                                                     GtkActionGroup     *action_group);
+                                                     GSimpleActionGroup *action_group,
+                                                     const gchar        *translation_domain);
 void               panel_applet_setup_menu_from_file (PanelApplet        *applet,
                                                      const gchar        *filename,
-                                                     GtkActionGroup     *action_group);
+                                                     GSimpleActionGroup *action_group,
+                                                     const gchar        *translation_domain);
 void               panel_applet_setup_menu_from_resource (PanelApplet    *applet,
                                                          const gchar    *resource_path,
-                                                         GtkActionGroup *action_group);
+                                                         GSimpleActionGroup *action_group,
+                                                         const gchar        *translation_domain);
 
 int                panel_applet_factory_main          (const gchar               *factory_id,
                                                       GType                       applet_type,
diff --git a/libpanel-applet/test-dbus-applet.c b/libpanel-applet/test-dbus-applet.c
index e0a4991..7d19d00 100644
--- a/libpanel-applet/test-dbus-applet.c
+++ b/libpanel-applet/test-dbus-applet.c
@@ -4,28 +4,34 @@
 #include "panel-applet.h"
 
 static void
-test_applet_on_do (GtkAction *action,
-                  gpointer   user_data)
+test_applet_on_do (GSimpleAction *action,
+                   GVariant      *parameter,
+                   gpointer       user_data)
 {
-        g_message ("%s called\n", gtk_action_get_name (action));
+       g_message ("%s called\n", g_action_get_name (G_ACTION (action)));
 }
 
-static const GtkActionEntry test_applet_menu_actions[] = {
-       { "TestAppletDo1", NULL, "TestAppletDo1",
-         NULL, NULL,
-         G_CALLBACK (test_applet_on_do) },
-       { "TestAppletDo2", NULL, "TestAppletDo2",
-         NULL, NULL,
-         G_CALLBACK (test_applet_on_do) },
-       { "TestAppletDo3", NULL, "TestAppletDo3",
-         NULL, NULL,
-         G_CALLBACK (test_applet_on_do) }
+static const GActionEntry test_applet_menu_actions [] = {
+       { "test-applet-do-1", test_applet_on_do, NULL, NULL, NULL },
+       { "test-applet-do-2", test_applet_on_do, NULL, NULL, NULL },
+       { "test-applet-do-3", test_applet_on_do, NULL, NULL, NULL }
 };
 
-static const char test_applet_menu_xml[] =
-       "<menuitem name=\"Test Item 1\" action=\"TestAppletDo1\" />\n"
-       "<menuitem name=\"Test Item 2\" action=\"TestAppletDo2\" />\n"
-       "<menuitem name=\"Test Item 3\" action=\"TestAppletDo3\" />\n";
+static const gchar test_applet_menu_xml[] =
+       "<section>"
+       "  <item>"
+       "    <attribute name=\"label\" translatable=\"yes\">Test Item 1</attribute>"
+       "    <attribute name=\"action\">test.test-applet-do-1</attribute>"
+       "  </item>"
+       "  <item>"
+       "     <attribute name=\"label\" translatable=\"yes\">Test Item 2</attribute>"
+       "     <attribute name=\"action\">test.test-applet-do-2</attribute>"
+       "  </item>"
+       "  <item>"
+       "     <attribute name=\"label\" translatable=\"yes\">Test Item 3</attribute>"
+       "     <attribute name=\"action\">test.test-applet-do-3</attribute>"
+       "  </item>"
+       "</section>";
 
 typedef struct _TestApplet      TestApplet;
 typedef struct _TestAppletClass TestAppletClass;
@@ -122,7 +128,7 @@ test_applet_handle_background_change (TestApplet                *applet,
 static gboolean
 test_applet_fill (TestApplet *applet)
 {
-       GtkActionGroup *action_group;
+       GSimpleActionGroup *action_group;
 
        applet->label = gtk_label_new (NULL);
 
@@ -137,15 +143,19 @@ test_applet_fill (TestApplet *applet)
                                          panel_applet_get_orient (PANEL_APPLET (applet)),
                                          NULL);
 
-       action_group = gtk_action_group_new ("TestAppletActions");
-       gtk_action_group_add_actions (action_group,
-                                     test_applet_menu_actions,
-                                     G_N_ELEMENTS (test_applet_menu_actions),
-                                     applet);
+       action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        test_applet_menu_actions,
+                                        G_N_ELEMENTS (test_applet_menu_actions),
+                                        applet);
+
+       gtk_widget_insert_action_group (GTK_WIDGET (applet), "test",
+                                       G_ACTION_GROUP (action_group));
 
        panel_applet_setup_menu (PANEL_APPLET (applet),
                                 test_applet_menu_xml,
-                                action_group);
+                                action_group,
+                                GETTEXT_PACKAGE);
        g_object_unref (action_group);
 
        gtk_widget_set_tooltip_text (GTK_WIDGET (applet), "Hello Tip");


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