diff -Nur gnome-cups-manager-0.31/gnome-cups-manager/gnome-cups-manager.glade gnome-cups-manager-0.31.new/gnome-cups-manager/gnome-cups-manager.glade --- gnome-cups-manager-0.31/gnome-cups-manager/gnome-cups-manager.glade 2005-03-03 17:26:48.000000000 +0100 +++ gnome-cups-manager-0.31.new/gnome-cups-manager/gnome-cups-manager.glade 2006-09-06 17:56:01.000000000 +0200 @@ -18,6 +18,8 @@ <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> <child> <widget class="GtkVBox" id="vbox13"> @@ -28,6 +30,8 @@ <child> <widget class="GtkMenuBar" id="menubar1"> <property name="visible">True</property> + <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property> + <property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property> <child> <widget class="GtkMenuItem" id="printer_item"> @@ -284,6 +288,8 @@ <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> <child> <widget class="GtkVBox" id="vbox14"> @@ -1445,6 +1451,8 @@ <property name="skip_pager_hint">False</property> <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> <child> <widget class="GtkVBox" id="vbox19"> @@ -1455,6 +1463,8 @@ <child> <widget class="GtkMenuBar" id="menubar2"> <property name="visible">True</property> + <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property> + <property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property> <child> <widget class="GtkMenuItem" id="printer1"> @@ -1472,7 +1482,7 @@ <property name="use_underline">True</property> <child internal-child="image"> - <widget class="GtkImage" id="image117"> + <widget class="GtkImage" id="image135"> <property name="visible">True</property> <property name="stock">gtk-add</property> <property name="icon_size">1</property> @@ -1501,7 +1511,7 @@ <accelerator key="Delete" modifiers="0" signal="activate"/> <child internal-child="image"> - <widget class="GtkImage" id="image118"> + <widget class="GtkImage" id="image136"> <property name="visible">True</property> <property name="stock">gtk-remove</property> <property name="icon_size">1</property> @@ -1547,7 +1557,7 @@ <property name="use_underline">True</property> <child internal-child="image"> - <widget class="GtkImage" id="image119"> + <widget class="GtkImage" id="image137"> <property name="visible">True</property> <property name="stock">gnome-stock-timer-stop</property> <property name="icon_size">1</property> @@ -1567,7 +1577,7 @@ <property name="use_underline">True</property> <child internal-child="image"> - <widget class="GtkImage" id="image120"> + <widget class="GtkImage" id="image138"> <property name="visible">True</property> <property name="stock">gnome-stock-timer</property> <property name="icon_size">1</property> @@ -1612,6 +1622,36 @@ </child> </widget> </child> + + <child> + <widget class="GtkMenuItem" id="global_settings1"> + <property name="visible">True</property> + <property name="label" translatable="yes">Global Settings</property> + <property name="use_underline">True</property> + + <child> + <widget class="GtkMenu" id="global_settings1_menu"> + + <child> + <widget class="GtkCheckMenuItem" id="detect_lan_printers1"> + <property name="visible">True</property> + <property name="label" translatable="yes">Detect LAN Printers</property> + <property name="use_underline">True</property> + <property name="active">False</property> + </widget> + </child> + + <child> + <widget class="GtkCheckMenuItem" id="share_lan_printers1"> + <property name="visible">True</property> + <property name="label" translatable="yes">Share Printers</property> + <property name="use_underline">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> </widget> <packing> <property name="padding">0</property> diff -Nur gnome-cups-manager-0.31/gnome-cups-manager/gnome-cups-manager.gladep gnome-cups-manager-0.31.new/gnome-cups-manager/gnome-cups-manager.gladep --- gnome-cups-manager-0.31/gnome-cups-manager/gnome-cups-manager.gladep 1970-01-01 01:00:00.000000000 +0100 +++ gnome-cups-manager-0.31.new/gnome-cups-manager/gnome-cups-manager.gladep 2006-09-06 17:55:40.000000000 +0200 @@ -0,0 +1,7 @@ +<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> +<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd"> + +<glade-project> + <name></name> + <program_name></program_name> +</glade-project> diff -Nur gnome-cups-manager-0.31/gnome-cups-manager/view-printers.c gnome-cups-manager-0.31.new/gnome-cups-manager/view-printers.c --- gnome-cups-manager-0.31/gnome-cups-manager/view-printers.c 2004-10-01 21:10:04.000000000 +0200 +++ gnome-cups-manager-0.31.new/gnome-cups-manager/view-printers.c 2006-09-06 17:55:40.000000000 +0200 @@ -41,6 +41,11 @@ #include <stdlib.h> #include <cups/cups.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <gtk/gtk.h> +#include <libgnome/gnome-i18n.h> + static void printer_view_weak_notify (gpointer user_data, GObject *old_spot) { @@ -49,6 +54,161 @@ *widget = NULL; } +static gint +_get_status_helper(const gchar* cmd) +{ + const gchar *argv_stat[] = { cmd , NULL}; + GSpawnFlags flags = G_SPAWN_FILE_AND_ARGV_ZERO; + GError *error=NULL; + gint spawn_exit_code, my_return_code; + gboolean ok; + + ok = g_spawn_sync (NULL, argv_stat, NULL, flags,NULL, NULL, NULL, NULL, &spawn_exit_code, &error); + + if (ok) + my_return_code = WEXITSTATUS (spawn_exit_code); + else + { + my_return_code = -1; + fprintf (stderr, "Error occured spawning: %s\n", error->message); + } + return (my_return_code); + +} + +gint browsing_status() +{ + return _get_status_helper("/usr/share/cups/browsing_status"); +} + +gint sharing_status() +{ + return _get_status_helper("/usr/share/cups/sharing_status"); +} + +static int +_set_status_helper(const gchar *cmd, + const gchar *enable_msg, + const gchar *disable_msg, + gboolean enable) +{ + char msg[1024]; + gchar *full_cmd = g_strdup_printf("%s %i", cmd, enable); + char const *argv_enable[] = { "gksudo", msg, full_cmd, NULL }; + char const *argv_disable[] = { "gksudo", msg, full_cmd, NULL }; + GSpawnFlags flags = G_SPAWN_SEARCH_PATH; + GError *error=NULL; + gint spawn_exit_code, my_return_code; + gboolean ok; + + if (enable) + { + snprintf(msg , sizeof(msg), "-m %s", enable_msg); + ok = g_spawn_sync (NULL,(gchar**) argv_enable, NULL, flags,NULL, NULL, NULL, NULL, &spawn_exit_code, &error); + } + else + { + snprintf(msg , sizeof(msg), "-m %s", disable_msg); + ok = g_spawn_sync (NULL, (gchar**) argv_disable, NULL, flags,NULL, NULL, NULL, NULL, &spawn_exit_code, &error); + } + + if (ok) + my_return_code = WEXITSTATUS (spawn_exit_code); + else + { + my_return_code = -1; + fprintf (stderr, "Error occured spawning: %s\n", error->message); + } + g_free(full_cmd); + return (my_return_code); +} + +gint browsing_set(gboolean enable) +{ + return _set_status_helper("/usr/share/cups/enable_browsing", + _("Enter your password to enable LAN printers detection."), + _("Enter your password to disable LAN printers detection."), + enable); +} + +gint sharing_set(gboolean enable) +{ + return _set_status_helper("/usr/share/cups/enable_sharing", + _("Enter your password to enable LAN printers sharing."), + _("Enter your password to disable LAN printers sharing."), + enable); +} + +static void +browsing_toggled_cb (GtkWidget *item, gpointer user_data) +{ + GladeXML *xml = GLADE_XML (user_data); + gboolean bstat, checkbox_state; + GtkWidget *dialog, *window; + item = glade_xml_get_widget (xml, "detect_lan_printers1"); + window = glade_xml_get_widget (xml, "printer_window"); + char *warning_msg = + _("Enabling LAN printers detection will open port 631 on your system. This exposes you to the " + "risk of exploiting any security vulnerabilities of the printing system. Remote attackers " + "could potentially gain access to your system with the privileges of the \"cupsys\" user."); + + bstat = browsing_status(); + checkbox_state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)); + + if (bstat != checkbox_state) + { + if (checkbox_state) + { + dialog = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, + "%s", warning_msg); + gint result = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + if (result == GTK_RESPONSE_OK) browsing_set(TRUE); + } + else + browsing_set(FALSE); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), browsing_status()); + } +} + +static void +sharing_toggled_cb (GtkWidget *item, gpointer user_data) +{ + GladeXML *xml = GLADE_XML (user_data); + gboolean bstat, checkbox_state; + GtkWidget *dialog, *window; + item = glade_xml_get_widget (xml, "share_lan_printers1"); + window = glade_xml_get_widget (xml, "printer_window"); + char *warning_msg = + _("Enabling LAN printers sharing will open port 631 on your system. This exposes you to the " + "risk of exploiting any security vulnerabilities of the printing system. Remote attackers " + "could potentially gain access to your system with the privileges of the \"cupsys\" user."); + + bstat = sharing_status(); + checkbox_state = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)); + + if (bstat != checkbox_state) + { + if (checkbox_state) + { + dialog = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_OK_CANCEL, + "%s", warning_msg); + gint result = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + if (result == GTK_RESPONSE_OK) sharing_set(TRUE); + } + else + sharing_set(FALSE); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), sharing_status()); + } +} + static void close_cb (GtkWidget *item, gpointer user_data) @@ -201,6 +361,12 @@ item = glade_xml_get_widget (xml, "delete_item"); g_signal_connect (item, "activate", G_CALLBACK (delete_cb), xml); + + item = glade_xml_get_widget (xml, "detect_lan_printers1"); + g_signal_connect (item, "activate", G_CALLBACK (browsing_toggled_cb), xml); + item = glade_xml_get_widget (xml, "share_lan_printers1"); + g_signal_connect (item, "activate", G_CALLBACK (sharing_toggled_cb), xml); + } static void @@ -215,6 +381,7 @@ gboolean delete; gboolean properties; gboolean status; + gboolean bstat; list = GNOME_PRINTER_LIST (g_object_get_data (G_OBJECT (xml), "icon_list")); @@ -244,6 +411,21 @@ item = glade_xml_get_widget (xml, "properties_item"); gtk_widget_set_sensitive (item, properties); + + item = glade_xml_get_widget (xml, "detect_lan_printers1"); + bstat = browsing_status(); + if ((bstat == 2)||(bstat==-1)) + gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + else + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), bstat); + + item = glade_xml_get_widget (xml, "share_lan_printers1"); + bstat = sharing_status(); + if ((bstat == 2)||(bstat==-1)) + gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); + else + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), bstat); + } static void