aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-printers-menu.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-02-02 18:15:55 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-02-02 18:15:55 +0100
commit767aae6a882f66781cfb7dcda1a1e0d35847d36c (patch)
tree6dd478fedfaaae62d517f64ea723ddb0420632ed /src/indicator-printers-menu.c
parentad2241282200224ce96d3ec7dc80d6d2b4b9053a (diff)
downloadayatana-indicator-printers-767aae6a882f66781cfb7dcda1a1e0d35847d36c.tar.gz
ayatana-indicator-printers-767aae6a882f66781cfb7dcda1a1e0d35847d36c.tar.bz2
ayatana-indicator-printers-767aae6a882f66781cfb7dcda1a1e0d35847d36c.zip
Move cups notifier object out of indicator-printers-menu
Diffstat (limited to 'src/indicator-printers-menu.c')
-rw-r--r--src/indicator-printers-menu.c118
1 files changed, 94 insertions, 24 deletions
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 <gio/gio.h>
#include <cups/cups.h>
-#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);
+ }
+}
+