aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/idoprogressmenuitem.c129
1 files changed, 57 insertions, 72 deletions
diff --git a/src/idoprogressmenuitem.c b/src/idoprogressmenuitem.c
index 004682e..821d0a6 100644
--- a/src/idoprogressmenuitem.c
+++ b/src/idoprogressmenuitem.c
@@ -1,19 +1,19 @@
/*
- * Copyright 2013 Canonical Ltd.
+ * Copyright 2023 Robert Tari
*
* Authors:
- * Charles Kerr <charles.kerr@canonical.com>
+ * Robert Tari <robert@tari.in>
*
- * This program is free software: you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 3, as published
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
* by the Free Software Foundation.
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranties of
- * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along
+ * You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -21,85 +21,70 @@
#include "idobasicmenuitem.h"
#include "idoactionhelper.h"
-static void
-on_progress_action_state_changed (IdoActionHelper * helper,
- GVariant * state,
- gpointer unused G_GNUC_UNUSED)
+static void onActivate (GtkMenuItem *item, gpointer pData)
{
- IdoBasicMenuItem * ido_menu_item;
- char * str;
-
- ido_menu_item = IDO_BASIC_MENU_ITEM (ido_action_helper_get_widget (helper));
-
- g_return_if_fail (ido_menu_item != NULL);
- g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_UINT32));
-
- str = g_strdup_printf ("%"G_GUINT32_FORMAT"%%", g_variant_get_uint32 (state));
- ido_basic_menu_item_set_secondary_text (ido_menu_item, str);
- g_free (str);
+ IdoActionHelper *pHelper = pData;
+ ido_action_helper_activate (pHelper);
}
/**
* ido_progress_menu_item_new_from_model:
- * @menu_item: the corresponding menuitem
- * @actions: action group to tell when this GtkMenuItem is activated
+ * @pMenuItem: the corresponding menuitem
+ * @pActionGroup: action group to tell when this GtkMenuItem is activated
*
* Creates a new progress menuitem with properties initialized from
* the menuitem's attributes.
*
* If the menuitem's 'action' attribute is set, trigger that action
- * in @actions when this IdoBasicMenuItem is activated.
+ * in @pActionGroup when this IdoProgressMenuItem is activated.
*/
-GtkMenuItem *
-ido_progress_menu_item_new_from_model (GMenuItem * menu_item,
- GActionGroup * actions)
+GtkMenuItem *ido_progress_menu_item_new_from_model (GMenuItem *pMenuItem, GActionGroup *pActionGroup)
{
- guint i;
- guint n;
- gchar * str;
- IdoBasicMenuItem * ido_menu_item;
- const gchar * names[1] = {0};
- GValue * values;
- const guint n_max = 1;
-
- /* create the ido menuitem */;
+ IdoBasicMenuItem *pBasicMenuItem = NULL;
+ gchar *sLabel = NULL;
- n = 0;
- values = g_new0(GValue, n_max);
-
- if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
+ if (g_menu_item_get_attribute (pMenuItem, "label", "s", &sLabel))
{
- names[n] = "text";
- g_value_init (&values[n], G_TYPE_STRING);
- g_value_take_string (&values[n], str);
- n++;
- }
-
- g_assert (n <= G_N_ELEMENTS (names));
- g_assert (n <= n_max);
- ido_menu_item = IDO_BASIC_MENU_ITEM(g_object_new_with_properties (IDO_TYPE_BASIC_MENU_ITEM, n, names, values));
-
- for (i=0; i<n; i++)
- g_value_unset (&values[i]);
-
- /* give it an ActionHelper */
-
- if (g_menu_item_get_attribute (menu_item, "action", "s", &str))
- {
- IdoActionHelper * helper;
-
- helper = ido_action_helper_new (GTK_WIDGET(ido_menu_item),
- actions,
- str,
- NULL);
- g_signal_connect (helper, "action-state-changed",
- G_CALLBACK (on_progress_action_state_changed), NULL);
- g_signal_connect_swapped (ido_menu_item, "destroy",
- G_CALLBACK (g_object_unref), helper);
-
- g_free (str);
+ pBasicMenuItem = IDO_BASIC_MENU_ITEM (g_object_new (IDO_TYPE_BASIC_MENU_ITEM, "text", sLabel, NULL));
+ g_free (sLabel);
+
+ GVariant *pIconVariant = g_menu_item_get_attribute_value (pMenuItem, "icon", NULL);
+
+ if (pIconVariant)
+ {
+ GIcon *pIcon = g_icon_deserialize (pIconVariant);
+ ido_basic_menu_item_set_icon (pBasicMenuItem, pIcon);
+ g_object_unref (pIcon);
+ g_variant_unref (pIconVariant);
+ }
+
+ guint16 nProgress = 0;
+
+ if (g_menu_item_get_attribute (pMenuItem, "x-ayatana-progress", "q", &nProgress))
+ {
+ gchar *sProgress = g_strdup_printf ("%"G_GUINT16_FORMAT"%%", nProgress);
+ ido_basic_menu_item_set_secondary_text (pBasicMenuItem, sProgress);
+ g_free (sProgress);
+ }
+
+ gchar *sAction = NULL;
+
+ if (g_menu_item_get_attribute (pMenuItem, "action", "s", &sAction))
+ {
+ GVariant *pTarget = g_menu_item_get_attribute_value (pMenuItem, "target", NULL);
+ IdoActionHelper *pHelper = ido_action_helper_new (GTK_WIDGET (pBasicMenuItem), pActionGroup, sAction, pTarget);
+ g_signal_connect_object (pBasicMenuItem, "activate", G_CALLBACK (onActivate), pHelper, 0);
+ g_signal_connect_swapped (pBasicMenuItem, "destroy", G_CALLBACK (g_object_unref), pHelper);
+
+ if (pTarget)
+ {
+ g_variant_unref (pTarget);
+ }
+
+ g_free (sAction);
+ }
}
- return GTK_MENU_ITEM (ido_menu_item);
+ return GTK_MENU_ITEM (pBasicMenuItem);
}