Class: Yast::NetworkPopupClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/NetworkPopup.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ChooseItem(title, items, selected)

Let the user choose one of a list of items

Parameters:

  • title (String)

    selectionbox title

  • items (Array<String>)

    a list of items

  • selected (String)

    preselected a value in the list

Returns:

  • one item or nil



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

def ChooseItem(title, items, selected)
  items = deep_copy(items)
  item = nil

  _Items = Builtins.maplist(items) do |i|
    device_name = NetworkInterfaces.GetValue(i, "NAME")
    if device_name == nil || device_name == ""
      #TRANSLATORS: Informs that device name is not known
      device_name = _("Unknown device")
    end
    if Ops.greater_than(Builtins.size(device_name), 30)
      device_name = Ops.add(Builtins.substring(device_name, 0, 27), "...")
    end
    ip_addr = NetworkInterfaces.GetValue(i, "BOOTPROTO") == "dhcp" ?
      # TRANSLATORS: Informs that the IP address is assigned via DHCP
      _("DHCP address") :
      NetworkInterfaces.GetValue(i, "IPADDR")
    if ip_addr == nil || ip_addr == ""
      # TRANSLATORS: table item, informing that device has no IP address
      ip_addr = _("No IP address assigned")
    end
    conn = _("No")
    conn = _("Yes") if NetworkInterfaces.IsConnected(i)
    Item(
      Id(i),
      NetworkInterfaces.GetDeviceTypeName(i),
      device_name,
      ip_addr,
      i,
      conn
    )
  end

  UI.OpenDialog(
    VBox(
      HSpacing(60),
      HBox(
        # translators: table header - details about the network device
        Table(
          Id(:items),
          Header(
            _("Device Type"),
            _("Device Name"),
            _("IP Address"),
            _("Device ID"),
            _("Connected")
          ),
          _Items
        ),
        VSpacing(10)
      ),
      ButtonBox(
        PushButton(
          Id(:ok),
          Opt(:default, :key_F10, :okButton),
          Label.OKButton
        ),
        PushButton(
          Id(:cancel),
          Opt(:key_F9, :cancelButton),
          Label.CancelButton
        )
      )
    )
  )
  UI.ChangeWidget(Id(:items), :CurrentItem, selected)
  UI.SetFocus(Id(:items))
  ret = nil
  begin
    ret = Convert.to_symbol(UI.UserInput)
  end while ret != :cancel && ret != :ok

  if ret == :ok
    item = Convert.to_string(UI.QueryWidget(Id(:items), :CurrentItem))
  end
  UI.CloseDialog

  item
end

- (Object) ChooseItemSimple(title, items, selected)

Let the user choose one of a list of items

Parameters:

  • title (String)

    selectionbox title

  • items (Array<String>)

    a list of items

  • selected (String)

    preselected a value in the list

Returns:

  • one item or nil



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

def ChooseItemSimple(title, items, selected)
  items = deep_copy(items)
  item = nil

  _Items = Builtins.maplist(items) { |i| Item(Id(i), i, i == selected) }

  UI.OpenDialog(
    VBox(
      HSpacing(40),
      HBox(SelectionBox(Id(:items), title, _Items), VSpacing(10)),
      ButtonBox(
        PushButton(
          Id(:ok),
          Opt(:default, :key_F10, :okButton),
          Label.OKButton
        ),
        PushButton(
          Id(:cancel),
          Opt(:key_F9, :cancelButton),
          Label.CancelButton
        )
      )
    )
  )
  UI.SetFocus(Id(:items))
  ret = nil
  begin
    ret = Convert.to_symbol(UI.UserInput)
  end while ret != :cancel && ret != :ok

  if ret == :ok
    item = Convert.to_string(UI.QueryWidget(Id(:items), :CurrentItem))
  end
  UI.CloseDialog

  item
end

- (Object) HostName(selected)

Give me one host name on the local network

display dialog with all hosts on the local network

Parameters:

  • selected (String)

    preselect a value in the list

Returns:

  • a hostname or nil if “Cancel” was pressed



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File '../../src/modules/NetworkPopup.rb', line 221

def HostName(selected)
  if @found_hosts == nil
    # label message
    UI.OpenDialog(Label(_("Scanning for hosts on this LAN...")))
    @found_hosts = Convert.convert(
      Builtins.sort(Convert.to_list(SCR.Read(path(".net.hostnames")))),
      :from => "list",
      :to   => "list <string>"
    )
    UI.CloseDialog

    @found_hosts = [] if @found_hosts == nil
  end

  # selection box label
  ret = ChooseItemSimple(_("Re&mote Hosts"), @found_hosts, selected)
  ret
end

- (Object) main



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File '../../src/modules/NetworkPopup.rb', line 42

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "Label"
  Yast.import "NetworkInterfaces"

  # cache all found hosts on the local network
  @found_hosts = nil

  # cache all found NFS servers on the local network
  @found_nfs_servers = nil
end

- (Object) NFSExport(server, selected)

Give me export path of selected server

display dialog with all exported directories from the selected server

Parameters:

  • server (String)

    a NFS server name

  • selected (String)

    preselected a value in the list

Returns:

  • an export or nil if “Cancel” was pressed



246
247
248
249
250
251
252
253
254
255
256
257
258
# File '../../src/modules/NetworkPopup.rb', line 246

def NFSExport(server, selected)
  dirs = Convert.convert(
    SCR.Read(path(".net.showexports"), server),
    :from => "any",
    :to   => "list <string>"
  )

  dirs = [] if dirs == nil

  # selection box label
  ret = ChooseItemSimple(_("&Exported Directories"), dirs, selected)
  ret
end

- (Object) NFSServer(selected)

Give me NFS server name on the local network

display dialog with all local NFS servers

Parameters:

  • selected (String)

    preselected a value in the list

Returns:

  • a hostname or nil if “Cancel” was pressed



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

def NFSServer(selected)
  if @found_nfs_servers == nil
    # label message
    UI.OpenDialog(Label(_("Scanning for hosts on this LAN...")))
    # #71064
    # this works also if ICMP broadcasts are ignored
    cmd = "/usr/sbin/rpcinfo -b mountd 1 | cut -d ' ' -f 2 | sort -u"
    out = Convert.to_map(SCR.Execute(path(".target.bash_output"), cmd))
    @found_nfs_servers = Builtins.filter(
      Builtins.splitstring(Ops.get_string(out, "stdout", ""), "\n")
    ) { |s| s != "" }
    UI.CloseDialog

    if @found_nfs_servers == nil
      @found_nfs_servers = []
    else
      # sort list of servers
      @found_nfs_servers = Builtins.sort(@found_nfs_servers)
    end
  end

  # selection box label
  ret = ChooseItemSimple(_("&NFS Servers"), @found_nfs_servers, selected)
  ret
end