diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-01-25 10:29:57 +0100 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-01-25 10:29:57 +0100 |
commit | 82ecfaaa89684a7504913fb039d0dd8302c82ec9 (patch) | |
tree | 65332ebc3eb241dd03bc377dc7360720c95e5363 /libindicator | |
parent | f02ca5a6b148d7ab6c33692da84f4601af4fd8c8 (diff) | |
download | libayatana-indicator-82ecfaaa89684a7504913fb039d0dd8302c82ec9.tar.gz libayatana-indicator-82ecfaaa89684a7504913fb039d0dd8302c82ec9.tar.bz2 libayatana-indicator-82ecfaaa89684a7504913fb039d0dd8302c82ec9.zip |
indicator-ng: require header item to have x-canonical-type set
Diffstat (limited to 'libindicator')
-rw-r--r-- | libindicator/indicator-ng.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c index 003ec70..05ece8d 100644 --- a/libindicator/indicator-ng.c +++ b/libindicator/indicator-ng.c @@ -219,6 +219,23 @@ indicator_ng_update_entry (IndicatorNg *self) g_variant_unref (state); } +static gboolean +indicator_ng_menu_item_is_of_type (GMenuModel *menu, + gint index, + const gchar *expected_type) +{ + gchar *type; + gboolean has_type = FALSE; + + if (g_menu_model_get_item_attribute (menu, index, "x-canonical-type", "s", &type)) + { + has_type = g_str_equal (type, expected_type); + g_free (type); + } + + return has_type; +} + static void indicator_ng_menu_changed (GMenuModel *menu, gint position, @@ -240,26 +257,32 @@ indicator_ng_menu_changed (GMenuModel *menu, if (added) { - GMenuModel *popup; - gchar *action; - g_clear_pointer (&self->header_action, g_free); - if (g_menu_model_get_item_attribute (self->menu, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action) && - g_str_has_prefix (action, "indicator.")) - { - self->header_action = g_strdup (action + 10); - } - popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); - if (popup) + if (indicator_ng_menu_item_is_of_type (self->menu, 0, "com.canonical.indicator.root")) { - gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->entry.menu), popup, NULL, TRUE); - g_object_unref (popup); - } + GMenuModel *popup; + gchar *action; - indicator_ng_update_entry (self); + if (g_menu_model_get_item_attribute (self->menu, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action) && + g_str_has_prefix (action, "indicator.")) + { + self->header_action = g_strdup (action + 10); + } - g_free (action); + popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); + if (popup) + { + gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->entry.menu), popup, NULL, TRUE); + g_object_unref (popup); + } + + indicator_ng_update_entry (self); + + g_free (action); + } + else + g_warning ("indicator menu item must be of type 'com.canonical.indicator.root'"); } } |