aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datetime-prefs-locations.c5
-rw-r--r--src/datetime-prefs.c20
-rw-r--r--src/service.c13
-rw-r--r--src/utils.c29
-rw-r--r--src/utils.h11
5 files changed, 42 insertions, 36 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/service.c b/src/service.c
index 0d8192a..3340337 100644
--- a/src/service.c
+++ b/src/service.c
@@ -439,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;
@@ -690,6 +690,7 @@ service_has_alarms (IndicatorDatetimeService * self)
static char *
get_appointment_time_format (struct IndicatorDatetimeAppt * appt,
GDateTime * now,
+ GSettings * settings,
gboolean terse)
{
char * fmt;
@@ -698,7 +699,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)
@@ -710,7 +711,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;
@@ -730,7 +731,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;
@@ -970,7 +971,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);
}
@@ -1012,7 +1013,7 @@ create_locations_section (IndicatorDatetimeService * self)
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);
g_menu_item_set_attribute (menu_item, "x-canonical-type",
diff --git a/src/utils.c b/src/utils.c
index 5b1f58f..f8aa1f8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -82,19 +82,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
@@ -349,14 +348,13 @@ get_full_date_format_string (gboolean show_day, gboolean show_date)
*/
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);
@@ -370,14 +368,11 @@ get_full_time_format_string (void)
twelvehour = FALSE;
break;
- case TIME_FORMAT_MODE_12_HOUR:
- case TIME_FORMAT_MODE_CUSTOM:
+ default:
twelvehour = TRUE;
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");
@@ -395,19 +390,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:
@@ -427,6 +426,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