Module: Yast::PrinterConnectionwizardInclude

Defined in:
../../src/include/printer/connectionwizard.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) changeSettingsDialog(selected)



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
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
# File '../../src/include/printer/connectionwizard.rb', line 604

def changeSettingsDialog(selected)
  content = nil
  connection_content = nil
  model_content = nil
  current_device_uri = ""
  uri_parts = []
  hostname = ""
  port_or_queue = ""
  uri_options = ""
  uri = ""
  queue = ""
  domain = ""
  printer = ""
  user = ""
  pass = ""
  active_directory_support = false
  beh_do_not_disable = true
  beh_attempts = "0"
  beh_delay = "30"
  case selected
    when :parallel
      content = getContentFromBackend("parallel")
    when :usb
      content = getContentFromBackend("usb")
    when :hplip
      if !Printerlib.TestAndInstallPackage("hplip", "installed")
        # Only a notification but no installation of HPLIP in the Connection Wizard.
        # Installing the package hplip can pull in tons of required packages
        # because the hplip package does not only provide the 'hp' backend but is a
        # full featured multifunction solution with GUI for HP printers and all-in-one devices.
        # HPLIP supports printing, scanning, faxing, photo card access, and device management.
        # Additionally installing hplip can become very complicated (see driveradd.ycp).
        # Therefore the Connection Wizard is not bloated with installing HPLIP.
        Popup.Message(
          # in the Connection Wizard but the RPM package hplip is not installed:
          _(
            "To access a HP device via the 'hp' backend,\nthe RPM package hplip must be installed."
          )
        )
        content = VBox(
          Left(Label(_("The RPM package hplip is not installed.")))
        )
      else
        content = getContentFromBackend("hp")
      end
    when :serial
      current_device_uri = getCurrentDeviceURI
      @current_serial_device_node = ""
      @serial_device_node_items = []
      if "serial:/" ==
          Builtins.substring(
            current_device_uri,
            0,
            Builtins.size("serial:/")
          )
        # serial:/dev/ttyS6?baud=115200+bits=7+parity=space+flow=hard+stop=1
        # remove the scheme 'serial:' so that only '/dev/ttyS6' is left:
        @current_serial_device_node = Builtins.mergestring(
          Builtins.sublist(
            Builtins.splitstring(current_device_uri, ":?"),
            1,
            1
          ),
          ""
        )
      end
      @current_serial_device_node_found = false
      Builtins.foreach(
        [
          "/dev/ttyS0",
          "/dev/ttyS1",
          "/dev/ttyS2",
          "/dev/ttyS3",
          "/dev/ttyS4",
          "/dev/ttyS5",
          "/dev/ttyS6",
          "/dev/ttyS7"
        ]
      ) do |device_node|
        if @current_serial_device_node == device_node
          @current_serial_device_node_found = true
          # Have the current serial device node preselected:
          @serial_device_node_items = Builtins.add(
            @serial_device_node_items,
            Item(Id(device_node), device_node, true)
          )
        else
          @serial_device_node_items = Builtins.add(
            @serial_device_node_items,
            Item(Id(device_node), device_node)
          )
        end
      end 

      if !@current_serial_device_node_found
        if "" == @current_serial_device_node
          # the CUPS serial backend may blindly write to any device:
          @serial_device_node_items = Builtins.prepend(
            @serial_device_node_items,
            Item(Id(""), "", true)
          )
        else
          @serial_device_node_items = Builtins.prepend(
            @serial_device_node_items,
            Item(
              Id(@current_serial_device_node),
              @current_serial_device_node,
              true
            )
          )
        end
      end
      @serial_baud_rate_items = []
      @serial_data_bits_items = []
      @serial_parity_items = []
      @serial_flow_control_items = []
      @serial_stop_bits_items = []
      if "serial:/" ==
          Builtins.substring(
            current_device_uri,
            0,
            Builtins.size("serial:/")
          )
        Builtins.foreach(
          # The Device URI has the form like:
          # serial:/dev/ttyS6?baud=115200+bits=7+parity=space+flow=hard+stop=1
          # remove all before the '?' so that only the parameters 'baud=115200+bits=7...' are left
          # as strings in a list like ["baud=115200","bits=7","parity=space","flow=hard","stop=1"]:
          Builtins.sublist(
            Builtins.splitstring(current_device_uri, "?+"),
            1
          )
        ) do |parameter|
          keyword_value = Builtins.splitstring(parameter, "=")
          keyword = Ops.get(keyword_value, 0, "")
          value = Ops.get(keyword_value, 1, "")
          value_found = false
          if "baud" == keyword
            Builtins.foreach(
              # The preset values are from backend/serial.c in the CUPS 1.3.9 sources:
              [
                "1200",
                "2400",
                "4800",
                "9600",
                "19200",
                "38400",
                "57600",
                "115200",
                "230400"
              ]
            ) do |item_value|
              if value == item_value
                value_found = true
                # Have the current value preselected:
                @serial_baud_rate_items = Builtins.add(
                  @serial_baud_rate_items,
                  Item(Id(item_value), item_value, true)
                )
              else
                @serial_baud_rate_items = Builtins.add(
                  @serial_baud_rate_items,
                  Item(Id(item_value), item_value)
                )
              end
            end 

            if !value_found
              if "" == value
                # the baud rate may have to be exactly what is set in the printer (e.g. via DIP switches):
                @serial_baud_rate_items = Builtins.prepend(
                  @serial_baud_rate_items,
                  Item(Id(""), "", true)
                )
              else
                # If the current value is none of them, it might be invalid or a typo.
                # Therefore the current value is added with an appropriate hint.
                # Nevertheless the current value must be topmost and preselected because
                # anything else which might be preselected (even an empty value)
                # would silently change the current value to the preselected one
                # when the user clicks [OK]:
                @serial_baud_rate_items = Builtins.prepend(
                  @serial_baud_rate_items,
                  Item(
                    Id(value),
                    Ops.add(value, " (might be invalid or a typo)"),
                    true
                  )
                )
              end
            end
          end
          if "bits" == keyword
            Builtins.foreach(
              # The preset values are from backend/serial.c in the CUPS 1.3.9 sources:
              ["7", "8"]
            ) do |item_value|
              if value == item_value
                value_found = true
                # Have the current value preselected:
                @serial_data_bits_items = Builtins.add(
                  @serial_data_bits_items,
                  Item(Id(item_value), item_value, true)
                )
              else
                @serial_data_bits_items = Builtins.add(
                  @serial_data_bits_items,
                  Item(Id(item_value), item_value)
                )
              end
            end 

            if !value_found
              if "" == value
                # the data bits may have to be exactly what is set in the printer (e.g. via DIP switches):
                @serial_data_bits_items = Builtins.prepend(
                  @serial_data_bits_items,
                  Item(Id(""), "", true)
                )
              else
                # If the current value is none of them, it might be invalid or a typo.
                # Therefore the current value is added with an appropriate hint.
                # Nevertheless the current value must be topmost and preselected because
                # anything else which might be preselected (even an empty value)
                # would silently change the current value to the preselected one
                # when the user clicks [OK]:
                @serial_data_bits_items = Builtins.prepend(
                  @serial_data_bits_items,
                  Item(
                    Id(value),
                    Ops.add(value, " (might be invalid or a typo)"),
                    true
                  )
                )
              end
            end
          end
          if "parity" == keyword
            Builtins.foreach(
              # The preset values are from backend/serial.c in the CUPS 1.3.9 sources:
              ["even", "odd", "none", "space", "mark"]
            ) do |item_value|
              if value == item_value
                value_found = true
                # Have the current value preselected:
                @serial_parity_items = Builtins.add(
                  @serial_parity_items,
                  Item(Id(item_value), item_value, true)
                )
              else
                @serial_parity_items = Builtins.add(
                  @serial_parity_items,
                  Item(Id(item_value), item_value)
                )
              end
            end 

            if !value_found
              if "" == value
                # the parity may have to be exactly what is set in the printer (e.g. via DIP switches):
                @serial_parity_items = Builtins.prepend(
                  @serial_parity_items,
                  Item(Id(""), "", true)
                )
              else
                # If the current value is none of them, it might be invalid or a typo.
                # Therefore the current value is added with an appropriate hint.
                # Nevertheless the current value must be topmost and preselected because
                # anything else which might be preselected (even an empty value)
                # would silently change the current value to the preselected one
                # when the user clicks [OK]:
                @serial_parity_items = Builtins.prepend(
                  @serial_parity_items,
                  Item(
                    Id(value),
                    Ops.add(value, " (might be invalid or a typo)"),
                    true
                  )
                )
              end
            end
          end
          if "flow" == keyword
            Builtins.foreach(
              # The preset values are from backend/serial.c in the CUPS 1.3.9 sources:
              ["none", "soft", "hard", "dtrdsr"]
            ) do |item_value|
              item_text = item_value
              item_text = "XON/XOFF (software)" if "soft" == item_value
              item_text = "RTS/CTS (hardware)" if "hard" == item_value
              item_text = "DTR/DSR (hardware)" if "dtrdsr" == item_value
              if value == item_value
                value_found = true
                # Have the current value preselected:
                @serial_flow_control_items = Builtins.add(
                  @serial_flow_control_items,
                  Item(Id(item_value), item_text, true)
                )
              else
                @serial_flow_control_items = Builtins.add(
                  @serial_flow_control_items,
                  Item(Id(item_value), item_text)
                )
              end
            end 

            if !value_found
              if "" == value
                # flow control may have to be exactly what is set in the printer (e.g. via DIP switches):
                @serial_flow_control_items = Builtins.prepend(
                  @serial_flow_control_items,
                  Item(Id(""), "", true)
                )
              else
                # If the current value is none of them, it might be invalid or a typo.
                # Therefore the current value is added with an appropriate hint.
                # Nevertheless the current value must be topmost and preselected because
                # anything else which might be preselected (even an empty value)
                # would silently change the current value to the preselected one
                # when the user clicks [OK]:
                @serial_flow_control_items = Builtins.prepend(
                  @serial_flow_control_items,
                  Item(
                    Id(value),
                    Ops.add(value, " (might be invalid or a typo)"),
                    true
                  )
                )
              end
            end
          end
          if "stop" == keyword
            Builtins.foreach(
              # The preset values are from backend/serial.c in the CUPS 1.3.9 sources:
              ["1", "2"]
            ) do |item_value|
              if value == item_value
                value_found = true
                # Have the current value preselected:
                @serial_stop_bits_items = Builtins.add(
                  @serial_stop_bits_items,
                  Item(Id(item_value), item_value, true)
                )
              else
                @serial_stop_bits_items = Builtins.add(
                  @serial_stop_bits_items,
                  Item(Id(item_value), item_value)
                )
              end
            end 

            if !value_found
              if "" == value
                # stop bits may have to be exactly what is set in the printer (e.g. via DIP switches):
                @serial_stop_bits_items = Builtins.prepend(
                  @serial_stop_bits_items,
                  Item(Id(""), "", true)
                )
              else
                # If the current value is none of them, it might be invalid or a typo.
                # Therefore the current value is added with an appropriate hint.
                # Nevertheless the current value must be topmost and preselected because
                # anything else which might be preselected (even an empty value)
                # would silently change the current value to the preselected one
                # when the user clicks [OK]:
                @serial_stop_bits_items = Builtins.prepend(
                  @serial_stop_bits_items,
                  Item(
                    Id(value),
                    Ops.add(value, " (might be invalid or a typo)"),
                    true
                  )
                )
              end
            end
          end
        end
      end
      model_content = getContentFromCurrentModel(true)
      content = VBox(
        Left(
          ComboBox(
            Id(:serial_device_node),
            # This ComboBox is editable because there could be
            # any kind of serial device node name "/dev/whatever":
            Opt(:editable),
            # Label for an editable ComboBox where
            # a serial device node (e.g. /dev/ttyS0 or /dev/ttyS1)
            # can be selected or entered:
            _("&Serial device"),
            @serial_device_node_items
          )
        ),
        Left(
          ComboBox(
            Id(:serial_baud_rate),
            # The backend/serial.c in the CUPS 1.3.9 sources
            # supports only the preset values below.
            # Nevertheless this ComboBox is editable to be future-proof:
            Opt(:editable),
            # Label for an editable ComboBox where
            # the baud rate for a serial device
            # can be selected or entered:
            _("&Baud rate"),
            @serial_baud_rate_items
          )
        ),
        Left(
          ComboBox(
            Id(:serial_data_bits),
            # The backend/serial.c in the CUPS 1.3.9 sources
            # supports only the preset values below (7 and 8).
            # Nevertheless this ComboBox is editable to be future-proof
            # because according to http://en.wikipedia.org/wiki/Serial_port
            # a serial port might also have 5, 6, or 9 data bits.
            Opt(:editable),
            # Label for an editable ComboBox where
            # the number of data bits for a serial device
            # can be selected or entered:
            _("&Data bits"),
            @serial_data_bits_items
          )
        ),
        Left(
          ComboBox(
            Id(:serial_parity),
            # The backend/serial.c in the CUPS 1.3.9 sources
            # supports only the preset values below.
            # Nevertheless this ComboBox is editable to be future-proof:
            Opt(:editable),
            # Label for an editable ComboBox where
            # the parity checking for a serial device
            # can be selected or entered:
            _("&Parity checking"),
            @serial_parity_items
          )
        ),
        Left(
          ComboBox(
            Id(:serial_flow_control),
            # The backend/serial.c in the CUPS 1.3.9 sources
            # supports only the preset values below.
            # Nevertheless this ComboBox is editable to be future-proof
            # because according to http://en.wikipedia.org/wiki/Flow_control
            # a serial port might also have another kind of flow control.
            Opt(:editable),
            # Label for an editable ComboBox where
            # the flow control for a serial device
            # can be selected or entered:
            _("&Flow control"),
            @serial_flow_control_items
          )
        ),
        Left(
          ComboBox(
            Id(:serial_stop_bits),
            # The backend/serial.c in the CUPS 1.3.9 sources
            # supports only the preset values below.
            # Nevertheless this ComboBox is editable to be future-proof:
            Opt(:editable),
            # Label for an editable ComboBox where
            # the number of stop bits for a serial device
            # can be selected or entered:
            _("S&top bits"),
            @serial_stop_bits_items
          )
        ),
        model_content
      )
    when :bluetooth
      if !Printerlib.TestAndInstallPackage("bluez-cups", "installed")
        if Popup.ContinueCancel(
            _(
              "To access a bluetooth printer, the RPM package bluez-cups must be installed."
            )
          )
          Printerlib.TestAndInstallPackage("bluez-cups", "install")
          # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
          # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
          # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
          # so that this leftover "abort" button must be explicitly hidden here:
          Wizard.HideAbortButton
        end
        # The user can also decide during the actual installation not to install it
        # or the installation may have failed for whatever reason
        # so that we test again whether or not it is now actually installed:
        if !Printerlib.TestAndInstallPackage("bluez-cups", "installed")
          content = VBox(
            Left(Label(_("The RPM package bluez-cups is not installed.")))
          )
        end
      else
        # Fallback message what the user may run manually when it fails
        # to generate a valid list of bluetooth device IDs:
        bluetooth_device_list = _(
          "It seems there are no bluetooth device IDs.\n" +
            "Run 'hcitool scan' to get the bluetooth device IDs.\n" +
            "Enter the ID without colons like '1A2B3C4D5E6F'."
        )
        Popup.ShowFeedback(
          "",
          # Busy message:
          # Body of a Popup::ShowFeedback:
          _("Retrieving bluetooth device IDs...")
        )
        # The command "hcitool scan" might need very much time or hang up.
        # To kill exactly hcitool there is the workaround via the temporary file because
        # hcitool scan | grep '...' & sleep 10 ; kill -9 $!
        # would kill only grep and
        # ( hcitool scan | grep '...' ) & sleep 10 ; kill -9 $!
        # would kill only the sub shell.
        if !Printerlib.ExecuteBashCommand(
            "hcitool scan >/tmp/hcitool_scan.out & sleep 10 ; kill -9 $! ; grep '..:..:..:..:..:..' /tmp/hcitool_scan.out | tr -s ' ' ; rm -f /tmp/hcitool_scan.out"
          )
          Popup.ErrorDetails(
            _("Failed to get a list of bluetooth device IDs."),
            Ops.add(
              "hcitool scan" + "\n",
              Ops.get_string(Printerlib.result, "stderr", "")
            )
          )
        else
          if "" != Ops.get_string(Printerlib.result, "stdout", "")
            bluetooth_device_list = Ops.get_string(
              Printerlib.result,
              "stdout",
              ""
            )
          end
        end
        Popup.ClearFeedback
        Builtins.y2milestone(
          "bluetooth_device_list '%1'",
          bluetooth_device_list
        )
        current_device_uri = getCurrentDeviceURI
        current_bluetooth_device_id = ""
        bluetooth_device_id_items = []
        if "bluetooth:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("bluetooth:/")
            )
          # bluetooth://deviceID
          uri_parts = Builtins.splitstring(current_device_uri, "/")
          # Remove empty parts (e.g. bluetooth://deviceID results ["bluetooth:","","deviceID"]):
          uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
          Builtins.y2milestone(
            "ConnectionWizardDialog uri_parts = '%1'",
            uri_parts
          )
          # Note that uri_parts[0] = "bluetooth:".
          if "" != Ops.get(uri_parts, 1, "")
            current_bluetooth_device_id = Ops.get(uri_parts, 1, "")
          end
        end
        current_bluetooth_device_id_found = false
        Builtins.foreach(Builtins.splitstring(bluetooth_device_list, " ")) do |word|
          if Builtins.regexpmatch(word, "..:..:..:..:..:..")
            # but the bluetooth backend needs it without the colons ':'
            # in its DeviceURI which has the form bluetooth://1A2B3C4D5E6F
            hexnumber = Builtins.filterchars(word, "0123456789ABCDEFabcdef")
            if "" != hexnumber
              if current_bluetooth_device_id == hexnumber
                current_bluetooth_device_id_found = true
                # Have the current bluetooth device id preselected:
                bluetooth_device_id_items = Builtins.add(
                  bluetooth_device_id_items,
                  Item(Id(hexnumber), hexnumber, true)
                )
              else
                bluetooth_device_id_items = Builtins.add(
                  bluetooth_device_id_items,
                  Item(Id(hexnumber), hexnumber)
                )
              end
            end
          end
        end 

        if !current_bluetooth_device_id_found
          if "" == current_bluetooth_device_id
            # the bluetooth backend may blindly write to any bluetooth device:
            bluetooth_device_id_items = Builtins.prepend(
              bluetooth_device_id_items,
              Item(Id(""), "", true)
            )
          else
            bluetooth_device_id_items = Builtins.prepend(
              bluetooth_device_id_items,
              Item(
                Id(current_bluetooth_device_id),
                current_bluetooth_device_id,
                true
              )
            )
          end
        end
        model_content = getContentFromCurrentModel(true)
        content = VBox(
          Left(
            ComboBox(
              Id(:bluetooth_device_id),
              Opt(:editable),
              # Label for an editable ComboBox where
              # a bluetooth device ID
              # can be selected or entered:
              _("&Bluetooth device ID"),
              bluetooth_device_id_items
            )
          ),
          Left(
            Frame(
              _("Currently available bluetooth device IDs"),
              # The RichText widget is required here to get scroll bars if needed
              # (a Label cuts the content because it does not provide scroll bars):
              RichText(
                Ops.add(Ops.add("<pre>", bluetooth_device_list), "</pre>")
              )
            ) # TRANSLATORS: Frame label for a list of bluetooth device IDs:
          ),
          model_content
        )
      end
    when :tcp
      hostname = ""
      port_or_queue = "9100"
      uri_options = ""
      current_device_uri = getCurrentDeviceURI
      if "socket:/" ==
          Builtins.substring(
            current_device_uri,
            0,
            Builtins.size("socket:/")
          )
        # socket://ip-address-or-hostname[:port-number][?waiteof=false]
        uri_parts = Builtins.splitstring(current_device_uri, ":/?")
        # Remove empty parts (e.g. socket://server results ["socket","","","server"]):
        uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
        Builtins.y2milestone(
          "ConnectionWizardDialog uri_parts = '%1'",
          uri_parts
        )
        # Note that uri_parts[0] = "socket".
        if "" != Ops.get(uri_parts, 1, "")
          hostname = Ops.get(uri_parts, 1, "")
          if "" != Ops.get(uri_parts, 2, "")
            if Builtins.issubstring(Ops.get(uri_parts, 2, ""), "=")
              uri_options = Ops.get(uri_parts, 2, "")
            else
              port_or_queue = Ops.get(uri_parts, 2, "")
              if Builtins.issubstring(Ops.get(uri_parts, 3, ""), "=")
                uri_options = Ops.get(uri_parts, 3, "")
              end
            end
          end
        end
      end
      connection_content = getNetworkContent(
        URIpercentDecoding(hostname),
        # TRANSLATORS: List of input field labels,
        # first for network scan button,
        # second for the TCP port number:
        _("Scan for Direct Socket Servers"),
        _("TCP Port Number"),
        URIpercentDecoding(port_or_queue),
        uri_options
      )
      model_content = getContentFromCurrentModel(true)
      content = VBox(connection_content, model_content)
    when :lpd
      hostname = ""
      port_or_queue = "LPT1"
      uri_options = ""
      current_device_uri = getCurrentDeviceURI
      if "lpd:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("lpd:/"))
        # (there is no authentication via LPD protocol)
        # to describe who requested a print job in the form
        #   lpd://username@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        # CUPS' "lpstat -v" suppresses "username:password@" (if it exists)
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "lpd"
        )
        # The Device URI has the form ([...[...]...] are optional parts):
        # lpd://ip-address-or-hostname/queue[?option1=value1[&option2=value2...[&optionN=valueN]...]]
        uri_parts = Builtins.splitstring(current_device_uri, ":/?")
        # Remove empty parts (e.g. lpd://server results ["lpd","","","server"]):
        uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
        Builtins.y2milestone(
          "ConnectionWizardDialog uri_parts = '%1'",
          uri_parts
        )
        # Note that uri_parts[0] = "lpd".
        if "" != Ops.get(uri_parts, 1, "")
          hostname = Ops.get(uri_parts, 1, "")
          if "" != Ops.get(uri_parts, 2, "")
            port_or_queue = Ops.get(uri_parts, 2, "")
            if "" != Ops.get(uri_parts, 3, "")
              uri_options = Ops.get(uri_parts, 3, "")
            end
          end
        end
      end
      if !Builtins.issubstring(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
        hostname = URIpercentDecoding(hostname)
      end
      connection_content = getNetworkContent(
        hostname,
        # TRANSLATORS: List of input field labels,
        # first for network scan button,
        # second for name of printer queue
        _("Scan for LPD Servers"),
        _("Queue Name (see the printer's manual)"),
        URIpercentDecoding(port_or_queue),
        uri_options
      )
      model_content = getContentFromCurrentModel(true)
      content = VBox(connection_content, model_content)
    when :ipp
      uri = ""
      current_device_uri = getCurrentDeviceURI
      if "ipp:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("ipp:/")) ||
          "http:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("http:/")
            )
        # fixed username and password for authentication in the form
        #   ipp://username:password@ip-address-or-hostname/...
        #   http://username:password@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        if "ipp:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("ipp:/")
            )
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "ipp"
          )
        end
        if "http:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("http:/")
            )
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "http"
          )
        end
        # A Device URI to print via CUPS server has the form "ipp://server/printers/queue"
        # while a Device URI to access a network printer via IPP
        # does probably not contain "/printers/" so that this is used here
        # as a best effort attempt to distinguish both cases:
        if !Builtins.issubstring(current_device_uri, "/printers/")
          # {ipp|http}://ip-address-or-hostname[:port-number]/resource[?option1=value1...[&optionN=valueN]...]
          uri = current_device_uri
        end
      end
      model_content = getContentFromCurrentModel(true)
      content = VBox(
        Left(
          InputField(
            Id(:uri),
            # Show it as wide as possible because it may have to contain
            # longer stuff like 'ipp://ip-address:port-number/resource':
            Opt(:hstretch),
            # TRANSLATORS: Input field label
            _("URI (see the printer's manual) [percent-encoded]"),
            uri
          )
        ),
        model_content
      )
    when :smb
      if !Printerlib.TestAndInstallPackage("samba-client", "installed")
        if Popup.ContinueCancel(
            _(
              "To access a SMB printer share, the RPM package samba-client must be installed."
            )
          )
          Printerlib.TestAndInstallPackage("samba-client", "install")
          # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
          # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
          # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
          # so that this leftover "abort" button must be explicitly hidden here:
          Wizard.HideAbortButton
        end
        # The user can also decide during the actual installation not to install it
        # or the installation may have failed for whatever reason
        # so that we test again whether or not it is now actually installed:
        if !Printerlib.TestAndInstallPackage("samba-client", "installed")
          content = VBox(
            Left(Label(_("The RPM package samba-client is not installed.")))
          )
        end
      else
        hostname = ""
        domain = ""
        printer = ""
        user = ""
        pass = ""
        current_device_uri = getCurrentDeviceURI
        if "smb:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("smb:/")
            )
          # smb://server[:port]/share
          # smb://workgroup/server[:port]/share
          # smb://username:password@server[:port]/share
          # smb://username:password@workgroup/server[:port]/share
          # CUPS' "lpstat -v" suppresses "username:password@" (if it exists)
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "smb"
          )
          # Here '/' is the only delimiter (so that username:password and server:port is one part):
          uri_parts = Builtins.splitstring(current_device_uri, "/")
          # Remove empty parts (e.g. smb://server results ["smb:","","server"]):
          uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
          Builtins.y2milestone(
            "ConnectionWizardDialog uri_parts = '%1'",
            uri_parts
          )
          if "" != Ops.get(uri_parts, 1, "") &&
              "" != Ops.get(uri_parts, 2, "")
            if Builtins.issubstring(Ops.get(uri_parts, 1, ""), "@")
              # or
              # smb://username:password@workgroup/server[:port]/share
              if "" != Ops.get(uri_parts, 3, "")
                user_pass_domain = Builtins.splitstring(
                  Ops.get(uri_parts, 1, ""),
                  ":@"
                )
                user = Ops.get(user_pass_domain, 0, "")
                pass = Ops.get(user_pass_domain, 1, "")
                domain = Ops.get(user_pass_domain, 2, "")
                hostname = Ops.get(uri_parts, 2, "")
                printer = Ops.get(uri_parts, 3, "")
              else
                user_pass_hostname = Builtins.splitstring(
                  Ops.get(uri_parts, 1, ""),
                  ":@"
                )
                user = Ops.get(user_pass_hostname, 0, "")
                pass = Ops.get(user_pass_hostname, 1, "")
                hostname = Ops.get(user_pass_hostname, 2, "")
                printer = Ops.get(uri_parts, 2, "")
              end
            else
              # or
              # smb://workgroup/server[:port]/share
              if "" != Ops.get(uri_parts, 3, "")
                domain = Ops.get(uri_parts, 1, "")
                hostname = Ops.get(uri_parts, 2, "")
                printer = Ops.get(uri_parts, 3, "")
              else
                hostname = Ops.get(uri_parts, 1, "")
                printer = Ops.get(uri_parts, 2, "")
              end
            end
          end
        end
        # Be backward compatible for openSUSE < 11.3 and be prepared for /usr/lib64/cups/
        Printerlib.ExecuteBashCommand(
          "ls -1 /usr/lib*/cups/backend/smb | head -n1 | tr -d '[:space:]'"
        )
        # readlink is in the coreutils RPM so that it is available in any case.
        Printerlib.ExecuteBashCommand(
          Ops.add(
            Ops.add(
              "readlink ",
              Ops.get_string(Printerlib.result, "stdout", "")
            ),
            " | tr -d '[:space:]'"
          )
        )
        # Only if /usr/lib[64]/cups/backend/smb -> /usr/bin/get_printing_ticket
        # there is support for Active Directory (R):
        if "/usr/bin/get_printing_ticket" ==
            Ops.get_string(Printerlib.result, "stdout", "")
          active_directory_support = true
        end
        model_content = getContentFromCurrentModel(true)
        content = VBox(
          Left(
            HBox(
              ComboBox(
                Id(:hostname), #),
                #`MenuButton
                #( // TRANSLATORS: Label for menu to search for remote servers
                #  _("Look up"),
                #  [ `item( `id(`scan), _("Scan for samba printers") ),
                #    // TRANSLATORS: Button to search for remote servers
                #    `item( `id(`scan_all), _("Look up for All Hosts") )
                #  ]
                Opt(:editable),
                # TRANSLATORS: Text entry for remote server name
                _("&Server (NetBIOS Host Name)"),
                [URIpercentDecoding(hostname)]
              )
            )
          ),
          Left(
            InputField(
              Id(:printer),
              # TRANSLATORS: Text entry for printer name
              _("&Printer (Share Name)"),
              URIpercentDecoding(printer)
            )
          ),
          Left(
            HBox(
              ComboBox(
                Id(:domain),
                Opt(:editable),
                # TRANSLATORS: Text entry for samba domain
                _("&Workgroup (Domain Name)"),
                [URIpercentDecoding(domain)]
              )
            )
          ),
          Left(
            Frame(
              _("Authentication (if needed)"),
              VBox(
                Left(
                  Label(_("Use fixed username and password")) # A Label for authentication via fixed username and password:
                ),
                Left(
                  HBox(
                    HSpacing(2),
                    VBox(
                      Left(
                        InputField(
                          Id(:user),
                          # TRANSLATORS: Text entry for username (authentication)
                          _("&User"),
                          URIpercentDecoding(user)
                        )
                      ),
                      Left(
                        Password(
                          Id(:pass),
                          # TRANSLATORS: Text entry for password (authentication)
                          _("Pass&word"),
                          URIpercentDecoding(pass)
                        )
                      )
                    )
                  )
                ),
                Left(
                  CheckBox(
                    Id(:active_directory_check_box),
                    Opt(:notify),
                    # A CheckBox to support Active Directory (R):
                    _("Support for &Active Directory (R)"),
                    active_directory_support
                  )
                )
              )
            ) # TRANSLATORS: Frame label for authentication
          ),
          Left(
            PushButton(
              Id(:test),
              # TRANSLATORS: Button to test remote printer machine
              _("&Test Connection")
            )
          ),
          model_content
        )
      end
    when :lpr
      hostname = ""
      port_or_queue = ""
      uri_options = ""
      current_device_uri = getCurrentDeviceURI
      if "lpd:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("lpd:/"))
        # (there is no authentication via LPD protocol)
        # to describe who requested a print job in the form
        #   lpd://username@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        # CUPS' "lpstat -v" suppresses "username:password@" (if it exists)
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "lpd"
        )
        # The Device URI has the form ([...[...]...] are optional parts):
        # lpd://ip-address-or-hostname/queue[?option1=value1[&option2=value2...[&optionN=valueN]...]]
        uri_parts = Builtins.splitstring(current_device_uri, ":/?")
        # Remove empty parts (e.g. lpd://server results ["lpd","","","server"]):
        uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
        Builtins.y2milestone(
          "ConnectionWizardDialog uri_parts = '%1'",
          uri_parts
        )
        # Note that uri_parts[0] = "lpd".
        if "" != Ops.get(uri_parts, 1, "")
          hostname = Ops.get(uri_parts, 1, "")
          if "" != Ops.get(uri_parts, 2, "")
            port_or_queue = Ops.get(uri_parts, 2, "")
            if "" != Ops.get(uri_parts, 3, "")
              uri_options = Ops.get(uri_parts, 3, "")
            end
          end
        end
      end
      if !Builtins.issubstring(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
        hostname = URIpercentDecoding(hostname)
      end
      connection_content = getNetworkContent(
        hostname,
        # TRANSLATORS: List of input field labels,
        # first for network scan button,
        # second for name of printer queue
        _("Scan for LPD Servers"),
        _("Queue Name"),
        URIpercentDecoding(port_or_queue),
        uri_options
      )
      model_content = getContentFromCurrentModel(false)
      content = VBox(connection_content, model_content)
    when :cups
      hostname = ""
      queue = ""
      uri_options = ""
      current_device_uri = getCurrentDeviceURI
      if "ipp:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("ipp:/")) ||
          "http:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("http:/")
            )
        # fixed username and password for authentication in the form
        #   ipp://username:password@ip-address-or-hostname/...
        #   http://username:password@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        if "ipp:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("ipp:/")
            )
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "ipp"
          )
        end
        if "http:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("http:/")
            )
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "http"
          )
        end
        # A Device URI to print via CUPS server has the form "ipp://server/printers/queue"
        # while a Device URI to access a network printer via IPP
        # does probably not contain "/printers/" so that this is used here
        # as a best effort attempt to distinguish both cases:
        if Builtins.issubstring(current_device_uri, "/printers/")
          # {ipp|http}://ip-address-or-hostname[:port-number]/resource[?option1=value1...[&optionN=valueN]...]
          # where resource is something like /printers/queue on a CUPS server.
          # Here ':' is no delimiter so that ip-address-or-hostname:port-number is one part
          uri_parts = Builtins.splitstring(current_device_uri, "/?")
          # Remove empty parts (e.g. ipp://server results ["ipp:","","server"]):
          uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
          Builtins.y2milestone(
            "ConnectionWizardDialog uri_parts = '%1'",
            uri_parts
          )
          # Note that uri_parts[0] = "{ipp:|http:}".
          if "" != Ops.get(uri_parts, 1, "")
            hostname = Ops.get(uri_parts, 1, "")
            if "printers" == Ops.get(uri_parts, 2, "")
              if "" != Ops.get(uri_parts, 3, "")
                queue = Ops.get(uri_parts, 3, "")
                if Builtins.issubstring(Ops.get(uri_parts, 4, ""), "=")
                  uri_options = Ops.get(uri_parts, 4, "")
                end
              end
            end
          end
        end
      end
      # TRANSLATORS: Text entry to fill IP or hostname of remote server
      @hostname_label = _("&IP Address or Host Name [percent-encoded]")
      if !Builtins.issubstring(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
        hostname = URIpercentDecoding(hostname)
        # TRANSLATORS: Text entry to fill IP or hostname of remote server
        @hostname_label = _("&IP Address or Host Name")
      end
      model_content = getContentFromCurrentModel(false)
      content = VBox(
        Left(
          HBox(
            ComboBox(
              Id(:hostname),
              Opt(:editable),
              @hostname_label,
              [hostname]
            ),
            MenuButton(
              _("Look up"),
              [
                Item(Id(:scan), _("Scan for IPP Servers")),
                Item(Id(:scan_broadcast), _("Scan for IPP Broadcasts")),
                Item(Id(:scan_all), _("Look up for All Hosts"))
              ]
            ) # TRANSLATORS: Label for menu to search for remote servers
          )
        ),
        Left(
          InputField(Id(:queue), _("Queue Name"), URIpercentDecoding(queue))
        ), # TRANSLATORS: InputField for a print queue name:
        Left(
          InputField(
            Id(:uri_options),
            # Show it as wide as possible because it may have to contain
            # longer stuff like 'option1=value1&option2=value2':
            Opt(:hstretch),
            # TRANSLATORS: InputField for optional Device URI parameters:
            _(
              "Optional 'option=value' parameter (usually empty) [percent-encoded]"
            ),
            uri_options
          )
        ),
        Left(
          PushButton(
            Id(:test),
            # TRANSLATORS: Button to test remote printer machine
            _("&Test Connection")
          )
        ),
        model_content
      )
    when :ipx
      if !Printerlib.TestAndInstallPackage("ncpfs", "installed")
        if Popup.ContinueCancel(
            _(
              "To access an IPX print queue, the RPM package ncpfs must be installed."
            )
          )
          Printerlib.TestAndInstallPackage("ncpfs", "install")
          # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
          # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
          # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
          # so that this leftover "abort" button must be explicitly hidden here:
          Wizard.HideAbortButton
        end
        # The user can also decide during the actual installation not to install it
        # or the installation may have failed for whatever reason
        # so that we test again whether or not it is now actually installed:
        if !Printerlib.TestAndInstallPackage("ncpfs", "installed")
          content = VBox(
            Left(Label(_("The RPM package ncpfs is not installed.")))
          )
        end
      else
        hostname = ""
        queue = ""
        user = ""
        pass = ""
        current_device_uri = getCurrentDeviceURI
        if "novell:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("novell:/")
            )
          # novell://server/queue
          # novell://username:password@server/queue
          # CUPS' "lpstat -v" suppresses "username:password@" (if it exists)
          # so that it may have to be retrieved form /etc/cups/printers.conf.
          # Fortunately getSMBuriWithUsernameAndPassword works here too
          # because the forms of IPX and SMB device URIs match sufficienty:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "novell"
          )
          # Here '/' is the only delimiter (so that username:password and server:port is one part):
          uri_parts = Builtins.splitstring(current_device_uri, "/")
          # Remove empty parts (e.g. novell://server results ["novell:","","server"]):
          uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
          Builtins.y2milestone(
            "ConnectionWizardDialog uri_parts = '%1'",
            uri_parts
          )
          if "" != Ops.get(uri_parts, 1, "") &&
              "" != Ops.get(uri_parts, 2, "")
            if Builtins.issubstring(Ops.get(uri_parts, 1, ""), "@")
              user_pass_hostname = Builtins.splitstring(
                Ops.get(uri_parts, 1, ""),
                ":@"
              )
              user = Ops.get(user_pass_hostname, 0, "")
              pass = Ops.get(user_pass_hostname, 1, "")
              hostname = Ops.get(user_pass_hostname, 2, "")
              queue = Ops.get(uri_parts, 2, "")
            else
              hostname = Ops.get(uri_parts, 1, "")
              queue = Ops.get(uri_parts, 2, "")
            end
          end
        end
        model_content = getContentFromCurrentModel(true)
        content = VBox(
          Left(
            InputField(
              Id(:hostname),
              # TRANSLATORS: Text entry for IP or hostname of remote server
              _("IP Address or Host Name"),
              hostname
            )
          ),
          Left(
            InputField(
              Id(:queue),
              # TRANSLATORS: Text entry for name of remote printer queue
              _("Queue Name"),
              queue
            )
          ),
          Left(
            Frame(
              _("Authenticate as"),
              VBox(
                InputField(
                  Id(:user),
                  # TRANSLATORS: Text entry for username (authentication)
                  _("User"),
                  user
                ),
                Password(
                  Id(:pass),
                  # TRANSLATORS: Text entry for password (authentication)
                  _("&Password"),
                  pass
                )
              )
            ) # TRANSLATORS: Frame label for authentication
          ),
          Left(
            PushButton(
              Id(:test),
              # TRANSLATORS: Button to test remote printer machine
              _("&Test Connection")
            )
          ),
          model_content
        )
      end
    when :uri
      current_device_uri = getCurrentDeviceURI
      if "smb:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("smb:/"))
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "smb"
        )
      end
      if "novell:/" ==
          Builtins.substring(
            current_device_uri,
            0,
            Builtins.size("novell:/")
          )
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "novell"
        )
      end
      # Even the DeviceURI for ipp/http can contain
      # fixed username and password for authentication in the form
      #   ipp://username:password@ip-address-or-hostname/...
      #   http://username:password@ip-address-or-hostname/...
      # but usage of this is really really not encouraged, see
      # https://bugzilla.novell.com/show_bug.cgi?id=512549
      # so that its setup not supported here but when
      # such an URI already exists, it should be shown correctly:
      if "ipp:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("ipp:/"))
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "ipp"
        )
      end
      if "http:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("http:/"))
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "http"
        )
      end
      # Even the DeviceURI for lpd can contain a fixed username
      # (there is no authentication via LPD protocol)
      # to describe who requested a print job in the form
      #   lpd://username@ip-address-or-hostname/...
      # but usage of this is really really not encouraged, see
      # https://bugzilla.novell.com/show_bug.cgi?id=512549
      # so that its setup not supported here but when
      # such an URI already exists, it should be shown correctly:
      if "lpd:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("lpd:/"))
        # so that it may have to be retrieved form /etc/cups/printers.conf:
        current_device_uri = getUriWithUsernameAndPassword(
          current_device_uri,
          "lpd"
        )
      end
      model_content = getContentFromCurrentModel(true)
      content = VBox(
        Left(
          InputField(
            Id(:uri),
            # Show it as wide as possible because it may have to contain
            # longer stuff like 'scheme://server:port/path/to/resource':
            Opt(:hstretch),
            # TRANSLATORS: Text entry for URI (Uniform Resource Identifier)
            _("URI (Uniform Resource Identifier) [percent-encoded]"),
            current_device_uri
          )
        ),
        model_content
      )
    when :pipe
      if !Printerlib.TestAndInstallPackage("cups-backends", "installed")
        if Popup.ContinueCancel(
            _(
              "To print via 'pipe', the RPM package cups-backends must be installed."
            )
          )
          Printerlib.TestAndInstallPackage("cups-backends", "install")
          # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
          # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
          # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
          # so that this leftover "abort" button must be explicitly hidden here:
          Wizard.HideAbortButton
        end
        # The user can also decide during the actual installation not to install it
        # or the installation may have failed for whatever reason
        # so that we test again whether or not it is now actually installed:
        if !Printerlib.TestAndInstallPackage("cups-backends", "installed")
          content = VBox(
            Left(
              Label(_("The RPM package cups-backends is not installed."))
            )
          )
        end
      else
        uri = ""
        current_device_uri = getCurrentDeviceURI
        if "pipe:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("pipe:/")
            )
          # pipe:/path/to/command[?option1=value1&option2=value2...]
          # remove the scheme 'pipe:' so that only the '/path/to/command...' is left:
          uri = Builtins.mergestring(
            Builtins.sublist(
              Builtins.splitstring(current_device_uri, ":"),
              1
            ),
            ""
          )
        end
        model_content = getContentFromCurrentModel(false)
        content = VBox(
          Left(
            InputField(
              Id(:program),
              # Show it as wide as possible because it may have to contain
              # longer stuff like 'path/to/command?option1=value1&option2=value2':
              Opt(:hstretch),
              # TRANSLATORS: Text entry for program name that will be called via pipe:
              _("Program (/path/to/command?option=value) [percent-encoded]"),
              uri
            )
          ),
          model_content
        )
      end
    when :beh
      if !Printerlib.TestAndInstallPackage("cups-backends", "installed")
        if Popup.ContinueCancel(
            _(
              "To use 'beh', the RPM package cups-backends must be installed."
            )
          )
          Printerlib.TestAndInstallPackage("cups-backends", "install")
          # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
          # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
          # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
          # so that this leftover "abort" button must be explicitly hidden here:
          Wizard.HideAbortButton
        end
        # The user can also decide during the actual installation not to install it
        # or the installation may have failed for whatever reason
        # so that we test again whether or not it is now actually installed:
        if !Printerlib.TestAndInstallPackage("cups-backends", "installed")
          content = VBox(
            Left(
              Label(_("The RPM package cups-backends is not installed."))
            )
          )
        end
      else
        uri = ""
        beh_do_not_disable = true
        beh_attempts = "0"
        beh_delay = "30"
        current_device_uri = getCurrentDeviceURI
        if "smb:/" ==
            Builtins.substring(current_device_uri, 0, Builtins.size("smb:/"))
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "smb"
          )
        end
        if "novell:/" ==
            Builtins.substring(
              current_device_uri,
              0,
              Builtins.size("novell:/")
            )
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "novell"
          )
        end
        # Even the DeviceURI for ipp/http can contain
        # fixed username and password for authentication in the form
        #   ipp://username:password@ip-address-or-hostname/...
        #   http://username:password@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        if "ipp:/" ==
            Builtins.substring(current_device_uri, 0, Builtins.size("ipp:/"))
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "ipp"
          )
        end
        if "http:/" ==
            Builtins.substring(current_device_uri, 0, Builtins.size("http:/"))
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "http"
          )
        end
        # Even the DeviceURI for lpd can contain a fixed username
        # (there is no authentication via LPD protocol)
        # to describe who requested a print job in the form
        #   lpd://username@ip-address-or-hostname/...
        # but usage of this is really really not encouraged, see
        # https://bugzilla.novell.com/show_bug.cgi?id=512549
        # so that its setup not supported here but when
        # such an URI already exists, it should be shown correctly:
        if "lpd:/" ==
            Builtins.substring(current_device_uri, 0, Builtins.size("lpd:/"))
          # so that it may have to be retrieved form /etc/cups/printers.conf:
          current_device_uri = getUriWithUsernameAndPassword(
            current_device_uri,
            "lpd"
          )
        end
        uri = current_device_uri
        if "beh:/" ==
            Builtins.substring(current_device_uri, 0, Builtins.size("beh:/"))
          # remove the beh-related stuff so that only the <originaluri> is left:
          uri = Builtins.mergestring(
            Builtins.sublist(Builtins.splitstring(current_device_uri, "/"), 4),
            "/"
          )
          uri_parts = Builtins.splitstring(current_device_uri, "/")
          # Remove possibly empty parts:
          uri_parts = Builtins.filter(uri_parts) { |part| "" != part }
          Builtins.y2milestone(
            "ConnectionWizardDialog uri_parts = '%1'",
            uri_parts
          )
          if "" != Ops.get(uri_parts, 1, "") &&
              "" != Ops.get(uri_parts, 2, "") &&
              "" != Ops.get(uri_parts, 3, "")
            beh_do_not_disable = false if "0" == Ops.get(uri_parts, 1, "")
            beh_attempts = Ops.get(uri_parts, 2, "")
            beh_delay = Ops.get(uri_parts, 3, "")
          end
        end
        model_content = getContentFromCurrentModel(true)
        content = VBox(
          Left(
            InputField(
              Id(:beh_original_uri),
              # Show it as wide as possible because it may have to contain
              # longer stuff like 'scheme://server:port/path/to/resource':
              Opt(:hstretch),
              # TRANSLATORS: Text entry for device URI (Uniform Resource Identifier)
              _(
                "Device URI (for which 'beh' should be applied) [percent-encoded]"
              ),
              uri
            )
          ),
          Left(
            CheckBox(
              Id(:beh_do_not_disable),
              # TRANSLATORS: Check box
              _("Never Disable the Queue"),
              beh_do_not_disable
            )
          ),
          Left(
            InputField(
              Id(:beh_attempts),
              # TRANSLATORS: Text entry
              _("Number of Retries ('0' means infinite retries)"),
              beh_attempts
            )
          ),
          Left(
            InputField(
              Id(:beh_delay),
              # TRANSLATORS: Text entry
              _("Delay in Seconds Between Two Retries"),
              beh_delay
            )
          ),
          model_content
        )
      end
    when :directly, :network, :server, :special
      content = VBox(Left(Label(_("Select a specific connection type."))))
    else
      Builtins.y2error("Unknown selected item %1", selected)
  end
  UI.ReplaceWidget(:connection_settings_replace_point, content)

  nil
end

- (Object) ConnectionWizardDialog



2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
# File '../../src/include/printer/connectionwizard.rb', line 2206

def ConnectionWizardDialog
  contents = VBox(
    HBox(
      HWeight(
        1,
        Tree(
          Id(:tree_selection),
          Opt(:notify),
          # TRANSLATORS: Label for tree widget description
          _("&Connection Type"),
          [
            Item(
              Id(:directly),
              # TRANSLATORS: Tree widget item
              _("Directly Connected Device"),
              true,
              [
                # Disabled legacy "Parallel Port" so that it is no longer accessible in the dialog:
                #Item(Id(:parallel), _("Parallel Port")),
                # TRANSLATORS: Tree widget item
                Item(Id(:usb), _("USB Port")),
                # TRANSLATORS: Tree widget item
                Item(Id(:hplip), _("HP Devices (HPLIP)")),
                # TRANSLATORS: Tree widget item
                # Disabled legacy "Serial Port" so that it is no longer accessible in the dialog:
                #Item(Id(:serial), _("Serial Port")),
                # TRANSLATORS: Tree widget item
                Item(Id(:bluetooth), _("Bluetooth"))
              ] # TRANSLATORS: Tree widget item
            ),
            Item(
              Id(:network),
              # TRANSLATORS: Tree widget item
              _("Access Network Printer or Printserver Box via"),
              true,
              [
                Item(Id(:tcp), _("TCP Port (AppSocket/JetDirect)")),
                # TRANSLATORS: Tree widget item
                Item(Id(:lpd), _("Line Printer Daemon (LPD) Protocol")),
                # TRANSLATORS: Tree widget item
                Item(Id(:ipp), _("Internet Printing Protocol (IPP)"))
              ] # TRANSLATORS: Tree widget item
            ),
            Item(
              Id(:server),
              # TRANSLATORS: Tree widget item
              _("Print via Print Server Machine"),
              true,
              [
                Item(Id(:smb), _("Windows (R) or Samba (SMB/CIFS)")),
                # TRANSLATORS: Tree widget item
                Item(Id(:lpr), _("Traditional UNIX Server (LPR/LPD)")),
                # `item( `id(`iprint), _("iPrint (Novell OES)") ),
                # TRANSLATORS: Tree widget item
                Item(Id(:cups), _("CUPS Server (IPP)")),
                # TRANSLATORS: Tree widget item
                # Disabled legacy "Novell Netware Print Server (IPX)" so that it is no longer accessible in the dialog:
                #Item(Id(:ipx), _("Novell Netware Print Server (IPX)"))
              ] # TRANSLATORS: Tree widget item
            ),
            Item(
              Id(:special),
              # TRANSLATORS: Tree widget item
              _("Special"),
              true,
              [
                Item(Id(:uri), _("Specify Arbitrary Device URI")),
                # TRANSLATORS: Tree widget item
                Item(
                  Id(:pipe),
                  _("Send Print Data to Other Program (pipe)")
                ),
                # TRANSLATORS: Tree widget item
                Item(Id(:beh), _("Daisy-chain Backend Error Handler (beh)"))
              ] # TRANSLATORS: Tree widget item
            )
          ]
        )
      ),
      HWeight(
        1,
        VBox(
          VStretch(),
          Frame(
            _("Connection Settings"),
            ReplacePoint(
              Id(:connection_settings_replace_point),
              VBox(Left(Label(_("Select a specific connection type."))))
            )
          ), # TRANSLATORS: Connection details widget
          VStretch()
        )
      )
    )
  )
  # 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."
  # In this case the "overview" is not the actual Overview dialog but the dialog
  # from which this DriverOptionsDialog was called i.e. BasicModifyDialog.
  # 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(
    _("Connection Wizard"),
    contents,
    Ops.get_string(@HELPS, "connection_wizard_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 an item which matches to the currently selected Device URI
  # from the previous "add queue" or "modify queue" dialogs or
  # which matches to the currently selected queue in the "overview" dialog.
  # But when the previous dialog was "printing via network"
  # there is no currently available Device URI.
  current_device_uri = getCurrentDeviceURI
  if "" != current_device_uri
    if "parallel:/" ==
        Builtins.substring(
          current_device_uri,
          0,
          Builtins.size("parallel:/")
        )
      UI.ChangeWidget(:tree_selection, :CurrentItem, :parallel)
      changeSettingsDialog(:parallel)
    elsif "usb:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("usb:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :usb)
      changeSettingsDialog(:usb)
    elsif "hp:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("hp:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :hplip)
      changeSettingsDialog(:hplip)
    elsif "serial:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("serial:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :serial)
      changeSettingsDialog(:serial)
    elsif "bluetooth:/" ==
        Builtins.substring(
          current_device_uri,
          0,
          Builtins.size("bluetooth:/")
        )
      UI.ChangeWidget(:tree_selection, :CurrentItem, :bluetooth)
      changeSettingsDialog(:bluetooth)
    elsif "scsi:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("scsi:/"))
      # see https://bugzilla.novell.com/show_bug.cgi?id=580121
      # and http://www.cups.org/str.php?L3500
      # i.e. the scsi backend will be dropped.
      # Therefore in yast2-printer SCSI printer support is also dropped.
      # Because of the dropped scsi backend there must be a user notification:
      if !Printerlib.ExecuteBashCommand("ls /usr/lib*/cups/backend/scsi")
        Popup.ErrorDetails(
          _("In CUPS version 1.5 SCSI printer support is dropped."),
          # Popup::ErrorDetails details (for experts only):
          _(
            "An untested and insecure workaround might be\n" +
              "to set 'FileDevice Yes' in cupsd.conf\n" +
              "and use a DeviceURI like 'file:/dev/sg...'"
          )
        )
      end
      # In this case "Specify Arbitrary Device URI" is used as fallback:
      UI.ChangeWidget(:tree_selection, :CurrentItem, :uri)
      changeSettingsDialog(:uri)
    elsif "socket:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("socket:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :tcp)
      changeSettingsDialog(:tcp)
    elsif "lpd:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("lpd:/"))
      # belongs to the `lpr case (print via traditional UNIX server)
      # or to the `lpd case (access a network printer via LPD port)
      # because the Device URI is in both cases "lpd://server/queue".
      # Nevertheless a currently useless 'false' condition is implemented
      # to be prepared where to insert a reasonable condition
      # to distinguish the cases which may appear in the future.
      # Because access a network printer via LPD port happens more often
      # than print via traditional UNIX server, the first case is used
      # as fallback in any case here:
      if false
        UI.ChangeWidget(:tree_selection, :CurrentItem, :lpr)
        changeSettingsDialog(:lpr)
      else
        UI.ChangeWidget(:tree_selection, :CurrentItem, :lpd)
        changeSettingsDialog(:lpd)
      end
    elsif "ipp:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("ipp:/")) ||
        "http:/" ==
          Builtins.substring(current_device_uri, 0, Builtins.size("http:/"))
      # while a Device URI to access a network printer via IPP
      # does probably not contain "/printers/" so that this is used here
      # as a best effort attempt to distinguish both cases:
      if Builtins.issubstring(current_device_uri, "/printers/")
        UI.ChangeWidget(:tree_selection, :CurrentItem, :cups)
        changeSettingsDialog(:cups)
      else
        UI.ChangeWidget(:tree_selection, :CurrentItem, :ipp)
        changeSettingsDialog(:ipp)
      end
    elsif "smb:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("smb:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :smb)
      changeSettingsDialog(:smb)
    elsif "novell:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("novell:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :ipx)
      changeSettingsDialog(:ipx)
    elsif "pipe:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("pipe:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :pipe)
      changeSettingsDialog(:pipe)
    elsif "beh:/" ==
        Builtins.substring(current_device_uri, 0, Builtins.size("beh:/"))
      UI.ChangeWidget(:tree_selection, :CurrentItem, :beh)
      changeSettingsDialog(:beh)
    end
  end

  validateAndMakeURI = lambda do |selected|
    valid = false
    @connection_uri = ""
    case selected
      when :hplip, :parallel, :usb
        @selected_connection_index = Convert.to_integer(
          UI.QueryWidget(Id(:connection_selection), :CurrentItem)
        )
        if nil == @selected_connection_index
          Popup.AnyMessage(
            _("Select a connection"),
            # Body of a Popup::AnyMessage when no connection was selected
            # because there is no connection available to be selected:
            _(
              "If no connection is shown here, it is not possible\n" +
                "to access the device via this type of connection.\n" +
                "Was the printer connected and switched on all the time?"
            )
          )
        elsif Ops.less_than(@selected_connection_index, 0)
          Popup.AnyMessage(
            _("Select a valid connection"),
            # Body of a Popup::AnyMessage when an invalid connection was selected
            # because the current connection is no longer valid:
            _(
              "When the current connection is no longer valid,\n" +
                "it does no longer work to access the device via this connection.\n" +
                "Is the printer still connected and switched on?"
            )
          )
        else
          @connection_uri = Ops.get(
            Printer.connections,
            [@selected_connection_index, "uri"],
            ""
          )
          @connection_model = Ops.get(
            Printer.connections,
            [@selected_connection_index, "model"],
            "Unknown"
          )
          valid = true if "" != @connection_uri
        end
      when :serial
        @serial_device_node = Convert.to_string(
          UI.QueryWidget(:serial_device_node, :Value)
        )
        @serial_baud_rate = Convert.to_string(
          UI.QueryWidget(:serial_baud_rate, :Value)
        )
        @serial_data_bits = Convert.to_string(
          UI.QueryWidget(:serial_data_bits, :Value)
        )
        @serial_parity = Convert.to_string(
          UI.QueryWidget(:serial_parity, :Value)
        )
        @serial_flow_control = Convert.to_string(
          UI.QueryWidget(:serial_flow_control, :Value)
        )
        @serial_stop_bits = Convert.to_string(
          UI.QueryWidget(:serial_stop_bits, :Value)
        )
        if Builtins.size(@serial_device_node) == 0 ||
            Builtins.size(@serial_baud_rate) == 0
          Popup.Error(_("Serial device and baud rate could not be empty."))
        else
          if "space" == @serial_parity && "7" != @serial_data_bits
            Popup.Error(
              _(
                "The 'space' parity checking is only supported with 7 data bits."
              )
            )
          else
            if "mark" == @serial_parity &&
                ("7" != @serial_data_bits || "1" != @serial_stop_bits)
              Popup.Error(
                _(
                  "The 'mark' parity checking is only supported with 7 data bits and 1 stop bit."
                )
              )
            else
              @connection_uri = Ops.add(
                Ops.add(Ops.add("serial:", @serial_device_node), "?baud="),
                @serial_baud_rate
              )
              if Ops.greater_than(Builtins.size(@serial_data_bits), 0)
                @connection_uri = Ops.add(
                  Ops.add(@connection_uri, "+bits="),
                  @serial_data_bits
                )
              end
              if Ops.greater_than(Builtins.size(@serial_parity), 0)
                @connection_uri = Ops.add(
                  Ops.add(@connection_uri, "+parity="),
                  @serial_parity
                )
              end
              if Ops.greater_than(Builtins.size(@serial_flow_control), 0)
                @connection_uri = Ops.add(
                  Ops.add(@connection_uri, "+flow="),
                  @serial_flow_control
                )
              end
              if Ops.greater_than(Builtins.size(@serial_stop_bits), 0)
                @connection_uri = Ops.add(
                  Ops.add(@connection_uri, "+stop="),
                  @serial_stop_bits
                )
              end
              valid = true
            end
          end
        end
      when :bluetooth
        @bluetooth_device_id = Convert.to_string(
          UI.QueryWidget(:bluetooth_device_id, :Value)
        )
        if Builtins.size(@bluetooth_device_id) == 0
          Popup.Error(_("Bluetooth device ID could not be empty."))
        else
          @connection_uri = Ops.add("bluetooth://", @bluetooth_device_id)
          valid = true
        end
      when :ipp, :uri
        @connection_uri = Convert.to_string(UI.QueryWidget(:uri, :Value))
        if Ops.greater_than(Builtins.size(@connection_uri), 0)
          # because special URI characters like ':' or '/' in connection_uri
          # must stay as is and not be percent encoded because only the values
          # of the URI parts must be percent encoded but not the whole URI.
          valid = true
        else
          Popup.Error(_("URI could not be empty."))
        end
      when :smb
        @smb_hostname = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        @smb_printer = Convert.to_string(UI.QueryWidget(:printer, :Value))
        @smb_domain = Convert.to_string(UI.QueryWidget(:domain, :Value))
        @smb_user = Convert.to_string(UI.QueryWidget(:user, :Value))
        @smb_pass = Convert.to_string(UI.QueryWidget(:pass, :Value))
        if "" == Builtins.filterchars(@smb_hostname, Printer.alnum_chars) ||
            "" == Builtins.filterchars(@smb_printer, Printer.alnum_chars)
          Popup.Error(_("Servername and printer could not be empty."))
        else
          if "" != Builtins.filterchars(@smb_user, Printer.alnum_chars) &&
              Ops.less_than(Builtins.size(@smb_pass), 1) ||
              "" == Builtins.filterchars(@smb_user, Printer.alnum_chars) &&
                Ops.greater_than(Builtins.size(@smb_pass), 0)
            Popup.Error(_("Both user and password must be specified."))
          else
            @connection_uri = "smb://"
            if "" != Builtins.filterchars(@smb_user, Printer.alnum_chars) &&
                Ops.greater_than(Builtins.size(@smb_pass), 0)
              @connection_uri = Builtins.sformat(
                "%1%2:%3@",
                @connection_uri,
                URIpercentEncoding(@smb_user),
                URIpercentEncoding(@smb_pass)
              )
            end
            if "" != Builtins.filterchars(@smb_domain, Printer.alnum_chars)
              @connection_uri = Builtins.sformat(
                "%1%2/",
                @connection_uri,
                URIpercentEncoding(@smb_domain)
              )
            end
            @connection_uri = Builtins.sformat(
              "%1%2/%3",
              @connection_uri,
              URIpercentEncoding(@smb_hostname),
              URIpercentEncoding(@smb_printer)
            )
            valid = true
          end
        end
      when :tcp
        @tcp_hostname = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        @tcp_port = Convert.to_string(
          UI.QueryWidget(:port_or_queue, :Value)
        )
        @tcp_uri_options = Convert.to_string(
          UI.QueryWidget(:uri_options, :Value)
        )
        if "" != Builtins.filterchars(@tcp_hostname, Printer.alnum_chars)
          if "" != Builtins.filterchars(@tcp_port, Printer.alnum_chars)
            if "" !=
                Builtins.filterchars(@tcp_uri_options, Printer.alnum_chars)
              # because special URI characters like '=' or '&' in tcp_uri_options
              # must stay as is and not be percent encoded because tcp_uri_options
              # contains all options like 'option1=value1&option2=value2'.
              @connection_uri = Builtins.sformat(
                "socket://%1:%2?%3",
                URIpercentEncoding(@tcp_hostname),
                URIpercentEncoding(@tcp_port),
                @tcp_uri_options
              )
            else
              @connection_uri = Builtins.sformat(
                "socket://%1:%2",
                URIpercentEncoding(@tcp_hostname),
                URIpercentEncoding(@tcp_port)
              )
            end
          else
            @connection_uri = Builtins.sformat(
              "socket://%1",
              URIpercentEncoding(@tcp_hostname)
            )
          end
          valid = true
        else
          Popup.Error(_("Servername could not be empty."))
        end
      when :lpd, :lpr
        @lpd_hostname = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        if !Builtins.issubstring(@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)
        end
        @lpd_queue = Convert.to_string(
          UI.QueryWidget(:port_or_queue, :Value)
        )
        @lpd_uri_options = Convert.to_string(
          UI.QueryWidget(:uri_options, :Value)
        )
        if "" != Builtins.filterchars(@lpd_hostname, Printer.alnum_chars) &&
            "" != Builtins.filterchars(@lpd_queue, Printer.alnum_chars)
          if "" !=
              Builtins.filterchars(@lpd_uri_options, Printer.alnum_chars)
            # because special URI characters like '=' or '&' in lpd_uri_options
            # must stay as is and not be percent encoded because lpd_uri_options
            # contains all options like 'option1=value1&option2=value2'.
            @connection_uri = Builtins.sformat(
              "lpd://%1/%2?%3",
              @lpd_hostname,
              URIpercentEncoding(@lpd_queue),
              @lpd_uri_options
            )
          else
            @connection_uri = Builtins.sformat(
              "lpd://%1/%2",
              @lpd_hostname,
              URIpercentEncoding(@lpd_queue)
            )
          end
          valid = true
        else
          Popup.Error(_("Servername and queue name could not be empty."))
        end
      when :cups
        @cups_hostname = Convert.to_string(
          UI.QueryWidget(:hostname, :Value)
        )
        if !Builtins.issubstring(@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)
        end
        @cups_queue = Convert.to_string(UI.QueryWidget(:queue, :Value))
        @cups_uri_options = Convert.to_string(
          UI.QueryWidget(:uri_options, :Value)
        )
        if "" != Builtins.filterchars(@cups_hostname, Printer.alnum_chars) &&
            "" != Builtins.filterchars(@cups_queue, Printer.alnum_chars)
          if "" !=
              Builtins.filterchars(@cups_uri_options, Printer.alnum_chars)
            # because special URI characters like '=' or '&' in cups_uri_options
            # must stay as is and not be percent encoded because cups_uri_options
            # contains all options like 'option1=value1&option2=value2'.
            @connection_uri = Builtins.sformat(
              "ipp://%1/printers/%2?%3",
              @cups_hostname,
              URIpercentEncoding(@cups_queue),
              @cups_uri_options
            )
          else
            @connection_uri = Builtins.sformat(
              "ipp://%1/printers/%2",
              @cups_hostname,
              URIpercentEncoding(@cups_queue)
            )
          end
          valid = true
        else
          Popup.Error(_("Servername and queue name could not be empty."))
        end
      when :ipx
        @ipx_hostname = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        @ipx_queue = Convert.to_string(UI.QueryWidget(:queue, :Value))
        @ipx_user = Convert.to_string(UI.QueryWidget(:user, :Value))
        @ipx_pass = Convert.to_string(UI.QueryWidget(:pass, :Value))
        if "" != Builtins.filterchars(@ipx_hostname, Printer.alnum_chars) &&
            "" != Builtins.filterchars(@ipx_queue, Printer.alnum_chars)
          @connection_uri = "novell://"
          if "" != Builtins.filterchars(@ipx_user, Printer.alnum_chars) &&
              Ops.greater_than(Builtins.size(@ipx_pass), 0)
            @connection_uri = Builtins.sformat(
              "%1%2:%3@",
              @connection_uri,
              @ipx_user,
              @ipx_pass
            )
          end
          @connection_uri = Builtins.sformat(
            "%1%2/%3",
            @connection_uri,
            @ipx_hostname,
            @ipx_queue
          )
          valid = true
        else
          Popup.Error(_("Servername and queue name could not be empty."))
        end
      when :beh
        @beh_original_uri = Convert.to_string(
          UI.QueryWidget(:beh_original_uri, :Value)
        )
        @beh_do_not_disable = Convert.to_boolean(
          UI.QueryWidget(:beh_do_not_disable, :Value)
        )
        @beh_attempts = Convert.to_string(
          UI.QueryWidget(:beh_attempts, :Value)
        )
        @beh_delay = Convert.to_string(UI.QueryWidget(:beh_delay, :Value))
        if "" !=
            Builtins.filterchars(@beh_original_uri, Printer.alnum_chars) &&
            "" != Builtins.filterchars(@beh_attempts, Printer.alnum_chars) &&
            "" != Builtins.filterchars(@beh_delay, Printer.alnum_chars)
          @connection_uri = Builtins.sformat(
            "beh:/%1/%2/%3/%4",
            @beh_do_not_disable ? "1" : "0",
            @beh_attempts,
            @beh_delay,
            @beh_original_uri
          )
          valid = true
        else
          Popup.Error(
            _(
              "Device URI, number of retries, and delay could not be empty."
            )
          )
        end
      when :pipe
        @pipe = Convert.to_string(UI.QueryWidget(:program, :Value))
        if "" != Builtins.filterchars(@pipe, Printer.alnum_chars)
          # because special URI characters like '/ ? = &' in pipe
          # must stay as is and not be percent encoded because pipe
          # contains all like 'path/to/command?option1=value1&option2=value2'
          @connection_uri = Builtins.sformat("pipe:/%1", @pipe)
          valid = true
        else
          Popup.Error(_("Could not be empty."))
        end
      else
        Builtins.y2warning(
          "validateAndMakeURI unknown selected value: '%1'",
          selected
        )
    end
    @connection_uri = "" if !valid
    valid
  end

  validateModel = lambda do |selected|
    case selected
      when :hplip, :parallel, :usb

      when :beh, :bluetooth, :cups, :ipp, :ipx, :lpd, :lpr, :pipe, :serial, :smb, :tcp, :uri
        @connection_model = Convert.to_string(
          UI.QueryWidget(Id("manufacturers_combo_box"), :Value)
        )
        if "" == @connection_model
          # Do not change or translate "raw", it is a technical term
          # when no driver is used for a print queue.
          Popup.Error(_("Select a manufacturer or 'raw queue'."))
          return false
        end
      else
        Builtins.y2warning(
          "validateModel unknown selected value: '%1'",
          selected
        )
    end
    true
  end

  scanForServers = lambda do |selected, all|
    hosts = []
    current_host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
    if all
      Builtins.y2milestone("scanForServers 'all'")
      Popup.ShowFeedback(
        _("Look up all hosts in the local network"),
        # Body of a Popup::ShowFeedback:
        _("Please wait...\nThis could take more than a minute.")
      )
      hosts = Convert.convert(
        SCR.Read(path(".net.hostnames")),
        :from => "any",
        :to   => "list <string>"
      )
      # Sleep half a second to let the user notice the Popup::ShowFeedback in any case
      # before it is removed even when the above SCR::Read finished immediately:
      Builtins.sleep(500)
      Popup.ClearFeedback
    else
      Builtins.y2milestone("scanForServers selected = '%1'", selected)
      case selected
        when :tcp
          @port = Convert.to_string(UI.QueryWidget(:port_or_queue, :Value))
          if "" == @port
            @port = "9100"
            UI.ChangeWidget(:port_or_queue, :Value, "9100")
          end
          Popup.ShowFeedback(
            # where %1 will be replaced by the port number:
            Builtins.sformat(
              _("Scan for hosts which are accessible via TCP port %1"),
              @port
            ),
            # Body of a Popup::ShowFeedback:
            _("Please wait...\nThis could take more than a minute.")
          )
          hosts = Convert.convert(
            SCR.Read(path(".net.hostnames"), Builtins.tointeger(@port)),
            :from => "any",
            :to   => "list <string>"
          )
          # Sleep half a second to let the user notice the Popup::ShowFeedback in any case
          # before it is removed even when the above SCR::Read finished immediately:
          Builtins.sleep(500)
          Popup.ClearFeedback
        when :smb
          Popup.ShowFeedback(
            _("Scan for hosts which are accessible via Samba (SMB)"),
            # Body of a Popup::ShowFeedback:
            _("Please wait...\nThis could take more than a minute.")
          )
          hosts = Convert.convert(
            SCR.Read(path(".net.hostnames.samba")),
            :from => "any",
            :to   => "list <string>"
          )
          # Sleep half a second to let the user notice the Popup::ShowFeedback in any case
          # before it is removed even when the above SCR::Read finished immediately:
          Builtins.sleep(500)
          Popup.ClearFeedback
        when :lpd, :lpr
          Popup.ShowFeedback(
            _("Scan for hosts which are accessible via port 515 (LPD/LPR)"),
            # Body of a Popup::ShowFeedback:
            _("Please wait...\nThis could take more than a minute.")
          )
          hosts = Convert.convert(
            SCR.Read(path(".net.hostnames"), 515),
            :from => "any",
            :to   => "list <string>"
          )
          # Sleep half a second to let the user notice the Popup::ShowFeedback in any case
          # before it is removed even when the above SCR::Read finished immediately:
          Builtins.sleep(500)
          Popup.ClearFeedback
        when :cups, :ipp
          Popup.ShowFeedback(
            _("Scan for hosts which are accessible via port 631 (CUPS/IPP)"),
            # Body of a Popup::ShowFeedback:
            _("Please wait...\nThis could take more than a minute.")
          )
          hosts = Convert.convert(
            SCR.Read(path(".net.hostnames"), 631),
            :from => "any",
            :to   => "list <string>"
          )
          #             hosts = (list<string>)filter (string h, hosts, ``{
          #                 list queues = (list<string>)SCR::Read (.cups.remote, h);
          #                 return size (queues) > 0;
          #             });
          # Sleep half a second to let the user notice the Popup::ShowFeedback in any case
          # before it is removed even when the above SCR::Read finished immediately:
          Builtins.sleep(500)
          Popup.ClearFeedback
        else
          Builtins.y2warning(
            "scanForServers unknown selected value: '%1'",
            selected
          )
      end
    end
    Builtins.y2milestone("scanForServers hosts = '%1'", hosts)
    if Ops.less_than(Builtins.size(hosts), 1)
      Popup.Message(
        _(
          "Scanning in the network did not find any host.\n(Network issue or firewall active?)"
        )
      )
      hosts = [current_host]
    end
    if !Builtins.contains(hosts, current_host)
      hosts = Builtins.prepend(hosts, current_host)
    end
    UI.ChangeWidget(:hostname, :Items, hosts)
    UI.ChangeWidget(:hostname, :Value, current_host)

    nil
  end

  testQueue = lambda do |selected|
    test_command = ""
    timeout = "5"
    host = ""
    port = ""
    queue = ""
    workgroup = ""
    user = ""
    password = ""
    case selected
      when :tcp
        host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        port = Convert.to_string(UI.QueryWidget(:port_or_queue, :Value))
        test_command = Builtins.sformat(
          "%1test_remote_socket \"%2\" \"%3\" %4",
          Printerlib.yast_bin_dir,
          host,
          port,
          timeout
        )
        if !Printerlib.ExecuteBashCommand(test_command)
          Popup.ErrorDetails(
            Builtins.sformat(
              # where %1 will be replaced by the port number
              # and %2 will be replaced by the host name:
              _("Access test failed for port '%1' on host '%2'."),
              port,
              host
            ), # Message of a Popup::ErrorDetails
            Ops.add(
              Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
              Ops.get_string(Printerlib.result, "stdout", "")
            )
          )
          return false
        end
      when :lpd, :lpr
        host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        queue = Convert.to_string(UI.QueryWidget(:port_or_queue, :Value))
        port = "515"
        test_command = Builtins.sformat(
          "%1test_remote_lpd \"%2\" \"%3\" %4",
          Printerlib.yast_bin_dir,
          host,
          queue,
          timeout
        )
        if !Printerlib.ExecuteBashCommand(test_command)
          Popup.ErrorDetails(
            Builtins.sformat(
              # where %1 will be replaced by the queue name
              # and %2 will be replaced by the host name:
              _("Access test failed for queue '%1' on host '%2'."),
              queue,
              host
            ), # Message of a Popup::ErrorDetails
            Ops.add(
              Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
              Ops.get_string(Printerlib.result, "stdout", "")
            )
          )
          return false
        end
      when :cups
        host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        queue = Convert.to_string(UI.QueryWidget(:queue, :Value))
        test_command = Builtins.sformat(
          "%1test_remote_ipp \"%2\" \"%3\" %4",
          Printerlib.yast_bin_dir,
          host,
          queue,
          timeout
        )
        if !Printerlib.ExecuteBashCommand(test_command)
          Popup.ErrorDetails(
            Builtins.sformat(
              # where %1 will be replaced by the queue name
              # and %2 will be replaced by the host name:
              _("Access test failed for queue '%1' on host '%2'."),
              queue,
              host
            ), # Message of a Popup::ErrorDetails
            Ops.add(
              Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
              Ops.get_string(Printerlib.result, "stdout", "")
            )
          )
          return false
        end
      when :smb
        @active_directory = Convert.to_boolean(
          UI.QueryWidget(:active_directory_check_box, :Value)
        )
        if @active_directory
          if !Popup.ContinueCancel(
              # because there is authentication via Active Directory (R) required:
              _(
                "This is only a generic test which may untruly report failures\n" +
                  "if authentication via Active Directory (R) is required.\n" +
                  "In this case a user who is allowed to print via Active Directory (R)\n" +
                  "should log in and test by himself if he can print from Gnome or KDE."
              )
            )
            return true
          end
        end
        host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        queue = Convert.to_string(UI.QueryWidget(:printer, :Value))
        workgroup = Convert.to_string(UI.QueryWidget(:domain, :Value))
        user = Convert.to_string(UI.QueryWidget(:user, :Value))
        password = Convert.to_string(UI.QueryWidget(:pass, :Value))
        test_command = Builtins.sformat(
          "%1test_remote_smb \"%2\" \"%3\" \"%4\" \"%5\" \"%6\" %7",
          Printerlib.yast_bin_dir,
          workgroup,
          host,
          queue,
          user,
          password,
          timeout
        )
        if !Printerlib.ExecuteBashCommand(test_command)
          if @active_directory
            Popup.ErrorDetails(
              Builtins.sformat(
                # where %1 will be replaced by the SMB share name
                # and %2 will be replaced by the host name:
                _(
                  "The generic test reports failures for share '%1' on host '%2'."
                ),
                queue,
                host
              ), # Message of a Popup::ErrorDetails
              Ops.add(
                Ops.add(
                  Ops.get_string(Printerlib.result, "stderr", ""),
                  "\n"
                ),
                Ops.get_string(Printerlib.result, "stdout", "")
              )
            )
            return true
          end
          Popup.ErrorDetails(
            Builtins.sformat(
              # where %1 will be replaced by the SMB share name
              # and %2 will be replaced by the host name:
              _("Access test failed for share '%1' on host '%2'."),
              queue,
              host
            ), # Message of a Popup::ErrorDetails
            Ops.add(
              Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
              Ops.get_string(Printerlib.result, "stdout", "")
            )
          )
          return false
        end
      when :ipx
        host = Convert.to_string(UI.QueryWidget(:hostname, :Value))
        queue = Convert.to_string(UI.QueryWidget(:queue, :Value))
        user = Convert.to_string(UI.QueryWidget(:user, :Value))
        password = Convert.to_string(UI.QueryWidget(:pass, :Value))
        test_command = Builtins.sformat(
          "%1test_remote_novell \"%2\" \"%3\" \"%4\" \"%5\" %6",
          Printerlib.yast_bin_dir,
          host,
          queue,
          user,
          password,
          timeout
        )
        if !Printerlib.ExecuteBashCommand(test_command)
          Popup.ErrorDetails(
            Builtins.sformat(
              # where %1 will be replaced by the queue name
              # and %2 will be replaced by the host name:
              _("Access test failed for queue '%1' on host '%2'."),
              queue,
              host
            ), # Message of a Popup::ErrorDetails
            Ops.add(
              Ops.add(Ops.get_string(Printerlib.result, "stderr", ""), "\n"),
              Ops.get_string(Printerlib.result, "stdout", "")
            )
          )
          return false
        end
    end
    Popup.Message(_("Test OK"))
    true
  end

  _UpdateConnectionsList = lambda do |selected|
    return false if "" == @connection_uri
    @connection_model = "Unknown" if "" == @connection_model
    # 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.
    uri_already_exists = false
    # I do not know if it is allowed to modify one same list "in place" via foreach like:
    #   list < string > words = [ "Jane", "World", "John" ];
    #   integer index = -1;
    #   foreach( string word,
    #            words,
    #            { index = index + 1;
    #              if( "World" == word )
    #              { words[index] = "Hello " + word;
    #              }
    #            }
    #          );
    # so that in any case the result words == [ "Jane", "Hello World", "John" ]
    # and therefore I prefer to be on the safe side with maplist
    # which might consume unnecessarily much memory and CPU
    # (maplist has two lists and all elements are at least copied
    #  instead of "in place" modification only where needed via foreach)
    # but for my small lists this does actually not matter:
    Printer.connections = Builtins.maplist(Printer.connections) do |connection_entry|
      if @connection_uri == Ops.get(connection_entry, "uri", "")
        uri_already_exists = true
        Builtins.y2internal(
          "UpdateConnectionsList: modify connections list type '%1' with uri '%2' for model '%3'",
          selected,
          @connection_uri,
          @connection_model
        )
        next {
          "uri"      => @connection_uri,
          "model"    => @connection_model,
          "deviceID" => "",
          "info"     => "modified by the connection wizard",
          "class"    => "ConnectionWizardDialog"
        }
      else
        next deep_copy(connection_entry)
      end
    end
    if !uri_already_exists
      Builtins.y2internal(
        "UpdateConnectionsList: adding connection type '%1' with uri '%2' for model '%3'",
        selected,
        @connection_uri,
        @connection_model
      )
      Printer.connections = Builtins.add(
        Printer.connections,
        {
          "uri"      => @connection_uri,
          "model"    => @connection_model,
          "deviceID" => "",
          "info"     => "created by the connection wizard",
          "class"    => "ConnectionWizardDialog"
        }
      )
    end
    # 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
    true
  end

  #UI::OpenDialog(content);
  ret = nil
  while ret != :back && ret != :next
    ret = UI.UserInput
    selected = Convert.to_symbol(UI.QueryWidget(:tree_selection, :Value))
    Builtins.y2milestone(
      "ConnectionWizardDialog selected = '%1', ret = '%2'",
      selected,
      ret
    )
    case Convert.to_symbol(ret)
      when :tree_selection
        changeSettingsDialog(selected)
      when :next
        if validateAndMakeURI.call(selected) && validateModel.call(selected)
          Builtins.y2milestone("ConnectionWizardDialog writing settings")
          _UpdateConnectionsList.call(selected)
        else
          Builtins.y2error(
            "ConnectionWizardDialog: Could not validate for '%1'",
            selected
          )
          ret = nil
        end
      when :scan_all
        scanForServers.call(selected, true)
      when :scan
        scanForServers.call(selected, false)
      when :test
        testQueue.call(selected) if validateAndMakeURI.call(selected)
      when :active_directory_check_box
        # Be backward compatible for openSUSE < 11.3 and be prepared for /usr/lib64/cups/
        Printerlib.ExecuteBashCommand(
          "ls -1 /usr/lib*/cups/backend/smb | head -n1 | tr -d '[:space:]'"
        )
        @smb_backend_link_name = Ops.get_string(
          Printerlib.result,
          "stdout",
          ""
        )
        # Without a link name /usr/lib[64]/cups/backend/smb (which is provided by samba-client)
        # the rest makes no sense (in particular the ln commands would create nonsense links in $PWD):
        if "" == @smb_backend_link_name
          UI.ChangeWidget(Id(:active_directory_check_box), :Value, false)
          UI.ChangeWidget(Id(:active_directory_check_box), :Enabled, false)
        else
          smb_backend_link_target_commandline = Ops.add(
            Ops.add("readlink ", @smb_backend_link_name),
            " | tr -d '[:space:]'"
          )
          if Convert.to_boolean(
              UI.QueryWidget(Id(:active_directory_check_box), :Value)
            )
            if !Printerlib.TestAndInstallPackage(
                "samba-krb-printing",
                "installed"
              )
              if Popup.ContinueCancel(
                  _(
                    "To support Active Directory (R), the RPM package samba-krb-printing must be installed."
                  )
                )
                Printerlib.TestAndInstallPackage(
                  "samba-krb-printing",
                  "install"
                )
                # There is no "abort" functionality which does a sudden death of the whole module (see dialogs.ycp).
                # Unfortunately when the YaST package installer is run via Printerlib::TestAndInstallPackage
                # it leaves a misused "abort" button labeled "Skip Autorefresh" with WidgetID "`abort"
                # so that this leftover "abort" button must be explicitly hidden here:
                Wizard.HideAbortButton
              end
            end
            # The user can also decide during the actual installation not to install it
            # or the installation may have failed for whatever reason
            # so that we test again whether or not it is now actually installed:
            if Printerlib.TestAndInstallPackage(
                "samba-krb-printing",
                "installed"
              )
              # or if samba-krb-printing is installed since a longer time
              # make sure that the symbolic link /usr/lib[64]/cups/backend/smb
              # points to /usr/bin/get_printing_ticket:
              Printerlib.ExecuteBashCommand(
                Ops.add(
                  "ln -sf /usr/bin/get_printing_ticket ",
                  @smb_backend_link_name
                )
              )
            end
          else
            Printerlib.ExecuteBashCommand(
              smb_backend_link_target_commandline
            )
            if "/usr/bin/get_printing_ticket" ==
                Ops.get_string(Printerlib.result, "stdout", "")
              # Show a user notification before it gets disabled:
              Popup.Warning(
                _(
                  "Active Directory (R) support will be disabled for all SMB print queues."
                )
              )
            end
            # Regardless if samba-krb-printing is installed or not,
            # only let the symbolic link /usr/lib[64]/cups/backend/smb
            # point to its traditional target /usr/bin/smbspool (provided by samba-client):
            Printerlib.ExecuteBashCommand(
              Ops.add("ln -sf /usr/bin/smbspool ", @smb_backend_link_name)
            )
          end
          # Detremine and set the actually right state of the active_directory_check_box:
          # Only if the /usr/lib[64]/cups/backend/smb link points to /usr/bin/get_printing_ticket
          # there is support for Active Directory (R) for SMB print queues.
          Printerlib.ExecuteBashCommand(smb_backend_link_target_commandline)
          if "/usr/bin/get_printing_ticket" ==
              Ops.get_string(Printerlib.result, "stdout", "")
            UI.ChangeWidget(Id(:active_directory_check_box), :Value, true)
          else
            UI.ChangeWidget(Id(:active_directory_check_box), :Value, false)
          end
        end
      else
        Builtins.y2milestone("Ignoring unexpected ret = '%1'", ret)
    end
  end
  # ret == `back || ret == `next
  deep_copy(ret) 
  #UI::CloseDialog();
end

- (Object) getContentFromBackend(backend)



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
# File '../../src/include/printer/connectionwizard.rb', line 478

def getContentFromBackend(backend)
  connection_items = []
  backend = Ops.add(backend, ":/")
  current_device_uri = getCurrentDeviceURI
  current_device_uri_found = false
  current_connection_item = nil
  Builtins.foreach(
    Convert.convert(
      Printer.ConnectionItems(""),
      :from => "list",
      :to   => "list <term>"
    )
  ) do |connection_item|
    # but Printer::ConnectionItems adds a trailing space character to model and uri
    # (because the current YaST UI has almost no additional space between table columns)
    # so that the last character must be removed to get the correct device URI value:
    uri = Ops.get_string(connection_item, 2, "")
    uri = Builtins.substring(uri, 0, Ops.subtract(Builtins.size(uri), 1))
    if backend == Builtins.substring(uri, 0, Builtins.size(backend))
      if current_device_uri == uri
        current_device_uri_found = true
        current_connection_item = deep_copy(connection_item)
      else
        connection_items = Builtins.add(connection_items, connection_item)
      end
    end
  end 

  if backend ==
      Builtins.substring(current_device_uri, 0, Builtins.size(backend))
    if !current_device_uri_found
      # Nevertheless the current connection must be topmost to be preselected because
      # anything else which might be topmost and preselected (even an empty value)
      # would silently change the current connection to the preselected one
      # when the user clicks [OK]:
      connection_items = Builtins.prepend(
        connection_items,
        # Add trailing spaces because the current YaST UI
        # has almost no additional space between table columns
        # in partitcular not where the widest entry in a column is:
        Item(
          Id(-1),
          "Unknown" + " ",
          Ops.add(current_device_uri, " "),
          "No longer valid (printer not connected?)"
        )
      )
    else
      # via the default Table widget preselection:
      connection_items = Builtins.prepend(
        connection_items,
        current_connection_item
      )
    end
  end
  content = VBox(
    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.
      connection_items
    )
  )
  deep_copy(content)
end

- (Object) getContentFromCurrentModel(no_default_raw_queue)



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
# File '../../src/include/printer/connectionwizard.rb', line 348

def getContentFromCurrentModel(no_default_raw_queue)
  content = nil
  current_model_info = Ops.get(
    Printer.connections,
    [Printer.selected_connections_index, "model"],
    ""
  )
  if "" == current_model_info ||
      "unknown" == Builtins.tolower(current_model_info)
    if Ops.greater_or_equal(Printer.selected_queues_index, 0)
      if "local" ==
          Ops.get(
            Printer.queues,
            [Printer.selected_queues_index, "config"],
            ""
          )
        ppd = Ops.get(
          Printer.queues,
          [Printer.selected_queues_index, "ppd"],
          ""
        )
        # 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
          no_default_raw_queue = false
        else
          no_default_raw_queue = true
        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)
            current_model_info = Ops.get_string(
              Printerlib.result,
              "stdout",
              ""
            )
          end
        end
      end
      if "" == current_model_info ||
          "unknown" == Builtins.tolower(current_model_info)
        current_model_info = Ops.get(
          Printer.queues,
          [Printer.selected_queues_index, "description"],
          ""
        )
      end
    end
  end
  if "" != current_model_info &&
      "unknown" != Builtins.tolower(current_model_info)
    current_model_info = Printer.DeriveModelName(current_model_info, 0)
    if no_default_raw_queue
      content = Left(
        ComboBox(
          Id("manufacturers_combo_box"),
          Opt(:editable),
          # Header for a ComboBox to keep the printer model or select another manufacturer:
          _("Keep the printer model or select another &manufacturer"),
          Builtins.prepend(
            Builtins.add(Printer.known_manufacturers, "Raw Queue"),
            current_model_info
          )
        )
      )
    else
      content = Left(
        ComboBox(
          Id("manufacturers_combo_box"),
          Opt(:editable),
          # Header for a ComboBox to optionally
          # keep the printer model or select a printer manufacturer.
          # Do not change or translate "raw", it is a technical term
          # when no driver is used for a print queue.
          _(
            "Keep the model or select a &manufacturer if no 'raw queue' should be set up"
          ),
          Builtins.prepend(
            Builtins.prepend(
              Printer.known_manufacturers,
              current_model_info
            ),
            "Raw Queue"
          )
        )
      )
    end
  else
    if no_default_raw_queue
      content = Left(
        ComboBox(
          Id("manufacturers_combo_box"),
          Opt(:editable),
          # Header for a ComboBox to select the printer manufacturer:
          _("Select the printer &manufacturer"),
          Builtins.prepend(
            Builtins.add(Printer.known_manufacturers, "Raw Queue"),
            ""
          )
        )
      )
    else
      content = Left(
        ComboBox(
          Id("manufacturers_combo_box"),
          Opt(:editable),
          # Header for a ComboBox to optionally select the printer manufacturer.
          # Do not change or translate "raw", it is a technical term
          # when no driver is used for a print queue.
          _(
            "Select a printer &manufacturer if no 'raw queue' should be set up."
          ),
          Builtins.prepend(Printer.known_manufacturers, "Raw Queue")
        )
      )
    end
  end
  deep_copy(content)
end

- (Object) getCurrentDeviceURI



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File '../../src/include/printer/connectionwizard.rb', line 245

def getCurrentDeviceURI
  if "" !=
      Ops.get(
        Printer.connections,
        [Printer.selected_connections_index, "uri"],
        ""
      )
    return Ops.get(
      Printer.connections,
      [Printer.selected_connections_index, "uri"],
      ""
    )
  end
  Ops.get(Printer.queues, [Printer.selected_queues_index, "uri"], "")
end

- (Object) getNetworkContent(hostname, scan_hosts_label, port_or_queue_label, port_or_queue, uri_options)



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
# File '../../src/include/printer/connectionwizard.rb', line 559

def getNetworkContent(hostname, scan_hosts_label, port_or_queue_label, port_or_queue, uri_options)
  hostname_label = _("&IP Address or Host Name")
  # No URIpercentDecoding/Encondin(hostname) is done
  # when it contains a '@' because a lpd URI can be of the form
  #   lpd://username@ip-address-or-hostname/...
  # and 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
  if Builtins.issubstring(hostname, "@")
    hostname_label = _("&IP Address or Host Name [percent-encoded]")
  end
  content = VBox(
    Left(
      HBox(
        ComboBox(Id(:hostname), Opt(:editable), hostname_label, [hostname]),
        MenuButton(
          _("Look up"),
          [
            Item(Id(:scan), scan_hosts_label),
            # TRANSLATORS: Button to search for remote servers
            Item(Id(:scan_all), _("Look up for All Hosts"))
          ]
        ) # TRANSLATORS: Label for menu to search for remote servers
      )
    ),
    Left(InputField(Id(:port_or_queue), port_or_queue_label, port_or_queue)),
    Left(
      InputField(
        Id(:uri_options),
        # Show it as wide as possible because it may have to contain
        # longer stuff like 'option1=value1&option2=value2':
        Opt(:hstretch),
        # TRANSLATORS: InputField for optional Device URI parameters:
        _(
          "Optional 'option=value' parameter (usually empty) [percent-encoded]"
        ),
        uri_options
      )
    ),
    Left(PushButton(Id(:test), _("&Test Connection"))) # TRANSLATORS: Button to test remote printer machine
  )
  deep_copy(content)
end

- (Object) getUriWithUsernameAndPassword(uri, scheme)



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
# File '../../src/include/printer/connectionwizard.rb', line 261

def getUriWithUsernameAndPassword(uri, scheme)
  # so that I may have to retrieve it directly form /etc/cups/printers.conf
  # but only in this special case (and not in general via tools/autodetect_print_queues)
  # because I also do not want to show the password needlessly in any dialog
  # (and/or needlessly in /var/log/YaST2/y2log via "Autodetected queues").
  # But the URI may be not in /etc/cups/printers.conf
  # because there was no queue set up with this device URI
  # (e.g. because the URI is right now created by the connection wizard)
  # or several queues in /etc/cups/printers.conf may match
  # or the URI may already contain a "username:password@" part
  # because it was created by a previous run of the connection wizard dialog
  # and now "username:password@" in the URI should be changed.
  # Therefore I do nothing if the URI already contains a '@'
  # in its second part parts[1] (note that parts[0] = "<scheme>:")
  # which indicates that a "username:password@" part already exists:
  parts = Builtins.splitstring(uri, "/")
  # Remove empty parts (e.g. <scheme>://server results ["<scheme>:","","server"]):
  parts = Builtins.filter(parts) { |part| "" != part }
  if !Builtins.issubstring(Ops.get(parts, 1, ""), "@")
    special_chars = "'\"\\()[]{}|^$?*+"
    part1 = Builtins.mergestring(
      Builtins.splitstring(Ops.get(parts, 1, ""), special_chars),
      "."
    )
    part2 = Builtins.mergestring(
      Builtins.splitstring(Ops.get(parts, 2, ""), special_chars),
      "."
    )
    # Let the whole pipe fail if any of its commands fail (requires bash):
    grepcommand = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Ops.add("set -o pipefail ; egrep '^DeviceURI ", scheme),
            "://[^:]+:[^@]+@"
          ),
          part1
        ),
        "/"
      ),
      part2
    )
    if "lpd" == scheme
      # to describe who requested a print job in the form lpd://username@ip-address-or-hostname/...
      # (i.e. grep only for "username@" instead of the usual "username:password@"):
      grepcommand = Ops.add(
        Ops.add(
          Ops.add(
            Ops.add(
              Ops.add("set -o pipefail ; egrep '^DeviceURI ", scheme),
              "://[^@]+@"
            ),
            part1
          ),
          "/"
        ),
        part2
      )
    end
    if "" != Ops.get(parts, 3, "")
      part3 = Builtins.mergestring(
        Builtins.splitstring(Ops.get(parts, 3, ""), special_chars),
        "."
      )
      grepcommand = Ops.add(Ops.add(grepcommand, "/"), part3)
    end
    grepcommand = Ops.add(grepcommand, "$' /etc/cups/printers.conf")
    Printerlib.ExecuteBashCommand(
      Ops.add(grepcommand, " | sort -u | wc -l | tr -d '[:space:]'")
    )
    if "1" == Ops.get_string(Printerlib.result, "stdout", "")
      # are unambiguous (exactly one or several exactly same such DeviceURIs)
      # so that I can actually get it form /etc/cups/printers.conf:
      if Printerlib.ExecuteBashCommand(
          Ops.add(
            grepcommand,
            " | head -n 1 | cut -s -d ' ' -f 2 | tr -d '[:space:]'"
          )
        )
        return Ops.get_string(Printerlib.result, "stdout", "")
      end
    end
  end
  # By default and as fallback return the unchanged URI:
  uri
end

- (Object) initialize_printer_connectionwizard(include_target)



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
# File '../../src/include/printer/connectionwizard.rb', line 31

def initialize_printer_connectionwizard(include_target)
  Yast.import "UI"

  textdomain "printer"

  Yast.import "Label"
  Yast.import "Printer"
  Yast.import "Printerlib"
  Yast.import "Popup"
  Yast.import "Wizard"

  Yast.include include_target, "printer/helps.rb"

  @connection_uri = ""
  @connection_model = ""

  # List of reserved URI characters ! # $ % & ' ( ) * + , / : ; = ? @ [ ]
  # (the % character is separated as percentage_percent_encoding)
  # plus the space character and their matching percent encodings
  # where each percent encoding must be exactly three characters
  # and uppercase letters, otherwise URIpercentDecoding would not work.
  # It is crucial to have "%":"%25" first so that URIpercentEncoding works correctly
  # because "%" must be replaced by "%25" first of all otherwise
  # a duplicate encoding would happen "Foo Bar" -> "Foo%20Bar" -> "Foo%2520Bar"
  # but only "Foo Bar" -> "Foo%20Bar" would be the correct encoding.
  # It is crucial to have "%":"%25" last so that URIpercentDecoding works correctly
  # because "%25" must be replaced by "%" last otherwise
  # a duplicate decoding would happen: "Foo%2520Bar" -> "Foo%20Bar" -> "Foo Bar".
  # but only "Foo%2520Bar" -> "Foo%20Bar" would be the correct decoding.
  # Therefore "%":"%25" cannot be at all in this list but is
  # separated as percentage_percent_encoding which is
  # prepended to this list so that URIpercentEncoding works correctly and
  # appended to this list so that URIpercentDecoding works correctly.
  # Unfortunately a simple map like $[ "%":"%25", " ":"%20", ... ]
  # does not work because in a map the ordering is not kept
  # even when there is no operation which changes the map
  # the internal ordering in a map is different
  # from how it was specified here.
  # It seems the internal ordering in a map is alphabetically sorted
  # so that $[ "%":"%25", " ":"%20", ... ] -> $[ " ":"%20", ... "%":"%25", ... ]
  # Therefore a list is used which keeps the initial ordering.
  @uri_percent_encodings = [
    { "character" => " ", "encoding" => "%20" },
    { "character" => "!", "encoding" => "%21" },
    { "character" => "#", "encoding" => "%23" },
    { "character" => "$", "encoding" => "%24" },
    { "character" => "&", "encoding" => "%26" },
    { "character" => "'", "encoding" => "%27" },
    { "character" => "(", "encoding" => "%28" },
    { "character" => ")", "encoding" => "%29" },
    { "character" => "*", "encoding" => "%2A" },
    { "character" => "+", "encoding" => "%2B" },
    { "character" => ",", "encoding" => "%2C" },
    { "character" => "/", "encoding" => "%2F" },
    { "character" => ":", "encoding" => "%3A" },
    { "character" => ";", "encoding" => "%3B" },
    { "character" => "=", "encoding" => "%3D" },
    { "character" => "?", "encoding" => "%3F" },
    { "character" => "@", "encoding" => "%40" },
    { "character" => "[", "encoding" => "%5B" },
    { "character" => "]", "encoding" => "%5D" }
  ]
  @percentage_percent_encoding = { "character" => "%", "encoding" => "%25" }
end

- (Object) URIpercentDecoding(input)



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
# File '../../src/include/printer/connectionwizard.rb', line 129

def URIpercentDecoding(input)
  # cannot be used because URL::transform_map_passwd is insufficient because
  # the characters ! # ' ( ) * [ ] are missing in URL::transform_map_passwd
  # and URL::UnEscapeString("Foo%2525Bar") results "Foo%Bar" which is wrong
  # because URIpercentDecoding("Foo%2525Bar") results "Foo%25Bar".
  # URIpercentDecoding is the opposite of the URIpercentEncoding function
  # so that URIpercentDecoding(URIpercentEncoding(input)) == input
  output = input
  # Assume the input is "First%3aSecond%3AThird%2525Rest"
  # Character positions: 0123456789012345678901234567890
  Builtins.foreach(
    Builtins.add(@uri_percent_encodings, @percentage_percent_encoding)
  ) do |current_encoding|
    character = Ops.get(current_encoding, "character", "")
    encoding = Ops.get(current_encoding, "encoding", "")
    next if "" == character || "" == encoding
    # Process the output of the previous foreach loop as rest_of_input
    # and clear the output for the current foreach loop:
    rest_of_input = output
    output = ""
    position = Builtins.search(rest_of_input, encoding)
    # For character = "%" and encoding = "%25"
    #   position = 22 = search( "First%3aSecond%3AThird%2525Rest", "%25" )
    # For character = ":" and encoding = "%3A"
    #   position = 14 = search( "First%3aSecond%3AThird%25Rest", "%3A" )
    position_lowercase = Builtins.search(
      rest_of_input,
      Builtins.tolower(encoding)
    )
    # For character = "%" and encoding = "%25"
    #   position_lowercase = 22 = search( "First%3aSecond%3AThird%2525Rest", "%25" )
    # For character = ":" and actual percent encoding = "%3a"
    #   position = 5 = search( "First%3aSecond%3AThird%25Rest", "%3a" )
    if position != nil && position_lowercase != nil &&
        Ops.less_than(position_lowercase, position) ||
        position == nil && position_lowercase != nil
      position = position_lowercase 
      # For character = ":" and actual percent encoding = "%3a"
      #   position = 5
    end
    # For character = "%" and encoding = "%25"
    #   position = 22
    while position != nil
      # the first position characters are those up to the current percent encoding
      # and at position + 3 the rest after the current percent encoding starts:
      characters_up_to_current_encoding = Builtins.substring(
        rest_of_input,
        0,
        position
      )
      output = Ops.add(
        Ops.add(output, characters_up_to_current_encoding),
        character
      )
      # For character = "%" and encoding = "%25"
      #   output = "First%3aSecond%3AThird%" = "" + "First%3aSecond%3AThird" + "%"
      # For character = ":" and actual percent encoding = "%3a"
      #   output = "First:" = "" + "First" + ":"
      # For character = ":" and encoding = "%3A"
      #   output = "First:Second:" = "First:" + "Second" + ":"
      rest_of_input = Builtins.substring(
        rest_of_input,
        Ops.add(position, 3)
      )
      # For character = "%" and encoding = "%25"
      #   rest_of_input = "25Rest"
      # For character = ":" and actual percent encoding = "%3a"
      #   rest_of_input = "Second%3AThird%25Rest"
      # For character = ":" and encoding = "%3A"
      #   rest_of_input = "Third%25Rest"
      position = Builtins.search(rest_of_input, encoding)
      # For character = "%" and encoding = "%25"
      #   position = nil = search( "25Rest", "%25" )
      # For character = ":" and encoding = "%3A"
      #   position = 6 = search( "Second%3AThird%25Rest", "%3A" )
      # For second while loop for character = ":" and encoding = "%3A"
      #   position = nil = search( "Third%25Rest", "%3A" )
      position_lowercase = Builtins.search(
        rest_of_input,
        Builtins.tolower(encoding)
      )
      # For character = "%" and encoding = "%25"
      #   position_lowercase = nil = search( "25Rest", "%25" )
      # For character = ":" and actual percent encoding = "%3a"
      #   position = nil = search( "Second%3AThird%25Rest", "%3a" )
      # For second while loop for character = ":" and actual percent encoding = "%3a"
      #   position = nil = search( "Third%25Rest", "%3a" )
      if position != nil && position_lowercase != nil &&
          Ops.less_than(position_lowercase, position) ||
          position == nil && position_lowercase != nil
        position = position_lowercase
      end 
      # For character = "%" and encoding = "%25"
      #   position = nil
      # For character = ":" and encoding = "%3A"
      #   position = 6
      # For second while loop for character = ":" and encoding = "%3A"
      #   position = nil
    end
    # After replacing all occurrences of the current percent encoding
    # by its character append what is left as rest of the input:
    output = Ops.add(output, rest_of_input) # For character = "%" and encoding = "%25"
    #   output = "First%3aSecond%3AThird%25Rest"
    # For character = ":" and encoding = "%3A"
    #   output = "First:Second:Third%25Rest"
  end 

  # output = "First:Second:Third%25Rest"
  Builtins.y2milestone(
    "URIpercentDecoding from '%1' to '%2'",
    input,
    output
  )
  output
end

- (Object) URIpercentEncoding(input)



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
# File '../../src/include/printer/connectionwizard.rb', line 96

def URIpercentEncoding(input)
  # cannot be used because URL::transform_map_passwd is insufficient because
  # the characters ! # ' ( ) * [ ] are missing in URL::transform_map_passwd.
  # URIpercentEncoding replaces the space character and
  # each reserved character ! # $ % & ' ( ) * + , / : ; = ? @ [ ]
  # in a value (component) of an URI with its matching percent encoding,
  # see https://bugzilla.novell.com/show_bug.cgi?id=512549
  # This function can only be used for percent encoding of the value
  # of a single URI component where no character in the input
  # is already percent encoded, otherwise e.g. "Foo%20Bar" results "Foo%2520Bar".
  # In particular this function cannot be used when the user can enter a whole URI
  # or the whole set of URI options (e.g. option1=value1&option2=value2).
  output = input
  Builtins.foreach(
    Builtins.prepend(@uri_percent_encodings, @percentage_percent_encoding)
  ) do |current_encoding|
    character = Ops.get(current_encoding, "character", "")
    encoding = Ops.get(current_encoding, "encoding", "")
    next if "" == character || "" == encoding
    output = Builtins.mergestring(
      Builtins.splitstring(output, character),
      encoding
    )
  end 

  Builtins.y2milestone(
    "URIpercentEncoding from '%1' to '%2'",
    input,
    output
  )
  output
end