[gnome-settings-daemon] print-notifications: fix a few issues



commit 1339365857a9f1131d9f62738631f3e7fd4fac88
Author: William Jon McCann <jmccann redhat com>
Date:   Fri Jan 28 18:34:13 2011 -0500

    print-notifications: fix a few issues
    
    Move the code into the manager and fix a few things up.

 .../gsd-print-notifications-manager.c              |  265 ++++++++++++++++++--
 .../gsd-print-notifications-plugin.c               |  229 +-----------------
 2 files changed, 249 insertions(+), 245 deletions(-)
---
diff --git a/plugins/print-notifications/gsd-print-notifications-manager.c b/plugins/print-notifications/gsd-print-notifications-manager.c
index 09ccb72..80e5a19 100644
--- a/plugins/print-notifications/gsd-print-notifications-manager.c
+++ b/plugins/print-notifications/gsd-print-notifications-manager.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2011 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,10 +32,9 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h>
-#include <gtk/gtk.h>
 
+#include <cups/cups.h>
+#include <libnotify/notify.h>
 #include <libnotify/notify.h>
 
 #include "gnome-settings-profile.h"
@@ -43,9 +42,15 @@
 
 #define GSD_PRINT_NOTIFICATIONS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, GsdPrintNotificationsManagerPrivate))
 
+#define CUPS_DBUS_NAME      "com.redhat.PrinterSpooler"
+#define CUPS_DBUS_PATH      "/com/redhat/PrinterSpooler"
+#define CUPS_DBUS_INTERFACE "com.redhat.PrinterSpooler"
+
 struct GsdPrintNotificationsManagerPrivate
 {
-        gboolean padding;
+        GDBusProxy                   *cups_proxy;
+        GDBusConnection              *bus_connection;
+        GSList                       *actual_jobs;
 };
 
 enum {
@@ -60,14 +65,218 @@ G_DEFINE_TYPE (GsdPrintNotificationsManager, gsd_print_notifications_manager, G_
 
 static gpointer manager_object = NULL;
 
+
+static void
+on_cups_notification (GDBusConnection *connection,
+                      const char      *sender_name,
+                      const char      *object_path,
+                      const char      *interface_name,
+                      const char      *signal_name,
+                      GVariant        *parameters,
+                      gpointer         user_data)
+{
+        GsdPrintNotificationsManager *manager = GSD_PRINT_NOTIFICATIONS_MANAGER (user_data);
+        NotifyNotification          *notification;
+        cups_job_t                  *jobs;
+        GSList                      *actual = NULL;
+        GSList                      *tmp = NULL;
+        gchar                       *printer_name = NULL;
+        gchar                       *user_name = NULL;
+        gchar                       *primary_text = NULL;
+        gchar                       *secondary_text = NULL;
+        guint                        job_id;
+        gint                         actual_job = -1;
+        gint                         num_jobs, i;
+        gint                         index = -1;
+
+        if (g_strcmp0 (signal_name, "PrinterAdded") == 0) {
+                /* Translators: New printer has been added */
+                primary_text = g_strdup (_("New printer"));
+                if (g_variant_n_children (parameters) == 1) {
+                        g_variant_get (parameters, "(&s)", &printer_name);
+                        secondary_text = g_strdup_printf ("%s", printer_name);
+                }
+        } else if (g_strcmp0 (signal_name, "PrinterRemoved") == 0) {
+                /* Translators: A printer has been removed */
+                primary_text = g_strdup (_("Printer removed"));
+                if (g_variant_n_children (parameters) == 1) {
+                        g_variant_get (parameters, "(&s)", &printer_name);
+                        secondary_text = g_strdup_printf ("%s", printer_name);
+                }
+        } else if (g_strcmp0 (signal_name, "QueueChanged") == 0) {
+                if (g_variant_n_children (parameters) == 1 ||
+                    g_variant_n_children (parameters) == 3) {
+                        g_variant_get (parameters, "(&s)", &printer_name);
+                }
+
+                if (manager->priv->actual_jobs != NULL) {
+                        num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
+
+                        for (actual = manager->priv->actual_jobs; actual; actual = actual->next) {
+                                actual_job = GPOINTER_TO_INT (actual->data);
+                                for (i = 0; i < num_jobs; i++) {
+                                        if (jobs[i].id == actual_job) {
+                                                switch (jobs[i].state) {
+                                                case IPP_JOB_PENDING:
+                                                case IPP_JOB_HELD:
+                                                case IPP_JOB_PROCESSING:
+                                                        break;
+                                                case IPP_JOB_STOPPED:
+                                                        /* Translators: A print job has been stopped */
+                                                        primary_text = g_strdup (_("Print job stopped"));
+                                                        /* Translators: "print-job xy" on a printer */
+                                                        secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
+                                                        actual->data = GINT_TO_POINTER (-1);
+                                                        break;
+                                                case IPP_JOB_CANCELED:
+                                                        /* Translators: A print job has been canceled */
+                                                        primary_text = g_strdup (_("Print job canceled"));
+                                                        /* Translators: "print-job xy" on a printer */
+                                                        secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
+                                                        actual->data = GINT_TO_POINTER (-1);
+                                                        break;
+                                                case IPP_JOB_ABORTED:
+                                                        /* Translators: A print job has been aborted */
+                                                        primary_text = g_strdup (_("Print job aborted"));
+                                                        /* Translators: "print-job xy" on a printer */
+                                                        secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
+                                                        actual->data = GINT_TO_POINTER (-1);
+                                                        break;
+                                                case IPP_JOB_COMPLETED:
+                                                        /* Translators: A print job has been completed */
+                                                        primary_text = g_strdup (_("Print job completed"));
+                                                        /* Translators: "print-job xy" on a printer */
+                                                        secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
+                                                        actual->data = GINT_TO_POINTER (-1);
+                                                        break;
+                                                }
+                                                break;
+                                        }
+                                }
+                        }
+
+                        for (actual = manager->priv->actual_jobs; actual; actual = actual->next) {
+                                if (GPOINTER_TO_INT (actual->data) < 0) {
+                                        tmp = actual->next;
+                                        manager->priv->actual_jobs =
+                                                g_slist_delete_link (manager->priv->actual_jobs, actual);
+                                        actual = tmp;
+                                        if (!actual)
+                                                break;
+                                }
+                        }
+
+                        cupsFreeJobs (num_jobs, jobs);
+                }
+        } else if (g_strcmp0 (signal_name, "JobQueuedLocal") == 0) {
+                if (g_variant_n_children (parameters) == 3) {
+                        g_variant_get (parameters, "(&su&s)", &printer_name, &job_id, &user_name);
+
+                        num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
+
+                        index = -1;
+                        for (i = 0; i < num_jobs; i++)
+                                if (jobs[i].id == job_id)
+                                        index = i;
+
+                        if (index >= 0) {
+                                /* Translators: Somebody sent something to printer */
+                                primary_text = g_strdup (_("New print job"));
+                                /* Translators: "print-job xy" on a printer */
+                                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[index].title, jobs[index].dest);
+                        }
+
+                        manager->priv->actual_jobs =
+                                g_slist_append (manager->priv->actual_jobs, GUINT_TO_POINTER (job_id));
+
+                        cupsFreeJobs (num_jobs, jobs);
+                }
+        } else if (g_strcmp0 (signal_name, "JobStartedLocal") == 0) {
+                if (g_variant_n_children (parameters) == 3) {
+                        g_variant_get (parameters, "(&su&s)", &printer_name, &job_id, &user_name);
+
+                        for (actual = manager->priv->actual_jobs; actual; actual = actual->next) {
+                                if (GPOINTER_TO_INT (actual->data) == job_id) {
+                                        num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
+
+                                        index = -1;
+                                        for (i = 0; i < num_jobs; i++)
+                                                if (jobs[i].id == job_id)
+                                                        index = i;
+
+                                        if (index >= 0) {
+                                                /* Translators: A job is printing */
+                                                primary_text = g_strdup (_("Printing job"));
+                                                /* Translators: "print-job xy" on a printer */
+                                                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[index].title, jobs[index].dest);
+                                        }
+
+                                        cupsFreeJobs (num_jobs, jobs);
+                                }
+                        }
+                }
+        }
+
+        if (primary_text) {
+                notification = notify_notification_new (primary_text,
+                                                        secondary_text,
+                                                        NULL);
+                notify_notification_show (notification, NULL);
+        }
+}
+
 gboolean
 gsd_print_notifications_manager_start (GsdPrintNotificationsManager *manager,
-                               GError               **error)
+                                       GError                      **error)
 {
+        cups_job_t *jobs;
+        GError     *lerror;
+        int         num_jobs;
+        int         i;
+
         g_debug ("Starting print-notifications manager");
 
         gnome_settings_profile_start (NULL);
+
+        manager->priv->actual_jobs = NULL;
+
+        lerror = NULL;
+        manager->priv->cups_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                                   0,
+                                                                   NULL,
+                                                                   CUPS_DBUS_NAME,
+                                                                   CUPS_DBUS_PATH,
+                                                                   CUPS_DBUS_INTERFACE,
+                                                                   NULL,
+                                                                   &lerror);
+        if (lerror != NULL) {
+                g_propagate_error (error, lerror);
+                return FALSE;
+        }
+
+        manager->priv->bus_connection = g_dbus_proxy_get_connection (manager->priv->cups_proxy);
+
+        g_dbus_connection_signal_subscribe (manager->priv->bus_connection,
+                                            NULL,
+                                            CUPS_DBUS_INTERFACE,
+                                            NULL,
+                                            CUPS_DBUS_PATH,
+                                            NULL,
+                                            0,
+                                            on_cups_notification,
+                                            manager,
+                                            NULL);
+
+        num_jobs = cupsGetJobs (&jobs, NULL, 1, CUPS_WHICHJOBS_ACTIVE);
+
+        for (i = 0; i < num_jobs; i++) {
+                manager->priv->actual_jobs = g_slist_append (manager->priv->actual_jobs, GUINT_TO_POINTER (jobs[i].id));
+        }
+
+        cupsFreeJobs (num_jobs, jobs);
+
         gnome_settings_profile_end (NULL);
+
         return TRUE;
 }
 
@@ -75,13 +284,25 @@ void
 gsd_print_notifications_manager_stop (GsdPrintNotificationsManager *manager)
 {
         g_debug ("Stopping print-notifications manager");
+
+        if (manager->priv->actual_jobs != NULL) {
+                g_slist_free (manager->priv->actual_jobs);
+                manager->priv->actual_jobs = NULL;
+        }
+
+        manager->priv->bus_connection = NULL;
+
+        if (manager->priv->cups_proxy != NULL) {
+                g_object_unref (manager->priv->cups_proxy);
+                manager->priv->cups_proxy = NULL;
+        }
 }
 
 static void
 gsd_print_notifications_manager_set_property (GObject        *object,
-                               guint           prop_id,
-                               const GValue   *value,
-                               GParamSpec     *pspec)
+                                              guint           prop_id,
+                                              const GValue   *value,
+                                              GParamSpec     *pspec)
 {
         GsdPrintNotificationsManager *self;
 
@@ -96,9 +317,9 @@ gsd_print_notifications_manager_set_property (GObject        *object,
 
 static void
 gsd_print_notifications_manager_get_property (GObject        *object,
-                               guint           prop_id,
-                               GValue         *value,
-                               GParamSpec     *pspec)
+                                              guint           prop_id,
+                                              GValue         *value,
+                                              GParamSpec     *pspec)
 {
         GsdPrintNotificationsManager *self;
 
@@ -113,8 +334,8 @@ gsd_print_notifications_manager_get_property (GObject        *object,
 
 static GObject *
 gsd_print_notifications_manager_constructor (GType                  type,
-                              guint                  n_construct_properties,
-                              GObjectConstructParam *construct_properties)
+                                             guint                  n_construct_properties,
+                                             GObjectConstructParam *construct_properties)
 {
         GsdPrintNotificationsManager      *print_notifications_manager;
         GsdPrintNotificationsManagerClass *klass;
@@ -122,8 +343,8 @@ gsd_print_notifications_manager_constructor (GType                  type,
         klass = GSD_PRINT_NOTIFICATIONS_MANAGER_CLASS (g_type_class_peek (GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER));
 
         print_notifications_manager = GSD_PRINT_NOTIFICATIONS_MANAGER (G_OBJECT_CLASS (gsd_print_notifications_manager_parent_class)->constructor (type,
-                                                                                                      n_construct_properties,
-                                                                                                      construct_properties));
+                                                                                                                                                   n_construct_properties,
+                                                                                                                                                   construct_properties));
 
         return G_OBJECT (print_notifications_manager);
 }
@@ -162,14 +383,20 @@ gsd_print_notifications_manager_init (GsdPrintNotificationsManager *manager)
 static void
 gsd_print_notifications_manager_finalize (GObject *object)
 {
-        GsdPrintNotificationsManager *print_notifications_manager;
+        GsdPrintNotificationsManager *manager;
 
         g_return_if_fail (object != NULL);
         g_return_if_fail (GSD_IS_PRINT_NOTIFICATIONS_MANAGER (object));
 
-        print_notifications_manager = GSD_PRINT_NOTIFICATIONS_MANAGER (object);
+        manager = GSD_PRINT_NOTIFICATIONS_MANAGER (object);
+
+        g_return_if_fail (manager->priv != NULL);
+
+        if (manager->priv->cups_proxy != NULL) {
+                g_object_unref (manager->priv->cups_proxy);
+        }
 
-        g_return_if_fail (print_notifications_manager->priv != NULL);
+        g_slist_free (manager->priv->actual_jobs);
 
         G_OBJECT_CLASS (gsd_print_notifications_manager_parent_class)->finalize (object);
 }
diff --git a/plugins/print-notifications/gsd-print-notifications-plugin.c b/plugins/print-notifications/gsd-print-notifications-plugin.c
index 57c9c42..2b9055b 100644
--- a/plugins/print-notifications/gsd-print-notifications-plugin.c
+++ b/plugins/print-notifications/gsd-print-notifications-plugin.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ * Copyright (C) 2011 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,31 +23,18 @@
 #include <glib/gi18n-lib.h>
 #include <gmodule.h>
 
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
-
-#include <cups/cups.h>
-#include <libnotify/notify.h>
-
 #include "gnome-settings-plugin.h"
 #include "gsd-print-notifications-plugin.h"
 #include "gsd-print-notifications-manager.h"
 
 struct GsdPrintNotificationsPluginPrivate {
         GsdPrintNotificationsManager *manager;
-        GDBusProxy                   *cups_proxy;
-        GDBusConnection              *bus_connection;
-        GSList                       *actual_jobs;
 };
 
 #define GSD_PRINT_NOTIFICATIONS_PLUGIN_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN, GsdPrintNotificationsPluginPrivate))
 
 GNOME_SETTINGS_PLUGIN_REGISTER (GsdPrintNotificationsPlugin, gsd_print_notifications_plugin)
 
-#define CUPS_DBUS_NAME      "com.redhat.PrinterSpooler"
-#define CUPS_DBUS_PATH      "/com/redhat/PrinterSpooler"
-#define CUPS_DBUS_INTERFACE "com.redhat.PrinterSpooler"
-
 static void
 gsd_print_notifications_plugin_init (GsdPrintNotificationsPlugin *plugin)
 {
@@ -78,236 +65,26 @@ gsd_print_notifications_plugin_finalize (GObject *object)
 }
 
 static void
-cups_notification_cb (GDBusConnection *connection,
-                      const gchar     *sender_name,
-                      const gchar     *object_path,
-                      const gchar     *interface_name,
-                      const gchar     *signal_name,
-                      GVariant        *parameters,
-                      gpointer         user_data)
-{
-  GsdPrintNotificationsPlugin *print_notifications_plugin = GSD_PRINT_NOTIFICATIONS_PLUGIN (user_data);
-  NotifyNotification          *notification;
-  cups_job_t                  *jobs;
-  GSList                      *actual = NULL;
-  GSList                      *tmp = NULL;
-  gchar                       *printer_name = NULL;
-  gchar                       *user_name = NULL;
-  gchar                       *primary_text = NULL;
-  gchar                       *secondary_text = NULL;
-  guint                        job_id;
-  gint                         actual_job = -1;
-  gint                         num_jobs, i;
-  gint                         index = -1;
-
-  if (g_strcmp0 (signal_name, "PrinterAdded") == 0) {
-    /* Translators: New printer has been added */
-    primary_text = g_strdup (_("New printer"));
-    if (g_variant_n_children (parameters) == 1) {
-      g_variant_get (parameters, "(&s)", &printer_name);
-      secondary_text = g_strdup_printf ("%s", printer_name);
-    }
-  }
-  else if (g_strcmp0 (signal_name, "PrinterRemoved") == 0) {
-    /* Translators: A printer has been removed */
-    primary_text = g_strdup (_("Printer removed"));
-    if (g_variant_n_children (parameters) == 1) {
-      g_variant_get (parameters, "(&s)", &printer_name);
-      secondary_text = g_strdup_printf ("%s", printer_name);
-    }
-  }
-  else if (g_strcmp0 (signal_name, "QueueChanged") == 0) {
-    if (g_variant_n_children (parameters) == 1 ||
-        g_variant_n_children (parameters) == 3) {
-      g_variant_get (parameters, "(&s)", &printer_name);
-    }
-
-    if (print_notifications_plugin->priv->actual_jobs) {
-      num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
-
-      for (actual = print_notifications_plugin->priv->actual_jobs; actual; actual = actual->next) {
-        actual_job = GPOINTER_TO_INT (actual->data);
-        for (i = 0; i < num_jobs; i++) {
-          if (jobs[i].id == actual_job) {
-            switch (jobs[i].state) {
-              case IPP_JOB_PENDING:
-              case IPP_JOB_HELD:
-              case IPP_JOB_PROCESSING:
-                break;
-              case IPP_JOB_STOPPED:
-                /* Translators: A print job has been stopped */
-                primary_text = g_strdup (_("Print job stopped"));
-                /* Translators: "print-job xy" on a printer */
-                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
-                actual->data = GINT_TO_POINTER (-1);
-                break;
-              case IPP_JOB_CANCELED:
-                /* Translators: A print job has been canceled */
-                primary_text = g_strdup (_("Print job canceled"));
-                /* Translators: "print-job xy" on a printer */
-                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
-                actual->data = GINT_TO_POINTER (-1);
-                break;
-              case IPP_JOB_ABORTED:
-                /* Translators: A print job has been aborted */
-                primary_text = g_strdup (_("Print job aborted"));
-                /* Translators: "print-job xy" on a printer */
-                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
-                actual->data = GINT_TO_POINTER (-1);
-                break;
-              case IPP_JOB_COMPLETED:
-                /* Translators: A print job has been completed */
-                primary_text = g_strdup (_("Print job completed"));
-                /* Translators: "print-job xy" on a printer */
-                secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[i].title, jobs[i].dest);
-                actual->data = GINT_TO_POINTER (-1);
-                break;
-            }
-            break;
-          }
-        }
-      }
-
-      for (actual = print_notifications_plugin->priv->actual_jobs; actual; actual = actual->next) {
-        if (GPOINTER_TO_INT (actual->data) < 0) {
-          tmp = actual->next;
-          print_notifications_plugin->priv->actual_jobs = 
-            g_slist_delete_link (print_notifications_plugin->priv->actual_jobs, actual);
-          actual = tmp;
-          if (!actual)
-            break;
-         }
-      }
-
-      cupsFreeJobs (num_jobs, jobs);
-    } 
-  }
-  else if (g_strcmp0 (signal_name, "JobQueuedLocal") == 0) {
-    if (g_variant_n_children (parameters) == 3) {
-      g_variant_get (parameters, "(&su&s)", &printer_name, &job_id, &user_name);
-
-      num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
-
-      index = -1;
-      for (i = 0; i < num_jobs; i++)
-        if (jobs[i].id == job_id)
-          index = i;
-
-      if (index >= 0) {
-        /* Translators: Somebody sent something to printer */
-        primary_text = g_strdup (_("New print job"));
-        /* Translators: "print-job xy" on a printer */
-        secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[index].title, jobs[index].dest);
-      }
-
-      print_notifications_plugin->priv->actual_jobs =
-        g_slist_append (print_notifications_plugin->priv->actual_jobs, GUINT_TO_POINTER (job_id));
-
-      cupsFreeJobs (num_jobs, jobs);
-    }
-  }
-  else if (g_strcmp0 (signal_name, "JobStartedLocal") == 0) {
-    if (g_variant_n_children (parameters) == 3) {
-      g_variant_get (parameters, "(&su&s)", &printer_name, &job_id, &user_name);
-
-      for (actual = print_notifications_plugin->priv->actual_jobs; actual; actual = actual->next) {
-        if (GPOINTER_TO_INT (actual->data) == job_id) {
-          num_jobs = cupsGetJobs (&jobs, printer_name, 1, CUPS_WHICHJOBS_ALL);
-
-          index = -1;
-          for (i = 0; i < num_jobs; i++)
-            if (jobs[i].id == job_id)
-              index = i;
-
-          if (index >= 0) {
-            /* Translators: A job is printing */
-            primary_text = g_strdup (_("Printing job"));
-            /* Translators: "print-job xy" on a printer */
-            secondary_text = g_strdup_printf (_("\"%s\" on printer %s"), jobs[index].title, jobs[index].dest);
-          }
-
-          cupsFreeJobs (num_jobs, jobs);
-        }
-      }
-    }
-  }
-
-  if (primary_text) {
-    notification = notify_notification_new (primary_text,
-                                            secondary_text,
-                                            NULL);
-    notify_notification_show (notification, NULL);
-  }
-}
-
-static void
 impl_activate (GnomeSettingsPlugin *plugin)
 {
-        GsdPrintNotificationsPlugin *print_notifications_plugin = GSD_PRINT_NOTIFICATIONS_PLUGIN (plugin);
-        cups_job_t                  *jobs;
-        gboolean                     res;
-        GError                      *error;
-        gint                         num_jobs, i;
+        gboolean res;
+        GError  *error;
 
         g_debug ("Activating print-notifications plugin");
 
-        print_notifications_plugin->priv->actual_jobs = NULL;
-
         error = NULL;
         res = gsd_print_notifications_manager_start (GSD_PRINT_NOTIFICATIONS_PLUGIN (plugin)->priv->manager, &error);
         if (! res) {
                 g_warning ("Unable to start print-notifications manager: %s", error->message);
                 g_error_free (error);
         }
-
-        print_notifications_plugin->priv->cups_proxy =
-          g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
-                                         0,
-                                         NULL,
-                                         CUPS_DBUS_NAME,
-                                         CUPS_DBUS_PATH,
-                                         CUPS_DBUS_INTERFACE,
-                                         NULL,
-                                         &error);
-
-        print_notifications_plugin->priv->bus_connection =
-          g_dbus_proxy_get_connection (print_notifications_plugin->priv->cups_proxy);
-
-        g_dbus_connection_signal_subscribe  (print_notifications_plugin->priv->bus_connection,
-                                             NULL,
-                                             CUPS_DBUS_INTERFACE,
-                                             NULL,
-                                             CUPS_DBUS_PATH,
-                                             NULL,
-                                             0,
-                                             cups_notification_cb,
-                                             print_notifications_plugin,
-                                             NULL);
-
-        num_jobs = cupsGetJobs (&jobs, NULL, 1, CUPS_WHICHJOBS_ACTIVE);
-
-        for (i = 0; i < num_jobs; i++)
-          print_notifications_plugin->priv->actual_jobs =
-            g_slist_append (print_notifications_plugin->priv->actual_jobs, GUINT_TO_POINTER (jobs[i].id));
-
-        cupsFreeJobs (num_jobs, jobs);
 }
 
 static void
 impl_deactivate (GnomeSettingsPlugin *plugin)
 {
-        GsdPrintNotificationsPlugin *print_notifications_plugin = GSD_PRINT_NOTIFICATIONS_PLUGIN (plugin);
-
         g_debug ("Deactivating print_notifications plugin");
         gsd_print_notifications_manager_stop (GSD_PRINT_NOTIFICATIONS_PLUGIN (plugin)->priv->manager);
-
-        g_slist_free (print_notifications_plugin->priv->actual_jobs);
-        print_notifications_plugin->priv->actual_jobs = NULL;
-
-        print_notifications_plugin->priv->bus_connection = NULL;
-
-        if (print_notifications_plugin->priv->cups_proxy != NULL)
-          g_object_unref (print_notifications_plugin->priv->cups_proxy);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]