[PATCH] Customizable time format of menu panel clock.



Hello.

I wrote a patch for gnome-core/panel/foobar-widget.c

It provides customizable format of menu panel clock.
It add "Customize..." into the "Format" menu, it launch Property Box.

See the screenshot at
    http://www.gnome.gr.jp/~kitame/panel/panel.png

How about this?

Regards.
-- 
Takuo Kitame <kitame@northeye.org>

--- gnome-core-1.2.1/panel/foobar-widget.c.orig	Tue Aug  8 09:23:33 2000
+++ gnome-core-1.2.1/panel/foobar-widget.c	Tue Aug  8 10:18:25 2000
@@ -26,6 +26,7 @@
 #include "gnome-run.h"
 
 #define SMALL_ICON_SIZE 20
+#define TIME_FORMAT_SIZE 64
 
 extern GlobalConfig global_config;
 extern GList *panel_list;
@@ -40,6 +41,7 @@
 static GtkWidget *clock_ebox = NULL;
 
 static GtkWindowClass *parent_class = NULL;
+static GtkWidget *fooclock_property = NULL;
 
 GtkType
 foobar_widget_get_type (void)
@@ -326,7 +328,7 @@
 	GtkWidget *label = GTK_WIDGET (data);
 	struct tm *das_tm;
 	time_t das_time;
-	char hour[20];
+	char hour[TIME_FORMAT_SIZE];
 
 	if (!IS_FOOBAR_WIDGET (das_global_foobar))
 		return FALSE;
@@ -335,15 +337,15 @@
 	das_tm = localtime (&das_time);
 
 	if (das_tm->tm_mday != day) {
-		if (strftime (hour, 20, _("%A %B %d"), das_tm) == 20)
-			hour[19] = '\0';
+		if (strftime (hour, TIME_FORMAT_SIZE, _("%A %B %d"), das_tm) == TIME_FORMAT_SIZE)
+			hour[TIME_FORMAT_SIZE - 1] = '\0';
 		gtk_tooltips_set_tip (panel_tooltips, clock_ebox, hour, NULL);
 
 		day = das_tm->tm_mday;
 	}
 
-	if (strftime (hour, 20, FOOBAR_WIDGET (das_global_foobar)->clock_format, das_tm) == 20)
-		hour[19] = '\0';
+	if (strftime (hour, TIME_FORMAT_SIZE, FOOBAR_WIDGET (das_global_foobar)->clock_format, das_tm) == TIME_FORMAT_SIZE)
+		hour[TIME_FORMAT_SIZE - 1] = '\0';
 
 	gtk_label_set_text (GTK_LABEL (label), hour);
 
@@ -367,16 +369,97 @@
 }
 
 static void
+fooclock_property_apply (GnomePropertyBox *pb, gint page, gpointer data)
+{
+	char *format;
+
+    format = g_strdup (gtk_entry_get_text (GTK_ENTRY(data)));
+    set_fooclock_format(NULL, format);
+    g_free (format);
+    gnome_property_box_set_state (pb, FALSE);
+}
+
+static void
+fooclock_property_changed (GtkWidget *w, gpointer data)
+{
+	GtkWidget *p = GTK_WIDGET (data);
+    
+    gnome_property_box_set_state (GNOME_PROPERTY_BOX (p), TRUE);
+}
+
+static void
+fooclock_property_cb (GtkWidget *w, gpointer data)
+{
+    GtkWidget *tab_label;
+    GtkWidget *vbox;
+    GtkWidget *hbox;
+    GtkWidget *entry;
+    GtkWidget *label;
+
+    if (fooclock_property) {
+        gtk_widget_grab_focus (fooclock_property);
+        return;
+    }
+
+    fooclock_property = gnome_property_box_new ();
+    tab_label = gtk_label_new (_("Time format"));
+
+    vbox = gtk_vbox_new (FALSE, 5);
+
+    hbox = gtk_hbox_new (FALSE, 5);
+    label = gtk_label_new (_("strftime format string "));
+    entry = gtk_entry_new ();
+    gtk_entry_set_max_length (GTK_ENTRY (entry), TIME_FORMAT_SIZE);
+    gtk_entry_set_text (GTK_ENTRY (entry),
+                        FOOBAR_WIDGET (das_global_foobar)->clock_format);
+
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 3);
+    gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 3);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 3);
+
+    label = gtk_label_new (_("ex: %m/%d %H:%M"));
+    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
+
+    gtk_widget_show_all (vbox);
+    gnome_property_box_append_page (GNOME_PROPERTY_BOX (fooclock_property),
+                                    vbox, tab_label);
+
+    gtk_signal_connect (GTK_OBJECT (fooclock_property), "apply",
+                        GTK_SIGNAL_FUNC (fooclock_property_apply),
+                        entry);
+
+    gtk_signal_connect (GTK_OBJECT (entry), "changed",
+                        GTK_SIGNAL_FUNC (fooclock_property_changed),
+                        fooclock_property);
+
+    gnome_dialog_run (GNOME_DIALOG (fooclock_property));
+
+    fooclock_property = NULL;
+}
+
+static void
+append_customize_item (GtkWidget *menu)
+{
+	GtkWidget *item;
+
+	item = gtk_menu_item_new_with_label (_("Customize..."));
+	gtk_menu_append (GTK_MENU (menu), item);
+	gtk_signal_connect (GTK_OBJECT (item), "activate",
+			    GTK_SIGNAL_FUNC (fooclock_property_cb),
+			    NULL);
+}
+
+static void
 append_format_item (GtkWidget *menu, const char *format)
 {
-	char hour[20];
+	char hour[TIME_FORMAT_SIZE];
 	GtkWidget *item;
 	struct tm *das_tm;
 	time_t das_time = 0;
 
 	das_tm = localtime (&das_time);
-	if (strftime (hour, 20, _(format), das_tm) == 20)
-		hour[19] = '\0';
+	if (strftime (hour, TIME_FORMAT_SIZE, _(format), das_tm) == TIME_FORMAT_SIZE)
+		hour[TIME_FORMAT_SIZE - 1] = '\0';
 
 	item = gtk_menu_item_new_with_label (hour);
 	gtk_menu_append (GTK_MENU (menu), item);
@@ -423,6 +506,8 @@
 	menu2 = gtk_menu_new ();
 	for (i=0; formats[i]; i++)
 		append_format_item (menu2, formats[i]);
+
+    append_customize_item (menu2);
 
 	add_tearoff (GTK_MENU (menu2));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]