From ff4aefe6c8d9c36881f26c2cf8514c2ce1f3edca Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 12 Aug 2013 21:19:42 +0200 Subject: Add ImMenu A base class for all messaging menus. ImPhoneMenu already subclasses from it, with a desktop version coming up. --- src/im-menu.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/im-menu.c (limited to 'src/im-menu.c') diff --git a/src/im-menu.c b/src/im-menu.c new file mode 100644 index 0000000..9f4d3e0 --- /dev/null +++ b/src/im-menu.c @@ -0,0 +1,148 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * 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 + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Lars Uebernickel + */ + +#include "im-menu.h" + +struct _ImMenuPrivate +{ + GMenu *toplevel_menu; + GMenu *menu; + ImApplicationList *applist; +}; + +G_DEFINE_TYPE_WITH_PRIVATE (ImMenu, im_menu, G_TYPE_OBJECT) + +enum +{ + PROP_0, + PROP_APPLICATION_LIST, + NUM_PROPERTIES +}; + +static void +im_menu_finalize (GObject *object) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + g_object_unref (priv->toplevel_menu); + g_object_unref (priv->menu); + g_object_unref (priv->applist); + + G_OBJECT_CLASS (im_menu_parent_class)->finalize (object); +} + +static void +im_menu_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + switch (property_id) + { + case PROP_APPLICATION_LIST: + g_value_set_object (value, priv->applist); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +im_menu_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (IM_MENU (object)); + + switch (property_id) + { + case PROP_APPLICATION_LIST: /* construct only */ + priv->applist = g_value_dup_object (value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + +static void +im_menu_class_init (ImMenuClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = im_menu_finalize; + object_class->get_property = im_menu_get_property; + object_class->set_property = im_menu_set_property; + + g_object_class_install_property (object_class, PROP_APPLICATION_LIST, + g_param_spec_object ("application-list", "", "", + IM_TYPE_APPLICATION_LIST, + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS)); +} + +static void +im_menu_init (ImMenu *menu) +{ + ImMenuPrivate *priv = im_menu_get_instance_private (menu); + GMenuItem *root; + + priv->toplevel_menu = g_menu_new (); + priv->menu = g_menu_new (); + + root = g_menu_item_new (NULL, "indicator.messages"); + g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_submenu (root, G_MENU_MODEL (priv->menu)); + g_menu_append_item (priv->toplevel_menu, root); + + g_object_unref (root); +} + +ImApplicationList * +im_menu_get_application_list (ImMenu *menu) +{ + ImMenuPrivate *priv; + + g_return_val_if_fail (IM_IS_MENU (menu), FALSE); + + priv = im_menu_get_instance_private (menu); + return priv->applist; +} + +gboolean +im_menu_export (ImMenu *menu, + GDBusConnection *connection, + const gchar *object_path, + GError **error) +{ + ImMenuPrivate *priv; + + g_return_val_if_fail (IM_IS_MENU (menu), FALSE); + + priv = im_menu_get_instance_private (menu); + return g_dbus_connection_export_menu_model (connection, + object_path, + G_MENU_MODEL (priv->toplevel_menu), + error) > 0; +} -- cgit v1.2.3 From 0b24c6a91ff91400568cab9b4d192a0a85db918e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 12 Aug 2013 21:33:39 +0200 Subject: Move toplevel menu logic into ImMenu Also, get rid of only exporting sections if they were non-empty. That was a hack for non-conformant GMenuModel renderers. --- src/im-menu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/im-menu.c') diff --git a/src/im-menu.c b/src/im-menu.c index 9f4d3e0..4c660e5 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -146,3 +146,17 @@ im_menu_export (ImMenu *menu, G_MENU_MODEL (priv->toplevel_menu), error) > 0; } + +void +im_menu_append_section (ImMenu *menu, + GMenuModel *section) +{ + ImMenuPrivate *priv; + + g_return_if_fail (IM_IS_MENU (menu)); + g_return_if_fail (G_IS_MENU_MODEL (section)); + + priv = im_menu_get_instance_private (menu); + + g_menu_append_section (priv->menu, NULL, section); +} -- cgit v1.2.3 From 046ef6f5581ab2634d5ef097e6c449316c2404bf Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 13 Aug 2013 09:43:22 +0200 Subject: Add desktop menu Only shows application launchers right now. --- src/im-menu.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/im-menu.c') diff --git a/src/im-menu.c b/src/im-menu.c index 4c660e5..ac23a29 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -113,6 +113,7 @@ im_menu_init (ImMenu *menu) root = g_menu_item_new (NULL, "indicator.messages"); g_menu_item_set_attribute (root, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_attribute (root, "action-namespace", "s", "indicator"); g_menu_item_set_submenu (root, G_MENU_MODEL (priv->menu)); g_menu_append_item (priv->toplevel_menu, root); @@ -160,3 +161,31 @@ im_menu_append_section (ImMenu *menu, g_menu_append_section (priv->menu, NULL, section); } + +void +im_menu_insert_section (ImMenu *menu, + gint position, + const gchar *namespace, + GMenuModel *section) +{ + ImMenuPrivate *priv; + GMenuItem *item; + + g_return_if_fail (IM_IS_MENU (menu)); + g_return_if_fail (G_IS_MENU_MODEL (section)); + + priv = im_menu_get_instance_private (menu); + + /* count from the back if position is < 0 */ + if (position < 0) + position = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + position; + + item = g_menu_item_new_section (NULL, section); + + if (namespace) + g_menu_item_set_attribute (item, "action-namespace", "s", namespace); + + g_menu_insert_item (priv->menu, position, item); + + g_object_unref (item); +} -- cgit v1.2.3 From 24b52f4270c0c4f9b2fa120c895908e3b50e8471 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Aug 2013 23:01:17 -0500 Subject: Adding a set_status virtual function --- src/im-menu.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/im-menu.c') diff --git a/src/im-menu.c b/src/im-menu.c index ac23a29..931d998 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -189,3 +189,19 @@ im_menu_insert_section (ImMenu *menu, g_object_unref (item); } + +void +im_menu_set_status (ImMenu * menu, + const gchar *id, + const gchar *status_str) +{ + g_return_if_fail(IM_IS_MENU(menu)); + g_return_if_fail(id != NULL); + g_return_if_fail(status_str != NULL); + + ImMenuClass * klass = IM_MENU_GET_CLASS(menu); + if (klass->set_status != NULL) + klass->set_status(menu, id, status_str); + + return; +} -- cgit v1.2.3 From 194c8bf9e07b10fb4857aeb5366b3aaee07dd9a2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 15 Aug 2013 12:50:16 -0500 Subject: Really we should set status on the application list --- src/im-menu.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src/im-menu.c') diff --git a/src/im-menu.c b/src/im-menu.c index 931d998..ac23a29 100644 --- a/src/im-menu.c +++ b/src/im-menu.c @@ -189,19 +189,3 @@ im_menu_insert_section (ImMenu *menu, g_object_unref (item); } - -void -im_menu_set_status (ImMenu * menu, - const gchar *id, - const gchar *status_str) -{ - g_return_if_fail(IM_IS_MENU(menu)); - g_return_if_fail(id != NULL); - g_return_if_fail(status_str != NULL); - - ImMenuClass * klass = IM_MENU_GET_CLASS(menu); - if (klass->set_status != NULL) - klass->set_status(menu, id, status_str); - - return; -} -- cgit v1.2.3