diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-03 14:39:34 +0100 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-03 14:39:34 +0100 |
commit | 001cd99d51b18ce30d2808e6209544336aadb4bc (patch) | |
tree | 42b529543d06166b484e57c79100fb190992f285 /src | |
parent | 77e7554604917b07811added685043ede4fb2396 (diff) | |
download | ayatana-indicator-printers-001cd99d51b18ce30d2808e6209544336aadb4bc.tar.gz ayatana-indicator-printers-001cd99d51b18ce30d2808e6209544336aadb4bc.tar.bz2 ayatana-indicator-printers-001cd99d51b18ce30d2808e6209544336aadb4bc.zip |
Use priv member instead of calling g_type_instance_get_private repeatedly
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-menu-item.c | 60 | ||||
-rw-r--r-- | src/indicator-menu-item.h | 1 | ||||
-rw-r--r-- | src/indicator-printers-menu.c | 57 | ||||
-rw-r--r-- | src/indicator-printers-menu.h | 1 | ||||
-rw-r--r-- | src/indicator-printers.c | 22 | ||||
-rw-r--r-- | src/indicator-printers.h | 1 |
6 files changed, 67 insertions, 75 deletions
diff --git a/src/indicator-menu-item.c b/src/indicator-menu-item.c index a751b4c..4c7dc90 100644 --- a/src/indicator-menu-item.c +++ b/src/indicator-menu-item.c @@ -6,8 +6,6 @@ G_DEFINE_TYPE (IndicatorMenuItem, indicator_menu_item, GTK_TYPE_MENU_ITEM) -#define MENU_ITEM_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_TYPE_MENU_ITEM, IndicatorMenuItemPrivate)) struct _IndicatorMenuItemPrivate { @@ -103,7 +101,6 @@ indicator_menu_item_get_property (GObject *object, GParamSpec *pspec) { IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object); - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (object); switch (property_id) { @@ -116,15 +113,15 @@ indicator_menu_item_get_property (GObject *object, break; case PROP_LABEL: - g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label))); + g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->label))); break; case PROP_RIGHT: - g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->right_label))); + g_value_set_string (value, gtk_label_get_label (GTK_LABEL (self->priv->right_label))); break; case PROP_RIGHT_IS_LOZENGE: - g_value_set_boolean (value, priv->right_is_lozenge); + g_value_set_boolean (value, self->priv->right_is_lozenge); break; default: @@ -176,11 +173,11 @@ indicator_menu_item_set_property (GObject *object, static void indicator_menu_item_dispose (GObject *object) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (object); + IndicatorMenuItem *self = INDICATOR_MENU_ITEM (object); - g_clear_object (&priv->image); - g_clear_object (&priv->label); - g_clear_object (&priv->right_label); + g_clear_object (&self->priv->image); + g_clear_object (&self->priv->label); + g_clear_object (&self->priv->right_label); G_OBJECT_CLASS (indicator_menu_item_parent_class)->dispose (object); } @@ -234,10 +231,15 @@ indicator_menu_item_class_init (IndicatorMenuItemClass *klass) static void indicator_menu_item_init (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); + IndicatorMenuItemPrivate *priv; gint spacing; GtkWidget *hbox; + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_TYPE_MENU_ITEM, + IndicatorMenuItemPrivate); + self->priv = priv; + gtk_widget_style_get (GTK_WIDGET (self), "toggle-spacing", &spacing, NULL); @@ -286,8 +288,7 @@ indicator_menu_item_new (void) const gchar * indicator_menu_item_get_label (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - return gtk_label_get_label (GTK_LABEL (priv->label)); + return gtk_label_get_label (GTK_LABEL (self->priv->label)); } @@ -295,8 +296,7 @@ void indicator_menu_item_set_label (IndicatorMenuItem *self, const gchar *text) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - gtk_label_set_label (GTK_LABEL (priv->label), text); + gtk_label_set_label (GTK_LABEL (self->priv->label), text); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]); } @@ -304,8 +304,7 @@ indicator_menu_item_set_label (IndicatorMenuItem *self, const gchar * indicator_menu_item_get_right (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - return gtk_label_get_label (GTK_LABEL (priv->right_label)); + return gtk_label_get_label (GTK_LABEL (self->priv->right_label)); } @@ -313,8 +312,7 @@ void indicator_menu_item_set_right (IndicatorMenuItem *self, const gchar *text) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - gtk_label_set_label (GTK_LABEL (priv->right_label), text); + gtk_label_set_label (GTK_LABEL (self->priv->right_label), text); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT]); } @@ -322,8 +320,7 @@ indicator_menu_item_set_right (IndicatorMenuItem *self, gboolean indicator_menu_item_get_right_is_lozenge (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - return priv->right_is_lozenge; + return self->priv->right_is_lozenge; } @@ -331,9 +328,8 @@ void indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self, gboolean is_lozenge) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - priv->right_is_lozenge = is_lozenge; - gtk_widget_queue_draw (priv->right_label); + self->priv->right_is_lozenge = is_lozenge; + gtk_widget_queue_draw (self->priv->right_label); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RIGHT_IS_LOZENGE]); } @@ -341,9 +337,8 @@ indicator_menu_item_set_right_is_lozenge (IndicatorMenuItem *self, GdkPixbuf * indicator_menu_item_get_icon (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - if (gtk_image_get_storage_type (priv->image) == GTK_IMAGE_PIXBUF) - return gtk_image_get_pixbuf (priv->image); + if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_PIXBUF) + return gtk_image_get_pixbuf (self->priv->image); else return NULL; } @@ -353,8 +348,7 @@ void indicator_menu_item_set_icon (IndicatorMenuItem *self, GdkPixbuf *icon) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - gtk_image_set_from_pixbuf (priv->image, icon); + gtk_image_set_from_pixbuf (self->priv->image, icon); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON]); } @@ -362,11 +356,10 @@ indicator_menu_item_set_icon (IndicatorMenuItem *self, const gchar * indicator_menu_item_get_icon_name (IndicatorMenuItem *self) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); const gchar *name = NULL; - if (gtk_image_get_storage_type (priv->image) == GTK_IMAGE_ICON_NAME) - gtk_image_get_icon_name (priv->image, &name, NULL); + if (gtk_image_get_storage_type (self->priv->image) == GTK_IMAGE_ICON_NAME) + gtk_image_get_icon_name (self->priv->image, &name, NULL); return name; } @@ -376,8 +369,7 @@ void indicator_menu_item_set_icon_name (IndicatorMenuItem *self, const gchar *name) { - IndicatorMenuItemPrivate *priv = MENU_ITEM_PRIVATE (self); - gtk_image_set_from_icon_name (priv->image, name, GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name (self->priv->image, name, GTK_ICON_SIZE_MENU); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ICON_NAME]); } diff --git a/src/indicator-menu-item.h b/src/indicator-menu-item.h index fc27b73..9c65b7c 100644 --- a/src/indicator-menu-item.h +++ b/src/indicator-menu-item.h @@ -35,6 +35,7 @@ typedef struct _IndicatorMenuItemPrivate IndicatorMenuItemPrivate; struct _IndicatorMenuItem { GtkMenuItem parent; + IndicatorMenuItemPrivate *priv; }; struct _IndicatorMenuItemClass diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c index a8152cd..2228ba2 100644 --- a/src/indicator-printers-menu.c +++ b/src/indicator-printers-menu.c @@ -7,9 +7,6 @@ G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT) -#define PRINTERS_MENU_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_TYPE_PRINTERS_MENU, IndicatorPrintersMenuPrivate)) - struct _IndicatorPrintersMenuPrivate { @@ -31,15 +28,15 @@ GParamSpec *properties[NUM_PROPERTIES]; static void dispose (GObject *object) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (object); + IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object); - if (priv->printers) { - g_hash_table_unref (priv->printers); - priv->printers = NULL; + if (self->priv->printers) { + g_hash_table_unref (self->priv->printers); + self->priv->printers = NULL; } - g_clear_object (&priv->root); - g_clear_object (&priv->cups_notifier); + g_clear_object (&self->priv->root); + g_clear_object (&self->priv->cups_notifier); G_OBJECT_CLASS (indicator_printers_menu_parent_class)->dispose (object); } @@ -160,10 +157,9 @@ update_printer_menuitem (IndicatorPrintersMenu *self, int state, int njobs) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); DbusmenuMenuitem *item; - item = g_hash_table_lookup (priv->printers, printer); + item = g_hash_table_lookup (self->priv->printers, printer); if (!item) { item = dbusmenu_menuitem_new (); @@ -174,8 +170,8 @@ update_printer_menuitem (IndicatorPrintersMenu *self, G_CALLBACK (show_system_settings), g_strdup (printer), (GClosureNotify) g_free, 0); - dbusmenu_menuitem_child_append(priv->root, item); - g_hash_table_insert (priv->printers, g_strdup (printer), item); + dbusmenu_menuitem_child_append(self->priv->root, item); + g_hash_table_insert (self->priv->printers, g_strdup (printer), item); } if (njobs == 0) { @@ -248,16 +244,19 @@ on_printer_state_changed (CupsNotifier *object, static void indicator_printers_menu_init (IndicatorPrintersMenu *self) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); int ndests, i; cups_dest_t *dests; - priv->root = dbusmenu_menuitem_new (); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_TYPE_PRINTERS_MENU, + IndicatorPrintersMenuPrivate); - priv->printers = g_hash_table_new_full (g_str_hash, - g_str_equal, - g_free, - g_object_unref); + self->priv->root = dbusmenu_menuitem_new (); + + self->priv->printers = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_object_unref); /* create initial menu items */ ndests = cupsGetDests (&dests); @@ -284,16 +283,14 @@ indicator_printers_menu_new (void) DbusmenuMenuitem * indicator_printers_menu_get_root (IndicatorPrintersMenu *self) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); - return priv->root; + return self->priv->root; } CupsNotifier * indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); - return priv->cups_notifier; + return self->priv->cups_notifier; } @@ -301,20 +298,18 @@ void indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self, CupsNotifier *cups_notifier) { - IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); - - if (priv->cups_notifier) { - g_object_disconnect (priv->cups_notifier, + if (self->priv->cups_notifier) { + g_object_disconnect (self->priv->cups_notifier, "any-signal", update_job, self, "any-signal", on_printer_state_changed, self, NULL); - g_object_unref (priv->cups_notifier); + g_object_unref (self->priv->cups_notifier); } - priv->cups_notifier = cups_notifier; + self->priv->cups_notifier = cups_notifier; - if (priv->cups_notifier) { - g_object_connect (priv->cups_notifier, + if (self->priv->cups_notifier) { + g_object_connect (self->priv->cups_notifier, "signal::job-created", update_job, self, "signal::job-state", update_job, self, "signal::job-completed", update_job, self, diff --git a/src/indicator-printers-menu.h b/src/indicator-printers-menu.h index 8e1a44f..75c076e 100644 --- a/src/indicator-printers-menu.h +++ b/src/indicator-printers-menu.h @@ -37,6 +37,7 @@ typedef struct _IndicatorPrintersMenuPrivate IndicatorPrintersMenuPrivate; struct _IndicatorPrintersMenu { GObject parent; + IndicatorPrintersMenuPrivate *priv; }; struct _IndicatorPrintersMenuClass diff --git a/src/indicator-printers.c b/src/indicator-printers.c index def019a..e9f9560 100644 --- a/src/indicator-printers.c +++ b/src/indicator-printers.c @@ -37,9 +37,6 @@ INDICATOR_SET_TYPE(INDICATOR_PRINTERS_TYPE) G_DEFINE_TYPE (IndicatorPrinters, indicator_printers, INDICATOR_OBJECT_TYPE) -#define INDICATOR_PRINTERS_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_PRINTERS_TYPE, IndicatorPrintersPrivate)) - struct _IndicatorPrintersPrivate { @@ -50,9 +47,9 @@ struct _IndicatorPrintersPrivate static void dispose (GObject *object) { - IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (object); - g_clear_object (&priv->entry.menu); - g_clear_object (&priv->entry.image); + IndicatorPrinters *self = INDICATOR_PRINTERS (object); + g_clear_object (&self->priv->entry.menu); + g_clear_object (&self->priv->entry.image); G_OBJECT_CLASS (indicator_printers_parent_class)->dispose (object); } @@ -60,8 +57,8 @@ dispose (GObject *object) static GList * get_entries (IndicatorObject *io) { - IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (io); - return g_list_append (NULL, &priv->entry); + IndicatorPrinters *self = INDICATOR_PRINTERS (io); + return g_list_append (NULL, &self->priv->entry); } @@ -214,13 +211,18 @@ new_indicator_item (DbusmenuMenuitem *newitem, static void -indicator_printers_init (IndicatorPrinters *io) +indicator_printers_init (IndicatorPrinters *self) { - IndicatorPrintersPrivate *priv = INDICATOR_PRINTERS_GET_PRIVATE (io); + IndicatorPrintersPrivate *priv; DbusmenuGtkMenu *menu; DbusmenuClient *client; GtkImage *image; + priv = G_TYPE_INSTANCE_GET_PRIVATE (self, + INDICATOR_PRINTERS_TYPE, + IndicatorPrintersPrivate); + self->priv = priv; + menu = dbusmenu_gtkmenu_new(INDICATOR_PRINTERS_DBUS_NAME, INDICATOR_PRINTERS_DBUS_OBJECT_PATH); diff --git a/src/indicator-printers.h b/src/indicator-printers.h index 0d97769..78d2367 100644 --- a/src/indicator-printers.h +++ b/src/indicator-printers.h @@ -52,6 +52,7 @@ typedef struct _IndicatorPrintersPrivate IndicatorPrintersPrivate; struct _IndicatorPrinters { IndicatorObject parent; + IndicatorPrintersPrivate *priv; }; struct _IndicatorPrintersClass |