diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-16 21:18:56 +0100 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2012-02-16 21:18:56 +0100 |
commit | ba27629c4519fa09da8cbfaffe2dcff003fcfef0 (patch) | |
tree | 67aa7e8ecbb19c0c0dd4f5b1e2ea3e003684c0cd /src/indicator-printers-service.c | |
parent | 1204ca2827e64aa041b4bd36813be3d70db54802 (diff) | |
parent | 8ce897a37ffe58051684fba7478a2f076aeec57d (diff) | |
download | ayatana-indicator-printers-ba27629c4519fa09da8cbfaffe2dcff003fcfef0.tar.gz ayatana-indicator-printers-ba27629c4519fa09da8cbfaffe2dcff003fcfef0.tar.bz2 ayatana-indicator-printers-ba27629c4519fa09da8cbfaffe2dcff003fcfef0.zip |
* New upstream release.
- prepare for i18n
- make sure CUPS' dbus notification is on while the service is running
- fix build system to enable out-of-tree builds
* debian/control
- bump libindicator dependency 0.3.91
Diffstat (limited to 'src/indicator-printers-service.c')
-rw-r--r-- | src/indicator-printers-service.c | 73 |
1 files changed, 72 insertions, 1 deletions
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 <libindicator/indicator-service.h> #include <libdbusmenu-glib/dbusmenu-glib.h> #include <gtk/gtk.h> +#include <cups/cups.h> #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, |