[gnome-settings-daemon] print-notifications: add new plugin
- From: William Jon McCann <mccann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] print-notifications: add new plugin
- Date: Sat, 29 Jan 2011 00:36:32 +0000 (UTC)
commit 251613c9564a0d5056a2a278fbe4e3f0ca07d665
Author: Marek Kasik <mkasik redhat com>
Date: Fri Jan 28 18:06:12 2011 -0500
print-notifications: add new plugin
configure.ac | 15 +
data/Makefile.am | 1 +
...gnome.settings-daemon.plugins.gschema.xml.in.in | 1 +
...n.plugins.print-notifications.gschema.xml.in.in | 14 +
plugins/Makefile.am | 6 +
plugins/print-notifications/Makefile.am | 40 +++
.../gsd-print-notifications-manager.c | 189 +++++++++++
.../gsd-print-notifications-manager.h | 57 ++++
.../gsd-print-notifications-plugin.c | 331 ++++++++++++++++++++
.../gsd-print-notifications-plugin.h | 59 ++++
.../print-notifications.gnome-settings-plugin.in | 8 +
11 files changed, 721 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4c8a158..ef7bbdc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -350,6 +350,19 @@ AC_SUBST(POLKIT_CFLAGS)
AC_SUBST(POLKIT_LIBS)
+# ---------------------------------------------------------------------------
+# CUPS
+# ---------------------------------------------------------------------------
+
+AC_CHECK_HEADERS([cups/cups.h cups/http.h cups/ipp.h], have_cups=yes, have_cups=no)
+if test x$have_cups = xyes ; then
+ CUPS_LIBS=-lcups
+ AC_SUBST(CUPS_LIBS)
+else
+ AC_MSG_WARN(*** Print-notifications plugin will not be built (CUPS header files not found) ***)
+fi
+AM_CONDITIONAL(BUILD_PRINT_NOTIFICATIONS, [test x$have_cups = xyes])
+
# ---------------------------------------------------------------------------
# Enable Profiling
@@ -452,6 +465,7 @@ plugins/keyboard/Makefile
plugins/media-keys/Makefile
plugins/media-keys/cut-n-paste/Makefile
plugins/mouse/Makefile
+plugins/print-notifications/Makefile
plugins/smartcard/Makefile
plugins/sound/Makefile
plugins/wacom/Makefile
@@ -470,6 +484,7 @@ data/org.gnome.settings-daemon.peripherals.gschema.xml.in
data/org.gnome.settings-daemon.plugins.housekeeping.gschema.xml.in
data/org.gnome.settings-daemon.plugins.xrandr.gschema.xml.in
data/org.gnome.settings-daemon.peripherals.wacom.gschema.xml.in
+data/org.gnome.settings-daemon.plugins.print-notifications.gschema.xml.in
po/Makefile.in
])
diff --git a/data/Makefile.am b/data/Makefile.am
index db669ee..8dae781 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -14,6 +14,7 @@ gsettings_SCHEMAS = \
org.gnome.settings-daemon.plugins.media-keys.gschema.xml \
org.gnome.settings-daemon.plugins.xsettings.gschema.xml \
org.gnome.settings-daemon.plugins.housekeeping.gschema.xml \
+ org.gnome.settings-daemon.plugins.print-notifications.gschema.xml \
org.gnome.settings-daemon.peripherals.wacom.gschema.xml \
org.gnome.settings-daemon.plugins.xrandr.gschema.xml
diff --git a/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
index 1a158a0..35e709a 100644
--- a/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
+++ b/data/org.gnome.settings-daemon.plugins.gschema.xml.in.in
@@ -7,6 +7,7 @@
<child name="font" schema="org.gnome.settings-daemon.plugins.font"/>
<child name="keybindings" schema="org.gnome.settings-daemon.plugins.keybindings"/>
<child name="mouse" schema="org.gnome.settings-daemon.plugins.mouse"/>
+ <child name="print-notifications" schema="org.gnome.settings-daemon.plugins.print-notifications"/>
<child name="smartcard" schema="org.gnome.settings-daemon.plugins.smartcard"/>
<child name="sound" schema="org.gnome.settings-daemon.plugins.sound"/>
</schema>
diff --git a/data/org.gnome.settings-daemon.plugins.print-notifications.gschema.xml.in.in b/data/org.gnome.settings-daemon.plugins.print-notifications.gschema.xml.in.in
new file mode 100644
index 0000000..7aee219
--- /dev/null
+++ b/data/org.gnome.settings-daemon.plugins.print-notifications.gschema.xml.in.in
@@ -0,0 +1,14 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.settings-daemon.plugins.print-notifications" path="/org/gnome/settings-daemon/plugins/print-notifications/">
+ <key name="active" type="b">
+ <default>true</default>
+ <_summary>Activation of this plugin</_summary>
+ <_description>Whether this plugin would be activated by gnome-settings-daemon or not</_description>
+ </key>
+ <key name="priority" type="i">
+ <default>1</default>
+ <_summary>Priority to use for this plugin</_summary>
+ <_description>Priority to use for this plugin in gnome-settings-daemon startup queue</_description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 33e39cb..52143a2 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -32,5 +32,11 @@ else
disabled_plugins += smartcard
endif
+if BUILD_PRINT_NOTIFICATIONS
+enabled_plugins += print-notifications
+else
+disabled_plugins += print-notifications
+endif
+
SUBDIRS = common $(enabled_plugins)
DIST_SUBDIRS = $(SUBDIRS) $(disabled_plugins)
diff --git a/plugins/print-notifications/Makefile.am b/plugins/print-notifications/Makefile.am
new file mode 100644
index 0000000..47a92ca
--- /dev/null
+++ b/plugins/print-notifications/Makefile.am
@@ -0,0 +1,40 @@
+plugin_LTLIBRARIES = \
+ libprint-notifications.la
+
+libprint_notifications_la_SOURCES = \
+ gsd-print-notifications-manager.c \
+ gsd-print-notifications-manager.h \
+ gsd-print-notifications-plugin.c \
+ gsd-print-notifications-plugin.h
+
+libprint_notifications_la_CPPFLAGS = \
+ -I$(top_srcdir)/gnome-settings-daemon \
+ -DGNOME_SETTINGS_LOCALEDIR=\""$(datadir)/locale"\" \
+ $(AM_CPPFLAGS)
+
+libprint_notifications_la_CFLAGS = \
+ $(SETTINGS_PLUGIN_CFLAGS) \
+ $(AM_CFLAGS)
+
+libprint_notifications_la_LDFLAGS = \
+ $(GSD_PLUGIN_LDFLAGS)
+
+libprint_notifications_la_LIBADD = \
+ $(CUPS_LIBS) \
+ $(SETTINGS_PLUGIN_LIBS)
+
+plugin_in_files = \
+ print-notifications.gnome-settings-plugin.in
+
+plugin_DATA = $(plugin_in_files:.gnome-settings-plugin.in=.gnome-settings-plugin)
+
+EXTRA_DIST = \
+ $(plugin_in_files)
+
+CLEANFILES = \
+ $(plugin_DATA)
+
+DISTCLEANFILES = \
+ $(plugin_DATA)
+
+ GSD_INTLTOOL_PLUGIN_RULE@
diff --git a/plugins/print-notifications/gsd-print-notifications-manager.c b/plugins/print-notifications/gsd-print-notifications-manager.c
new file mode 100644
index 0000000..09ccb72
--- /dev/null
+++ b/plugins/print-notifications/gsd-print-notifications-manager.c
@@ -0,0 +1,189 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include <locale.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gdk/gdk.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
+#include <libnotify/notify.h>
+
+#include "gnome-settings-profile.h"
+#include "gsd-print-notifications-manager.h"
+
+#define GSD_PRINT_NOTIFICATIONS_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, GsdPrintNotificationsManagerPrivate))
+
+struct GsdPrintNotificationsManagerPrivate
+{
+ gboolean padding;
+};
+
+enum {
+ PROP_0,
+};
+
+static void gsd_print_notifications_manager_class_init (GsdPrintNotificationsManagerClass *klass);
+static void gsd_print_notifications_manager_init (GsdPrintNotificationsManager *print_notifications_manager);
+static void gsd_print_notifications_manager_finalize (GObject *object);
+
+G_DEFINE_TYPE (GsdPrintNotificationsManager, gsd_print_notifications_manager, G_TYPE_OBJECT)
+
+static gpointer manager_object = NULL;
+
+gboolean
+gsd_print_notifications_manager_start (GsdPrintNotificationsManager *manager,
+ GError **error)
+{
+ g_debug ("Starting print-notifications manager");
+
+ gnome_settings_profile_start (NULL);
+ gnome_settings_profile_end (NULL);
+ return TRUE;
+}
+
+void
+gsd_print_notifications_manager_stop (GsdPrintNotificationsManager *manager)
+{
+ g_debug ("Stopping print-notifications manager");
+}
+
+static void
+gsd_print_notifications_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GsdPrintNotificationsManager *self;
+
+ self = GSD_PRINT_NOTIFICATIONS_MANAGER (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gsd_print_notifications_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GsdPrintNotificationsManager *self;
+
+ self = GSD_PRINT_NOTIFICATIONS_MANAGER (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static GObject *
+gsd_print_notifications_manager_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_properties)
+{
+ GsdPrintNotificationsManager *print_notifications_manager;
+ GsdPrintNotificationsManagerClass *klass;
+
+ 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));
+
+ return G_OBJECT (print_notifications_manager);
+}
+
+static void
+gsd_print_notifications_manager_dispose (GObject *object)
+{
+ GsdPrintNotificationsManager *print_notifications_manager;
+
+ print_notifications_manager = GSD_PRINT_NOTIFICATIONS_MANAGER (object);
+
+ G_OBJECT_CLASS (gsd_print_notifications_manager_parent_class)->dispose (object);
+}
+
+static void
+gsd_print_notifications_manager_class_init (GsdPrintNotificationsManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = gsd_print_notifications_manager_get_property;
+ object_class->set_property = gsd_print_notifications_manager_set_property;
+ object_class->constructor = gsd_print_notifications_manager_constructor;
+ object_class->dispose = gsd_print_notifications_manager_dispose;
+ object_class->finalize = gsd_print_notifications_manager_finalize;
+
+ g_type_class_add_private (klass, sizeof (GsdPrintNotificationsManagerPrivate));
+}
+
+static void
+gsd_print_notifications_manager_init (GsdPrintNotificationsManager *manager)
+{
+ manager->priv = GSD_PRINT_NOTIFICATIONS_MANAGER_GET_PRIVATE (manager);
+
+}
+
+static void
+gsd_print_notifications_manager_finalize (GObject *object)
+{
+ GsdPrintNotificationsManager *print_notifications_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);
+
+ g_return_if_fail (print_notifications_manager->priv != NULL);
+
+ G_OBJECT_CLASS (gsd_print_notifications_manager_parent_class)->finalize (object);
+}
+
+GsdPrintNotificationsManager *
+gsd_print_notifications_manager_new (void)
+{
+ if (manager_object != NULL) {
+ g_object_ref (manager_object);
+ } else {
+ manager_object = g_object_new (GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, NULL);
+ g_object_add_weak_pointer (manager_object,
+ (gpointer *) &manager_object);
+ }
+
+ return GSD_PRINT_NOTIFICATIONS_MANAGER (manager_object);
+}
diff --git a/plugins/print-notifications/gsd-print-notifications-manager.h b/plugins/print-notifications/gsd-print-notifications-manager.h
new file mode 100644
index 0000000..0e58f0c
--- /dev/null
+++ b/plugins/print-notifications/gsd-print-notifications-manager.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_PRINT_NOTIFICATIONS_MANAGER_H
+#define __GSD_PRINT_NOTIFICATIONS_MANAGER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER (gsd_print_notifications_manager_get_type ())
+#define GSD_PRINT_NOTIFICATIONS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, GsdPrintNotificationsManager))
+#define GSD_PRINT_NOTIFICATIONS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, GsdPrintNotificationsManagerClass))
+#define GSD_IS_PRINT_NOTIFICATIONS_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER))
+#define GSD_IS_PRINT_NOTIFICATIONS_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER))
+#define GSD_PRINT_NOTIFICATIONS_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_PRINT_NOTIFICATIONS_MANAGER, GsdPrintNotificationsManagerClass))
+
+typedef struct GsdPrintNotificationsManagerPrivate GsdPrintNotificationsManagerPrivate;
+
+typedef struct
+{
+ GObject parent;
+ GsdPrintNotificationsManagerPrivate *priv;
+} GsdPrintNotificationsManager;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} GsdPrintNotificationsManagerClass;
+
+GType gsd_print_notifications_manager_get_type (void);
+
+GsdPrintNotificationsManager *gsd_print_notifications_manager_new (void);
+gboolean gsd_print_notifications_manager_start (GsdPrintNotificationsManager *manager,
+ GError **error);
+void gsd_print_notifications_manager_stop (GsdPrintNotificationsManager *manager);
+
+G_END_DECLS
+
+#endif /* __GSD_PRINT_NOTIFICATIONS_MANAGER_H */
diff --git a/plugins/print-notifications/gsd-print-notifications-plugin.c b/plugins/print-notifications/gsd-print-notifications-plugin.c
new file mode 100644
index 0000000..57c9c42
--- /dev/null
+++ b/plugins/print-notifications/gsd-print-notifications-plugin.c
@@ -0,0 +1,331 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#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)
+{
+ plugin->priv = GSD_PRINT_NOTIFICATIONS_PLUGIN_GET_PRIVATE (plugin);
+
+ plugin->priv->manager = gsd_print_notifications_manager_new ();
+}
+
+static void
+gsd_print_notifications_plugin_finalize (GObject *object)
+{
+ GsdPrintNotificationsPlugin *plugin;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GSD_IS_PRINT_NOTIFICATIONS_PLUGIN (object));
+
+ g_debug ("GsdPrintNotificationsPlugin finalizing");
+
+ plugin = GSD_PRINT_NOTIFICATIONS_PLUGIN (object);
+
+ g_return_if_fail (plugin->priv != NULL);
+
+ if (plugin->priv->manager != NULL) {
+ g_object_unref (plugin->priv->manager);
+ }
+
+ G_OBJECT_CLASS (gsd_print_notifications_plugin_parent_class)->finalize (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;
+
+ 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
+gsd_print_notifications_plugin_class_init (GsdPrintNotificationsPluginClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GnomeSettingsPluginClass *plugin_class = GNOME_SETTINGS_PLUGIN_CLASS (klass);
+
+ object_class->finalize = gsd_print_notifications_plugin_finalize;
+
+ plugin_class->activate = impl_activate;
+ plugin_class->deactivate = impl_deactivate;
+
+ g_type_class_add_private (klass, sizeof (GsdPrintNotificationsPluginPrivate));
+}
+
+static void
+gsd_print_notifications_plugin_class_finalize (GsdPrintNotificationsPluginClass *klass)
+{
+}
+
diff --git a/plugins/print-notifications/gsd-print-notifications-plugin.h b/plugins/print-notifications/gsd-print-notifications-plugin.h
new file mode 100644
index 0000000..c3e18e1
--- /dev/null
+++ b/plugins/print-notifications/gsd-print-notifications-plugin.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 William Jon McCann <mccann jhu edu>
+ *
+ * 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
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef __GSD_PRINT_NOTIFICATIONS_PLUGIN_H__
+#define __GSD_PRINT_NOTIFICATIONS_PLUGIN_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gmodule.h>
+
+#include "gnome-settings-plugin.h"
+
+G_BEGIN_DECLS
+
+#define GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN (gsd_print_notifications_plugin_get_type ())
+#define GSD_PRINT_NOTIFICATIONS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN, GsdPrintNotificationsPlugin))
+#define GSD_PRINT_NOTIFICATIONS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN, GsdPrintNotificationsPluginClass))
+#define GSD_IS_PRINT_NOTIFICATIONS_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN))
+#define GSD_IS_PRINT_NOTIFICATIONS_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN))
+#define GSD_PRINT_NOTIFICATIONS_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_PRINT_NOTIFICATIONS_PLUGIN, GsdPrintNotificationsPluginClass))
+
+typedef struct GsdPrintNotificationsPluginPrivate GsdPrintNotificationsPluginPrivate;
+
+typedef struct
+{
+ GnomeSettingsPlugin parent;
+ GsdPrintNotificationsPluginPrivate *priv;
+} GsdPrintNotificationsPlugin;
+
+typedef struct
+{
+ GnomeSettingsPluginClass parent_class;
+} GsdPrintNotificationsPluginClass;
+
+GType gsd_print_notifications_plugin_get_type (void) G_GNUC_CONST;
+
+/* All the plugins must implement this function */
+G_MODULE_EXPORT GType register_gnome_settings_plugin (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GSD_PRINT_NOTIFICATIONS_PLUGIN_H__ */
diff --git a/plugins/print-notifications/print-notifications.gnome-settings-plugin.in b/plugins/print-notifications/print-notifications.gnome-settings-plugin.in
new file mode 100644
index 0000000..f5f5aef
--- /dev/null
+++ b/plugins/print-notifications/print-notifications.gnome-settings-plugin.in
@@ -0,0 +1,8 @@
+[GNOME Settings Plugin]
+Module=print-notifications
+IAge=0
+_Name=Print-notifications
+_Description=Print-notifications plugin
+Authors=AUTHOR
+Copyright=Copyright © 2011 AUTHOR
+Website=
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]