aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkarl-qdh <karl@qdh.org.uk>2011-02-16 13:21:33 +0000
committerkarl-qdh <karl@qdh.org.uk>2011-02-16 13:21:33 +0000
commit97a6b5ae809cd6df25a95207a69da7d93c49bf8e (patch)
treedbb89564ac6080480aecc68f5b13b7faac9733b8 /src
parentaf5f67f6a005f3cfd23af998ef16cc8c507edba1 (diff)
parent37fc0a3158e5ff5f8cf9096de49451379c2d11f1 (diff)
downloadayatana-indicator-datetime-97a6b5ae809cd6df25a95207a69da7d93c49bf8e.tar.gz
ayatana-indicator-datetime-97a6b5ae809cd6df25a95207a69da7d93c49bf8e.tar.bz2
ayatana-indicator-datetime-97a6b5ae809cd6df25a95207a69da7d93c49bf8e.zip
Added myerrys branch
Diffstat (limited to 'src')
-rw-r--r--src/datetime-service.c40
-rw-r--r--src/indicator-datetime.c64
2 files changed, 61 insertions, 43 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index e2313f8..8390652 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -145,6 +145,8 @@ check_timezone_sync (void) {
dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, label);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone");
+ dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
+ dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE);
} else {
g_debug("Label for current location is null, this shouldn't happen");
}
@@ -153,6 +155,7 @@ check_timezone_sync (void) {
dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, geo_timezone);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_RIGHT, "+tzone");
+ dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
}
} else {
// TODO work out the geo location name in a nice way
@@ -210,7 +213,7 @@ update_current_timezone (void) {
return;
}
-/* See how our timezone setting went
+/* See how our timezone setting went */
static void
quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data)
{
@@ -220,26 +223,31 @@ quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data)
g_warning("Unable to quick set timezone");
}
return;
-}*/
+}
-/* Set the timezone to the Geoclue discovered one
+/* Set the timezone to the Geoclue discovered one */
static void
-quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, const gchar *command)
+quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data)
{
- g_debug("Quick setting timezone to: %s", geo_timezone);
+ const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_LABEL);
+
+ g_debug("Quick setting timezone to: %s", tz);
- g_return_if_fail(geo_timezone != NULL);
+ g_return_if_fail(tz != NULL);
+
+ if (g_strcmp0(tz, current_timezone) == 0)
+ return;
OobsObject * obj = oobs_time_config_get();
g_return_if_fail(obj != NULL);
OobsTimeConfig * timeconfig = OOBS_TIME_CONFIG(obj);
- oobs_time_config_set_timezone(timeconfig, geo_timezone);
+ oobs_time_config_set_timezone(timeconfig, tz);
oobs_object_commit_async(obj, quick_set_tz_cb, NULL);
return;
-}*/
+}
/* Updates the label in the date menuitem */
static gboolean
@@ -359,15 +367,15 @@ update_timezone_menu_items(gpointer user_data) {
}
guint len = g_strv_length(locations);
DbusmenuMenuitem *item;
- gint i;
+ gint i, offset;
/* Remove all of the previous locations */
if (dconflocations != NULL) {
g_debug("Freeing old locations");
- while (appointments != NULL) {
+ while (dconflocations != NULL) {
DbusmenuMenuitem * litem = DBUSMENU_MENUITEM(dconflocations->data);
g_debug("Freeing old location: %p", litem);
- // Remove all the existing menu items which are in appointments.
+ // Remove all the existing menu items which are in dconflocations.
dconflocations = g_list_remove(dconflocations, litem);
dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem));
g_object_unref(G_OBJECT(litem));
@@ -385,6 +393,7 @@ update_timezone_menu_items(gpointer user_data) {
return FALSE;
}
+ offset = dbusmenu_menuitem_get_position (current_location, root)+1;
for (i = 0; i < len; i++) {
// Iterate over configured places and add any which aren't already listed
if (g_strcmp0(locations[i], current_timezone) != 0 &&
@@ -397,9 +406,8 @@ update_timezone_menu_items(gpointer user_data) {
dbusmenu_menuitem_property_set_bool (item, TIMEZONE_MENUITEM_PROP_RADIO, FALSE);
dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE);
dbusmenu_menuitem_property_set_bool (item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
- dbusmenu_menuitem_child_add_position (root, item,
- dbusmenu_menuitem_get_position (locations_separator, root)+3);
- //g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
+ dbusmenu_menuitem_child_add_position (root, item, offset++);
+ g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
dconflocations = g_list_append(dconflocations, item);
}
}
@@ -717,7 +725,7 @@ build_menus (DbusmenuMenuitem * root)
dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_LABEL, "Updating location information...");
dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
- //g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
+ g_signal_connect(G_OBJECT(geo_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
dbusmenu_menuitem_child_append(root, geo_location);
current_location = dbusmenu_menuitem_new();
@@ -725,7 +733,7 @@ build_menus (DbusmenuMenuitem * root)
dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_LABEL, "Current Timezone");
dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE);
dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- //g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
+ g_signal_connect(G_OBJECT(current_location), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(quick_set_tz), NULL);
dbusmenu_menuitem_child_append(root, current_location);
check_timezone_sync();
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index a9b77b9..0f60428 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -105,7 +105,7 @@ enum {
typedef struct _indicator_item_t indicator_item_t;
struct _indicator_item_t {
- GtkWidget * radio;
+ GtkWidget * gmi;
GtkWidget * icon;
GtkWidget * label;
GtkWidget * right;
@@ -176,7 +176,6 @@ static void update_time (IndicatorDatetime * self);
static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
static gint generate_strftime_bitmask (const char *time_str);
-static GSList *location_group = NULL;
/* Indicator Module Config */
INDICATOR_SET_VERSION
@@ -1070,14 +1069,14 @@ generate_format_string (IndicatorDatetime * self)
/* Whenever we have a property change on a DbusmenuMenuitem
we need to be responsive to that. */
static void
-indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, indicator_item_t * mi_data)
+indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, indicator_item_t * mi_data)
{
if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_LABEL)) {
/* Set the main label */
- gtk_label_set_text(GTK_LABEL(mi_data->label), value);
+ gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL));
} else if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_RIGHT)) {
/* Set the right label */
- gtk_label_set_text(GTK_LABEL(mi_data->right), value);
+ gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL));
} else if (!g_strcmp0(prop, APPOINTMENT_MENUITEM_PROP_ICON)) {
/* We don't use the value here, which is probably less efficient,
but it's easier to use the easy function. And since th value
@@ -1108,12 +1107,12 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, in
}
} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_LABEL)) {
/* Set the main label */
- gtk_label_set_text(GTK_LABEL(mi_data->label), value);
+ gtk_label_set_text(GTK_LABEL(mi_data->label), g_variant_get_string(value, NULL));
} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RIGHT)) {
/* Set the right label */
- gtk_label_set_text(GTK_LABEL(mi_data->right), value);
+ gtk_label_set_text(GTK_LABEL(mi_data->right), g_variant_get_string(value, NULL));
} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) {
- //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio), value);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value));
} else {
g_warning("Indicator Item property '%s' unknown", prop);
}
@@ -1135,7 +1134,7 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu
indicator_item_t * mi_data = g_new0(indicator_item_t, 1);
- GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
+ mi_data->gmi = gtk_menu_item_new();
GtkWidget * hbox = gtk_hbox_new(FALSE, 4);
@@ -1186,10 +1185,10 @@ new_appointment_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbu
gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0);
gtk_widget_show(mi_data->right);
- gtk_container_add(GTK_CONTAINER(gmi), hbox);
+ gtk_container_add(GTK_CONTAINER(mi_data->gmi), hbox);
gtk_widget_show(hbox);
- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
+ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent);
g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data);
g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data);
@@ -1225,6 +1224,22 @@ new_calendar_item (DbusmenuMenuitem * newitem,
return TRUE;
}
+static void
+timezone_toggled_cb (GtkCheckMenuItem *checkmenuitem, DbusmenuMenuitem * dbusitem)
+{
+ /* Make sure that the displayed radio-active setting is always
+ consistent with the dbus menuitem */
+ gtk_check_menu_item_set_active(checkmenuitem,
+ dbusmenu_menuitem_property_get_bool(dbusitem, TIMEZONE_MENUITEM_PROP_RADIO));
+}
+
+static void
+timezone_destroyed_cb (DbusmenuMenuitem * dbusitem, indicator_item_t * mi_data)
+{
+ g_signal_handlers_disconnect_by_func(G_OBJECT(mi_data->gmi), G_CALLBACK(timezone_toggled_cb), dbusitem);
+ g_free(mi_data);
+}
+
static gboolean
new_timezone_item(DbusmenuMenuitem * newitem,
DbusmenuMenuitem * parent,
@@ -1238,41 +1253,36 @@ new_timezone_item(DbusmenuMenuitem * newitem,
// Menu item with a radio button and a right aligned time
indicator_item_t * mi_data = g_new0(indicator_item_t, 1);
- GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new());
+ mi_data->gmi = gtk_check_menu_item_new();
+
+ gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(mi_data->gmi), TRUE);
+ gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi),
+ dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO));
GtkWidget * hbox = gtk_hbox_new(FALSE, 4);
- mi_data->radio = gtk_radio_button_new(location_group);
- if (location_group == NULL)
- location_group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(mi_data->radio));
-
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mi_data->radio),
- dbusmenu_menuitem_property_get_bool(newitem, TIMEZONE_MENUITEM_PROP_RADIO));
-
- gtk_box_pack_start(GTK_BOX(hbox), mi_data->radio, FALSE, FALSE, 0);
- gtk_widget_show(mi_data->radio);
-
/* Label, probably a username, chat room or mailbox name */
- mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, APPOINTMENT_MENUITEM_PROP_LABEL));
+ mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_LABEL));
gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, 0);
gtk_widget_show(mi_data->label);
/* Usually either the time or the count on the individual
item. */
- mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, APPOINTMENT_MENUITEM_PROP_RIGHT));
+ mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, TIMEZONE_MENUITEM_PROP_RIGHT));
gtk_size_group_add_widget(indicator_right_group, mi_data->right);
gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0);
gtk_widget_show(mi_data->right);
- gtk_container_add(GTK_CONTAINER(gmi), hbox);
+ gtk_container_add(GTK_CONTAINER(mi_data->gmi), hbox);
gtk_widget_show(hbox);
- dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent);
+ dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent);
+ g_signal_connect(G_OBJECT(mi_data->gmi), "toggled", G_CALLBACK(timezone_toggled_cb), newitem);
g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data);
- g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data);
+ g_signal_connect(G_OBJECT(newitem), "destroyed", G_CALLBACK(timezone_destroyed_cb), mi_data);
return TRUE;
}