Module: Yast::PrinterBasicmodifyInclude
- Defined in:
- ../../src/include/printer/basicmodify.rb
Instance Method Summary (collapse)
-
- (Object) BasicModifyDialog
BasicModifyDialog dialog.
- - (Object) initialize_printer_basicmodify(include_target)
Instance Method Details
- (Object) BasicModifyDialog
BasicModifyDialog dialog
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 |
# File '../../src/include/printer/basicmodify.rb', line 46 def BasicModifyDialog Builtins.y2milestone( "entering BasicModifyDialog for queue '%1'", Ops.get(Printer.queues, Printer.selected_queues_index, {}) ) any_model_driver_filter_input_text = _("any model") non_matching_fallback_driver_filter_string = "qqqqqqqqqq" commandline = "" name = Ops.get( Printer.queues, [Printer.selected_queues_index, "name"], "" ) uri = Ops.get(Printer.queues, [Printer.selected_queues_index, "uri"], "") description = Ops.get( Printer.queues, [Printer.selected_queues_index, "description"], "" ) location = Ops.get( Printer.queues, [Printer.selected_queues_index, "location"], "" ) ppd = Ops.get(Printer.queues, [Printer.selected_queues_index, "ppd"], "") is_default = false if "yes" == Ops.get( Printer.queues, [Printer.selected_queues_index, "default"], "" ) is_default = true end accepting_jobs = true if "yes" == Ops.get( Printer.queues, [Printer.selected_queues_index, "rejecting"], "" ) accepting_jobs = false end printing_enabled = true if "yes" == Ops.get( Printer.queues, [Printer.selected_queues_index, "disabled"], "" ) printing_enabled = false end # Title of the Basic Modify Dialog where %1 will be replaced by the queue name. # The actual queue name is a system value which cannot be translated: caption = Builtins.sformat(_("Modify %1"), name) # Clear whatever content of a previous dialog which would show up here for several seconds # until all the following stuff is done before Wizard::SetContentsButtons is called # which finally shows the right content for this dialog. Wizard.SetContents( caption, Empty(), Ops.get_string(@HELPS, "basic_modify_dialog", ""), false, false ) Wizard.HideAbortButton model = Printer.DeriveModelName(description, 0) driver_filter_input_text = Printer.DeriveModelName(model, 0) driver_filter_string = Printer.DeriveDriverFilterString( driver_filter_input_text ) nick_name = "" = Empty() paper_choice_content = Empty() a4_paper_choice = false a4_default_paper = false = RadioButton(Id(:a4), Opt(:disabled), "A&4") letter_paper_choice = false letter_default_paper = false = RadioButton( Id(:letter), Opt(:disabled), "Le&tter" ) default_paper_size = "" # Only local queues can be selected in the overview dialog to be modified. # For a local raw queue ppd is the empty string. # For a local queue with a System V style interface script ppd is "/etc/cups/interfaces/<name-of-the-script>". # For a local queue with URI "ipp://server/printers/queue" ppd is "ipp://server/printers/queue.ppd". # For a normal local queue with URI "ipp://server/resource" ppd is "/etc/cups/ppd/<queue-name>.ppd". # For a normal local queue ppd is "/etc/cups/ppd/<queue-name>.ppd". # The leading part "/etc/" may vary depending on how the local cupsd # is installed or configured, see "/usr/bin/cups-config --serverroot". if "" != ppd commandline = Ops.add("test -r ", ppd) if Printerlib.ExecuteBashCommand(commandline) = PushButton( Id(:driver_options), # Label of a PushButton to go to a dialog # to set all available options for the printer driver # which is currently used for a print queue: _("All &Options for the Current Driver") ) else ppd = "" end end if Builtins.issubstring(ppd, "/cups/ppd/") # which suppresses it in certain "lpinfo -m" output. # Note the YCP quoting: \" becomes " and \\n becomes \n in the commandline. commandline = Ops.add( Ops.add("grep '^*NickName' ", ppd), " | cut -s -d '\"' -f2 | sed -e 's/(recommended)//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | tr -s ' ' | tr -d '\\n'" ) if Printerlib.ExecuteBashCommand(commandline) Builtins.y2milestone( "'%1' stdout (nick_name) is: '%2'", commandline, Ops.get_string(Printerlib.result, "stdout", "") ) nick_name = Ops.get_string(Printerlib.result, "stdout", "") driver_filter_input_text = Printer.DeriveModelName(nick_name, 0) driver_filter_string = Printer.DeriveDriverFilterString( driver_filter_input_text ) end if !Printer.DetermineDriverOptions("") # (e.g. the driver options from another previously modified queue): Printer. = [] end Builtins.foreach(Printer.) do |driver_option| if "PageSize" == Ops.get_string(driver_option, "keyword", "") Builtins.foreach(Ops.get_list(driver_option, "values", [])) do |value| if "*A4" == value default_paper_size = "A4" a4_default_paper = true = RadioButton(Id(:a4), "A&4", true) else if "A4" == value a4_paper_choice = true = RadioButton(Id(:a4), "A&4") else if "*Letter" == value default_paper_size = "Letter" letter_default_paper = true = RadioButton( Id(:letter), "Le&tter", true ) else if "Letter" == value letter_paper_choice = true = RadioButton( Id(:letter), "Le&tter" ) else if "*" == Builtins.substring(value, 0, 1) default_paper_size = Builtins.substring(value, 1) end end end end end end Builtins.y2milestone( "Default paper size is: '%1'", default_paper_size ) end end end # DefaultPageSize is required according to the Adobe PPD specification. # Nevertheless we don't rely on correct PPDs (e.g. whatever "third-party" PPDs) # and test if it really exists in the actually used PPD: if "" != default_paper_size default_paper_size_label = _("Default Paper Size of the Current Driver") if a4_default_paper || letter_default_paper paper_choice_content = RadioButtonGroup( Id(:paper_size_radio_buttons), HBox( Label(default_paper_size_label), HSpacing(2), , HSpacing(1), ) ) else if a4_paper_choice || letter_paper_choice paper_choice_content = RadioButtonGroup( Id(:paper_size_radio_buttons), HBox( Label( Ops.add( Ops.add( Ops.add(default_paper_size_label, ": "), default_paper_size ), " " ) ), HSpacing(2), , HSpacing(1), ) ) else paper_choice_content = Label( Ops.add( Ops.add(default_paper_size_label, ": "), default_paper_size ) ) end end end # If the currently used driver is replaced by another driver, # show the same content as in the BasicAddDialog to set the default paper size: new_driver_paper_choice_content = RadioButtonGroup( Id(:paper_size_radio_buttons), HBox( Label(_("Default paper size (if printer and driver supports it)")), # Label of a RadioButtonGroup to specify the default paper size: # Have none of the RadioButtons preselected which means that # by default the CUPS default is used for the default paper size. # For the CUPS 1.3 default see http://www.cups.org/str.php?L2846 # For CUPS 1.4 the default depends on the "DefaultPaperSize" # setting in cupsd.conf # see https://bugzilla.novell.com/show_bug.cgi?id=395760 # and http://www.cups.org/str.php?L2848 HSpacing(2), RadioButton(Id(:a4), "A&4"), HSpacing(1), RadioButton(Id(:letter), "Le&tter"), HStretch() ) ) # Usually the id in the connection items is the matching index number in the connections list. # Here the id of the current connection is set to -1 because the uri of the current connection # is derived from the queues list and this uri may be not present in the connections list # for example when the queue has a special non-autodetectable DeviceURI (e.g. for iPrint) # or when the queue is for an USB printer which is currently not connected (e.g. a laptop user). # Therefore -1 (which means "invalid index number in the connections list") is used to be safe # and additionally -1 is used to distinguish when the current connection is kept # or when the connection was modified (then the id would be > 0 and valid in the connections list). # The current_connection item is preselected because it is the first entry in the # table of connections via prepend(): current_connection = Item( Id(-1), _("Current Connection") + ": ", Ops.add(uri, " "), description ) # Usually the id in the driver items is the matching index number in the ppds list. # Here the id of the current driver is set to -1 because the ppd for the current driver # is derived from the queues list and this ppd may be not present in the ppds list # for example when the queue has a ppd which is not in /usr/share/cups/model/ (e.g. a manually set up queue) # or when the ppd for the queue in /etc/cups/ppd/ was modified (e.g. different default option settings). # Therefore -1 (which means "invalid index number in the ppds list") is used to be safe # and additionally -1 is used to distinguish when the current driver is kept # or when the driver was modified (then the id would be > 0 and valid in the ppds list). # Furthermore the current_driver item is preselected via the additional "true". current_driver = Item( Id(-1), # Do not change or translate "raw", it is a technical term when no driver is used. # Do not change or translate "System V style interface script", it is a technical term. _( "No driver is used (it is a 'raw' queue or a 'System V style interface script' is used)" ), true ) if "" != nick_name current_driver = Item( Id(-1), Ops.add(_("Current Driver") + ": ", nick_name), true ) end if "" == driver_filter_string # to avoid that the full list of thousands of PPDs is shown automatically # because it can take a very long time until the user can proceed: driver_filter_input_text = _("Enter your printer model here.") driver_filter_string = non_matching_fallback_driver_filter_string end contents = VBox( VBox( HBox( Label(_("Connection")), # Caption for a Table with a list of printer connections: HStretch(), PushButton( Id(:more_connections), # Label of a PushButton to restart printer autodetection # to show more available printer connections # in the Table with a list of printer connections: _("&Detect More") ), PushButton( Id(:connection_wizard), # Label of a PushButton to go to the "Connection Wizard" # to specify the printer connection individually: _("Connection &Wizard") ) ), ReplacePoint( Id(:connection_selection_replace_point), Table( Id(:connection_selection), # By default there is no UserInput() # if only something was selected in the Table # (without clicking additionally a button) # but the notify and immediate options # forces UserInput() in this case: Opt(:notify, :immediate, :keepSorting), # Headers of a Table with a list of printer connections: Header( # Printer model name: _("Model"), # Header of a Table column with a list of printer connections. # Connection of the printer (e.g. via USB or via parallel port): _("Connection"), # Header of a Table column with a list of printer connections. # Additional description of the printer or its particular connection: _("Description") ), # Header of a Table column with a list of printer connections. Builtins.prepend( Printer.ConnectionItems("BasicAddDialog"), current_connection ) ) ) ), VStretch(), VBox( Left( Label( _( "Adjust Options of the Current Driver or Assign a Different Driver" ) ) # Caption for a printer driver selection: ), ReplacePoint( Id(:paper_choice_and_driver_options_replace_point), VBox(Left(paper_choice_content), Left()) ), HBox( ReplacePoint( Id(:apply_driver_filter_replace_point), PushButton( Id(:apply_driver_filter), # This button must be the default # (it is activated when the user pressed the Enter key) # because when the user has clicked into InputField to enter something # it is normal to finish entering by pressing the Enter key # but if the Enter key was linked to 'Next' or 'Back', # the user would get the wrong action. Opt(:default), # Label of a PushButton to search a list for a search string # and then show the search result: _("&Search for") ) ), ReplacePoint( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", # Make it lowercase to make it more obvious that this is a search string # which the user could change as needed and not a final fixed model name. # Many users do not understand that the model name which is preset here # (i.e. initially for this dialog and when the user selected a connection) # as search string can be changed by the user as needed to find drivers. Builtins.tolower(driver_filter_input_text) ) ), PushButton( Id(:more_drivers), # Label of a PushButton to find and show more available printer drivers: _("&Find More") ), PushButton( Id(:add_driver), # Label of a PushButton to go to the "Add Driver" dialog # to install or remove driver packages (and perhaps download it before): _("Driver &Packages") ) ), ReplacePoint( Id(:driver_selection_replace_point), SelectionBox( Id(:driver_selection), # By default there is no UserInput() # if only something was selected in the SelectionBox # (without clicking additionally a button) # but the notify option forces UserInput() in this case: Opt(:notify), "", Builtins.prepend( Printer.DriverItems(driver_filter_string, false), current_driver ) ) ) ), VStretch(), VBox( HBox( TextEntry( Id(:description_input), Opt(:hstretch), # Label of a TextEntry for a short printer driver description (only one line): _("Description &Text"), description ), HSpacing(2), TextEntry( Id(:location_input), Opt(:hstretch), # Label of a TextEntry for printer location string: _("&Location"), location ) ), Left( HBox( CheckBox( Id(:default_queue_checkbox), # CheckBox to set a local print queue to be the default queue: _("&Use as Default"), is_default ), HSpacing(2), CheckBox( Id(:accept_jobs_checkbox), # CheckBox to set a local print queue to accept print jobs: _("Accept Print &Jobs"), accepting_jobs ), HSpacing(2), CheckBox( Id(:enable_printing_checkbox), # CheckBox to enable printing for a local print queue: _("&Enable Printing"), printing_enabled ) ) ) ) ) # According to the YaST Style Guide (dated Thu, 06 Nov 2008) # there is no longer a "abort" functionality which exits the whole module. # Instead this button is now named "Cancel" and its functionality is # to go back to the Overview dialog (i.e. what the "back" button would do) # because it reads "Cancel - Closes the window and returns to the overview." # Therefore the button with the "abort" functionality is not shown at all # and the button with the "back" functionality is named "Cancel". # According to the YaST Style Guide (dated Thu, 06 Nov 2008) # the "finish" button in a single (step) configuration dialog must now be named "OK". Wizard.SetContentsButtons( caption, contents, Ops.get_string(@HELPS, "basic_modify_dialog", ""), # Set a new label for the "back" button, see the comment above: Label.CancelButton, # Set a new label for the "next" button, see the comment above: Label.OKButton ) Wizard.HideAbortButton # Try to preselect the connection which matches to the current_device_uri # if such a connection exists in the connection_selection table: if Ops.greater_or_equal(Printer.selected_connections_index, 0) # exists in the connection_selection table because the Printer::ConnectionItems function # sets Printer::selected_connections_index != -1 only if such an item exists in the table # so that this item can be preselected: Builtins.y2milestone( "Preselected connection: '%1'", Ops.get(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) end user_input = nil while true # (the default widget is the result of UI::UserInput when the user pressed the Enter key) # regardless whatever function call or UI bug (e.g. bnc#558900) may have changed the default widget: UI.ReplaceWidget( Id(:apply_driver_filter_replace_point), PushButton( Id(:apply_driver_filter), # This button must be the default # (it is activated when the user pressed the Enter key) # because when the user has clicked into InputField to enter something # it is normal to finish entering by pressing the Enter key # but if the Enter key was linked to 'Next' or 'Back', # the user would get the wrong action. Opt(:default), # Label of a PushButton to search a list for a search string # and then show the search result: _("&Search for") ) ) if :apply_driver_filter == user_input # set the focus to the InputField for the driver search string # so that the user can just continue typing other search strings. # In contrast when the user is not already searching drivers, # it is annoying in particular in the text-only ncurses UI # when the focus becomes always set to the driver search string InputField. UI.SetFocus(:driver_filter_input) end # Wait for user input: user_input = UI.UserInput if :abort == user_input || :cancel == user_input || :back == user_input break end if :next == user_input commandline = Ops.add( Ops.add("/usr/sbin/lpadmin -h localhost -p '", name), "'" ) something_has_changed = false set_paper_size_later = false selected_connection_index = Convert.to_integer( UI.QueryWidget(Id(:connection_selection), :CurrentItem) ) if Ops.greater_or_equal(selected_connection_index, 0) uri = Ops.get( Printer.connections, [selected_connection_index, "uri"], "" ) if "" != uri commandline = Ops.add( Ops.add(Ops.add(commandline, " -v '"), uri), "'" ) Printer.current_device_uri = uri something_has_changed = true end end selected_ppd_index = Convert.to_integer( UI.QueryWidget(Id(:driver_selection), :CurrentItem) ) if Ops.greater_or_equal(selected_ppd_index, 0) ppd = Ops.get(Printer.ppds, [selected_ppd_index, "ppd"], "") if "" != ppd commandline = Ops.add( Ops.add(Ops.add(commandline, " -m '"), ppd), "'" ) something_has_changed = true # The paper size for a new driver will be only set # after the new driver was actually successfully set: set_paper_size_later = true end else # Depending on the currently used driver no paper size selection might exists # in particular not for a 'raw' queue or when a 'System V style interface script' is used: if UI.WidgetExists(Id(:paper_size_radio_buttons)) paper_size = UI.QueryWidget( Id(:paper_size_radio_buttons), :CurrentButton ) if :a4 == paper_size && "A4" != default_paper_size commandline = Ops.add(commandline, " -o PageSize=A4") something_has_changed = true end if :letter == paper_size && "Letter" != default_paper_size commandline = Ops.add(commandline, " -o PageSize=Letter") something_has_changed = true end end end description_input = Convert.to_string( UI.QueryWidget(Id(:description_input), :Value) ) # Delete ' characters because they are used for quoting in the bash commandline: description_input = Builtins.deletechars(description_input, "'") # Leading and/or trailing and/or sequences of spaces look ugly and are condensed here: description_input = Builtins.mergestring( Builtins.filter(Builtins.splitstring(description_input, " ")) do |word| "" != word end, " " ) if description_input != description commandline = Ops.add( Ops.add(Ops.add(commandline, " -D '"), description_input), "'" ) something_has_changed = true end location_input = Convert.to_string( UI.QueryWidget(Id(:location_input), :Value) ) # Delete ' characters because they are used for quoting in the bash commandline: location_input = Builtins.deletechars(location_input, "'") # Leading and/or trailing and/or sequences of spaces look ugly and are condensed here: location_input = Builtins.mergestring( Builtins.filter(Builtins.splitstring(location_input, " ")) do |word| "" != word end, " " ) if location_input != location commandline = Ops.add( Ops.add(Ops.add(commandline, " -L '"), location_input), "'" ) something_has_changed = true end is_default_input = Convert.to_boolean( UI.QueryWidget(Id(:default_queue_checkbox), :Value) ) if is_default_input != is_default something_has_changed = true if is_default_input # with other option settings so that a separate lpadmin command is called: commandline = Ops.add( Ops.add( Ops.add(commandline, " ; /usr/sbin/lpadmin -h localhost -d '"), name ), "'" ) else # see http://www.cups.org/newsgroups.php?gcups.general+v:31874 # All one can do is set up a dummy queue, make it the default, and remove it. # To be on the safe side the dummy queue neither accepts jobs # nor is printing enabled (no '-E' as last lpadmin option) # nor is it announced ("shared") to whatever BrowseAddress in cupsd.conf. # Here I assume blindly that no queue "yast2unsetdefaultqueue" exists. commandline = Ops.add( Ops.add( Ops.add( commandline, " ; /usr/sbin/lpadmin -h localhost -p yast2unsetdefaultqueue -v file:/dev/null -o printer-is-shared=false" ), " ; /usr/sbin/lpadmin -h localhost -d yast2unsetdefaultqueue" ), " ; /usr/sbin/lpadmin -h localhost -x yast2unsetdefaultqueue" ) end end accepting_jobs_input = Convert.to_boolean( UI.QueryWidget(Id(:accept_jobs_checkbox), :Value) ) if accepting_jobs_input != accepting_jobs something_has_changed = true if accepting_jobs_input commandline = Ops.add( Ops.add( Ops.add(commandline, " ; /usr/sbin/accept -h localhost '"), name ), "'" ) else commandline = Ops.add( Ops.add( Ops.add(commandline, " ; /usr/sbin/reject -h localhost '"), name ), "'" ) end end printing_enabled_input = Convert.to_boolean( UI.QueryWidget(Id(:enable_printing_checkbox), :Value) ) if printing_enabled_input != printing_enabled something_has_changed = true if printing_enabled_input commandline = Ops.add( Ops.add( Ops.add(commandline, " ; /usr/sbin/cupsenable -h localhost '"), name ), "'" ) else commandline = Ops.add( Ops.add( Ops.add( commandline, " ; /usr/sbin/cupsdisable -h localhost '" ), name ), "'" ) end end if something_has_changed Wizard.DisableBackButton Wizard.DisableNextButton if !Printerlib.ExecuteBashCommand(commandline) Popup.ErrorDetails( # 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). Builtins.sformat(_("Failed to modify %1."), name), Ops.get_string(Printerlib.result, "stderr", "") ) else # after a new driver was actually successfully set. if set_paper_size_later # in particular not for a 'raw' queue or when a 'System V style interface script' is used. # When a driver is set for a 'raw' queue or for a queue with a 'System V style interface script', # it is therefore not possible to set the default paper size for the new driver now # so that the user would have to run the modify dialog again to do this. if UI.WidgetExists(Id(:paper_size_radio_buttons)) default_paper_size = "" paper_size = UI.QueryWidget( Id(:paper_size_radio_buttons), :CurrentButton ) default_paper_size = "A4" if :a4 == paper_size default_paper_size = "Letter" if :letter == paper_size # Try to set the requested default_paper_size if it is an available choice for this queue. # If no default_paper_size is requested, the CUPS default is used. # For the CUPS 1.3 default see http://www.cups.org/str.php?L2846 # For CUPS 1.4 the default depends on the "DefaultPaperSize" setting in cupsd.conf # see https://bugzilla.novell.com/show_bug.cgi?id=395760 # and http://www.cups.org/str.php?L2848 if "" != default_paper_size # Note the YCP quoting: \\< becomes \< and \\> becomes \> in the commandline. commandline = Ops.add( Ops.add( Ops.add( Ops.add("lpoptions -h localhost -p '", name), "' -l | grep '^PageSize.*\\<" ), default_paper_size ), "\\>'" ) if Printerlib.ExecuteBashCommand(commandline) commandline = Ops.add( Ops.add( Ops.add( Ops.add("/usr/sbin/lpadmin -h localhost -p '", name), "' -o 'PageSize=" ), default_paper_size ), "'" ) # Do not care if it fails to set the default_paper_size (i.e. show no error message to the user) # because the default_paper_size setting is nice to have but not mandatoty for a working queue: Printerlib.ExecuteBashCommand(commandline) end end end end end # Since CUPS 1.4 the new DirtyCleanInterval directive controls the delay when cupsd updates config files: if !Printerlib.WaitForUpdatedConfigFiles( _("Modifying Printer Setup") ) Popup.WarningDetails( _("Modified Printer Configuration not yet Stored in the System"), # Explanation details of a Popup::WarningDetails. # The 'next dialog' is the overview dialog where the printer configurations are shown # which has a 'Refresh List' button to update the shown printer configurations: _( "If the next dialog does not show the expected modifications, wait some time and use the 'Refresh List' button." ) ) end Wizard.EnableBackButton Wizard.EnableNextButton else Builtins.y2milestone("Nothing changed in 'Modify' dialog.") end # Exit this dialog in any case: break end break if :connection_wizard == user_input break if :add_driver == user_input if :driver_options == user_input if Ops.less_than(Printer.selected_queues_index, 0) || "" == Ops.get( Printer.queues, [Printer.selected_queues_index, "name"], "" ) || "remote" == Ops.get( Printer.queues, [Printer.selected_queues_index, "config"], "remote" ) Popup.AnyMessage( _("No driver options available"), # Body of a Popup::AnyMessage when "Driver Options" was selected: _( "Possible reasons: Nothing selected or it is a remote configuration." ) ) next end # Take a changed paper size setting into account. # The Printer::DriverOptionItems call stores the current setting # in Printer::driver_options so that it is known the DriverOptionsDialog if UI.WidgetExists(Id(:paper_size_radio_buttons)) paper_size = UI.QueryWidget( Id(:paper_size_radio_buttons), :CurrentButton ) if :a4 == paper_size && "A4" != default_paper_size Printer.DriverOptionItems("PageSize", "A4") end if :letter == paper_size && "Letter" != default_paper_size Printer.DriverOptionItems("PageSize", "Letter") end end # Exit this dialog and go to the DriverOptionsDialog via the sequencer in wizards.ycp: break end if :more_connections == user_input UI.ReplaceWidget( Id(:connection_selection_replace_point), Table( Id(:connection_selection), # By default there is no UserInput() # if only something was selected in the Table # (without clicking additionally a button) # but the notify and immediate options # forces UserInput() in this case: Opt(:notify, :immediate, :keepSorting), # Headers of a Table with a list of printer connections: Header( # Printer model name: _("Model"), # Header of a Table column with a list of printer connections. # Connection of the printer (e.g. via USB or via parallel port): _("Connection"), # Header of a Table column with a list of printer connections. # Additional description of the printer or its particular connection: _("Description") ), # Header of a Table column with a list of printer connections. Builtins.prepend( Printer.ConnectionItems("MoreConnections"), current_connection ) ) ) # Try to preselect the connection which matches to the current_device_uri # if such a connection exists in the connection_selection table: if Ops.greater_or_equal(Printer.selected_connections_index, 0) # exists in the connection_selection table because the Printer::ConnectionItems function # sets Printer::selected_connections_index != -1 only if such an item exists in the table # so that this item can be preselected: Builtins.y2milestone( "Preselected connection: '%1'", Ops.get( Printer.connections, Printer.selected_connections_index, {} ) ) UI.ChangeWidget( :connection_selection, :CurrentItem, Id(Printer.selected_connections_index) ) end UI.FakeUserInput(:connection_selection) next end if :connection_selection == user_input selected_connection_index = Convert.to_integer( UI.QueryWidget(Id(:connection_selection), :CurrentItem) ) if nil == selected_connection_index Popup.AnyMessage( _("No Connection Selected"), # Body of a Popup::AnyMessage when no connection was selected: _("Select a connection.") ) next end # selected_connection_index is -1 for the currently used connection # which is an invalid index in the connections list because # it means that the connection is not to be exchanged. # To be safe that the currently used connection cannot be exchanged # Printer::selected_connections_index is set to -1 in this case. if selected_connection_index != Printer.selected_connections_index Printer.selected_connections_index = selected_connection_index Printer.current_device_uri = Ops.get( Printer.connections, [selected_connection_index, "uri"], "" ) Builtins.y2milestone( "Selected connection is: %1", Ops.get(Printer.connections, selected_connection_index, {}) ) # Invalidate any previously selected driver, if a connection is selected anew # or if a previously selected connection had changed: Printer.selected_ppds_index = -1 end if Ops.greater_or_equal(selected_connection_index, 0) # derive the driver_filter_string from the model of the new connection: driver_filter_string = "" driver_filter_input_text = "" model = Ops.get( Printer.connections, [Printer.selected_connections_index, "model"], "" ) Builtins.y2milestone("Drivers for '%1'", model) if "" != model && "unknown" != Builtins.tolower(model) driver_filter_input_text = Printer.DeriveModelName(model, 0) driver_filter_string = Printer.DeriveDriverFilterString( driver_filter_input_text ) end else # derive the driver_filter_string from the NickName of the currently used PPD # or derive the driver_filter_string from the description of the currently used connection: if "" != nick_name driver_filter_input_text = Printer.DeriveModelName(nick_name, 0) else model = Printer.DeriveModelName(description, 0) driver_filter_input_text = Printer.DeriveModelName(model, 0) end driver_filter_string = Printer.DeriveDriverFilterString( driver_filter_input_text ) end if "" == driver_filter_string # to avoid that the full list of thousands of PPDs is shown automatically # because it can take a very long time until the user can proceed: driver_filter_input_text = _("Enter your printer model here.") driver_filter_string = non_matching_fallback_driver_filter_string end UI.ReplaceWidget( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", # Make it lowercase to make it more obvious that this is a search string # which the user could change as needed and not a final fixed model name. # Many users do not understand that the model name which is preset here # (i.e. initially for this dialog and when the user selected a connection) # as search string can be changed by the user as needed to find drivers. Builtins.tolower(driver_filter_input_text) ) ) UI.ReplaceWidget( Id(:driver_selection_replace_point), SelectionBox( Id(:driver_selection), # By default there is no UserInput() # if only something was selected in the SelectionBox # (without clicking additionally a button) # but the notify option forces UserInput() in this case: Opt(:notify), "", Builtins.prepend( Printer.DriverItems(driver_filter_string, false), current_driver ) ) ) # Do the same as if user_input == `driver_selection # but don't show a popup if nil == selected_ppd_index: selected_ppd_index = Convert.to_integer( UI.QueryWidget(Id(:driver_selection), :CurrentItem) ) next if nil == selected_ppd_index # selected_ppd_index is -1 for the currently used driver # which is an invalid index in the ppds list because # it means that the driver is not to be exchanged. # To be safe that the currently used driver cannot be exchanged # Printer::selected_ppds_index is set to -1 in this case. if selected_ppd_index != Printer.selected_ppds_index Printer.selected_ppds_index = selected_ppd_index if Ops.greater_or_equal(selected_ppd_index, 0) Builtins.y2milestone( "Selected driver is: %1", Ops.get(Printer.ppds, selected_ppd_index, {}) ) else if "" != nick_name Builtins.y2milestone( "Selected currently used driver: '%1'", nick_name ) else Builtins.y2milestone( "Selected currently used driver: No driver is used (it is a 'raw' queue or a 'System V style interface script' is used)" ) end end end if Ops.greater_or_equal(selected_ppd_index, 0) # the widgets to change options for the currently used driver are removed: UI.ReplaceWidget( Id(:paper_choice_and_driver_options_replace_point), Empty() ) else # the widgets to change options for the currently used driver are recreated: UI.ReplaceWidget( Id(:paper_choice_and_driver_options_replace_point), VBox(Left(paper_choice_content), Left()) ) end next end if :driver_selection == user_input selected_ppd_index = Convert.to_integer( UI.QueryWidget(Id(:driver_selection), :CurrentItem) ) if nil == selected_ppd_index Popup.AnyMessage( _("No Driver Selected"), # Body of a Popup::AnyMessage when no driver was selected: _("Select a driver.") ) next end # selected_ppd_index is -1 for the currently used driver # and also for a possible dummy entry "Select a driver" which is inserted # by the DriverItems function when no driver was preselected. # -1 is an invalid index in the ppds list and # it means that the driver is not to be exchanged. # To be safe that the currently used driver cannot be exchanged # Printer::selected_ppds_index is set to -1 in this case. if selected_ppd_index != Printer.selected_ppds_index Printer.selected_ppds_index = selected_ppd_index if Ops.greater_or_equal(selected_ppd_index, 0) Builtins.y2milestone( "Selected driver is: %1", Ops.get(Printer.ppds, selected_ppd_index, {}) ) else if "" != nick_name Builtins.y2milestone( "Selected currently used driver: '%1'", nick_name ) else Builtins.y2milestone( "Selected currently used driver: No driver is used (it is a 'raw' queue or a 'System V style interface script' is used)" ) end end end if Ops.greater_or_equal(selected_ppd_index, 0) # the widgets to change options for the currently used driver are removed and # the description_input field is overwritten with the NickName of the new selected driver: #UI::ReplaceWidget( `id(`paper_choice_and_driver_options_replace_point), `Empty() ); UI.ReplaceWidget( Id(:paper_choice_and_driver_options_replace_point), Left(new_driver_paper_choice_content) ) new_description = Ops.get( Printer.ppds, [selected_ppd_index, "nickname"], "" ) if "" != model && "unknown" != Builtins.tolower(model) new_description = Ops.add( Ops.add(model, " with driver "), new_description ) end # Delete ' characters because they are used for quoting in the bash commandline: new_description = Builtins.deletechars(new_description, "'") UI.ChangeWidget(Id(:description_input), :Value, new_description) else # the widgets to change options for the currently used driver are recreated and # the description_input field is restored with the current description of the queue: UI.ReplaceWidget( Id(:paper_choice_and_driver_options_replace_point), VBox(Left(paper_choice_content), Left()) ) UI.ChangeWidget(Id(:description_input), :Value, description) end next end if :apply_driver_filter == user_input driver_filter_input_text = Convert.to_string( UI.QueryWidget(Id(:driver_filter_input), :Value) ) Builtins.y2milestone("Drivers for '%1'", driver_filter_input_text) if any_model_driver_filter_input_text == driver_filter_input_text driver_filter_input_text = "" end driver_filter_string = Printer.DeriveDriverFilterString( driver_filter_input_text ) if "" == driver_filter_string driver_filter_input_text = any_model_driver_filter_input_text end UI.ReplaceWidget( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", driver_filter_input_text ) ) UI.ReplaceWidget( Id(:driver_selection_replace_point), SelectionBox( Id(:driver_selection), # By default there is no UserInput() # if only something was selected in the SelectionBox # (without clicking additionally a button) # but the notify option forces UserInput() in this case: Opt(:notify), "", Builtins.prepend( Printer.DriverItems(driver_filter_string, false), current_driver ) ) ) next end if :more_drivers == user_input if non_matching_fallback_driver_filter_string != driver_filter_string driver_filter_string = "" end valid_driver_found = false driver_items = [] # Use the existing value of driver_filter_input_text # which is usually set to nick_name and to model as fallback # but it could be any string which was entered before by the user. # The "more drivers" functionality must work based on the current search string # and when nothing is found based on the current search string # it falls back to show all drivers so that there is a valid result in any case. driver_filter_input_text = Convert.to_string( UI.QueryWidget(Id(:driver_filter_input), :Value) ) Builtins.y2milestone( "More drivers for '%1'", driver_filter_input_text ) if "" != driver_filter_input_text && "unknown" != Builtins.tolower(driver_filter_input_text) && any_model_driver_filter_input_text != driver_filter_input_text && non_matching_fallback_driver_filter_string != driver_filter_string manufacturer_and_model_number = Printer.DeriveModelName( driver_filter_input_text, 2 ) # Note that manufacturer_and_model_number may be the empty string # (when driver_filter_input_text does not contain word which contains a number) # or manufacturer_and_model_number may be only one word # (when driver_filter_input_text starts with a known manufacturer # but does not contain a word which contains a number # or when driver_filter_input_text does not start with a known manufacturer # but contains a word which contains a number). if "" != manufacturer_and_model_number && Builtins.issubstring(manufacturer_and_model_number, " ") UI.ReplaceWidget( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", manufacturer_and_model_number ) ) driver_filter_string = Printer.DeriveDriverFilterString( manufacturer_and_model_number ) if "" != driver_filter_string driver_items = Printer.DriverItems(driver_filter_string, true) # Printer::DriverItems may result a driver_items list with one single element # [ `item( `id( -1 ), _("No matching driver found.") ) ] # to show at least a meaningful text as fallback entry to the user # or Printer::DriverItems may result a driver_items list with the first item # [ `item( `id( -1 ), _("Select a driver.") ), ... ] # when Printer::DriverItems could not preselect a driver item. # If a valid driver was found (but perhaps none was preselected), # there would be a non-negative id value of the first or second element # which is driver_items[0,0,0] or driver_items[1,0,0] # (id[0] is the value of the id, see the comment in Printer::DriverItems). if Ops.greater_or_equal( Ops.get_integer(driver_items, [0, 0, 0], -1), 0 ) || Ops.greater_or_equal( Ops.get_integer(driver_items, [1, 0, 0], -1), 0 ) valid_driver_found = true end end end # Try to use only the manufacturer or only the model number when nothing was found above: if !valid_driver_found manufacturer_or_model_number = Printer.DeriveModelName( driver_filter_input_text, 1 ) if "" != manufacturer_or_model_number UI.ReplaceWidget( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", manufacturer_or_model_number ) ) driver_filter_string = Printer.DeriveDriverFilterString( manufacturer_or_model_number ) if "" != driver_filter_string driver_items = Printer.DriverItems(driver_filter_string, true) # Printer::DriverItems may result a driver_items list with one single element # [ `item( `id( -1 ), _("No matching driver found.") ) ] # to show at least a meaningful text as fallback entry to the user # or Printer::DriverItems may result a driver_items list with the first item # [ `item( `id( -1 ), _("Select a driver.") ), ... ] # when Printer::DriverItems could not preselect a driver item. # If a valid driver was found (but perhaps none was preselected), # there would be a non-negative id value of the first or second element # which is driver_items[0,0,0] or driver_items[1,0,0] # (id[0] is the value of the id, see the comment in Printer::DriverItems). if Ops.greater_or_equal( Ops.get_integer(driver_items, [0, 0, 0], -1), 0 ) || Ops.greater_or_equal( Ops.get_integer(driver_items, [1, 0, 0], -1), 0 ) valid_driver_found = true end end end end end # Nothing was found above. # Fall back to show all drivers: if !valid_driver_found UI.ReplaceWidget( Id(:driver_filter_input_replace_point), InputField( Id(:driver_filter_input), Opt(:hstretch), # No InputField header because there is the "Caption for a printer driver selection": "", any_model_driver_filter_input_text ) ) driver_items = Printer.DriverItems("", true) end UI.ReplaceWidget( Id(:driver_selection_replace_point), SelectionBox( Id(:driver_selection), # By default there is no UserInput() # if only something was selected in the SelectionBox # (without clicking additionally a button) # but the notify option forces UserInput() in this case: Opt(:notify), "", Builtins.prepend(driver_items, current_driver) ) ) next end Builtins.y2milestone( "Ignoring unexpected returncode in BasicModifyDialog: %1", user_input ) next end Builtins.y2milestone("leaving BasicModifyDialog") deep_copy(user_input) end |
- (Object) initialize_printer_basicmodify(include_target)
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File '../../src/include/printer/basicmodify.rb', line 30 def initialize_printer_basicmodify(include_target) Yast.import "UI" textdomain "printer" Yast.import "Label" Yast.import "Wizard" Yast.import "Printer" Yast.import "Printerlib" Yast.import "Popup" Yast.include include_target, "printer/helps.rb" end |