From da8f22976088f5272d72dc0383bb36b2f88a1f9c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 16 Feb 2012 17:36:05 +0100 Subject: Mark strings translatable --- src/indicator-printer-state-notifier.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/indicator-printer-state-notifier.c b/src/indicator-printer-state-notifier.c index d3668a2..8261274 100644 --- a/src/indicator-printer-state-notifier.c +++ b/src/indicator-printer-state-notifier.c @@ -18,6 +18,7 @@ #include "indicator-printer-state-notifier.h" +#include #include #include #include @@ -125,13 +126,13 @@ show_alert_box (const gchar *printer, primary_text = g_strdup_printf (reason, printer); if (njobs == 1) - fmt = "You have %d job queued to print on this printer."; + fmt = _("You have %d job queued to print on this printer."); else - fmt = "You have %d jobs queued to print on this printer."; + fmt = _("You have %d jobs queued to print on this printer."); secondary_text = g_strdup_printf (fmt, njobs); dialog = g_object_new (GTK_TYPE_MESSAGE_DIALOG, - "title", "Printing Problem", + "title", _("Printing Problem"), "icon-name", "printer", "image", image, "text", primary_text, @@ -147,7 +148,7 @@ show_alert_box (const gchar *printer, g_free (secondary_text); gtk_dialog_add_buttons (GTK_DIALOG (dialog), - "_Settings…", RESPONSE_SHOW_SYSTEM_SETTINGS, + _("_Settings…"), RESPONSE_SHOW_SYSTEM_SETTINGS, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), @@ -313,14 +314,14 @@ indicator_printer_state_notifier_init (IndicatorPrinterStateNotifier *self) priv->printer_alerts = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert_many ( priv->printer_alerts, - "media-low", "The printer “%s” is low on paper.", - "media-empty", "The printer “%s” is out of paper.", - "toner-low", "The printer “%s” is low on toner.", - "toner-empty", "The printer “%s” is out of toner.", - "cover-open", "A cover is open on the printer “%s”.", - "door-open", "A door is open on the printer “%s”.", - "cups-missing-filter", "The printer “%s” can’t be used, because required software is missing.", - "offline", "The printer “%s” is currently off-line.", + "media-low", _("The printer “%s” is low on paper."), + "media-empty", _("The printer “%s” is out of paper."), + "toner-low", _("The printer “%s” is low on toner."), + "toner-empty", _("The printer “%s” is out of toner."), + "cover-open", _("A cover is open on the printer “%s”."), + "door-open", _("A door is open on the printer “%s”."), + "cups-missing-filter", _("The printer “%s” can’t be used, because required software is missing."), + "offline", _("The printer “%s” is currently off-line."), NULL); } -- cgit v1.2.3 From e76730160da068ce4a358297ac171f0dd656f69c Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 16 Feb 2012 18:33:05 +0100 Subject: Make sure CUPS' dbus notification is on while the service is running --- src/indicator-printers-service.c | 73 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-printers-service.c b/src/indicator-printers-service.c index 58644ab..5daf697 100644 --- a/src/indicator-printers-service.c +++ b/src/indicator-printers-service.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "dbus-names.h" #include "cups-notifier.h" @@ -26,10 +27,77 @@ #include "indicator-printer-state-notifier.h" +static int +create_subscription () +{ + ipp_t *req; + ipp_t *resp; + ipp_attribute_t *attr; + int id = 0; + + req = ippNewRequest (IPP_CREATE_PRINTER_SUBSCRIPTION); + ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI, + "printer-uri", NULL, "/"); + ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD, + "notify-events", NULL, "all"); + ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI, + "notify-recipient-uri", NULL, "dbus://"); + ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER, + "notify-lease-duration", 0); + + resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/"); + if (!resp || cupsLastError() != IPP_OK) { + g_warning ("Error subscribing to CUPS notifications: %s\n", + cupsLastErrorString ()); + return 0; + } + + attr = ippFindAttribute (resp, "notify-subscription-id", IPP_TAG_INTEGER); + if (attr) + id = attr->values[0].integer; + else + g_warning ("ipp-create-printer-subscription response doesn't contain " + "subscription id.\n"); + + ippDelete (resp); + return id; +} + + +void +cancel_subscription (int id) +{ + ipp_t *req; + ipp_t *resp; + + if (id <= 0) + return; + + req = ippNewRequest (IPP_CANCEL_SUBSCRIPTION); + ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI, + "printer-uri", NULL, "/"); + ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER, + "notify-subscription-id", id); + + resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/"); + if (!resp || cupsLastError() != IPP_OK) { + g_warning ("Error subscribing to CUPS notifications: %s\n", + cupsLastErrorString ()); + return; + } + + ippDelete (resp); +} + + static void service_shutdown (IndicatorService *service, gpointer user_data) { + int subscription_id = GPOINTER_TO_INT (user_data); + g_debug("Shutting down indicator-printers-service"); + + cancel_subscription (subscription_id); gtk_main_quit (); } @@ -42,15 +110,18 @@ int main (int argc, char *argv[]) IndicatorPrintersMenu *menu; IndicatorPrinterStateNotifier *state_notifier; GError *error = NULL; + int subscription_id; gtk_init (&argc, &argv); + subscription_id = create_subscription (); + service = indicator_service_new_version (INDICATOR_PRINTERS_DBUS_NAME, INDICATOR_PRINTERS_DBUS_VERSION); g_signal_connect (service, "shutdown", G_CALLBACK (service_shutdown), - NULL); + GINT_TO_POINTER (subscription_id)); cups_notifier = cups_notifier_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, 0, -- cgit v1.2.3 From 5f29b2a3e4b1744596defea708a7f717d737be53 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 16 Feb 2012 19:28:10 +0100 Subject: Also generate cups-notifier in the text directory --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index bedc091..2c87ad0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,7 +17,7 @@ cups_notifier_sources = \ cups-notifier.c \ cups-notifier.h -$(cups_notifier_sources): $(top_srcdir)/src/org.cups.cupsd.Notifier.xml +$(cups_notifier_sources): org.cups.cupsd.Notifier.xml gdbus-codegen \ --interface-prefix org.cups.cupsd \ --c-namespace Cups \ -- cgit v1.2.3 From 5b0b1ba9bc75e2a3a653c78889d67c705f617849 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 16 Feb 2012 19:45:24 +0100 Subject: Don't distribute generated sources and delete them on `make clean` --- src/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 2c87ad0..6e10cb9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,13 +34,15 @@ indicator_printers_service_SOURCES = \ indicator-printer-state-notifier.h \ spawn-printer-settings.c \ spawn-printer-settings.h \ - dbus-names.h \ - $(cups_notifier_sources) + dbus-names.h + +nodist_indicator_printers_service_SOURCES = $(cups_notifier_sources) indicator_printers_service_CPPFLAGS = $(SERVICE_CFLAGS) indicator_printers_service_LDADD = $(SERVICE_LIBS) BUILT_SOURCES = $(cups_notifier_sources) +CLEANFILES= $(BUILT_SOURCES) EXTRA_DIST = org.cups.cupsd.Notifier.xml -- cgit v1.2.3