[maemo-commits] [maemo-commits] r9659 - in projects/haf/branches/hildon-libs/hildon-1: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Feb 6 10:28:23 EET 2007
Author: xan
Date: 2007-02-06 10:28:22 +0200 (Tue, 06 Feb 2007)
New Revision: 9659

Modified:
   projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2
   projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.c
   projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.h
Log:
2007-02-06 Xan Lopez <xan.lopez at nokia.com> 

        * src/hildon-helper.c:
        * src/hildon-helper.h:

        Fix the insensitive message function to copy the string in the widget,
        as it might not valid anymore when the banner needs to be displayed.

        Also add a version with printf-like string formatting.



Modified: projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2	2007-02-06 08:23:03 UTC (rev 9658)
+++ projects/haf/branches/hildon-libs/hildon-1/ChangeLog.2	2007-02-06 08:28:22 UTC (rev 9659)
@@ -1,3 +1,13 @@
+2007-02-06 Xan Lopez <xan.lopez at nokia.com> 
+
+	* src/hildon-helper.c:
+	* src/hildon-helper.h:
+
+	Fix the insensitive message function to copy the string in the widget,
+	as it might not valid anymore when the banner needs to be displayed.
+
+	Also add a version with printf-like string formatting.
+
 2007-02-06  Michael Dominic Kostrzewa  <michael.kostrzewa at nokia.com> 
 
 	* examples/hildon-insensitive-example.c: Correcting the example for

Modified: projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.c
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.c	2007-02-06 08:23:03 UTC (rev 9658)
+++ projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.c	2007-02-06 08:28:22 UTC (rev 9659)
@@ -234,15 +234,33 @@
     return signum;
 }
 
+static GQuark
+hildon_helper_insensitive_message_quark (void)
+{
+  static GQuark quark = 0;
+
+  if (G_UNLIKELY (quark == 0))
+    quark = g_quark_from_static_string ("hildon-insensitive-message");
+
+  return quark;
+}
+
+
 static void
-show_insensitive_message                        (GtkWidget *widget, 
-                                                 const gchar *message)
+show_insensitive_message (GtkWidget *widget, gpointer user_data)
 {
-    g_assert (GTK_IS_WIDGET (widget));
+  gchar *message = NULL;
 
+  g_assert (GTK_IS_WIDGET (widget));
+
+  message = (gchar*) g_object_get_qdata (G_OBJECT (widget),
+					 hildon_helper_insensitive_message_quark ());
+
+  if (message)
     hildon_banner_show_information (widget, NULL, message);
 }
 
+
 /**
  * hildon_helper_set_insensitive_message
  * @widget : A @GtkWidget to assign a banner to
@@ -253,6 +271,7 @@
  * using a standard @HildonBanner. 
  *
  **/
+
 void
 hildon_helper_set_insensitive_message           (GtkWidget *widget,
                                                  const gchar *message)
@@ -260,17 +279,58 @@
     g_return_if_fail (GTK_IS_WIDGET (widget));
     g_return_if_fail (message != NULL);
 
+    gpointer stored_message;
+
+    /* Clean up any previous instance of the insensitive message */
     g_signal_handlers_disconnect_matched (G_OBJECT (widget), G_SIGNAL_MATCH_FUNC,
 					  0, 0, NULL,
-                      G_CALLBACK (show_insensitive_message), NULL);
+					  G_CALLBACK (show_insensitive_message), NULL);
+    
+    stored_message = g_object_get_qdata (G_OBJECT (widget), hildon_helper_insensitive_message_quark ());
+    if (stored_message)
+      g_free (stored_message);
 
+    /* We need to dup the string because the pointer might not be valid when the
+     insensitive-press signal callback is executed */
+    g_object_set_qdata_full (G_OBJECT (widget), hildon_helper_insensitive_message_quark (), 
+			     (gpointer)g_strdup (message),
+			     g_free);
+
     if (message != NULL) {
-        g_signal_connect (G_OBJECT (widget), "insensitive-press",
-                G_CALLBACK (show_insensitive_message), (gpointer) message);
+      g_signal_connect (G_OBJECT (widget), "insensitive-press",
+			G_CALLBACK (show_insensitive_message), NULL);
     }
 }
 
+/**
+ * hildon_helper_set_insensitive_messagef
+ * @widget : A @GtkWidget to assign a banner to
+ * @format : a printf-like format string
+ * @varargs : arguments for the format string
+ *
+ * A version of hildon_helper_set_insensitive_message with string formatting.
+ *
+ **/
 
+void
+hildon_helper_set_insensitive_messagef        (GtkWidget *widget,
+					       const gchar *format,
+					       ...)
+{
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  gchar *message;
+  va_list args;
+
+  va_start (args, format);
+  message = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  hildon_helper_set_insensitive_message (widget, message);
+
+  g_free (message);
+}
+
 /**
  * hildon_helper_set_logical_color:
  * @widget : A @GtkWidget to assign this logical font for.

Modified: projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.h
===================================================================
--- projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.h	2007-02-06 08:23:03 UTC (rev 9658)
+++ projects/haf/branches/hildon-libs/hildon-1/src/hildon-helper.h	2007-02-06 08:28:22 UTC (rev 9659)
@@ -48,6 +48,11 @@
 hildon_helper_set_insensitive_message           (GtkWidget *widget,
                                                  const gchar *message);
 
+void
+hildon_helper_set_insensitive_messagef          (GtkWidget *widget,
+						 const gchar *format,
+						 ...);
+
 G_END_DECLS
 
 #endif                                          /* HILDON_HELPER_H */


More information about the maemo-commits mailing list