From a10f207618976b59a0cc43c01befbf67128c92a5 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 17 Feb 2011 14:30:43 -0500 Subject: first pass at preferences dialog --- src/datetime-service.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 0894e83..cc6c9d5 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -51,11 +51,9 @@ with this program. If not, see . #include "datetime-interface.h" #include "dbus-shared.h" +#include "settings-shared.h" -#define SETTINGS_INTERFACE "com.canonical.indicator.datetime" -#define SETTINGS_LOCATIONS "locations" - static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data); static gboolean update_appointment_menu_items (gpointer user_data); static gboolean update_timezone_menu_items(gpointer user_data); @@ -363,7 +361,7 @@ check_for_calendar (gpointer user_data) static gboolean update_timezone_menu_items(gpointer user_data) { g_debug("Updating timezone menu items"); - gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS); + gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS_S); if (locations == NULL) { g_debug("No locations configured (NULL)"); return FALSE; @@ -648,13 +646,13 @@ check_for_timeadmin (gpointer user_data) { g_return_val_if_fail (settings != NULL, FALSE); - gchar * timeadmin = g_find_program_in_path("time-admin"); + gchar * timeadmin = g_find_program_in_path("indicator-datetime-preferences"); if (timeadmin != NULL) { - g_debug("Found the time-admin application: %s", timeadmin); + g_debug("Found the indicator-datetime-preferences application: %s", timeadmin); dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); g_free(timeadmin); } else { - g_debug("Unable to find time-admin app."); + g_debug("Unable to find indicator-datetime-preferences app."); dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); } @@ -721,7 +719,7 @@ build_menus (DbusmenuMenuitem * root) dbusmenu_menuitem_property_set (settings, DBUSMENU_MENUITEM_PROP_LABEL, _("Time & Date Settings...")); /* insensitive until we check for available apps */ dbusmenu_menuitem_property_set_bool(settings, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); - g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "time-admin"); + g_signal_connect(G_OBJECT(settings), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "indicator-datetime-preferences"); dbusmenu_menuitem_child_append(root, settings); g_idle_add(check_for_timeadmin, NULL); -- cgit v1.2.3 From cf3ae1adfd378d4bfb3a9cf02609ba45d9f764a8 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Feb 2011 14:42:24 -0500 Subject: hook show-locations up --- src/datetime-service.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index 1f3eac6..45efbf6 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -114,6 +114,8 @@ check_timezone_sync (void) { g_debug("Timezones are different"); } + gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); + if (geo_location != NULL && current_location != NULL) { g_debug("Got timezone %s", current_timezone); g_debug("Got timezone %s", geo_timezone); @@ -144,7 +146,7 @@ check_timezone_sync (void) { // TODO work out the current location name in a nice way dbusmenu_menuitem_property_set (current_location, TIMEZONE_MENUITEM_PROP_ZONE, label); // TODO work out the current time at that location - dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show); 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,20 +155,20 @@ check_timezone_sync (void) { // TODO work out the geo location name in a nice way dbusmenu_menuitem_property_set (geo_location, TIMEZONE_MENUITEM_PROP_ZONE, geo_timezone); // TODO work out the current time at that location - dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + 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); // TODO work out the current time at that location - dbusmenu_menuitem_property_set_bool(geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + 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); // 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, TRUE); - dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool(current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show); + dbusmenu_menuitem_property_set_bool(locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show); } } g_debug("Finished checking timezone sync"); @@ -368,10 +370,8 @@ update_timezone_menu_items(gpointer user_data) { /* Remove all of the previous locations */ if (dconflocations != NULL) { - g_debug("Freeing old locations"); 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 dconflocations. dconflocations = g_list_remove(dconflocations, litem); dbusmenu_menuitem_child_delete(root, DBUSMENU_MENUITEM(litem)); @@ -379,11 +379,13 @@ update_timezone_menu_items(gpointer user_data) { } } + gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); + // TODO: Remove items from the dconflocations at the end of the iteration // Make sure if there are multiple locations, our current location is shown if (len > 0) { - dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, show); + dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, show); dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); } else { g_debug("No locations configured (Empty List)"); @@ -401,7 +403,7 @@ update_timezone_menu_items(gpointer user_data) { dbusmenu_menuitem_property_set (item, TIMEZONE_MENUITEM_PROP_ZONE, 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, 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); @@ -727,6 +729,13 @@ check_for_timeadmin (gpointer user_data) return FALSE; } +static void +show_locations_changed (void) +{ + /* Re-calculate */ + check_timezone_sync(); +} + /* Does the work to build the default menu, really calls out to other functions but this is the core to clean up the main function. */ @@ -757,7 +766,7 @@ build_menus (DbusmenuMenuitem * root) locations_separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(locations_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); - dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_child_append(root, locations_separator); geo_location = dbusmenu_menuitem_new(); @@ -778,6 +787,8 @@ build_menus (DbusmenuMenuitem * root) check_timezone_sync(); + g_signal_connect (conf, "changed::" SETTINGS_SHOW_LOCATIONS_S, G_CALLBACK (show_locations_changed), NULL); + DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_append(root, separator); -- cgit v1.2.3 From 02a56bbe87dba95388735c9961345b5166940b1c Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 23 Feb 2011 15:13:42 -0500 Subject: disable clicking on locations; use pretty zone names in indicator --- src/datetime-service.c | 64 ++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'src/datetime-service.c') 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 . #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(); -- cgit v1.2.3 From 42125be0102026e6ecae842413261a8b05a25e96 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 25 Feb 2011 11:41:56 -0500 Subject: fix a couple memory leaks noted by MacSlow --- src/datetime-service.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/datetime-service.c') diff --git a/src/datetime-service.c b/src/datetime-service.c index ab609c4..af63a2a 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -99,6 +99,9 @@ set_timezone_label (DbusmenuMenuitem * mi, const gchar * location) dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_NAME, name); dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_ZONE, zone); + + g_free (zone); + g_free (name); } /* Check to see if our timezones are the same */ -- cgit v1.2.3