Browse Source

* plugins/clock/clock-digital.c: Allow markup and center the string.

* plugins/clock/*: Move the localtime functions into 1 util and allow usage without locatime_r.


(Old svn revision: 25899)
upstream/xfce4-panel-4.10.1
Nick Schermer 15 years ago
parent
commit
626ecc46fe
  1. 6
      ChangeLog
  2. 3
      plugins/clock/clock-analog.c
  3. 3
      plugins/clock/clock-binary.c
  4. 3
      plugins/clock/clock-dialog.c
  5. 8
      plugins/clock/clock-digital.c
  6. 6
      plugins/clock/clock-lcd.c
  7. 25
      plugins/clock/clock.c
  8. 3
      plugins/clock/clock.h

6
ChangeLog

@ -1,3 +1,9 @@
2007-07-08 12:00 nick
* plugins/clock/clock-digital.c: Allow markup and center the string.
* plugins/clock/*: Move the localtime functions into 1 util and allow
usage without locatime_r.
2007-07-07 10:32 nick
* plugins/clock/clock-lcd.c: Typo, the 8 was test code.

3
plugins/clock/clock-analog.c

@ -232,7 +232,6 @@ xfce_clock_analog_expose_event (GtkWidget *widget,
gdouble xc, yc;
gdouble angle, radius;
cairo_t *cr;
time_t now = time (0);
struct tm tm;
g_return_val_if_fail (XFCE_CLOCK_IS_ANALOG (clock), FALSE);
@ -252,7 +251,7 @@ xfce_clock_analog_expose_event (GtkWidget *widget,
if (G_LIKELY (cr != NULL))
{
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* set the line properties */
cairo_set_line_width (cr, 1);

3
plugins/clock/clock-binary.c

@ -264,7 +264,6 @@ xfce_clock_binary_expose_event (GtkWidget *widget,
gint decimal_bcd[] = {80, 40, 20, 10, 8, 4, 2, 1};
cairo_t *cr;
GdkColor active, inactive;
time_t now = time (0);
struct tm tm;
g_return_val_if_fail (XFCE_CLOCK_IS_BINARY (clock), FALSE);
@ -298,7 +297,7 @@ xfce_clock_binary_expose_event (GtkWidget *widget,
if (G_LIKELY (cr != NULL))
{
/* get the current time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* walk the three or two time parts */
for (i = 0; i < columns; i++)

3
plugins/clock/clock-dialog.c

@ -318,13 +318,12 @@ xfce_clock_dialog_append_combobox_formats (GtkComboBox *combo,
const gchar *current_format)
{
gint i;
time_t now = time (0);
struct tm tm;
gchar *string;
gboolean has_active = FALSE;
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
for (i = 0; formats[i] != NULL; i++)
{

8
plugins/clock/clock-digital.c

@ -121,6 +121,9 @@ xfce_clock_digital_init (XfceClockDigital *clock)
{
/* init */
clock->format = NULL;
/* center text */
gtk_label_set_justify (GTK_LABEL (clock), GTK_JUSTIFY_CENTER);
}
@ -202,20 +205,19 @@ xfce_clock_digital_update (gpointer user_data)
{
XfceClockDigital *clock = XFCE_CLOCK_DIGITAL (user_data);
gchar *string;
time_t now = time (0);
struct tm tm;
g_return_val_if_fail (XFCE_CLOCK_IS_DIGITAL (clock), FALSE);
g_return_val_if_fail (clock->format != NULL, FALSE);
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* get the string */
string = xfce_clock_util_strdup_strftime (clock->format, &tm);
/* set the new label */
gtk_label_set_text (GTK_LABEL (clock), string);
gtk_label_set_markup (GTK_LABEL (clock), string);
/* cleanup */
g_free (string);

6
plugins/clock/clock-lcd.c

@ -282,7 +282,6 @@ xfce_clock_lcd_expose_event (GtkWidget *widget,
gdouble offset_x, offset_y;
gint ticks, i;
gdouble size;
time_t now = time (0);
struct tm tm;
g_return_val_if_fail (XFCE_CLOCK_IS_LCD (clock), FALSE);
@ -303,7 +302,7 @@ xfce_clock_lcd_expose_event (GtkWidget *widget,
if (G_LIKELY (cr != NULL))
{
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* draw the hours */
ticks = tm.tm_hour;
@ -372,11 +371,10 @@ xfce_clock_lcd_get_ratio (XfceClockLcd *clock)
{
gdouble ratio;
gint ticks;
time_t now = time (0);
struct tm tm;
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* hour + minutes */
ratio = (3 * 0.5 + 6 * RELATIVE_SPACE);

25
plugins/clock/clock.c

@ -54,6 +54,23 @@ XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (xfce_clock_plugin_construct);
/** utilities **/
void
xfce_clock_util_get_localtime (struct tm *tm)
{
time_t now = time (0);
#ifndef HAVE_LOCALTIME_R
struct tm *tmbuf;
tmbuf = localtime (&now);
*tm = *tmbuf;
#else
localtime_r (&now, tm);
#endif
}
static guint
xfce_clock_util_interval_from_format (const gchar *format)
{
@ -93,7 +110,6 @@ xfce_clock_util_interval_from_format (const gchar *format)
static guint
xfce_clock_util_next_interval (guint timeout_interval)
{
time_t now = time (0);
struct tm tm;
GTimeVal timeval;
guint interval;
@ -105,7 +121,7 @@ xfce_clock_util_next_interval (guint timeout_interval)
interval = 1000 - (timeval.tv_usec / 1000);
/* get current time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* add the interval time to the next update */
switch (timeout_interval)
@ -165,9 +181,8 @@ xfce_clock_tooltip_update (gpointer user_data)
{
ClockPlugin *clock = (ClockPlugin *) user_data;
gchar *string;
time_t now = time (0);
struct tm tm;
static GtkTooltips *tooltips = NULL;
struct tm tm;
g_return_val_if_fail (clock->tooltip_format != NULL, TRUE);
@ -176,7 +191,7 @@ xfce_clock_tooltip_update (gpointer user_data)
tooltips = gtk_tooltips_new ();
/* get the local time */
localtime_r (&now, &tm);
xfce_clock_util_get_localtime (&tm);
/* get the string */
string = xfce_clock_util_strdup_strftime (clock->tooltip_format, &tm);

3
plugins/clock/clock.h

@ -82,6 +82,9 @@ struct _ClockPlugin
};
void xfce_clock_util_get_localtime (struct tm *tm) G_GNUC_INTERNAL;
gchar *xfce_clock_util_strdup_strftime (const gchar *format,
const struct tm *tm) G_GNUC_MALLOC G_GNUC_INTERNAL;

Loading…
Cancel
Save