diff options
Diffstat (limited to 'src/datetime-service.c')
-rw-r--r-- | src/datetime-service.c | 91 |
1 files changed, 25 insertions, 66 deletions
diff --git a/src/datetime-service.c b/src/datetime-service.c index e46b04d..5a492c1 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -38,6 +38,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <geoclue/geoclue-master.h> #include <geoclue/geoclue-master-client.h> +#define GNOME_DESKTOP_USE_UNSTABLE_API +#include <gdesktop-enums.h> +#include <libgnome-desktop/gnome-wall-clock.h> + #include <time.h> #include <libecal/e-cal.h> #include <libical/ical.h> @@ -57,7 +61,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. 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); -static void setup_timer (void); static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data); static void geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data); static gboolean get_greeter_mode (void); @@ -482,7 +485,7 @@ check_for_calendar (gpointer user_data) dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); gchar *evo = g_find_program_in_path("evolution"); - if (evo != NULL) { + if (!get_greeter_mode () && evo != NULL) { g_debug("Found the calendar application: %s", evo); g_signal_connect (G_OBJECT(date), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, @@ -770,6 +773,18 @@ update_appointment_menu_items (gpointer user_data) ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL); + icaltimezone* current_zone = icaltimezone_get_builtin_timezone(current_timezone); + if (!current_zone) { + // current_timezone may be a TZID? + current_zone = icaltimezone_get_builtin_timezone_from_tzid(current_timezone); + } + if (current_zone && !e_cal_set_default_timezone(ecal, current_zone, &gerror)) { + g_debug("Failed to set ecal default timezone %s", gerror->message); + g_error_free(gerror); + gerror = NULL; + continue; + } + if (!e_cal_open(ecal, FALSE, &gerror)) { g_debug("Failed to get ecal sources %s", gerror->message); g_error_free(gerror); @@ -1127,67 +1142,12 @@ build_menus (DbusmenuMenuitem * root) return; } -/* Run when the timezone file changes */ static void -timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data) +on_clock_changed (GnomeWallClock *clock, + GParamSpec *pspec, + gpointer user_data) { - update_current_timezone(); - datetime_interface_update(DATETIME_INTERFACE(user_data)); - update_datetime(NULL); - setup_timer(); - return; -} - -/* Set up monitoring the timezone file */ -static void -build_timezone (DatetimeInterface * dbus) -{ - GFile * timezonefile = g_file_new_for_path(TIMEZONE_FILE); - GFileMonitor * monitor = g_file_monitor_file(timezonefile, G_FILE_MONITOR_NONE, NULL, NULL); - if (monitor != NULL) { - g_signal_connect(G_OBJECT(monitor), "changed", G_CALLBACK(timezone_changed), dbus); - g_debug("Monitoring timezone file: '" TIMEZONE_FILE "'"); - } else { - g_warning("Unable to monitor timezone file: '" TIMEZONE_FILE "'"); - } - return; -} - -/* Source ID for the timer */ -static guint timer = 0; - -/* Execute at a given time, update and setup a new - timer to go again. */ -static gboolean -timer_func (gpointer user_data) -{ - timer = 0; - /* Reset up each time to reduce error */ - setup_timer(); - update_datetime(NULL); - return FALSE; -} - -/* Sets up the time to launch the timer to update the - date in the datetime entry */ -static void -setup_timer (void) -{ - if (timer != 0) { - g_source_remove(timer); - timer = 0; - } - - time_t t; - t = time(NULL); - struct tm * ltime = localtime(&t); - - timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) + - ((59 - ltime->tm_min) * 60) + - ((60 - ltime->tm_sec)) + 60 /* one minute past */, - timer_func, NULL); - - return; + update_datetime (NULL); } static void @@ -1201,7 +1161,6 @@ session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signa if (!idle) { datetime_interface_update(DATETIME_INTERFACE(user_data)); update_datetime(NULL); - setup_timer(); } } return; @@ -1425,6 +1384,8 @@ service_shutdown (IndicatorService * service, gpointer user_data) int main (int argc, char ** argv) { + GnomeWallClock *clock; + g_type_init(); /* Acknowledging the service init and setting up the interface */ @@ -1460,11 +1421,9 @@ main (int argc, char ** argv) /* Setup dbus interface */ dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL); - /* Setup timezone watch */ - build_timezone(dbus); - /* Setup the timer */ - setup_timer(); + clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL); + g_signal_connect (clock, "notify::clock", G_CALLBACK (on_clock_changed), NULL); /* And watch for system resumes */ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, |