Merge lp:~larsu/indicator-messages/lp1216833 into lp:indicator-messages/14.04

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: 410
Merged at revision: 409
Proposed branch: lp:~larsu/indicator-messages/lp1216833
Merge into: lp:indicator-messages/14.04
Prerequisite: lp:~larsu/indicator-messages/menu-visibility
Diff against target: 191 lines (+86/-30)
3 files modified
src/im-desktop-menu.c (+46/-1)
src/im-menu.c (+36/-25)
src/im-menu.h (+4/-4)
To merge this branch: bzr merge lp:~larsu/indicator-messages/lp1216833
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+214535@code.launchpad.net

Commit message

desktop menu: sort applications like specified

Default chat client, default email client, and the other applications sorted by alphabet.

Description of the change

desktop menu: sort applications like specified

Default chat client, default email client, and the other applications sorted by alphabet.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Thanks for the leak fix.

I'm uncomfortable with hardcoding a default chat app here, but since you and seb and I have discussed it without coming up with a better alternative, I think it's a reasonable tradeoff... :|

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/im-desktop-menu.c'
2--- src/im-desktop-menu.c 2014-04-08 16:29:40 +0000
3+++ src/im-desktop-menu.c 2014-04-08 16:29:41 +0000
4@@ -28,6 +28,8 @@
5 ImMenu parent;
6
7 gboolean status_section_visible;
8+ GMenu *default_chat_client_section;
9+ GMenu *default_mail_client_section;
10 GHashTable *source_sections;
11 };
12
13@@ -74,6 +76,20 @@
14 g_object_unref (status_section);
15 }
16
17+static gboolean
18+g_app_info_is_default_for_uri_scheme (GAppInfo *info,
19+ const gchar *uri_scheme)
20+{
21+ GAppInfo *default_info;
22+ gboolean is_default;
23+
24+ default_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
25+ is_default = g_app_info_equal (info, default_info);
26+
27+ g_object_unref (default_info);
28+ return is_default;
29+}
30+
31 static void
32 im_desktop_menu_app_added (ImApplicationList *applist,
33 const gchar *app_id,
34@@ -85,6 +101,7 @@
35 GMenu *app_section;
36 GMenu *source_section;
37 gchar *namespace;
38+ GMenuItem *item;
39
40 app_section = g_menu_new ();
41
42@@ -145,11 +162,33 @@
43 g_menu_append_section (section, NULL, G_MENU_MODEL (app_section));
44 g_menu_append_section (section, NULL, G_MENU_MODEL (source_section));
45
46+ item = g_menu_item_new_section (NULL, G_MENU_MODEL (section));
47+
48 namespace = g_strconcat ("indicator.", app_id, NULL);
49- im_menu_insert_section (IM_MENU (menu), g_app_info_get_name(G_APP_INFO(app_info)), namespace, G_MENU_MODEL (section));
50+ g_menu_item_set_attribute (item, "action-namespace", "s", namespace);
51+
52+ /* The default chat client is not stored anywhere, so let's hardcode empathy. */
53+ if (g_str_equal (app_id, "empathy"))
54+ {
55+ g_menu_remove_all (menu->default_chat_client_section);
56+ g_menu_append_item (menu->default_chat_client_section, item);
57+ }
58+ else if (g_app_info_is_default_for_uri_scheme (G_APP_INFO (app_info), "mailto"))
59+ {
60+ g_menu_remove_all (menu->default_mail_client_section);
61+ g_menu_append_item (menu->default_mail_client_section, item);
62+ }
63+ else
64+ {
65+ g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s",
66+ g_app_info_get_name(G_APP_INFO(app_info)));
67+ im_menu_insert_item_sorted (IM_MENU (menu), item, menu->status_section_visible ? 3 : 2, -1);
68+ }
69+
70 g_hash_table_insert (menu->source_sections, g_strdup (app_id), source_section);
71
72 g_free (namespace);
73+ g_object_unref (item);
74 g_object_unref (section);
75 g_object_unref (app_section);
76 }
77@@ -312,6 +351,12 @@
78 ImDesktopMenu *menu = IM_DESKTOP_MENU (object);
79 ImApplicationList *applist;
80
81+ menu->default_chat_client_section = g_menu_new ();
82+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_chat_client_section));
83+
84+ menu->default_mail_client_section = g_menu_new ();
85+ im_menu_append_section (IM_MENU (menu), G_MENU_MODEL (menu->default_mail_client_section));
86+
87 {
88 GMenu *clear_section;
89
90
91=== modified file 'src/im-menu.c'
92--- src/im-menu.c 2014-04-08 16:29:40 +0000
93+++ src/im-menu.c 2014-04-08 16:29:41 +0000
94@@ -176,43 +176,54 @@
95 g_menu_append_section (priv->menu, NULL, section);
96 }
97
98+/*
99+ * Inserts @item into @menu by comparing its
100+ * "x-messaging-menu-sort-string" with those found in existing menu
101+ * items between positions @first and @last.
102+ *
103+ * If @last is negative, it is counted from the end of @menu.
104+ */
105 void
106-im_menu_insert_section (ImMenu *menu,
107- const gchar *sort_string,
108- const gchar *namespace,
109- GMenuModel *section)
110+im_menu_insert_item_sorted (ImMenu *menu,
111+ GMenuItem *item,
112+ gint first,
113+ gint last)
114 {
115- int position;
116 ImMenuPrivate *priv;
117- GMenuItem *item;
118+ gint position = first;
119+ gchar *sort_string;
120
121 g_return_if_fail (IM_IS_MENU (menu));
122- g_return_if_fail (G_IS_MENU_MODEL (section));
123+ g_return_if_fail (G_IS_MENU_ITEM (item));
124
125 priv = im_menu_get_instance_private (menu);
126
127- for (position = 1; position < g_menu_model_get_n_items(G_MENU_MODEL (priv->menu)) - 1; position++)
128+ if (last < 0)
129+ last = g_menu_model_get_n_items (G_MENU_MODEL (priv->menu)) + last;
130+
131+ g_return_if_fail (first <= last);
132+
133+ if (g_menu_item_get_attribute (item, "x-messaging-menu-sort-string", "s", &sort_string))
134 {
135- gchar *item_sort;
136-
137- if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
138+ while (position < last)
139 {
140- gint cmp;
141-
142- cmp = g_utf8_collate(sort_string, item_sort);
143- g_free (item_sort);
144- if (cmp < 0)
145- break;
146+ gchar *item_sort;
147+
148+ if (g_menu_model_get_item_attribute(G_MENU_MODEL(priv->menu), position, "x-messaging-menu-sort-string", "s", &item_sort))
149+ {
150+ gint cmp;
151+
152+ cmp = g_utf8_collate(sort_string, item_sort);
153+ g_free (item_sort);
154+ if (cmp < 0)
155+ break;
156+ }
157+
158+ position++;
159 }
160+
161+ g_free (sort_string);
162 }
163
164- item = g_menu_item_new_section (NULL, section);
165- g_menu_item_set_attribute (item, "x-messaging-menu-sort-string", "s", sort_string);
166-
167- if (namespace)
168- g_menu_item_set_attribute (item, "action-namespace", "s", namespace);
169-
170 g_menu_insert_item (priv->menu, position, item);
171-
172- g_object_unref (item);
173 }
174
175=== modified file 'src/im-menu.h'
176--- src/im-menu.h 2014-04-08 16:29:40 +0000
177+++ src/im-menu.h 2014-04-08 16:29:41 +0000
178@@ -59,9 +59,9 @@
179 void im_menu_append_section (ImMenu *menu,
180 GMenuModel *section);
181
182-void im_menu_insert_section (ImMenu *menu,
183- const gchar *sort_string,
184- const gchar *namespace,
185- GMenuModel *section);
186+void im_menu_insert_item_sorted (ImMenu *menu,
187+ GMenuItem *item,
188+ gint first,
189+ gint last);
190
191 #endif

Subscribers

People subscribed via source and target branches