aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-09-08 20:17:44 +0000
committerTarmac <Unknown>2013-09-08 20:17:44 +0000
commitb7f625ed8003197cd9d0a81240aea944860c8dc3 (patch)
treed94fd355f855c179072831004f8e3ae17b7b87d1
parent0896192c82c10144c184f274943ed692599d7529 (diff)
parente2096aa3f7d1a78ad0a8968a29529a6609a6fd5a (diff)
downloadayatana-indicator-datetime-b7f625ed8003197cd9d0a81240aea944860c8dc3.tar.gz
ayatana-indicator-datetime-b7f625ed8003197cd9d0a81240aea944860c8dc3.tar.bz2
ayatana-indicator-datetime-b7f625ed8003197cd9d0a81240aea944860c8dc3.zip
This change adds a GSettings* arg to the utils functions so that they don't have to churn through temporary GSettings objects.
These functions are usually called in a loop, causing a lot of GSettings temporaries, even though the calling code already has an instance for that GSettings schema. Approved by Ted Gould, PS Jenkins bot.
-rw-r--r--src/datetime-prefs-locations.c5
-rw-r--r--src/datetime-prefs.c20
-rw-r--r--src/service.c50
-rw-r--r--src/settings-shared.h9
-rw-r--r--src/utils.c38
-rw-r--r--src/utils.h11
6 files changed, 55 insertions, 78 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 39805a7..0928205 100644
--- a/src/service.c
+++ b/src/service.c
@@ -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,7 +466,7 @@ 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_take_string (str));
g_variant_builder_add (&b, "{sv}", "visible", g_variant_new_boolean (visible));
@@ -521,7 +490,7 @@ 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);
@@ -714,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;
@@ -722,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)
@@ -734,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;
@@ -754,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;
@@ -994,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,7 +1004,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 (loc->name, detailed_action);
g_menu_item_set_attribute (menu_item, "x-canonical-type",
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 50d896d..1c3626d 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
@@ -347,33 +346,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;
@@ -382,8 +372,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");
@@ -401,19 +389,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:
@@ -433,6 +425,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