aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-service.c
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-02-25 13:26:01 -0500
committerMichael Terry <mike@mterry.name>2011-02-25 13:26:01 -0500
commit6d8cd56957cbd5123748085448b1b340bf8c4d1c (patch)
tree1cd5dd06593bb7ccdbf6328457cfca202a54c8ac /src/datetime-service.c
parent398154d354d19a85f629a6d7131b1a7bd6b7b869 (diff)
parent42125be0102026e6ecae842413261a8b05a25e96 (diff)
downloadayatana-indicator-datetime-6d8cd56957cbd5123748085448b1b340bf8c4d1c.tar.gz
ayatana-indicator-datetime-6d8cd56957cbd5123748085448b1b340bf8c4d1c.tar.bz2
ayatana-indicator-datetime-6d8cd56957cbd5123748085448b1b340bf8c4d1c.zip
merge with trunk
Diffstat (limited to 'src/datetime-service.c')
-rw-r--r--src/datetime-service.c134
1 files changed, 51 insertions, 83 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index 6a9575e..d3cfafb 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -52,14 +52,10 @@ 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"
-#define SETTINGS_INTERFACE "com.canonical.indicator.datetime"
-#define SETTINGS_LOCATIONS "locations"
-#define SETTINGS_SHOW_CALENDAR "show-calendar"
-#define SETTINGS_SHOW_EVENTS "show-events"
-#define SETTINGS_SHOW_LOCATIONS "show-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);
@@ -95,6 +91,19 @@ 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);
+
+ g_free (zone);
+ g_free (name);
+}
+
/* Check to see if our timezones are the same */
static void
check_timezone_sync (void) {
@@ -119,12 +128,7 @@ check_timezone_sync (void) {
g_debug("Timezones are different");
}
- if (!g_settings_get_boolean(conf, SETTINGS_SHOW_LOCATIONS)) {
- dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- return;
- }
+ 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);
@@ -154,31 +158,31 @@ 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, 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");
}
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, 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);
+ 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, 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);
+ 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, 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");
@@ -221,42 +225,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)
@@ -316,7 +284,7 @@ check_for_calendar (gpointer user_data)
{
g_return_val_if_fail (calendar != NULL, FALSE);
- if (!g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR)) return FALSE;
+ if (!g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR_S)) return FALSE;
gchar *evo = g_find_program_in_path("evolution");
if (evo != NULL) {
@@ -354,15 +322,9 @@ check_for_calendar (gpointer user_data)
static gboolean
update_timezone_menu_items(gpointer user_data) {
- if (!g_settings_get_boolean(conf, SETTINGS_SHOW_LOCATIONS)) {
- dbusmenu_menuitem_property_set_bool (locations_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- dbusmenu_menuitem_property_set_bool (current_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- dbusmenu_menuitem_property_set_bool (geo_location, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
- return FALSE;
- }
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;
@@ -373,10 +335,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));
@@ -384,11 +344,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)");
@@ -403,12 +365,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, 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);
}
}
@@ -420,6 +381,7 @@ update_timezone_menu_items(gpointer user_data) {
// Authentication function
static gchar *
auth_func (ECal *ecal, const gchar *prompt, const gchar *key, gpointer user_data) {
+ gboolean remember; // TODO: Is this useful? Should we be storing it somewhere?
ESource *source = e_cal_get_source (ecal);
gchar *auth_domain = e_source_get_duped_property (source, "auth-domain");
@@ -428,7 +390,6 @@ auth_func (ECal *ecal, const gchar *prompt, const gchar *key, gpointer user_data
else component_name = "Calendar";
gchar *password = e_passwords_get_password (component_name, key);
- gboolean remember;
if (password == NULL) {
password = e_passwords_ask_password (
@@ -498,7 +459,7 @@ update_appointment_menu_items (gpointer user_data) {
// FFR: we should take into account short term timers, for instance
// tea timers, pomodoro timers etc... that people may add, this is hinted to in the spec.
if (calendar == NULL) return FALSE;
- if (!g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS)) return FALSE;
+ if (!g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) return FALSE;
time_t t1, t2;
gchar *query, *is, *ie, *ad;
@@ -722,19 +683,26 @@ 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);
}
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. */
@@ -765,27 +733,27 @@ 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();
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();
+ 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);
@@ -794,7 +762,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);