From 41321ee042e649b3957ffdc2019ade016c49f814 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Fri, 1 Apr 2011 09:18:43 +0100 Subject: Set a minimum number of days to look for appointments for, allowed it to extend past month end by 1 week. --- src/datetime-service.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 1ddaa4d..7f14e74 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -656,6 +656,8 @@ update_appointment_menu_items (gpointer user_data) const int mon = today->tm_mon; const int year = today->tm_year; + int start_month_saved = mon; + struct tm *start_tm = NULL; int this_year = today->tm_year + 1900; int days[12]={31,28,31,30,31,30,31,31,30,31,30,31}; @@ -667,6 +669,7 @@ update_appointment_menu_items (gpointer user_data) if (start_time_appointments > 0) { start_tm = localtime(&start_time_appointments); int start_month = start_tm->tm_mon; + start_month_saved = start_month; int start_year = start_tm->tm_year + 1900; if ((start_month != mon) || (start_year != this_year)) { // Set t1 to the start of that month. @@ -681,6 +684,7 @@ update_appointment_menu_items (gpointer user_data) g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1)); + highlightdays = highlightdays + 7; // Minimum of 7 days ahead t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60); if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) { @@ -781,10 +785,12 @@ update_appointment_menu_items (gpointer user_data) const int dmon = due->tm_mon; const int dyear = due->tm_year; - // Mark day - g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday); - g_variant_builder_add (&markeddays, "i", dmday); - + if (start_month_saved == dmon) { + // Mark day if our query hasn't hit the next month. + g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday); + g_variant_builder_add (&markeddays, "i", dmday); + } + // If the appointment time is less than the selected date, // don't create an appointment item for it. if (vtype == E_CAL_COMPONENT_EVENT) { -- cgit v1.2.3 From 3bcb5d1ba9bf9890dd52d81cd35496d5d97b34a0 Mon Sep 17 00:00:00 2001 From: Dylan McCall Date: Sun, 3 Apr 2011 16:48:20 -0700 Subject: Follow show-calendar setting regardless of whether Evolution is present (LP: #748772) Visibility of upcoming events is no longer tied to show-calendar setting. --- src/datetime-service.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 1ddaa4d..4c3bb94 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -439,18 +439,16 @@ static gboolean check_for_calendar (gpointer user_data) { g_return_val_if_fail (calendar != NULL, FALSE); - // Always enable the calendar even if it does nothing - dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); - dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + + dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); gchar *evo = g_find_program_in_path("evolution"); if (evo != NULL) { g_debug("Found the calendar application: %s", evo); - - dbusmenu_menuitem_property_set_bool(date, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + g_signal_connect (G_OBJECT(date), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - G_CALLBACK (activate_cb), "evolution -c calendar"); - + G_CALLBACK (activate_cb), "evolution -c calendar"); + events_separator = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(events_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); dbusmenu_menuitem_child_add_position(root, events_separator, 2); @@ -478,8 +476,16 @@ check_for_calendar (gpointer user_data) g_free(evo); } else { g_debug("Unable to find calendar app."); - dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); + } + + if (g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR_S)) { + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); + } else { + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, FALSE); + dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); } return FALSE; -- cgit v1.2.3 From 26edf58f8d17fc0cf46de985f59b49a9b0a2999f Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 4 Apr 2011 13:05:27 +0100 Subject: Added a change which _could_ work if evolution URI's were correct, however local:system is not a valid URI, effectively this will stop showing all calendars right now --- configure.ac | 11 +++++++---- src/datetime-service.c | 17 ++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index ef49e53..2357aa3 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,7 @@ GDK_REQUIRED_VERSION=2.22 GLIB_REQUIRED_VERSION=2.26 GTK_REQUIRED_VERSION=2.12 GTK3_REQUIRED_VERSION=3.0 +GCONF_REQUIRED_VERSION=2.31 AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(INDICATOR, indicator3 >= $INDICATOR_REQUIRED_VERSION @@ -86,7 +87,7 @@ AS_IF([test "x$with_gtk" = x3], AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(SERVICE, indicator >= $INDICATOR_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS @@ -97,11 +98,12 @@ AS_IF([test "x$with_gtk" = x3], libedataserver-1.2 >= EDS_REQUIRED_VERSION libedataserverui-1.2 >= EDS_REQUIRED_VERSION cairo >= CAIRO_REQUIRED_VERSION - gdk-2.0 >= GDK_REQUIRED_VERSION) + gdk-2.0 >= GDK_REQUIRED_VERSION + gconf-2.0 >= GCONF_REQUIRED_VERSION) ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(SERVICE, indicator >= $INDICATOR_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION libido-0.1 >= $INDICATOR_DISPLAY_OBJECTS @@ -112,7 +114,8 @@ AS_IF([test "x$with_gtk" = x3], libedataserver-1.2 >= EDS_REQUIRED_VERSION libedataserverui-1.2 >= EDS_REQUIRED_VERSION cairo >= CAIRO_REQUIRED_VERSION - gdk-2.0 >= GDK_REQUIRED_VERSION) + gdk-2.0 >= GDK_REQUIRED_VERSION + gconf-2.0 >= GCONF_REQUIRED_VERSION) ], [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])] ) diff --git a/src/datetime-service.c b/src/datetime-service.c index 1ddaa4d..eb69d42 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -28,6 +28,7 @@ with this program. If not, see . #include #include #include +#include #include #include @@ -82,6 +83,7 @@ static GList * comp_instances = NULL; static gboolean updating_appointments = FALSE; static time_t start_time_appointments = (time_t) 0; GSettings *conf; +GConfClient* gconf; /* Geoclue trackers */ @@ -698,7 +700,13 @@ update_appointment_menu_items (gpointer user_data) comp_instances = NULL; } } - + GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror); + if (gerror) { + g_debug("Failed to get evolution preference for enabled calendars"); + g_error_free(gerror); + gerror = NULL; + cal_list = NULL; + } // Generate instances for all sources for (g = e_source_list_peek_groups (sources); g; g = g->next) { ESourceGroup *group = E_SOURCE_GROUP (g->data); @@ -716,6 +724,11 @@ update_appointment_menu_items (gpointer user_data) gerror = NULL; continue; } + const gchar *ecal_uri = e_cal_get_uri(ecal); + g_debug("Checking ecal_uri is enabled: %s, %s", ecal_uri); + // If source URI is not in source_list continue + if (cal_list != NULL && g_slist_find(cal_list, ecal_uri) == NULL) continue; + g_debug("ecal_uri is enabled, generating instances"); e_cal_generate_instances (ecal, t1, t2, (ECalRecurInstanceFn) populate_appointment_instances, (gpointer) source); } @@ -1300,6 +1313,8 @@ main (int argc, char ** argv) /* Set up GSettings */ conf = g_settings_new(SETTINGS_INTERFACE); + /* Set up gconf for getting evolution enabled calendars */ + gconf = gconf_client_get_default(); // TODO Add a signal handler to catch gsettings changes and respond to them /* Building the base menu */ -- cgit v1.2.3 From f6af2cf76470bfe177503c12699c84ba013feee7 Mon Sep 17 00:00:00 2001 From: karl-qdh Date: Mon, 4 Apr 2011 13:53:19 +0100 Subject: Working patch! YAY --- src/datetime-service.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index eb69d42..d01f5dc 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -724,11 +724,18 @@ update_appointment_menu_items (gpointer user_data) gerror = NULL; continue; } - const gchar *ecal_uri = e_cal_get_uri(ecal); - g_debug("Checking ecal_uri is enabled: %s, %s", ecal_uri); - // If source URI is not in source_list continue - if (cal_list != NULL && g_slist_find(cal_list, ecal_uri) == NULL) continue; - g_debug("ecal_uri is enabled, generating instances"); + const gchar *ecal_uid = e_source_peek_uid(source); + gboolean match = FALSE; + g_debug("Checking ecal_uid is enabled: %s", ecal_uid); + for (i = 0; i Date: Tue, 5 Apr 2011 14:54:57 -0500 Subject: Detect a full day event and print it differently --- src/datetime-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/datetime-service.c b/src/datetime-service.c index 6458ae9..eff3cfa 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -860,6 +860,9 @@ update_appointment_menu_items (gpointer user_data) g_free (summary); // Due text + if (time_add_day(ci->start, 1) == ci->end) { + strftime(right, 20, "%A", due); + } else { if (apt_output == SETTINGS_TIME_12_HOUR) { if ((mday == dmday) && (mon == dmon) && (year == dyear)) strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due); @@ -871,6 +874,7 @@ update_appointment_menu_items (gpointer user_data) else strftime(right, 20, _(DEFAULT_TIME_24_FORMAT_WITH_DAY), due); } + } g_debug("Appointment time: %s, for date %s", right, asctime(due)); dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right); -- cgit v1.2.3 From 3a5ab9e661b7d7438c6c494b271c6be86a3703e8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Apr 2011 14:58:16 -0500 Subject: Translator comment --- src/datetime-service.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index eff3cfa..66a6cdb 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -861,7 +861,11 @@ update_appointment_menu_items (gpointer user_data) // Due text if (time_add_day(ci->start, 1) == ci->end) { - strftime(right, 20, "%A", due); + /* TRANSLATORS: This is a strftime string for the day for full day events + in the menu. It should most likely be either '%A' for a full text day + (Wednesday) or '%a' for a shortened one (Wed). You should only need to + change for '%a' in the case of langauges with very long day names. */ + strftime(right, 20, _("%A"), due); } else { if (apt_output == SETTINGS_TIME_12_HOUR) { if ((mday == dmday) && (mon == dmon) && (year == dyear)) -- cgit v1.2.3 From 9744a2f892fb78f74e9c942197ca98309a9e2759 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Apr 2011 15:10:50 -0500 Subject: Pull the full day into a boolean and reformat --- src/datetime-service.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 66a6cdb..c72b061 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -859,25 +859,33 @@ update_appointment_menu_items (gpointer user_data) g_debug("Summary: %s", summary); g_free (summary); + gboolean full_day = FALSE; + if (vtype == E_CAL_COMPONENT_EVENT) { + time_t start = ci->start; + if (time_add_day(start, 1) == ci->end) { + full_day = TRUE; + } + } + // Due text - if (time_add_day(ci->start, 1) == ci->end) { + if (full_day) { /* TRANSLATORS: This is a strftime string for the day for full day events in the menu. It should most likely be either '%A' for a full text day (Wednesday) or '%a' for a shortened one (Wed). You should only need to change for '%a' in the case of langauges with very long day names. */ strftime(right, 20, _("%A"), due); } else { - if (apt_output == SETTINGS_TIME_12_HOUR) { - if ((mday == dmday) && (mon == dmon) && (year == dyear)) - strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due); - else - strftime(right, 20, _(DEFAULT_TIME_12_FORMAT_WITH_DAY), due); - } else if (apt_output == SETTINGS_TIME_24_HOUR) { - if ((mday == dmday) && (mon == dmon) && (year == dyear)) - strftime(right, 20, _(DEFAULT_TIME_24_FORMAT), due); - else - strftime(right, 20, _(DEFAULT_TIME_24_FORMAT_WITH_DAY), due); - } + if (apt_output == SETTINGS_TIME_12_HOUR) { + if ((mday == dmday) && (mon == dmon) && (year == dyear)) + strftime(right, 20, _(DEFAULT_TIME_12_FORMAT), due); + else + strftime(right, 20, _(DEFAULT_TIME_12_FORMAT_WITH_DAY), due); + } else if (apt_output == SETTINGS_TIME_24_HOUR) { + if ((mday == dmday) && (mon == dmon) && (year == dyear)) + strftime(right, 20, _(DEFAULT_TIME_24_FORMAT), due); + else + strftime(right, 20, _(DEFAULT_TIME_24_FORMAT_WITH_DAY), due); + } } g_debug("Appointment time: %s, for date %s", right, asctime(due)); dbusmenu_menuitem_property_set (item, APPOINTMENT_MENUITEM_PROP_RIGHT, right); -- cgit v1.2.3 From db8896f805704ea21387cb4acd712901177e1ea3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Apr 2011 15:11:12 -0500 Subject: Use stack memory instead of the global to avoid it getting modified --- src/datetime-service.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index c72b061..0ceb975 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -802,9 +802,10 @@ update_appointment_menu_items (gpointer user_data) DbusmenuMenuitem * item; ECalComponentVType vtype = e_cal_component_get_vtype (ecalcomp); + struct tm due_data = {0}; struct tm *due = NULL; - if (vtype == E_CAL_COMPONENT_EVENT) due = localtime(&ci->start); - else if (vtype == E_CAL_COMPONENT_TODO) due = localtime(&ci->end); + if (vtype == E_CAL_COMPONENT_EVENT) due = localtime_r(&ci->start, &due_data); + else if (vtype == E_CAL_COMPONENT_TODO) due = localtime_r(&ci->end, &due_data); else continue; const int dmday = due->tm_mday; -- cgit v1.2.3 From 76760205d4a4ab209515b7333794cd059ecda82a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 5 Apr 2011 15:22:12 -0500 Subject: Use gmtime for full day events. --- src/datetime-service.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/datetime-service.c b/src/datetime-service.c index 0ceb975..5e8d312 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -870,11 +870,14 @@ update_appointment_menu_items (gpointer user_data) // Due text if (full_day) { + struct tm fulldaytime = {0}; + gmtime_r(&ci->start, &fulldaytime); + /* TRANSLATORS: This is a strftime string for the day for full day events in the menu. It should most likely be either '%A' for a full text day (Wednesday) or '%a' for a shortened one (Wed). You should only need to change for '%a' in the case of langauges with very long day names. */ - strftime(right, 20, _("%A"), due); + strftime(right, 20, _("%A"), &fulldaytime); } else { if (apt_output == SETTINGS_TIME_12_HOUR) { if ((mday == dmday) && (mon == dmon) && (year == dyear)) -- cgit v1.2.3 From 3b6b878ba8ca5e3edd8e44f1f3a978f473ce5c81 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 6 Apr 2011 11:05:31 -0400 Subject: pass locale to server; dynamically determine version --- src/timezone-completion.c | 64 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index ad04d0c..1a495b6 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -50,7 +50,7 @@ struct _TimezoneCompletionPrivate #define TIMEZONE_COMPLETION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), TIMEZONE_COMPLETION_TYPE, TimezoneCompletionPrivate)) -#define GEONAME_URL "http://geoname-lookup.ubuntu.com/?query=%s&release=%s" +#define GEONAME_URL "http://geoname-lookup.ubuntu.com/?query=%s&release=%s&lang=%s" /* Prototypes */ static void timezone_completion_class_init (TimezoneCompletionClass *klass); @@ -280,6 +280,58 @@ geonames_data_ready (GObject *object, GAsyncResult *res, gpointer user_data) json_parse_ready, user_data); } +/* Returns message locale, with possible country info too like en_US */ +static gchar * +get_locale (void) +{ + /* Check LANGUAGE, LC_ALL, LC_MESSAGES, and LANG, treat as colon-separated */ + const gchar *env_names[] = {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG", NULL}; + const gchar *env = NULL; + gint i; + + for (i = 0; env_names[i]; i++) { + env = g_getenv (env_names[i]); + if (env != NULL && env[0] != 0) + break; + } + + if (env == NULL) + return NULL; + + /* Now, we split on colons as expected, but also on . and @ to filter out + extra pieces of locale we don't care about as we only use first chunk. */ + gchar **split = g_strsplit_set (env, ":.@", 2); + if (split == NULL) + return NULL; + + if (split[0] == NULL) { + g_strfreev (split); + return NULL; + } + + gchar *locale = g_strdup (split[0]); + g_strfreev (split); + return locale; +} + +static gchar * +get_version (void) +{ + static gchar *version = NULL; + + if (version == NULL) { + gchar *stdout = NULL; + g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL); + + if (stdout != NULL) + version = g_strstrip (stdout); + else + version = ""; + } + + return version; +} + static gboolean request_zones (TimezoneCompletion * completion) { @@ -302,9 +354,17 @@ request_zones (TimezoneCompletion * completion) priv->request_text = g_strdup (text); gchar * escaped = g_uri_escape_string (text, NULL, FALSE); - gchar * url = g_strdup_printf (GEONAME_URL, escaped, "11.04"); // FIXME: don't hardcode + gchar * version = get_version (); + gchar * locale = get_locale (); + gchar * url = g_strdup_printf (GEONAME_URL, escaped, version, locale); + g_debug("url: %s", url); + g_free (locale); + g_free (version); + g_free (escaped); GFile * file = g_file_new_for_uri (url); + g_free (url); + g_file_read_async (file, G_PRIORITY_DEFAULT, priv->cancel, geonames_data_ready, completion); -- cgit v1.2.3 From f62a2a6767eb177f261a6a5b0ddf18ce9482f6ba Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 6 Apr 2011 11:16:45 -0400 Subject: whoops, remove debug comment --- src/timezone-completion.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/timezone-completion.c b/src/timezone-completion.c index 1a495b6..1cbc4d0 100644 --- a/src/timezone-completion.c +++ b/src/timezone-completion.c @@ -357,7 +357,6 @@ request_zones (TimezoneCompletion * completion) gchar * version = get_version (); gchar * locale = get_locale (); gchar * url = g_strdup_printf (GEONAME_URL, escaped, version, locale); - g_debug("url: %s", url); g_free (locale); g_free (version); g_free (escaped); -- cgit v1.2.3 From 20aee32a693b5fa78f1a3547351a9fb316534935 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 7 Apr 2011 16:48:50 +0100 Subject: when user clicks a timezone location, switch to that timezone (and support showing user's preferred name for the current timezone in the menu) --- src/datetime-prefs.c | 40 ++--------------------- src/datetime-service.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++---- src/utils.c | 36 +++++++++++++++++++++ src/utils.h | 1 + 4 files changed, 121 insertions(+), 44 deletions(-) diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 4a32fd6..9b00e60 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -181,46 +181,10 @@ ntp_query_answered (GObject *object, GAsyncResult *res, gpointer user_data) g_variant_unref (answers); } -static gchar * -get_zone_name (const gchar * location) -{ - gchar * new_zone, * new_name; - gchar * old_zone, * old_name; - gchar * rv; - - split_settings_location (location, &new_zone, &new_name); - - GSettings * conf = g_settings_new (SETTINGS_INTERFACE); - gchar * tz_name = g_settings_get_string (conf, SETTINGS_TIMEZONE_NAME_S); - split_settings_location (tz_name, &old_zone, &old_name); - g_free (tz_name); - g_object_unref (conf); - - // new_name is always just a sanitized version of a timezone. - // old_name is potentially a saved "pretty" version of a timezone name from - // geonames. So we prefer to use it if available and the zones match. - - if (g_strcmp0 (old_zone, new_zone) == 0) { - rv = old_name; - old_name = NULL; - } - else { - rv = new_name; - new_name = NULL; - } - - g_free (new_zone); - g_free (old_zone); - g_free (new_name); - g_free (old_name); - - return rv; -} - static void sync_entry (const gchar * location) { - gchar * name = get_zone_name (location); + gchar * name = get_current_zone_name (location); gtk_entry_set_text (GTK_ENTRY (tz_entry), name); g_free (name); @@ -606,7 +570,7 @@ entry_focus_out (GtkEntry * entry, GdkEventFocus * event) if (location == NULL) return FALSE; - gchar * name = get_zone_name (location->zone); + gchar * name = get_current_zone_name (location->zone); gboolean correct = (g_strcmp0 (gtk_entry_get_text (entry), name) == 0); g_free (name); diff --git a/src/datetime-service.c b/src/datetime-service.c index 5e8d312..df37b5e 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -114,6 +114,17 @@ set_timezone_label (DbusmenuMenuitem * mi, const gchar * location) g_free (name); } +static void +set_current_timezone_label (DbusmenuMenuitem * mi, const gchar * location) +{ + gchar * name = get_current_zone_name (location); + + dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_NAME, name); + dbusmenu_menuitem_property_set (mi, TIMEZONE_MENUITEM_PROP_ZONE, location); + + g_free (name); +} + /* Check to see if our timezones are the same */ static void check_timezone_sync (void) { @@ -168,7 +179,7 @@ check_timezone_sync (void) { if (label != NULL) { // TODO work out the current location name in a nice way - set_timezone_label (current_location, label); + set_current_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); @@ -177,18 +188,18 @@ check_timezone_sync (void) { } if (geo_timezone != NULL) { // TODO work out the geo location name in a nice way - set_timezone_label (geo_location, geo_timezone); + set_current_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 - set_timezone_label (geo_location, geo_timezone); + set_current_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 - set_timezone_label (current_location, current_timezone); + set_current_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); @@ -236,6 +247,69 @@ update_current_timezone (void) { return; } +static void +quick_set_tz_cb (GObject *object, GAsyncResult *res, gpointer data) +{ + GError * error = NULL; + GVariant * answers = g_dbus_proxy_call_finish (G_DBUS_PROXY (object), res, &error); + + if (error != NULL) { + g_warning("Could not set timezone for SettingsDaemon: %s", error->message); + g_error_free(error); + return; + } + + g_variant_unref (answers); +} + +static void +quick_set_tz_proxy_cb (GObject *object, GAsyncResult *res, gpointer zone) +{ + GError * error = NULL; + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish (res, &error); + + if (error != NULL) { + g_warning("Could not grab DBus proxy for SettingsDaemon: %s", error->message); + g_error_free(error); + g_free (zone); + return; + } + + gchar * file = g_build_filename ("/usr/share/zoneinfo", (char *)zone, NULL); + g_dbus_proxy_call (proxy, "SetTimezone", g_variant_new ("(s)", file), + G_DBUS_CALL_FLAGS_NONE, -1, NULL, quick_set_tz_cb, NULL); + g_free (file); + g_free (zone); + g_object_unref (proxy); +} + +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); + + const gchar * name = dbusmenu_menuitem_property_get(menuitem, TIMEZONE_MENUITEM_PROP_NAME); + + /* Set it in gsettings so we don't lose user's preferred name */ + GSettings * conf = g_settings_new (SETTINGS_INTERFACE); + gchar * tz_full = g_strdup_printf ("%s %s", tz, name); + g_settings_set_string (conf, SETTINGS_TIMEZONE_NAME_S, tz_full); + g_free (tz_full); + g_object_unref (conf); + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, + "org.gnome.SettingsDaemon.DateTimeMechanism", + "/", + "org.gnome.SettingsDaemon.DateTimeMechanism", + NULL, quick_set_tz_proxy_cb, g_strdup (tz)); + + return; +} + /* Updates the label in the date menuitem */ static gboolean update_datetime (gpointer user_data) @@ -543,6 +617,7 @@ update_timezone_menu_items(gpointer user_data) { 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); } } @@ -1048,14 +1123,15 @@ build_menus (DbusmenuMenuitem * root) geo_location = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (geo_location, DBUSMENU_MENUITEM_PROP_TYPE, TIMEZONE_MENUITEM_TYPE); - set_timezone_label (geo_location, ""); + set_current_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); - set_timezone_label (current_location, ""); + set_current_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); dbusmenu_menuitem_child_append(root, current_location); diff --git a/src/utils.c b/src/utils.c index d8851aa..ab93ecf 100644 --- a/src/utils.c +++ b/src/utils.c @@ -81,6 +81,42 @@ split_settings_location (const gchar * location, gchar ** zone, gchar ** name) } } +gchar * +get_current_zone_name (const gchar * location) +{ + gchar * new_zone, * new_name; + gchar * old_zone, * old_name; + gchar * rv; + + split_settings_location (location, &new_zone, &new_name); + + GSettings * conf = g_settings_new (SETTINGS_INTERFACE); + gchar * tz_name = g_settings_get_string (conf, SETTINGS_TIMEZONE_NAME_S); + split_settings_location (tz_name, &old_zone, &old_name); + g_free (tz_name); + g_object_unref (conf); + + // new_name is always just a sanitized version of a timezone. + // old_name is potentially a saved "pretty" version of a timezone name from + // geonames. So we prefer to use it if available and the zones match. + + if (g_strcmp0 (old_zone, new_zone) == 0) { + rv = old_name; + old_name = NULL; + } + else { + rv = new_name; + new_name = NULL; + } + + g_free (new_zone); + g_free (old_zone); + g_free (new_name); + g_free (old_name); + + return rv; +} + /* Translate msg according to the locale specified by LC_TIME */ static char * T_(const char *msg) diff --git a/src/utils.h b/src/utils.h index 5f7842c..c2bc0c5 100644 --- a/src/utils.h +++ b/src/utils.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS gboolean is_locale_12h (void); void split_settings_location (const gchar * location, gchar ** zone, gchar ** name); +gchar * get_current_zone_name (const gchar * location); gchar * generate_format_string_full (gboolean show_day, gboolean show_date); gchar * generate_format_string_at_time (GDateTime * time); -- cgit v1.2.3 From 6d42bccac27b7214e5e650f698c2b117231e3f77 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 7 Apr 2011 13:12:22 -0500 Subject: 0.2.2 --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index b932e56..6c62342 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(indicator-datetime, 0.2.1, ted@canonical.com) +AC_INIT(indicator-datetime, 0.2.2, ted@canonical.com) AC_COPYRIGHT([Copyright 2009,2010 Canonical]) AC_PREREQ(2.53) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(indicator-datetime, 0.2.1) +AM_INIT_AUTOMAKE(indicator-datetime, 0.2.2) AM_MAINTAINER_MODE -- cgit v1.2.3