42
40
struct _IdoLocationMenuItemPrivate
48
44
guint timestamp_timer;
50
GtkWidget * name_label;
51
GtkWidget * timestamp_label;
54
47
typedef IdoLocationMenuItemPrivate priv_t;
56
G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, GTK_TYPE_MENU_ITEM);
49
G_DEFINE_TYPE (IdoLocationMenuItem, ido_location_menu_item, IDO_TYPE_TIME_STAMP_MENU_ITEM);
59
52
**** Timestamp Label
63
update_timestamp_label (IdoLocationMenuItem * self)
56
update_timestamp (IdoLocationMenuItem * self)
65
priv_t * p = self->priv;
67
if (p->format && *p->format)
73
tz = g_time_zone_new (p->timezone);
75
tz = g_time_zone_new_local ();
76
now = g_date_time_new_now (tz);
77
str = g_date_time_format (now, p->format);
79
gtk_label_set_text (GTK_LABEL(p->timestamp_label), str);
82
g_date_time_unref (now);
83
g_time_zone_unref (tz);
87
gtk_label_set_text (GTK_LABEL(p->timestamp_label), "");
59
GDateTime * date_time;
61
tz = g_time_zone_new (self->priv->timezone);
63
tz = g_time_zone_new_local ();
64
date_time = g_date_time_new_now (tz);
66
ido_time_stamp_menu_item_set_date_time (IDO_TIME_STAMP_MENU_ITEM(self),
69
g_date_time_unref (date_time);
70
g_time_zone_unref (tz);
103
static void start_timestamp_timer (IdoLocationMenuItem * self);
85
static void restart_timestamp_timer (IdoLocationMenuItem * self);
106
88
on_timestamp_timer (gpointer gself)
108
90
IdoLocationMenuItem * self = IDO_LOCATION_MENU_ITEM (gself);
110
update_timestamp_label (self);
92
update_timestamp (self);
112
start_timestamp_timer (self);
94
restart_timestamp_timer (self);
113
95
return G_SOURCE_REMOVE;
146
start_timestamp_timer (IdoLocationMenuItem * self)
128
restart_timestamp_timer (IdoLocationMenuItem * self)
130
const char * fmt = ido_time_stamp_menu_item_get_format (IDO_TIME_STAMP_MENU_ITEM (self));
131
gboolean timestamp_shows_seconds;
148
132
int interval_sec;
149
gboolean timestamp_shows_seconds;
150
priv_t * p = self->priv;
151
const char * const fmt = p->format;
153
134
stop_timestamp_timer (self);
182
163
switch (property_id)
185
g_value_set_string (value, p->name);
188
165
case PROP_TIMEZONE:
189
166
g_value_set_string (value, p->timezone);
193
g_value_set_string (value, p->format);
197
170
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
210
183
switch (property_id)
213
ido_location_menu_item_set_name (self, g_value_get_string (value));
216
185
case PROP_TIMEZONE:
217
186
ido_location_menu_item_set_timezone (self, g_value_get_string (value));
221
ido_location_menu_item_set_format (self, g_value_get_string (value));
225
190
G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec);
265
226
gobject_class->dispose = my_dispose;
266
227
gobject_class->finalize = my_finalize;
268
prop_flags = G_PARAM_CONSTRUCT
270
| G_PARAM_STATIC_STRINGS;
272
properties[PROP_NAME] = g_param_spec_string (
274
"The location's name",
275
"The name to display; eg, 'Oklahoma City'",
279
229
properties[PROP_TIMEZONE] = g_param_spec_string (
281
231
"timezone identifier",
282
232
"string used to identify a timezone; eg, 'America/Chicago'",
286
properties[PROP_FORMAT] = g_param_spec_string (
289
"strftime-style format string for the timestamp",
234
G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
293
236
g_object_class_install_properties (gobject_class, PROP_LAST, properties);
297
240
ido_location_menu_item_init (IdoLocationMenuItem *self)
303
242
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
304
243
IDO_LOCATION_MENU_ITEM_TYPE,
305
244
IdoLocationMenuItemPrivate);
309
p->name_label = gtk_label_new (NULL);
310
gtk_misc_set_alignment (GTK_MISC(p->name_label), 0.0, 0.5);
312
p->timestamp_label = gtk_label_new (NULL);
313
gtk_misc_set_alignment (GTK_MISC(p->timestamp_label), 1.0, 0.5);
317
gtk_grid_attach (grid, p->name_label, 0, 0, 1, 1);
318
gtk_grid_attach (grid, p->timestamp_label, 1, 0, 1, 1);
319
g_object_set (p->name_label,
320
"halign", GTK_ALIGN_START,
323
"valign", GTK_ALIGN_CENTER,
325
g_object_set (p->timestamp_label,
326
"halign", GTK_ALIGN_END,
328
"valign", GTK_ALIGN_CENTER,
331
gtk_widget_show_all (w);
332
gtk_container_add (GTK_CONTAINER (self), w);
246
/* Update the timer whenever the format string changes
247
because it determines whether we update once per second or per minute */
248
g_signal_connect (self, "notify::format",
249
G_CALLBACK(restart_timestamp_timer), NULL);
348
* ido_location_menu_item_set_name:
349
* @name: human-readable name, such as a city (eg: "Oklahoma City")
351
* Sets this location's name, for display in the menuitem's primary label.
354
ido_location_menu_item_set_name (IdoLocationMenuItem * self,
359
g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self));
363
p->name = g_strdup (name);
364
gtk_label_set_text (GTK_LABEL(p->name_label), p->name);
368
264
* ido_location_menu_item_set_timezone:
369
265
* @timezone: timezone identifier (eg: "America/Chicago")
383
279
g_free (p->timezone);
384
280
p->timezone = g_strdup (timezone);
385
update_timestamp_label (self);
389
* ido_location_menu_item_set_format:
390
* @format: the format string used when showing the location's time
392
* Set the format string for rendering the location's time
393
* in its right-justified secondary label.
395
* See strfrtime(3) for more information on the format string.
398
ido_location_menu_item_set_format (IdoLocationMenuItem * self,
403
g_return_if_fail (IDO_IS_LOCATION_MENU_ITEM (self));
407
p->format = g_strdup (format);
408
update_timestamp_label (self);
409
start_timestamp_timer (self);
281
update_timestamp (self);
437
309
if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
439
GParameter p = { "name", G_VALUE_INIT };
311
GParameter p = { "text", G_VALUE_INIT };
440
312
g_value_init (&p.value, G_TYPE_STRING);
441
313
g_value_take_string (&p.value, str);
442
314
parameters[n++] = p;