aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/im-desktop-menu.c47
-rw-r--r--src/im-menu.c57
-rw-r--r--src/im-menu.h8
3 files changed, 83 insertions, 29 deletions
diff --git a/src/im-desktop-menu.c b/src/im-desktop-menu.c
index bfae137..137e222 100644
--- a/src/im-desktop-menu.c
+++ b/src/im-desktop-menu.c
@@ -28,6 +28,8 @@ struct _ImDesktopMenu
ImMenu parent;
gboolean status_section_visible;
+ GMenu *default_chat_client_section;
+ GMenu *default_mail_client_section;
GHashTable *source_sections;
};
@@ -74,6 +76,20 @@ im_desktop_menu_show_chat_section (ImDesktopMenu *menu)
g_object_unref (status_section);
}
+static gboolean
+g_app_info_is_default_for_uri_scheme (GAppInfo *info,
+ const gchar *uri_scheme)
+{
+ GAppInfo *default_info;
+ gboolean is_default;
+
+ default_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
+ is_default = g_app_info_equal (info, default_info);
+
+ g_object_unref (default_info);
+ return is_default;
+}
+
static void
im_desktop_menu_app_added (ImApplicationList *applist,
const gchar *app_id,
@@ -85,6 +101,7 @@ im_desktop_menu_app_added (ImApplicationList *applist,
GMenu *app_section;
GMenu *source_section;
gchar *namespace;
+ GMenuItem *item;
app_section = g_menu_new ();
@@ -145,11 +162,33 @@ im_desktop_menu_app_added (ImApplicationList *applist,
g_menu_append_section (section, NULL, G_MENU_MODEL (app_section));
g_menu_append_section (section, NULL, G_MENU_MODEL (source_section));
+ item = g_menu_item_new_section (NULL, G_MENU_MODEL (section));
+
namespace = g_strconcat ("indicator.", app_id, NULL);
- im_menu_insert_section (IM_MENU (menu), g_app_info_get_name(G_APP_INFO(app_info)), namespace, G_MENU_MODEL (section));
+ g_menu_item_set_attribute (item, "action-namespace", "s", namespace);
+
+ /* The default chat client is not stored anywhere, so let's hardcode empathy. */
+ if (g_str_equal (app_id, "empathy"))
+ {
+ g_menu_remove_all (menu->default_chat_client_section);
+ g_menu_append_item (menu->default_chat_client_section, item);
+ }
+ else if (g_app_info_is_default_for_uri_scheme (G_APP_INFO (app_info), "mailto"))
+ {
+ g_menu_remove_all (menu->default_mail_client_section);
+ g_menu_append_item (menu->default_mail_client_section, item);
+ }
+ else
+ {
+ g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s",
+ g_app_info_get_name(G_APP_INFO(app_info)));
+ im_menu_insert_item_sorted (IM_MENU (menu), item, menu->status_section_visible ? 3 : 2, -1);
+ }
+
g_hash_table_insert (menu->source_sections, g_strdup (app_id), source_section);
g_free (namespace);
+ g_object_unref (item);
g_object_unref (section);
g_object_unref (app_section);
}
@@ -312,6 +351,12 @@ im_desktop_menu_constructed (GObject *object)
ImDesktopMenu *menu = IM_DESKTOP_MENU (object);
ImApplicationList *applist;
+ menu->default_chat_client_section = g_menu_new ();
+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_chat_client_section));
+
+ menu->default_mail_client_section = g_menu_new ();
+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_mail_client_section));
+
{
GMenu *clear_section;
diff --git a/src/im-menu.c b/src/im-menu.c
index 57cf957..55d4685 100644
--- a/src/im-menu.c
+++ b/src/im-menu.c
@@ -176,43 +176,52 @@ im_menu_append_section (ImMenu *menu,
g_menu_append_section (priv->menu, NULL, section);
}
+/*
+ * Inserts @item into @menu by comparing its
+ * "x-messaging-menu-sort-string" with those found in existing menu
+ * items between positions @first and @last.
+ *
+ * If @last is negative, it is counted from the end of @menu.
+ */
void
-im_menu_insert_section (ImMenu *menu,
- const gchar *sort_string,
- const gchar *namespace,
- GMenuModel *section)
+im_menu_insert_item_sorted (ImMenu *menu,
+ GMenuItem *item,
+ gint first,
+ gint last)
{
- int position;
ImMenuPrivate *priv;
- GMenuItem *item;
+ gint position = first;
+ gchar *sort_string;
g_return_if_fail (IM_IS_MENU (menu));
- g_return_if_fail (G_IS_MENU_MODEL (section));
+ g_return_if_fail (G_IS_MENU_ITEM (item));
priv = im_menu_get_instance_private (menu);
- for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)
- {
- gchar *item_sort;
+ if (last < 0)
+ last = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + last;
+
+ g_return_if_fail (first <= last);
- if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
+ if (g_menu_item_get_attribute (item, "x-messaging-menu-sort-string", "s", &sort_string))
+ {
+ while (position < last)
{
- gint cmp;
+ gchar *item_sort;
- cmp = g_utf8_collate(sort_string, item_sort);
- g_free (item_sort);
- if (cmp < 0)
- break;
- }
- }
+ if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
+ {
+ gint cmp;
- item = g_menu_item_new_section (NULL, section);
- g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s", sort_string);
+ cmp = g_utf8_collate(sort_string, item_sort);
+ g_free (item_sort);
+ if (cmp < 0)
+ break;
+ }
- if (namespace)
- g_menu_item_set_attribute (item, "action-namespace", "s", namespace);
+ position++;
+ }
+ }
g_menu_insert_item (priv->menu, position, item);
-
- g_object_unref (item);
}
diff --git a/src/im-menu.h b/src/im-menu.h
index 57815b5..f67abc8 100644
--- a/src/im-menu.h
+++ b/src/im-menu.h
@@ -59,9 +59,9 @@ void im_menu_prepend_section (ImMenu
void im_menu_append_section (ImMenu *menu,
GMenuModel *section);
-void im_menu_insert_section (ImMenu *menu,
- const gchar *sort_string,
- const gchar *namespace,
- GMenuModel *section);
+void im_menu_insert_item_sorted (ImMenu *menu,
+ GMenuItem *item,
+ gint first,
+ gint last);
#endif