aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-02-09 22:27:06 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-02-09 22:27:06 +0100
commita796e6d7df042dacb147dbf4dc31df1909f0cc41 (patch)
tree1e777f988f908828e7d8578103b5f7a709d59c64 /src
parent28e4c27cdb3827988a55e57ac1c97a1da2778029 (diff)
downloadayatana-indicator-printers-a796e6d7df042dacb147dbf4dc31df1909f0cc41.tar.gz
ayatana-indicator-printers-a796e6d7df042dacb147dbf4dc31df1909f0cc41.tar.bz2
ayatana-indicator-printers-a796e6d7df042dacb147dbf4dc31df1909f0cc41.zip
Don't show errors from non-existing printers
Of course, this shouldn't ever happen in practice.
Diffstat (limited to 'src')
-rw-r--r--src/indicator-printer-state-notifier.c4
-rw-r--r--src/indicator-printers-menu.c41
2 files changed, 16 insertions, 29 deletions
diff --git a/src/indicator-printer-state-notifier.c b/src/indicator-printer-state-notifier.c
index 751137a..122c800 100644
--- a/src/indicator-printer-state-notifier.c
+++ b/src/indicator-printer-state-notifier.c
@@ -162,8 +162,8 @@ on_printer_state_changed (CupsNotifier *object,
cupsFreeJobs (njobs, jobs);
/* don't show any events if the current user does not have jobs queued on
- * that printer */
- if (njobs == 0)
+ * that printer or this printer is unknown to CUPS */
+ if (njobs <= 0)
return;
state_reasons = g_strsplit (printer_state_reasons, " ", 0);
diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c
index 1548610..58bd72a 100644
--- a/src/indicator-printers-menu.c
+++ b/src/indicator-printers-menu.c
@@ -102,19 +102,6 @@ indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass)
}
-static int
-get_number_of_active_jobs (const gchar *printer)
-{
- int njobs;
- cups_job_t *jobs;
-
- njobs = cupsGetJobs (&jobs, printer, 1, CUPS_WHICHJOBS_ACTIVE);
- cupsFreeJobs (njobs, jobs);
-
- return njobs;
-}
-
-
static void
spawn_command_line_async_f (const gchar *fmt,
...)
@@ -153,10 +140,19 @@ on_printer_item_activated (DbusmenuMenuitem *menuitem,
static void
update_printer_menuitem (IndicatorPrintersMenu *self,
const char *printer,
- int state,
- int njobs)
+ int state)
{
DbusmenuMenuitem *item;
+ int njobs;
+ cups_job_t *jobs;
+
+ njobs = cupsGetJobs (&jobs, printer, 1, CUPS_WHICHJOBS_ACTIVE);
+ cupsFreeJobs (njobs, jobs);
+
+ if (njobs < 0) {
+ g_warning ("printer '%s' does not exist\n", printer);
+ return;
+ }
item = g_hash_table_lookup (self->priv->printers, printer);
@@ -214,10 +210,7 @@ update_job (CupsNotifier *cups_notifier,
{
IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
- update_printer_menuitem (self,
- printer_name,
- printer_state,
- get_number_of_active_jobs (printer_name));
+ update_printer_menuitem (self, printer_name, printer_state);
}
@@ -233,10 +226,7 @@ on_printer_state_changed (CupsNotifier *object,
{
IndicatorPrintersMenu *self = INDICATOR_PRINTERS_MENU (user_data);
- update_printer_menuitem (self,
- printer_name,
- printer_state,
- get_number_of_active_jobs (printer_name));
+ update_printer_menuitem (self, printer_name, printer_state);
}
@@ -263,10 +253,7 @@ indicator_printers_menu_init (IndicatorPrintersMenu *self)
int state = atoi (cupsGetOption ("printer-state",
dests[i].num_options,
dests[i].options));
- update_printer_menuitem (self,
- dests[i].name,
- state,
- get_number_of_active_jobs (dests[i].name));
+ update_printer_menuitem (self, dests[i].name, state);
}
cupsFreeDests (ndests, dests);
}