36
static void xfce_clock_digital_finalize (GObject *object);
37
static void xfce_clock_digital_set_property (GObject *object,
41
static void xfce_clock_digital_get_property (GObject *object,
34
static void xfce_clock_digital_set_property (GObject *object,
38
static void xfce_clock_digital_get_property (GObject *object,
42
static void xfce_clock_digital_finalize (GObject *object);
43
static gboolean xfce_clock_digital_update (gpointer user_data);
54
55
struct _XfceClockDigitalClass
56
GtkLabelClass __parent__;
57
GtkLabelClass __parent__;
59
60
struct _XfceClockDigital
63
/* current clock format */
64
ClockPluginTimeout *timeout;
69
G_DEFINE_TYPE (XfceClockDigital, xfce_clock_digital, GTK_TYPE_LABEL);
71
XFCE_PANEL_DEFINE_TYPE (XfceClockDigital, xfce_clock_digital, GTK_TYPE_LABEL)
74
76
xfce_clock_digital_class_init (XfceClockDigitalClass *klass)
76
GObjectClass *gobject_class;
78
gobject_class = G_OBJECT_CLASS (klass);
79
gobject_class->finalize = xfce_clock_digital_finalize;
80
gobject_class->set_property = xfce_clock_digital_set_property;
81
gobject_class->get_property = xfce_clock_digital_get_property;
84
* Digital clock format
86
g_object_class_install_property (gobject_class,
88
g_param_spec_string ("digital-format", "digital-format", "digital-format",
89
NULL, PANEL_PARAM_READWRITE));
78
GObjectClass *gobject_class;
80
gobject_class = G_OBJECT_CLASS (klass);
81
gobject_class->finalize = xfce_clock_digital_finalize;
82
gobject_class->set_property = xfce_clock_digital_set_property;
83
gobject_class->get_property = xfce_clock_digital_get_property;
85
g_object_class_install_property (gobject_class,
87
g_param_spec_double ("size-ratio", NULL, NULL,
90
| G_PARAM_STATIC_STRINGS));
92
g_object_class_install_property (gobject_class,
94
g_param_spec_enum ("orientation", NULL, NULL,
96
GTK_ORIENTATION_HORIZONTAL,
98
| G_PARAM_STATIC_STRINGS));
100
g_object_class_install_property (gobject_class,
102
g_param_spec_string ("digital-format", NULL, NULL,
103
DEFAULT_DIGITAL_FORMAT,
105
| G_PARAM_STATIC_STRINGS));
95
111
xfce_clock_digital_init (XfceClockDigital *digital)
98
digital->format = NULL;
101
gtk_label_set_justify (GTK_LABEL (digital), GTK_JUSTIFY_CENTER);
107
xfce_clock_digital_finalize (GObject *object)
109
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
112
g_free (digital->format);
114
(*G_OBJECT_CLASS (xfce_clock_digital_parent_class)->finalize) (object);
113
digital->format = g_strdup (DEFAULT_DIGITAL_FORMAT);
114
digital->timeout = clock_plugin_timeout_new (clock_plugin_interval_from_format (digital->format),
115
xfce_clock_digital_update,
118
gtk_label_set_justify (GTK_LABEL (digital), GTK_JUSTIFY_CENTER);
122
126
const GValue *value,
123
127
GParamSpec *pspec)
125
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
129
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
129
case PROP_DIGITAL_FORMAT:
131
g_free (digital->format);
134
digital->format = g_value_dup_string (value);
136
/* update the widget */
137
xfce_clock_digital_update (digital);
141
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133
case PROP_ORIENTATION:
134
gtk_label_set_angle (GTK_LABEL (object),
135
g_value_get_enum (value) == GTK_ORIENTATION_HORIZONTAL ?
139
case PROP_DIGITAL_FORMAT:
140
g_free (digital->format);
141
digital->format = g_value_dup_string (value);
145
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
149
/* reschedule the timeout and redraw */
150
clock_plugin_timeout_set_interval (digital->timeout,
151
clock_plugin_interval_from_format (digital->format));
152
xfce_clock_digital_update (digital);
152
161
GParamSpec *pspec)
154
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
163
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
158
case PROP_DIGITAL_FORMAT:
159
g_value_set_string (value, digital->format);
163
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
167
case PROP_DIGITAL_FORMAT:
168
g_value_set_string (value, digital->format);
171
case PROP_SIZE_RATIO:
172
g_value_set_double (value, -1.0);
176
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184
xfce_clock_digital_finalize (GObject *object)
186
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (object);
188
/* stop the timeout */
189
clock_plugin_timeout_free (digital->timeout);
191
g_free (digital->format);
193
(*G_OBJECT_CLASS (xfce_clock_digital_parent_class)->finalize) (object);
199
xfce_clock_digital_update (gpointer user_data)
201
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (user_data);
205
panel_return_val_if_fail (XFCE_CLOCK_IS_DIGITAL (digital), FALSE);
207
/* get the local time */
208
clock_plugin_get_localtime (&tm);
210
/* set time string */
211
string = clock_plugin_strdup_strftime (digital->format, &tm);
212
gtk_label_set_markup (GTK_LABEL (digital), string);
171
221
xfce_clock_digital_new (void)
173
return g_object_new (XFCE_CLOCK_TYPE_DIGITAL, NULL);
179
xfce_clock_digital_update (gpointer user_data)
181
XfceClockDigital *digital = XFCE_CLOCK_DIGITAL (user_data);
185
g_return_val_if_fail (XFCE_CLOCK_IS_DIGITAL (digital), FALSE);
187
/* get the local time */
188
xfce_clock_util_get_localtime (&tm);
191
string = xfce_clock_util_strdup_strftime (digital->format ? digital->format : DEFAULT_DIGITAL_FORMAT, &tm);
193
/* set the new label */
194
gtk_label_set_markup (GTK_LABEL (digital), string);
223
return g_object_new (XFCE_CLOCK_TYPE_DIGITAL, NULL);