Class: Yast::SourceDialogsClass

Inherits:
Module
  • Object
show all
Extended by:
I18n
Includes:
Logger
Defined in:
src/modules/SourceDialogs.rb,
src/modules/SourceDialogs.rb

Overview

Displays possibilities to install from NFS, CD or partion

Constant Summary collapse

WIDGET_LABELS =

widget ID => translatable label (needs to be translated by _())

{
  # radio button
  slp:               N_("&Scan Using SLP..."),
  # radio button
  comm_repos:        N_("Commun&ity Repositories"),
  # radio button
  sccrepos:          N_("&Extensions and Modules from Registration Server..."),
  # radio button
  specify_url:       N_("Specify &URL..."),
  # radio button
  ftp:               N_("&FTP..."),
  # radio button
  http:              N_("&HTTP..."),
  # radio button
  https:             N_("HTT&PS..."),
  # radio button
  samba:             N_("S&MB/CIFS"),
  # radio button
  nfs:               N_("NF&S..."),
  # radio button
  cd:                N_("&CD..."),
  # radio button
  dvd:               N_("&DVD..."),
  # radio button
  hd:                N_("&Hard Disk..."),
  # radio button
  usb:               N_("&USB Mass Storage (USB Stick, Disk)..."),
  # radio button
  local_dir:         N_("&Local Directory..."),
  # radio button
  local_iso:         N_("&Local ISO Image..."),
  # check box
  download_metadata: N_("&Download repository description files")
}.freeze
VALID_URL_SCHEMES =
["ftp", "tftp", "http", "https", "nfs",
"nfs4", "cifs", "smb", "cd", "dvd", "iso", "dir", "file", "hd"].freeze
SPECIAL_TYPES =

repository types which need special handling

[:slp, :cd, :dvd, :comm_repos, :sccrepos].freeze
FILE_BIN =
"/usr/bin/file".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addon_enabledObject (readonly)

the status of the global checkbox


17
18
19
# File 'src/modules/SourceDialogs.rb', line 17

def addon_enabled
  @addon_enabled
end

#display_addon_checkboxObject

display a global enable/disable checkbox in URL type dialog


15
16
17
# File 'src/modules/SourceDialogs.rb', line 15

def display_addon_checkbox
  @display_addon_checkbox
end

Instance Method Details

#addon_checkbox_termObject


2010
2011
2012
2013
2014
2015
2016
2017
2018
# File 'src/modules/SourceDialogs.rb', line 2010

def addon_checkbox_term
  return Empty() unless @display_addon_checkbox

  VBox(
    Left(CheckBox(Id(:add_addon), Opt(:notify),
      _("I would li&ke to install an additional Add On Product"), false)),
    VSpacing(1)
  )
end

#addon_spacing_termObject


2020
2021
2022
# File 'src/modules/SourceDialogs.rb', line 2020

def addon_spacing_term
  @display_addon_checkbox ? HSpacing(3) : Empty()
end

#CDInit(_key) ⇒ Object

Init function of a widget


799
800
801
802
803
804
805
806
807
808
809
# File 'src/modules/SourceDialogs.rb', line 799

def CDInit(_key)
  parsed = URL.Parse(@_url)
  scheme = Ops.get_string(parsed, "scheme", "")
  if scheme == "dvd"
    UI.ChangeWidget(Id(:dvd), :Value, true)
  else
    UI.ChangeWidget(Id(:cd), :Value, true)
  end

  nil
end

#CDStore(_key, _event) ⇒ Object

Store function of a widget


814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
# File 'src/modules/SourceDialogs.rb', line 814

def CDStore(_key, _event)
  device = Convert.to_symbol(UI.QueryWidget(Id(:device), :CurrentButton))
  parsed = URL.Parse(@_url)
  scheme = Builtins.tolower(Ops.get_string(parsed, "scheme", ""))

  # preserve other URL options, e.g. ?devices=/dev/sr0
  # change the URL only when necessary
  if device == :cd && scheme != "cd"
    @_url = "cd:///"
  elsif device == :dvd && scheme != "dvd"
    @_url = "dvd:///"
  end

  nil
end

#CDWidgetObject

Get widget description map


832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'src/modules/SourceDialogs.rb', line 832

def CDWidget
  {
    "widget"        => :custom,
    "custom_widget" => RadioButtonGroup(
      Id(:device),
      VBox(
        # radio button
        Left(RadioButton(Id(:cd), _("&CD-ROM"))),
        # radio button
        Left(RadioButton(Id(:dvd), _("&DVD-ROM")))
      )
    ),
    "init"          => fun_ref(method(:CDInit), "void (string)"),
    "store"         => fun_ref(method(:CDStore), "void (string, map)"),
    "help"          => _(
      "<p><big><b>CD or DVD Media</b></big><br>\n" \
        "Set <b>CD-ROM</b> or <b>DVD-ROM</b> to specify the type of media.</p>"
    )
  }
end

#confirm_abort?Boolean

Returns boolean whether user confirmed to abort the configuration


2701
2702
2703
# File 'src/modules/SourceDialogs.rb', line 2701

def confirm_abort?
  (Stage.initial ? Popup.ConfirmAbort(:painless) : Popup.ReallyAbort(SourceManager.Modified()))
end

#CRURLDefinedBoolean

Returns whether Community Repositories are defined in the control file.


1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
# File 'src/modules/SourceDialogs.rb', line 1992

def CRURLDefined
  link = ProductFeatures.GetStringFeature(
    "software",
    "external_sources_link"
  )

  Builtins.y2debug("software/external_sources_link -> '%1'", link)

  if link.nil? || link == ""
    Builtins.y2milestone(
      "No software/external_sources_link, community repos will be disabled"
    )
    false
  else
    true
  end
end

#DetectDisk(usb_only) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 1110

def DetectDisk(usb_only)
  Builtins.y2milestone("Detecting %1USB disks", usb_only ? "" : "non-")
  disks = Convert.convert(
    SCR.Read(path(".probe.disk")),
    from: "any",
    to:   "list <map>"
  )

  Builtins.y2debug("Detected disks: %1", disks)

  disks = Builtins.filter(disks) do |disk|
    Ops.get_string(disk, "driver", "") == "usb-storage" && usb_only ||
      Ops.get_string(disk, "driver", "") != "usb-storage" && !usb_only
  end

  Builtins.y2milestone("Found disks: %1", disks)

  ret = []

  Builtins.foreach(disks) do |disk|
    dev_id = GetDeviceID(Ops.get_list(disk, "dev_names", []))
    ret = Builtins.add(
      ret,
      "model"      => Ops.get_string(disk, "model", ""),
      # compute the size (number of sectors * size of sector)
      "size"       => Ops.multiply(
        Ops.get_integer(disk, ["resource", "size", 0, "x"], 0),
        Ops.get_integer(disk, ["resource", "size", 0, "y"], 0)
      ),
      "dev"        => Ops.get_string(disk, "dev_name", ""),
      "dev_by_id"  => dev_id,
      "partitions" => DetectPartitions(dev_id)
    )
  end

  Builtins.y2milestone("Disk configuration: %1", ret)

  deep_copy(ret)
end

#DetectHardDiskObject


1154
1155
1156
# File 'src/modules/SourceDialogs.rb', line 1154

def DetectHardDisk
  DetectDisk(false)
end

#DetectPartitions(disk_id) ⇒ Object


1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
# File 'src/modules/SourceDialogs.rb', line 1077

def DetectPartitions(disk_id)
  command = Builtins.sformat("ls %1-part*", disk_id)

  out = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))

  if Ops.get_integer(out, "exit", -1).nonzero?
    Builtins.y2error("Command %1 failed", command)
    return []
  end

  ret = Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
  ret_size = Builtins.size(ret)

  # remove empty string at the end
  if Ops.greater_than(ret_size, 0) &&
      Ops.get(ret, Ops.subtract(ret_size, 1), "dummy") == ""
    ret = Builtins.remove(ret, Ops.subtract(ret_size, 1))
  end

  deep_copy(ret)
end

#DetectUSBDiskObject


1150
1151
1152
# File 'src/modules/SourceDialogs.rb', line 1150

def DetectUSBDisk
  DetectDisk(true)
end

#DirHandle(_key, _event) ⇒ Object

Handle function of a widget


928
929
930
931
932
933
934
935
936
# File 'src/modules/SourceDialogs.rb', line 928

def DirHandle(_key, _event)
  dir = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  # dialog caption
  result = UI.AskForExistingDirectory(dir, _("Local Directory"))

  UI.ChangeWidget(Id(:dir), :Value, result) if !result.nil?

  nil
end

#DirInit(_key) ⇒ Object

Init function of a widget


857
858
859
860
861
862
863
864
865
866
867
868
869
870
# File 'src/modules/SourceDialogs.rb', line 857

def DirInit(_key)
  parsed = URL.Parse(@_url)

  path = parsed["path"]
  path = "/" if path.empty?

  UI.ChangeWidget(Id(:dir), :Value, path)
  UI.SetFocus(:dir)

  # is it a plain directory?
  UI.ChangeWidget(Id(:ch_plain), :Value, @_plaindir)

  nil
end

#DirStore(_key, _event) ⇒ Object

Store function of a widget


888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
# File 'src/modules/SourceDialogs.rb', line 888

def DirStore(_key, _event)
  parsed = URL.Parse(@_url)

  # keep file:// scheme if it was used originally
  scheme = parsed["scheme"] || ""
  scheme = "dir" if !scheme.casecmp("file").zero?

  parsed = {
    "scheme" => scheme,
    "path"   => Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  }

  if Convert.to_boolean(UI.QueryWidget(Id(:ch_plain), :Value))
    @_plaindir = true
  end

  @_url = URL.Build(parsed)

  nil
end

#DirValidate(_key, _event) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 952

def DirValidate(_key, _event)
  s = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  if s.nil? || s == ""
    # error popup
    Popup.Error(Message.RequiredItem)
    UI.SetFocus(Id(:dir))
    return false
  end

  stat = Convert.to_map(SCR.Read(path(".target.stat"), s))

  Builtins.y2milestone("stat %1: %2", s, stat)

  if !Ops.get_boolean(stat, "isdir", false)
    # error popup - the entered path is not a directory
    Report.Error(
      _(
        "The entered path is not a directory\nor the directory does not exist.\n"
      )
    )
    UI.SetFocus(Id(:dir))

    return false
  end

  true
end

#DirWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 1036

def DirWidget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      HBox(
        # text entry
        InputField(Id(:dir), Opt(:hstretch), _("&Path to Directory")),
        VBox(
          Label(""),
          # push button
          PushButton(Id(:browse), Label.BrowseButton)
        )
      ),
      # checkbox label
      Left(CheckBox(Id(:ch_plain), _("&Plain RPM Directory")))
    ),
    "init"              => fun_ref(method(:DirInit), "void (string)"),
    "store"             => fun_ref(method(:DirStore), "void (string, map)"),
    "handle"            => fun_ref(
      method(:DirHandle),
      "symbol (string, map)"
    ),
    "handle_events"     => [:browse],
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:DirValidate),
      "boolean (string, map)"
    ),
    "help"              => Ops.add(
      _(
        "<p><big><b>Local Directory</b></big><br>\n" \
          "Use <b>Path to Directory</b> to specify the path to the\n" \
          "directory. If the directory contains only RPM packages without\n" \
          "any metadata (i.e. there is no product information), then check option\n" \
          "<b>Plain RPM Directory</b>.</p>\n"
      ),
      @multi_cd_help
    )
  }
end

#DiskInit(_key) ⇒ Object

Init function of a widget


1323
1324
1325
1326
1327
1328
1329
# File 'src/modules/SourceDialogs.rb', line 1323

def DiskInit(_key)
  # refresh the cache
  disks = DetectHardDisk()
  InitDiskWidget(disks)

  nil
end

#DiskSelectionList(disks, selected) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 1158

def DiskSelectionList(disks, selected)
  disks = deep_copy(disks)
  ret = []
  found = false

  Builtins.foreach(disks) do |disk|
    label = Ops.get_string(disk, "model", "")
    # add size if it's known and there is just one partition
    # TODO detect size of each partition
    sz = Ops.get_integer(disk, "size", 0)
    if Ops.greater_than(sz, 0) &&
        Builtins.size(Ops.get_list(disk, "partitions", [])) == 1
      label = Ops.add(Ops.add(label, " - "), String.FormatSize(sz))
    end
    dev = Ops.get_string(disk, "dev", "")
    Builtins.foreach(Ops.get_list(disk, "partitions", [])) do |part|
      partnum = Builtins.regexpsub(part, ".*-part([0-9]*)$", "\\1")
      disk_label = Ops.add(label, Builtins.sformat(" (%1%2)", dev, partnum))
      found ||= part == selected
      ret = Builtins.add(ret, Item(Id(part), disk_label, part == selected))
    end
  end

  if !found && Builtins.regexpmatch(selected, "^/dev/disk/by-id/usb-")
    Builtins.y2milestone(
      "USB disk %1 is not currently attached, adding the raw device to the list",
      selected
    )

    # remove the /dev prefix
    dev_name = Builtins.regexpsub(
      selected,
      "^/dev/disk/by-id/usb-(.*)",
      "\\1"
    )
    ret = Builtins.add(ret, Item(Id(selected), dev_name, true))
  end

  deep_copy(ret)
end

#DiskStore(_key, _event) ⇒ Object

Store function of a widget


1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
# File 'src/modules/SourceDialogs.rb', line 1334

def DiskStore(_key, _event)
  # build URL like this: usb:///openSUSE?device=/dev/sdb8&filesystem=auto
  query = Builtins.sformat(
    "device=%1&filesystem=%2",
    Convert.to_string(UI.QueryWidget(Id(:disk), :Value)),
    Convert.to_string(UI.QueryWidget(Id(:fs), :Value))
  )

  dir = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))

  @_plaindir = Convert.to_boolean(UI.QueryWidget(Id(:ch_plain), :Value))

  parsed = { "scheme" => "hd", "path" => dir, "query" => query }

  @_url = URL.Build(parsed)

  Builtins.y2milestone("New Disk url: %1", URL.HidePassword(@_url))

  nil
end

#DiskWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 1357

def DiskWidget
  {
    "widget"        => :custom,
    "custom_widget" => VBox(
      # combobox title
      ComboBox(Id(:disk), Opt(:hstretch), _("&Disk Device")),
      ComboBox(Id(:fs), Opt(:editable), _("&File System")),
      InputField(Id(:dir), _("Dire&ctory")),
      Left(CheckBox(Id(:ch_plain), _("&Plain RPM Directory")))
    ),
    "init"          => fun_ref(method(:DiskInit), "void (string)"),
    "store"         => fun_ref(method(:DiskStore), "void (string, map)"),
    "help"          => _(
      "<p><big><b>Disk</b></big><br>\n" \
        "Select the disk on which the repository is located.\n" \
        "Use <b>Path to Directory</b> to specify the directory of the repository.\n" \
        "If the path is omitted, the system will use the root directory of the disk.\n" \
        "If the directory contains only RPM packages without\n" \
        "any metadata (i.e. there is no product information), then check option\n" \
        "<b>Plain RPM Directory</b>.</p>\n"
    ) +
      # 'auto' is a value in the combo box widget, do not translate it!
      _(
        "<p>The file system used on the device will be detected automatically\n" \
          "if you select file system 'auto'. If the detection fails or you\n" \
          "want to use a certain file system, select it from the list.</p>\n"
      )
  }
end

#EditDialogSymbol

Sample implementation of URL selection dialog


2631
2632
2633
2634
2635
# File 'src/modules/SourceDialogs.rb', line 2631

def EditDialog
  proto = URLScheme(@_url)

  EditDialogProtocol(proto)
end

#EditDialogProtocol(proto) ⇒ Symbol

Sample implementation of URL selection dialog


2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
# File 'src/modules/SourceDialogs.rb', line 2593

def EditDialogProtocol(proto)
  Builtins.y2milestone("Displaying dialog for protocol %1", proto)
  caption = Ops.get(@_caption, proto, "")

  CWM.ShowAndRun(
    "widget_names"       => ["repo_name", proto],
    "widget_descr"       => Widgets(),
    "contents"           => HVCenter(
      MinWidth(65, VBox("repo_name", proto))
    ),
    "caption"            => caption,
    "back_button"        => Label.BackButton,
    "next_button"        => Label.NextButton,
    "fallback_functions" => @default_cwm_fallback_functions
  )
end

#EditDialogProtocolService(proto) ⇒ Symbol

Sample implementation of URL selection dialog


2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
# File 'src/modules/SourceDialogs.rb', line 2612

def EditDialogProtocolService(proto)
  Builtins.y2milestone("Displaying service dialog for protocol %1", proto)
  caption = Ops.get(@_caption, proto, "")

  CWM.ShowAndRun(
    "widget_names"       => ["service_name", proto],
    "widget_descr"       => Widgets(),
    "contents"           => HVCenter(
      MinWidth(65, VBox("service_name", proto))
    ),
    "caption"            => caption,
    "back_button"        => Label.BackButton,
    "next_button"        => Label.NextButton,
    "fallback_functions" => @default_cwm_fallback_functions
  )
end

#EditDisplayObject


2545
2546
2547
# File 'src/modules/SourceDialogs.rb', line 2545

def EditDisplay
  EditDisplayInt(true)
end

#EditDisplayInt(repository) ⇒ Object


2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
# File 'src/modules/SourceDialogs.rb', line 2521

def EditDisplayInt(repository)
  proto = URLScheme(@_url)

  Builtins.y2milestone(
    "Displaying %1 popup for protocol %2",
    repository ? "repository" : "service",
    proto
  )

  w = CWM.CreateWidgets(
    [repository ? "repo_name" : "service_name", proto],
    Widgets()
  )
  Builtins.y2milestone("w: %1", w)
  contents = PopupContents(proto, repository)
  contents = CWM.PrepareDialog(contents, w)
  UI.OpenDialog(contents)
  ret = CWM.Run(w, {})
  Builtins.y2milestone("Ret: %1", ret)
  UI.CloseDialog

  ret == :ok ? GetURL() : ""
end

#EditDisplayServiceObject


2549
2550
2551
# File 'src/modules/SourceDialogs.rb', line 2549

def EditDisplayService
  EditDisplayInt(false)
end

#EditPopup(url) ⇒ String

URL editation popup


2556
2557
2558
2559
2560
# File 'src/modules/SourceDialogs.rb', line 2556

def EditPopup(url)
  SetURL(url)

  EditDisplay()
end

#EditPopupNoHTTPS(url) ⇒ String

URL editation popup without the HTTPS option


2584
2585
2586
2587
2588
2589
# File 'src/modules/SourceDialogs.rb', line 2584

def EditPopupNoHTTPS(url)
  @_allow_https = false
  ret = EditPopup(url)
  @_allow_https = true
  ret
end

#EditPopupService(url) ⇒ String

URL editation popup


2565
2566
2567
2568
2569
# File 'src/modules/SourceDialogs.rb', line 2565

def EditPopupService(url)
  SetURL(url)

  EditDisplayService()
end

#EditPopupType(url, plaindir_type) ⇒ String

URL editation popup, allows setting plaindir type


2575
2576
2577
2578
2579
# File 'src/modules/SourceDialogs.rb', line 2575

def EditPopupType(url, plaindir_type)
  SetURLType(url, plaindir_type)

  EditDisplay()
end

#GetDeviceID(devices) ⇒ Object


1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
# File 'src/modules/SourceDialogs.rb', line 1099

def GetDeviceID(devices)
  devices = deep_copy(devices)
  ret = ""

  Builtins.foreach(devices) do |dev|
    ret = dev if Builtins.regexpmatch(dev, "^/dev/disk/by-id/")
  end

  ret
end

#GetDownloadOptionObject


2422
2423
2424
# File 'src/modules/SourceDialogs.rb', line 2422

def GetDownloadOption
  
end

#GetRawURLString

Return the configured URL in the dialog, do not do any conversion (return the internal value)


292
293
294
# File 'src/modules/SourceDialogs.rb', line 292

def GetRawURL
  @_url
end

#GetRepoNameString

Return RepoName after the run of the dialog


310
311
312
# File 'src/modules/SourceDialogs.rb', line 310

def GetRepoName
  @_repo_name
end

#GetURLString

Return URL after the run of the dialog


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'src/modules/SourceDialogs.rb', line 274

def GetURL
  parsed = URL.Parse(@_url)

  # usb scheme is not valid, it's used only internally
  # convert it for external clients
  if Ops.get_string(parsed, "scheme", "") == "usb"
    Ops.set(parsed, "scheme", "hd")

    Ops.set(parsed, "path", "/") if Ops.get_string(parsed, "path", "") == ""

    URL.Build(parsed)
  else
    @_url
  end
end

#global_disableBoolean

Get the status of the global checkbox.


2267
2268
2269
# File 'src/modules/SourceDialogs.rb', line 2267

def global_disable
  UI.WidgetExists(:add_addon) && !UI.QueryWidget(:add_addon, :Value)
end

#InitDiskWidget(disks) ⇒ Object

common code for USBInit() and DiskInit()


1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
# File 'src/modules/SourceDialogs.rb', line 1224

def InitDiskWidget(disks)
  disks = deep_copy(disks)
  parsed = URL.Parse(@_url)
  query = URL.MakeMapFromParams(Ops.get_string(parsed, "query", ""))

  UI.ChangeWidget(
    Id(:disk),
    :Items,
    DiskSelectionList(disks, Ops.get(query, "device", ""))
  )

  SetFileSystems(Ops.get(query, "filesystem", "auto"))

  UI.ChangeWidget(Id(:dir), :Value, Ops.get_string(parsed, "path", ""))

  # is it a plain directory?
  UI.ChangeWidget(Id(:ch_plain), :Value, @_plaindir)

  UI.SetFocus(:disk)

  nil
end

#InitFocusServerInit(server_type) ⇒ Object


1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
# File 'src/modules/SourceDialogs.rb', line 1423

def InitFocusServerInit(server_type)
  case server_type
  when :ftp
    UI.SetFocus(:server)
  when :http
    UI.SetFocus(:server)
  when :https
    UI.SetFocus(:server)
  when :samba
    UI.SetFocus(:server)
  end

  nil
end

#IsAnyNetworkAvailableObject

Checks whether some network is available in the current moment, see the bug #170147 for more information.


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
# File 'src/modules/SourceDialogs.rb', line 1962

def IsAnyNetworkAvailable
  ret = false

  command = "TERM=dumb /sbin/ip -o address show | grep inet | grep -v scope.host"
  Builtins.y2milestone("Running %1", command)
  cmd_run = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), command)
  )
  Builtins.y2milestone("Command returned: %1", cmd_run)

  # command failed
  if Ops.get_integer(cmd_run, "exit", -1).nonzero?
    # some errors were there, we don't know the status, rather return that it's available
    # `grep` also returns non zero exit code when there is nothing to do...
    if Ops.get_string(cmd_run, "stdout", "") != ""
      Builtins.y2error("Checking the network failed")
      ret = true
    end
    # some devices are listed
  elsif !Ops.get_string(cmd_run, "stdout", "").nil? &&
      Ops.get_string(cmd_run, "stdout", "") != ""
    ret = true
  end

  ret
end

#IsISOURL(url) ⇒ Boolean

Check if URL is an ISO URL


349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'src/modules/SourceDialogs.rb', line 349

def IsISOURL(url)
  begin
    uri = URI(url)
  rescue URI::InvalidURIError
    return false
  end

  # empty or generic uri have nil scheme causing exception below (bnc#934216)
  return false if uri.scheme.nil?

  params = URI.decode_www_form(uri.query || "").to_h

  uri.scheme.casecmp("iso").zero? && params.key?("url")
end

#IsoHandle(_key, _event) ⇒ Object

Handle function of a widget


942
943
944
945
946
947
948
949
950
# File 'src/modules/SourceDialogs.rb', line 942

def IsoHandle(_key, _event)
  dir = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  # dialog caption
  result = UI.AskForExistingFile(dir, "*", _("ISO Image File"))

  UI.ChangeWidget(Id(:dir), :Value, result) if !result.nil?

  nil
end

#IsoInit(_key) ⇒ Object

Init function of a widget


874
875
876
877
878
879
880
881
882
883
# File 'src/modules/SourceDialogs.rb', line 874

def IsoInit(_key)
  @_url = PreprocessISOURL(@_url)
  parsed = URI.parse(@_url)
  path = URI.unescape(parsed.path)

  UI.ChangeWidget(Id(:dir), :Value, path)
  UI.SetFocus(:dir)

  nil
end

#IsoStore(_key, _event) ⇒ Object

Store function of a widget


912
913
914
915
916
917
918
919
920
921
922
# File 'src/modules/SourceDialogs.rb', line 912

def IsoStore(_key, _event)
  parsed = {
    "scheme" => "iso",
    "path"   => Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  }

  @_url = URL.Build(parsed)
  @_url = PostprocessISOURL(@_url)

  nil
end

#IsoValidate(_key, _event) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 980

def IsoValidate(_key, _event)
  s = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  if s.nil? || s == ""
    # error popup
    Popup.Error(Message.RequiredItem)
    UI.SetFocus(Id(:dir))
    return false
  end

  stat = Convert.to_map(SCR.Read(path(".target.stat"), s))

  Builtins.y2milestone("stat %1: %2", s, stat)

  if !Ops.get_boolean(stat, "isreg", false)
    # error popup - the entered path is not a regular file
    Report.Error(
      _("The entered path is not a file\nor the file does not exist.\n")
    )
    UI.SetFocus(Id(:dir))

    return false
  end

  file = "/usr/bin/file"
  # try to detect ISO image by file if it's present
  if Ops.greater_than(SCR.Read(path(".target.size"), file), 0)
    # Use also -k as new images contain at first DOS boot sector for UEFI
    # then iso magic block
    command = Builtins.sformat("%1 -kb -- '%2'", file, String.Quote(s))

    out = SCR.Execute(path(".target.bash_output"), command)

    stdout = out["stdout"] || ""

    if stdout.include? "ISO 9660 CD-ROM filesystem"
      Builtins.y2milestone("ISO 9660 image detected")
    else
      # continue/cancel popup, %1 is a file name
      return Popup.ContinueCancel(
        Builtins.sformat(
          _(
            "File '%1'\n" \
              "does not seem to be an ISO image.\n" \
              "Use it anyway?\n"
          ),
          s
        )
      )
    end
  end

  true
end

#IsoWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 1389

def IsoWidget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      HBox(
        # text entry
        InputField(Id(:dir), Opt(:hstretch), _("&Path to ISO Image")),
        VBox(
          Label(""),
          # push button
          PushButton(Id(:browse), Label.BrowseButton)
        )
      )
    ),
    "init"              => fun_ref(method(:IsoInit), "void (string)"),
    "store"             => fun_ref(method(:IsoStore), "void (string, map)"),
    "handle"            => fun_ref(
      method(:IsoHandle),
      "symbol (string, map)"
    ),
    "handle_events"     => [:browse],
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:IsoValidate),
      "boolean (string, map)"
    ),
    "help"              => _(
      "<p><big><b>Local ISO Image</b></big><br>\n" \
        "Use <b>Path to ISO Image</b> to specify the path to the\n" \
        "ISO image file.</p>"
    )
  }
end

#IsPlainDirObject


296
297
298
# File 'src/modules/SourceDialogs.rb', line 296

def IsPlainDir
  @_plaindir
end

#mainObject


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'src/modules/SourceDialogs.rb', line 62

def main
  Yast.import "Pkg"
  Yast.import "UI"
  textdomain "packager"

  Yast.import "Label"
  Yast.import "URL"
  Yast.import "URLRecode"
  Yast.import "Popup"
  Yast.import "CWM"
  Yast.import "SourceManager"
  Yast.import "Message"
  Yast.import "Report"
  Yast.import "NetworkPopup"
  Yast.import "String"
  Yast.import "Hostname"
  Yast.import "IP"
  Yast.import "ProductControl"
  Yast.import "ProductFeatures"
  Yast.import "Stage"
  Yast.import "WFM"

  # common functions / data

  # URL to work with
  @_url = ""

  # The repo at _url is plaindir
  @_plaindir = false

  # Repo name to work with
  @_repo_name = ""

  # value of the "download" check box
   = true

  # Allow HTTPS for next repository dialog?
  @_allow_https = true

  # display a check box in type selection dialog in the next run
  @display_addon_checkbox = false

  # CD/DVD device name to use (e.g. /dev/sr1) in case of multiple
  # devices in the system. Empty string means use the default.
  @cd_device_name = ""

  # Help text suffix for some types of the media
  @iso_help = _(
    "<p>If the location is a file holding an ISO image\nof the media, set <b>ISO Image</b>.</p>"
  )

  # Help text suffix for some types of the media
  @multi_cd_help = _(
    "<p>If the repository is on multiple media,\n" \
      "set the location of the first media of the set.</p>\n"
  )

  # Belongs to a constant, but can't be there because of `fun_ref`
  @default_cwm_fallback_functions = {
    abort: fun_ref(method(:confirm_abort?), "boolean ()")
  }

  # NFS editation widget

  @nfs_details_content = VBox(
    HBox(
      # text entry
      InputField(Id(:server), Opt(:hstretch), _("&Server Name")),
      VBox(Label(""), PushButton(Id(:nfs_browse), Label.BrowseButton))
    ),
    HBox(
      # text entry
      InputField(
        Id(:dir),
        Opt(:hstretch),
        _("&Path to Directory or ISO Image")
      ),
      VBox(
        Label(""),
        PushButton(Id(:nfs_exports_browse), Label.BrowseButton)
      )
    ),
    # checkbox label
    Left(CheckBox(Id(:ch_iso), _("&ISO Image"))),
    # checkbox label
    Left(CheckBox(Id(:ch_nfs4), _("N&FS v4 Protocol"))),
    VSpacing(0.4),
    Left(
      ComboBox(
        Id(:mount_options),
        Opt(:editable),
        _("Mount Options"),
        [
          # TRANSLATORS: "(default)" - is a combobox value and means default libzypp
          # NFS mount option (users can change it to anything else, the field is editable)
          Item(Id(:default), _("(default)"), true),
          "ro,nolock,soft,timeo=300",
          "ro,nolock,soft,timeo=300,sec=krb5p"
        ]
      )
    )
  )

  @nfs_complete_content = InputField(
    Id(:complete_url),
    Opt(:hstretch),
    _("URL of the Repository")
  )

  # dialog contents for different views

  @details_content = VBox(
    HBox(
      HSpacing(0.5),
      # frame
      Frame(_("P&rotocol"), ReplacePoint(Id(:rb_type_rp), Empty())),
      HSpacing(0.5)
    ),
    ReplacePoint(Id(:server_rp), Empty())
  )

  # input field label
  @complete_content = InputField(
    Id(:complete_url),
    Opt(:hstretch),
    _("&URL of the Repository")
  )

  # use selected editing URL part, remember the value in case the URL is wrong
  # and the dialog needs to displayed again
  @editing_parts = false

  # general data

  # Individual widgets
  @_widgets = {}

  # Captions for individual protocols
  @_caption = {
    # label / dialog caption
    "url"   => _("Repository URL"),
    # label / dialog caption
    "nfs"   => _("NFS Server"),
    # label / dialog caption
    "cd"    => _("CD or DVD Media"),
    # label / dialog caption
    "dvd"   => _("CD or DVD Media"),
    # label / dialog caption
    "hd"    => _("Hard Disk"),
    # label / dialog caption
    "usb"   => _("USB Stick or Disk"),
    # label / dialog caption
    "dir"   => _("Local Directory"),
    # label / dialog caption
    "iso"   => _("Local ISO Image"),
    # label / dialog caption
    "http"  => _("Server and Directory"),
    # label / dialog caption
    "https" => _("Server and Directory"),
    # label / dialog caption
    "ftp"   => _("Server and Directory"),
    # label / dialog caption
    "smb"   => _("Server and Directory"),
    # label / dialog caption
    "cifs"  => _("Server and Directory")
  }
end

#network_buttonObject


2031
2032
2033
2034
2035
2036
2037
# File 'src/modules/SourceDialogs.rb', line 2031

def network_button
  if Mode.installation || Mode.live_installation || Mode.update
    Right(PushButton(Id(:network), _("Net&work Configuration...")))
  else
    Empty()
  end
end

#NFSHandle(key, event) ⇒ Object

Handle function of a widget


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
# File 'src/modules/SourceDialogs.rb', line 710

def NFSHandle(key, event)
  event = deep_copy(event)
  Builtins.y2debug("NFSHandle: key: %1, event: %2", key, event)

  if Ops.get(event, "ID") == :nfs_browse
    server = Convert.to_string(UI.QueryWidget(Id(:server), :Value))
    # dialog caption
    result = NetworkPopup.NFSServer(server)

    UI.ChangeWidget(Id(:server), :Value, result) if !result.nil?
  elsif Ops.get(event, "ID") == :nfs_exports_browse
    server = Convert.to_string(UI.QueryWidget(Id(:server), :Value))
    nfs_export = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
    # dialog caption
    result = NetworkPopup.NFSExport(server, nfs_export)

    UI.ChangeWidget(Id(:dir), :Value, result) if !result.nil?
  elsif (Ops.get(event, "ID") == :edit_url_parts ||
      Ops.get(event, "ID") == :edit_complete_url) &&
      Ops.get_string(event, "EventReason", "") == "ValueChanged"
    Builtins.y2milestone("Changing dialog type: %1", Ops.get(event, "ID"))

    # store the current settings
    if Ops.get(event, "ID") == :edit_url_parts
      NFSStoreComplete()
    else
      NFSStoreParts()
    end

    # reinitialize the dialog (set the current values)
    NFSInit(nil)
  end

  nil
end

#NFSInit(_key) ⇒ Object

Init function of a widget


597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'src/modules/SourceDialogs.rb', line 597

def NFSInit(_key)
  # check the current edit type
  current_type = Convert.to_symbol(UI.QueryWidget(Id(:edit_type), :Value))
  Builtins.y2debug("Current edit type: %1", current_type)

  UI.ReplaceWidget(
    Id(:edit_content),
    current_type == :edit_url_parts ? @nfs_details_content : @nfs_complete_content
  )

  if current_type == :edit_url_parts
    iso = IsISOURL(@_url)

    repo_url = @_url

    repo_url = PreprocessISOURL(repo_url) if iso

    parsed = URL.Parse(repo_url)
    UI.ChangeWidget(Id(:server), :Value, Ops.get_string(parsed, "host", ""))
    UI.ChangeWidget(Id(:dir), :Value, Ops.get_string(parsed, "path", ""))
    UI.ChangeWidget(Id(:ch_iso), :Value, iso)
    UI.SetFocus(:server)

    query_map = URL.MakeMapFromParams(Ops.get_string(parsed, "query", ""))

    nfs4 = Builtins.tolower(Ops.get_string(parsed, "scheme", "nfs")) == "nfs4" ||
      Ops.get_string(query_map, "type", "") == "nfs4"

    if Ops.get_string(parsed, "query", "") != ""
      UI.ChangeWidget(
        Id(:mount_options),
        :Value,
        Ops.get_string(query_map, "mountoptions", "")
      )
    end

    Builtins.y2milestone("NFSv4: %1", nfs4)

    UI.ChangeWidget(Id(:ch_nfs4), :Value, nfs4)
  else
    UI.ChangeWidget(Id(:complete_url), :Value, @_url)
  end

  nil
end

#NFSStore(_key, _event) ⇒ Object

Store function of a widget


693
694
695
696
697
698
699
700
701
702
703
704
# File 'src/modules/SourceDialogs.rb', line 693

def NFSStore(_key, _event)
  current_type = Convert.to_symbol(UI.QueryWidget(Id(:edit_type), :Value))
  Builtins.y2milestone("Current edit type: %1", current_type)

  if current_type == :edit_url_parts
    NFSStoreParts()
  else
    NFSStoreComplete()
  end

  nil
end

#NFSStoreCompleteObject


684
685
686
687
688
# File 'src/modules/SourceDialogs.rb', line 684

def NFSStoreComplete
  @_url = Convert.to_string(UI.QueryWidget(Id(:complete_url), :Value))

  nil
end

#NFSStorePartsObject


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
# File 'src/modules/SourceDialogs.rb', line 643

def NFSStoreParts
  parsed = {
    "scheme" => "nfs",
    "host"   => NormalizeHost(
      Convert.to_string(UI.QueryWidget(Id(:server), :Value))
    ),
    "path"   => Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
  }

  nfs4 = Convert.to_boolean(UI.QueryWidget(Id(:ch_nfs4), :Value))
  if nfs4
    # keep nfs4:// if it is used in the original URL
    if Builtins.tolower(Ops.get_string(URL.Parse(@_url), "scheme", "")) == "nfs4"
      Ops.set(parsed, "scheme", "nfs4")
    else
      Ops.set(parsed, "query", "type=nfs4")
    end
  end

  @_url = URL.Build(parsed)
  iso = Convert.to_boolean(UI.QueryWidget(Id(:ch_iso), :Value))

  # workaround: URL::Build does not accept numbers in scheme,
  # for nfs4 scheme it returns URL with no scheme (like "://foo/bar")
  @_url = Ops.add("nfs4", @_url) if !Builtins.regexpmatch(@_url, "^nfs")

  @_url = PostprocessISOURL(@_url) if iso

  if UI.QueryWidget(Id(:mount_options), :Value) != :default
    mount_opts = Convert.to_string(
      UI.QueryWidget(Id(:mount_options), :Value)
    )
    @_url = Ops.add(
      Ops.add(@_url, "?mountoptions="),
      URL.EscapeString(mount_opts, URL.transform_map_filename)
    )
  end

  nil
end

#NFSWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 748

def NFSWidget
  {
    "widget"        => :custom,
    "custom_widget" => VBox(
      RadioButtonGroup(
        Id(:edit_type),
        HBox(
          RadioButton(
            Id(:edit_url_parts),
            Opt(:notify),
            _("Edit Parts of the URL"),
            true
          ),
          HSpacing(2),
          RadioButton(
            Id(:edit_complete_url),
            Opt(:notify),
            _("Edit Complete URL")
          )
        )
      ),
      ReplacePoint(Id(:edit_content), Empty())
    ),
    "init"          => fun_ref(method(:NFSInit), "void (string)"),
    "store"         => fun_ref(method(:NFSStore), "void (string, map)"),
    "handle"        => fun_ref(method(:NFSHandle), "symbol (string, map)"),
    # help text
    "help"          => Ops.add(
      Ops.add(
        _(
          "<p><big><b>NFS Server</b></big><br>\n" \
            "Use <b>Server Name</b> and <b>Path to Directory or ISO Image</b>\n" \
            "to specify the NFS server host name and path on the server.</p>"
        ),
        @multi_cd_help
      ),
      _(
        "<p><big><b>Mount Options</b></big><br>\n" \
          "You can specify extra options used for mounting the NFS volume.\n" \
          "This is an expert option, keeping the default value is recommened. " \
          "See <b>man 5 nfs</b>\n" \
          "for details and the list of supported options."
      )
    )
  }
end

#NormalizeHost(host) ⇒ String

Remove leading and trailing (and inner) spaces from the host name


413
414
415
416
# File 'src/modules/SourceDialogs.rb', line 413

def NormalizeHost(host)
  host = Builtins.deletechars(host, " \t")
  host
end

#PathIsISO(url) ⇒ Boolean

check if given path points to ISO file


397
398
399
400
# File 'src/modules/SourceDialogs.rb', line 397

def PathIsISO(url)
  return false if Ops.less_than(Builtins.size(url), 4)
  Builtins.substring(url, Ops.subtract(Builtins.size(url), 4), 4) == ".iso"
end

#PlainURLInit(_key) ⇒ Object

Init function of a widget


537
538
539
540
541
542
# File 'src/modules/SourceDialogs.rb', line 537

def PlainURLInit(_key)
  UI.ChangeWidget(Id(:url), :Value, @_url)
  UI.SetFocus(:url)

  nil
end

#PlainURLStore(_key, _event) ⇒ Object

Store function of a widget


547
548
549
550
551
# File 'src/modules/SourceDialogs.rb', line 547

def PlainURLStore(_key, _event)
  @_url = Convert.to_string(UI.QueryWidget(Id(:url), :Value))

  nil
end

#PlainURLValidate(_key, _event) ⇒ Object


553
554
555
556
557
558
559
560
561
562
563
# File 'src/modules/SourceDialogs.rb', line 553

def PlainURLValidate(_key, _event)
  url = Convert.to_string(UI.QueryWidget(Id(:url), :Value))
  if url == ""
    UI.SetFocus(Id(:url))
    # popup message
    Popup.Message(_("URL cannot be empty."))
    return false
  end

  valid_scheme?(url)
end

#PlainURLWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 567

def PlainURLWidget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      # text entry
      InputField(Id(:url), Opt(:hstretch), _("&URL"))
    ),
    "init"              => fun_ref(method(:PlainURLInit), "void (string)"),
    "store"             => fun_ref(
      method(:PlainURLStore),
      "void (string, map)"
    ),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:PlainURLValidate),
      "boolean (string, map)"
    ),
    # help text
    "help"              => Ops.add(
      _(
        "<p><big><b>Repository URL</b></big><br>\n" \
          "Use <b>URL</b> to specify the URL of the repository.</p>"
      ),
      @multi_cd_help
    )
  }
end

#PopupButtonsObject

Return an HBox with ok and cancel buttons for use by other dialogs.


420
421
422
423
424
425
426
# File 'src/modules/SourceDialogs.rb', line 420

def PopupButtons
  HBox(
    PushButton(Id(:ok), Opt(:default), Label.OKButton),
    HSpacing(2),
    PushButton(Id(:cancel), Label.CancelButton)
  )
end

#PopupContents(proto, repository) ⇒ Yast::Term

Get contents of a popup for specified protocol


2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
# File 'src/modules/SourceDialogs.rb', line 2508

def PopupContents(proto, repository)
  VBox(
    HSpacing(50),
    # label
    Heading(Ops.get(@_caption, proto, "")),
    repository ? "repo_name" : "service_name",
    VSpacing(0.4),
    proto,
    VSpacing(0.4),
    PopupButtons()
  )
end

#PostprocessISOURL(url) ⇒ String

Postprocess URL of an ISO image


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
# File 'src/modules/SourceDialogs.rb', line 317

def PostprocessISOURL(url)
  log.info "Updating ISO URL: #{URL.HidePassword(url)}"

  uri = URI(url)
  query = uri.query || ""
  params = URI.decode_www_form(query).to_h
  path = uri.path || ""
  params["iso"] = File.basename(path)

  new_url = uri.dup
  new_url.path = File.dirname(path)
  new_url.query = nil
  # URL scheme in the "url" option must be set to "dir" (or empty)
  # for a local ISO image (see https://bugzilla.suse.com/show_bug.cgi?id=919138
  # and https://en.opensuse.org/openSUSE:Libzypp_URIs#ISO_Images )
  new_url.scheme = "dir" if uri.scheme.casecmp("iso").zero?
  # url can be already escaped, so unescape double escaping (bsc#954813)
  params["url"] = URI.unescape(new_url.to_s)

  processed = URI("")
  # libzypp do not use web encoding as in https://www.w3.org/TR/html5/forms.html#url-encoded-form-data
  # but percentage enconding only. For more details see (bsc#954813#c20)
  processed.query = URI.encode_www_form(params).gsub(/\+/, "%20")

  ret = "iso:///" + processed.to_s
  log.info "Updated URL: #{URL.HidePassword(ret)}"
  ret
end

#PreprocessISOURL(url) ⇒ String

Preprocess the ISO URL to be used in the dialogs


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
# File 'src/modules/SourceDialogs.rb', line 367

def PreprocessISOURL(url)
  log.info "Preprocessing ISO URL: #{URL.HidePassword(url)}"

  # empty iso is used when we adding new url
  return "" if url == "iso://"
  uri = URI(url)
  query = uri.query || ""

  # libzypp do not use web encoding as in https://www.w3.org/TR/html5/forms.html#url-encoded-form-data
  # but percentage enconding only. For more details see (bsc#954813#c20)
  params = URI.decode_www_form(query.gsub(/%20/, "+")).to_h

  param_url = params.delete("url") || ""
  processed = URI(URI.encode(param_url))
  processed.scheme = "iso" if processed.scheme.casecmp("dir").zero?
  # we need to construct path from more potential sources, as url can look like
  # `iso:/subdir?iso=test.iso&path=dir%3A%2Finstall` resulting in
  # path "/install/subdir/test.iso"
  processed.path = File.join(processed.path || "", uri.path, params.delete("iso") || "")
  processed.query = URI.encode_www_form(params) unless params.empty?

  ret = processed.to_s

  log.info "Updated URL: #{URL.HidePassword(ret)}"
  ret
end

#RefreshTypeWidgetsObject


2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
# File 'src/modules/SourceDialogs.rb', line 2389

def RefreshTypeWidgets
  return unless UI.WidgetExists(:add_addon)

  enabled = UI.QueryWidget(Id(:add_addon), :Value)

  WIDGET_LABELS.keys.each do |widget|
    UI.ChangeWidget(Id(widget), :Enabled, enabled) if UI.WidgetExists(widget)
  end
  UI.ChangeWidget(Id(:type), :Enabled, enabled) if UI.WidgetExists(:type)
end

#RepoNameInit(_key) ⇒ Object

Init function of a widget


451
452
453
454
455
# File 'src/modules/SourceDialogs.rb', line 451

def RepoNameInit(_key)
  UI.ChangeWidget(Id(:repo_name), :Value, @_repo_name)

  nil
end

#RepoNameStore(_key, _event) ⇒ Object

Store function of a widget


460
461
462
463
464
# File 'src/modules/SourceDialogs.rb', line 460

def RepoNameStore(_key, _event)
  @_repo_name = Convert.to_string(UI.QueryWidget(Id(:repo_name), :Value))

  nil
end

#RepoNameValidate(_key, _event) ⇒ Object


466
467
468
469
470
471
472
473
474
475
# File 'src/modules/SourceDialogs.rb', line 466

def RepoNameValidate(_key, _event)
  repo_name = Convert.to_string(UI.QueryWidget(Id(:repo_name), :Value))
  if repo_name == "" && @_repo_name != "" # do not fail on new repo creation
    UI.SetFocus(Id(:repo_name))
    # popup message
    Popup.Message(_("The name of the repository cannot be empty."))
    return false
  end
  true
end

#RepoNameWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 479

def RepoNameWidget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      # text entry
      InputField(Id(:repo_name), Opt(:hstretch), _("&Repository Name"))
    ),
    "init"              => fun_ref(method(:RepoNameInit), "void (string)"),
    "store"             => fun_ref(
      method(:RepoNameStore),
      "void (string, map)"
    ),
    "validate_type"     => :function,
    # TODO: FIXME: RepoName can be empty if the URL has been changed,
    # yast will use the product name or the URL in this case (the repository is recreated)
    "validate_function" => fun_ref(
      method(:RepoNameValidate),
      "boolean (string, map)"
    ),
    # help text
    "help"              => _(
      "<p><big><b>Repository Name</b></big><br>\nUse <b>Repository Name</b> " \
        "to specify the name of the repository. If it is empty, " \
        "YaST will use the product name (if available) or the URL as the name.</p>\n"
    )
  }
end

#scc_repos_widgetObject


2024
2025
2026
2027
2028
2029
# File 'src/modules/SourceDialogs.rb', line 2024

def scc_repos_widget
  display_scc = WFM.ClientExists("inst_scc") && !Stage.initial
  log.info "Displaying SCC option: #{display_scc}"

  display_scc ? Left(RadioButton(Id(:sccrepos), _(WIDGET_LABELS[:sccrepos]))) : Empty()
end

#SelectHandle(_key, event) ⇒ Symbol

Handles Ui events in New repository type selection dialog


2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
# File 'src/modules/SourceDialogs.rb', line 2241

def SelectHandle(_key, event)
  case event["ID"]
  when :back
    # reset the preselected URL when going back
    @_url = ""
    return nil
  when :add_addon
    RefreshTypeWidgets()
    return nil
  when :network
    Yast::WFM.CallFunction("inst_lan", [{ "skip_detection" => true }])
  end

  return nil if event["ID"] != :next && event["ID"] != :ok

  #  TODO: disable "download" option when CD or DVD source is selected

  selected = UI.QueryWidget(Id(:type), :CurrentButton)
  return :finish if SPECIAL_TYPES.include?(selected) && !global_disable

  nil
end

#SelectInit(_key) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 2344

def SelectInit(_key)
  current = nil

  if @_url == "ftp://"
    current = :ftp
  elsif @_url == "http://"
    current = :http
  elsif @_url == "https://"
    current = :https
  elsif @_url == "smb://"
    current = :samba
  elsif @_url == "nfs://"
    current = :nfs
  elsif @_url == "nfs4://"
    current = :nfs
  elsif @_url == "cd://"
    current = :cd
  elsif @_url == "dvd://"
    current = :dvd
  elsif @_url == "hd://"
    current = :hd
  elsif @_url == "usb://"
    current = :usb
  elsif @_url == "dir://" || @_url == "file://"
    current = :local_dir
  elsif @_url == "iso://"
    current = :local_iso
  elsif @_url == "slp://"
    current = :slp
  elsif @_url == "commrepos://"
    current = :comm_repos
  elsif @_url == "sccrepos://"
    current = :sccrepos
  else
    Builtins.y2warning("Unknown URL scheme '%1'", @_url)
    current = :specify_url
  end

  UI.ChangeWidget(Id(:type), :CurrentButton, current) if !current.nil?

  RefreshTypeWidgets()

  nil
end

#SelectRadioWidgetObject


2144
2145
2146
# File 'src/modules/SourceDialogs.rb', line 2144

def SelectRadioWidget
  SelectRadioWidgetOpt(false)
end

#SelectRadioWidgetDLObject


2148
2149
2150
# File 'src/modules/SourceDialogs.rb', line 2148

def SelectRadioWidgetDL
  SelectRadioWidgetOpt(true)
end

#SelectRadioWidgetOpt(download_widget) ⇒ Object

FIXME: two almost same definitions in the same function smell bad


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
# File 'src/modules/SourceDialogs.rb', line 2040

def SelectRadioWidgetOpt(download_widget)
  contents = HBox(
    HStretch(),
    VBox(
      VStretch(),
      addon_checkbox_term,
      RadioButtonGroup(
        Id(:type),
        VBox(
          HBox(
            addon_spacing_term,
            VBox(
              # radio button
              Left(RadioButton(Id(:slp), _(WIDGET_LABELS[:slp]))),
              # bnc #428370, No need to offer community repositories if not defined
              if CRURLDefined()
                # radio button
                Left(RadioButton(Id(:comm_repos), _(WIDGET_LABELS[:comm_repos])))
              else
                Empty()
              end,
              scc_repos_widget,
              VSpacing(0.4),
              Left(RadioButton(Id(:specify_url), _(WIDGET_LABELS[:specify_url]))),
              VSpacing(0.4),

              *[:ftp, :http, :https, :samba, :nfs, :cd, :dvd, :hd, :usb,
                :local_dir, :local_iso].map do |id|
                Left(RadioButton(Id(id), _(WIDGET_LABELS[id])))
              end,
              if download_widget
                VBox(
                  VSpacing(2),
                  Left(
                    CheckBox(
                      Id(:download_metadata),
                      _(WIDGET_LABELS[:download_metadata]),
                      
                    )
                  )
                )
              else
                Empty()
              end,
              VStretch()
            )
          )
        )
      )
    ),
    HStretch()
  )
  if !IsAnyNetworkAvailable()
    Builtins.y2milestone(
      "Network is not available, skipping all Network-related options..."
    )

    contents = HBox(
      HStretch(),
      VBox(
        VStretch(),
        addon_checkbox_term,
        RadioButtonGroup(
          Id(:type),
          VBox(
            HBox(
              addon_spacing_term,
              VBox(
                Left(RadioButton(Id(:specify_url),
                  _(WIDGET_LABELS[:specify_url]))),
                VSpacing(0.4),
                *[:cd, :dvd, :hd, :usb, :local_dir, :local_iso].map do |id|
                  Left(RadioButton(Id(id), _(WIDGET_LABELS[id])))
                end,
                if download_widget
                  VBox(
                    VSpacing(2),
                    Left(
                      CheckBox(
                        Id(:download_metadata),
                        _(WIDGET_LABELS[:download_metadata]),
                        
                      )
                    )
                  )
                else
                  Empty()
                end,
                VStretch()
              )
            )
          )
        )
      ),
      HStretch()
    )
  else
    Builtins.y2milestone(
      "Network is available, allowing Network-related options..."
    )
  end
  deep_copy(contents)
end

#SelectStore(_key, _event) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 2271

def SelectStore(_key, _event)
  @_url = ""
  @_plaindir = false
  @_repo_name = ""
  @addon_enabled = !global_disable

  return nil if global_disable

  selected = Convert.to_symbol(UI.QueryWidget(Id(:type), :CurrentButton))

  if Builtins.contains(
    [
      :ftp,
      :http,
      :https,
      :samba,
      :nfs,
      :cd,
      :dvd,
      :usb,
      :hd,
      :local_dir,
      :specify_url,
      :slp,
      :local_iso,
      :sccrepos,
      :comm_repos
    ],
    selected
  )
    if selected == :ftp
      @_url = "ftp://"
    elsif selected == :http
      @_url = "http://"
    elsif selected == :https
      @_url = "https://"
    elsif selected == :samba
      @_url = "smb://"
    elsif selected == :nfs
      @_url = "nfs://"
    # this case is specific, as it return complete path and not just
    # prefix as others
    elsif selected == :cd || selected == :dvd
      # use three slashes as third slash means path
      @_url = selected == :cd ? "cd:///" : "dvd:///"
      if @cd_device_name != ""
        @_url = Ops.add(
          Ops.add(@_url, "?devices="),
          URLRecode.EscapeQuery(@cd_device_name)
        )
      end
    elsif selected == :hd
      @_url = "hd://"
    elsif selected == :usb
      @_url = "usb://"
    elsif selected == :local_dir
      @_url = "dir://"
    elsif selected == :local_iso
      @_url = "iso://"
    elsif selected == :slp
      @_url = "slp://"
    elsif selected == :comm_repos
      @_url = "commrepos://"
    elsif selected == :sccrepos
      @_url = "sccrepos://"
    end
  else
    Builtins.y2error("Unexpected repo type %1", selected)
  end

  nil
end

#SelectStoreDl(key, event) ⇒ Object


2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
# File 'src/modules/SourceDialogs.rb', line 2432

def SelectStoreDl(key, event)
  event = deep_copy(event)
  SelectStore(key, event)

   = Convert.to_boolean(
    UI.QueryWidget(Id(:download_metadata), :Value)
  )

  nil
end

#SelectValidate(_key, _event) ⇒ Object


2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
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
# File 'src/modules/SourceDialogs.rb', line 2195

def SelectValidate(_key, _event)
  # skip validation if disabled by the global checkbox
  return true if global_disable

  selected = Convert.to_symbol(UI.QueryWidget(Id(:type), :CurrentButton))
  if selected.nil?
    # error popup
    Popup.Message(_("Select the media type"))
    return false
  end
  if selected == :cd || selected == :dvd
    Pkg.SourceReleaseAll
    msg = if selected == :cd
      _("Insert the add-on product CD")
    else
      _("Insert the add-on product DVD")
    end

    # reset the device name
    @cd_device_name = ""

    # ask for a medium
    ui_result = SourceManager.AskForCD(msg)
    return false if !Ops.get_boolean(ui_result, "continue", false)

    cd_device = Ops.get_string(ui_result, "device", "")
    if !cd_device.nil? && cd_device != ""
      Builtins.y2milestone("Selected CD/DVD device: %1", cd_device)
      @cd_device_name = cd_device
    end
  elsif selected == :usb
    usb_disks = DetectUSBDisk()

    if Builtins.size(usb_disks).zero?
      Report.Error(_("No USB disk was detected."))
      return false
    end
  end
  true
end

#SelectWidgetObject


2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
# File 'src/modules/SourceDialogs.rb', line 2400

def SelectWidget
  {
    "widget"            => :func,
    "widget_func"       => fun_ref(method(:SelectRadioWidget), "term ()"),
    "init"              => fun_ref(method(:SelectInit), "void (string)"),
    "help"              => SelectWidgetHelp(),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:SelectValidate),
      "boolean (string, map)"
    ),
    "store"             => fun_ref(
      method(:SelectStore),
      "void (string, map)"
    ),
    "handle"            => fun_ref(
      method(:SelectHandle),
      "symbol (string, map)"
    )
  }
end

#SelectWidgetDLObject


2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
# File 'src/modules/SourceDialogs.rb', line 2453

def SelectWidgetDL
  {
    "widget"            => :func,
    "widget_func"       => fun_ref(method(:SelectRadioWidgetDL), "term ()"),
    "init"              => fun_ref(method(:SelectInit), "void (string)"),
    "help"              => Ops.add(SelectWidgetHelp(), SelectWidgetHelpDl()),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:SelectValidate),
      "boolean (string, map)"
    ),
    "store"             => fun_ref(
      method(:SelectStoreDl),
      "void (string, map)"
    ),
    "handle"            => fun_ref(
      method(:SelectHandle),
      "symbol (string, map)"
    )
  }
end

#SelectWidgetHelpObject


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
# File 'src/modules/SourceDialogs.rb', line 2152

def SelectWidgetHelp
  # help text
  help_text = _(
    "<p><big><b>Media Type</b></big><br>\n" \
      "The software repository can be located on CD, on a network server,\n" \
      "or on the hard disk.</p>"
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "To add  <b>CD</b> or <b>DVD</b>,\n" \
        "have the product CD set or the DVD available.</p>"
    )
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "The product CDs can be copied to the hard disk.\n" \
        "Enter the path to the first CD, for example, /data1/<b>CD1</b>.\n" \
        "Only the base path is required if all CDs are copied\n" \
        "into the same directory.</p>\n"
    )
  )

  # help, continued
  help_text = Ops.add(
    help_text,
    _(
      "<p>\n" \
        "Network installation requires a working network connection.\n" \
        "Specify the directory in which the packages from\n" \
        "the first CD are located, such as /data1/CD1.</p>\n"
    )
  )
  help_text
end

#SelectWidgetHelpDlObject


2443
2444
2445
2446
2447
2448
2449
2450
2451
# File 'src/modules/SourceDialogs.rb', line 2443

def SelectWidgetHelpDl
  _(
    "<p><b>Download Files</b><br>\n" \
      "Each repository has description files which describe the content of the\n" \
      "repository. Check <b>Download repository description files</b> to download the\n" \
      "files when closing this YaST module. If the option is unchecked, YaST will\n" \
      "automatically download the files when it needs them later. </p>\n"
  )
end

#ServerHandle(key, event) ⇒ Object

Handle function of a widget


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
# File 'src/modules/SourceDialogs.rb', line 1559

def ServerHandle(key, event)
  event = deep_copy(event)
  Builtins.y2milestone("ServerHandle: %1, %2", key, event)

  current_type = Convert.to_symbol(UI.QueryWidget(Id(:edit_type), :Value))
  Builtins.y2debug("Current edit type: %1", current_type)

  id = Ops.get(event, "ID")
  if Ops.is_symbol?(id) &&
      Builtins.contains(
        [:http, :https, :ftp, :samba, :rb_type],
        Convert.to_symbol(id)
      ) &&
      current_type == :edit_url_parts
    type = Convert.to_symbol(UI.QueryWidget(Id(:rb_type), :CurrentButton))
    server = if UI.WidgetExists(Id(:server))
      Convert.to_string(UI.QueryWidget(Id(:server), :Value))
    else
      ""
    end
    dir = if UI.WidgetExists(Id(:dir))
      Convert.to_string(UI.QueryWidget(Id(:dir), :Value))
    else
      ""
    end
    anonymous = if UI.WidgetExists(Id(:anonymous))
      Convert.to_boolean(UI.QueryWidget(Id(:anonymous), :Value))
    else
      false
    end
    username = if UI.WidgetExists(Id(:username))
      Convert.to_string(UI.QueryWidget(Id(:username), :Value))
    else
      ""
    end
    password = if UI.WidgetExists(Id(:password))
      Convert.to_string(UI.QueryWidget(Id(:password), :Value))
    else
      ""
    end
    port = if UI.WidgetExists(Id(:port))
      Convert.to_string(UI.QueryWidget(Id(:port), :Value))
    else
      ""
    end

    widget = VBox(
      HBox(
        # text entry
        InputField(Id(:server), Opt(:hstretch), _("Server &Name"), server),
        if type == :http || type == :https
          HBox(
            HSpacing(1),
            HSquash(InputField(Id(:port), _("&Port"), port))
          )
        else
          Empty()
        end,
        if type == :samba
          # text entry
          InputField(Id(:share), Opt(:hstretch), _("&Share"))
        else
          Empty()
        end
      ),
      if type == :samba
        VBox(
          InputField(
            Id(:dir),
            Opt(:hstretch),
            # text entry
            _("&Path to Directory or ISO Image"),
            dir
          ),
          # checkbox label
          Left(CheckBox(Id(:ch_iso), _("ISO &Image")))
        )
      else
        # text entry
        InputField(Id(:dir), Opt(:hstretch), _("&Directory on Server"), dir)
      end,
      HBox(
        HSpacing(0.5),
        # frame
        Frame(
          _("Au&thentication"),
          VBox(
            Left(
              CheckBox(
                Id(:anonymous),
                Opt(:notify),
                # check box
                _("&Anonymous"),
                anonymous
              )
            ),
            if type == :samba
              # text entry
              InputField(
                Id(:workgroup),
                Opt(:hstretch),
                _("&Workgroup or Domain")
              )
            else
              Empty()
            end,
            # text entry
            VSpacing(0.4),
            HBox(
              InputField(
                Id(:username),
                Opt(:hstretch),
                _("&User Name"),
                username
              ),
              # password entry
              Password(
                Id(:password),
                Opt(:hstretch),
                _("&Password"),
                password
              )
            )
          )
        ),
        HSpacing(0.5)
      )
    )
    UI.ReplaceWidget(Id(:server_rp), widget)

    if UI.WidgetExists(Id(:port))
      # maximum port number is 65535
      UI.ChangeWidget(Id(:port), :InputMaxLength, 5)
      # allow only numbers in the port spec
      UI.ChangeWidget(Id(:port), :ValidChars, String.CDigit)
    end

    # update widget status
    UI.ChangeWidget(Id(:username), :Enabled, !anonymous)
    UI.ChangeWidget(Id(:password), :Enabled, !anonymous)
    if UI.WidgetExists(Id(:workgroup))
      UI.ChangeWidget(Id(:workgroup), :Enabled, !anonymous)
    end

    InitFocusServerInit(Convert.to_symbol(id))

    return nil
  end

  if Ops.get(event, "ID") == :anonymous && current_type == :edit_url_parts
    anonymous = Convert.to_boolean(UI.QueryWidget(Id(:anonymous), :Value))
    UI.ChangeWidget(Id(:username), :Enabled, !anonymous)
    UI.ChangeWidget(Id(:password), :Enabled, !anonymous)
    if UI.WidgetExists(Id(:workgroup))
      UI.ChangeWidget(Id(:workgroup), :Enabled, !anonymous)
    end
    return nil
  elsif (id == :edit_url_parts || id == :edit_complete_url) &&
      Ops.get_string(event, "EventReason", "") == "ValueChanged"
    Builtins.y2milestone("Changing dialog type")

    # store the current values (note: the radio button just has been switched,
    # compare to the opposite value!)
    if id == :edit_url_parts
      ServerStoreComplete()
    else
      ServerStoreParts()
    end

    @editing_parts = id == :edit_url_parts

    # reinitialize the dialog (set the current values)
    ServerInit(nil)
  end

  nil
end

#ServerInit(key) ⇒ Object


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
# File 'src/modules/SourceDialogs.rb', line 1737

def ServerInit(key)
  # check the current edit type
  current_type = @editing_parts ? :edit_url_parts : :edit_complete_url

  # set the stored value
  UI.ChangeWidget(Id(:edit_type), :Value, current_type)

  Builtins.y2debug("Current edit type: %1", current_type)

  UI.ReplaceWidget(
    Id(:edit_content),
    current_type == :edit_url_parts ? @details_content : @complete_content
  )

  if current_type == :edit_url_parts
    protocol_box = HBox(
      HStretch(),
      # radio button
      RadioButton(Id(:ftp), Opt(:notify), _("&FTP")),
      HStretch(),
      # radio button
      RadioButton(Id(:http), Opt(:notify), _("H&TTP")),
      HStretch()
    )
    if @_allow_https
      protocol_box = Builtins.add(
        protocol_box,
        # radio button
        RadioButton(Id(:https), Opt(:notify), _("HTT&PS"))
      )
      protocol_box = Builtins.add(protocol_box, HStretch())
    end
    protocol_box = Builtins.add(
      protocol_box,
      # radio button
      RadioButton(Id(:samba), Opt(:notify), _("S&MB/CIFS"))
    )
    protocol_box = Builtins.add(protocol_box, HStretch())
    protocol_box = RadioButtonGroup(
      Id(:rb_type),
      Opt(:notify),
      protocol_box
    )
    UI.ReplaceWidget(Id(:rb_type_rp), protocol_box)

    iso = IsISOURL(@_url)
    @_url = PreprocessISOURL(@_url) if iso
    parsed = URL.Parse(@_url)
    type = :ftp
    if Ops.get_string(parsed, "scheme", "") == "http"
      type = :http
    elsif Ops.get_string(parsed, "scheme", "") == "https"
      type = :https
    elsif Ops.get_string(parsed, "scheme", "") == "smb"
      type = :samba
    end
    UI.ChangeWidget(Id(:rb_type), :CurrentButton, type)

    ServerHandle(key, "ID" => :rb_type)

    UI.ChangeWidget(Id(:server), :Value, Ops.get_string(parsed, "host", ""))
    dir = Ops.get_string(parsed, "path", "")
    if type == :samba
      UI.ChangeWidget(Id(:ch_iso), :Value, iso)
      sharepath = Builtins.regexptokenize(dir, "^/*([^/]+)(/.*)?$")
      share = Ops.get_string(sharepath, 0, "")
      dir = Ops.get_string(sharepath, 1, "")
      dir = "/" if dir.nil?

      query = URI.decode_www_form(parsed["query"] || "").to_h
      # libzypp uses "workgroup" or "domain" parameter, see "man zypper"
      workgroup = query["workgroup"] || query["domain"] || ""

      UI.ChangeWidget(Id(:workgroup), :Value, workgroup)
      UI.ChangeWidget(Id(:share), :Value, share)
    end
    UI.ChangeWidget(Id(:dir), :Value, dir)
    UI.ChangeWidget(
      Id(:username),
      :Value,
      Ops.get_string(parsed, "user", "")
    )
    UI.ChangeWidget(
      Id(:password),
      :Value,
      Ops.get_string(parsed, "pass", "")
    )
    anonymous = !(Ops.get_string(parsed, "user", "") != "" ||
      Ops.get_string(parsed, "pass", "") != "")
    Builtins.y2milestone("Anonymous: %1", anonymous)
    UI.ChangeWidget(Id(:anonymous), :Value, anonymous)
    if anonymous
      UI.ChangeWidget(Id(:username), :Enabled, false)
      UI.ChangeWidget(Id(:password), :Enabled, false)
      if UI.WidgetExists(Id(:workgroup))
        UI.ChangeWidget(Id(:workgroup), :Enabled, !anonymous)
      end
    end

    # set HTTP/HTTPS port if it's specified
    if type == :http || type == :https
      port_num = Ops.get_string(parsed, "port", "")

      if !port_num.nil? && port_num != ""
        UI.ChangeWidget(Id(:port), :Value, port_num)
      end
    end

    InitFocusServerInit(type)
  else
    UI.ChangeWidget(Id(:complete_url), :Value, @_url)
  end

  nil
end

#ServerStore(key, event) ⇒ Object


1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
# File 'src/modules/SourceDialogs.rb', line 1878

def ServerStore(key, event)
  Builtins.y2debug("Server store: %1, %2", key, event)

  current_type = Convert.to_symbol(UI.QueryWidget(Id(:edit_type), :Value))
  Builtins.y2debug("Current edit type: %1", current_type)

  @editing_parts = current_type == :edit_url_parts

  if @editing_parts
    ServerStoreParts()
  else
    ServerStoreComplete()
  end

  nil
end

#ServerStoreCompleteObject


1549
1550
1551
1552
1553
# File 'src/modules/SourceDialogs.rb', line 1549

def ServerStoreComplete
  @_url = Convert.to_string(UI.QueryWidget(Id(:complete_url), :Value))

  nil
end

#ServerStorePartsObject


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
# File 'src/modules/SourceDialogs.rb', line 1438

def ServerStoreParts
  type = Convert.to_symbol(UI.QueryWidget(Id(:rb_type), :CurrentButton))

  # initialize keys to empty values so the new and old values can be simply compared
  parsed = {
    "fragment" => "",
    "host"     => "",
    "pass"     => "",
    "path"     => "",
    "port"     => "",
    "query"    => "",
    "scheme"   => "",
    "user"     => ""
  }
  if type == :ftp
    Ops.set(parsed, "scheme", "ftp")
  elsif type == :http
    Ops.set(parsed, "scheme", "http")
  elsif type == :https
    Ops.set(parsed, "scheme", "https")
  elsif type == :samba
    Ops.set(parsed, "scheme", "smb")
  end

  anonymous = Convert.to_boolean(UI.QueryWidget(Id(:anonymous), :Value))
  if !anonymous
    user = Convert.to_string(UI.QueryWidget(Id(:username), :Value))
    pass = Convert.to_string(UI.QueryWidget(Id(:password), :Value))
    Ops.set(parsed, "user", user) if Builtins.size(user).nonzero?
    Ops.set(parsed, "pass", pass) if Builtins.size(pass).nonzero?
  end

  host = NormalizeHost(
    Convert.to_string(UI.QueryWidget(Id(:server), :Value))
  )
  directory = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))

  # is / in the host name?
  pos = Builtins.findfirstof(host, "/")
  if !pos.nil?
    # update the hostname and the directory,
    # URL::Build return empty URL when the hostname is not valid
    Builtins.y2milestone("The hostname contains a path: %1", host)
    dir = Builtins.substring(host, pos)

    if Builtins.substring(dir, Ops.subtract(Builtins.size(dir), 1), 1) != "/" &&
        Builtins.substring(directory, 0, 1) != "/"
      dir = Ops.add(dir, "/")
    end

    directory = Ops.add(dir, directory)
    host = Builtins.substring(host, 0, pos)

    Builtins.y2milestone(
      "Updated hostname: %1, directory: %2",
      host,
      directory
    )
  end

  Ops.set(parsed, "host", host)

  if type == :samba
    share = Convert.to_string(UI.QueryWidget(Id(:share), :Value))
    directory = Ops.add(Slashed(share), Slashed(directory))
  elsif type != :ftp
    # FTP needs to distinguish absolute and relative path
    # do not add the slash if host and directory is empty
    # (avoid e.g. http:// -> http:/// when switching from the parts to the complete view)
    directory = Slashed(directory) if host != "" || directory != ""
  end
  if UI.WidgetExists(Id(:workgroup))
    workgroup = Convert.to_string(UI.QueryWidget(Id(:workgroup), :Value))
    if type == :samba && Ops.greater_than(Builtins.size(workgroup), 0)
      Ops.set(parsed, "domain", workgroup)
    end
  end
  Ops.set(parsed, "path", directory)

  # set HTTP/HTTPS port
  if type == :http || type == :https
    Ops.set(
      parsed,
      "port",
      Convert.to_string(UI.QueryWidget(Id(:port), :Value))
    )
  end

  # keep the URL if user haven't changed anything (don't change escaped chars bnc#529944)
  parsed_old = URL.Parse(@_url)
  if parsed == parsed_old
    Builtins.y2milestone("No change, NOT updating the complete URL")
    Builtins.y2debug("Unchanged URL: %1", parsed)
  else
    Builtins.y2milestone("A change detected, updating complete URL")
    Builtins.y2debug("Updating the URL: %1 -> %2", parsed_old, parsed)

    # do not log the entered password
    Builtins.y2milestone("Entered URL: %1", URL.HidePasswordToken(parsed))
    @_url = URL.Build(parsed)
    Builtins.y2milestone("URL::Build: %1", URL.HidePassword(@_url))

    if UI.WidgetExists(Id(:ch_iso))
      iso = Convert.to_boolean(UI.QueryWidget(Id(:ch_iso), :Value))
      @_url = PostprocessISOURL(@_url) if iso
    end
  end

  nil
end

#ServerValidate(_key, _event) ⇒ Object


1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
# File 'src/modules/SourceDialogs.rb', line 1853

def ServerValidate(_key, _event)
  current_type = Convert.to_symbol(UI.QueryWidget(Id(:edit_type), :Value))
  Builtins.y2debug("Current edit type: %1", current_type)

  if current_type == :edit_url_parts
    host = NormalizeHost(
      Convert.to_string(UI.QueryWidget(Id(:server), :Value))
    )
    if !Hostname.CheckFQ(host)
      if !IP.Check(host)
        UI.SetFocus(:server)
        Popup.Error(
          Builtins.sformat("%1\n\n%2", Hostname.ValidFQ, IP.Valid4)
        )
        return false
      end
    end
  else
    url = UI.QueryWidget(Id(:complete_url), :Value)
    return valid_scheme?(url)
  end

  true
end

#ServerWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 1897

def ServerWidget
  {
    "widget"            => :custom,
    "custom_widget"     => VBox(
      RadioButtonGroup(
        Id(:edit_type),
        HBox(
          RadioButton(
            Id(:edit_url_parts),
            Opt(:notify),
            _("Edit Parts of the URL"),
            @editing_parts
          ),
          HSpacing(2),
          RadioButton(
            Id(:edit_complete_url),
            Opt(:notify),
            _("Edit Complete URL"),
            !@editing_parts
          )
        )
      ),
      VSpacing(0.3),
      ReplacePoint(Id(:edit_content), Empty())
    ),
    "init"              => fun_ref(method(:ServerInit), "void (string)"),
    "validate_type"     => :function,
    "validate_function" => fun_ref(
      method(:ServerValidate),
      "boolean (string, map)"
    ),
    "store"             => fun_ref(
      method(:ServerStore),
      "void (string, map)"
    ),
    "handle"            => fun_ref(
      method(:ServerHandle),
      "symbol (string, map)"
    ),
    # help text - server dialog
    "help"              => Ops.add(
      _(
        "<p><big><b>Server and Directory</b></big><br>\n" \
          "Use <b>Server Name</b> and <b>Path to Directory or ISO Image</b>\n" \
          "to specify the NFS server host name and path on the server.\n" \
          "To enable authentication, uncheck <b>Anonymous</b> and specify the\n" \
          "<b>User Name</b> and the <b>Password</b>.</p>\n" \
          "<p>\n" \
          "For the SMB/CIFS repository, specify <b>Share</b> name and <b>Path to Directory\n" \
          "or ISO Image</b>. \n" \
          "If the location is a file holding an ISO image\n" \
          "of the media, set <b>ISO Image</b>.</p>\n"
      ) +
        # help text - server dialog, there is a "Port" widget
        _(
          "<p>It is possible to set the <b>Port</b> number for a HTTP/HTTPS repository.\n" \
            "Leave it empty to use the default port.</p>\n"
        ),
      @multi_cd_help
    )
  }
end

#ServiceNameWidgetObject


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
# File 'src/modules/SourceDialogs.rb', line 507

def ServiceNameWidget
  ret = RepoNameWidget()

  Ops.set(
    ret,
    "custom_widget",
    VBox(
      # text entry
      InputField(Id(:repo_name), Opt(:hstretch), _("&Service Name"))
    )
  )

  # help text
  Ops.set(
    ret,
    "help",
    _(
      "<p><big><b>Service Name</b></big><br>\n" \
        "Use <b>Service Name</b> to specify the name of the service. " \
        "If it is empty, YaST will use part of the service URL as the name.</p>\n"
    )
  )

  deep_copy(ret)
end

#SetDownloadOption(download) ⇒ Object


2426
2427
2428
2429
2430
# File 'src/modules/SourceDialogs.rb', line 2426

def SetDownloadOption(download)
   = download

  nil
end

#SetFileSystems(selected_fs) ⇒ Object


1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
# File 'src/modules/SourceDialogs.rb', line 1199

def SetFileSystems(selected_fs)
  fs_list = [
    "auto",
    "vfat",
    "ntfs",
    "ntfs-3g",
    "ext2",
    "ext3",
    "ext4",
    "reiserfs",
    "xfs",
    "jfs",
    "iso9660"
  ]

  items = Builtins.maplist(fs_list) do |fs|
    Item(Id(fs), fs, fs == selected_fs)
  end

  UI.ChangeWidget(Id(:fs), :Items, items)

  nil
end

#SetRepoName(repo_name) ⇒ Object

Set the RepoName to work with


302
303
304
305
306
# File 'src/modules/SourceDialogs.rb', line 302

def SetRepoName(repo_name)
  @_repo_name = repo_name

  nil
end

#SetURL(url) ⇒ Object

Set the URL to work with


232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'src/modules/SourceDialogs.rb', line 232

def SetURL(url)
  @_url = url

  parsed = URL.Parse(@_url)

  # check if it's HDD or USB
  # convert it to the internal representation
  if Ops.get_string(parsed, "scheme", "") == "hd"
    query = Ops.get_string(parsed, "query", "")

    if Builtins.regexpmatch(query, "device=/dev/disk/by-id/usb-")
      Ops.set(parsed, "scheme", "usb")

      @_url = URL.Build(parsed)
      Builtins.y2milestone(
        "URL %1 is an USB device, changing the scheme to %2",
        URL.HidePassword(url),
        @_url
      )
    end
  end

  # reset the plaindir flag
  @_plaindir = false

  nil
end

#SetURLType(url, plaindir_type) ⇒ Object

Set the URL to work with, set the plaindir flag (type of the repository)


263
264
265
266
267
268
269
270
# File 'src/modules/SourceDialogs.rb', line 263

def SetURLType(url, plaindir_type)
  SetURL(url)
  # set the flag AFTER setting the URL!
  # SetURL() resets the _plaindir flag
  @_plaindir = plaindir_type

  nil
end

#Slashed(urlpart) ⇒ String

Add a slash to the part of url, if it is not already present


405
406
407
408
# File 'src/modules/SourceDialogs.rb', line 405

def Slashed(urlpart)
  return urlpart if Builtins.substring(urlpart, 0, 1) == "/"
  Ops.add("/", urlpart)
end

#TypeDialogSymbol

Sample implementation of URL type selection dialog


2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
# File 'src/modules/SourceDialogs.rb', line 2656

def TypeDialog
  Builtins.y2milestone("Running repository type dialog")
  # dialog caption
  caption = _("Media Type")
  ret = CWM.ShowAndRun(
    "widget_names"       => ["select"],
    "widget_descr"       => Widgets(),
    "contents"           => VBox(network_button, "select"),
    "caption"            => caption,
    "back_button"        => Label.BackButton,
    "next_button"        => Label.NextButton,
    "fallback_functions" => @default_cwm_fallback_functions
  )
  Builtins.y2milestone("Type dialog returned %1", ret)
  ret
end

#TypeDialogDownloadOptSymbol

Sample implementation of URL type selection dialog


2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
# File 'src/modules/SourceDialogs.rb', line 2675

def TypeDialogDownloadOpt
  Builtins.y2milestone(
    "Running repository type dialog with download option"
  )

  # dialog caption
  caption = _("Add On Product")
  ui = CWM.ShowAndRun(
    "widget_names"       => ["select_dl"],
    "widget_descr"       => Widgets(),
    "contents"           => VBox(network_button, "select_dl"),
    "caption"            => caption,
    "back_button"        => Label.BackButton,
    "next_button"        => Label.NextButton,
    "fallback_functions" => @default_cwm_fallback_functions
  )

  ret = { "ui" => ui, "download" =>  }

  Builtins.y2milestone("Type dialog returned %1", ret)
  deep_copy(ret)
end

#TypePopupString

URL editation popup with the HTTPS option


2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
# File 'src/modules/SourceDialogs.rb', line 2639

def TypePopup
  w = CWM.CreateWidgets(["select"], Widgets())
  contents = PopupContents("select", true)
  contents = CWM.PrepareDialog(contents, w)
  UI.OpenDialog(contents)
  ret = CWM.Run(w, {})
  Builtins.y2milestone("Ret: %1", ret)
  UI.CloseDialog
  ""
  #    if (ret == `ok)
  #   return GetURL ();
  #    else
  #   return "";
end

#URLScheme(url) ⇒ String

Get scheme of a URL, also for ISO URL get scheme of the access protocol


431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'src/modules/SourceDialogs.rb', line 431

def URLScheme(url)
  if IsISOURL(url)
    tmp_url = PreprocessISOURL(url)
    parsed = URL.Parse(tmp_url)
  else
    parsed = URL.Parse(url)
  end
  scheme = Ops.get_string(parsed, "scheme", "")

  scheme = "url" if scheme == "" || scheme.nil?
  Builtins.y2milestone(
    "URL scheme for URL %1: %2",
    URL.HidePassword(url),
    scheme
  )
  scheme
end

#USBInit(_key) ⇒ Object

Init function of a widget


1249
1250
1251
1252
1253
1254
1255
# File 'src/modules/SourceDialogs.rb', line 1249

def USBInit(_key)
  # detect disks
  usb_disks = DetectUSBDisk()
  InitDiskWidget(usb_disks)

  nil
end

#USBStore(_key, _event) ⇒ Object

Store function of a widget


1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
# File 'src/modules/SourceDialogs.rb', line 1260

def USBStore(_key, _event)
  # build URL like this: usb:///openSUSE?device=/dev/sdb8&filesystem=auto
  query = Builtins.sformat(
    "device=%1&filesystem=%2",
    Convert.to_string(UI.QueryWidget(Id(:disk), :Value)),
    Convert.to_string(UI.QueryWidget(Id(:fs), :Value))
  )

  dir = Convert.to_string(UI.QueryWidget(Id(:dir), :Value))

  @_plaindir = Convert.to_boolean(UI.QueryWidget(Id(:ch_plain), :Value))

  parsed = { "scheme" => "usb", "path" => dir, "query" => query }

  @_url = URL.Build(parsed)

  Builtins.y2milestone("New USB url: %1", URL.HidePassword(@_url))

  nil
end

#USBWidgetObject

Get widget description map


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
# File 'src/modules/SourceDialogs.rb', line 1283

def USBWidget
  {
    "widget"        => :custom,
    "custom_widget" => VBox(
      # combobox title
      Left(
        ComboBox(
          Id(:disk),
          # `opt(`hstretch),
          _("&USB Mass Storage Device") +
            # the spacing is added to make the widget wider
            "                                                   "
        )
      ),
      Left(ComboBox(Id(:fs), Opt(:editable), _("&File System"))),
      Left(InputField(Id(:dir), _("Dire&ctory"))),
      Left(CheckBox(Id(:ch_plain), _("&Plain RPM Directory")))
    ),
    "init"          => fun_ref(method(:USBInit), "void (string)"),
    "store"         => fun_ref(method(:USBStore), "void (string, map)"),
    "help"          => _(
      "<p><big><b>USB Stick or Disk</b></big><br>\n" \
        "Select the USB device on which the repository is located.\n" \
        "Use <b>Path to Directory</b> to specify the directory of the repository.\n" \
        "If the path is omitted, the system will use the root directory of the disk.\n" \
        "If the directory contains only RPM packages without\n" \
        "any metadata (i.e. there is no product information), then check option\n" \
        "<b>Plain RPM Directory</b>.</p>\n"
    ) +
      # 'auto' is a value in the combo box widget, do not translate it!
      _(
        "<p>The file system used on the device will be detected automatically\n" \
          "if you select file system 'auto'. If the detection fails or you\n" \
          "want to use a certain file system, select it from the list.</p>\n"
      )
  }
end

#valid_scheme?(url) ⇒ Boolean


2705
2706
2707
2708
2709
2710
2711
2712
2713
# File 'src/modules/SourceDialogs.rb', line 2705

def valid_scheme?(url)
  scheme = URL.Parse(url)["scheme"] || ""
  scheme.downcase!
  ret = VALID_URL_SCHEMES.include?(scheme)

  Report.Error(_("URL scheme '%s' is not valid.") % scheme) unless ret

  ret
end

#WidgetsObject

Get individual widgets


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
# File 'src/modules/SourceDialogs.rb', line 2477

def Widgets
  if Builtins.size(@_widgets).zero?
    @_widgets = {
      "repo_name"    => RepoNameWidget(),
      "service_name" => ServiceNameWidget(),
      "url"          => PlainURLWidget(),
      "nfs"          => NFSWidget(),
      "cd"           => CDWidget(),
      "dvd"          => CDWidget(),
      "hd"           => DiskWidget(),
      "usb"          => USBWidget(),
      "dir"          => DirWidget(),
      "file"         => DirWidget(),
      "iso"          => IsoWidget(),
      "http"         => ServerWidget(),
      "https"        => ServerWidget(),
      "ftp"          => ServerWidget(),
      "smb"          => ServerWidget(),
      "cifs"         => ServerWidget(),
      "select"       => SelectWidget(),
      "select_dl"    => SelectWidgetDL()
    }
  end
  deep_copy(@_widgets)
end