diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-09-09 11:50:22 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-09-09 11:50:22 -0500 |
commit | 605e4b6391cb3f4f87e84ee63df9d50c60eea95c (patch) | |
tree | bf673742fac21e7ea293aa30894f01431b4ab5d7 | |
parent | ecee96636e70894355aaee58675b1dbacd202ac9 (diff) | |
parent | b7f625ed8003197cd9d0a81240aea944860c8dc3 (diff) | |
download | ayatana-indicator-datetime-605e4b6391cb3f4f87e84ee63df9d50c60eea95c.tar.gz ayatana-indicator-datetime-605e4b6391cb3f4f87e84ee63df9d50c60eea95c.tar.bz2 ayatana-indicator-datetime-605e4b6391cb3f4f87e84ee63df9d50c60eea95c.zip |
sync with trunk
-rw-r--r-- | src/datetime-prefs-locations.c | 5 | ||||
-rw-r--r-- | src/datetime-prefs.c | 20 | ||||
-rw-r--r-- | src/planner.c | 2 | ||||
-rw-r--r-- | src/service.c | 76 | ||||
-rw-r--r-- | src/settings-shared.h | 9 | ||||
-rw-r--r-- | src/utils.c | 43 | ||||
-rw-r--r-- | src/utils.h | 11 |
7 files changed, 67 insertions, 99 deletions
diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index bc044a2..ca3d9b5 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -417,6 +417,7 @@ update_times (GtkWidget * dlg) g_signal_handlers_block_by_func (store, save_when_idle, dlg); + GSettings * settings = g_settings_new (SETTINGS_INTERFACE); GtkTreeIter iter; if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) { GDateTime * now = g_date_time_new_now_local (); @@ -428,7 +429,7 @@ update_times (GtkWidget * dlg) if (strzone && *strzone) { GTimeZone * tz = g_time_zone_new (strzone); GDateTime * now_tz = g_date_time_to_timezone (now, tz); - gchar * format = generate_full_format_string_at_time (now, now_tz); + gchar * format = generate_full_format_string_at_time (now, now_tz, settings); gchar * time_str = g_date_time_format (now_tz, format); gchar * old_time_str; @@ -447,6 +448,8 @@ update_times (GtkWidget * dlg) g_date_time_unref (now); } + g_object_unref (settings); + g_signal_handlers_unblock_by_func (store, save_when_idle, dlg); return TRUE; diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 25c9b2a..9b48ca9 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -70,6 +70,7 @@ struct _IndicatorDatetimePanelPrivate gboolean user_edited_time; gboolean changing_time; GtkWidget * loc_dlg; + GSettings * settings; CcTimezoneCompletion * completion; }; @@ -214,7 +215,7 @@ toggle_ntp (GtkWidget * radio, GParamSpec * pspec, IndicatorDatetimePanel * self static void sync_entry (IndicatorDatetimePanel * self, const gchar * location) { - gchar * name = get_current_zone_name (location); + gchar * name = get_current_zone_name (location, self->priv->settings); gtk_entry_set_text (GTK_ENTRY (self->priv->tz_entry), name); g_free (name); @@ -599,11 +600,9 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, zone = cc_timezone_map_get_timezone_at_coords (self->priv->tzmap, lon, lat); } - GSettings * conf = g_settings_new (SETTINGS_INTERFACE); gchar * tz_name = g_strdup_printf ("%s %s", zone, name); - g_settings_set_string (conf, SETTINGS_TIMEZONE_NAME_S, tz_name); + g_settings_set_string (self->priv->settings, SETTINGS_TIMEZONE_NAME_S, tz_name); g_free (tz_name); - g_object_unref (conf); cc_timezone_map_set_timezone (self->priv->tzmap, zone); @@ -623,7 +622,7 @@ entry_focus_out (GtkEntry * entry, GdkEventFocus * event, IndicatorDatetimePanel gchar * zone; g_object_get (location, "zone", &zone, NULL); - gchar * name = get_current_zone_name (zone); + gchar * name = get_current_zone_name (zone, self->priv->settings); gboolean correct = (g_strcmp0 (gtk_entry_get_text (entry), name) == 0); g_free (name); g_free (zone); @@ -639,14 +638,18 @@ entry_focus_out (GtkEntry * entry, GdkEventFocus * event, IndicatorDatetimePanel static void indicator_datetime_panel_init (IndicatorDatetimePanel * self) { + GError * error; + GSettings * conf; + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, INDICATOR_DATETIME_TYPE_PANEL, IndicatorDatetimePanelPrivate); - GError * error = NULL; + self->priv->settings = conf = g_settings_new (SETTINGS_INTERFACE); self->priv->builder = gtk_builder_new (); gtk_builder_set_translation_domain (self->priv->builder, GETTEXT_PACKAGE); + error = NULL; gtk_builder_add_from_file (self->priv->builder, DATETIME_DIALOG_UI_FILE, &error); if (error != NULL) { /* We have to abort, we can't continue without the ui file */ @@ -655,8 +658,6 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) return; } - GSettings * conf = g_settings_new (SETTINGS_INTERFACE); - /* Add policykit button */ GtkWidget * polkit_button = gtk_lock_button_new (NULL); @@ -755,8 +756,6 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) #undef WIG - g_object_unref (conf); - gtk_widget_show_all (panel); gtk_container_add (GTK_CONTAINER (self), panel); } @@ -769,6 +768,7 @@ indicator_datetime_panel_dispose (GObject * object) g_clear_object (&priv->builder); g_clear_object (&priv->proxy); + g_clear_object (&priv->settings); if (priv->loc_dlg) { gtk_widget_destroy (priv->loc_dlg); diff --git a/src/planner.c b/src/planner.c index 124aeae..e826c2c 100644 --- a/src/planner.c +++ b/src/planner.c @@ -188,6 +188,8 @@ indicator_datetime_planner_get_appointments (IndicatorDatetimePlanner * self, IndicatorDatetimePlannerClass * klass; g_return_if_fail (INDICATOR_IS_DATETIME_PLANNER (self)); + g_return_val_if_fail (begin != NULL, NULL); + g_return_val_if_fail (end != NULL, NULL); klass = INDICATOR_DATETIME_PLANNER_GET_CLASS (self); g_return_if_fail (klass->get_appointments != NULL); diff --git a/src/service.c b/src/service.c index c46beeb..0928205 100644 --- a/src/service.c +++ b/src/service.c @@ -227,7 +227,7 @@ calculate_seconds_until_next_fifteen_minutes (GDateTime * now) g_date_time_get_day_of_month (next), g_date_time_get_hour (next), g_date_time_get_minute (next), - 1); + 0.1); str = g_date_time_format (start_of_next, "%F %T"); g_debug ("%s %s the next timestamp rebuild will be at %s", G_STRLOC, G_STRFUNC, str); @@ -299,7 +299,7 @@ calculate_milliseconds_until_next_minute (GDateTime * now) g_date_time_get_day_of_month (next), g_date_time_get_hour (next), g_date_time_get_minute (next), - 0); + 0.1); interval_usec = g_date_time_difference (start_of_next, now); interval_msec = (interval_usec + 999) / 1000; @@ -424,43 +424,12 @@ skew_timer_func (gpointer gself) **** ***/ -typedef enum -{ - TIME_FORMAT_MODE_LOCALE_DEFAULT, - TIME_FORMAT_MODE_12_HOUR, - TIME_FORMAT_MODE_24_HOUR, - TIME_FORMAT_MODE_CUSTOM -} -TimeFormatMode; - -/* gets the user's time-format from GSettings */ -static TimeFormatMode -get_time_format_mode (IndicatorDatetimeService * self) -{ - char * str; - TimeFormatMode mode; - - str = g_settings_get_string (self->priv->settings, SETTINGS_TIME_FORMAT_S); - - if (!g_strcmp0 ("12-hour", str)) - mode = TIME_FORMAT_MODE_12_HOUR; - else if (!g_strcmp0 ("24-hour", str)) - mode = TIME_FORMAT_MODE_24_HOUR; - else if (!g_strcmp0 ("custom", str)) - mode = TIME_FORMAT_MODE_CUSTOM; - else - mode = TIME_FORMAT_MODE_LOCALE_DEFAULT; - - g_free (str); - return mode; -} - static gchar * get_header_label_format_string (IndicatorDatetimeService * self) { char * fmt; - const TimeFormatMode mode = get_time_format_mode (self); GSettings * s = self->priv->settings; + const TimeFormatMode mode = g_settings_get_enum (s, SETTINGS_TIME_FORMAT_S); if (mode == TIME_FORMAT_MODE_CUSTOM) { @@ -470,7 +439,7 @@ get_header_label_format_string (IndicatorDatetimeService * self) { gboolean show_day = g_settings_get_boolean (s, SETTINGS_SHOW_DAY_S); gboolean show_date = g_settings_get_boolean (s, SETTINGS_SHOW_DATE_S); - fmt = generate_full_format_string (show_day, show_date); + fmt = generate_full_format_string (show_day, show_date, s); } return fmt; @@ -497,14 +466,13 @@ create_desktop_header_state (IndicatorDatetimeService * self) g_warning ("%s", str); } - g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_init (&b, G_VARIANT_TYPE_VARDICT); g_variant_builder_add (&b, "{sv}", "accessible-desc", g_variant_new_string (str)); - g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (str)); + g_variant_builder_add (&b, "{sv}", "label", g_variant_new_take_string (str)); g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (visible)); /* cleanup */ g_date_time_unref (now); - g_free (str); g_free (fmt); return g_variant_builder_end (&b); } @@ -522,13 +490,12 @@ create_phone_header_state (IndicatorDatetimeService * self) gboolean has_alarms; gchar * a11y; - g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); + g_variant_builder_init (&b, G_VARIANT_TYPE_VARDICT); /* label */ now = indicator_datetime_service_get_localtime (self); fmt = get_terse_time_format_string (now); label = g_date_time_format (now, fmt); - g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label)); /* icon */ if ((has_alarms = service_has_alarms (self))) @@ -545,14 +512,12 @@ create_phone_header_state (IndicatorDatetimeService * self) else a11y = g_strdup (label); g_variant_builder_add (&b, "{sv}", "accessible-desc", - g_variant_new_string (a11y)); + g_variant_new_take_string (a11y)); - /* visible */ g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (TRUE)); + g_variant_builder_add (&b, "{sv}", "label", g_variant_new_take_string (label)); /* cleanup */ - g_free (a11y); - g_free (label); g_date_time_unref (now); return g_variant_builder_end (&b); } @@ -652,10 +617,8 @@ add_localtime_menuitem (GMenu * menu, static void add_calendar_menuitem (GMenu * menu) { - char * label; GMenuItem * menu_item; - label = g_strdup ("[calendar]"); menu_item = g_menu_item_new ("[calendar]", NULL); g_menu_item_set_action_and_target_value (menu_item, "indicator.calendar", g_variant_new_int64(0)); g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", "com.canonical.indicator.calendar"); @@ -663,7 +626,6 @@ add_calendar_menuitem (GMenu * menu) g_menu_append_item (menu, menu_item); g_object_unref (menu_item); - g_free (label); } static GMenuModel * @@ -721,6 +683,7 @@ service_has_alarms (IndicatorDatetimeService * self) static char * get_appointment_time_format (struct IndicatorDatetimeAppt * appt, GDateTime * now, + GSettings * settings, gboolean terse) { char * fmt; @@ -729,7 +692,7 @@ get_appointment_time_format (struct IndicatorDatetimeAppt * appt, if (appt->is_daily) { const char * time_fmt = terse ? get_terse_time_format_string (appt->begin) - : get_full_time_format_string (); + : get_full_time_format_string (settings); fmt = join_date_and_time_format_strings (_("Daily"), time_fmt); } else if (full_day) @@ -741,7 +704,7 @@ get_appointment_time_format (struct IndicatorDatetimeAppt * appt, else { fmt = terse ? generate_terse_format_string_at_time (now, appt->begin) - : generate_full_format_string_at_time (now, appt->begin); + : generate_full_format_string_at_time (now, appt->begin, settings); } return fmt; @@ -761,7 +724,7 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) for (l=appts, i=0; l!=NULL && i<MAX_APPTS; l=l->next, i++) { struct IndicatorDatetimeAppt * appt = l->data; - char * fmt = get_appointment_time_format (appt, now, terse); + char * fmt = get_appointment_time_format (appt, now, self->priv->settings, terse); const gint64 unix_time = g_date_time_to_unix (appt->begin); GMenuItem * menu_item; @@ -1001,7 +964,7 @@ create_locations_section (IndicatorDatetimeService * self) const char * tz = indicator_datetime_timezone_get_timezone (detected_timezones[i]); if (tz && *tz) { - gchar * name = get_current_zone_name (tz); + gchar * name = get_current_zone_name (tz, p->settings); locations = locations_add (locations, tz, name, visible); g_free (name); } @@ -1034,18 +997,16 @@ create_locations_section (IndicatorDatetimeService * self) struct TimeLocation * loc = l->data; if (loc->visible) { - char * label; char * detailed_action; char * fmt; GMenuItem * menu_item; - label = g_strdup (loc->name); detailed_action = g_strdup_printf ("indicator.set-location::%s %s", loc->zone, loc->name); - fmt = generate_full_format_string_at_time (now, loc->local_time); + fmt = generate_full_format_string_at_time (now, loc->local_time, p->settings); - menu_item = g_menu_item_new (label, detailed_action); + menu_item = g_menu_item_new (loc->name, detailed_action); g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", "com.canonical.indicator.location"); g_menu_item_set_attribute (menu_item, "x-canonical-timezone", @@ -1057,7 +1018,6 @@ create_locations_section (IndicatorDatetimeService * self) g_object_unref (menu_item); g_free (fmt); g_free (detailed_action); - g_free (label); } } @@ -1650,8 +1610,8 @@ update_appointment_lists (IndicatorDatetimeService * self) /* get all the appointments in the calendar month */ g_date_time_get_ymd (calendar_date, &y, &m, &d); - begin = g_date_time_new_local (y, m, 1, 0, 0, 0); - end = g_date_time_new_local (y, m, g_date_get_days_in_month(m,y), 23, 59, 0); + begin = g_date_time_new_local (y, m, 1, 0, 0, 0.1); + end = g_date_time_new_local (y, m, g_date_get_days_in_month(m,y), 23, 59, 59.9); if (begin && end) indicator_datetime_planner_get_appointments (planner, begin, end, on_calendar_appointments_ready, diff --git a/src/settings-shared.h b/src/settings-shared.h index 27ce34c..afcccb6 100644 --- a/src/settings-shared.h +++ b/src/settings-shared.h @@ -22,6 +22,15 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef __DATETIME_SETTINGS_SHARED_H__ #define __DATETIME_SETTINGS_SHARED_H__ +typedef enum +{ + TIME_FORMAT_MODE_LOCALE_DEFAULT, + TIME_FORMAT_MODE_12_HOUR, + TIME_FORMAT_MODE_24_HOUR, + TIME_FORMAT_MODE_CUSTOM +} +TimeFormatMode; + #define SETTINGS_INTERFACE "com.canonical.indicator.datetime" #define SETTINGS_SHOW_CLOCK_S "show-clock" #define SETTINGS_TIME_FORMAT_S "time-format" diff --git a/src/utils.c b/src/utils.c index 5dccc52..9b0f24f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -91,19 +91,18 @@ split_settings_location (const gchar * location, gchar ** zone, gchar ** name) } gchar * -get_current_zone_name (const gchar * location) +get_current_zone_name (const gchar * location, GSettings * settings) { gchar * new_zone, * new_name; + gchar * tz_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); + tz_name = g_settings_get_string (settings, 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 @@ -143,9 +142,9 @@ T_(const char *msg) LC_MESSAGES directory, so we won't find any translation there. */ char *message_locale = g_strdup(setlocale(LC_MESSAGES, NULL)); - char *time_locale = g_strdup(setlocale(LC_TIME, NULL)); + const char *time_locale = setlocale (LC_TIME, NULL); char *language = g_strdup(g_getenv("LANGUAGE")); - char *rv; + const char *rv; if (language) g_unsetenv("LANGUAGE"); setlocale(LC_MESSAGES, time_locale); @@ -158,7 +157,6 @@ T_(const char *msg) if (language) g_setenv("LANGUAGE", language, TRUE); g_free(message_locale); - g_free(time_locale); g_free(language); return rv; } @@ -357,33 +355,24 @@ get_full_date_format_string (gboolean show_day, gboolean show_date) * */ -enum -{ - SETTINGS_TIME_LOCALE = 0, - SETTINGS_TIME_12_HOUR = 1, - SETTINGS_TIME_24_HOUR = 2, - SETTINGS_TIME_CUSTOM = 3 -}; - const gchar * -get_full_time_format_string (void) +get_full_time_format_string (GSettings * settings) { - GSettings * settings; gboolean twelvehour; gboolean show_seconds; const gchar * fmt; - settings = g_settings_new (SETTINGS_INTERFACE); + g_return_val_if_fail (settings != NULL, NULL); show_seconds = g_settings_get_boolean (settings, SETTINGS_SHOW_SECONDS_S); switch (g_settings_get_enum (settings, SETTINGS_TIME_FORMAT_S)) { - case SETTINGS_TIME_LOCALE: + case TIME_FORMAT_MODE_LOCALE_DEFAULT: twelvehour = is_locale_12h(); break; - case SETTINGS_TIME_24_HOUR: + case TIME_FORMAT_MODE_24_HOUR: twelvehour = FALSE; break; @@ -392,8 +381,6 @@ get_full_time_format_string (void) break; } - g_object_unref (settings); - if (twelvehour && show_seconds) /* TRANSLATORS: a strftime(3) format for 12hr time w/seconds */ fmt = T_("%l:%M:%S %p"); @@ -411,19 +398,23 @@ get_full_time_format_string (void) } gchar * -generate_full_format_string (gboolean show_day, gboolean show_date) +generate_full_format_string (gboolean show_day, gboolean show_date, GSettings * settings) { const gchar * date_fmt = get_full_date_format_string (show_day, show_date); - const gchar * time_fmt = get_full_time_format_string (); + const gchar * time_fmt = get_full_time_format_string (settings); return join_date_and_time_format_strings (date_fmt, time_fmt); } gchar * -generate_full_format_string_at_time (GDateTime * now, GDateTime * time) +generate_full_format_string_at_time (GDateTime * now, GDateTime * time, GSettings * settings) { gboolean show_day; gboolean show_date; + g_return_val_if_fail (now != NULL, NULL); + g_return_val_if_fail (time != NULL, NULL); + g_return_val_if_fail (settings != NULL, NULL); + switch (get_date_proximity (now, time)) { case DATE_PROXIMITY_TODAY: @@ -443,6 +434,6 @@ generate_full_format_string_at_time (GDateTime * now, GDateTime * time) break; } - return generate_full_format_string (show_day, show_date); + return generate_full_format_string (show_day, show_date, settings); } diff --git a/src/utils.h b/src/utils.h index 3b0d0a2..fff9194 100644 --- a/src/utils.h +++ b/src/utils.h @@ -33,7 +33,8 @@ void split_settings_location (const char * location, char ** zone, char ** name); -gchar * get_current_zone_name (const char * location); +gchar * get_current_zone_name (const char * location, + GSettings * settings); gchar* join_date_and_time_format_strings (const char * date_fmt, const char * time_fmt); @@ -43,16 +44,18 @@ gchar* join_date_and_time_format_strings (const char * date_fmt, const gchar * get_terse_time_format_string (GDateTime * time); -const gchar * get_full_time_format_string (void); +const gchar * get_full_time_format_string (GSettings * settings); gchar * generate_terse_format_string_at_time (GDateTime * now, GDateTime * time); gchar * generate_full_format_string (gboolean show_day, - gboolean show_date); + gboolean show_date, + GSettings * settings); gchar * generate_full_format_string_at_time (GDateTime * now, - GDateTime * time); + GDateTime * time, + GSettings * settings); G_END_DECLS |