[yast-commit] r49198 - /branches/tmp/mzugec/printer2/src/overview.ycp
Author: mzugec Date: Wed Jul 16 22:31:47 2008 New Revision: 49198 URL: http://svn.opensuse.org/viewcvs/yast?rev=49198&view=rev Log: removed OverviewDialog added `edit into handleOverview Modified: branches/tmp/mzugec/printer2/src/overview.ycp Modified: branches/tmp/mzugec/printer2/src/overview.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/printer2/src/overview.ycp?rev=49198&r1=49197&r2=49198&view=diff ============================================================================== --- branches/tmp/mzugec/printer2/src/overview.ycp (original) +++ branches/tmp/mzugec/printer2/src/overview.ycp Wed Jul 16 22:31:47 2008 @@ -98,6 +98,13 @@ UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } +/** + * handle function + * for add, edit and delete buttons, + * local and remote checkboxes, + * test button and refresh overview + */ + symbol handleOverview(string key, map event){ if (event["EventReason"]:""=="ValueChanged" && (event["ID"]:nil==`remote_content_checkbox || event["ID"]:nil==`local_content_checkbox)){ @@ -107,8 +114,9 @@ UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } + integer selected_queue_index = (integer)UI::QueryWidget( `id(`overview_table), `CurrentItem ); + 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: @@ -155,9 +163,7 @@ if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `test){ y2milestone("printing test page"); - string queue_name = ""; - integer selected_queue_index = (integer)UI::QueryWidget( `id(`overview_table), `CurrentItem ); queue_name = Printer::queues[selected_queue_index,"name"]:""; if( "" == queue_name ) { Popup::AnyMessage( // Header of a Popup::AnyMessage when no queue was selected: @@ -260,8 +266,29 @@ return `add; } + if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `edit){ + 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 modified: + _("Cannot Modify"), + // Body of a Popup::AnyMessage when a remote queue was selected to be modified: + _("This is a remote queue. Only local queues can be modified.") + ); + return nil; + } + Printer::selected_queues_index = selected_queue_index; + y2milestone( "To be modified: '%1', selected_queues_index = %2", queue_name, Printer::selected_queues_index ); + return `modify; + } - 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: Printer::selected_queues_index = -1; @@ -281,473 +308,10 @@ 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; } -/** - * Overview dialog - * @return dialog result - */ -any OverviewDialog() -{ string caption = _("Overview of Already Configured Printers (so called 'Print Queues')"); - boolean local_content_selected = Printer::queue_filter_show_local; - boolean remote_content_selected = Printer::queue_filter_show_remote; - boolean local_cupsd_required = true; - boolean local_cupsd_accessible = Printer::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ); - // By default there is no /etc/cups/client.conf file at all - // 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 ) - { // 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 ) - { - local_content_selected = true; - remote_content_selected = true; - } - else - { local_cupsd_required = false; - local_content_selected = false; - remote_content_selected = true; - } - } - if( local_cupsd_required && ! local_cupsd_accessible ) - { if( ! Popup::ContinueCancelHeadline( _("Start local running CUPS daemon"), - _("A local running CUPS daemon is needed for your setup.") - ) - ) - { return `abort; - } - if( ! Service::Start("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.") - ); - } - else - { Popup::TimedMessage( _("Waiting for the CUPS daemon to become ready to operate..."), - 60 - ); - } - local_cupsd_accessible = Printer::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ); - if( ! local_cupsd_accessible ) - { 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 `abort; - } - } - term queue_table_header = `header( // Header of a Table column with a list of print queues. - // Where the queue configuration exists (local or remote): - _("Configuration"), - // Header of a Table column with a list of print queues. - // Print queue name: - _("Name"), - // Header of a Table column with a list of print queues. - // Print queue description (e.g. model or driver): - _("Description"), - // Header of a Table column with a list of print queues. - // Location of the printer (e.g. second floor, room 2.3): - _("Location"), - // Header of a Table column with a list of print queues. - // Whether or not is is the default queue: - _("Default"), - // Header of a Table column with a list of print queues. - // Queue status (accepting/rejecting and enabled/disabled): - _("Status") - ); - term contents = `VBox( `Left( `RadioButtonGroup( `id(`which_content_radio_buttons), - `HBox( `Label( _("Show") ), - `CheckBox( `id(`local_content_checkbox), - `opt(`notify), - _("local queues"), - local_content_selected - ), - `CheckBox( `id(`remote_content_checkbox), - `opt(`notify), - _("remote queues"), - remote_content_selected - ) - ) - ) - ), - `ReplacePoint( `id(`queue_table_replace_point), - // Reserve sufficient space for the table: - `VBox( `VStretch(), - `Label( _("Building the table of available queues...") ), - `VStretch() - ) - ), - `Left( `HBox( `Label( _("Either") + " " ), - `PushButton( `id(`add_button), - _("&Add") - ), - `Label( " " + _("a new queue or select a queue and print a") + " " ), - `PushButton( `id(`testpage_button), - _("&Testpage") - ) - ) - ), - `ReplacePoint( `id(`change_buttons_replace_point), - `Left( `HBox( `Label( _("Alternatively select one and") + " " ), - `PushButton( `id(`modify_button), - _("&Modify") - ), - `Label( " " + _("or") + " " ), - `PushButton( `id(`delete_button), - _("&Delete") - ), - `Label( " " + _("it") ) - ) - ) - ), - `Left( `HBox( `Label( _("Configure") + " " ), - `PushButton( `id(`printing_via_network_button), - _("Printing via &Network") - ), - `Label( " " + _("if a desired remote printer is not shown") ) - ) - ), - `Left( `HBox( `Label( _("Configure") + " " ), - `PushButton( `id(`remote_access_button), - _("&Remote Access") - ), - `Label( " " + _("to share local queues in the network.") ) - ) - ), - `Left( `HBox( `Label( _("Specify via") + " " ), - `PushButton( `id(`autoconfig_button), - _("A&utoconfig") - ), - `Label( " " + _("in which way USB printers are configured automatically.") ) - ) - ) - ); - Wizard::SetContentsButtons( caption, - contents, - HELPS["overview"]:"", - Label::QuitButton(), - Label::FinishButton() - ); - UI::FakeUserInput(`local_content_checkbox); - any ret = nil; - while(true) - { ret = UI::UserInput(); - if( ret == `abort || ret == `cancel || ret == `back || ret == `next ) break; - if( ret == `queues ) - { integer selected_queue_index = (integer)UI::QueryWidget( `id(`queues), `CurrentItem ); - if( nil == selected_queue_index || selected_queue_index < 0 ) - { // To be safe invalidate Printer::selected_queues_index when no queue exists: - Printer::selected_queues_index = -1; - continue; - } - // To be safe enable the modify and delete buttons only when it is explicitely verified - // that the "config" is "local", otherwise have those buttons disabled by fallback: - if( "local" == Printer::queues[selected_queue_index,"config"]:"remote" ) - { Printer::selected_queues_index = selected_queue_index; - // Enable the modify and delete buttons when a local queue is selected: - UI::ReplaceWidget( `id(`change_buttons_replace_point), - `Left( `HBox( `Label( _("Alternatively select one and") + " " ), - `PushButton( `id(`modify_button), - _("&Modify") - ), - `Label( " " + _("or") + " " ), - `PushButton( `id(`delete_button), - _("&Delete") - ), - `Label( " " + _("it") ) - ) - ) - ); - } - else - { // To be safe invalidate Printer::selected_queues_index when a remote queue is selected: - Printer::selected_queues_index = -1; - // Disable the modify and delete buttons when a remote queue is selected and by fallback: - UI::ReplaceWidget( `id(`change_buttons_replace_point), - `Left( `HBox( `Label( `opt(`disabled), _("Alternatively select one and") + " " ), - `PushButton( `id(`modify_button), - `opt(`disabled), - _("&Modify") - ), - `Label( `opt(`disabled), " " + _("or") + " " ), - `PushButton( `id(`delete_button), - `opt(`disabled), - _("&Delete") - ), - `Label( `opt(`disabled), " " + _("it") ) - ) - ) - ); - } - continue; - } - if( ret == `local_content_checkbox || ret == `remote_content_checkbox ) - { - Printer::queue_filter_show_local = (boolean)UI::QueryWidget(`local_content_checkbox, `Value); - Printer::queue_filter_show_remote = (boolean)UI::QueryWidget(`remote_content_checkbox, `Value); - UI::ReplaceWidget( `id(`queue_table_replace_point), - `Table( `id(`queues), - // The notify and immediate options are only needed - // when both local and remote queues are shown in one table - // to disable the modify and delete buttons when a remote queue is selected - // and to re-enable those buttons when a local queue is selected: - `opt(`notify, `immediate), - queue_table_header, - Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote ) - ) - ); - UI::ReplaceWidget( `id(`change_buttons_replace_point), - `Left( `HBox( `Label( _("Alternatively select one and") + " " ), - `PushButton( `id(`modify_button), - _("&Modify") - ), - `Label( " " + _("or") + " " ), - `PushButton( `id(`delete_button), - _("&Delete") - ), - `Label( " " + _("it") ) - ) - ) - ); - // The above content has the modify and delete buttons enabled. - // But when the first queue is a remote queue, those buttons must be disabled. - // Therefore a queue-selection is faked so that it is re-calculated - // whether or not those buttons are enabled or disabled: - UI::FakeUserInput( `queues ); - continue; - } - if( ret == `add_button ) - { if( client_only && client_conf_server_name != "localhost" ) - { if( ! Popup::YesNoHeadline( "Disable remote CUPS server setting", - "A remote CUPS server setting conflicts with adding a print queue." - ) - ) - { continue; - } - // 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") - ); - continue; - } - } - 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." - ) - ) - { continue; - } - // 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.") - ); - continue; - } - 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.") - ); - continue; - } - // 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(); - ret = `add; - break; - } - if( ret == `modify_button ) - { integer selected_queue_index = (integer)UI::QueryWidget( `id(`queues), `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.") - ); - continue; - } - if( "local" != Printer::queues[selected_queue_index,"config"]:"remote" ) - { Popup::AnyMessage( // Header of a Popup::AnyMessage when a remote queue was selected to be modified: - _("Cannot Modify"), - // Body of a Popup::AnyMessage when a remote queue was selected to be modified: - _("This is a remote queue. Only local queues can be modified.") - ); - continue; - } - Printer::selected_queues_index = selected_queue_index; - y2milestone( "To be modified: '%1', selected_queues_index = %2", queue_name, Printer::selected_queues_index ); - ret = `modify; - break; - } - if( ret == `delete_button ) - { integer selected_queue_index = (integer)UI::QueryWidget( `id(`queues), `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.") - ); - continue; - } - 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.") - ); - continue; - } - 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 - ) - ) - { // The user has decided to cancel the deletion of the queue: - continue; - } - // 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: - ret = `delete; - break; - } - if( ret == `testpage_button ) - { string queue_name = ""; - integer selected_queue_index = (integer)UI::QueryWidget( `id(`queues), `CurrentItem ); - 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.") - ); - continue; - } - if( "yes" == Printer::queues[selected_queue_index,"rejecting"]:"no" ) - { Popup::AnyMessage( // Header of a Popup::AnyMessage when the queue rejects print jobs: - _("Rejecting Print Jobs"), - // Body of a Popup::AnyMessage when the queue rejects print jobs: - _("The testpage cannot be printed because print jobs are rejected.") - ); - continue; - } - if( "yes" == Printer::queues[selected_queue_index,"disabled"]:"no" ) - { Popup::AnyMessage( // Header of a Popup::AnyMessage when printing is disabled for the queue: - _("Printout Disabled"), - // Body of a Popup::AnyMessage when printing is disabled for the queue: - _("The testpage cannot be printed because printout is disabled.") - ); - continue; - } - if( "local" == Printer::queues[selected_queue_index,"config"]:"remote" ) - { Printer::selected_queues_index = selected_queue_index; - } - Wizard::DisableBackButton(); - Wizard::DisableAbortButton(); - Wizard::DisableNextButton(); - if( ! Printer::ExecuteBashCommand( "/usr/bin/lp -d '" - + queue_name - + "' -o page-label=\"Testprint:$(hostname)\" /usr/share/cups/data/testprint.ps" - ) - ) - { Popup::Error( // Message of a Popup::Error - // where %1 will be replaced by the queue name. - // 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). - sformat( _("Failed to print testpage for queue %1."), queue_name ) - ); - } - else - { Popup::TimedMessage( // Popup message - // where %1 will be replaced by the queue name. - sformat( _("Sent testpage to queue %1. Is should start to print soon."), queue_name ), - 60 - ); - } - Wizard::EnableBackButton(); - Wizard::EnableAbortButton(); - Wizard::EnableNextButton(); - continue; - } - if( ret == `remote_access_button ) - { ret = `sharing; - break; - } - if( ret == `printing_via_network_button ) - { ret = `printing_via_network; - break; - } - if( ret == `autoconfig_button ) - { // To be used while the 'Autoconfig' functionality is not yet implemented: - Popup::AnyMessage( // Header of a Popup::AnyMessage when the "Autoconfig" button was clicked: - _("Not yet implemented"), - // Body of a Popup::AnyMessage when the "Autoconfig" button was clicked: - _("Configure 'Autoconfig' is not yet implemented. Do it manually in /etc/cups-autoconfig.conf") - ); - // After changes regarding autoconfig of USB printers, enforce to show also local queues. - // For example when autoconfig was disabled before and becomes now enabled, - // there is perhaps a new local queue for a USB printer which should be shown to the user - // in particular when his queue_filter_string was "remote" before: - if( Printer::queue_filter_show_remote ) - { - UI::ChangeWidget( `id(`remote_content_checkbox), `Value, true); - UI::ChangeWidget( `id(`local_content_checkbox), `Value, true); -// UI::FakeUserInput( `all_content_radio_button ); - } - continue; - // To be used when the 'Autoconfig' functionality is implemented: - ret = `printing_via_network; - break; - } - y2milestone( "Ignoring unexpected returncode in OverviewDialog: %1", ret ); - continue; - } - return ret; -} - /* EOF */ } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mzugec@svn.opensuse.org