Author: juha
Date: 2006-10-13 14:28:31 +0000 (Fri, 13 Oct 2006)
New Revision: 23402

Modified:
   xfcalendar/trunk/panel-plugin/oc_config.c
   xfcalendar/trunk/panel-plugin/orageclock.c
   xfcalendar/trunk/panel-plugin/orageclock.h
Log:
made tooltip configurable. 



Modified: xfcalendar/trunk/panel-plugin/oc_config.c
===================================================================
--- xfcalendar/trunk/panel-plugin/oc_config.c   2006-10-13 12:53:43 UTC (rev 
23401)
+++ xfcalendar/trunk/panel-plugin/oc_config.c   2006-10-13 14:28:31 UTC (rev 
23402)
@@ -194,7 +194,7 @@
     gtk_container_set_border_width(GTK_CONTAINER(frame), 6);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, FALSE, FALSE, 0);
     
-    table = gtk_table_new(5, 2, FALSE);
+    table = gtk_table_new(3, 4, FALSE);
     gtk_container_set_border_width(GTK_CONTAINER(table), 10);
     gtk_table_set_row_spacings(GTK_TABLE(table), 6);
     gtk_table_set_col_spacings(GTK_TABLE(table), 6);
@@ -226,7 +226,7 @@
 
     /* background color */
     cb = gtk_check_button_new_with_mnemonic(_("set _background color:"));
-    oc_table_add(table, cb, 0, 2);
+    oc_table_add(table, cb, 2, 1);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->bg_set);
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_set_bg_toggled), clock);
 
@@ -234,17 +234,17 @@
         clock->bg = def_bg;
     }
     color = gtk_color_button_new_with_color(&clock->bg);
-    oc_table_add(table, color, 1, 2);
+    oc_table_add(table, color, 3, 1);
     g_signal_connect(G_OBJECT(color), "color-set"
             , G_CALLBACK(oc_bg_color_changed), clock);
 
     /* clock size (=vbox size): height and width */
     cb = gtk_check_button_new_with_mnemonic(_("set _height:"));
-    oc_table_add(table, cb, 0, 3);
+    oc_table_add(table, cb, 0, 2);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->height_set);
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_set_height_toggled), clock);
     sb = gtk_spin_button_new_with_range(10, 200, 1);
-    oc_table_add(table, sb, 1, 3);
+    oc_table_add(table, sb, 1, 2);
     if (!clock->height_set)
         clock->height = 32;
     gtk_spin_button_set_value(GTK_SPIN_BUTTON(sb), (gdouble)clock->height);
@@ -252,11 +252,11 @@
             G_CALLBACK(oc_set_height_changed), clock);
 
     cb = gtk_check_button_new_with_mnemonic(_("set _width:"));
-    oc_table_add(table, cb, 0, 4);
+    oc_table_add(table, cb, 2, 2);
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cb), clock->width_set);
     g_signal_connect(cb, "toggled", G_CALLBACK(oc_set_width_toggled), clock);
     sb = gtk_spin_button_new_with_range(10, 400, 1);
-    oc_table_add(table, sb, 1, 4);
+    oc_table_add(table, sb, 3, 2);
 
     if (!clock->width_set)
         clock->width = 70;
@@ -276,7 +276,7 @@
     gtk_container_set_border_width(GTK_CONTAINER(frame), 6);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), frame, FALSE, FALSE, 0);
 
-    table = gtk_table_new(4, 3, FALSE);
+    table = gtk_table_new(5, 3, FALSE);
     gtk_container_set_border_width(GTK_CONTAINER(table), 10);
     gtk_table_set_row_spacings(GTK_TABLE(table), 6);
     gtk_table_set_col_spacings(GTK_TABLE(table), 6);
@@ -371,7 +371,17 @@
     g_signal_connect(G_OBJECT(font), "font-set"
             , G_CALLBACK(oc_line_font_changed3), clock);
 
-    /* hints */
+    /* Tooltip hint */
+    label = gtk_label_new(_("Tooltip:"));
+    oc_table_add(table, label, 0, 4);
+
+    entry = gtk_entry_new();
+    gtk_entry_set_text(GTK_ENTRY(entry), clock->tooltip_data->str); 
+    oc_table_add(table, entry, 1, 4);
+    g_signal_connect(entry, "key-release-event", G_CALLBACK(oc_line_changed)
+            , clock->tooltip_data);
+
+    /* Instructions */
     hbox = gtk_hbox_new(FALSE, 0);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), hbox, FALSE, FALSE, 6);
 

Modified: xfcalendar/trunk/panel-plugin/orageclock.c
===================================================================
--- xfcalendar/trunk/panel-plugin/orageclock.c  2006-10-13 12:53:43 UTC (rev 
23401)
+++ xfcalendar/trunk/panel-plugin/orageclock.c  2006-10-13 14:28:31 UTC (rev 
23402)
@@ -44,83 +44,63 @@
  *                               Clock                                  *
  * -------------------------------------------------------------------- */
 
-
-static gboolean oc_date_tooltip(Clock *clock)
+static void utf8_strftime(char *res, int res_l, char *format, struct tm *tm)
 {
-    char date_s[255];
-    char *utf8date = NULL;
+    char *utf8res = NULL;
 
-    /* TRANSLATORS: Use format characters from strftime(3)
-     * to get the proper string for your locale.
-     * I used these:
-     * %A  : full weekday name
-     * %d  : day of the month
-     * %B  : full month name
-     * %Y  : four digit year
-     * %V  : ISO week number
-     */
-    strftime(date_s, 255
-            , g_locale_from_utf8( _("%A %d %B %Y/%V"), -1, NULL, NULL, NULL)
-            , &clock->now);
-
-    /* Conversion to utf8 */
-    if (!g_utf8_validate(date_s, -1, NULL)) {
-        utf8date = g_locale_to_utf8(date_s, -1, NULL, NULL, NULL);
+    /* strftime is nasty. It returns formatted characters (%A...) in utf8
+     * but it does not convert plain characters so they will be in locale 
+     * charset.
+     * We need to convert all formatting text first into utf8 to make
+     * sure all plain characters are also in utf8. Only that way, we can 
+     * be sure that all characters returned into res are in utf8 no matter
+     * what format is used */
+    strftime(res, res_l, g_locale_from_utf8(format, -1, NULL, NULL, NULL), tm);
+    /* Then convert to utf8 if needed */
+    if (!g_utf8_validate(res, -1, NULL)) {
+        utf8res = g_locale_to_utf8(res, -1, NULL, NULL, NULL);
+        if (utf8res) {
+            g_strlcpy(res, utf8res, res_l);
+            g_free(utf8res);
+        }
     }
+}
 
-    if (utf8date) {
-        gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(clock->plugin), 
-                utf8date, NULL);
-        g_free(utf8date);
-    }
-    else {
-        gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(clock->plugin), 
-                date_s, NULL);
-    }
+static void oc_tooltip_set(Clock *clock)
+{
+    char res[OC_MAX_LINE_LENGTH-1];
 
-    return(TRUE);
+    utf8_strftime(res, sizeof(res), clock->tooltip_data->str, &clock->now);
+    if (strcmp(res,  clock->tooltip_prev)) {
+        gtk_tooltips_set_tip(clock->tips, GTK_WIDGET(clock->plugin),res, NULL);
+        strcpy(clock->tooltip_prev, res);
+    }
 }
 
 static gboolean oc_get_time(Clock *clock)
 {
     time_t  t;
-    char    time_s[OC_MAX_LINE_LENGTH-1];
-    char    *utf8time_s = NULL;
+    char    res[OC_MAX_LINE_LENGTH-1];
     int     i;
-    static gint mday = -1;
     ClockLine *line;
 
     time(&t);
     localtime_r(&t, &clock->now);
-
     for (i = 0; i < OC_MAX_LINES; i++) {
         line = &clock->line[i];
         if (line->show) {
-            strftime(time_s, sizeof(time_s)
-                    , g_locale_from_utf8(line->data->str, -1, NULL, NULL, NULL)
-                    , &clock->now);
-            if (!g_utf8_validate(time_s, -1, NULL)) {
-                utf8time_s = g_locale_to_utf8(time_s, -1, NULL, NULL, NULL);
-                if (utf8time_s) {
-                    g_strlcpy(time_s, utf8time_s, sizeof(time_s));
-                    g_free(utf8time_s);
-                }
-            }
+            utf8_strftime(res, sizeof(res), line->data->str, &clock->now);
             /* gtk_label_set_text call takes almost
              * 100 % of the time wasted in this procedure 
              * */
-            if (strcmp(time_s,  line->prev)) {
-                gtk_label_set_text(GTK_LABEL(line->label), time_s);
-                strcpy(line->prev, time_s);
+            if (strcmp(res,  line->prev)) {
+                gtk_label_set_text(GTK_LABEL(line->label), res);
+                strcpy(line->prev, res);
             }
         }
     }
+    oc_tooltip_set(clock);
 
-    if (mday != clock->now.tm_mday) {
-        oc_date_tooltip(clock);
-        mday = clock->now.tm_mday;
-    }
-
     return(TRUE);
 }
 
@@ -305,6 +285,9 @@
         }
     }
 
+    if (ret = xfce_rc_read_entry(rc, "tooltip", NULL))
+        g_string_assign(clock->tooltip_data, ret); 
+
     xfce_rc_close(rc);
 }
 
@@ -382,6 +365,8 @@
         }
     }
 
+    xfce_rc_write_entry(rc, "tooltip",  clock->tooltip_data->str);
+
     xfce_rc_close(rc);
 }
 
@@ -423,6 +408,17 @@
         clock->line[i].font = g_string_new("");
     }
 
+    /* TRANSLATORS: Use format characters from strftime(3)
+     * to get the proper string for your locale.
+     * I used these:
+     * %A  : full weekday name
+     * %d  : day of the month
+     * %B  : full month name
+     * %Y  : four digit year
+     * %V  : ISO week number
+     */
+    clock->tooltip_data = g_string_new(_("%A %d %B %Y/%V"));
+
     clock->tips = gtk_tooltips_new();
     g_object_ref(clock->tips);
     gtk_object_sink(GTK_OBJECT(clock->tips));

Modified: xfcalendar/trunk/panel-plugin/orageclock.h
===================================================================
--- xfcalendar/trunk/panel-plugin/orageclock.h  2006-10-13 12:53:43 UTC (rev 
23401)
+++ xfcalendar/trunk/panel-plugin/orageclock.h  2006-10-13 14:28:31 UTC (rev 
23402)
@@ -51,6 +51,8 @@
     gchar     *TZ_orig;
     GtkWidget *tz_entry;
     ClockLine  line[OC_MAX_LINES];
+    GString   *tooltip_data;
+    gchar      tooltip_prev[OC_MAX_LINE_LENGTH+1];
 
     GtkTooltips *tips;
     int timeout_id;

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to