aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/datetime-service.c64
-rw-r--r--src/dbus-shared.h3
-rw-r--r--src/indicator-datetime.c10
-rw-r--r--src/utils.c13
5 files changed, 37 insertions, 55 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 7e8ac4b..6d388c7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,8 @@ indicator_datetime_service_SOURCES = \
calendar-menu-item.c \
calendar-menu-item.h \
datetime-service.c \
+ utils.c \
+ utils.h \
dbus-shared.h \
settings-shared.h
indicator_datetime_service_CFLAGS = \
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 45efbf6..ab609c4 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -53,6 +53,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "datetime-interface.h"
#include "dbus-shared.h"
#include "settings-shared.h"
+#include "utils.h"
static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data);
@@ -90,6 +91,16 @@ static GeoclueAddress * geo_address = NULL;
static gchar * current_timezone = NULL;
static gchar * geo_timezone = NULL;
+static void
+set_timezone_label (DbusmenuMenuitem * mi, const gchar * location)
+{
+ gchar * zone, * name;
+ split_settings_location (location, &zone, &name);
+
+ dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_NAME, name);
+ dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_ZONE, zone);
+}
+
/* Check to see if our timezones are the same */
static void
check_timezone_sync (void) {
@@ -144,7 +155,7 @@ check_timezone_sync (void) {
if (label != NULL) {
// TODO work out the current location name in a nice way
- dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, label);
+ set_timezone_label (current_location, label);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE);
@@ -153,18 +164,18 @@ check_timezone_sync (void) {
}
if (geo_timezone != NULL) {
// TODO work out the geo location name in a nice way
- dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone);
+ set_timezone_label (geo_location, geo_timezone);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
}
} else {
// TODO work out the geo location name in a nice way
- dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone);
+ set_timezone_label (geo_location, geo_timezone);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
// TODO work out the current location name in a nice way
- dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, current_timezone);
+ set_timezone_label (current_location, current_timezone);
// TODO work out the current time at that location
dbusmenu_menuitem_property_set_bool(current_location, TIMEZONE_MENUITEM_PROP_RADIO, TRUE);
dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show);
@@ -211,42 +222,6 @@ update_current_timezone (void) {
return;
}
-/* See how our timezone setting went */
-static void
-quick_set_tz_cb (OobsObject * obj, OobsResult result, gpointer user_data)
-{
- if (result == OOBS_RESULT_OK) {
- g_debug("Timezone set");
- } else {
- g_warning("Unable to quick set timezone");
- }
- return;
-}
-
-/* Set the timezone to the Geoclue discovered one */
-static void
-quick_set_tz (DbusmenuMenuitem * menuitem, guint timestamp, gpointer user_data)
-{
- const gchar * tz = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_ZONE);
-
- g_debug("Quick setting timezone to: %s", tz);
-
- 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, tz);
-
- oobs_object_commit_async(obj, quick_set_tz_cb, NULL);
-
- return;
-}
-
/* Updates the label in the date menuitem */
static gboolean
update_datetime (gpointer user_data)
@@ -400,12 +375,11 @@ update_timezone_menu_items(gpointer user_data) {
g_debug("Adding timezone in update_timezones %s", locations[i]);
item = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
- dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_ZONE, locations[i]);
+ set_timezone_label (item, locations[i]);
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, show);
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);
}
}
@@ -771,18 +745,16 @@ build_menus (DbusmenuMenuitem * root)
geo_location = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set (geo_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
- dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, "");
+ set_timezone_label (geo_location, "");
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);
dbusmenu_menuitem_child_append(root, geo_location);
current_location = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set (current_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE);
- dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, "");
+ set_timezone_label (current_location, "");
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);
dbusmenu_menuitem_child_append(root, current_location);
check_timezone_sync();
diff --git a/src/dbus-shared.h b/src/dbus-shared.h
index bad8354..f0f05a9 100644
--- a/src/dbus-shared.h
+++ b/src/dbus-shared.h
@@ -35,5 +35,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#define APPOINTMENT_MENUITEM_PROP_RIGHT "appointment-time"
#define TIMEZONE_MENUITEM_TYPE "timezone-item"
-#define TIMEZONE_MENUITEM_PROP_ZONE "timezone-zone"
+#define TIMEZONE_MENUITEM_PROP_ZONE "timezone-zone"
+#define TIMEZONE_MENUITEM_PROP_NAME "timezone-name"
#define TIMEZONE_MENUITEM_PROP_RADIO "timezone-radio"
diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c
index fb421cb..33f78c4 100644
--- a/src/indicator-datetime.c
+++ b/src/indicator-datetime.c
@@ -999,13 +999,13 @@ generate_format_string_now (IndicatorDatetime * self)
static void
timezone_update_labels (indicator_item_t * mi_data)
{
- const gchar * zone_name = dbusmenu_menuitem_property_get(mi_data->mi, TIMEZONE_MENUITEM_PROP_ZONE);
+ const gchar * zone = dbusmenu_menuitem_property_get(mi_data->mi, TIMEZONE_MENUITEM_PROP_ZONE);
+ const gchar * name = dbusmenu_menuitem_property_get(mi_data->mi, TIMEZONE_MENUITEM_PROP_NAME);
- /* TODO: Make zone name a little more user friendly */
- gtk_label_set_text(GTK_LABEL(mi_data->label), zone_name);
+ gtk_label_set_text(GTK_LABEL(mi_data->label), name);
/* Show current time in that zone on the right */
- GTimeZone * tz = g_time_zone_new(zone_name);
+ GTimeZone * tz = g_time_zone_new(zone);
set_label_to_time_in_zone(mi_data->self, GTK_LABEL(mi_data->right), tz, NULL, NULL);
g_time_zone_unref(tz);
}
@@ -1051,6 +1051,8 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value,
}
} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_ZONE)) {
timezone_update_labels(mi_data);
+ } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_NAME)) {
+ timezone_update_labels(mi_data);
} else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) {
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value));
} else {
diff --git a/src/utils.c b/src/utils.c
index 89c499b..20ae958 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -79,11 +79,16 @@ split_settings_location (const gchar * location, gchar ** zone, gchar ** name)
gchar * after = first ? g_strstrip (first + 1) : NULL;
if (after == NULL || after[0] == 0) {
/* Make up name from zone */
- gchar * slash = strrchr (location_dup, '/');
- after = slash ? slash + 1 : location_dup;
+ gchar * chr = strrchr (location_dup, '/');
+ after = g_strdup (chr ? chr + 1 : location_dup);
+ while ((chr = strchr (after, '_')) != NULL) { /* and turn underscores to spaces */
+ *chr = ' ';
+ }
+ *name = after;
+ }
+ else {
+ *name = g_strdup (after);
}
-
- *name = g_strdup (after);
}
}