← Back to team overview

ayatana-commits team mailing list archive

[Branch ~indicator-applet-developers/indicator-me/trunk] Rev 104: first attempt at putting a hint in the entry

 

------------------------------------------------------------
revno: 104
committer: David Barth <david.barth@xxxxxxxxxxxxx>
branch nick: indicator-me.entry
timestamp: Fri 2010-09-10 09:29:03 +0200
message:
  first attempt at putting a hint in the entry
modified:
  src/dbus-shared-names.h
  src/indicator-me.c
  src/me-service.c


--
lp:indicator-me
https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk

Your team ayatana-commits is subscribed to branch lp:indicator-me.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk/+edit-subscription
=== 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-10 07:29:03 +0000
@@ -32,6 +32,7 @@
 
 #define DBUSMENU_ENTRY_MENUITEM_TYPE           "x-canonical-entry-item"
 #define DBUSMENU_ENTRY_MENUITEM_PROP_TEXT      "text"
+#define DBUSMENU_ENTRY_MENUITEM_PROP_HINT      "hint"
 
 #define DBUSMENU_ABOUT_ME_MENUITEM_TYPE           "x-canonical-about-me-item"
 #define DBUSMENU_ABOUT_ME_MENUITEM_PROP_NAME      "name"

=== modified file 'src/indicator-me.c'
--- src/indicator-me.c	2010-03-31 22:07:27 +0000
+++ src/indicator-me.c	2010-09-10 07:29:03 +0000
@@ -254,11 +254,66 @@
 }
 
 static void
+entry_maybe_show_hint (GtkEntry *entry)
+{
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
+  const gchar *hint = g_object_get_data (G_OBJECT (entry), DBUSMENU_ENTRY_MENUITEM_PROP_HINT);
+
+  if (gtk_entry_get_text_length (entry) > 0 ||
+      GTK_WIDGET_HAS_FOCUS (entry))
+    return;
+
+  gtk_entry_set_text (entry, hint);
+
+	GtkStyle *style = gtk_widget_get_style (GTK_WIDGET (entry));
+  GdkColor *color = &style->text[GTK_STATE_INSENSITIVE];
+  gtk_widget_modify_text (GTK_WIDGET (entry), GTK_STATE_NORMAL, color);
+}
+
+
+static void
+entry_set_hint (GtkEntry *entry, const char *hint)
+{
+    g_debug ("entry hint: %s", hint);
+		g_object_set_data_full (G_OBJECT (entry), DBUSMENU_ENTRY_MENUITEM_PROP_HINT,
+                            g_strdup (hint), (GDestroyNotify) g_free);
+    entry_maybe_show_hint (entry);
+}
+
+static gboolean
+entry_focus_in_cb (GtkWidget *widget, GdkEventFocus *event)
+{
+  // GtkEntry *entry = GTK_ENTRY (widget);
+
+  g_debug ("%s", __func__);
+
+  return FALSE;
+}
+
+static gboolean
+entry_focus_out_cb (GtkWidget *widget, GdkEventFocus *event)
+{
+  GtkEntry *entry = GTK_ENTRY (widget);
+
+  g_debug ("%s", __func__);
+
+  entry_maybe_show_hint (entry);
+
+  return FALSE;
+}
+
+static void
 entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GValue *value, GtkEntry *entry)
 {
+  g_return_if_fail (GTK_IS_ENTRY (entry));
+
 	if (g_strcmp0 (prop, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) == 0) {
 		gtk_entry_set_text (entry, g_value_get_string (value));
 	}
+	if (g_strcmp0 (prop, DBUSMENU_ENTRY_MENUITEM_PROP_HINT) == 0) {
+    entry_set_hint (entry, g_value_get_string (value));
+	}
 }
 
 static void
@@ -277,31 +332,6 @@
 }
 
 static gboolean
-menu_visibility_changed (GtkWidget          *widget,
-                         IdoEntryMenuItem   *menuitem)
-{
-  if (GTK_IS_WIDGET (widget)
-      && IDO_IS_ENTRY_MENU_ITEM (menuitem))
-    gtk_menu_shell_select_item (GTK_MENU_SHELL (widget), GTK_WIDGET (menuitem));
-
-  return FALSE;
-}
-
-static void
-entry_parent_changed (GtkWidget *widget,
-                      gpointer   user_data)
-{
-  GtkWidget *parent = gtk_widget_get_parent (widget);
-
-  if (parent && GTK_IS_MENU_SHELL (parent))
-    {
-      g_signal_connect (parent,
-                        "map", G_CALLBACK (menu_visibility_changed),
-                        widget);
-    }
-}
-
-static gboolean
 new_entry_item (DbusmenuMenuitem * newitem,
                 DbusmenuMenuitem * parent,
                 DbusmenuClient   * client)
@@ -314,14 +344,23 @@
 	GtkEntry *entry = GTK_ENTRY(ido_entry_menu_item_get_entry (ido));
 	if (dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT) != NULL)
 		gtk_entry_set_text(entry, dbusmenu_menuitem_property_get(newitem, DBUSMENU_ENTRY_MENUITEM_PROP_TEXT));
+	if (dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_HINT) != NULL) {
+    entry_set_hint (entry, dbusmenu_menuitem_property_get (newitem, DBUSMENU_ENTRY_MENUITEM_PROP_HINT));
+	}
+
 	gtk_entry_set_width_chars (entry, 23); /* set some nice aspect ratio for the menu */
   gtk_entry_set_max_length (entry, 140); /* enforce current gwibber limit */
 
   ido_entry = ido;
 
+#if 0
+  /* this is dangerous: it leaves the signal connected even if the dbusmenu
+     object is disposed, for example if the service quits
+  */
   g_signal_connect (ido,
                     "notify::parent", G_CALLBACK (entry_parent_changed),
                     NULL);
+#endif
 
 	dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent);
 	/* disconnect the activate signal that newitem_base connected with the wrong
@@ -333,6 +372,13 @@
 	g_signal_connect (DBUSMENU_MENUITEM (newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK (entry_prop_change_cb), entry);
 	g_signal_connect (GTK_ENTRY (entry), "activate", G_CALLBACK (entry_activate_cb), newitem);
 
+  g_signal_connect (entry,
+                    "focus-in-event", G_CALLBACK (entry_focus_in_cb),
+                    entry);
+  g_signal_connect (entry,
+                    "focus-out-event", G_CALLBACK (entry_focus_out_cb),
+                    entry);
+
 	return TRUE;
 }
 

=== modified file 'src/me-service.c'
--- src/me-service.c	2010-09-09 13:26:05 +0000
+++ src/me-service.c	2010-09-10 07:29:03 +0000
@@ -409,6 +409,7 @@
 #endif
 
   broadcast_field = DBUSMENU_MENUITEM (entry_menu_item_new());
+  dbusmenu_menuitem_property_set (broadcast_field, DBUSMENU_ENTRY_MENUITEM_PROP_HINT, "Post message...");
   dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
   dbusmenu_menuitem_property_set_bool (broadcast_field, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
   dbusmenu_menuitem_child_append(root, broadcast_field);