aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-11-08 09:23:54 -0600
committerCharles Kerr <charles.kerr@canonical.com>2013-11-08 09:23:54 -0600
commit063a6b3c082bc788510a3da6c8f2425a33973b32 (patch)
treea516db5b838355cf885a076e8bdc062caf5a595f
parent4c4adbcbf17733c47d23f0eec578c0574ef64efa (diff)
downloadayatana-indicator-datetime-063a6b3c082bc788510a3da6c8f2425a33973b32.tar.gz
ayatana-indicator-datetime-063a6b3c082bc788510a3da6c8f2425a33973b32.tar.bz2
ayatana-indicator-datetime-063a6b3c082bc788510a3da6c8f2425a33973b32.zip
when setting a G_MENU_ATTRIBUTE_ICON property, use g_icon_serialize() output instead of a filename / themed icon name
-rw-r--r--src/service.c127
1 files changed, 74 insertions, 53 deletions
diff --git a/src/service.c b/src/service.c
index 1ffb745..38564d2 100644
--- a/src/service.c
+++ b/src/service.c
@@ -101,15 +101,8 @@ struct _IndicatorDatetimeServicePrivate
IndicatorDatetimeClock * clock;
IndicatorDatetimePlanner * planner;
- /* the clock app's icon filename */
- gchar * clock_app_icon_filename;
-
gchar * header_label_format_string;
- /* Whether or not we've tried to load the clock app's icon.
- This way we don't keep trying to reload it on the desktop */
- gboolean clock_app_icon_initialized;
-
guint own_id;
guint actions_export_id;
GDBusConnection * conn;
@@ -147,11 +140,16 @@ struct _IndicatorDatetimeServicePrivate
GSList * upcoming_appointments;
/* variant cache */
- GVariant * desktop_title_variant;
- GVariant * phone_title_variant;
- GVariant * visible_true_variant;
- GVariant * visible_false_variant;
- GVariant * alarm_icon_variant;
+
+ GVariant * alarm_icon_serialized;
+ GVariant * calendar_icon_serialized;
+ GVariant * clock_app_icon_serialized;
+
+ GVariant * desktop_title_dict_entry;
+ GVariant * phone_title_dict_entry;
+ GVariant * visible_true_dict_entry;
+ GVariant * visible_false_dict_entry;
+ GVariant * alarm_icon_dict_entry;
};
typedef IndicatorDatetimeServicePrivate priv_t;
@@ -703,8 +701,8 @@ create_desktop_header_state (IndicatorDatetimeService * self)
g_variant_builder_init (&b, G_VARIANT_TYPE_VARDICT);
g_variant_builder_add (&b, "{sv}", "accessible-desc", label_variant);
g_variant_builder_add (&b, "{sv}", "label", label_variant);
- g_variant_builder_add_value (&b, p->desktop_title_variant);
- g_variant_builder_add_value (&b, visible ? p->visible_true_variant : p->visible_false_variant);
+ g_variant_builder_add_value (&b, p->desktop_title_dict_entry);
+ g_variant_builder_add_value (&b, visible ? p->visible_true_dict_entry : p->visible_false_dict_entry);
/* cleanup */
g_date_time_unref (now);
@@ -724,12 +722,11 @@ create_phone_header_state (IndicatorDatetimeService * self)
const gchar * fmt;
g_variant_builder_init (&b, G_VARIANT_TYPE_VARDICT);
- g_variant_builder_add_value (&b, p->phone_title_variant);
- g_variant_builder_add_value (&b, p->visible_true_variant);
+ g_variant_builder_add_value (&b, p->phone_title_dict_entry);
+ g_variant_builder_add_value (&b, p->visible_true_dict_entry);
- /* icon */
if (has_alarms)
- g_variant_builder_add_value (&b, p->alarm_icon_variant);
+ g_variant_builder_add_value (&b, p->alarm_icon_dict_entry);
/* label, a11y */
now = indicator_datetime_service_get_localtime (self);
@@ -836,7 +833,7 @@ create_calendar_section (IndicatorDatetimeService * self, int profile)
now = indicator_datetime_service_get_localtime (self);
label = g_date_time_format (now, _("%A, %e %B %Y"));
item = g_menu_item_new (label, NULL);
- g_menu_item_set_attribute (item, G_MENU_ATTRIBUTE_ICON, "s", "calendar");
+ g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, self->priv->calendar_icon_serialized);
if (allow_activation)
g_menu_item_set_action_and_target_value (item, "indicator.activate-planner", g_variant_new_int64(0));
g_menu_append_item (menu, item);
@@ -947,19 +944,19 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean phone)
menu_item = g_menu_item_new (appt->summary, NULL);
if (appt->has_alarms)
- g_menu_item_set_attribute (menu_item, G_MENU_ATTRIBUTE_ICON,
- "s", ALARM_CLOCK_ICON_NAME);
+ g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON,
+ self->priv->alarm_icon_serialized);
else if (appt->color != NULL)
g_menu_item_set_attribute (menu_item, "x-canonical-color",
"s", appt->color);
g_menu_item_set_attribute (menu_item, "x-canonical-time",
- "x", unix_time);
+ "x", unix_time);
g_menu_item_set_attribute (menu_item, "x-canonical-time-format",
- "s", fmt);
+ "s", fmt);
g_menu_item_set_attribute (menu_item, "x-canonical-type",
- "s", appt->has_alarms ? "com.canonical.indicator.alarm"
- : "com.canonical.indicator.appointment");
+ "s", appt->has_alarms ? "com.canonical.indicator.alarm"
+ : "com.canonical.indicator.appointment");
if (phone)
g_menu_item_set_action_and_target_value (menu_item,
@@ -981,9 +978,10 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean phone)
/* try to extract the clock app's filename from click. (/$pkgdir/$icon) */
-static gchar *
-get_clock_app_icon_filename (void)
+static GVariant *
+get_clock_app_icon (void)
{
+ GVariant * serialized = NULL;
gchar * icon_filename = NULL;
gchar * pkgdir;
@@ -1014,7 +1012,19 @@ get_clock_app_icon_filename (void)
g_free (pkgdir);
}
- return icon_filename;
+ if (icon_filename != NULL)
+ {
+ GFile * file = g_file_new_for_path (icon_filename);
+ GIcon * icon = g_file_icon_new (file);
+
+ serialized = g_icon_serialize (icon);
+
+ g_object_unref (icon);
+ g_object_unref (file);
+ g_free (icon_filename);
+ }
+
+ return serialized;
}
static GMenuModel *
@@ -1024,15 +1034,9 @@ create_phone_appointments_section (IndicatorDatetimeService * self)
GMenu * menu = g_menu_new ();
GMenuItem * menu_item;
- if (G_UNLIKELY (!p->clock_app_icon_initialized))
- {
- p->clock_app_icon_initialized = TRUE;
- p->clock_app_icon_filename = get_clock_app_icon_filename ();
- }
-
menu_item = g_menu_item_new (_("Clock"), "indicator.activate-phone-clock-app");
- if (p->clock_app_icon_filename != NULL)
- g_menu_item_set_attribute (menu_item, G_MENU_ATTRIBUTE_ICON, "s", p->clock_app_icon_filename);
+ if (p->clock_app_icon_serialized != NULL)
+ g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, p->clock_app_icon_serialized);
g_menu_append_item (menu, menu_item);
g_object_unref (menu_item);
@@ -2081,11 +2085,14 @@ my_dispose (GObject * o)
g_clear_object (&p->phone_header_action);
g_clear_object (&p->conn);
- g_clear_pointer (&p->desktop_title_variant, g_variant_unref);
- g_clear_pointer (&p->phone_title_variant, g_variant_unref);
- g_clear_pointer (&p->visible_true_variant, g_variant_unref);
- g_clear_pointer (&p->visible_false_variant, g_variant_unref);
- g_clear_pointer (&p->alarm_icon_variant, g_variant_unref);
+ g_clear_pointer (&p->desktop_title_dict_entry, g_variant_unref);
+ g_clear_pointer (&p->phone_title_dict_entry, g_variant_unref);
+ g_clear_pointer (&p->visible_true_dict_entry, g_variant_unref);
+ g_clear_pointer (&p->visible_false_dict_entry, g_variant_unref);
+ g_clear_pointer (&p->alarm_icon_dict_entry, g_variant_unref);
+ g_clear_pointer (&p->alarm_icon_serialized, g_variant_unref);
+ g_clear_pointer (&p->calendar_icon_serialized, g_variant_unref);
+ g_clear_pointer (&p->clock_app_icon_serialized, g_variant_unref);
G_OBJECT_CLASS (indicator_datetime_service_parent_class)->dispose (o);
}
@@ -2096,7 +2103,6 @@ my_finalize (GObject * o)
IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE(o);
priv_t * p = self->priv;
- g_free (p->clock_app_icon_filename);
g_free (p->header_label_format_string);
g_clear_pointer (&p->skew_time, g_date_time_unref);
g_clear_pointer (&p->calendar_date, g_date_time_unref);
@@ -2111,8 +2117,9 @@ my_finalize (GObject * o)
static void
indicator_datetime_service_init (IndicatorDatetimeService * self)
{
- GIcon * icon;
priv_t * p;
+ GIcon * icon;
+ GVariant * v;
/* init the priv pointer */
@@ -2125,22 +2132,36 @@ indicator_datetime_service_init (IndicatorDatetimeService * self)
p->settings = g_settings_new (SETTINGS_INTERFACE);
- p->desktop_title_variant = g_variant_new ("{sv}", "title", g_variant_new_string (_("Date and Time")));
- g_variant_ref_sink (p->desktop_title_variant);
+ /* build our variant cache */
- p->phone_title_variant = g_variant_new ("{sv}", "title", g_variant_new_string (_("Upcoming")));
- g_variant_ref_sink (p->phone_title_variant);
+ v = p->desktop_title_dict_entry = g_variant_new ("{sv}", "title", g_variant_new_string (_("Date and Time")));
+ g_variant_ref_sink (v);
- p->visible_true_variant = g_variant_new ("{sv}", "visible", g_variant_new_boolean (TRUE));
- g_variant_ref_sink (p->visible_true_variant);
+ v = p->phone_title_dict_entry = g_variant_new ("{sv}", "title", g_variant_new_string (_("Upcoming")));
+ g_variant_ref_sink (v);
- p->visible_false_variant = g_variant_new ("{sv}", "visible", g_variant_new_boolean (FALSE));
- g_variant_ref_sink (p->visible_false_variant);
+ v = p->visible_true_dict_entry = g_variant_new ("{sv}", "visible", g_variant_new_boolean (TRUE));
+ g_variant_ref_sink (v);
+
+ v = p->visible_false_dict_entry = g_variant_new ("{sv}", "visible", g_variant_new_boolean (FALSE));
+ g_variant_ref_sink (v);
icon = g_themed_icon_new_with_default_fallbacks (ALARM_CLOCK_ICON_NAME);
- p->alarm_icon_variant = g_variant_new ("{sv}", "icon", g_icon_serialize (icon));
- g_variant_ref_sink (p->alarm_icon_variant);
+ v = p->alarm_icon_serialized = g_icon_serialize (icon);
+ g_variant_ref_sink (v);
g_object_unref (icon);
+
+ v = p->alarm_icon_dict_entry = g_variant_new ("{sv}", "icon", p->alarm_icon_serialized);
+ g_variant_ref_sink (v);
+
+ icon = g_themed_icon_new_with_default_fallbacks ("calendar");
+ v = p->calendar_icon_serialized = g_icon_serialize (icon);
+ g_variant_ref_sink (v);
+ g_object_unref (icon);
+
+ v = p->clock_app_icon_serialized = get_clock_app_icon ();
+ if (v != NULL)
+ g_variant_ref_sink (v);
}
static void