aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am4
-rw-r--r--src/app-section.c21
-rw-r--r--src/gmenuutils.c79
-rw-r--r--src/gmenuutils.h38
-rw-r--r--src/messages-service.c46
5 files changed, 131 insertions, 57 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 79fdee6..e9f88e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -48,7 +48,9 @@ indicator_messages_service_SOURCES = \
gactionmuxer.c \
gactionmuxer.h \
gsettingsstrv.c \
- gsettingsstrv.h
+ gsettingsstrv.h \
+ gmenuutils.c \
+ gmenuutils.h
indicator_messages_service_CFLAGS = \
$(APPLET_CFLAGS) \
diff --git a/src/app-section.c b/src/app-section.c
index 7bbbbbb..1662a9f 100644
--- a/src/app-section.c
+++ b/src/app-section.c
@@ -30,6 +30,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libindicator/indicator-desktop-shortcuts.h>
#include "app-section.h"
#include "dbus-data.h"
+#include "gmenuutils.h"
struct _AppSectionPrivate
{
@@ -208,24 +209,11 @@ nick_activate_cb (GSimpleAction *action,
}
static void
-g_menu_item_set_icon (GMenuItem *item,
- GIcon *icon)
-{
- gchar *iconstr;
-
- iconstr = g_icon_to_string (icon);
- g_menu_item_set_attribute (item, INDICATOR_MENU_ATTRIBUTE_ICON_NAME, "s", iconstr);
-
- g_free (iconstr);
-}
-
-static void
app_section_set_app_info (AppSection *self,
GDesktopAppInfo *appinfo)
{
AppSectionPrivate *priv = self->priv;
GSimpleAction *launch;
- GMenuItem *item;
g_return_if_fail (priv->appinfo == NULL);
@@ -240,9 +228,10 @@ app_section_set_app_info (AppSection *self,
g_signal_connect (launch, "activate", G_CALLBACK (activate_cb), self);
g_simple_action_group_insert (priv->static_shortcuts, G_ACTION (launch));
- item = g_menu_item_new (g_app_info_get_name (G_APP_INFO (priv->appinfo)), "launch");
- g_menu_item_set_icon (item, g_app_info_get_icon (G_APP_INFO (priv->appinfo)));
- g_menu_append_item (priv->menu, item);
+ g_menu_append_with_icon (priv->menu,
+ g_app_info_get_name (G_APP_INFO (priv->appinfo)),
+ g_app_info_get_icon (G_APP_INFO (priv->appinfo)),
+ "launch");
/* Start to build static shortcuts */
priv->ids = indicator_desktop_shortcuts_new(g_desktop_app_info_get_filename (priv->appinfo), "Messaging Menu");
diff --git a/src/gmenuutils.c b/src/gmenuutils.c
new file mode 100644
index 0000000..056e75f
--- /dev/null
+++ b/src/gmenuutils.c
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2012 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lars Uebernickel <lars.uebernickel@canonical.com>
+ */
+
+#include "gmenuutils.h"
+#include "dbus-data.h"
+
+/* g_menu_find_section:
+ * @menu: a #GMenu
+ * @section: the section to be found in @menu
+ *
+ * @Returns the index of the first menu item that is linked to #section, or -1
+ * if there's no such item.
+ */
+int
+g_menu_find_section (GMenu *menu,
+ GMenuModel *section)
+{
+ GMenuModel *model = G_MENU_MODEL (menu);
+ int n_items;
+ int i;
+
+ g_return_val_if_fail (G_IS_MENU_MODEL (section), -1);
+
+ n_items = g_menu_model_get_n_items (model);
+ for (i = 0; i < n_items; i++)
+ {
+ if (section == g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION))
+ return i;
+ }
+
+ return -1;
+}
+
+
+void
+g_menu_append_with_icon (GMenu *menu,
+ const gchar *label,
+ GIcon *icon,
+ const gchar *detailed_action)
+{
+ gchar *iconstr;
+
+ iconstr = g_icon_to_string (icon);
+ g_menu_append_with_icon_name (menu, label, iconstr, detailed_action);
+
+ g_free (iconstr);
+}
+
+void
+g_menu_append_with_icon_name (GMenu *menu,
+ const gchar *label,
+ const gchar *icon_name,
+ const gchar *detailed_action)
+{
+ GMenuItem *item;
+
+ item = g_menu_item_new (label, detailed_action);
+ g_menu_item_set_attribute (item, INDICATOR_MENU_ATTRIBUTE_ICON_NAME, "s", icon_name);
+
+ g_menu_append_item (menu, item);
+
+ g_object_unref (item);
+}
diff --git a/src/gmenuutils.h b/src/gmenuutils.h
new file mode 100644
index 0000000..e00ac55
--- /dev/null
+++ b/src/gmenuutils.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lars Uebernickel <lars.uebernickel@canonical.com>
+ */
+
+#ifndef __G_MENU_UTILS_H__
+#define __G_MENU_UTILS_H__
+
+#include <gio/gio.h>
+
+int g_menu_find_section (GMenu *menu,
+ GMenuModel *section);
+
+void g_menu_append_with_icon (GMenu *menu,
+ const gchar *label,
+ GIcon *icon,
+ const gchar *detailed_action);
+
+void g_menu_append_with_icon_name (GMenu *menu,
+ const gchar *label,
+ const gchar *icon_name,
+ const gchar *detailed_action);
+
+#endif
diff --git a/src/messages-service.c b/src/messages-service.c
index f07ea68..8a08423 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -32,6 +32,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "messages-service-dbus.h"
#include "gactionmuxer.h"
#include "gsettingsstrv.h"
+#include "gmenuutils.h"
static GHashTable *applications;
@@ -110,26 +111,6 @@ add_application (const gchar *desktop_id)
return section;
}
-/* g_menu_model_find_section:
- *
- * @Returns the index of the first menu item that is linked to #section, or -1
- * if there's no such item.
- */
-static int
-g_menu_find_section (GMenu *menu,
- GMenuModel *section)
-{
- int n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
- int i;
-
- for (i = 0; i < n_items; i++) {
- if (section == g_menu_model_get_item_link (G_MENU_MODEL (menu), i, G_MENU_LINK_SECTION))
- return i;
- }
-
- return -1;
-}
-
static void
remove_application (const char *desktop_id)
{
@@ -268,32 +249,17 @@ unregister_application (MessageServiceDbus *msd,
g_settings_strv_remove (settings, "applications", desktop_id);
}
-static void
-g_menu_append_with_icon (GMenu *menu,
- const gchar *label,
- const gchar *icon_name,
- const gchar *detailed_action)
-{
- GMenuItem *item;
-
- item = g_menu_item_new (label, detailed_action);
- g_menu_item_set_attribute (item, INDICATOR_MENU_ATTRIBUTE_ICON_NAME, "s", icon_name);
-
- g_menu_append_item (menu, item);
- g_object_unref (item);
-}
-
GMenuModel *
create_status_section ()
{
GMenu *menu;
menu = g_menu_new ();
- g_menu_append_with_icon (menu, _("Available"), "user-available", "status::available");
- g_menu_append_with_icon (menu, _("Away"), "user-away", "status::away");
- g_menu_append_with_icon (menu, _("Busy"), "user-busy", "status::busy");
- g_menu_append_with_icon (menu, _("Invisible"), "user-invisible", "status::invisible");
- g_menu_append_with_icon (menu, _("Offline"), "user-offline", "status::offline");
+ g_menu_append_with_icon_name (menu, _("Available"), "user-available", "status::available");
+ g_menu_append_with_icon_name (menu, _("Away"), "user-away", "status::away");
+ g_menu_append_with_icon_name (menu, _("Busy"), "user-busy", "status::busy");
+ g_menu_append_with_icon_name (menu, _("Invisible"), "user-invisible", "status::invisible");
+ g_menu_append_with_icon_name (menu, _("Offline"), "user-offline", "status::offline");
return G_MENU_MODEL (menu);
}