Module: Yast::HwinfoNewidInclude

Defined in:
../../src/include/hwinfo/newid.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) AdjustDialogButtons(count_of_items_in_table)

bugzilla #237339



337
338
339
340
341
342
343
344
345
346
347
348
349
# File '../../src/include/hwinfo/newid.rb', line 337

def AdjustDialogButtons(count_of_items_in_table)
  # at least one PCIID defined
  if Ops.greater_than(count_of_items_in_table, 0)
    UI.ChangeWidget(Id(:edit), :Enabled, true)
    UI.ChangeWidget(Id(:delete), :Enabled, true) 
    # nothing listed, disabling buttons
  else
    UI.ChangeWidget(Id(:edit), :Enabled, false)
    UI.ChangeWidget(Id(:delete), :Enabled, false)
  end

  nil
end

- (Array) get_table_items

Return list of items for table widget

Returns:

  • (Array)

    List of items



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File '../../src/include/hwinfo/newid.rb', line 49

def get_table_items
  ids = NewID.GetNewIDs

  # prepare table items
  table_items = []
  id = 0

  Builtins.foreach(ids) do |newid|
    # IDs for selected PCI device
    newid = NewID.AddIDs(newid) if Builtins.haskey(newid, "uniq")
    table_items = Builtins.add(
      table_items,
      Item(
        Id(id),
        Ops.get_string(newid, "driver", ""),
        NewID.GetModelString(Ops.get_string(newid, "uniq", "")),
        add_hex_prefix(Ops.get_string(newid, "vendor", "")),
        add_hex_prefix(Ops.get_string(newid, "device", "")),
        add_hex_prefix(Ops.get_string(newid, "subvendor", "")),
        add_hex_prefix(Ops.get_string(newid, "subdevice", "")),
        add_hex_prefix(Ops.get_string(newid, "class", "")),
        add_hex_prefix(Ops.get_string(newid, "class_mask", "")),
        Ops.get_string(newid, "sysdir", "")
      )
    )
    id = Ops.add(id, 1)
  end if ids != nil

  deep_copy(table_items)
end

- (Object) GetIdValue(widget)



81
82
83
84
85
86
87
# File '../../src/include/hwinfo/newid.rb', line 81

def GetIdValue(widget)
  ret = Convert.to_string(UI.QueryWidget(Id(widget), :Value))

  ret = "" if ret == nil

  ret
end

- (Object) GetNewPCIIDChanged

Function returns whether PCI ID settings have been changed



460
461
462
# File '../../src/include/hwinfo/newid.rb', line 460

def GetNewPCIIDChanged
  @pci_id_changed
end

- (Object) HandleNewPCIIDDialog(key, event)



463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
# File '../../src/include/hwinfo/newid.rb', line 463

def HandleNewPCIIDDialog(key, event)
  event = deep_copy(event)
  # we serve only PC_ID settings
  return nil if key != "pci_id_table_and_buttons"
  return nil if Ops.get(event, "ID") == "kernel_settings"

  Builtins.y2milestone("Key: %1, Event: %2", key, event)

  handle_function_returns = Ops.get(event, "ID")

  if handle_function_returns == nil
    Builtins.y2warning("Unknown event")
  elsif handle_function_returns == :back
    # returning back
    handle_function_returns = :back
  elsif handle_function_returns == :next
    # activate the settings
    NewID.Activate
    # returning next
    handle_function_returns = :next
  elsif handle_function_returns == :cancel
    if GetNewPCIIDChanged()
      if Popup.ReallyAbort(true) == false
        # loop - continue
        handle_function_returns = :continue
      end
    end
    # returning abort
    handle_function_returns = :abort
  elsif handle_function_returns == :add ||
      handle_function_returns == :add_selected
    result = handle_function_returns == :add ?
      NewIDPopup({}) :
      NewDeviceIDPopup({})

    if Ops.get_symbol(result, "ui", :cancel) == :ok
      # add new id
      NewID.AddID(Ops.get_map(result, "newid", {}))

      # refresh table content
      RefreshTableContent()
    end
  elsif handle_function_returns == :edit
    curr = Convert.to_integer(
      UI.QueryWidget(Id(:newid_table), :CurrentItem)
    )
    nid = NewID.GetNewID(curr)

    result = Builtins.haskey(nid, "uniq") ?
      NewDeviceIDPopup(nid) :
      NewIDPopup(nid)

    if Ops.get_symbol(result, "ui", :cancel) == :ok
      NewID.SetNewID(Ops.get_map(result, "newid", {}), curr)
      RefreshTableContent()
      UI.ChangeWidget(Id(:newid_table), :CurrentItem, curr)
    end
  elsif handle_function_returns == :delete
    curr = Convert.to_integer(
      UI.QueryWidget(Id(:newid_table), :CurrentItem)
    )
    NewID.RemoveID(curr)

    RefreshTableContent()

    numids = Builtins.size(NewID.GetNewIDs)

    # preselect the nearest line to deleted one if possible
    if Ops.greater_than(numids, 0)
      curr = Ops.subtract(numids, 1) if Ops.greater_or_equal(curr, numids)

      UI.ChangeWidget(Id(:newid_table), :CurrentItem, curr)
    end
  end

  Builtins.y2milestone("Returning %1", handle_function_returns)

  nil
end

- (Object) initialize_hwinfo_newid(include_target)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File '../../src/include/hwinfo/newid.rb', line 16

def initialize_hwinfo_newid(include_target)
  Yast.import "UI"

  textdomain "tune"

  Yast.import "Wizard"
  Yast.import "NewID"
  Yast.import "Report"

  Yast.import "Popup"
  Yast.import "Label"
  Yast.import "Mode"

  Yast.include include_target, "hwinfo/routines.rb"

  # FIXME: move to the NewID.ycp module
  # PCI ID settings have been changed
  @pci_id_changed = false

  @handle_function_returns = nil
end

- (Object) InitNewPCIIDDialog(id)



442
443
444
445
446
447
448
449
450
# File '../../src/include/hwinfo/newid.rb', line 442

def InitNewPCIIDDialog(id)
  Wizard.DisableBackButton
  Builtins.y2milestone("Init: %1", id)
  items = get_table_items
  UI.ChangeWidget(Id(:newid_table), :Items, items)
  AdjustDialogButtons(Builtins.size(items))

  nil
end

- (Object) NewDeviceIDPopup(newid)



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File '../../src/include/hwinfo/newid.rb', line 256

def NewDeviceIDPopup(newid)
  newid = deep_copy(newid)
  # ask user to support new device
  new_id_dialog = VBox(
    VSpacing(0.4),
    # text in dialog header
    Heading(_("PCI ID Setup")),
    VSpacing(0.5),
    HBox(
      HSpacing(1),
      # textentry label
      TextEntry(
        Id(:driver),
        _("&Driver"),
        Ops.get_string(newid, "driver", "")
      ),
      HSpacing(1.5),
      # textentry label
      TextEntry(
        Id(:sysdir),
        _("Sys&FS Directory"),
        Ops.get_string(newid, "sysdir", "")
      ),
      HSpacing(1)
    ),
    VSpacing(1),
    HBox(
      HSpacing(1),
      ComboBox(
        Id(:pcidevices),
        _("PCI &Device"),
        pci_items(Ops.get_string(newid, "uniq", ""))
      ),
      HSpacing(1)
    ),
    VSpacing(1),
    ButtonBox(
      PushButton(Id(:ok), Opt(:default), Label.OKButton),
      PushButton(Id(:cancel), Label.CancelButton)
    ),
    VSpacing(0.4)
  )

  UI.OpenDialog(new_id_dialog)

  ui = nil
  ret = {}
  begin
    ui = Convert.to_symbol(UI.UserInput)

    if ui == :ok
      # read and set values
      driver = Convert.to_string(UI.QueryWidget(Id(:driver), :Value))
      sysdir = Convert.to_string(UI.QueryWidget(Id(:sysdir), :Value))
      uniq = Convert.to_string(UI.QueryWidget(Id(:pcidevices), :Value))

      if driver == "" && sysdir == ""
        # error message, driver name and sysfs directory are empty
        Report.Error(_("Enter the driver or SysFS directory name."))
        ui = nil
      else
        ret = {
          "ui"    => :ok,
          "newid" => {
            "uniq"   => uniq,
            "driver" => driver,
            "sysdir" => sysdir
          }
        }
      end
    elsif ui == :close || ui == :cancel
      ret = { "ui" => :cancel }
    end
  end while ui != :ok && ui != :cancel && ui != :close

  UI.CloseDialog

  deep_copy(ret)
end

- (Object) NewIDConfigDialog

Main PCI ID configuration dialog

Returns:

  • (Object)

    Result from UserInput()



545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
# File '../../src/include/hwinfo/newid.rb', line 545

def NewIDConfigDialog
  Wizard.SetContents(
    NewPCIIDDialogCaption(),
    NewPCIIDDialogContent(),
    NewPCIIDDialogHelp(),
    true,
    true
  )
  Wizard.DisableBackButton
  Wizard.SetNextButton(:next, Label.OKButton)

  InitNewPCIIDDialog("pci_id_table_and_buttons")

  @handle_function_returns = nil
  while true
    @handle_function_returns = Convert.to_symbol(UI.UserInput)
    HandleNewPCIIDDialog(
      "pci_id_table_and_buttons",
      { "ID" => @handle_function_returns }
    )
    # breaking the loop
    if @handle_function_returns == :back ||
        @handle_function_returns == :next ||
        @handle_function_returns == :abort
      break
    end
  end

  Builtins.y2milestone("New PCI ID: %1", @handle_function_returns)
  @handle_function_returns
end

- (Object) NewIDPopup(newid)



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

def NewIDPopup(newid)
  newid = deep_copy(newid)
  # ask user to support new device
  new_id_dialog = VBox(
    VSpacing(0.4),
    # text in dialog header
    Heading(_("PCI ID Setup")),
    VSpacing(0.5),
    HBox(
      HSpacing(1),
      VBox(
        # textentry label
        TextEntry(
          Id(:driver),
          _("&Driver"),
          Ops.get_string(newid, "driver", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:vendor),
          _("&Vendor"),
          Ops.get_string(newid, "vendor", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:subvendor),
          _("&Subvendor"),
          Ops.get_string(newid, "subvendor", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:class),
          _("&Class"),
          Ops.get_string(newid, "class", "")
        )
      ),
      HSpacing(1.5),
      VBox(
        # textentry label
        TextEntry(
          Id(:sysdir),
          _("Sys&FS Directory"),
          Ops.get_string(newid, "sysdir", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:device),
          _("&Device"),
          Ops.get_string(newid, "device", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:subdevice),
          _("S&ubdevice"),
          Ops.get_string(newid, "subdevice", "")
        ),
        VSpacing(0.5),
        # textentry label
        TextEntry(
          Id(:class_mask),
          _("Class &Mask"),
          Ops.get_string(newid, "class_mask", "")
        )
      ),
      HSpacing(1)
    ),
    VSpacing(1),
    ButtonBox(
      PushButton(Id(:ok), Opt(:default), Label.OKButton),
      PushButton(Id(:cancel), Label.CancelButton)
    ),
    VSpacing(0.4)
  )

  UI.OpenDialog(new_id_dialog)

  # allow only hex numbures
  hexchars = "0123456789abcdefABCDEFx"
  UI.ChangeWidget(Id(:vendor), :ValidChars, hexchars)
  UI.ChangeWidget(Id(:subvendor), :ValidChars, hexchars)
  UI.ChangeWidget(Id(:device), :ValidChars, hexchars)
  UI.ChangeWidget(Id(:subdevice), :ValidChars, hexchars)
  UI.ChangeWidget(Id(:class), :ValidChars, hexchars)
  UI.ChangeWidget(Id(:class_mask), :ValidChars, hexchars)

  ui = nil
  ret = {}
  begin
    ui = Convert.to_symbol(UI.UserInput)

    if ui == :ok
      # read and set values
      vendor = GetIdValue(:vendor)
      subvendor = GetIdValue(:subvendor)
      device = GetIdValue(:device)
      subdevice = GetIdValue(:subdevice)
      _class = GetIdValue(:class)
      class_mask = GetIdValue(:class_mask)
      driver = Convert.to_string(UI.QueryWidget(Id(:driver), :Value))
      sysdir = Convert.to_string(UI.QueryWidget(Id(:sysdir), :Value))

      if driver == "" && sysdir == ""
        # error message, driver name and sysfs directory are empty. one is needed
        Report.Error(_("Enter the driver or SysFS directory name."))
        ui = nil
      elsif vendor == "" && subvendor == "" && device == "" &&
          subdevice == "" &&
          class_mask == "" &&
          _class == ""
        # error message, user didn't fill any PCI ID value
        Report.Error(_("At least one PCI ID value is required."))
        ui = nil
      else
        ret = {
          "ui"    => :ok,
          "newid" => {
            "vendor"     => vendor,
            "device"     => device,
            "subvendor"  => subvendor,
            "subdevice"  => subdevice,
            "class"      => _class,
            "class_mask" => class_mask,
            "driver"     => driver,
            "sysdir"     => sysdir
          }
        }
      end
    elsif ui == :close || ui == :cancel
      ret = { "ui" => :cancel }
    end
  end while ui != :ok && ui != :cancel && ui != :close

  UI.CloseDialog

  deep_copy(ret)
end

- (Object) NewPCIIDDialogCaption



437
438
439
440
# File '../../src/include/hwinfo/newid.rb', line 437

def NewPCIIDDialogCaption
  # dialog header
  _("PCI ID Setup")
end

- (Object) NewPCIIDDialogContent



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File '../../src/include/hwinfo/newid.rb', line 360

def NewPCIIDDialogContent
  VBox(
    # table header, use as short texts as possible
    Table(
      Id(:newid_table),
      Header(
        _("Driver"),
        _("Card Name"),
        _("Vendor"),
        _("Device"),
        # table header, use as short texts as possible
        _("Subvendor"),
        _("Subdevice"),
        _("Class"),
        _("Class Mask"),
        _("SysFS Dir.")
      )
    ),
    VSpacing(0.5),
    HBox(
      MenuButton(
        Ops.add(Label.AddButton, "..."),
        [
          Item(Id(:add_selected), _("&From List")),
          Item(Id(:add), _("&Manually"))
        ]
      ),
      HSpacing(1),
      PushButton(Id(:edit), Label.EditButton),
      HSpacing(1),
      PushButton(Id(:delete), Label.DeleteButton),
      HStretch()
    ),
    VSpacing(0.5)
  )
end

- (Object) NewPCIIDDialogHelp



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File '../../src/include/hwinfo/newid.rb', line 397

def NewPCIIDDialogHelp
  # bugzilla #237379
  button_label = Mode.installation || Mode.config ?
    Label.OKButton :
    Label.FinishButton
  if Builtins.regexpmatch(button_label, "&")
    button_label = Builtins.regexpsub(button_label, "(.*)&(.*)", "\\1\\2")
  end

  Ops.add(
    Ops.add(
      # help text header
      _("<P><B>PCI ID Setup</B><BR></P>") +
        # PCI ID help text
        _(
          "<P>It is possible to add a PCI ID to a device driver to extend its internal database of known supported devices.</P>"
        ) +
        # PCI ID help text
        _(
          "<P>PCI ID numbers are entered and displayed as hexadecimal numbers. <b>SysFS Dir.</b> is the directory name in the /sys/bus/pci/drivers directory. If it is empty, the driver name is used as the directory name.</P>"
        ) +
        # PCI ID help text
        _(
          "<P>If the driver is compiled into the kernel, leave the driver name empty and enter the SysFS directory name instead.</P>"
        ),
      Builtins.sformat(
        # PCI ID help text, %1 stands for a button name (OK or Finish -- depends on the situation)
        _(
          "<P>Use the buttons below the table to change the list of PCI IDs. Press <b>%1</b> to activate the settings.</P>"
        ),
        button_label
      )
    ),
    # PCI ID help text
    _(
      "<P><B>Warning:</B> This is an expert configuration. Only continue if you know what you are doing.</P>"
    )
  )
end

- (Object) pci_items(selected_uniq)



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File '../../src/include/hwinfo/newid.rb', line 231

def pci_items(selected_uniq)
  ret = []

  pcidevices = NewID.GetPCIdevices

  Builtins.foreach(pcidevices) do |pcidev|
    uniq = Ops.get_string(pcidev, "unique_key", "")
    model = Ops.get_string(pcidev, "model", "")
    busid = Ops.get_string(pcidev, "sysfs_bus_id", "")
    if uniq != "" && model != "" && busid != ""
      ret = Builtins.add(
        ret,
        Item(
          Id(uniq),
          Builtins.sformat("%1 (%2)", model, busid),
          uniq == selected_uniq
        )
      )
    end
  end 


  deep_copy(ret)
end

- (Object) ReadSettings



38
39
40
41
# File '../../src/include/hwinfo/newid.rb', line 38

def ReadSettings
  NewID.Read("/etc/sysconfig/hardware/newids")
  :next
end

- (Object) RefreshTableContent



351
352
353
354
355
356
357
358
# File '../../src/include/hwinfo/newid.rb', line 351

def RefreshTableContent
  items = get_table_items

  UI.ChangeWidget(:newid_table, :Items, items)
  AdjustDialogButtons(Builtins.size(items))

  nil
end

- (Object) SetNewPCIIDChanged(changed)

Function sets whether PCI ID settings have been changed



453
454
455
456
457
# File '../../src/include/hwinfo/newid.rb', line 453

def SetNewPCIIDChanged(changed)
  @pci_id_changed = changed

  nil
end

- (Object) WriteSettings



43
44
45
# File '../../src/include/hwinfo/newid.rb', line 43

def WriteSettings
  NewID.Write ? :next : :abort
end