Author: mzugec Date: Wed Jul 16 22:22:42 2008 New Revision: 49197 URL: http://svn.opensuse.org/viewcvs/yast?rev=49197&view=rev Log: moved `add and `delete into handleOverview Modified: branches/tmp/mzugec/printer2/src/Printer.ycp branches/tmp/mzugec/printer2/src/overview.ycp Modified: branches/tmp/mzugec/printer2/src/Printer.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/printer2/src/Printer.ycp?rev=49197&r1=49196&r2=49197&view=diff ============================================================================== --- branches/tmp/mzugec/printer2/src/Printer.ycp (original) +++ branches/tmp/mzugec/printer2/src/Printer.ycp Wed Jul 16 22:22:42 2008 @@ -201,6 +201,10 @@ global boolean queue_filter_show_local = true; global boolean queue_filter_show_remote = true; + +global boolean client_only = false; +global string client_conf_server_name = ""; + /** * Driver options (options in the PPD for one specific existing queue): * Determined at runtime via Printer::DetermineDriverOptions( "queue_name") @@ -638,6 +642,9 @@ // Progress 1. stage (Autodetect already configured printers): if( Abort() ) return false; Progress::NextStage(); + client_only = Printer::ExecuteBashCommand( "egrep -i '^ServerName[[:space:]]+[[:alnum:]]' /etc/cups/client.conf" ); + if( ExecuteBashCommand( "sed -n -e 's/^[Se][Ee][Rr][Vv][Ee][Rr][Nn][Aa][Mm][Ee][[:space:]][[:space:]]*\\(.*\\)$/\\1/p' /etc/cups/client.conf | tr -d '[:space:]'" ) ) + client_conf_server_name = result["stdout"]:""; // Progress last stage (progress finished): if( Abort() ) return false; Progress::Finish(); Modified: branches/tmp/mzugec/printer2/src/overview.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/printer2/src/overview.ycp?rev=49197&r1=49196&r2=49197&view=diff ============================================================================== --- branches/tmp/mzugec/printer2/src/overview.ycp (original) +++ branches/tmp/mzugec/printer2/src/overview.ycp Wed Jul 16 22:22:42 2008 @@ -52,15 +52,11 @@ // and usually there is no ServerName entry in a /etc/cups/client.conf file. // Therefore client_only is only true if there is a /etc/cups/client.conf file // with an active ServerName entry: - boolean client_only = Printer::ExecuteBashCommand( "egrep -i '^ServerName[[:space:]]+[[:alnum:]]' /etc/cups/client.conf" ); - string client_conf_server_name = ""; - if( client_only ) + if( Printer::client_only ) { // YCP string quoting: A double backslash '\\' results a single backslash '\' in the string. // At least the trailing newline character must be removed. - if( Printer::ExecuteBashCommand( "sed -n -e 's/^[Se][Ee][Rr][Vv][Ee][Rr][Nn][Aa][Mm][Ee][[:space:]][[:space:]]*\\(.*\\)$/\\1/p' /etc/cups/client.conf | tr -d '[:space:]'" ) ) - client_conf_server_name = Printer::result["stdout"]:""; - if( "localhost" == client_conf_server_name ) + if( Printer::client_conf_server_name == "localhost" ) { local_content_selected = true; remote_content_selected = true; @@ -111,6 +107,52 @@ UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } + if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `delete){ + integer selected_queue_index = (integer)UI::QueryWidget( `id(`overview_table), `CurrentItem ); + string queue_name = Printer::queues[selected_queue_index,"name"]:""; + if( "" == queue_name ) + { Popup::AnyMessage( // Header of a Popup::AnyMessage when no queue was selected: + _("No Queue Selected"), + // Body of a Popup::AnyMessage when no queue was selected: + _("Select a queue.") + ); + return nil; + } + if( "local" != Printer::queues[selected_queue_index,"config"]:"remote" ) + { Popup::AnyMessage( // Header of a Popup::AnyMessage when a remote queue was selected to be deleted: + _("Cannot Delete"), + // Body of a Popup::AnyMessage when a remote queue was selected to be deleted: + _("This is a remote queue. Only local queues can be deleted.") + ); + return nil; + } + if (Popup::AnyQuestion( // Header of a confirmation popup before a queue will be deleted: + _("Confirm Deletion"), + // Body of a confirmation popup before a queue will be deleted: + _("The queue would be deleted immediately and cannot be restored."), + // 'Yes' button label of a confirmation popup before a queue will be deleted: + sformat( _("Delete queue %1"), queue_name ), + // 'No' button label of a confirmation popup before a queue will be deleted: + _("Do not delete it"), + `focus_no + )) + { + // To be safe invalidate Printer::selected_queues_index in any case: + Printer::selected_queues_index = -1; + y2milestone( "To be deleted:'%1', selected_queue_index = %2", queue_name, selected_queue_index ); + if( ! Printer::DeleteQueue( queue_name ) ) + { Popup::Error( // Message of a Popup::Error + // where %1 will be replaced by the queue name. + // Only a simple message because before the function Printer::DeleteQueue + // was called and this function would have shown more specific messages. + sformat( _("Failed to delete queue %1."), queue_name ) + ); + } + // Re-run the OverviewDialog (with a re-created list of queues) via the sequencer: + return `delete; + } + } + if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `test){ y2milestone("printing test page"); @@ -165,6 +207,60 @@ return nil; } + if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `add){ + // client only + if( Printer::client_only && Printer::client_conf_server_name != "localhost" ) + { if( ! Popup::YesNoHeadline( "Disable remote CUPS server setting", + "A remote CUPS server setting conflicts with adding a print queue." + ) + ) + return nil; + // Disable the 'ServerName' entry in /etc/cups/client.conf: + if( ! Printer::ExecuteBashCommand( "sed -i.yast2.save -e 's/^[Se][Ee][Rr][Vv][Ee][Rr][Nn][Aa][Mm][Ee]/#ServerName/' /etc/cups/client.conf" ) ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("Failed to disable the 'ServerName' entry in /etc/cups/client.conf") + ); + return nil; + } + } + if( ! Printer::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ) ) + { // No local running cupsd is accessible: + if( ! Popup::YesNoHeadline( "Start local running CUPS daemon", + "A local running CUPS daemon is needed to add a print queue." + ) + ) + return nil; + // Do a restart to be safe: + if( ! Service::Restart("cups") ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("Failed to start the CUPS daemon.") + ); + return nil; + } + Popup::TimedMessage( _("Waiting for the CUPS daemon to become ready to operate..."), 60 ); + } + if( ! Printer::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ) ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("No local running CUPS daemon is accessible.") + ); + return nil; + } + // To be safe autodetect the queues again. + // When there was a switch from "client only" to a local running cupsd + // existing local queues are not yet know so that the NewQueueName function + // may not notice when a queue name proposal for a new (i.e. added) queue + // already exists as local queue: + Printer::AutodetectQueues(); + return `add; + } + + integer selected_queue_index = (integer)UI::QueryWidget( `id(`overview_table), `CurrentItem ); if( selected_queue_index == nil || selected_queue_index < 0 ) { // To be safe invalidate Printer::selected_queues_index when no queue exists: @@ -181,10 +277,10 @@ Printer::selected_queues_index = -1; // Disable the modify and delete buttons when a remote queue is selected and by fallback: } + } UI::ChangeWidget(`edit, `Enabled, Printer::selected_queues_index>-1); UI::ChangeWidget(`delete, `Enabled, Printer::selected_queues_index>-1); UI::ChangeWidget(`test, `Enabled, Printer::selected_queues_index>-1); - } y2internal("event %1", event); return nil; } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org