From 44e84ede3da7d4a7e45c8c5b674a21703811e15c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 14:37:01 -0500 Subject: Setting up the label and lable guide properties. --- src/app-indicator.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index 32f512f..98e90ae 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -104,7 +104,9 @@ enum { PROP_ATTENTION_ICON_NAME, PROP_ICON_THEME_PATH, PROP_MENU, - PROP_CONNECTED + PROP_CONNECTED, + PROP_LABEL, + PROP_LABEL_GUIDE }; /* The strings so that they can be slowly looked up. */ @@ -116,6 +118,8 @@ enum { #define PROP_ICON_THEME_PATH_S "icon-theme-path" #define PROP_MENU_S "menu" #define PROP_CONNECTED_S "connected" +#define PROP_LABEL_S "label" +#define PROP_LABEL_GUIDE_S "label-guide" /* Private macro, shhhh! */ #define APP_INDICATOR_GET_PRIVATE(o) \ @@ -284,6 +288,41 @@ app_indicator_class_init (AppIndicatorClass *klass) "Pretty simple, true if we have a reasonable expectation of being displayed through this object. You should hide your TrayIcon if so.", FALSE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + /** + AppIndicator:label: + + A label that can be shown next to the string in the application + indicator. The label will not be shown unless there is an icon + as well. The label is useful for numerical and other frequently + updated information. In general, it shouldn't be shown unless a + user requests it as it can take up a significant amount of space + on the user's panel. This may not be shown in all visualizations. + */ + g_object_class_install_property(object_class, + PROP_LABEL, + g_param_spec_string (PROP_LABEL_S, + "A label next to the icon", + "A label to provide dynamic information.", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + /** + AppIndicator:label-guide: + + An optional string to provide guidance to the panel on how big + the #AppIndicator:label string could get. If this is set correctly + then the panel should never 'jiggle' as the string adjusts through + out the range of options. For instance, if you were providing a + percentage like "54% thrust" in #AppIndicator:label you'd want to + set this string to "100% thrust" to ensure space when Scotty can + get you enough power. + */ + g_object_class_install_property(object_class, + PROP_LABEL_GUIDE, + g_param_spec_string (PROP_LABEL_GUIDE_S, + "A string to size the space available for the label.", + "To ensure that the label does not cause the panel to 'jiggle' this string should provide information on how much space it could take.", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /* Signals */ -- cgit v1.2.3 From e541156e92220917a58ff8abce1cfa235dc343f1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 14:47:42 -0500 Subject: Adding the label and guide fields to the private struct and tying that into the properties. --- src/app-indicator.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index 98e90ae..29149ae 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -72,6 +72,8 @@ struct _AppIndicatorPrivate { gchar * icon_path; DbusmenuServer *menuservice; GtkWidget *menu; + gchar * label; + gchar * label_guide; GtkStatusIcon * status_icon; gint fallback_timer; @@ -407,6 +409,8 @@ app_indicator_init (AppIndicator *self) priv->icon_path = NULL; priv->menu = NULL; priv->menuservice = NULL; + priv->label = NULL; + priv->label_guide = NULL; priv->watcher_proxy = NULL; priv->connection = NULL; @@ -530,6 +534,16 @@ app_indicator_finalize (GObject *object) g_free(priv->icon_path); priv->icon_path = NULL; } + + if (priv->label != NULL) { + g_free(priv->label); + priv->label = NULL; + } + + if (priv->label_guide != NULL) { + g_free(priv->label_guide); + priv->label_guide = NULL; + } G_OBJECT_CLASS (app_indicator_parent_class)->finalize (object); return; @@ -602,6 +616,33 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu priv->icon_path = g_value_dup_string(value); break; + case PROP_LABEL: { + gchar * oldlabel = priv->label; + priv->label = g_value_dup_string(value); + + if (g_strcmp0(oldlabel, priv->label) != 0) { + // TODO: signal change + } + + if (oldlabel != NULL) { + g_free(oldlabel); + } + break; + } + case PROP_LABEL_GUIDE: { + gchar * oldguide = priv->label_guide; + priv->label_guide = g_value_dup_string(value); + + if (g_strcmp0(oldguide, priv->label_guide) != 0) { + // TODO: signal change + } + + if (oldguide != NULL) { + g_free(oldguide); + } + break; + } + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -659,6 +700,14 @@ app_indicator_get_property (GObject * object, guint prop_id, GValue * value, GPa g_value_set_boolean (value, priv->watcher_proxy != NULL ? TRUE : FALSE); break; + case PROP_LABEL: + g_value_set_string (value, priv->label); + break; + + case PROP_LABEL_GUIDE: + g_value_set_string (value, priv->label_guide); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; -- cgit v1.2.3 From 706a72b9b2a36c39ce274a2508031b4cc0f4bb2e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 15:12:23 -0500 Subject: Adding in the convience wrappers --- src/app-indicator.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index 29149ae..ce79165 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -1222,6 +1222,31 @@ app_indicator_set_icon (AppIndicator *self, const gchar *icon_name) return; } +/** + app_indicator_set_label: + @self: The #AppIndicator object to use + @label: The label to show next to the icon. + @guide: A guide to size the label correctly. + + This is a wrapper function for the #AppIndicator:label and + #AppIndicator:guide properties. This function can take #NULL + as either @label or @guide and will clear the entries. +*/ +void +app_indicator_set_label (AppIndicator *self, const gchar * label, const gchar * guide) +{ + g_return_if_fail (IS_APP_INDICATOR (self)); + /* Note: The label can be NULL, it's okay */ + /* Note: The guide can be NULL, it's okay */ + + g_object_set(G_OBJECT(self), + PROP_LABEL_S, label == NULL ? "" : label, + PROP_LABEL_GUIDE_S, guide == NULL ? "" : guide, + NULL); + + return; +} + static void activate_menuitem (DbusmenuMenuitem *mi, guint timestamp, gpointer user_data) { @@ -1749,3 +1774,36 @@ app_indicator_get_menu (AppIndicator *self) return GTK_MENU(priv->menu); } + +/** + app_indicator_get_label: + @self: The #AppIndicator object to use + + Wrapper function for property #AppIndicator:label. + + Return value: The current label. +*/ +const gchar * +app_indicator_get_label (AppIndicator *self) +{ + g_return_val_if_fail (IS_APP_INDICATOR (self), NULL); + + return self->priv->label; +} + +/** + app_indicator_get_label_guide: + @self: The #AppIndicator object to use + + Wrapper function for property #AppIndicator:label-guide. + + Return value: The current label guide. +*/ +const gchar * +app_indicator_get_label_guide (AppIndicator *self) +{ + g_return_val_if_fail (IS_APP_INDICATOR (self), NULL); + + return self->priv->label_guide; +} + -- cgit v1.2.3 From fc9d5d4f762493d0b8378b12ac6c8451e5b9683b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 15:55:21 -0500 Subject: Adding in a signal to tell when the label is updated. --- src/app-indicator.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index ce79165..ec153c6 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -89,6 +89,7 @@ enum { NEW_ICON, NEW_ATTENTION_ICON, NEW_STATUS, + NEW_LABEL, CONNECTION_CHANGED, LAST_SIGNAL }; @@ -373,6 +374,23 @@ app_indicator_class_init (AppIndicatorClass *klass) G_TYPE_NONE, 1, G_TYPE_STRING); + /** + AppIndicator::new-label: + @arg0: The #AppIndicator object + @arg1: The string for the label + @arg1: The string for the guide + + Emitted when either #AppIndicator:label or #AppIndicator:label-guide are + changed. + */ + signals[NEW_LABEL] = g_signal_new (APP_INDICATOR_SIGNAL_NEW_LABEL, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (AppIndicatorClass, new_label), + NULL, NULL, + g_cclosure_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); + /** AppIndicator::connection-changed: @arg0: The #AppIndicator object -- cgit v1.2.3 From 84821ece8828fc87a45b9ba2ca75ef0a15d797ce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 16:18:42 -0500 Subject: Reusing the application service marshallers, not beautiful, but it works for now. --- src/app-indicator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index ec153c6..e0ccec4 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -37,6 +37,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "app-indicator.h" #include "app-indicator-enum-types.h" +#include "application-service-marshal.h" #include "notification-item-server.h" #include "notification-watcher-client.h" @@ -388,7 +389,7 @@ app_indicator_class_init (AppIndicatorClass *klass) G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (AppIndicatorClass, new_label), NULL, NULL, - g_cclosure_marshal_VOID__STRING_STRING, + _application_service_marshal_VOID__STRING_STRING, G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); /** -- cgit v1.2.3 From 52bfc9d4ba3d38ab07004b6fdb04173912329cf8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 16:45:18 -0500 Subject: Signaling when the labels change in the idle loop --- src/app-indicator.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index e0ccec4..0da0b01 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -75,6 +75,7 @@ struct _AppIndicatorPrivate { GtkWidget *menu; gchar * label; gchar * label_guide; + guint label_change_idle; GtkStatusIcon * status_icon; gint fallback_timer; @@ -144,6 +145,7 @@ static void app_indicator_finalize (GObject *object); static void app_indicator_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void app_indicator_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); /* Other stuff */ +static void signal_label_change (AppIndicator * self); static void check_connect (AppIndicator * self); static void register_service_cb (DBusGProxy * proxy, GError * error, gpointer data); static void start_fallback_timer (AppIndicator * self, gboolean disable_timeout); @@ -430,6 +432,7 @@ app_indicator_init (AppIndicator *self) priv->menuservice = NULL; priv->label = NULL; priv->label_guide = NULL; + priv->label_change_idle = 0; priv->watcher_proxy = NULL; priv->connection = NULL; @@ -481,6 +484,11 @@ app_indicator_dispose (GObject *object) priv->fallback_timer = 0; } + if (priv->label_change_idle != 0) { + g_source_remove(priv->label_change_idle); + priv->label_change_idle = 0; + } + if (priv->menu != NULL) { g_signal_handlers_disconnect_by_func (G_OBJECT (priv->menu), client_menu_changed, @@ -640,7 +648,7 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu priv->label = g_value_dup_string(value); if (g_strcmp0(oldlabel, priv->label) != 0) { - // TODO: signal change + signal_label_change(APP_INDICATOR(object)); } if (oldlabel != NULL) { @@ -653,7 +661,7 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu priv->label_guide = g_value_dup_string(value); if (g_strcmp0(oldguide, priv->label_guide) != 0) { - // TODO: signal change + signal_label_change(APP_INDICATOR(object)); } if (oldguide != NULL) { @@ -735,6 +743,39 @@ app_indicator_get_property (GObject * object, guint prop_id, GValue * value, GPa return; } +/* Sends the label changed signal and resets the source ID */ +static gboolean +signal_label_change_idle (gpointer user_data) +{ + AppIndicator * self = (AppIndicator *)user_data; + AppIndicatorPrivate *priv = self->priv; + + g_signal_emit(G_OBJECT(self), signals[NEW_LABEL], 0, + priv->label != NULL ? priv->label : "", + priv->label_guide != NULL ? priv->label_guide : "", + TRUE); + + priv->label_change_idle = 0; + + return FALSE; +} + +/* Sets up an idle function to send the label changed signal + so that we don't send it too many times. */ +static void +signal_label_change (AppIndicator * self) +{ + AppIndicatorPrivate *priv = self->priv; + + /* don't set it twice */ + if (priv->label_change_idle != 0) { + return; + } + + priv->label_change_idle = g_idle_add(signal_label_change_idle, self); + return; +} + /* This function is used to see if we have enough information to connect to things. If we do, and we're not connected, it connects for us. */ -- cgit v1.2.3 From f72116833d67c954ec69dfe8aced4e7e26c36c23 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Aug 2010 17:09:57 -0500 Subject: Turning null strings into NULLs --- src/app-indicator.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index 0da0b01..b3fa3e5 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -651,6 +651,11 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu signal_label_change(APP_INDICATOR(object)); } + if (priv->label != NULL && priv->label[0] == '\0') { + g_free(priv->label); + priv->label = NULL; + } + if (oldlabel != NULL) { g_free(oldlabel); } @@ -664,6 +669,11 @@ app_indicator_set_property (GObject * object, guint prop_id, const GValue * valu signal_label_change(APP_INDICATOR(object)); } + if (priv->label_guide != NULL && priv->label_guide[0] == '\0') { + g_free(priv->label_guide); + priv->label_guide = NULL; + } + if (oldguide != NULL) { g_free(oldguide); } -- cgit v1.2.3 From d377c945f1dcc36710313fdfa7e79b725fa8d42e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 5 Aug 2010 16:43:15 -0500 Subject: Fixing merge --- src/app-indicator.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/app-indicator.c') diff --git a/src/app-indicator.c b/src/app-indicator.c index 3bfdf2f..22b9c03 100644 --- a/src/app-indicator.c +++ b/src/app-indicator.c @@ -1339,6 +1339,7 @@ app_indicator_set_label (AppIndicator *self, const gchar * label, const gchar * Sets the path to use when searching for icons. **/ +void app_indicator_set_icon_theme_path (AppIndicator *self, const gchar *icon_theme_path) { g_return_if_fail (IS_APP_INDICATOR (self)); -- cgit v1.2.3