From 767aae6a882f66781cfb7dcda1a1e0d35847d36c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 2 Feb 2012 18:15:55 +0100 Subject: Move cups notifier object out of indicator-printers-menu --- src/indicator-printers-menu.c | 118 +++++++++++++++++++++++++++++++-------- src/indicator-printers-menu.h | 5 ++ src/indicator-printers-service.c | 21 ++++++- 3 files changed, 119 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c index 95bee79..a8152cd 100644 --- a/src/indicator-printers-menu.c +++ b/src/indicator-printers-menu.c @@ -4,8 +4,6 @@ #include #include -#include "cups-notifier.h" - G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT) @@ -21,6 +19,15 @@ struct _IndicatorPrintersMenuPrivate }; +enum { + PROP_0, + PROP_CUPS_NOTIFIER, + NUM_PROPERTIES +}; + +GParamSpec *properties[NUM_PROPERTIES]; + + static void dispose (GObject *object) { @@ -38,6 +45,46 @@ dispose (GObject *object) } +void +set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object); + + switch (property_id) { + case PROP_CUPS_NOTIFIER: + indicator_printers_menu_set_cups_notifier (self, + g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + + +void +get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (object); + + switch (property_id) { + case PROP_CUPS_NOTIFIER: + g_value_set_object (value, + indicator_printers_menu_get_cups_notifier (self)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + } +} + + static void indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass) { @@ -46,6 +93,16 @@ indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass) g_type_class_add_private (klass, sizeof (IndicatorPrintersMenuPrivate)); object_class->dispose = dispose; + object_class->get_property = get_property; + object_class->set_property = set_property; + + properties[PROP_CUPS_NOTIFIER] = g_param_spec_object ("cups-notifier", + "Cups Notifier", + "A cups notifier object", + CUPS_TYPE_NOTIFIER, + G_PARAM_READWRITE); + + g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); } @@ -194,7 +251,6 @@ indicator_printers_menu_init (IndicatorPrintersMenu *self) IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); int ndests, i; cups_dest_t *dests; - GError *error = NULL; priv->root = dbusmenu_menuitem_new (); @@ -203,27 +259,6 @@ indicator_printers_menu_init (IndicatorPrintersMenu *self) g_free, g_object_unref); - priv->cups_notifier = cups_notifier_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - 0, - NULL, - "/org/cups/cupsd/Notifier", - NULL, - &error); - if (error) { - g_warning ("Error creating cups notify handler: %s", error->message); - g_clear_error (&error); - } - else { - g_signal_connect (priv->cups_notifier, "job-created", - G_CALLBACK (update_job), self); - g_signal_connect (priv->cups_notifier, "job-state", - G_CALLBACK (update_job), self); - g_signal_connect (priv->cups_notifier, "job-completed", - G_CALLBACK (update_job), self); - g_signal_connect (priv->cups_notifier, "printer-state-changed", - G_CALLBACK (on_printer_state_changed), self); - } - /* create initial menu items */ ndests = cupsGetDests (&dests); for (i = 0; i < ndests; i++) { @@ -253,3 +288,38 @@ indicator_printers_menu_get_root (IndicatorPrintersMenu *self) return priv->root; } + +CupsNotifier * +indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self) +{ + IndicatorPrintersMenuPrivate *priv = PRINTERS_MENU_PRIVATE (self); + return priv->cups_notifier; +} + + +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, + "any-signal", update_job, self, + "any-signal", on_printer_state_changed, self, + NULL); + g_object_unref (priv->cups_notifier); + } + + priv->cups_notifier = cups_notifier; + + if (priv->cups_notifier) { + g_object_connect (priv->cups_notifier, + "signal::job-created", update_job, self, + "signal::job-state", update_job, self, + "signal::job-completed", update_job, self, + "signal::printer-state-changed", on_printer_state_changed, self, + NULL); + } +} + diff --git a/src/indicator-printers-menu.h b/src/indicator-printers-menu.h index bca9b0c..8e1a44f 100644 --- a/src/indicator-printers-menu.h +++ b/src/indicator-printers-menu.h @@ -4,6 +4,8 @@ #include #include +#include "cups-notifier.h" + G_BEGIN_DECLS #define INDICATOR_TYPE_PRINTERS_MENU indicator_printers_menu_get_type() @@ -46,6 +48,9 @@ GType indicator_printers_menu_get_type (void) G_GNUC_CONST; IndicatorPrintersMenu *indicator_printers_menu_new (void); DbusmenuMenuitem * indicator_printers_menu_get_root (IndicatorPrintersMenu *menu); +CupsNotifier * indicator_printers_menu_get_cups_notifier (IndicatorPrintersMenu *self); +void indicator_printers_menu_set_cups_notifier (IndicatorPrintersMenu *self, + CupsNotifier *cups_notifier); G_END_DECLS diff --git a/src/indicator-printers-service.c b/src/indicator-printers-service.c index f390f36..ce89dd0 100644 --- a/src/indicator-printers-service.c +++ b/src/indicator-printers-service.c @@ -21,6 +21,7 @@ #include #include "dbus-names.h" +#include "cups-notifier.h" #include "indicator-printers-menu.h" @@ -36,7 +37,9 @@ int main (int argc, char *argv[]) { IndicatorService *service; DbusmenuServer *menuserver; + CupsNotifier *cups_notifier; IndicatorPrintersMenu *menu; + GError *error = NULL; gtk_init (&argc, &argv); @@ -47,7 +50,22 @@ int main (int argc, char *argv[]) G_CALLBACK (service_shutdown), NULL); - menu = indicator_printers_menu_new (); + cups_notifier = cups_notifier_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + 0, + NULL, + CUPS_DBUS_PATH, + NULL, + &error); + if (error) { + g_warning ("Error creating cups notify handler: %s", error->message); + g_error_free (error); + g_object_unref (service); + return 1; + } + + menu = g_object_new (INDICATOR_TYPE_PRINTERS_MENU, + "cups-notifier", cups_notifier, + NULL); menuserver = dbusmenu_server_new (INDICATOR_PRINTERS_DBUS_OBJECT_PATH); dbusmenu_server_set_root (menuserver, @@ -57,6 +75,7 @@ int main (int argc, char *argv[]) g_object_unref (menu); g_object_unref (menuserver); + g_object_unref (cups_notifier); g_object_unref (service); return 0; } -- cgit v1.2.3