Author: mzugec Date: Wed Jul 16 18:47:29 2008 New Revision: 49192 URL: http://svn.opensuse.org/viewcvs/yast?rev=49192&view=rev Log: move functionality to initOverview move testprinter to handleOverview Modified: branches/tmp/mzugec/printer2/src/dialogs.ycp branches/tmp/mzugec/printer2/src/overview.ycp Modified: branches/tmp/mzugec/printer2/src/dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/printer2/src/dialogs.ycp?rev=49192&r1=49191&r2=49192&view=diff ============================================================================== --- branches/tmp/mzugec/printer2/src/dialogs.ycp (original) +++ branches/tmp/mzugec/printer2/src/dialogs.ycp Wed Jul 16 18:47:29 2008 @@ -169,7 +169,6 @@ `CheckBox( `id(`local_content_checkbox),`opt(`notify), _("local queues")), `CheckBox( `id(`remote_content_checkbox),`opt(`notify), _("remote queues")))), `VWeight(2,`Table (`id (`overview_table), `opt (`notify, `immediate), -// `header(_("Queue Name"),_("Device"), _("Model"), _("Default Queue")) `header( // Header of a Table column with a list of print queues. // Where the queue configuration exists (local or remote): _("Configuration"), Modified: branches/tmp/mzugec/printer2/src/overview.ycp URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/mzugec/printer2/src/overview.ycp?rev=49192&r1=49191&r2=49192&view=diff ============================================================================== --- branches/tmp/mzugec/printer2/src/overview.ycp (original) +++ branches/tmp/mzugec/printer2/src/overview.ycp Wed Jul 16 18:47:29 2008 @@ -44,19 +44,148 @@ void initOverview(string key){ - UI::ChangeWidget(`local_content_checkbox, `Value, Printer::queue_filter_show_local); - UI::ChangeWidget(`remote_content_checkbox, `Value, Printer::queue_filter_show_remote); + 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 ) + { + Popup::ErrorDetails( _("Start local running CUPS daemon"), + _("A local running CUPS daemon is needed for your setup.") + ); + + 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.") + ); + } + UI::ChangeWidget(`local_content_checkbox, `Value, local_content_selected); + UI::ChangeWidget(`remote_content_checkbox, `Value, remote_content_selected); UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } symbol handleOverview(string key, map event){ + if (event["EventReason"]:""=="ValueChanged" && (event["ID"]:nil==`remote_content_checkbox || event["ID"]:nil==`local_content_checkbox)){ y2milestone("Refreshing overview items"); 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::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } -y2internal("event %1", event); + + 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: + _("No Queue Selected"), + // Body of a Popup::AnyMessage when no queue was selected: + _("Select a queue.") + ); + return nil; + } + 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.") + ); + return nil; + } + 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.") + ); + return nil; + } + if( "local" == Printer::queues[selected_queue_index,"config"]:"remote" ) + Printer::selected_queues_index = selected_queue_index; + 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 + ); + } + return nil; + } + + 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; + } else{ + // 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( Printer::queues[selected_queue_index,"config"]:"remote" == "local" ) + { + Printer::selected_queues_index = selected_queue_index; + } + 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::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