Merge lp:~dbarth/indicator-me/entry-hint into lp:indicator-me

Proposed by David Barth
Status: Merged
Merged at revision: 104
Proposed branch: lp:~dbarth/indicator-me/entry-hint
Merge into: lp:indicator-me
Diff against target: 368 lines (+189/-27)
5 files modified
src/dbus-shared-names.h (+1/-0)
src/indicator-me.c (+122/-25)
src/me-service-gwibber.c (+62/-2)
src/me-service-gwibber.h (+1/-0)
src/me-service.c (+3/-0)
To merge this branch: bzr merge lp:~dbarth/indicator-me/entry-hint
Reviewer Review Type Date Requested Status
Ted Gould (community) Needs Information
Cody Russell (community) Approve
Review via email: mp+35595@code.launchpad.net

Description of the change

Add a hint field to the broadcast field. The hint is computed from the list of protocols associated with accounts configured for broadcasting.

To post a comment you must log in.
lp:~dbarth/indicator-me/entry-hint updated
108. By David Barth

Fix the entry hint to be shown at the right time

Revision history for this message
Cody Russell (bratsche) :
review: Approve
Revision history for this message
Ted Gould (ted) wrote :

A few concerns.

 * This patch adds several translatable strings. So I don't think it can land for Maverick.
 * And this comment:
179 + /* this is dangerous: it leaves the signal connected even if the dbusmenu
180 + object is disposed, for example if the service quits
181 + */
   We should just remove the signal handler on distruction instead of not having it, or delete the code entirely if it's not needed.
 *

review: Needs Information

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/dbus-shared-names.h'
--- src/dbus-shared-names.h 2010-03-11 12:20:48 +0000
+++ src/dbus-shared-names.h 2010-09-16 14:51:54 +0000
@@ -32,6 +32,7 @@
3232
33#define DBUSMENU_ENTRY_MENUITEM_TYPE "x-canonical-entry-item"33#define DBUSMENU_ENTRY_MENUITEM_TYPE "x-canonical-entry-item"
34#define DBUSMENU_ENTRY_MENUITEM_PROP_TEXT "text"34#define DBUSMENU_ENTRY_MENUITEM_PROP_TEXT "text"
35#define DBUSMENU_ENTRY_MENUITEM_PROP_HINT "hint"
3536
36#define DBUSMENU_ABOUT_ME_MENUITEM_TYPE "x-canonical-about-me-item"37#define DBUSMENU_ABOUT_ME_MENUITEM_TYPE "x-canonical-about-me-item"
37#define DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME "name"38#define DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME "name"
3839
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c 2010-03-31 22:07:27 +0000
+++ src/indicator-me.c 2010-09-16 14:51:54 +0000
@@ -254,11 +254,112 @@
254}254}
255255
256static void256static void
257entry_hint_set_shown (GtkWidget *widget, gboolean flag)
258{
259 g_object_set_data (G_OBJECT (widget),
260 DBUSMENU_ENTRY_MENUITEM_PROP_HINT "_shown",
261 GUINT_TO_POINTER (flag));
262}
263
264
265static void
266entry_set_style (GtkEntry *entry, GtkStateType state)
267{
268 GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (entry));
269 GdkColor *color = &style->text[state];
270 gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, color);
271}
272
273static void
274entry_maybe_show_hint (GtkEntry *entry)
275{
276 g_return_if_fail (GTK_IS_ENTRY (entry));
277
278 const gchar *hint = g_object_get_data (G_OBJECT (entry),
279 DBUSMENU_ENTRY_MENUITEM_PROP_HINT);
280 if (gtk_entry_get_text_length (entry) > 0 ||
281 GTK_WIDGET_HAS_FOCUS (entry)) {
282 g_debug ("%s, the hint shouldn't be shown atm", __func__);
283
284 entry_set_style (entry, GTK_STATE_NORMAL);
285 entry_hint_set_shown (GTK_WIDGET (entry), FALSE);
286
287 } else {
288 g_debug ("%s, nothing in the entry or not focused, so setting the hint to: %s", __func__, hint);
289
290 gtk_entry_set_text (entry, hint);
291 entry_set_style (entry, GTK_STATE_INSENSITIVE);
292
293 entry_hint_set_shown (GTK_WIDGET (entry), TRUE);
294 }
295}
296
297
298static void
299entry_set_hint (GtkEntry *entry, const char *hint)
300{
301 g_debug ("entry hint: %s", hint);
302 g_object_set_data_full (G_OBJECT (entry), DBUSMENU_ENTRY_MENUITEM_PROP_HINT,
303 g_strdup (hint), (GDestroyNotify) g_free);
304 entry_maybe_show_hint (entry);
305}
306
307static gboolean
308entry_hint_is_shown (GtkWidget *widget)
309{
310 gboolean shown = GPOINTER_TO_UINT
311 (g_object_get_data (G_OBJECT (widget),
312 DBUSMENU_ENTRY_MENUITEM_PROP_HINT "_shown"));
313
314 return shown;
315}
316
317static gboolean
318entry_focus_grab_cb (GtkWidget *widget, GdkEventFocus *event)
319{
320 GtkEntry *entry = GTK_ENTRY (widget);
321 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
322 gboolean select_on_focus;
323
324 g_debug ("%s", __func__);
325
326 if (entry_hint_is_shown (GTK_WIDGET (entry))) {
327 /* override select-on-focus */
328 g_object_get (settings, "gtk-entry-select-on-focus", &select_on_focus, NULL);
329 g_object_set (settings, "gtk-entry-select-on-focus", FALSE, NULL);
330 gtk_entry_set_text (entry, "");
331 g_object_set (settings, "gtk-entry-select-on-focus", select_on_focus, NULL);
332 }
333
334 entry_set_style (entry, GTK_STATE_NORMAL);
335 entry_hint_set_shown (GTK_WIDGET (entry), FALSE);
336
337 return FALSE;
338}
339
340static gboolean
341entry_focus_ungrab_cb (GtkWidget *widget, GdkEventFocus *event)
342{
343 GtkEntry *entry = GTK_ENTRY (widget);
344
345 g_debug ("%s", __func__);
346
347 entry_maybe_show_hint (entry);
348
349 return FALSE;
350}
351
352static void
257entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GValue *value, GtkEntry *entry)353entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GValue *value, GtkEntry *entry)
258{354{
355 g_return_if_fail (GTK_IS_ENTRY (entry));
356
259 if (g_strcmp0 (prop, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) == 0) {357 if (g_strcmp0 (prop, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) == 0) {
260 gtk_entry_set_text (entry, g_value_get_string (value));358 gtk_entry_set_text (entry, g_value_get_string (value));
261 }359 }
360 if (g_strcmp0 (prop, DBUSMENU_ENTRY_MENUITEM_PROP_HINT) == 0) {
361 entry_set_hint (entry, g_value_get_string (value));
362 }
262}363}
263364
264static void365static void
@@ -277,31 +378,6 @@
277}378}
278379
279static gboolean380static gboolean
280menu_visibility_changed (GtkWidget *widget,
281 IdoEntryMenuItem *menuitem)
282{
283 if (GTK_IS_WIDGET (widget)
284 && IDO_IS_ENTRY_MENU_ITEM (menuitem))
285 gtk_menu_shell_select_item (GTK_MENU_SHELL (widget), GTK_WIDGET (menuitem));
286
287 return FALSE;
288}
289
290static void
291entry_parent_changed (GtkWidget *widget,
292 gpointer user_data)
293{
294 GtkWidget *parent = gtk_widget_get_parent (widget);
295
296 if (parent && GTK_IS_MENU_SHELL (parent))
297 {
298 g_signal_connect (parent,
299 "map", G_CALLBACK (menu_visibility_changed),
300 widget);
301 }
302}
303
304static gboolean
305new_entry_item (DbusmenuMenuitem * newitem,381new_entry_item (DbusmenuMenuitem * newitem,
306 DbusmenuMenuitem * parent,382 DbusmenuMenuitem * parent,
307 DbusmenuClient * client)383 DbusmenuClient * client)
@@ -314,14 +390,27 @@
314 GtkEntry *entry = GTK_ENTRY(ido_entry_menu_item_get_entry (ido));390 GtkEntry *entry = GTK_ENTRY(ido_entry_menu_item_get_entry (ido));
315 if (dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) != NULL)391 if (dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) != NULL)
316 gtk_entry_set_text(entry, dbusmenu_menuitem_property_get(newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT));392 gtk_entry_set_text(entry, dbusmenu_menuitem_property_get(newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT));
393 if (dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_HINT) != NULL) {
394 entry_set_hint (entry, dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_HINT));
395 }
396
317 gtk_entry_set_width_chars (entry, 23); /* set some nice aspect ratio for the menu */397 gtk_entry_set_width_chars (entry, 23); /* set some nice aspect ratio for the menu */
318 gtk_entry_set_max_length (entry, 140); /* enforce current gwibber limit */398 gtk_entry_set_max_length (entry, 140); /* enforce current gwibber limit */
319399
400 /* override select-on-focus */
401 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (entry));
402 g_object_set (settings, "gtk-entry-select-on-focus", FALSE, NULL);
403
320 ido_entry = ido;404 ido_entry = ido;
321405
406#if 0
407 /* this is dangerous: it leaves the signal connected even if the dbusmenu
408 object is disposed, for example if the service quits
409 */
322 g_signal_connect (ido,410 g_signal_connect (ido,
323 "notify::parent", G_CALLBACK (entry_parent_changed),411 "notify::parent", G_CALLBACK (entry_parent_changed),
324 NULL);412 NULL);
413#endif
325414
326 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);415 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);
327 /* disconnect the activate signal that newitem_base connected with the wrong416 /* disconnect the activate signal that newitem_base connected with the wrong
@@ -333,6 +422,14 @@
333 g_signal_connect (DBUSMENU_MENUITEM (newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK (entry_prop_change_cb), entry);422 g_signal_connect (DBUSMENU_MENUITEM (newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK (entry_prop_change_cb), entry);
334 g_signal_connect (GTK_ENTRY (entry), "activate", G_CALLBACK (entry_activate_cb), newitem);423 g_signal_connect (GTK_ENTRY (entry), "activate", G_CALLBACK (entry_activate_cb), newitem);
335424
425 g_signal_connect (entry,
426 "grab-focus", G_CALLBACK (entry_focus_grab_cb),
427 entry);
428
429 g_signal_connect (entry,
430 "grab-broken-event", G_CALLBACK (entry_focus_ungrab_cb),
431 entry);
432
336 return TRUE;433 return TRUE;
337}434}
338435
339436
=== modified file 'src/me-service-gwibber.c'
--- src/me-service-gwibber.c 2010-08-17 14:43:36 +0000
+++ src/me-service-gwibber.c 2010-09-16 14:51:54 +0000
@@ -22,7 +22,10 @@
2222
23#include "me-service-gwibber.h"23#include "me-service-gwibber.h"
2424
25#include <glib/gi18n.h>
26
25#include <glib.h>27#include <glib.h>
28#include <glib/gprintf.h>
2629
27#include <gwibber.h>30#include <gwibber.h>
2831
@@ -34,6 +37,7 @@
34 GwibberAccounts * me_gwibber_accounts;37 GwibberAccounts * me_gwibber_accounts;
35 int status;38 int status;
36 gboolean has_configured_accounts;39 gboolean has_configured_accounts;
40 gchar * accounts_string;
37};41};
3842
39/* Signals */43/* Signals */
@@ -89,6 +93,7 @@
89 priv->me_gwibber_accounts = NULL;93 priv->me_gwibber_accounts = NULL;
90 priv->status = ME_GWIBBER_SERVICE_STATUS_NOT_RUNNING;94 priv->status = ME_GWIBBER_SERVICE_STATUS_NOT_RUNNING;
91 priv->has_configured_accounts = FALSE;95 priv->has_configured_accounts = FALSE;
96 priv->accounts_string = NULL;
9297
93 setup_service_proxies(self);98 setup_service_proxies(self);
94 return;99 return;
@@ -109,6 +114,11 @@
109 priv->me_gwibber_accounts = NULL;114 priv->me_gwibber_accounts = NULL;
110 }115 }
111116
117 if (priv->accounts_string != NULL) {
118 g_free(priv->accounts_string);
119 priv->accounts_string = NULL;
120 }
121
112 G_OBJECT_CLASS (me_gwibber_service_parent_class)->dispose (object);122 G_OBJECT_CLASS (me_gwibber_service_parent_class)->dispose (object);
113 return;123 return;
114}124}
@@ -140,32 +150,72 @@
140150
141 if (priv->me_gwibber_accounts == NULL) {151 if (priv->me_gwibber_accounts == NULL) {
142 g_warning ("no accounts, can't query for accounts");152 g_warning ("no accounts, can't query for accounts");
143 return;153 goto reset_accounts_string;
144 }154 }
145 155
146 accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts);156 accounts_table = gwibber_accounts_list (priv->me_gwibber_accounts);
147 if (accounts_table == NULL) {157 if (accounts_table == NULL) {
148 g_warning ("failed to get accounts list");158 g_warning ("failed to get accounts list");
149 return;159 goto reset_accounts_string;
150 }160 }
151161
152 g_hash_table_iter_init (&accounts_iter, accounts_table);162 g_hash_table_iter_init (&accounts_iter, accounts_table);
153163
154 priv->has_configured_accounts = FALSE;164 priv->has_configured_accounts = FALSE;
165 GList *list = NULL;
155166
156 while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) {167 while (g_hash_table_iter_next (&accounts_iter, &account, &account_table)) {
157 send_enabled = check_account_send_enabled (account_table);168 send_enabled = check_account_send_enabled (account_table);
158 if (send_enabled) {169 if (send_enabled) {
159 priv->has_configured_accounts = TRUE;170 priv->has_configured_accounts = TRUE;
171 GValue *value = g_hash_table_lookup (account_table, "service");
172 if (value != NULL)
173 list = g_list_append (list,
174 g_strdup (g_value_get_string (value)));
160 }175 }
161 }176 }
162177
178 if (priv->accounts_string != NULL) {
179 g_free(priv->accounts_string);
180 priv->accounts_string = NULL;
181 }
182
183 guint len = g_list_length (list);
184 if (len > 0) {
185 GList *item0 = g_list_nth (list, 0);
186 GList *item1 = g_list_nth (list, 1);
187 if (len == 1)
188 priv->accounts_string = g_strconcat (_("Post to: "),
189 item0->data,
190 "...", NULL);
191 else if (len < 3)
192 priv->accounts_string = g_strconcat (_("Post to: "),
193 item0->data,
194 ", ",
195 item1->data,
196 "...", NULL);
197 else
198 priv->accounts_string = g_strdup (_("Post to: multiple networks..."));
199 g_debug ("accounts_string: %s", priv->accounts_string);
200 }
201
202 g_list_foreach (list, (GFunc) g_free, NULL);
203 g_list_free (list);
204
163 g_signal_emit (G_OBJECT (self),205 g_signal_emit (G_OBJECT (self),
164 ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID,206 ME_GWIBBER_SERVICE_SIGNAL_STATUS_CHANGED_ID,
165 0, priv->status, TRUE);207 0, priv->status, TRUE);
166208
167 g_hash_table_destroy(accounts_table);209 g_hash_table_destroy(accounts_table);
210
168 return;211 return;
212
213reset_accounts_string:
214
215 if (priv->accounts_string != NULL) {
216 g_free(priv->accounts_string);
217 priv->accounts_string = NULL;
218 }
169}219}
170220
171static void221static void
@@ -300,3 +350,13 @@
300350
301 return priv->has_configured_accounts;351 return priv->has_configured_accounts;
302}352}
353
354const gchar *
355me_gwibber_service_get_accounts_string (MeGwibberService *self)
356{
357 g_return_val_if_fail (IS_ME_GWIBBER_SERVICE (self), FALSE);
358
359 MeGwibberServicePrivate * priv = ME_GWIBBER_SERVICE_GET_PRIVATE(self);
360
361 return priv->accounts_string;
362}
303363
=== modified file 'src/me-service-gwibber.h'
--- src/me-service-gwibber.h 2010-08-16 15:11:05 +0000
+++ src/me-service-gwibber.h 2010-09-16 14:51:54 +0000
@@ -68,6 +68,7 @@
68MeGwibberService * me_gwibber_service_get (void);68MeGwibberService * me_gwibber_service_get (void);
69void me_gwibber_service_send (MeGwibberService *self, const gchar *msg);69void me_gwibber_service_send (MeGwibberService *self, const gchar *msg);
70gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self);70gboolean me_gwibber_service_has_configured_accounts (MeGwibberService *self);
71const gchar * me_gwibber_service_get_accounts_string (MeGwibberService *self);
7172
72G_END_DECLS73G_END_DECLS
7374
7475
=== modified file 'src/me-service.c'
--- src/me-service.c 2010-09-09 13:26:05 +0000
+++ src/me-service.c 2010-09-16 14:51:54 +0000
@@ -189,6 +189,8 @@
189 if (! dbusmenu_menuitem_property_get_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE))189 if (! dbusmenu_menuitem_property_get_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE))
190 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);190 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
191191
192 dbusmenu_menuitem_property_set (broadcast_field, DBUSMENU_ENTRY_MENUITEM_PROP_HINT, me_gwibber_service_get_accounts_string (instance));
193
192 return;194 return;
193}195}
194196
@@ -409,6 +411,7 @@
409#endif411#endif
410412
411 broadcast_field = DBUSMENU_MENUITEM (entry_menu_item_new());413 broadcast_field = DBUSMENU_MENUITEM (entry_menu_item_new());
414 dbusmenu_menuitem_property_set (broadcast_field, DBUSMENU_ENTRY_MENUITEM_PROP_HINT, _("Post message..."));
412 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);415 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
413 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);416 dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
414 dbusmenu_menuitem_child_append(root, broadcast_field);417 dbusmenu_menuitem_child_append(root, broadcast_field);

Subscribers

People subscribed via source and target branches