Merge lp:~ted/indicator-messages/menu-update into lp:indicator-messages/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: not available
Proposed branch: lp:~ted/indicator-messages/menu-update
Merge into: lp:indicator-messages/0.5
Diff against target: None lines
To merge this branch: bzr merge lp:~ted/indicator-messages/menu-update
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+10782@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Ted Gould (ted) wrote :

This branch fixes the launcher items to make them custom menu items with small descriptions on them.

Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good. Just one question:

In new_launcher_item; I know it's a static function, so was just wondering if args were checked before calling it elsewhere in the code, or should the function also check it's args just in case?

review: Needs Information
Revision history for this message
Ted Gould (ted) wrote :

On Thu, 2009-08-27 at 14:20 +0000, Neil J. Patel wrote:
> In new_launcher_item; I know it's a static function, so was
> just wondering if args were checked before calling it
> elsewhere in the code, or should the function also check
> it's args just in case?

Remember that comment on the dbusmenu review about application
developers stealing code and not thinking about it... I don't know any
of those ;)

Fixed (r141)

141. By Ted Gould

Checking args from libdbusmenu, stealing code from there. Comments by Neil.

Revision history for this message
Neil J. Patel (njpatel) wrote :

LOL. Approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2009-08-19 18:36:22 +0000
3+++ configure.ac 2009-08-26 21:43:14 +0000
4@@ -28,7 +28,7 @@
5 PANEL_REQUIRED_VERSION=2.0.0
6 INDICATE_REQUIRED_VERSION=0.2.0
7 INDICATOR_REQUIRED_VERSION=0.2.0
8-DBUSMENUGTK_REQUIRED_VERSION=0.0.0
9+DBUSMENUGTK_REQUIRED_VERSION=0.0.2
10
11 PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION
12 gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION
13
14=== modified file 'src/app-menu-item.c'
15--- src/app-menu-item.c 2009-08-20 03:29:40 +0000
16+++ src/app-menu-item.c 2009-08-26 21:47:55 +0000
17@@ -218,10 +218,10 @@
18 /* TRANSLATORS: This is the name of the program and the number of indicators. So it
19 would read something like "Mail Client (5)" */
20 gchar * label = g_strdup_printf(_("%s (%d)"), app_menu_item_get_name(self), priv->unreadcount);
21- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", label);
22+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, label);
23 g_free(label);
24 } else {
25- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", app_menu_item_get_name(self));
26+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, app_menu_item_get_name(self));
27 }
28
29 return;
30
31=== modified file 'src/dbus-data.h'
32--- src/dbus-data.h 2009-08-26 02:39:54 +0000
33+++ src/dbus-data.h 2009-08-27 01:06:09 +0000
34@@ -8,4 +8,8 @@
35 #define INDICATOR_MESSAGES_DBUS_SERVICE_OBJECT "/org/ayatana/indicator/messages/service"
36 #define INDICATOR_MESSAGES_DBUS_SERVICE_INTERFACE "org.ayatana.indicator.messages.service"
37
38+#define LAUNCHER_MENUITEM_TYPE "launcher-item"
39+#define LAUNCHER_MENUITEM_PROP_APP_NAME "application-name"
40+#define LAUNCHER_MENUITEM_PROP_APP_DESC "application-description"
41+
42 #endif /* __DBUS_DATA_H__ */
43
44=== modified file 'src/im-menu-item.c'
45--- src/im-menu-item.c 2009-08-04 16:44:11 +0000
46+++ src/im-menu-item.c 2009-08-26 21:47:55 +0000
47@@ -253,7 +253,7 @@
48 return;
49 }
50
51- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", propertydata);
52+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, propertydata);
53
54 return;
55 }
56
57=== modified file 'src/indicator-messages.c'
58--- src/indicator-messages.c 2009-08-26 15:50:02 +0000
59+++ src/indicator-messages.c 2009-08-27 01:46:43 +0000
60@@ -21,6 +21,7 @@
61 */
62
63 #include <string.h>
64+#include <glib.h>
65 #include <gtk/gtk.h>
66 #include <libdbusmenu-gtk/menu.h>
67 #include <dbus/dbus-glib.h>
68@@ -136,6 +137,35 @@
69 return FALSE;
70 }
71
72+static gboolean
73+new_launcher_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client)
74+{
75+ GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
76+
77+ GtkWidget * vbox = gtk_vbox_new(TRUE, 2);
78+
79+ GtkWidget * app_label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, LAUNCHER_MENUITEM_PROP_APP_NAME));
80+ gtk_misc_set_alignment(GTK_MISC(app_label), 0.0, 0.5);
81+ GtkWidget * dsc_label = gtk_label_new("");
82+ gtk_misc_set_alignment(GTK_MISC(dsc_label), 0.05, 0.5);
83+ gtk_label_set_ellipsize(GTK_LABEL(dsc_label), PANGO_ELLIPSIZE_END);
84+ gchar * markup = g_markup_printf_escaped("<span font-size=\"smaller\">%s</span>", dbusmenu_menuitem_property_get(newitem, LAUNCHER_MENUITEM_PROP_APP_DESC));
85+ gtk_label_set_markup(GTK_LABEL(dsc_label), markup);
86+ g_free(markup);
87+
88+ gtk_box_pack_start(GTK_BOX(vbox), app_label, FALSE, FALSE, 0);
89+ gtk_widget_show(app_label);
90+ gtk_box_pack_start(GTK_BOX(vbox), dsc_label, FALSE, FALSE, 0);
91+ gtk_widget_show(dsc_label);
92+
93+ gtk_container_add(GTK_CONTAINER(gmi), GTK_WIDGET(vbox));
94+ gtk_widget_show(GTK_WIDGET(vbox));
95+
96+ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
97+
98+ return TRUE;
99+}
100+
101 GtkLabel *
102 get_label (void)
103 {
104@@ -175,6 +205,11 @@
105
106 g_idle_add(setup_icon_proxy, NULL);
107
108- return GTK_MENU(dbusmenu_gtkmenu_new(INDICATOR_MESSAGES_DBUS_NAME, INDICATOR_MESSAGES_DBUS_OBJECT));
109+ DbusmenuGtkMenu * menu = dbusmenu_gtkmenu_new(INDICATOR_MESSAGES_DBUS_NAME, INDICATOR_MESSAGES_DBUS_OBJECT);
110+ DbusmenuGtkClient * client = dbusmenu_gtkmenu_get_client(menu);
111+
112+ dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), LAUNCHER_MENUITEM_TYPE, new_launcher_item);
113+
114+ return GTK_MENU(menu);
115 }
116
117
118=== modified file 'src/launcher-menu-item.c'
119--- src/launcher-menu-item.c 2009-08-26 17:44:48 +0000
120+++ src/launcher-menu-item.c 2009-08-27 01:53:29 +0000
121@@ -28,6 +28,7 @@
122 #include <glib/gi18n.h>
123 #include <gio/gdesktopappinfo.h>
124 #include "launcher-menu-item.h"
125+#include "dbus-data.h"
126
127 enum {
128 NAME_CHANGED,
129@@ -130,7 +131,9 @@
130 priv->desktop = g_strdup(desktop_file);
131
132 g_debug("\tName: %s", launcher_menu_item_get_name(self));
133- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", launcher_menu_item_get_name(self));
134+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", LAUNCHER_MENUITEM_TYPE);
135+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), LAUNCHER_MENUITEM_PROP_APP_NAME, launcher_menu_item_get_name(self));
136+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), LAUNCHER_MENUITEM_PROP_APP_DESC, launcher_menu_item_get_description(self));
137
138 g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL);
139
140@@ -157,23 +160,12 @@
141 LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self);
142 g_return_if_fail(priv->appinfo != NULL);
143
144- /* This should manage the X stuff for us */
145- GdkAppLaunchContext * context = gdk_app_launch_context_new();
146-
147- /* Using the current time as we don't have the event
148- time as that's not sent across the bus */
149- GTimeVal time;
150- g_get_current_time(&time);
151- gdk_app_launch_context_set_timestamp(context, time.tv_usec / 1000);
152-
153 GError * error = NULL;
154- if (!g_app_info_launch(priv->appinfo, NULL, G_APP_LAUNCH_CONTEXT(context), &error)) {
155+ if (!g_app_info_launch(priv->appinfo, NULL, NULL, &error)) {
156 g_warning("Application failed to launch '%s' because: %s", launcher_menu_item_get_name(self), error->message);
157 g_error_free(error);
158 }
159
160- g_object_unref(G_OBJECT(context));
161-
162 return;
163 }
164
165@@ -185,20 +177,30 @@
166 return priv->desktop;
167 }
168
169+/* Gets the decription for the item that should
170+ go in the messaging menu */
171+const gchar *
172+launcher_menu_item_get_description (LauncherMenuItem * li)
173+{
174+ g_return_val_if_fail(IS_LAUNCHER_MENU_ITEM(li), NULL);
175+ LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(li);
176+ return g_app_info_get_description(priv->appinfo);
177+}
178+
179 /* Hides the menu item based on whether it is eclipsed
180 or not. */
181 void
182 launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed)
183 {
184 g_debug("Laucher '%s' is %s", launcher_menu_item_get_name(li), eclipsed ? "now eclipsed" : "shown again");
185- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), "show", eclipsed ? "false" : "true");
186+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE, eclipsed ? "false" : "true");
187 return;
188 }
189
190 gboolean
191 launcher_menu_item_get_eclipsed (LauncherMenuItem * li)
192 {
193- const gchar * show = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(li), "show");
194+ const gchar * show = dbusmenu_menuitem_property_get(DBUSMENU_MENUITEM(li), DBUSMENU_MENUITEM_PROP_VISIBLE);
195 if (show == NULL) {
196 return FALSE;
197 }
198
199=== modified file 'src/launcher-menu-item.h'
200--- src/launcher-menu-item.h 2009-08-26 16:14:39 +0000
201+++ src/launcher-menu-item.h 2009-08-27 01:25:00 +0000
202@@ -56,6 +56,7 @@
203 LauncherMenuItem * launcher_menu_item_new (const gchar * desktop_file);
204 const gchar * launcher_menu_item_get_name (LauncherMenuItem * appitem);
205 const gchar * launcher_menu_item_get_desktop (LauncherMenuItem * launchitem);
206+const gchar * launcher_menu_item_get_description (LauncherMenuItem * li);
207 void launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed);
208 gboolean launcher_menu_item_get_eclipsed (LauncherMenuItem * li);
209
210
211=== modified file 'src/messages-service.c'
212--- src/messages-service.c 2009-08-26 17:44:48 +0000
213+++ src/messages-service.c 2009-08-26 21:47:55 +0000
214@@ -908,7 +908,7 @@
215 g_list_free(li->appdiritems);
216
217 if (li->menuitem != NULL) {
218- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li->menuitem), "visible", "false");
219+ dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li->menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, "false");
220 dbusmenu_menuitem_child_delete(root_menuitem, DBUSMENU_MENUITEM(li->menuitem));
221 g_object_unref(G_OBJECT(li->menuitem));
222 li->menuitem = NULL;

Subscribers

People subscribed via source and target branches

to all changes: