[PATCH] Panel Clock Improvements: I18N tooltip, calender popup
Oliver M. Bolzer
oliver at fakeroot.net
Wed Dec 3 23:40:15 CET 2003
Hi!
Last weekend I finally got the time to try XFce and I love it! Great Work.
To get a feel for the code, I hacked the clock panel-plugin to add
the one feature I was most missing after leaving KDE's panel behind me.
- Calender Popup when clicking on the clock
The code is almost entirely taken from the datetime plugin Choe Hwanjin.
I liked the calender but prefered the clock from the standard pluin
more, so combined the best of both worlds.
The other patch is also for the clock plugin to internationalize
the date tooltip.
- Internationalize clock's tooltip
On a glibc system, passing %x to strftime would have been sufficent,
but that's not portable, hence nl_langinfo( D_FMT ). Because there
is no standartized format that also includes %a at the locale-dependent
place, it is not shown. An alternative would be to include locale-dependent
format-strings for strftime(3) in each locale's message catalog.
--
Oliver M. Bolzer
oliver at fakeroot.net
GPG (PGP) Fingerprint = 621B 52F6 2AC1 36DB 8761 018F 8786 87AD EF50 D1FF
-------------- next part --------------
--- xfce4-panel-4.0.0.final.orig/plugins/clock/clock.c 2003-07-18 23:02:26.000000000 +0200
+++ xfce4-panel-4.0.0.final.cal/plugins/clock/clock.c 2003-12-03 23:04:03.000000000 +0100
@@ -3,6 +3,7 @@
* Copyright (C) 2002 Jasper Huijsmans(huysmans at users.sourceforge.net)
* Xavier Maillard (zedek at fxgsproject.org)
* Olivier Fourdan (fourdan at xfce.org)
+ * Choe Hwanjin(krisna at kldp.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -85,7 +86,9 @@
{
GtkWidget *eventbox;
GtkWidget *clock; /* our XfceClock widget */
+ GtkWidget *calender; /* calender popup */
+ gint orientation; /* panel orientation */
int timeout_id; /* update the date tooltip */
}
t_clock;
@@ -115,6 +118,123 @@
}
ClockDialog;
+/* creation of calender popup */
+static GtkWidget *
+pop_calendar_window(GtkWidget *parent, int orientation)
+{
+ GtkWidget *window;
+ GtkWidget *cal;
+ gint parent_x, parent_y, parent_w, parent_h;
+ gint root_w, root_h;
+ gint width, height, x, y;
+ GtkRequisition requisition;
+ GtkAllocation allocation;
+
+ window = gtk_window_new(GTK_WINDOW_POPUP);
+
+ cal = gtk_calendar_new();
+ gtk_container_add(GTK_CONTAINER(window), cal);
+
+ gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
+ gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);
+
+ root_w = gdk_screen_width();
+ root_h = gdk_screen_height();
+
+ gtk_widget_realize(GTK_WIDGET(window));
+
+ gtk_widget_size_request(GTK_WIDGET(cal), &requisition);
+
+ allocation.x = requisition.width;
+ allocation.y = requisition.height;
+ gtk_widget_size_allocate(GTK_WIDGET(cal), &allocation);
+
+ gtk_widget_size_request(GTK_WIDGET(cal), &requisition);
+ width = requisition.width;
+ height = requisition.height;
+
+ if (orientation == GTK_ORIENTATION_VERTICAL) {
+ if (parent_x < root_w / 2) {
+ if (parent_y < root_h / 2) {
+ /* upper left */
+ x = parent_x + parent_w;
+ y = parent_y;
+ } else {
+ /* lower left */
+ x = parent_x + parent_w;
+ y = parent_y + parent_h - height;
+ }
+ } else {
+ if (parent_y < root_h / 2) {
+ /* upper right */
+ x = parent_x - width;
+ y = parent_y;
+ } else {
+ /* lower right */
+ x = parent_x - width;
+ y = parent_y + parent_h - height;
+ }
+ }
+ } else {
+ if (parent_x < root_w / 2) {
+ if (parent_y < root_h / 2) {
+ /* upper left */
+ x = parent_x;
+ y = parent_y + parent_h;
+ } else {
+ /* lower left */
+ x = parent_x;
+ y = parent_y - height;
+ }
+ } else {
+ if (parent_y < root_h / 2) {
+ /* upper right */
+ x = parent_x + parent_w - width;
+ y = parent_y + parent_h;
+ } else {
+ /* lower right */
+ x = parent_x + parent_w - width;
+ y = parent_y - height;
+ }
+ }
+ }
+
+ gtk_window_move(GTK_WINDOW(window), x, y);
+ gtk_widget_show(cal);
+ gtk_widget_show(window);
+
+ return window;
+}
+
+/* input handler for mouse clicks on clock*/
+static gboolean
+on_button_press_event_cb(GtkWidget *widget,
+ GdkEventButton *event, gpointer data)
+{
+ if (event->button == 1) {
+ t_clock *clock;
+
+ if (data == NULL)
+ return FALSE;
+
+ clock = (t_clock*)data;
+ if (clock->calender != NULL) {
+ gtk_widget_destroy(clock->calender);
+ clock->calender = NULL;
+ } else {
+ clock->calender = pop_calendar_window(clock->eventbox,
+ clock->orientation);
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+
/* creation and destruction */
gboolean
clock_date_tooltip (GtkWidget * widget)
@@ -162,6 +282,12 @@
/* Add tooltip to show the current date */
clock_date_tooltip (clock->eventbox);
+ /* Calender popup */
+ clock->calender = NULL;
+ clock->orientation = GTK_ORIENTATION_HORIZONTAL;
+ g_signal_connect( clock->eventbox, "button-press-event",
+ G_CALLBACK(on_button_press_event_cb), clock );
+
clock->timeout_id =
g_timeout_add (60000, (GSourceFunc) clock_date_tooltip,
clock->eventbox);
@@ -231,6 +357,14 @@
update_clock_size (tmp, size);
}
+void
+clock_set_orientation(Control *control, int orientation)
+{
+ t_clock *clock = control->data;
+ clock->orientation = orientation;
+}
+
+
/* Write the configuration at exit */
void
clock_write_config (Control * control, xmlNodePtr parent)
@@ -608,6 +742,7 @@
cc->create_options = clock_create_options;
cc->set_size = clock_set_size;
+ cc->set_orientation = clock_set_orientation;
}
/* macro defined in plugins.h */
-------------- next part --------------
diff -urN -x configure xfce4-panel-4.0.0.final.cal/aclocal.m4 xfce4-panel-4.0.0.final.intldate/aclocal.m4
--- xfce4-panel-4.0.0.final.cal/aclocal.m4 2003-09-21 11:39:23.000000000 +0200
+++ xfce4-panel-4.0.0.final.intldate/aclocal.m4 2003-12-03 20:42:26.000000000 +0100
@@ -7457,3 +7457,26 @@
fi
])
+# codeset.m4 serial AM1 (gettext-0.10.40)
+dnl Copyright (C) 2000-2002 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+dnl From Bruno Haible.
+
+AC_DEFUN([AM_LANGINFO_CODESET],
+[
+ AC_CACHE_CHECK([for nl_langinfo and CODESET], am_cv_langinfo_codeset,
+ [AC_TRY_LINK([#include <langinfo.h>],
+ [char* cs = nl_langinfo(CODESET);],
+ am_cv_langinfo_codeset=yes,
+ am_cv_langinfo_codeset=no)
+ ])
+ if test $am_cv_langinfo_codeset = yes; then
+ AC_DEFINE(HAVE_LANGINFO_CODESET, 1,
+ [Define if you have <langinfo.h> and nl_langinfo(CODESET).])
+ fi
+])
diff -urN -x configure xfce4-panel-4.0.0.final.cal/config.h.in xfce4-panel-4.0.0.final.intldate/config.h.in
--- xfce4-panel-4.0.0.final.cal/config.h.in 2003-08-01 18:52:37.000000000 +0200
+++ xfce4-panel-4.0.0.final.intldate/config.h.in 2003-12-03 19:10:51.000000000 +0100
@@ -24,6 +24,9 @@
/* Define if the GNU gettext() function is already present or preinstalled. */
#undef HAVE_GETTEXT
+/* Define if you have <langinfo.h> and nl_langinfo(CODESET). */
+#undef HAVE_LANGINFO_CODESET
+
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
diff -urN -x configure xfce4-panel-4.0.0.final.cal/configure.ac xfce4-panel-4.0.0.final.intldate/configure.ac
--- xfce4-panel-4.0.0.final.cal/configure.ac 2003-09-21 11:36:24.000000000 +0200
+++ xfce4-panel-4.0.0.final.intldate/configure.ac 2003-12-03 22:42:54.000000000 +0100
@@ -34,6 +34,7 @@
dnl Check for i18n support
BM_I18N([xfce4-panel], [ca de es es_MX fr fi hi hu lt ms nl ja ko pl pt_PT ru ta
tr zh_CN zh_TW])
+AM_LANGINFO_CODESET
dnl Check for X11 installed
BM_LIBX11_REQUIRE
diff -urN -x configure xfce4-panel-4.0.0.final.cal/plugins/clock/clock.c xfce4-panel-4.0.0.final.intldate/plugins/clock/clock.c
--- xfce4-panel-4.0.0.final.cal/plugins/clock/clock.c 2003-12-03 19:04:06.000000000 +0100
+++ xfce4-panel-4.0.0.final.intldate/plugins/clock/clock.c 2003-12-03 22:53:32.000000000 +0100
@@ -40,6 +40,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
#include <libxfce4util/i18n.h>
#include <libxfcegui4/xfce_clock.h>
@@ -251,6 +254,16 @@
ticks = time (0);
tm = localtime (&ticks);
+
+#ifdef D_FMT
+ int len;
+ gchar *utf8date;
+
+ len = strftime(date_s, sizeof(date_s) - 1, nl_langinfo( D_FMT ), tm );
+ date_s[len] = '\0';
+ utf8date = g_locale_to_utf8(date_s, len, NULL, NULL, NULL);
+ add_tooltip (widget, utf8date);
+#else
if ((mday != tm->tm_mday) || (wday != tm->tm_wday) || (mon != tm->tm_mon)
|| (year != tm->tm_year))
{
@@ -262,6 +275,7 @@
_(month_names[mon]), year + 1900);
add_tooltip (widget, _(date_s));
}
+#endif
return TRUE;
}
More information about the Xfce4-dev
mailing list