aboutsummaryrefslogtreecommitdiff
path: root/src/im-phone-menu.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-11-26 20:32:48 +0000
committerTarmac <Unknown>2012-11-26 20:32:48 +0000
commitefe27b122bc3fef166a7f5f62cdfd81d45495426 (patch)
treeb5c87bcc747acd9cc8f261c6d3d62c7cf8a8daf4 /src/im-phone-menu.c
parent4a6fa0a418b899667988d25b7f8922a031f72f38 (diff)
parent9287c2e6577e71d8f68d9c9e7d393a4f8524ab10 (diff)
downloadayatana-indicator-messages-efe27b122bc3fef166a7f5f62cdfd81d45495426.tar.gz
ayatana-indicator-messages-efe27b122bc3fef166a7f5f62cdfd81d45495426.tar.bz2
ayatana-indicator-messages-efe27b122bc3fef166a7f5f62cdfd81d45495426.zip
Implement more of the phone spec.
Approved by Renato Araujo Oliveira Filho, PS Jenkins bot.
Diffstat (limited to 'src/im-phone-menu.c')
-rw-r--r--src/im-phone-menu.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/src/im-phone-menu.c b/src/im-phone-menu.c
index 0ba41c4..728c08b 100644
--- a/src/im-phone-menu.c
+++ b/src/im-phone-menu.c
@@ -60,6 +60,33 @@ im_phone_menu_foreach_item_with_action (GMenuModel *menu,
}
static void
+im_phone_menu_update_toplevel (ImPhoneMenu *menu)
+{
+ if (g_menu_model_get_n_items (G_MENU_MODEL (menu->message_section)) ||
+ g_menu_model_get_n_items (G_MENU_MODEL (menu->source_section)))
+ {
+ if (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)) == 0)
+ {
+ GMenuItem *item;
+
+ g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section));
+ g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section));
+
+ item = g_menu_item_new ("Clear All", "remove-all");
+ g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.button");
+ g_menu_append_item (menu->toplevel_menu, item);
+
+ g_object_unref (item);
+ }
+ }
+ else
+ {
+ while (g_menu_model_get_n_items (G_MENU_MODEL (menu->toplevel_menu)))
+ g_menu_remove (menu->toplevel_menu, 0);
+ }
+}
+
+static void
im_phone_menu_dispose (GObject *object)
{
ImPhoneMenu *menu = IM_PHONE_MENU (object);
@@ -89,12 +116,16 @@ im_phone_menu_class_init (ImPhoneMenuClass *klass)
static void
im_phone_menu_init (ImPhoneMenu *menu)
{
+ menu->toplevel_menu = g_menu_new ();
menu->message_section = g_menu_new ();
menu->source_section = g_menu_new ();
- menu->toplevel_menu = g_menu_new ();
- g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->message_section));
- g_menu_append_section (menu->toplevel_menu, NULL, G_MENU_MODEL (menu->source_section));
+ g_signal_connect_swapped (menu->message_section, "items-changed",
+ G_CALLBACK (im_phone_menu_update_toplevel), menu);
+ g_signal_connect_swapped (menu->source_section, "items-changed",
+ G_CALLBACK (im_phone_menu_update_toplevel), menu);
+
+ im_phone_menu_update_toplevel (menu);
}
ImPhoneMenu *
@@ -113,7 +144,8 @@ im_phone_menu_get_model (ImPhoneMenu *menu)
void
im_phone_menu_add_message (ImPhoneMenu *menu,
- GDesktopAppInfo *app,
+ const gchar *app_id,
+ const gchar *app_icon,
const gchar *id,
const gchar *iconstr,
const gchar *title,
@@ -121,17 +153,13 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
const gchar *body,
gint64 time)
{
- const gchar *app_id;
GMenuItem *item;
gchar *action_name;
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
-
- app_id = g_app_info_get_id (G_APP_INFO (app));
g_return_if_fail (app_id);
- action_name = g_strconcat (app_id, ".", id, NULL);
+ action_name = g_strconcat (app_id, ".msg.", id, NULL);
item = g_menu_item_new (title, action_name);
g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.messageitem");
@@ -143,6 +171,9 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
if (iconstr)
g_menu_item_set_attribute (item, "x-canonical-icon", "s", iconstr);
+ if (app_icon)
+ g_menu_item_set_attribute (item, "x-canonical-app-icon", "s", app_icon);
+
g_menu_append_item (menu->message_section, item);
g_free (action_name);
@@ -151,15 +182,15 @@ im_phone_menu_add_message (ImPhoneMenu *menu,
void
im_phone_menu_remove_message (ImPhoneMenu *menu,
- GDesktopAppInfo *app,
+ const gchar *app_id,
const gchar *id)
{
gchar *action_name;
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
+ g_return_if_fail (app_id != NULL);
- action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL);
+ action_name = g_strconcat (app_id, ".msg.", id, NULL);
im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->message_section),
action_name,
(ImMenuForeachFunc) g_menu_remove);
@@ -169,7 +200,7 @@ im_phone_menu_remove_message (ImPhoneMenu *menu,
void
im_phone_menu_add_source (ImPhoneMenu *menu,
- GDesktopAppInfo *app,
+ const gchar *app_id,
const gchar *id,
const gchar *label,
const gchar *iconstr)
@@ -178,9 +209,9 @@ im_phone_menu_add_source (ImPhoneMenu *menu,
gchar *action_name;
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
+ g_return_if_fail (app_id != NULL);
- action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL);
+ action_name = g_strconcat (app_id, ".src.", id, NULL);
item = g_menu_item_new (label, action_name);
g_menu_item_set_attribute (item, "x-canonical-type", "s", "com.canonical.indicator.messages.sourceitem");
@@ -196,15 +227,15 @@ im_phone_menu_add_source (ImPhoneMenu *menu,
void
im_phone_menu_remove_source (ImPhoneMenu *menu,
- GDesktopAppInfo *app,
+ const gchar *app_id,
const gchar *id)
{
gchar *action_name;
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
+ g_return_if_fail (app_id != NULL);
- action_name = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", id, NULL);
+ action_name = g_strconcat (app_id, ".src.", id, NULL);
im_phone_menu_foreach_item_with_action (G_MENU_MODEL (menu->source_section),
action_name,
(ImMenuForeachFunc) g_menu_remove);
@@ -214,13 +245,13 @@ im_phone_menu_remove_source (ImPhoneMenu *menu,
static void
im_phone_menu_remove_all_for_app (GMenu *menu,
- GDesktopAppInfo *app)
+ const gchar *app_id)
{
gchar *prefix;
gint n_items;
gint i = 0;
- prefix = g_strconcat (g_app_info_get_id (G_APP_INFO (app)), ".", NULL);
+ prefix = g_strconcat (app_id, ".", NULL);
n_items = g_menu_model_get_n_items (G_MENU_MODEL (menu));
while (i < n_items)
@@ -246,11 +277,11 @@ im_phone_menu_remove_all_for_app (GMenu *menu,
void
im_phone_menu_remove_application (ImPhoneMenu *menu,
- GDesktopAppInfo *app)
+ const gchar *app_id)
{
g_return_if_fail (IM_IS_PHONE_MENU (menu));
- g_return_if_fail (G_IS_DESKTOP_APP_INFO (app));
+ g_return_if_fail (app_id != NULL);
- im_phone_menu_remove_all_for_app (menu->source_section, app);
- im_phone_menu_remove_all_for_app (menu->message_section, app);
+ im_phone_menu_remove_all_for_app (menu->source_section, app_id);
+ im_phone_menu_remove_all_for_app (menu->message_section, app_id);
}