~ubuntu-branches/ubuntu/trusty/indicator-printers/trusty

« back to all changes in this revision

Viewing changes to src/indicator-printers-service.c

  • Committer: Package Import Robot
  • Author(s): Lars Uebernickel
  • Date: 2012-03-20 18:50:39 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120320185039-wexgpfwq9waruv2o
Tags: 0.1.5-0ubuntu1
* New upstream release.
  - translate accessible description (LP: #957522)
  - set lease durations on cups subscriptions (LP: #959195)
  - draw number of jobs as lozenge

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "indicator-printers-menu.h"
27
27
#include "indicator-printer-state-notifier.h"
28
28
 
 
29
#define NOTIFY_LEASE_DURATION (15 * 60)
 
30
 
29
31
 
30
32
static int
31
33
create_subscription ()
43
45
    ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
44
46
                  "notify-recipient-uri", NULL, "dbus://");
45
47
    ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
46
 
                   "notify-lease-duration", 0);
 
48
                   "notify-lease-duration", NOTIFY_LEASE_DURATION);
47
49
 
48
50
    resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
49
51
    if (!resp || cupsLastError() != IPP_OK) {
64
66
}
65
67
 
66
68
 
 
69
static gboolean
 
70
renew_subscription (int id)
 
71
{
 
72
    ipp_t *req;
 
73
    ipp_t *resp;
 
74
 
 
75
    req = ippNewRequest (IPP_RENEW_SUBSCRIPTION);
 
76
    ippAddInteger (req, IPP_TAG_OPERATION, IPP_TAG_INTEGER,
 
77
                   "notify-subscription-id", id);
 
78
    ippAddString (req, IPP_TAG_OPERATION, IPP_TAG_URI,
 
79
                  "printer-uri", NULL, "/");
 
80
    ippAddString (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
 
81
                  "notify-recipient-uri", NULL, "dbus://");
 
82
    ippAddInteger (req, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
 
83
                   "notify-lease-duration", NOTIFY_LEASE_DURATION);
 
84
 
 
85
    resp = cupsDoRequest (CUPS_HTTP_DEFAULT, req, "/");
 
86
    if (!resp || cupsLastError() != IPP_OK) {
 
87
        g_warning ("Error renewing CUPS subscription %d: %s\n",
 
88
                   id, cupsLastErrorString ());
 
89
        return FALSE;
 
90
    }
 
91
 
 
92
    ippDelete (resp);
 
93
    return TRUE;
 
94
}
 
95
 
 
96
 
 
97
static gboolean
 
98
renew_subscription_timeout (gpointer userdata)
 
99
{
 
100
    int *subscription_id = userdata;
 
101
 
 
102
    if (*subscription_id <= 0 || !renew_subscription (*subscription_id))
 
103
        *subscription_id = create_subscription ();
 
104
 
 
105
    return TRUE;
 
106
}
 
107
 
 
108
 
67
109
void
68
110
cancel_subscription (int id)
69
111
{
115
157
    gtk_init (&argc, &argv);
116
158
 
117
159
    subscription_id = create_subscription ();
 
160
    g_timeout_add_seconds (NOTIFY_LEASE_DURATION - 60,
 
161
                           renew_subscription_timeout,
 
162
                           &subscription_id);
118
163
 
119
164
    service = indicator_service_new_version (INDICATOR_PRINTERS_DBUS_NAME,
120
165
                                             INDICATOR_PRINTERS_DBUS_VERSION);