[yast-commit] r59907 - in /trunk/printer/src: Printer.ycp basicadd.ycp basicmodify.ycp connectionwizard.ycp
![](https://seccdn.libravatar.org/avatar/d6bf8101a50cb3a4074921544e319e9a.jpg?s=120&d=mm&r=g)
Author: jsmeix Date: Wed Dec 2 16:43:55 2009 New Revision: 59907 URL: http://svn.opensuse.org/viewcvs/yast?rev=59907&view=rev Log: Implemented that the current URI from the Connection Wizard gets preselected in the Add/Modify dialogs. Modified: trunk/printer/src/Printer.ycp trunk/printer/src/basicadd.ycp trunk/printer/src/basicmodify.ycp trunk/printer/src/connectionwizard.ycp Modified: trunk/printer/src/Printer.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/Printer.ycp?rev=59907... ============================================================================== --- trunk/printer/src/Printer.ycp (original) +++ trunk/printer/src/Printer.ycp Wed Dec 2 16:43:55 2009 @@ -1165,23 +1165,25 @@ sorted_connection_items = sort( term one_item, term another_item, connection_items, - { // Have the entries which are "created by the connection wizard" topmost: + { // Have entries which are "created by the connection wizard" + // or "modified by the connection wizard" topmost: // Have short local variable names for shorter comparison expression // and avoid multiple complicated accesses of same elements in an list: string this = one_item[3]:""; string that = another_item[3]:""; - // This is an entry where the info is "created by the connection wizard" + string connection_wizard_match = "by the connection wizard"; + // This is an entry where the info is "created/modified by the connection wizard" // and that is no such entry: - if( ( this == "created by the connection wizard" ) - && ( that != "created by the connection wizard" ) + if( issubstring( this, connection_wizard_match ) + && ( ! issubstring( that, connection_wizard_match ) ) ) return true; - // This is an entry where the info is not "created by the connection wizard" + // This is an entry where the info is not "created/modified by the connection wizard" // but that is such an entry: - if( ( this != "created by the connection wizard" ) - && ( that == "created by the connection wizard" ) + if( ( ! issubstring( this, connection_wizard_match ) ) + && issubstring( that, connection_wizard_match ) ) return false; - // If both are "created by the connection wizard" - // or if both are not "created by the connection wizard" + // If both are "created/modified by the connection wizard" + // or if both are not "created/modified by the connection wizard" // have entries with a valid model name topmost: // Have short local variable names for shorter comparison expression // and avoid multiple complicated accesses of same elements in an list: Modified: trunk/printer/src/basicadd.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/basicadd.ycp?rev=5990... ============================================================================== --- trunk/printer/src/basicadd.ycp (original) +++ trunk/printer/src/basicadd.ycp Wed Dec 2 16:43:55 2009 @@ -451,7 +451,7 @@ // (there is only "Kyocera" but not "Kyocera Mita" in the known_manufacturers list). foreach( string known_manufacturer, Printer::known_manufacturers, - { if( manufacturer == tolower( known_manufacturer ) ) + { if( tolower( manufacturer ) == tolower( known_manufacturer ) ) { driver_filter_string = "^" + driver_filter_string; break; } Modified: trunk/printer/src/basicmodify.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/basicmodify.ycp?rev=5... ============================================================================== --- trunk/printer/src/basicmodify.ycp (original) +++ trunk/printer/src/basicmodify.ycp Wed Dec 2 16:43:55 2009 @@ -78,17 +78,38 @@ Wizard::HideAbortButton(); string model = ""; list <string> description_words = splitstring( description, " " ); - if( size( description_words ) > 2 ) - { model = description_words[0]:"" + " " - + description_words[1]:"" + " " - + description_words[2]:""; - } - if( size( description_words ) == 2 ) - { model = description_words[0]:"" + " " - + description_words[1]:""; - } - if( size( description_words ) == 1 ) - { model = description_words[0]:""; + // In Printer.ycp and basicmodify.ycp there are lines like + // description = model + " with driver " + description; + // new_description = model + " with driver " + new_description; + // Avoid having "with" and/or "driver" in the model string: + description_words = filter( string word, + description_words, + { return( "with" != word && "driver" != word ); + } + ); + // Use the queue description only if its first word is actually a known manufacturer: + boolean description_starts_with_known_manufacturer = false; + foreach( string known_manufacturer, + Printer::known_manufacturers, + { if( tolower( description_words[0]:"" ) == tolower( known_manufacturer ) ) + { description_starts_with_known_manufacturer = true; + break; + } + } + ); + if( description_starts_with_known_manufacturer ) + { if( size( description_words ) > 2 ) + { model = description_words[0]:"" + " " + + description_words[1]:"" + " " + + description_words[2]:""; + } + if( size( description_words ) == 2 ) + { model = description_words[0]:"" + " " + + description_words[1]:""; + } + if( size( description_words ) == 1 ) + { model = description_words[0]:""; + } } string driver_filter_input_text = model; // Match anywhere in the NickName entry in the PPD: @@ -461,6 +482,12 @@ // so that this item can be preselected: y2milestone( "Preselected connection: '%1'", Printer::connections[Printer::selected_connections_index]:$[] ); UI::ChangeWidget( `connection_selection, `CurrentItem, `id(Printer::selected_connections_index) ); + // In contrast to BasicAddDialog fake user input of a connection_selection here only + // when a connection was preselected because initially drivers are shown which + // match to the description of the queue which is to be modified here + // but when the user had used the Connection Wizard, a different connection + // becomes usually preselected and this requires different drivers to be shown: + UI::FakeUserInput( `connection_selection ); } any ret = nil; while(true) @@ -789,7 +816,7 @@ // (there is only "Kyocera" but not "Kyocera Mita" in the known_manufacturers list). foreach( string known_manufacturer, Printer::known_manufacturers, - { if( manufacturer == tolower( known_manufacturer ) ) + { if( tolower( manufacturer ) == tolower( known_manufacturer ) ) { driver_filter_string = "^" + driver_filter_string; break; } @@ -808,17 +835,42 @@ } else { description_words = splitstring( description, " " ); - if( size( description_words ) > 2 ) - { model = description_words[0]:"" + " " - + description_words[1]:"" + " " - + description_words[2]:""; - } - if( size( description_words ) == 2 ) - { model = description_words[0]:"" + " " - + description_words[1]:""; + // In Printer.ycp and basicmodify.ycp there are lines like + // description = model + " with driver " + description; + // new_description = model + " with driver " + new_description; + // Avoid having "with" and/or "driver" in the model string: + description_words = filter( string word, + description_words, + { return( "with" != word && "driver" != word ); + } + ); + // Use the queue description only if its first word is actually a known manufacturer: + boolean description_starts_with_known_manufacturer = false; + foreach( string known_manufacturer, + Printer::known_manufacturers, + { if( tolower( description_words[0]:"" ) == tolower( known_manufacturer ) ) + { description_starts_with_known_manufacturer = true; + break; + } + } + ); + if( description_starts_with_known_manufacturer ) + { if( size( description_words ) > 2 ) + if( size( description_words ) > 2 ) + { model = description_words[0]:"" + " " + + description_words[1]:"" + " " + + description_words[2]:""; + } + if( size( description_words ) == 2 ) + { model = description_words[0]:"" + " " + + description_words[1]:""; + } + if( size( description_words ) == 1 ) + { model = description_words[0]:""; + } } - if( size( description_words ) == 1 ) - { model = description_words[0]:""; + else + { model = ""; } driver_filter_input_text = model; // Replace each sequence of spaces in driver_filter_input_text @@ -864,7 +916,7 @@ // (there is only "Kyocera" but not "Kyocera Mita" in the known_manufacturers list). foreach( string known_manufacturer, Printer::known_manufacturers, - { if( manufacturer == tolower( known_manufacturer ) ) + { if( tolower( manufacturer ) == tolower( known_manufacturer ) ) { driver_filter_string = "^" + driver_filter_string; break; } Modified: trunk/printer/src/connectionwizard.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/connectionwizard.ycp?... ============================================================================== --- trunk/printer/src/connectionwizard.ycp (original) +++ trunk/printer/src/connectionwizard.ycp Wed Dec 2 16:43:55 2009 @@ -159,17 +159,47 @@ && "unknown" != tolower( current_model_info ) ) { list <string> description_words = splitstring( current_model_info, " " ); - if( size( description_words ) > 2 ) - { current_model_info = description_words[0]:"" + " " - + description_words[1]:"" + " " - + description_words[2]:""; - } - if( size( description_words ) == 2 ) - { current_model_info = description_words[0]:"" + " " - + description_words[1]:""; + // In Printer.ycp and basicmodify.ycp there are lines like + // description = model + " with driver " + description; + // new_description = model + " with driver " + new_description; + // Avoid having "with" and/or "driver" in the current_model_info: + description_words = filter( string word, + description_words, + { return( "with" != word && "driver" != word ); + } + ); + // Use the queue description only if its first word is actually a known manufacturer: + boolean description_starts_with_known_manufacturer = false; + foreach( string known_manufacturer, + Printer::known_manufacturers, + { if( tolower( description_words[0]:"" ) == tolower( known_manufacturer ) ) + { description_starts_with_known_manufacturer = true; + break; + } + } + ); + if( description_starts_with_known_manufacturer ) + { if( size( description_words ) > 2 + && "with" != description_words[1]:"" + && "with" != description_words[2]:"" + && "driver" != description_words[2]:"" + ) + { current_model_info = description_words[0]:"" + " " + + description_words[1]:"" + " " + + description_words[2]:""; + } + if( size( description_words ) == 2 + && "with" != description_words[1]:"" + ) + { current_model_info = description_words[0]:"" + " " + + description_words[1]:""; + } + if( size( description_words ) == 1 ) + { current_model_info = description_words[0]:""; + } } - if( size( description_words ) == 1 ) - { current_model_info = description_words[0]:""; + else + { current_model_info = ""; } } } @@ -1845,6 +1875,13 @@ case(`lpd): case(`lpr): string lpd_hostname = (string)UI::QueryWidget( `hostname, `Value ); + if( ! issubstring( lpd_hostname, "@" ) ) + { // It would be wrong to do URIpercentEncoding(lpd_hostname) + // when it contains a '@' because a lpd URI can be of the form + // lpd://username@ip-address-or-hostname/... + // see https://bugzilla.novell.com/show_bug.cgi?id=512549 + lpd_hostname = URIpercentEncoding( lpd_hostname ); + } string lpd_queue = (string)UI::QueryWidget( `port_or_queue, `Value ); string lpd_uri_options = (string)UI::QueryWidget( `uri_options, `Value ); if( "" != filterchars( lpd_hostname, Printer::alnum_chars ) @@ -1856,14 +1893,14 @@ // must stay as is and not be percent encoded because lpd_uri_options // contains all options like 'option1=value1&option2=value2'. connection_uri = sformat( "lpd://%1/%2?%3", - URIpercentEncoding( lpd_hostname ), + lpd_hostname, URIpercentEncoding( lpd_queue ), lpd_uri_options ); } else { connection_uri = sformat( "lpd://%1/%2", - URIpercentEncoding( lpd_hostname ), + lpd_hostname, URIpercentEncoding( lpd_queue ) ); } @@ -1875,6 +1912,14 @@ break; case(`cups): string cups_hostname = (string)UI::QueryWidget( `hostname, `Value ); + if( ! issubstring( cups_hostname, "@" ) ) + { // It would be wrong to do URIpercentEncoding(cups_hostname) + // when it contains a '@' because a ipp/http URI can be of the form + // ipp://username:password@ip-address-or-hostname/... + // http://username:password@ip-address-or-hostname/... + // see https://bugzilla.novell.com/show_bug.cgi?id=512549 + cups_hostname = URIpercentEncoding( cups_hostname ); + } string cups_queue = (string)UI::QueryWidget( `queue, `Value ); string cups_uri_options = (string)UI::QueryWidget( `uri_options, `Value ); if( "" != filterchars( cups_hostname, Printer::alnum_chars ) @@ -1886,14 +1931,14 @@ // must stay as is and not be percent encoded because cups_uri_options // contains all options like 'option1=value1&option2=value2'. connection_uri = sformat( "ipp://%1/printers/%2?%3", - URIpercentEncoding( cups_hostname ), + cups_hostname, URIpercentEncoding( cups_queue ), cups_uri_options ); } else { connection_uri = sformat( "ipp://%1/printers/%2", - URIpercentEncoding( cups_hostname ), + cups_hostname, URIpercentEncoding( cups_queue ) ); } @@ -2240,22 +2285,76 @@ return true; } -boolean storeQueue( symbol selected ) +boolean UpdateConnectionsList( symbol selected ) { if( "" == connection_uri ) { return false; } if( "" == connection_model ) { connection_model = "Unknown"; } - y2internal( "storeQueue storing type '%1' with uri '%2' for model '%3'", selected, connection_uri, connection_model ); - Printer::connections = add( Printer::connections, - $[ "uri" : connection_uri, - "model" : connection_model, - "deviceID" : "", - "info" : "created by the connection wizard", - "class" : "ConnectionWizardDialog" - ] - ); + // Avoid duplicate URIs because Printer::current_device_uri must point to a unique URI + // otherwise preselection in BasicAddDialog and BasicModifyDialog would be ambiguous. + // If an URI already exists, update its matching entry in the Printer::connections list. + // Usually there should not exist duplicate URIs in the Printer::connections list + // (in contrast duplicate URIs in the Printer::queues list are perfectly o.k.) + // but if duplicate URIs exist in Printer::connections, all those entries are updated. + boolean uri_already_exists = false; +/* + // I do not know if it is allowed to modify one same list "in place" via foreach: + integer connections_index = -1; + foreach( map< string, string > connection_entry, + Printer::connections, + { // Set the connections_index to the index number of the current connection_entry: + connections_index = connections_index + 1; + // If the URI already exists, update its matching entry in the Printer::connections list: + if( connection_uri == connection_entry["uri"]:"" ) + { uri_already_exists = true; + y2internal( "UpdateConnectionsList: modify connections list type '%1' with uri '%2' for model '%3'", selected, connection_uri, connection_model ); + Printer::connections[connections_index,"model"] = connection_model; + // Leave te values for deviceID, info, and class unchanged because when the URI is the same + // those values still match to the URI and therefore should also stay the same. + } + } + ); +*/ + Printer::connections = maplist( map< string, string > connection_entry, + Printer::connections, + { if( connection_uri == connection_entry["uri"]:"" ) + { uri_already_exists = true; + y2internal( "UpdateConnectionsList: modify connections list type '%1' with uri '%2' for model '%3'", selected, connection_uri, connection_model ); + return $[ "uri" : connection_uri, + "model" : connection_model, + "deviceID" : "", + "info" : "modified by the connection wizard", + "class" : "ConnectionWizardDialog" + ]; + } + else + { return connection_entry; + } + } + ); + if( ! uri_already_exists ) + { y2internal( "UpdateConnectionsList: adding connection type '%1' with uri '%2' for model '%3'", selected, connection_uri, connection_model ); + Printer::connections = add( Printer::connections, + $[ "uri" : connection_uri, + "model" : connection_model, + "deviceID" : "", + "info" : "created by the connection wizard", + "class" : "ConnectionWizardDialog" + ] + ); + } + // Set Printer::current_device_uri so that BasicAddDialog and BasicModifyDialog + // can preselect the currently used connection when calling Printer::ConnectionItems(...) + // which sets Printer::selected_connections_index if it matches to Printer::current_device_uri. + // It makes sense to have the currently used connection from the ConnectionWizardDialog + // preselected also in BasicModifyDialog because when the user launched the Connection Wizard + // from the BasicModifyDialog he wants to change the connection so that it is sufficiently safe + // to have the changed connection preselected when he is back in the BasicModifyDialog + // so that the connection would get changed in the system without explicite selection + // by the user in the BasicModifyDialog if the user clicks "OK" in the BasicModifyDialog. + Printer::current_device_uri = connection_uri; return true; } @@ -2274,7 +2373,7 @@ && validateModel( selected ) ) { y2milestone( "ConnectionWizardDialog writing settings" ); - storeQueue( selected ); + UpdateConnectionsList( selected ); } else { y2error( "ConnectionWizardDialog: Could not validate for '%1'", selected ); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
jsmeix@svn.opensuse.org