[Goodies-commits] r4907 - xfce4-datetime-plugin/trunk/panel-plugin

Diego Ongaro ongardie at xfce.org
Sun Jun 8 01:16:02 CEST 2008


Author: ongardie
Date: 2008-06-07 23:16:02 +0000 (Sat, 07 Jun 2008)
New Revision: 4907

Modified:
   xfce4-datetime-plugin/trunk/panel-plugin/datetime.c
   xfce4-datetime-plugin/trunk/panel-plugin/datetime.h
Log:
Efficiently show tooltips when appropriate


Modified: xfce4-datetime-plugin/trunk/panel-plugin/datetime.c
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/datetime.c	2008-06-07 23:15:57 UTC (rev 4906)
+++ xfce4-datetime-plugin/trunk/panel-plugin/datetime.c	2008-06-07 23:16:02 UTC (rev 4907)
@@ -36,8 +36,6 @@
 #include "datetime.h"
 #include "datetime-dialog.h"
 
-#define USE_GTK_TOOLTIP_API     GTK_CHECK_VERSION(2,12,0)
-
 #define DATETIME_MAX_STRLEN 256
 
 /**
@@ -129,14 +127,16 @@
   g_get_current_time(&timeval);
   current = localtime((time_t *)&timeval.tv_sec);
 
-  if (datetime->date_format != NULL && GTK_IS_LABEL(datetime->date_label))
+  if (datetime->layout != LAYOUT_TIME &&
+      datetime->date_format != NULL && GTK_IS_LABEL(datetime->date_label))
   {
     utf8str = datetime_do_utf8strftime(datetime->date_format, current);
     gtk_label_set_text(GTK_LABEL(datetime->date_label), utf8str);
     g_free(utf8str);
   }
 
-  if (datetime->time_format != NULL && GTK_IS_LABEL(datetime->time_label))
+  if (datetime->layout != LAYOUT_DATE &&
+      datetime->time_format != NULL && GTK_IS_LABEL(datetime->time_label))
   {
     utf8str = datetime_do_utf8strftime(datetime->time_format, current);
     gtk_label_set_text(GTK_LABEL(datetime->time_label), utf8str);
@@ -157,7 +157,44 @@
   return TRUE;
 }
 
+#if USE_GTK_TOOLTIP_API
+static gboolean datetime_query_tooltip(GtkWidget *widget,
+                                       gint x, gint y,
+                                       gboolean keyboard_mode,
+                                       GtkTooltip *tooltip,
+                                       t_datetime *datetime)
+{
+  GTimeVal timeval;
+  struct tm *current;
+  gchar *utf8str;
+  gchar *format = NULL;
 
+  switch(datetime->layout)
+  {
+    case LAYOUT_TIME:
+      format = datetime->date_format;
+      break;
+    case LAYOUT_DATE:
+      format = datetime->time_format;
+      break;
+    default:
+      break;
+  }
+
+  if (format == NULL)
+    return FALSE;
+
+  g_get_current_time(&timeval);
+  current = localtime((time_t *)&timeval.tv_sec);
+
+  utf8str = datetime_do_utf8strftime(format, current);
+  gtk_tooltip_set_text(tooltip, utf8str);
+  g_free(utf8str);
+
+  return TRUE;
+}
+#endif
+
 static void on_calendar_realized(GtkWidget *widget, gpointer data)
 {
   gint parent_x, parent_y, parent_w, parent_h;
@@ -386,6 +423,28 @@
       break;
   }
 
+#if USE_GTK_TOOLTIP_API
+  /* update tooltip handler */
+  if (datetime->tooltip_id)
+  {
+    g_signal_handler_disconnect(datetime->button,
+                                datetime->tooltip_id);
+    datetime->tooltip_id = 0;
+  }
+  switch(datetime->layout)
+  {
+    case LAYOUT_DATE:
+    case LAYOUT_TIME:
+      gtk_widget_set_has_tooltip(GTK_WIDGET(datetime->button), TRUE);
+      datetime->tooltip_id = g_signal_connect(datetime->button, "query-tooltip",
+                                 G_CALLBACK(datetime_query_tooltip), datetime);
+      break;
+
+    default:
+      gtk_widget_set_has_tooltip(GTK_WIDGET(datetime->button), FALSE);
+  }
+#endif
+
   /* set order based on layout-selection */
   switch(datetime->layout)
   {

Modified: xfce4-datetime-plugin/trunk/panel-plugin/datetime.h
===================================================================
--- xfce4-datetime-plugin/trunk/panel-plugin/datetime.h	2008-06-07 23:15:57 UTC (rev 4906)
+++ xfce4-datetime-plugin/trunk/panel-plugin/datetime.h	2008-06-07 23:16:02 UTC (rev 4907)
@@ -21,6 +21,8 @@
 #ifndef DATETIME_H
 #define DATETIME_H
 
+#define USE_GTK_TOOLTIP_API     GTK_CHECK_VERSION(2,12,0)
+
 /* enums */
 enum {
   DATE = 0,
@@ -46,6 +48,9 @@
   GtkTooltips *tips;
   guint update_interval;  /* time between updates in milliseconds */
   guint timeout_id;
+#if USE_GTK_TOOLTIP_API
+  gulong tooltip_id;
+#endif
 
   /* settings */
   gchar *date_font;




More information about the Goodies-commits mailing list