diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 39 | ||||
-rw-r--r-- | src/ido-detail-label.c | 400 | ||||
-rw-r--r-- | src/ido-detail-label.h | 59 | ||||
-rw-r--r-- | src/ido-menu-item.c | 425 | ||||
-rw-r--r-- | src/ido-menu-item.h | 54 | ||||
-rw-r--r-- | src/im-app-menu-item.c | 351 | ||||
-rw-r--r-- | src/im-app-menu-item.h | 54 | ||||
-rw-r--r-- | src/im-source-menu-item.c | 407 | ||||
-rw-r--r-- | src/im-source-menu-item.h | 54 | ||||
-rw-r--r-- | src/indicator-messages.c | 382 |
10 files changed, 0 insertions, 2225 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 5d8bad8..c011d5d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,45 +3,6 @@ EXTRA_DIST = libexec_PROGRAMS = indicator-messages-service - -###################################### -# Building the messages indicator -###################################### - -messaginglibdir = $(INDICATORDIR) -messaginglib_LTLIBRARIES = libmessaging.la -libmessaging_la_SOURCES = \ - indicator-messages.c \ - ido-menu-item.c \ - ido-menu-item.h \ - im-app-menu-item.c \ - im-app-menu-item.h \ - im-source-menu-item.c \ - im-source-menu-item.h \ - ido-detail-label.c \ - ido-detail-label.h \ - dbus-data.h -libmessaging_la_CFLAGS = \ - $(APPLET_CFLAGS) \ - $(COVERAGE_CFLAGS) \ - -I$(top_builddir)/common \ - -Wall \ - -Wl,-Bsymbolic-functions \ - -Wl,-z,defs \ - -Wl,--as-needed \ - -Werror \ - -DG_LOG_DOMAIN=\"Indicator-Messages\" -libmessaging_la_LIBADD = \ - $(top_builddir)/common/libmessaging-common.la \ - $(APPLET_LIBS) -lm -libmessaging_la_LDFLAGS = \ - $(COVERAGE_LDFLAGS) \ - -module -avoid-version - -###################################### -# Building the messages service -###################################### - indicator_messages_service_SOURCES = \ messages-service.c \ app-section.c \ diff --git a/src/ido-detail-label.c b/src/ido-detail-label.c deleted file mode 100644 index c97c06d..0000000 --- a/src/ido-detail-label.c +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#include "ido-detail-label.h" - -#include <math.h> - -G_DEFINE_TYPE (IdoDetailLabel, ido_detail_label, GTK_TYPE_WIDGET) - -struct _IdoDetailLabelPrivate -{ - gchar *text; - PangoLayout *layout; - gboolean draw_lozenge; -}; - -enum -{ - PROP_0, - PROP_TEXT, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -static void -ido_detail_label_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - IdoDetailLabel *self = IDO_DETAIL_LABEL (object); - - switch (property_id) - { - case PROP_TEXT: - g_value_set_string (value, self->priv->text); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ido_detail_label_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - IdoDetailLabel *self = IDO_DETAIL_LABEL (object); - - switch (property_id) - { - case PROP_TEXT: - ido_detail_label_set_text (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - - -static void -ido_detail_label_finalize (GObject *object) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; - - g_free (priv->text); - - G_OBJECT_CLASS (ido_detail_label_parent_class)->finalize (object); -} - -static void -ido_detail_label_dispose (GObject *object) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (object)->priv; - - g_clear_object (&priv->layout); - - G_OBJECT_CLASS (ido_detail_label_parent_class)->dispose (object); -} - -static void -ido_detail_label_ensure_layout (IdoDetailLabel *label) -{ - IdoDetailLabelPrivate *priv = label->priv; - - if (priv->layout == NULL) - { - priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (label), priv->text); - pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER); - pango_layout_set_ellipsize (priv->layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height (priv->layout, -1); - - // TODO update layout on "style-updated" and "direction-changed" - } -} - -static void -cairo_lozenge (cairo_t *cr, - double x, - double y, - double w, - double h, - double radius) -{ - double x1 = x + w - radius; - double x2 = x + radius; - double y1 = y + radius; - double y2 = y + h - radius; - - cairo_move_to (cr, x + radius, y); - cairo_arc (cr, x1, y1, radius, G_PI * 1.5, G_PI * 2); - cairo_arc (cr, x1, y2, radius, 0, G_PI * 0.5); - cairo_arc (cr, x2, y2, radius, G_PI * 0.5, G_PI); - cairo_arc (cr, x2, y1, radius, G_PI, G_PI * 1.5); -} - -static PangoFontMetrics * -gtk_widget_get_font_metrics (GtkWidget *widget, - PangoContext *context) -{ - PangoFontMetrics *font_metrics; - PangoFontDescription *font; - GtkStyleContext *style; - style = gtk_widget_get_style_context (GTK_WIDGET (widget)); - gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, - "font", &font, NULL); - - font_metrics = pango_context_get_metrics (context, - font, - pango_context_get_language (context)); - pango_font_description_free (font); - return font_metrics; -} - -static gint -ido_detail_label_get_minimum_text_width (IdoDetailLabel *label) -{ - IdoDetailLabelPrivate *priv = label->priv; - PangoContext *context; - PangoFontMetrics *metrics; - gint char_width; - gint w; - - context = pango_layout_get_context (priv->layout); - metrics = gtk_widget_get_font_metrics (GTK_WIDGET (label), context); - char_width = pango_font_metrics_get_approximate_digit_width (metrics); - - w = 2 * char_width / PANGO_SCALE; - pango_font_metrics_unref (metrics); - return w; -} - -static gboolean -ido_detail_label_draw (GtkWidget *widget, - cairo_t *cr) -{ - IdoDetailLabel *label = IDO_DETAIL_LABEL (widget); - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoRectangle extents; - GtkAllocation allocation; - double x, w, h, radius; - GdkRGBA color; - - if (!priv->text || !*priv->text) - return TRUE; - - gtk_widget_get_allocation (widget, &allocation); - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - h = MIN (allocation.height, extents.height); - radius = floor (h / 2.0); - w = MAX (ido_detail_label_get_minimum_text_width (label), extents.width) + 2.0 * radius; - x = allocation.width - w; - - pango_layout_set_width (priv->layout, (allocation.width - 2 * radius) * PANGO_SCALE); - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - gtk_style_context_get_color (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - cairo_set_line_width (cr, 1.0); - cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); - - if (priv->draw_lozenge) - cairo_lozenge (cr, x, 0.0, w, h, radius); - - cairo_move_to (cr, x + radius, (allocation.height - extents.height) / 2.0); - pango_cairo_layout_path (cr, priv->layout); - cairo_fill (cr); - - return TRUE; -} - -static void -ido_detail_label_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoRectangle extents; - double radius; - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - - radius = floor (extents.height / 2.0); - - *minimum = ido_detail_label_get_minimum_text_width (IDO_DETAIL_LABEL (widget)) + 2.0 * radius; - *natural = MAX (*minimum, extents.width + 2.0 * radius); -} - -static void -ido_detail_label_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - IdoDetailLabelPrivate *priv = IDO_DETAIL_LABEL (widget)->priv; - PangoContext *context; - PangoFontMetrics *metrics; - PangoRectangle extents; - - ido_detail_label_ensure_layout (IDO_DETAIL_LABEL (widget)); - - pango_layout_get_extents (priv->layout, NULL, &extents); - pango_extents_to_pixels (&extents, NULL); - context = pango_layout_get_context (priv->layout); - metrics = gtk_widget_get_font_metrics (widget, context); - - *minimum = *natural = (pango_font_metrics_get_ascent (metrics) + - pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; - - pango_font_metrics_unref (metrics); -} - -static void -ido_detail_label_class_init (IdoDetailLabelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->get_property = ido_detail_label_get_property; - object_class->set_property = ido_detail_label_set_property; - object_class->finalize = ido_detail_label_finalize; - object_class->dispose = ido_detail_label_dispose; - - widget_class->draw = ido_detail_label_draw; - widget_class->get_preferred_width = ido_detail_label_get_preferred_width; - widget_class->get_preferred_height = ido_detail_label_get_preferred_height; - - g_type_class_add_private (klass, sizeof (IdoDetailLabelPrivate)); - - properties[PROP_TEXT] = g_param_spec_string ("text", - "Text", - "The text of the label", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -ido_detail_label_init (IdoDetailLabel *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_TYPE_DETAIL_LABEL, - IdoDetailLabelPrivate); - - gtk_widget_set_has_window (GTK_WIDGET (self), FALSE); -} - -GtkWidget * -ido_detail_label_new (const gchar *label) -{ - return g_object_new (IDO_TYPE_DETAIL_LABEL, - "text", label, - NULL); -} - -const gchar * -ido_detail_label_get_text (IdoDetailLabel *label) -{ - g_return_val_if_fail (IDO_IS_DETAIL_LABEL (label), NULL); - return label->priv->text; -} - -/* collapse_whitespace: - * @str: the source string - * - * Collapses all occurences of consecutive whitespace charactes in @str - * into a single space. - * - * Returns: (transfer full): a newly-allocated string - */ -static gchar * -collapse_whitespace (const gchar *str) -{ - GString *result; - gboolean in_space = FALSE; - - if (str == NULL) - return NULL; - - result = g_string_new (""); - - while (*str) - { - gunichar c = g_utf8_get_char_validated (str, -1); - - if (c < 0) - break; - - if (!g_unichar_isspace (c)) - { - g_string_append_unichar (result, c); - in_space = FALSE; - } - else if (!in_space) - { - g_string_append_c (result, ' '); - in_space = TRUE; - } - - str = g_utf8_next_char (str); - } - - return g_string_free (result, FALSE); -} - -static void -ido_detail_label_set_text_impl (IdoDetailLabel *label, - const gchar *text, - gboolean draw_lozenge) -{ - IdoDetailLabelPrivate * priv = label->priv; - - g_clear_object (&priv->layout); - g_free (priv->text); - - priv->text = g_strdup (text); - priv->draw_lozenge = draw_lozenge; - - g_object_notify_by_pspec (G_OBJECT (label), properties[PROP_TEXT]); - gtk_widget_queue_resize (GTK_WIDGET (label)); -} - -void -ido_detail_label_set_text (IdoDetailLabel *label, - const gchar *text) -{ - gchar *str; - - g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); - - str = collapse_whitespace (text); - ido_detail_label_set_text_impl (label, str, FALSE); - g_free (str); -} - -void -ido_detail_label_set_count (IdoDetailLabel *label, - gint count) -{ - gchar *text; - - g_return_if_fail (IDO_IS_DETAIL_LABEL (label)); - - text = g_strdup_printf ("%d", count); - ido_detail_label_set_text_impl (label, text, TRUE); - g_free (text); -} diff --git a/src/ido-detail-label.h b/src/ido-detail-label.h deleted file mode 100644 index 1995fee..0000000 --- a/src/ido-detail-label.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#ifndef __IDO_DETAIL_LABEL_H__ -#define __IDO_DETAIL_LABEL_H__ - -#include <gtk/gtk.h> - -#define IDO_TYPE_DETAIL_LABEL (ido_detail_label_get_type()) -#define IDO_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabel)) -#define IDO_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) -#define IDO_IS_DETAIL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_DETAIL_LABEL)) -#define IDO_IS_DETAIL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_DETAIL_LABEL)) -#define IDO_DETAIL_LABEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_DETAIL_LABEL, IdoDetailLabelClass)) - -typedef struct _IdoDetailLabel IdoDetailLabel; -typedef struct _IdoDetailLabelClass IdoDetailLabelClass; -typedef struct _IdoDetailLabelPrivate IdoDetailLabelPrivate; - -struct _IdoDetailLabel -{ - GtkWidget parent; - IdoDetailLabelPrivate *priv; -}; - -struct _IdoDetailLabelClass -{ - GtkWidgetClass parent_class; -}; - -GType ido_detail_label_get_type (void) G_GNUC_CONST; - -GtkWidget * ido_detail_label_new (const gchar *str); - -const gchar * ido_detail_label_get_text (IdoDetailLabel *label); - -void ido_detail_label_set_text (IdoDetailLabel *label, - const gchar *text); - -void ido_detail_label_set_count (IdoDetailLabel *label, - gint count); - -#endif diff --git a/src/ido-menu-item.c b/src/ido-menu-item.c deleted file mode 100644 index 32044ff..0000000 --- a/src/ido-menu-item.c +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#include "ido-menu-item.h" - -struct _IdoMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - GVariant *target; - - GtkWidget *icon; - GtkWidget *label; - - gboolean has_indicator; - gboolean in_set_active; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (IdoMenuItem, ido_menu_item, GTK_TYPE_CHECK_MENU_ITEM); - -static void -ido_menu_item_constructed (GObject *object) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (object)->priv; - GtkWidget *grid; - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_right (priv->icon, 6); - - priv->label = g_object_ref (gtk_label_new ("")); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (ido_menu_item_parent_class)->constructed (object); -} - -static void -ido_menu_item_set_active (IdoMenuItem *self, - gboolean active) -{ - /* HACK gtk_check_menu_item_set_active calls gtk_menu_item_activate. - * Make sure our activate handler doesn't toggle the action as a - * result of calling this function. */ - - self->priv->in_set_active = TRUE; - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (self), active); - self->priv->in_set_active = FALSE; -} - -static void -ido_menu_item_set_has_indicator (IdoMenuItem *self, - gboolean has_indicator) -{ - if (has_indicator == self->priv->has_indicator) - return; - - self->priv->has_indicator = has_indicator; - - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -static void -ido_menu_item_set_state (IdoMenuItem *self, - GVariant *state) -{ - IdoMenuItemPrivate *priv = self->priv; - - if (priv->target) - { - ido_menu_item_set_has_indicator (self, TRUE); - ido_menu_item_set_active (self, FALSE); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (self), TRUE); - gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (self), FALSE); - - if (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING)) - { - ido_menu_item_set_active (self, g_variant_equal (priv->target, state)); - } - else if (g_variant_is_of_type (state, G_VARIANT_TYPE ("as")) && - g_variant_is_of_type (priv->target, G_VARIANT_TYPE_STRING)) - { - const gchar *target_str; - const gchar **state_strs; - const gchar **it; - - target_str = g_variant_get_string (priv->target, NULL); - state_strs = g_variant_get_strv (state, NULL); - - it = state_strs; - while (*it != NULL && !g_str_equal (*it, target_str)) - it++; - - if (*it != NULL) - { - ido_menu_item_set_active (self, TRUE); - gtk_check_menu_item_set_inconsistent (GTK_CHECK_MENU_ITEM (self), - g_strv_length ((gchar **)state_strs) > 1); - } - - g_free (state_strs); - } - } - else if (g_variant_is_of_type (state, G_VARIANT_TYPE_BOOLEAN)) - { - ido_menu_item_set_has_indicator (self, TRUE); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (self), FALSE); - ido_menu_item_set_active (self, g_variant_get_boolean (state)); - } - else - { - ido_menu_item_set_has_indicator (self, FALSE); - } -} - -static void -ido_menu_item_set_action_name (IdoMenuItem *self, - const gchar *action_name) -{ - IdoMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - const GVariantType *param_type; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, ¶m_type, NULL, NULL, &state)) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); - - if (state) - { - ido_menu_item_set_state (self, state); - g_variant_unref (state); - } - } - else - { - ido_menu_item_set_active (self, FALSE); - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - ido_menu_item_set_has_indicator (self, FALSE); - } -} - -static void -ido_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - ido_menu_item_set_action_name (self, action_name); -} - -static void -ido_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - } -} - -static void -ido_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -ido_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - IdoMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - ido_menu_item_set_state (self, value); -} - -static void -ido_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - IdoMenuItem *self = IDO_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - ido_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - ido_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -ido_menu_item_dispose (GObject *object) -{ - IdoMenuItem *self = IDO_MENU_ITEM (object); - - if (self->priv->action_group) - ido_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - - if (self->priv->target) - { - g_variant_unref (self->priv->target); - self->priv->target = NULL; - } - - G_OBJECT_CLASS (ido_menu_item_parent_class)->dispose (object); -} - -static void -ido_menu_item_finalize (GObject *object) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (ido_menu_item_parent_class)->finalize (object); -} - -static void -ido_menu_item_activate (GtkMenuItem *item) -{ - IdoMenuItemPrivate *priv = IDO_MENU_ITEM (item)->priv; - - /* see ido_menu_item_set_active */ - if (!priv->in_set_active && priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, priv->target); - - if (priv->in_set_active) - GTK_MENU_ITEM_CLASS (ido_menu_item_parent_class)->activate (item); -} - -static void -ido_menu_item_draw_indicator (GtkCheckMenuItem *item, - cairo_t *cr) -{ - IdoMenuItem *self = IDO_MENU_ITEM (item); - - if (self->priv->has_indicator) - GTK_CHECK_MENU_ITEM_CLASS (ido_menu_item_parent_class) - ->draw_indicator (item, cr); -} - -static void -ido_menu_item_class_init (IdoMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - GtkCheckMenuItemClass *check_class = GTK_CHECK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (IdoMenuItemPrivate)); - - object_class->constructed = ido_menu_item_constructed; - object_class->set_property = ido_menu_set_property; - object_class->dispose = ido_menu_item_dispose; - object_class->finalize = ido_menu_item_finalize; - - menu_item_class->activate = ido_menu_item_activate; - - check_class->draw_indicator = ido_menu_item_draw_indicator; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -ido_menu_item_init (IdoMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IDO_TYPE_MENU_ITEM, - IdoMenuItemPrivate); -} - -void -ido_menu_item_set_menu_item (IdoMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label = NULL; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - - /* only indent the label if icon is set to "" */ - if (iconstr[0] == '\0') - { - gint width; - - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, NULL); - gtk_widget_set_size_request (self->priv->icon, width, -1); - } - else - { - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - self->priv->target = g_menu_item_get_attribute_value (menuitem, "target", NULL); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - ido_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -ido_menu_item_set_action_group (IdoMenuItem *self, - GActionGroup *action_group) -{ - IdoMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, ido_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (ido_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (ido_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (ido_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (ido_menu_item_action_state_changed), self); - } -} diff --git a/src/ido-menu-item.h b/src/ido-menu-item.h deleted file mode 100644 index 0521928..0000000 --- a/src/ido-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#ifndef __IDO_MENU_ITEM_H__ -#define __IDO_MENU_ITEM_H__ - -#include <gtk/gtk.h> - -#define IDO_TYPE_MENU_ITEM (ido_menu_item_get_type ()) -#define IDO_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_MENU_ITEM, IdoMenuItem)) -#define IDO_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_MENU_ITEM, IdoMenuItemClass)) -#define IS_IDO_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_MENU_ITEM)) -#define IS_IDO_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_MENU_ITEM)) -#define IDO_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_MENU_ITEM, IdoMenuItemClass)) - -typedef struct _IdoMenuItem IdoMenuItem; -typedef struct _IdoMenuItemClass IdoMenuItemClass; -typedef struct _IdoMenuItemPrivate IdoMenuItemPrivate; - -struct _IdoMenuItemClass -{ - GtkCheckMenuItemClass parent_class; -}; - -struct _IdoMenuItem -{ - GtkCheckMenuItem parent; - IdoMenuItemPrivate *priv; -}; - -GType ido_menu_item_get_type (void); - -void ido_menu_item_set_menu_item (IdoMenuItem *item, - GMenuItem *menuitem); -void ido_menu_item_set_action_group (IdoMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/im-app-menu-item.c b/src/im-app-menu-item.c deleted file mode 100644 index a204631..0000000 --- a/src/im-app-menu-item.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#include "im-app-menu-item.h" - -struct _ImAppMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - gboolean is_running; - - GtkWidget *icon; - GtkWidget *label; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (ImAppMenuItem, im_app_menu_item, GTK_TYPE_MENU_ITEM); - -static void -im_app_menu_item_constructed (GObject *object) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (object)->priv; - GtkWidget *grid; - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_right (priv->icon, 6); - - priv->label = g_object_ref (gtk_label_new ("")); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->constructed (object); -} - -static void -im_app_menu_item_set_action_name (ImAppMenuItem *self, - const gchar *action_name) -{ - ImAppMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - priv->is_running = FALSE; - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, NULL, NULL, NULL, &state)) - { - if (state && g_variant_is_of_type (state, G_VARIANT_TYPE ("b"))) - priv->is_running = g_variant_get_boolean (state); - else - enabled = FALSE; - - if (state) - g_variant_unref (state); - } - - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -im_app_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_app_menu_item_set_action_name (self, action_name); -} - -static void -im_app_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - self->priv->is_running = FALSE; - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -im_app_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_app_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - ImAppMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - g_return_if_fail (g_variant_is_of_type (value, G_VARIANT_TYPE ("b"))); - - self->priv->is_running = g_variant_get_boolean (value); - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -im_app_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ImAppMenuItem *self = IM_APP_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - im_app_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - im_app_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -im_app_menu_item_dispose (GObject *object) -{ - ImAppMenuItem *self = IM_APP_MENU_ITEM (object); - - if (self->priv->action_group) - im_app_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->dispose (object); -} - -static void -im_app_menu_item_finalize (GObject *object) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (im_app_menu_item_parent_class)->finalize (object); -} - -static gboolean -im_app_menu_item_draw (GtkWidget *widget, - cairo_t *cr) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (widget)->priv; - - GTK_WIDGET_CLASS (im_app_menu_item_parent_class)->draw (widget, cr); - - if (priv->is_running) - { - const int arrow_width = 5; - const double half_arrow_height = 4.5; - GtkAllocation alloc; - GdkRGBA color; - double center; - - gtk_widget_get_allocation (widget, &alloc); - - gtk_style_context_get_color (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - center = alloc.height / 2 + 0.5; - - cairo_move_to (cr, 0, center - half_arrow_height); - cairo_line_to (cr, 0, center + half_arrow_height); - cairo_line_to (cr, arrow_width, center); - cairo_close_path (cr); - - cairo_fill (cr); - } - - return FALSE; -} - -static void -im_app_menu_item_activate (GtkMenuItem *item) -{ - ImAppMenuItemPrivate *priv = IM_APP_MENU_ITEM (item)->priv; - - if (priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, NULL); -} - -static void -im_app_menu_item_class_init (ImAppMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ImAppMenuItemPrivate)); - - object_class->constructed = im_app_menu_item_constructed; - object_class->set_property = im_app_menu_set_property; - object_class->dispose = im_app_menu_item_dispose; - object_class->finalize = im_app_menu_item_finalize; - - widget_class->draw = im_app_menu_item_draw; - - menu_item_class->activate = im_app_menu_item_activate; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -im_app_menu_item_init (ImAppMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IM_TYPE_APP_MENU_ITEM, - ImAppMenuItemPrivate); -} - -void -im_app_menu_item_set_menu_item (ImAppMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - im_app_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -im_app_menu_item_set_action_group (ImAppMenuItem *self, - GActionGroup *action_group) -{ - ImAppMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_app_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (im_app_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (im_app_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (im_app_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (im_app_menu_item_action_state_changed), self); - } -} diff --git a/src/im-app-menu-item.h b/src/im-app-menu-item.h deleted file mode 100644 index 519de8d..0000000 --- a/src/im-app-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#ifndef __IM_APP_MENU_ITEM_H__ -#define __IM_APP_MENU_ITEM_H__ - -#include <gtk/gtk.h> - -#define IM_TYPE_APP_MENU_ITEM (im_app_menu_item_get_type ()) -#define IM_APP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_APP_MENU_ITEM, ImAppMenuItem)) -#define IM_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_APP_MENU_ITEM, ImAppMenuItemClass)) -#define IS_IM_APP_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_APP_MENU_ITEM)) -#define IS_IM_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_APP_MENU_ITEM)) -#define IM_APP_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_APP_MENU_ITEM, ImAppMenuItemClass)) - -typedef struct _ImAppMenuItem ImAppMenuItem; -typedef struct _ImAppMenuItemClass ImAppMenuItemClass; -typedef struct _ImAppMenuItemPrivate ImAppMenuItemPrivate; - -struct _ImAppMenuItemClass -{ - GtkMenuItemClass parent_class; -}; - -struct _ImAppMenuItem -{ - GtkMenuItem parent; - ImAppMenuItemPrivate *priv; -}; - -GType im_app_menu_item_get_type (void); - -void im_app_menu_item_set_menu_item (ImAppMenuItem *item, - GMenuItem *menuitem); -void im_app_menu_item_set_action_group (ImAppMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/im-source-menu-item.c b/src/im-source-menu-item.c deleted file mode 100644 index 775fa91..0000000 --- a/src/im-source-menu-item.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#include "im-source-menu-item.h" - -#include <libintl.h> -#include "ido-detail-label.h" - -struct _ImSourceMenuItemPrivate -{ - GActionGroup *action_group; - gchar *action; - - GtkWidget *icon; - GtkWidget *label; - GtkWidget *detail; - - gint64 time; - guint timer_id; -}; - -enum -{ - PROP_0, - PROP_MENU_ITEM, - PROP_ACTION_GROUP, - NUM_PROPERTIES -}; - -static GParamSpec *properties[NUM_PROPERTIES]; - -G_DEFINE_TYPE (ImSourceMenuItem, im_source_menu_item, GTK_TYPE_MENU_ITEM); - -static void -im_source_menu_item_constructed (GObject *object) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (object)->priv; - GtkWidget *grid; - gint icon_width; - - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &icon_width, NULL); - - priv->icon = g_object_ref (gtk_image_new ()); - gtk_widget_set_margin_left (priv->icon, icon_width + 6); - - priv->label = g_object_ref (gtk_label_new ("")); - gtk_label_set_max_width_chars (GTK_LABEL (priv->label), 40); - gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5); - - priv->detail = g_object_ref (ido_detail_label_new ("")); - gtk_widget_set_halign (priv->detail, GTK_ALIGN_END); - gtk_widget_set_hexpand (priv->detail, TRUE); - gtk_style_context_add_class (gtk_widget_get_style_context (priv->detail), "accelerator"); - - grid = gtk_grid_new (); - gtk_grid_attach (GTK_GRID (grid), priv->icon, 0, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->label, 1, 0, 1, 1); - gtk_grid_attach (GTK_GRID (grid), priv->detail, 2, 0, 1, 1); - - gtk_container_add (GTK_CONTAINER (object), grid); - gtk_widget_show_all (grid); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->constructed (object); -} - -static gchar * -im_source_menu_item_time_span_string (gint64 timestamp) -{ - gchar *str; - gint64 span; - gint hours; - gint minutes; - - span = MAX (g_get_real_time () - timestamp, 0) / G_USEC_PER_SEC; - hours = span / 3600; - minutes = (span / 60) % 60; - - if (hours == 0) - { - /* TRANSLATORS: number of minutes that have passed */ - str = g_strdup_printf (ngettext ("%d m", "%d m", minutes), minutes); - } - else - { - /* TRANSLATORS: number of hours that have passed */ - str = g_strdup_printf (ngettext ("%d h", "%d h", hours), hours); - } - - return str; -} - -static void -im_source_menu_item_set_detail_time (ImSourceMenuItem *self, - gint64 time) -{ - ImSourceMenuItemPrivate *priv = self->priv; - gchar *str; - - priv->time = time; - - str = im_source_menu_item_time_span_string (priv->time); - ido_detail_label_set_text (IDO_DETAIL_LABEL (priv->detail), str); - - g_free (str); -} - -static gboolean -im_source_menu_item_update_time (gpointer data) -{ - ImSourceMenuItem *self = data; - - im_source_menu_item_set_detail_time (self, self->priv->time); - - return TRUE; -} - -static gboolean -im_source_menu_item_set_state (ImSourceMenuItem *self, - GVariant *state) -{ - ImSourceMenuItemPrivate *priv = self->priv; - guint32 count; - gint64 time; - const gchar *str; - - if (priv->timer_id != 0) - { - g_source_remove (priv->timer_id); - priv->timer_id = 0; - } - - g_return_val_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE ("(uxsb)")), FALSE); - - g_variant_get (state, "(ux&sb)", &count, &time, &str, NULL); - - if (count != 0) - ido_detail_label_set_count (IDO_DETAIL_LABEL (priv->detail), count); - else if (time != 0) - { - im_source_menu_item_set_detail_time (self, time); - priv->timer_id = g_timeout_add_seconds (59, im_source_menu_item_update_time, self); - } - else if (str != NULL && *str) - ido_detail_label_set_text (IDO_DETAIL_LABEL (priv->detail), str); - - return TRUE; -} - -static void -im_source_menu_item_set_action_name (ImSourceMenuItem *self, - const gchar *action_name) -{ - ImSourceMenuItemPrivate *priv = self->priv; - gboolean enabled = FALSE; - GVariant *state; - - if (priv->action != NULL) - g_free (priv->action); - - priv->action = g_strdup (action_name); - - if (priv->action_group != NULL && priv->action != NULL && - g_action_group_query_action (priv->action_group, priv->action, - &enabled, NULL, NULL, NULL, &state)) - { - if (!state || !im_source_menu_item_set_state (self, state)) - enabled = FALSE; - - if (state) - g_variant_unref (state); - } - - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_source_menu_item_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_source_menu_item_set_action_name (self, action_name); -} - -static void -im_source_menu_item_action_removed (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - { - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - } -} - -static void -im_source_menu_item_action_enabled_changed (GActionGroup *action_group, - gchar *action_name, - gboolean enabled, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - gtk_widget_set_sensitive (GTK_WIDGET (self), enabled); -} - -static void -im_source_menu_item_action_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - ImSourceMenuItem *self = user_data; - - if (g_strcmp0 (self->priv->action, action_name) == 0) - im_source_menu_item_set_state (self, value); -} - -static void -im_source_menu_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ImSourceMenuItem *self = IM_SOURCE_MENU_ITEM (object); - - switch (property_id) - { - case PROP_MENU_ITEM: - im_source_menu_item_set_menu_item (self, G_MENU_ITEM (g_value_get_object (value))); - break; - - case PROP_ACTION_GROUP: - im_source_menu_item_set_action_group (self, G_ACTION_GROUP (g_value_get_object (value))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -im_source_menu_item_dispose (GObject *object) -{ - ImSourceMenuItem *self = IM_SOURCE_MENU_ITEM (object); - - if (self->priv->timer_id != 0) - { - g_source_remove (self->priv->timer_id); - self->priv->timer_id = 0; - } - - if (self->priv->action_group) - im_source_menu_item_set_action_group (self, NULL); - - g_clear_object (&self->priv->icon); - g_clear_object (&self->priv->label); - g_clear_object (&self->priv->detail); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->dispose (object); -} - -static void -im_source_menu_item_finalize (GObject *object) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (object)->priv; - - g_free (priv->action); - - G_OBJECT_CLASS (im_source_menu_item_parent_class)->finalize (object); -} - -static void -im_source_menu_item_activate (GtkMenuItem *item) -{ - ImSourceMenuItemPrivate *priv = IM_SOURCE_MENU_ITEM (item)->priv; - - if (priv->action && priv->action_group) - g_action_group_activate_action (priv->action_group, priv->action, NULL); -} - -static void -im_source_menu_item_class_init (ImSourceMenuItemClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS (klass); - - g_type_class_add_private (klass, sizeof (ImSourceMenuItemPrivate)); - - object_class->constructed = im_source_menu_item_constructed; - object_class->set_property = im_source_menu_set_property; - object_class->dispose = im_source_menu_item_dispose; - object_class->finalize = im_source_menu_item_finalize; - - menu_item_class->activate = im_source_menu_item_activate; - - properties[PROP_MENU_ITEM] = g_param_spec_object ("menu-item", - "Menu item", - "The model GMenuItem for this menu item", - G_TYPE_MENU_ITEM, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - properties[PROP_ACTION_GROUP] = g_param_spec_object ("action-group", - "Action group", - "The action group associated with this menu item", - G_TYPE_ACTION_GROUP, - G_PARAM_WRITABLE | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); -} - -static void -im_source_menu_item_init (ImSourceMenuItem *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - IM_TYPE_SOURCE_MENU_ITEM, - ImSourceMenuItemPrivate); -} - -void -im_source_menu_item_set_menu_item (ImSourceMenuItem *self, - GMenuItem *menuitem) -{ - gchar *iconstr = NULL; - GIcon *icon = NULL; - gchar *label; - gchar *action = NULL; - - if (g_menu_item_get_attribute (menuitem, "x-canonical-icon", "s", &iconstr)) - { - GError *error; - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) - { - g_warning ("unable to set icon: %s", error->message); - g_error_free (error); - } - g_free (iconstr); - } - gtk_image_set_from_gicon (GTK_IMAGE (self->priv->icon), icon, GTK_ICON_SIZE_MENU); - - g_menu_item_get_attribute (menuitem, "label", "s", &label); - gtk_label_set_label (GTK_LABEL (self->priv->label), label ? label : ""); - - g_menu_item_get_attribute (menuitem, "action", "s", &action); - im_source_menu_item_set_action_name (self, action); - - if (icon) - g_object_unref (icon); - g_free (label); - g_free (action); -} - -void -im_source_menu_item_set_action_group (ImSourceMenuItem *self, - GActionGroup *action_group) -{ - ImSourceMenuItemPrivate *priv = self->priv; - - if (priv->action_group != NULL) - { - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_added, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_removed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_enabled_changed, self); - g_signal_handlers_disconnect_by_func (priv->action_group, im_source_menu_item_action_state_changed, self); - - g_clear_object (&priv->action_group); - } - - if (action_group != NULL) - { - priv->action_group = g_object_ref (action_group); - - g_signal_connect (priv->action_group, "action-added", - G_CALLBACK (im_source_menu_item_action_added), self); - g_signal_connect (priv->action_group, "action-removed", - G_CALLBACK (im_source_menu_item_action_removed), self); - g_signal_connect (priv->action_group, "action-enabled-changed", - G_CALLBACK (im_source_menu_item_action_enabled_changed), self); - g_signal_connect (priv->action_group, "action-state-changed", - G_CALLBACK (im_source_menu_item_action_state_changed), self); - } -} diff --git a/src/im-source-menu-item.h b/src/im-source-menu-item.h deleted file mode 100644 index c359b94..0000000 --- a/src/im-source-menu-item.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Lars Uebernickel <lars.uebernickel@canonical.com> - */ - -#ifndef __IM_SOURCE_MENU_ITEM_H__ -#define __IM_SOURCE_MENU_ITEM_H__ - -#include <gtk/gtk.h> - -#define IM_TYPE_SOURCE_MENU_ITEM (im_source_menu_item_get_type ()) -#define IM_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItem)) -#define IM_SOURCE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItemClass)) -#define IS_IM_SOURCE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IM_TYPE_SOURCE_MENU_ITEM)) -#define IS_IM_SOURCE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_TYPE_SOURCE_MENU_ITEM)) -#define IM_SOURCE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_TYPE_SOURCE_MENU_ITEM, ImSourceMenuItemClass)) - -typedef struct _ImSourceMenuItem ImSourceMenuItem; -typedef struct _ImSourceMenuItemClass ImSourceMenuItemClass; -typedef struct _ImSourceMenuItemPrivate ImSourceMenuItemPrivate; - -struct _ImSourceMenuItemClass -{ - GtkMenuItemClass parent_class; -}; - -struct _ImSourceMenuItem -{ - GtkMenuItem parent; - ImSourceMenuItemPrivate *priv; -}; - -GType im_source_menu_item_get_type (void); - -void im_source_menu_item_set_menu_item (ImSourceMenuItem *item, - GMenuItem *menuitem); -void im_source_menu_item_set_action_group (ImSourceMenuItem *self, - GActionGroup *action_group); - -#endif diff --git a/src/indicator-messages.c b/src/indicator-messages.c deleted file mode 100644 index 5c5df31..0000000 --- a/src/indicator-messages.c +++ /dev/null @@ -1,382 +0,0 @@ -/* -An indicator to show information that is in messaging applications -that the user is using. - -Copyright 2012 Canonical Ltd. - -Authors: - Ted Gould <ted@canonical.com> - Lars Uebernickel <lars.uebernickel@canonical.com> - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#include "config.h" - -#include <string.h> -#include <math.h> -#include <glib.h> -#include <glib-object.h> -#include <glib/gi18n-lib.h> -#include <gtk/gtk.h> - -#include <libindicator/indicator.h> -#include <libindicator/indicator-object.h> -#include <libindicator/indicator-service-manager.h> - -#include "dbus-data.h" - -#include "ido-menu-item.h" -#include "im-app-menu-item.h" -#include "im-source-menu-item.h" - -#define INDICATOR_MESSAGES_TYPE (indicator_messages_get_type ()) -#define INDICATOR_MESSAGES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessages)) -#define INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass)) -#define IS_INDICATOR_MESSAGES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_MESSAGES_TYPE)) -#define IS_INDICATOR_MESSAGES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_MESSAGES_TYPE)) -#define INDICATOR_MESSAGES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_MESSAGES_TYPE, IndicatorMessagesClass)) - -typedef struct _IndicatorMessages IndicatorMessages; -typedef struct _IndicatorMessagesClass IndicatorMessagesClass; - -struct _IndicatorMessagesClass { - IndicatorObjectClass parent_class; -}; - -struct _IndicatorMessages { - IndicatorObject parent; - IndicatorServiceManager * service; - GActionGroup *actions; - GMenuModel *menu; - GtkWidget *image; - GtkWidget *gtkmenu; - gchar *accessible_desc; -}; - -GType indicator_messages_get_type (void); - -/* Indicator Module Config */ -INDICATOR_SET_VERSION -INDICATOR_SET_TYPE(INDICATOR_MESSAGES_TYPE) - -/* Prototypes */ -static void indicator_messages_class_init (IndicatorMessagesClass *klass); -static void indicator_messages_init (IndicatorMessages *self); -static void indicator_messages_dispose (GObject *object); -static void indicator_messages_finalize (GObject *object); -static void service_connection_changed (IndicatorServiceManager *sm, - gboolean connected, - gpointer user_data); -static GtkImage * get_image (IndicatorObject * io); -static GtkMenu * get_menu (IndicatorObject * io); -static const gchar * get_accessible_desc (IndicatorObject * io); -static const gchar * get_name_hint (IndicatorObject * io); -static void menu_items_changed (GMenuModel *menu, - gint position, - gint removed, - gint added, - gpointer user_data); -static void messages_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data); -static void messages_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data); -static void indicator_messages_add_toplevel_menu (IndicatorMessages *self); - -G_DEFINE_TYPE (IndicatorMessages, indicator_messages, INDICATOR_OBJECT_TYPE); - -/* Initialize the one-timers */ -static void -indicator_messages_class_init (IndicatorMessagesClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = indicator_messages_dispose; - object_class->finalize = indicator_messages_finalize; - - IndicatorObjectClass * io_class = INDICATOR_OBJECT_CLASS(klass); - - io_class->get_image = get_image; - io_class->get_menu = get_menu; - io_class->get_accessible_desc = get_accessible_desc; - io_class->get_name_hint = get_name_hint; -} - -/* Build up our per-instance variables */ -static void -indicator_messages_init (IndicatorMessages *self) -{ - self->service = indicator_service_manager_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1); - g_signal_connect (self->service, "connection-change", - G_CALLBACK (service_connection_changed), self); - - self->gtkmenu = gtk_menu_new (); - g_object_ref_sink (self->gtkmenu); - - self->image = g_object_ref_sink (gtk_image_new ()); - - /* make sure custom menu item types are registered (so that - * gtk_model_new_from_menu can pick them up */ - ido_menu_item_get_type (); - im_app_menu_item_get_type (); - im_source_menu_item_get_type (); -} - -/* Unref stuff */ -static void -indicator_messages_dispose (GObject *object) -{ - IndicatorMessages * self = INDICATOR_MESSAGES(object); - g_return_if_fail(self != NULL); - - g_clear_object (&self->service); - g_clear_object (&self->actions); - g_clear_object (&self->menu); - g_clear_object (&self->gtkmenu); - g_clear_object (&self->image); - - G_OBJECT_CLASS (indicator_messages_parent_class)->dispose (object); - return; -} - -/* Destory all memory users */ -static void -indicator_messages_finalize (GObject *object) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (object); - - g_free (self->accessible_desc); - - G_OBJECT_CLASS (indicator_messages_parent_class)->finalize (object); - return; -} - - - -/* Functions */ - -static void service_connection_changed (IndicatorServiceManager *sm, - gboolean connected, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - GDBusConnection *bus; - GError *error = NULL; - - if (self->actions != NULL) { - g_signal_handlers_disconnect_by_func (self->actions, messages_action_added, self); - g_signal_handlers_disconnect_by_func (self->actions, messages_state_changed, self); - g_clear_object (&self->actions); - } - if (self->menu != NULL) { - g_signal_handlers_disconnect_by_func (self->menu, menu_items_changed, self); - g_clear_object (&self->menu); - } - gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->gtkmenu), NULL, NULL, FALSE); - - if (connected == FALSE) - return; - - bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - if (!bus) { - g_warning ("error connecting to the session bus: %s", error->message); - g_error_free (error); - return; - } - - self->actions = G_ACTION_GROUP (g_dbus_action_group_get (bus, - INDICATOR_MESSAGES_DBUS_NAME, - INDICATOR_MESSAGES_DBUS_OBJECT)); - gtk_widget_insert_action_group (self->gtkmenu, - get_name_hint (INDICATOR_OBJECT (self)), - self->actions); - g_signal_connect (self->actions, "action-added::messages", - G_CALLBACK (messages_action_added), self); - g_signal_connect (self->actions, "action-state-changed::messages", - G_CALLBACK (messages_state_changed), self); - - self->menu = G_MENU_MODEL (g_dbus_menu_model_get (bus, - INDICATOR_MESSAGES_DBUS_NAME, - INDICATOR_MESSAGES_DBUS_OBJECT)); - g_signal_connect (self->menu, "items-changed", G_CALLBACK (menu_items_changed), self); - - if (g_menu_model_get_n_items (self->menu) == 1) - indicator_messages_add_toplevel_menu (self); - else - indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE); - - g_object_unref (bus); -} - -static GtkImage * -get_image (IndicatorObject * io) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (io); - - gtk_widget_show (self->image); - return GTK_IMAGE (self->image); -} - -static GtkMenu * -get_menu (IndicatorObject * io) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (io); - - return GTK_MENU (self->gtkmenu); -} - -static const gchar * -get_accessible_desc (IndicatorObject * io) -{ - IndicatorMessages *self = INDICATOR_MESSAGES (io); - return self->accessible_desc; -} - -static const gchar * -get_name_hint (IndicatorObject *io) -{ - return PACKAGE; -} - -static void -indicator_messages_accessible_desc_updated (IndicatorMessages *self) -{ - GList *entries; - - entries = indicator_object_get_entries (INDICATOR_OBJECT (self)); - g_return_if_fail (entries != NULL); - - g_signal_emit_by_name (self, INDICATOR_OBJECT_SIGNAL_ACCESSIBLE_DESC_UPDATE, entries->data); - - g_list_free (entries); -} - -static GIcon * -g_menu_model_get_item_attribute_icon (GMenuModel *menu, - gint index, - const gchar *attribute) -{ - gchar *iconstr; - GIcon *icon = NULL; - - if (g_menu_model_get_item_attribute (menu, index, attribute, "s", &iconstr)) { - GError *error; - - icon = g_icon_new_for_string (iconstr, &error); - if (icon == NULL) { - g_warning ("unable to load icon: %s", error->message); - g_error_free (error); - } - - g_free (iconstr); - } - - return icon; -} - -static void -indicator_messages_add_toplevel_menu (IndicatorMessages *self) -{ - GIcon *icon; - GMenuModel *popup; - - indicator_object_set_visible (INDICATOR_OBJECT (self), TRUE); - - icon = g_menu_model_get_item_attribute_icon (self->menu, 0, "x-canonical-icon"); - if (icon) { - gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon, GTK_ICON_SIZE_LARGE_TOOLBAR); - g_object_unref (icon); - } - - g_free (self->accessible_desc); - self->accessible_desc = NULL; - if (g_menu_model_get_item_attribute (self->menu, 0, "x-canonical-accessible-description", - "s", &self->accessible_desc)) { - indicator_messages_accessible_desc_updated (self); - } - - popup = g_menu_model_get_item_link (self->menu, 0, G_MENU_LINK_SUBMENU); - if (popup) { - gtk_menu_shell_bind_model (GTK_MENU_SHELL (self->gtkmenu), - popup, - get_name_hint (INDICATOR_OBJECT (self)), - TRUE); - - g_object_unref (popup); - } -} - -static void -menu_items_changed (GMenuModel *menu, - gint position, - gint removed, - gint added, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - - g_return_if_fail (position == 0); - - if (added == 1) - indicator_messages_add_toplevel_menu (self); - else if (removed == 1) - indicator_object_set_visible (INDICATOR_OBJECT (self), FALSE); -} - -static void -indicator_messages_update_icon (IndicatorMessages *self, - GVariant *state) -{ - GIcon *icon; - GError *error = NULL; - - g_return_if_fail (g_variant_is_of_type (state, G_VARIANT_TYPE_STRING)); - - icon = g_icon_new_for_string (g_variant_get_string (state, NULL), &error); - if (icon == NULL) { - g_warning ("unable to load icon: %s", error->message); - g_error_free (error); - } - else { - gtk_image_set_from_gicon (GTK_IMAGE (self->image), icon, GTK_ICON_SIZE_LARGE_TOOLBAR); - g_object_unref (icon); - } -} - -static void -messages_action_added (GActionGroup *action_group, - gchar *action_name, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - GVariant *state; - - state = g_action_group_get_action_state (action_group, "messages"); - indicator_messages_update_icon (self, state); - - g_variant_unref (state); -} - -static void -messages_state_changed (GActionGroup *action_group, - gchar *action_name, - GVariant *value, - gpointer user_data) -{ - IndicatorMessages *self = user_data; - - indicator_messages_update_icon (self, value); -} |