Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/plugins/clock/Makefile.am b/plugins/clock/Makefile.am
- index 923fb33..e0287d3 100644
- --- a/plugins/clock/Makefile.am
- +++ b/plugins/clock/Makefile.am
- @@ -25,7 +25,9 @@ libclock_la_SOURCES = \
- clock-fuzzy.c \
- clock-fuzzy.h \
- clock-lcd.c \
- - clock-lcd.h
- + clock-lcd.h \
- + clock-hex.c \
- + clock-hex.h
- libclock_la_CFLAGS = \
- $(GTK_CFLAGS) \
- diff --git a/plugins/clock/clock-dialog.glade b/plugins/clock/clock-dialog.glade
- index 68e9639..7f62476 100644
- --- a/plugins/clock/clock-dialog.glade
- +++ b/plugins/clock/clock-dialog.glade
- @@ -344,6 +344,43 @@
- <property name="position">8</property>
- </packing>
- </child>
- + <child>
- + <object class="GtkCheckButton" id="true-hex">
- + <property name="label" translatable="yes">True _hexadecimal time</property>
- + <property name="visible">True</property>
- + <property name="can_focus">True</property>
- + <property name="receives_default">False</property>
- + <property name="use_underline">True</property>
- + <property name="draw_indicator">True</property>
- + </object>
- + <packing>
- + <property name="position">1</property>
- + </packing>
- + </child>
- + <child>
- + <object class="GtkHBox" id="hex-box">
- + <property name="visible">True</property>
- + <property name="spacing">12</property>
- + <child>
- + <object class="GtkLabel" id="label9">
- + <property name="visible">True</property>
- + <property name="label" translatable="yes">F_ormat:</property>
- + <property name="use_underline">True</property>
- + </object>
- + <packing>
- + <property name="expand">False</property>
- + <property name="position">0</property>
- + </packing>
- + </child>
- + <child>
- + <object class="GtkEntry" id="hex-format">
- + <property name="visible">True</property>
- + <property name="text">5</property>
- + <property name="tooltip_text" translatable="yes">%H: hours, %X: maximes(true hex only), %M: minutes, %S: seconds (fake hex only). Case of identifier specifies digit case (0xa vs 0xA).</property>
- + </object>
- + </child>
- + </object>
- + </child>
- </object>
- </child>
- </object>
- @@ -436,6 +473,9 @@
- <row>
- <col id="0" translatable="yes">LCD</col>
- </row>
- + <row>
- + <col id="0" translatable="yes">Hexadecimal</col>
- + </row>
- </data>
- </object>
- </interface>
- diff --git a/plugins/clock/clock-hex.c b/plugins/clock/clock-hex.c
- new file mode 100644
- index 0000000..5a756a5
- --- /dev/null
- +++ b/plugins/clock/clock-hex.c
- @@ -0,0 +1,496 @@
- +/*
- + * Copyright (C) 2007-2010 Nick Schermer <nick@xfce.org>
- + * Copyright (C) 2012 Jonas Kulla <Nyocurio@gmail.com>
- + *
- + * This library is free software; you can redistribute it and/or modify it
- + * under the terms of the GNU General Public License as published by the Free
- + * Software Foundation; either version 2 of the License, or (at your option)
- + * any later version.
- + *
- + * This library is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- + * more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the Free Software
- + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + */
- +
- +#ifdef HAVE_CONFIG_H
- +#include <config.h>
- +#endif
- +
- +#ifdef HAVE_TIME_H
- +#include <time.h>
- +#endif
- +
- +#include <gtk/gtk.h>
- +
- +#include "clock.h"
- +#include "clock-hex.h"
- +
- +#define DEFAULT_FONT_SIZE 10
- +
- +
- +struct xtm
- +{
- + guint8 seconds : 4;
- + guint8 minutes : 4;
- + guint8 maximes : 4;
- + guint8 hours : 4;
- +};
- +
- +
- +static void xfce_clock_hex_set_property (GObject *object,
- + guint prop_id,
- + const GValue *value,
- + GParamSpec *pspec);
- +static void xfce_clock_hex_get_property (GObject *object,
- + guint prop_id,
- + GValue *value,
- + GParamSpec *pspec);
- +static void xfce_clock_hex_finalize (GObject *object);
- +static gboolean xfce_clock_hex_update (gpointer user_data);
- +static void xfce_clock_hex_update_font_size (XfceClockHex *hex);
- +
- +static void xfce_clock_hex_tm_to_xtm (const struct tm *_tm,
- + struct xtm *_xtm);
- +static gchar xfce_clock_hex_uint_to_xchar (guint u,
- + gboolean upcase);
- +static gchar * xfce_clock_hex_format_true_xtime (gchar *buffer,
- + gsize buffer_size,
- + const gchar *format,
- + struct xtm *xtime);
- +static gchar * xfce_clock_hex_format_fake_xtime (gchar *buffer,
- + gsize buffer_size,
- + const gchar *format,
- + struct tm *_time);
- +void xfce_clock_hex_write_hex_uint (gchar **bufferp,
- + guint u,
- + gboolean upcase,
- + gboolean leading_zero);
- +
- +
- +
- +enum
- +{
- + PROP_0,
- + PROP_TRUE_HEX,
- + PROP_HEX_FORMAT,
- + PROP_FONT_SIZE,
- + PROP_SIZE_RATIO,
- + PROP_ORIENTATION
- +};
- +
- +struct _XfceClockHexClass
- +{
- + GtkLabelClass __parent__;
- +};
- +
- +struct _XfceClockHex
- +{
- + GtkLabel __parent__;
- +
- + ClockPluginTimeout *timeout;
- +
- + guint true_hex : 1;
- + gchar *format;
- + guint font_size;
- +
- + struct xtm xtime;
- +};
- +
- +
- +
- +XFCE_PANEL_DEFINE_TYPE (XfceClockHex, xfce_clock_hex, GTK_TYPE_LABEL)
- +
- +
- +
- +static void
- +xfce_clock_hex_class_init (XfceClockHexClass *klass)
- +{
- + GObjectClass *gobject_class;
- +
- + gobject_class = G_OBJECT_CLASS (klass);
- + gobject_class->finalize = xfce_clock_hex_finalize;
- + gobject_class->set_property = xfce_clock_hex_set_property;
- + gobject_class->get_property = xfce_clock_hex_get_property;
- +
- + g_object_class_install_property (gobject_class,
- + PROP_SIZE_RATIO,
- + g_param_spec_double ("size-ratio", NULL, NULL,
- + -1, G_MAXDOUBLE, 0.0,
- + G_PARAM_READABLE
- + | G_PARAM_STATIC_STRINGS));
- +
- + g_object_class_install_property (gobject_class,
- + PROP_ORIENTATION,
- + g_param_spec_enum ("orientation", NULL, NULL,
- + GTK_TYPE_ORIENTATION,
- + GTK_ORIENTATION_HORIZONTAL,
- + G_PARAM_WRITABLE
- + | G_PARAM_STATIC_STRINGS));
- +
- + g_object_class_install_property (gobject_class,
- + PROP_TRUE_HEX,
- + g_param_spec_boolean ("true-hex", NULL, NULL,
- + TRUE,
- + G_PARAM_READWRITE
- + | G_PARAM_STATIC_STRINGS));
- +
- + g_object_class_install_property (gobject_class,
- + PROP_HEX_FORMAT,
- + g_param_spec_string ("hex-format", NULL, NULL,
- + DEFAULT_HEX_FORMAT,
- + G_PARAM_READWRITE
- + | G_PARAM_STATIC_STRINGS));
- +
- + g_object_class_install_property (gobject_class,
- + PROP_FONT_SIZE,
- + g_param_spec_uint ("font-size", NULL, NULL,
- + DEFAULT_FONT_SIZE, 0, G_MAXUINT,
- + G_PARAM_READABLE
- + | G_PARAM_STATIC_STRINGS));
- +}
- +
- +
- +
- +static void
- +xfce_clock_hex_init (XfceClockHex *hex)
- +{
- + hex->format = g_strdup (DEFAULT_HEX_FORMAT);
- + hex->timeout = clock_plugin_timeout_new (CLOCK_INTERVAL_SECOND, //FIXME: make this dependent on "true-hex"
- + xfce_clock_hex_update,
- + hex);
- +
- + gtk_label_set_justify (GTK_LABEL (hex), GTK_JUSTIFY_CENTER);
- + hex->font_size = DEFAULT_FONT_SIZE;
- + xfce_clock_hex_update_font_size (hex);
- +}
- +
- +
- +
- +static void
- +xfce_clock_hex_set_property (GObject *object,
- + guint prop_id,
- + const GValue *value,
- + GParamSpec *pspec)
- +{
- + XfceClockHex *hex = XFCE_CLOCK_HEX (object);
- +
- + switch (prop_id)
- + {
- + case PROP_ORIENTATION:
- + gtk_label_set_angle (GTK_LABEL (object),
- + g_value_get_enum (value) == GTK_ORIENTATION_HORIZONTAL ?
- + 0 : 270);
- + break;
- +
- + case PROP_TRUE_HEX:
- + hex->true_hex = g_value_get_boolean (value);
- + break;
- +
- + case PROP_HEX_FORMAT:
- + g_free (hex->format);
- + hex->format = g_value_dup_string (value);
- + break;
- +
- + case PROP_FONT_SIZE:
- + hex->font_size = g_value_get_uint (value);
- + xfce_clock_hex_update_font_size (hex);
- +
- + default:
- + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- + break;
- + }
- +
- + /* reschedule the timeout and redraw */
- + if (hex->true_hex)
- + {
- + clock_plugin_timeout_set_interval (hex->timeout,
- + CLOCK_INTERVAL_SECOND);
- + }
- + else
- + {
- + clock_plugin_timeout_set_interval (hex->timeout,
- + clock_plugin_interval_from_format (hex->format));
- + }
- +
- + xfce_clock_hex_update (hex);
- +}
- +
- +
- +
- +static void
- +xfce_clock_hex_get_property (GObject *object,
- + guint prop_id,
- + GValue *value,
- + GParamSpec *pspec)
- +{
- + XfceClockHex *hex = XFCE_CLOCK_HEX (object);
- +
- + switch (prop_id)
- + {
- + case PROP_TRUE_HEX:
- + g_value_set_boolean (value, hex->true_hex);
- + break;
- +
- + case PROP_HEX_FORMAT:
- + g_value_set_string (value, hex->format);
- + break;
- +
- + case PROP_SIZE_RATIO:
- + g_value_set_double (value, -1.0);
- + break;
- +
- + default:
- + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- + break;
- + }
- +}
- +
- +
- +
- +static void
- +xfce_clock_hex_finalize (GObject *object)
- +{
- + XfceClockHex *hex = XFCE_CLOCK_HEX (object);
- +
- + /* stop the timeout */
- + clock_plugin_timeout_free (hex->timeout);
- +
- + g_free (hex->format);
- +
- + (*G_OBJECT_CLASS (xfce_clock_hex_parent_class)->finalize) (object);
- +}
- +
- +
- +
- +static gboolean
- +xfce_clock_hex_update (gpointer user_data)
- +{
- + XfceClockHex *hex = XFCE_CLOCK_HEX (user_data);
- + gchar string[64];
- + struct tm tm;
- +
- + panel_return_val_if_fail (XFCE_CLOCK_IS_HEX (hex), FALSE);
- +
- + /* get the local time */
- + clock_plugin_get_localtime (&tm);
- +
- + if (hex->true_hex)
- + {
- + xfce_clock_hex_tm_to_xtm (&tm, &hex->xtime);
- + xfce_clock_hex_format_true_xtime (string, 64, hex->format, &hex->xtime);
- + }
- + else
- + {
- + xfce_clock_hex_format_fake_xtime (string, 64, hex->format, &tm);
- + }
- +
- + gtk_label_set_markup (GTK_LABEL (hex), string);
- +
- + return TRUE;
- +}
- +
- +
- +
- +
- +static void
- +xfce_clock_hex_update_font_size (XfceClockHex *hex)
- +{
- + gchar string[20];
- +
- + g_snprintf (string, 20, "Monospace %d", hex->font_size);
- + gtk_widget_modify_font (GTK_WIDGET(hex),
- + pango_font_description_from_string(string));
- +}
- +
- +
- +
- +static void
- +xfce_clock_hex_tm_to_xtm (const struct tm *_tm,
- + struct xtm *_xtm)
- +{
- + guint seconds_passed;
- + gdouble day_passed;
- + guint16 xsec_passed;
- +
- + seconds_passed = _tm->tm_sec + (_tm->tm_min * 60) + (_tm->tm_hour * 3600);
- + day_passed = (gdouble)seconds_passed / (60*60*24);
- +
- +//*((guint16*)&hex->xtime) = 0x10000 * day_passed;
- + xsec_passed = 0x10000 * day_passed;
- +
- + _xtm->seconds = (xsec_passed >> 0x0) & 0xF;
- + _xtm->minutes = (xsec_passed >> 0x4) & 0xF;
- + _xtm->maximes = (xsec_passed >> 0x8) & 0xF;
- + _xtm->hours = (xsec_passed >> 0xC) & 0xF;
- +}
- +
- +
- +
- +static gchar
- +xfce_clock_hex_uint_to_xchar (guint u,
- + gboolean upcase)
- +{
- + if (u < 10)
- + return u + '0';
- + else if (u < 16)
- + return (u - 10) + (upcase ? 'A' : 'a');
- + else
- + return 0;
- +}
- +
- +
- +
- +static gchar *
- +xfce_clock_hex_format_true_xtime (gchar *buffer,
- + gsize buffer_size,
- + const gchar *format,
- + struct xtm *xtime)
- +{
- + gsize chars_written = 0;
- + gboolean upcase;
- +
- + for ( ; *format; format++)
- + {
- + if (G_UNLIKELY(++chars_written == buffer_size))
- + break;
- +
- + if (*format != '%')
- + {
- + *(buffer++) = *format;
- + continue;
- + }
- +
- + upcase = *++format <= 'Z';
- +
- + switch (*format)
- + {
- + case 'H' :
- + case 'h' :
- + *buffer++ = xfce_clock_hex_uint_to_xchar (xtime->hours, upcase);
- + break;
- +
- + case 'X' :
- + case 'x' :
- + *buffer++ = xfce_clock_hex_uint_to_xchar (xtime->maximes, upcase);
- + break;
- +
- + case 'M' :
- + case 'm' :
- + *buffer++ = xfce_clock_hex_uint_to_xchar (xtime->minutes, upcase);
- + break;
- +
- + //case 'S' :
- + //case 's' :
- + //*buffer++ = xfce_clock_hex_uint_to_xchar (xtime->seconds, upcase);
- + //break;
- +
- + default :
- + *buffer++ = '%';
- + format--;
- + }
- + }
- +
- + *buffer = '\0';
- + return buffer;
- +}
- +
- +
- +
- +void
- +xfce_clock_hex_write_hex_uint (gchar **bufferp,
- + guint u,
- + gboolean upcase,
- + gboolean leading_zero)
- +{
- + gchar _conv[3];
- + gchar *conv = _conv;
- + gboolean two_digits = u > 0xF;
- +
- + g_snprintf (_conv, 3, "%x", u);
- +
- + if (upcase) { conv = g_ascii_strup (_conv, 3); }
- +
- + if (leading_zero && !two_digits)
- + {
- + *(*bufferp)++ = '0';
- + *(*bufferp)++ = conv[0];
- + }
- + else
- + {
- + *(*bufferp)++ = conv[0];
- + if (two_digits) { *(*bufferp)++ = conv[1]; }
- + }
- +
- + if (upcase) { g_free(conv); }
- +}
- +
- +
- +
- +static gchar *
- +xfce_clock_hex_format_fake_xtime (gchar *buffer,
- + gsize buffer_size,
- + const gchar *format,
- + struct tm *_time)
- +{
- + gsize chars_written = 0;
- + gboolean upcase;
- +
- + for ( ; *format; format++)
- + {
- + if (G_UNLIKELY(++chars_written == buffer_size))
- + break;
- +
- + if (*format != '%')
- + {
- + *(buffer++) = *format;
- + continue;
- + }
- +
- + if (chars_written + 1 == buffer_size)
- + break;
- +
- + upcase = *++format <= 'Z';
- +
- + switch (*format)
- + {
- + case 'H' :
- + case 'h' :
- + xfce_clock_hex_write_hex_uint (&buffer, _time->tm_hour, upcase, TRUE);
- + chars_written++;
- + break;
- +
- + case 'M' :
- + case 'm' :
- + xfce_clock_hex_write_hex_uint (&buffer, _time->tm_min, upcase, TRUE);
- + chars_written++;
- + break;
- +
- + case 'S' :
- + case 's' :
- + xfce_clock_hex_write_hex_uint (&buffer, _time->tm_sec, upcase, TRUE);
- + chars_written++;
- + break;
- +
- + default :
- + *buffer++ = '%';
- + format--;
- + }
- + }
- +
- + *buffer = '\0';
- + return buffer;
- +}
- +
- +
- +
- +
- +GtkWidget *
- +xfce_clock_hex_new (void)
- +{
- + return g_object_new (XFCE_CLOCK_TYPE_HEX, NULL);
- +}
- diff --git a/plugins/clock/clock-hex.h b/plugins/clock/clock-hex.h
- new file mode 100644
- index 0000000..248a9fd
- --- /dev/null
- +++ b/plugins/clock/clock-hex.h
- @@ -0,0 +1,45 @@
- +/*
- + * Copyright (C) 2007-2010 Nick Schermer <nick@xfce.org>
- + * Copyright (C) 2012 Jonas Kulla <Nyocurio@gmail.com>
- + *
- + * This library is free software; you can redistribute it and/or modify it
- + * under the terms of the GNU General Public License as published by the Free
- + * Software Foundation; either version 2 of the License, or (at your option)
- + * any later version.
- + *
- + * This library is distributed in the hope that it will be useful, but WITHOUT
- + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- + * more details.
- + *
- + * You should have received a copy of the GNU Lesser General Public
- + * License along with this library; if not, write to the Free Software
- + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- + */
- +
- +#ifndef __CLOCK_HEX_H__
- +#define __CLOCK_HEX_H__
- +
- +G_BEGIN_DECLS
- +
- +#define DEFAULT_HEX_FORMAT " %H_%X%M "
- +
- +typedef struct _XfceClockHexClass XfceClockHexClass;
- +typedef struct _XfceClockHex XfceClockHex;
- +
- +#define XFCE_CLOCK_TYPE_HEX (xfce_clock_hex_get_type ())
- +#define XFCE_CLOCK_HEX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_CLOCK_TYPE_HEX, XfceClockHex))
- +#define XFCE_CLOCK_HEX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_HEX, XfceClockHexClass))
- +#define XFCE_CLOCK_IS_HEX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_CLOCK_TYPE_HEX))
- +#define XFCE_CLOCK_IS_HEX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_CLOCK_TYPE_HEX))
- +#define XFCE_CLOCK_HEX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_CLOCK_TYPE_HEX, XfceClockHexClass))
- +
- +GType xfce_clock_hex_get_type (void) G_GNUC_CONST;
- +
- +void xfce_clock_hex_register_type (XfcePanelTypeModule *type_module);
- +
- +GtkWidget *xfce_clock_hex_new (void) G_GNUC_MALLOC;
- +
- +G_END_DECLS
- +
- +#endif /* !__CLOCK_HEX_H__ */
- diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
- index 2e38943..72ba83e 100644
- --- a/plugins/clock/clock.c
- +++ b/plugins/clock/clock.c
- @@ -42,6 +42,7 @@
- #include "clock-fuzzy.h"
- #include "clock-lcd.h"
- #include "clock-dialog_ui.h"
- +#include "clock-hex.h"
- #define DEFAULT_TOOLTIP_FORMAT "%A %d %B %Y"
- @@ -94,10 +95,11 @@ typedef enum
- CLOCK_PLUGIN_MODE_DIGITAL,
- CLOCK_PLUGIN_MODE_FUZZY,
- CLOCK_PLUGIN_MODE_LCD,
- + CLOCK_PLUGIN_MODE_HEX,
- /* defines */
- CLOCK_PLUGIN_MODE_MIN = CLOCK_PLUGIN_MODE_ANALOG,
- - CLOCK_PLUGIN_MODE_MAX = CLOCK_PLUGIN_MODE_LCD,
- + CLOCK_PLUGIN_MODE_MAX = CLOCK_PLUGIN_MODE_HEX,
- CLOCK_PLUGIN_MODE_DEFAULT = CLOCK_PLUGIN_MODE_DIGITAL
- }
- ClockPluginMode;
- @@ -172,7 +174,8 @@ XFCE_PANEL_DEFINE_PLUGIN (ClockPlugin, clock_plugin,
- xfce_clock_binary_register_type,
- xfce_clock_digital_register_type,
- xfce_clock_fuzzy_register_type,
- - xfce_clock_lcd_register_type)
- + xfce_clock_lcd_register_type,
- + xfce_clock_hex_register_type)
- @@ -566,6 +569,8 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
- { "fuzziness-box", "fuzziness", "value" },
- { "show-inactive", "show-inactive", "active" },
- { "show-grid", "show-grid", "active" },
- + { "true-hex", "true-hex", "active" },
- + { "hex-box", "hex-format", "text" },
- };
- panel_return_if_fail (GTK_IS_COMBO_BOX (combo));
- @@ -596,6 +601,10 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox *combo,
- active = 1 << 1 | 1 << 3 | 1 << 4 | 1 << 5;
- break;
- + case CLOCK_PLUGIN_MODE_HEX:
- + active = 1 << 10 | 1 << 11;
- + break;
- +
- default:
- panel_assert_not_reached ();
- active = 0;
- @@ -805,7 +814,7 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
- static void
- clock_plugin_set_mode (ClockPlugin *plugin)
- {
- - const PanelProperty properties[][5] =
- + const PanelProperty properties[][6] =
- {
- { /* analog */
- { "show-seconds", G_TYPE_BOOLEAN },
- @@ -832,6 +841,11 @@ clock_plugin_set_mode (ClockPlugin *plugin)
- { "show-meridiem", G_TYPE_BOOLEAN },
- { "flash-separators", G_TYPE_BOOLEAN },
- { NULL },
- + },
- + { /* hex */
- + { "true-hex", G_TYPE_BOOLEAN },
- + { "hex-format", G_TYPE_STRING },
- + { NULL },
- }
- };
- GtkOrientation orientation;
- @@ -850,8 +864,10 @@ clock_plugin_set_mode (ClockPlugin *plugin)
- plugin->clock = xfce_clock_digital_new ();
- else if (plugin->mode == CLOCK_PLUGIN_MODE_FUZZY)
- plugin->clock = xfce_clock_fuzzy_new ();
- - else
- + else if (plugin->mode == CLOCK_PLUGIN_MODE_LCD)
- plugin->clock = xfce_clock_lcd_new ();
- + else
- + plugin->clock = xfce_clock_hex_new ();
- if (plugin->rotate_vertically)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement