From 918a2b8d3f34b5d0a9fee974c191ec2a40e3cebc Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Sun, 12 Feb 2012 14:58:57 +0100 Subject: Show printer settings when "Settings..." is clicked on an alert dialog --- src/Makefile.am | 2 ++ src/indicator-printer-state-notifier.c | 4 +++- src/indicator-printers-menu.c | 29 +++------------------------- src/spawn-printer-settings.c | 35 ++++++++++++++++++++++++++++++++++ src/spawn-printer-settings.h | 11 +++++++++++ 5 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 src/spawn-printer-settings.c create mode 100644 src/spawn-printer-settings.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 0e4a874..26e2f6f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,8 @@ indicator_printers_service_SOURCES = \ indicator-printers-menu.h \ indicator-printer-state-notifier.c \ indicator-printer-state-notifier.h \ + spawn-printer-settings.c \ + spawn-printer-settings.h \ $(cups_notifier_sources) indicator_printers_service_CPPFLAGS = $(SERVICE_CFLAGS) diff --git a/src/indicator-printer-state-notifier.c b/src/indicator-printer-state-notifier.c index 7d8ce03..b0c19e5 100644 --- a/src/indicator-printer-state-notifier.c +++ b/src/indicator-printer-state-notifier.c @@ -24,6 +24,7 @@ #include #include "cups-notifier.h" +#include "spawn-printer-settings.h" #define RESPONSE_SHOW_SYSTEM_SETTINGS 1 @@ -153,7 +154,8 @@ show_alert_box (const gchar *printer, GTK_RESPONSE_OK); gtk_widget_show_all (dialog); - gtk_dialog_run (GTK_DIALOG (dialog)); + if (gtk_dialog_run (GTK_DIALOG (dialog)) == RESPONSE_SHOW_SYSTEM_SETTINGS) + spawn_printer_settings_with_args ("show-printer %s", printer); gtk_widget_destroy (dialog); } diff --git a/src/indicator-printers-menu.c b/src/indicator-printers-menu.c index a558c20..eb88f97 100644 --- a/src/indicator-printers-menu.c +++ b/src/indicator-printers-menu.c @@ -20,6 +20,8 @@ #include +#include "spawn-printer-settings.h" + G_DEFINE_TYPE (IndicatorPrintersMenu, indicator_printers_menu, G_TYPE_OBJECT) @@ -119,38 +121,13 @@ indicator_printers_menu_class_init (IndicatorPrintersMenuClass *klass) } -static void -spawn_command_line_async_f (const gchar *fmt, - ...) -{ - va_list args; - gchar *cmdline; - GError *err = NULL; - - va_start (args, fmt); - cmdline = g_strdup_vprintf (fmt, args); - va_end (args); - - g_spawn_command_line_async (cmdline, &err); - if (err) { - g_warning ("Couldn't execute command `%s`: %s", - cmdline, err->message); - g_error_free (err); - } - - g_free (cmdline); -} - - static void on_printer_item_activated (DbusmenuMenuitem *menuitem, guint timestamp, gpointer user_data) { const gchar *printer = user_data; - - spawn_command_line_async_f ("gnome-control-center printers show-printer %s", - printer); + spawn_printer_settings_with_args ("show-printer %s", printer); } diff --git a/src/spawn-printer-settings.c b/src/spawn-printer-settings.c new file mode 100644 index 0000000..bf1893d --- /dev/null +++ b/src/spawn-printer-settings.c @@ -0,0 +1,35 @@ + +#include "spawn-printer-settings.h" + +void +spawn_printer_settings () +{ + spawn_printer_settings_with_args (NULL); +} + + +void +spawn_printer_settings_with_args (const gchar *fmt, + ...) +{ + GString *cmdline; + GError *err = NULL; + + cmdline = g_string_new ("gnome-control-center printers "); + + if (fmt) { + va_list args; + va_start (args, fmt); + g_string_append_vprintf (cmdline, fmt, args); + va_end (args); + } + + g_spawn_command_line_async (cmdline->str, &err); + if (err) { + g_warning ("Could not spawn printer settings: %s", err->message); + g_error_free (err); + } + + g_string_free (cmdline, TRUE); +} + diff --git a/src/spawn-printer-settings.h b/src/spawn-printer-settings.h new file mode 100644 index 0000000..7f30406 --- /dev/null +++ b/src/spawn-printer-settings.h @@ -0,0 +1,11 @@ + +#ifndef SPAWN_PRINTER_SETTINGS_H +#define SPAWN_PRINTER_SETTINGS_H + +#include + +void spawn_printer_settings (); +void spawn_printer_settings_with_args (const gchar *args, ...); + +#endif + -- cgit v1.2.3