aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-service.c
diff options
context:
space:
mode:
authorkarl-qdh <karl@qdh.org.uk>2011-02-25 17:22:33 +0000
committerkarl-qdh <karl@qdh.org.uk>2011-02-25 17:22:33 +0000
commit0188356e069018c07849f8c2c09c9741bbf70ff5 (patch)
treea0ba2047125ba0ada887f2722ea0c11a52fd9792 /src/datetime-service.c
parentd0e5a69a026bc879759cde57f8ba324c67b6b37a (diff)
parent6f103ce25995b5a40967b0ba683b7f7330aadd8a (diff)
downloadayatana-indicator-datetime-0188356e069018c07849f8c2c09c9741bbf70ff5.tar.gz
ayatana-indicator-datetime-0188356e069018c07849f8c2c09c9741bbf70ff5.tar.bz2
ayatana-indicator-datetime-0188356e069018c07849f8c2c09c9741bbf70ff5.zip
Updated to newest trunk needs more merging
Diffstat (limited to 'src/datetime-service.c')
-rw-r--r--src/datetime-service.c140
1 files changed, 54 insertions, 86 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c
index a3e45bf..bf038b4 100644
--- a/src/datetime-service.c
+++ b/src/datetime-service.c
@@ -47,18 +47,12 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include <libical/icaltime.h>
#include <cairo/cairo.h>
-
#include <oobs/oobs-timeconfig.h>
#include "datetime-interface.h"
#include "dbus-shared.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"
+#include "settings-shared.h"
+#include "utils.h"
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);
@@ -95,6 +89,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) {
@@ -118,13 +125,8 @@ check_timezone_sync (void) {
} else {
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 +156,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");
@@ -222,42 +224,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)
@@ -317,7 +283,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,16 +320,11 @@ 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;
- }
+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;
@@ -374,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));
@@ -385,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)");
@@ -404,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);
}
}
@@ -421,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");
@@ -499,7 +460,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;
@@ -725,19 +686,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. */
@@ -768,27 +736,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);
@@ -797,7 +765,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);