Hello community,
here is the log from the commit of package gnome-cups-manager
checked in at Tue Dec 18 18:43:10 CET 2007.
--------
--- GNOME/gnome-cups-manager/gnome-cups-manager.changes 2007-11-30 18:50:33.000000000 +0100
+++ /mounts/work_src_done/STABLE/gnome-cups-manager/gnome-cups-manager.changes 2007-12-17 17:09:19.579984000 +0100
@@ -1,0 +2,7 @@
+Mon Dec 17 17:08:11 CET 2007 - crivera@suse.de
+
+- Add gnome-cups-manager-dbus-icon.patch. This patch uses CUPS
+ dbus signals to detect printer change instead of polling. This
+ fixes 345163.
+
+-------------------------------------------------------------------
New:
----
gnome-cups-manager-dbus-icon.patch
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ gnome-cups-manager.spec ++++++
--- /var/tmp/diff_new_pack.c21808/_old 2007-12-18 18:38:37.000000000 +0100
+++ /var/tmp/diff_new_pack.c21808/_new 2007-12-18 18:38:37.000000000 +0100
@@ -11,9 +11,9 @@
# norootforbuild
Name: gnome-cups-manager
-BuildRequires: cups cups-devel fdupes gcc-c++ gnome-common gnome-icon-theme gnutls-devel intltool krb5-devel libglade2-devel libgnomecups-devel libgnomeprintui-devel libgnomeui-devel libsmbclient libsmbclient-devel libwnck-devel mDNSResponder-devel perl-XML-Parser update-desktop-files
+BuildRequires: cups cups-devel dbus-1 dbus-1-glib fdupes gcc-c++ gnome-common gnome-icon-theme gnutls-devel intltool krb5-devel libglade2-devel libgnomecups-devel libgnomeprintui-devel libgnomeui-devel libsmbclient libsmbclient-devel libwnck-devel mDNSResponder-devel perl-XML-Parser update-desktop-files
Version: 0.32
-Release: 18
+Release: 22
Url: http://www.gnome.org/
Group: System/GUI/GNOME
License: GPL v2 only
@@ -28,6 +28,7 @@
Patch5: gnome-cups-manager-icon-callback.patch
Patch6: gnome-cups-manager-gcc4.3-fixes.patch
Patch7: gnome-cups-add-filter-printers.patch
+Patch8: gnome-cups-manager-dbus-icon.patch
AutoReqProv: on
Requires: gnome-icon-theme
Requires: %{name}-lang = %{version}
@@ -60,6 +61,7 @@
%patch5 -p1
%patch6 -p1
%patch7 -p1
+%patch8 -p1
%build
sed -i "s/\(ALL_LINGUAS.*\) no /\1 /" configure.in
@@ -110,6 +112,10 @@
%{_includedir}/libgnomecups-1/libgnomecups/*
%changelog
+* Mon Dec 17 2007 - crivera@suse.de
+- Add gnome-cups-manager-dbus-icon.patch. This patch uses CUPS
+ dbus signals to detect printer change instead of polling. This
+ fixes 345163.
* Fri Nov 30 2007 - crivera@suse.de
- Remove duplicate printers from the detected list, if possible.
This fixes 215490.
++++++ gnome-cups-manager-dbus-icon.patch ++++++
diff -ur /usr/src/packages/BUILD/gnome-cups-manager-0.32/configure.in ./configure.in
--- /usr/src/packages/BUILD/gnome-cups-manager-0.32/configure.in 2007-12-14 04:51:57.000000000 -0500
+++ ./configure.in 2007-12-06 13:25:51.000000000 -0500
@@ -42,6 +42,8 @@
libbonobo-2.0 >= $LIBBONOBO_REQUIRED
libgnomecups-1.0 >= $LIBGNOMECUPS_REQUIRED
gnome-keyring-1
+dbus-1
+dbus-glib-1
])
AC_SUBST(GNOME_CFLAGS)
AC_SUBST(GNOME_LIBS)
diff -ur /usr/src/packages/BUILD/gnome-cups-manager-0.32/gnome-cups-manager/gnome-cups-icon.c ./gnome-cups-manager/gnome-cups-icon.c
--- /usr/src/packages/BUILD/gnome-cups-manager-0.32/gnome-cups-manager/gnome-cups-icon.c 2007-09-27 09:24:03.000000000 -0400
+++ ./gnome-cups-manager/gnome-cups-icon.c 2007-12-14 04:51:50.000000000 -0500
@@ -1,148 +1,373 @@
#include
+#include
+#include
#include
+#include
+#include
+#include
+
+#include
+#include
+
+#include
+#include
+#include
+
+static GHashTable *printer_hash;
+static GAsyncQueue *queue;
+static http_t *global_cups_connection;
+static const gchar *user_name;
+
+typedef enum {
+ LAUNCH_TYPE_JOBS,
+ LAUNCH_TYPE_MANAGER,
+ LAUNCH_TYPE_PROPERTIES
+} LaunchType;
+
+typedef struct {
+ gchar *name;
+ GtkStatusIcon *icon;
+ GtkWidget *menu;
+} CupsPrinter;
+
+typedef struct {
+ gchar *name;
+ int job_count;
+} JobData;
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "view-queue.h"
-#include "printer-properties.h"
-#include "tray.h"
-
-#include
-#include
-#include
-#include
-#include
-
-static void
-die_cb (GnomeClient *client, gpointer data)
-{
- gtk_main_quit ();
-}
-
-static void
-add_to_session (void)
-{
- GnomeClient *client;
-
- client = gnome_master_client ();
-
- gnome_client_set_priority (client, 50);
-
- gnome_client_set_restart_style (client, GNOME_RESTART_IMMEDIATELY);
-
- g_signal_connect (client, "die", G_CALLBACK (die_cb), NULL);
-}
-
-static void
-remove_from_session (void)
-{
- GnomeClient *client;
-
- client = gnome_master_client ();
-
- gnome_client_set_restart_style (client, GNOME_RESTART_NEVER);
-}
-
-static gboolean
-check_cups_again (gpointer user_data)
-{
- static int tries = 0;
-
- if (gnome_cups_check_daemon ()) {
- gnome_cups_manager_start_icon ();
- return FALSE;
- } else {
- if (++tries == 3) {
- GtkWidget *dialog;
- /* FIXME: dialog text */
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Could not start the printer tray icon, because the CUPS server could not be contacted."));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-
- remove_from_session ();
-
- gtk_main_quit ();
- }
-
- }
-
- return TRUE;
-}
-
-static void
-check_cups (void)
-{
- if (gnome_cups_check_daemon ()) {
- gnome_cups_manager_start_icon ();
- } else {
- g_timeout_add (30000, check_cups_again, NULL);
- }
-}
-
-static void
-event_cb (BonoboListener *listener, const char *event_name,
- const BonoboArg *arg, CORBA_Environment *ev,
- gpointer user_data)
-{
-}
-
-static gboolean
-already_running (void)
-{
- BonoboListener *listener;
- Bonobo_RegistrationResult reg_result;
-
- listener = bonobo_listener_new (event_cb, NULL);
-
- reg_result = bonobo_activation_register_active_server ("OAFIID:gnome-cups-icon",
- BONOBO_OBJREF (listener), NULL);
-
- if (reg_result == Bonobo_ACTIVATION_REG_SUCCESS) {
- return FALSE;
- } else {
- bonobo_object_unref (listener);
- return TRUE;
- }
-}
-
-int
-main (int argc, char *argv[])
-{
- gnome_program_init ("gnome-cups-icon",
- VERSION,
- LIBGNOMEUI_MODULE, argc, argv,
- GNOME_PROGRAM_STANDARD_PROPERTIES,
- GNOME_PARAM_HUMAN_READABLE_NAME, _("Print Monitor"),
- NULL);
+static void launch_manager (char *printer_name, LaunchType type)
+{
+ if (type == LAUNCH_TYPE_JOBS) {
+ char *argv[] = { "gnome-cups-manager", "-v", printer_name, NULL };
+ g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+ } else if (type == LAUNCH_TYPE_PROPERTIES) {
+ char *argv[] = { "gnome-cups-manager", "-p", printer_name, NULL };
+ g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+ } else {
+ char *argv[] = { "gnome-cups-manager", NULL };
+ g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
+ }
+}
+
+static void jobs_clicked_cb (GObject *object, gpointer user_data)
+{
+ launch_manager ((char *) g_object_get_data (object, "printer_name"), LAUNCH_TYPE_JOBS);
+}
+
+static void properties_clicked_cb (GObject *object, gpointer user_data)
+{
+ launch_manager ((char *) g_object_get_data (object, "printer_name"), LAUNCH_TYPE_PROPERTIES);
+}
+
+static void manager_clicked_cb (GObject *object, gpointer user_data)
+{
+ launch_manager (NULL, LAUNCH_TYPE_MANAGER);
+}
+
+static void icon_popup_menu (GtkStatusIcon *icon, guint button, guint activate_time, gpointer user_data)
+{
+ GtkMenu *menu = (GtkMenu *) g_object_get_data (G_OBJECT (icon), "printer_menu");
+ gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+ gtk_status_icon_position_menu,
+ GTK_STATUS_ICON (icon), button, activate_time);
+}
+
+static GtkWidget *create_menu (char *printer_name)
+{
+ GtkWidget *item;
+ GtkWidget *menu = gtk_menu_new ();
+
+ item = gtk_image_menu_item_new_with_label ("Jobs");
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+ gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_FILL, GTK_ICON_SIZE_MENU));
+ g_object_set_data (G_OBJECT (item), "printer_name", printer_name);
+ g_signal_connect (item, "activate", G_CALLBACK (jobs_clicked_cb), NULL);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL(menu), item);
+
+ item = gtk_image_menu_item_new_with_label ("Manager");
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+ gtk_image_new_from_stock (GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
+ g_signal_connect (item, "activate", G_CALLBACK (manager_clicked_cb), NULL);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ item = gtk_image_menu_item_new_with_label ("Properties");
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
+ gtk_image_new_from_stock (GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
+ g_object_set_data (G_OBJECT (item), "printer_name", printer_name);
+ g_signal_connect (item, "activate", G_CALLBACK (properties_clicked_cb), NULL);
+ gtk_widget_show (item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ return menu;
+}
+
+static gboolean update_printer_icon (gpointer data)
+{
+ JobData *jd = data;
+ CupsPrinter *cp = g_hash_table_lookup (printer_hash, jd->name);
+ g_print ("Printer '%s' has %d jobs for %s\n", jd->name, jd->job_count, user_name);
+
+ if (jd->job_count && !cp) {
+ gchar *tt = g_strdup_printf ("%s has %d job(s) pending for %s",
+ jd->name, jd->job_count, user_name);
+ GtkStatusIcon *icon = gtk_status_icon_new_from_file (GNOME_CUPS_MANAGER_PIXMAPDIR
+ "/printer-tray-normal.png");
+ gtk_status_icon_set_tooltip (icon, tt);
+ g_free (tt);
+
+ g_signal_connect (icon, "popup-menu", G_CALLBACK (icon_popup_menu), NULL);
+
+ cp = g_new (CupsPrinter, 1);
+ cp->name = jd->name;
+ cp->icon = icon;
+ cp->menu = create_menu (cp->name);
+
+ g_object_set_data (G_OBJECT (cp->icon), "printer_menu", cp->menu);
+ g_hash_table_insert (printer_hash, cp->name, cp);
+ } else if (!jd->job_count && cp) {
+ g_free (cp->name);
+ g_object_unref (cp->icon);
+ gtk_widget_destroy (GTK_WIDGET (cp->menu));
+ g_free (cp);
+ g_hash_table_remove (printer_hash, jd->name);
+ } else {
+ g_free (jd->name);
+ }
+
+ g_free (jd);
+ return FALSE;
+}
+
+static gpointer watch_printer_jobs (gpointer user_data)
+{
+ g_async_queue_ref (queue);
+
+ while (TRUE) {
+ ipp_t *request, *response;
+ ipp_attribute_t *attr;
+ gchar *printer_uri, *printer_name;
+ JobData *jd;
+ int job_count = 0;
+
+ printer_name = (char *) g_async_queue_pop (queue);
+
+ request = ippNewRequest (IPP_GET_JOBS);
+ printer_uri = g_strconcat ("ipp://localhost/printers/", printer_name, NULL);
+ ippAddString (request, IPP_TAG_OPERATION, IPP_TAG_URI,
+ "job-uri", NULL, printer_uri);
+ response = cupsDoRequest (global_cups_connection, request, "/");
+ if (!response || response->request.status.status_code > IPP_OK_CONFLICT) {
+ g_printerr ("Failed to get the list of jobs from cupsd\n");
+ return FALSE;
+ }
+
+ /* We only coun't jobs for the user we're running as submitted from the localhost */
+ for (attr = response->attrs; attr; attr = attr->next) {
+ gboolean user_job = TRUE;
+
+ while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
+ attr = attr->next;
+
+ if (!attr)
+ break;
+
+ for (; attr && attr->group_tag == IPP_TAG_JOB; attr = attr->next) {
+ if (!strcmp (attr->name, "job-printer-uri") && attr->value_tag == IPP_TAG_URI) {
+ g_print ("job uri is %s\n", attr->values[0].string.text);
+ } else if (!strcmp (attr->name, "job-originating-user-name") &&
+ strcmp (attr->values[0].string.text, user_name)) {
+ user_job = FALSE;
+ g_print ("job user name is %s, skipping\n", attr->values[0].string.text);
+ } else if (!strcmp (attr->name, "job-originating-host-name")) {
+ char hn[512];
+
+ if (gethostname (hn, 512))
+ hn[0] = '\0';
+
+ if (strcmp (attr->values[0].string.text, "localhost") &&
+ strcmp (attr->values[0].string.text, hn)) {
+ g_print ("job submitted from %s, but hostname is %s\n",
+ attr->values[0].string.text, hn);
+ user_job = FALSE;
+ }
+ }
+ }
+
+ if (user_job)
+ job_count++;
+
+ if (!attr)
+ break;
+ }
+
+ jd = g_new0 (JobData, 1);
+ jd->name = printer_name;
+ jd->job_count = job_count;
+ g_idle_add (update_printer_icon, jd);
+ ippDelete (response);
+ }
+
+ return NULL;
+}
+
+static gboolean check_cups_printers (void)
+{
+ ipp_t *request, *response;
+ ipp_attribute_t *attr;
+
+ request = ippNewRequest (CUPS_GET_PRINTERS);
+ response = cupsDoRequest (global_cups_connection, request, "/");
+ if (!response || response->request.status.status_code > IPP_OK_CONFLICT) {
+ g_printerr ("Failed to get the list of printers from cupsd\n");
+ return FALSE;
+ }
+
+ for (attr = response->attrs; attr; attr = attr->next) {
+ while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
+ attr = attr->next;
+
+ if (!attr)
+ break;
+
+ for (; attr && attr->group_tag == IPP_TAG_PRINTER; attr = attr->next) {
+ if (!strncmp (attr->name, "printer-name", 12) && attr->value_tag == IPP_TAG_NAME) {
+ g_async_queue_push (queue, g_strdup (attr->values[0].string.text));
+ }
+ }
+
+ if (!attr)
+ break;
+ }
+
+ ippDelete (response);
+ return TRUE;
+}
+
+static DBusHandlerResult message_filter (DBusConnection *c, DBusMessage *m, void *user_data)
+{
+ DBusMessageIter iter;
+ char *printer_name = NULL;
+
+ g_print ("MSG: %s %s %s\n", dbus_message_get_path (m), dbus_message_get_interface (m), dbus_message_get_member (m));
+
+ if (dbus_message_iter_init (m, &iter) == FALSE ||
+ strcmp (dbus_message_get_interface (m), "com.redhat.PrinterSpooler") ||
+ dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ dbus_message_iter_get_basic (&iter, &printer_name);
+ g_async_queue_push (queue, g_strdup (printer_name));
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static gboolean cups_connect (void)
+{
+ global_cups_connection = httpConnectEncrypt (cupsServer (), ippPort (), cupsEncryption ());
+ if (!global_cups_connection) {
+ g_printerr ("Failed to connect to cupsd\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void cups_disconnect (void)
+{
+ if (global_cups_connection)
+ httpClose (global_cups_connection);
+}
+
+int main (int argc, char *argv[])
+{
+ DBusGConnection *system_conn, *session_conn;
+ DBusGProxy *proxy;
+ DBusError error;
+ GError *err = NULL;
+ int retval = 1;
+ guint request_result;
+ gboolean ret;
+
+ g_thread_init (NULL);
+ gtk_init (&argc, &argv);
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- bonobo_init (&argc, argv);
- bonobo_activate ();
-
- if (!already_running ()) {
- gnome_cups_ui_init (argv[0]);
-
- check_cups ();
- add_to_session ();
- gtk_main ();
- }
-
- return 0;
+ system_conn = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err);
+ if (!system_conn) {
+ g_printerr ("Failed to connect to system bus: %s\n", err->message);
+ g_error_free (err);
+ exit (EXIT_FAILURE);
+ }
+
+ session_conn = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
+ if (!session_conn) {
+ g_printerr ("Failed to connect to session bus: %s\n", err->message);
+ g_error_free (err);
+ dbus_g_connection_unref (system_conn);
+ exit (EXIT_FAILURE);
+ }
+
+ proxy = dbus_g_proxy_new_for_name (session_conn,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS);
+
+ ret = dbus_g_proxy_call (proxy, "RequestName", NULL,
+ G_TYPE_STRING, "org.gnome.GnomeCupsIcon",
+ G_TYPE_UINT, 0,
+ G_TYPE_INVALID,
+ G_TYPE_UINT, &request_result,
+ G_TYPE_INVALID);
+ if (!ret) {
+ g_printerr ("Failed to get name on the session bus\n");
+ goto done;
+ }
+
+ if (request_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+ g_print ("An instance is already running\n");
+ retval = 0;
+ goto done;
+ }
+
+ if (!dbus_connection_add_filter (dbus_g_connection_get_connection (system_conn),
+ message_filter, NULL, NULL)) {
+ g_printerr ("Failed to register DBUS filter function\n");
+ goto done;
+ }
+
+ dbus_error_init (&error);
+ dbus_bus_add_match (dbus_g_connection_get_connection (system_conn),
+ "type=signal,interface=com.redhat.PrinterSpooler", &error);
+ if (dbus_error_is_set (&error)) {
+ g_printerr ("Failed to add match rule\n");
+ dbus_error_free (&error);
+ goto done;
+ }
+
+ if (!cups_connect ()) {
+ g_printerr ("Failed to connect to cupsd\n");
+ goto done;
+ }
+
+ queue = g_async_queue_new ();
+ printer_hash = g_hash_table_new (g_str_hash, g_str_equal);
+ user_name = g_get_user_name ();
+
+ check_cups_printers ();
+ g_thread_create (watch_printer_jobs, NULL, FALSE, NULL);
+
+ gtk_main ();
+
+ cups_disconnect ();
+ retval = 0;
+
+done:
+ dbus_g_connection_unref (system_conn);
+ dbus_g_connection_unref (session_conn);
+ return retval;
}
diff -ur /usr/src/packages/BUILD/gnome-cups-manager-0.32/gnome-cups-manager/Makefile.am ./gnome-cups-manager/Makefile.am
--- /usr/src/packages/BUILD/gnome-cups-manager-0.32/gnome-cups-manager/Makefile.am 2007-09-27 09:24:03.000000000 -0400
+++ ./gnome-cups-manager/Makefile.am 2007-12-07 13:56:59.000000000 -0500
@@ -34,10 +34,7 @@
eggtrayicon.h
gnome_cups_icon_SOURCES= \
- $(cut_and_paste_sources) \
- gnome-cups-icon.c \
- tray.c \
- tray.h
+ gnome-cups-icon.c
gnome_cups_manager_SOURCES = \
$(BUILT_SOURCES) \
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org