Module: Yast::PartitioningEpHdDialogsInclude

Defined in:
../../src/include/partitioning/ep-hd-dialogs.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) ConfirmPartitionsDelete(disk, pnames)



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 705

def ConfirmPartitionsDelete(disk, pnames)
  pnames = deep_copy(pnames)
  ConfirmRecursiveDelete(
    disk,
    pnames,
    _("Confirm Deleting of All Partitions"),
    Builtins.sformat(
      _(
        "The disk \"%1\" contains at least one partition.\nIf you proceed, the following partitions will be deleted:"
      ),
      disk
    ),
    Builtins.sformat(_("Really delete all partitions on \"%1\"?"), disk)
  )
end

- (Object) DlgCreatePartition(data)



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 440

def DlgCreatePartition(data)
  aliases = {
    "Type"        => lambda do
      (
        data_ref = arg_ref(data.value);
        _MiniWorkflowStepPartitionType_result = MiniWorkflowStepPartitionType(
          data_ref
        );
        data.value = data_ref.value;
        _MiniWorkflowStepPartitionType_result
      )
    end,
    "Size"        => lambda do
      (
        data_ref = arg_ref(data.value);
        _MiniWorkflowStepPartitionSize_result = MiniWorkflowStepPartitionSize(
          data_ref
        );
        data.value = data_ref.value;
        _MiniWorkflowStepPartitionSize_result
      )
    end,
    "FormatMount" => lambda do
      (
        data_ref = arg_ref(data.value);
        _MiniWorkflowStepFormatMount_result = MiniWorkflowStepFormatMount(
          data_ref
        );
        data.value = data_ref.value;
        _MiniWorkflowStepFormatMount_result
      )
    end,
    "Password"    => lambda do
      (
        data_ref = arg_ref(data.value);
        _MiniWorkflowStepPassword_result = MiniWorkflowStepPassword(
          data_ref
        );
        data.value = data_ref.value;
        _MiniWorkflowStepPassword_result
      )
    end
  }

  sequence = {
    "Type"        => { :next => "Size" },
    "Size"        => { :next => "FormatMount", :finish => :finish },
    "FormatMount" => { :next => "Password", :finish => :finish },
    "Password"    => { :finish => :finish }
  }

  slots = Ops.get_map(data.value, "slots", {})

  if Builtins.haskey(slots, :primary)
    Ops.set(data.value, "type", :primary)
  elsif Builtins.haskey(slots, :extended)
    Ops.set(data.value, "type", :extended)
  elsif Builtins.haskey(slots, :logical)
    Ops.set(data.value, "type", :logical)
  end

  start = Builtins.size(slots) == 1 ? "Size" : "Type"

  if start == "Size"
    r = Storage.NextPartition(
      Ops.get_string(data.value, "disk_device", ""),
      Ops.get_symbol(data.value, "type", :none)
    )
    Ops.set(data.value, "device", Ops.get_string(r, "device", ""))

    if Builtins.haskey(data.value, "disk_udev_id")
      Ops.set(
        data.value,
        "udev_id",
        Builtins.maplist(Ops.get_list(data.value, "disk_udev_id", [])) do |s|
          Builtins.sformat("%1-part%2", s, Ops.get_integer(r, "nr", 0))
        end
      )
    end

    if Builtins.haskey(data.value, "disk_udev_path")
      Ops.set(
        data.value,
        "udev_path",
        Builtins.sformat(
          "%1-part%2",
          Ops.get_string(data.value, "disk_udev_path", ""),
          Ops.get_integer(r, "nr", 0)
        )
      )
    end
  end

  # dialog title
  title = Builtins.sformat(
    _("Add Partition on %1"),
    Ops.get_string(data.value, "disk_device", "error")
  )

  widget = MiniWorkflow.Run(
    title,
    StorageIcons.hd_part_icon,
    aliases,
    sequence,
    start
  )

  widget == :finish
end

- (Object) DlgEditPartition(data)



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 551

def DlgEditPartition(data)
  device = Ops.get_string(data.value, "device", "error")

  aliases = { "FormatMount" => lambda do
    (
      data_ref = arg_ref(data.value);
      _MiniWorkflowStepFormatMount_result = MiniWorkflowStepFormatMount(
        data_ref
      );
      data.value = data_ref.value;
      _MiniWorkflowStepFormatMount_result
    )
  end, "Password" => lambda(
  ) do
    (
      data_ref = arg_ref(data.value);
      _MiniWorkflowStepPassword_result = MiniWorkflowStepPassword(data_ref);
      data.value = data_ref.value;
      _MiniWorkflowStepPassword_result
    )
  end }

  sequence = {
    "FormatMount" => { :next => "Password", :finish => :finish },
    "Password"    => { :finish => :finish }
  }

  # dialog title
  title = Builtins.sformat(_("Edit Partition %1"), device)

  widget = MiniWorkflow.Run(
    title,
    StorageIcons.hd_part_icon,
    aliases,
    sequence,
    "FormatMount"
  )

  widget == :finish
end

- (Object) DlgMovePartition(part)



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 593

def DlgMovePartition(part)
  device = Ops.get_string(part.value, "device", "error")

  free_cyl_before = 0
  free_cyl_after = 0

  free_cyl_before_ref = arg_ref(free_cyl_before)
  free_cyl_after_ref = arg_ref(free_cyl_after)
  Storage.FreeCylindersAroundPartition(
    device,
    free_cyl_before_ref,
    free_cyl_after_ref
  )
  free_cyl_before = free_cyl_before_ref.value
  free_cyl_after = free_cyl_after_ref.value

  if free_cyl_before == 0 && free_cyl_after == 0
    # error popup text, %1 is replace with name of partition
    Popup.Error(
      Builtins.sformat(_("No space to moved partition %1."), device)
    )
    return false
  end

  move = 0

  if Ops.greater_than(free_cyl_before, 0) && free_cyl_after == 0
    # popup text, %1 is replace with name of partition
    if !Popup.YesNo(
        Builtins.sformat(_("Move partition %1 forward?"), device)
      )
      return false
    end

    move = Ops.unary_minus(free_cyl_before)
  elsif free_cyl_before == 0 && Ops.greater_than(free_cyl_after, 0)
    # popup text, %1 is replace with name of partition
    if !Popup.YesNo(
        Builtins.sformat(_("Move partition %1 backward?"), device)
      )
      return false
    end

    move = free_cyl_after
  elsif Ops.greater_than(free_cyl_before, 0) &&
      Ops.greater_than(free_cyl_after, 0)
    UI.OpenDialog(
      Opt(:decorated),
      Greasemonkey.Transform(
        VBox(
          MarginBox(
            2,
            0.4,
            RadioButtonGroup(
              Id(:directions),
              VBox(
                # popup text, %1 is replace with name of partition
                Label(Builtins.sformat(_("Move partition %1?"), device)),
                # radio button text
                term(:LeftRadioButton, Id(:forward), _("Forward"), true),
                # radio button text
                term(:LeftRadioButton, Id(:backward), _("Backward"))
              )
            )
          ),
          ButtonBox(
            PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton),
            PushButton(Id(:ok), Opt(:default, :okButton), Label.OKButton)
          )
        )
      )
    )

    widget = Convert.to_symbol(UI.UserInput)

    direction = Convert.to_symbol(UI.QueryWidget(Id(:directions), :Value))

    UI.CloseDialog

    return false if widget != :ok

    case direction
      when :forward
        move = Ops.unary_minus(free_cyl_before)
      when :backward
        move = free_cyl_after
    end
  end

  return false if move == 0

  Ops.set(
    part.value,
    ["region", 0],
    Ops.add(Ops.get_integer(part.value, ["region", 0], 0), move)
  )
  Builtins.y2milestone("part:%1", part.value)
  true
end

- (Object) DlgResizePartition(data, disk)



694
695
696
697
698
699
700
701
702
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 694

def DlgResizePartition(data, disk)
  disk = deep_copy(disk)
  (
    data_ref = arg_ref(data.value);
    _DlgResize_result = DlgResize(data_ref, disk);
    data.value = data_ref.value;
    _DlgResize_result
  )
end

- (Object) initialize_partitioning_ep_hd_dialogs(include_target)



28
29
30
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 28

def initialize_partitioning_ep_hd_dialogs(include_target)
  textdomain "storage"
end

- (Object) MiniWorkflowStepPartitionSize(data)



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 169

def MiniWorkflowStepPartitionSize(data)
  Builtins.y2milestone("MiniWorkflowStepPartitionSize data:%1", data.value)

  cyl_size = Ops.get_integer(data.value, "cyl_size", 0)
  cyl_count = Ops.get_integer(data.value, "cyl_count", 0)
  slots = Ops.get_list(
    data.value,
    ["slots", Ops.get_symbol(data.value, "type", :unknown)],
    []
  )
  slot = Ops.get(slots, 0, [])

  region = Convert.convert(
    Ops.get(data.value, "region", slot),
    :from => "any",
    :to   => "list <integer>"
  )
  size_k = Ops.divide(Ops.multiply(Ops.get(region, 1, 0), cyl_size), 1024)

  min_num_cyl = 1
  max_num_cyl = Ops.get(slot, 1, 0)

  min_size_k = Builtins.tointeger(
    Ops.divide(
      Convert.convert(
        Ops.multiply(min_num_cyl, cyl_size),
        :from => "integer",
        :to   => "float"
      ),
      1024.0
    )
  )
  max_size_k = Builtins.tointeger(
    Ops.divide(
      Convert.convert(
        Ops.multiply(max_num_cyl, cyl_size),
        :from => "integer",
        :to   => "float"
      ),
      1024.0
    )
  )

  type = Ops.get_symbol(data.value, "type", :unknown)
  what = :nothing # ;-)

  #prefer max size for extended partition (#428337)
  #cascaded triple operators would do, but this is more readable
  if region == slot
    what = type == :extended ? :max_size : :manual_size
  else
    what = :manual_region
  end

  contents = HVSquash(
    # frame heading
    term(
      :FrameWithMarginBox,
      _("New Partition Size"),
      RadioButtonGroup(
        Id(:size),
        VBox(
          term(
            :LeftRadioButton,
            Id(:max_size),
            Opt(:notify),
            # radio button text, %1 is replaced by size
            Builtins.sformat(
              _("Maximum Size (%1)"),
              Storage.KByteToHumanString(max_size_k)
            )
          ),
          # radio button text
          term(
            :LeftRadioButtonWithAttachment,
            Id(:manual_size),
            Opt(:notify),
            _("Custom Size"),
            VBox(
              Id(:manual_size_attachment),
              MinWidth(
                15,
                InputField(Id(:size_input), Opt(:shrinkable), _("Size"))
              )
            )
          ),
          # radio button text
          term(
            :LeftRadioButtonWithAttachment,
            Id(:manual_region),
            Opt(:notify),
            _("Custom Region"),
            VBox(
              Id(:manual_region_attachment),
              MinWidth(
                10,
                IntField(
                  Id(:start_cyl),
                  _("Start Cylinder"),
                  0,
                  cyl_count,
                  Region.Start(region)
                )
              ),
              MinWidth(
                10,
                IntField(
                  Id(:end_cyl),
                  _("End Cylinder"),
                  0,
                  cyl_count,
                  Region.End(region)
                )
              )
            )
          )
        )
      )
    )
  )

  MiniWorkflow.SetContents(
    Greasemonkey.Transform(contents),
    MiniWorkflowStepPartitionSizeHelptext()
  )
  MiniWorkflow.SetLastStep(type == :extended)

  UI.ChangeWidget(Id(:size), :Value, what)
  UI.SetFocus(
    what == :extended ?
      Id(:max_size) :
      what == :manual_size ? Id(:size_input) : Id(:manual_region)
  )
  UI.ChangeWidget(
    Id(:manual_size_attachment),
    :Enabled,
    what == :manual_size
  )
  UI.ChangeWidget(
    Id(:size_input),
    :Value,
    Storage.KByteToHumanString(size_k)
  )
  UI.ChangeWidget(
    Id(:manual_region_attachment),
    :Enabled,
    what == :manual_region
  )

  widget = nil
  begin
    widget = MiniWorkflow.UserInput

    case widget
      when :max_size
        UI.ChangeWidget(Id(:manual_size_attachment), :Enabled, false)
        UI.ChangeWidget(Id(:manual_region_attachment), :Enabled, false)
      when :manual_size
        UI.ChangeWidget(Id(:manual_size_attachment), :Enabled, true)
        UI.ChangeWidget(Id(:manual_region_attachment), :Enabled, false)
        UI.SetFocus(Id(:size_input))
      when :manual_region
        UI.ChangeWidget(Id(:manual_size_attachment), :Enabled, false)
        UI.ChangeWidget(Id(:manual_region_attachment), :Enabled, true)
        UI.SetFocus(Id(:end_cyl)) # or `start_cyl, who cares
      when :next
        what = Convert.to_symbol(UI.QueryWidget(Id(:size), :Value))

        case what
          when :manual_size
            tmp = Convert.to_string(UI.QueryWidget(Id(:size_input), :Value))
            if !(
                size_k_ref = arg_ref(size_k);
                _HumanStringToKByteWithRangeCheck_result = Storage.HumanStringToKByteWithRangeCheck(
                  tmp,
                  size_k_ref,
                  min_size_k,
                  max_size_k
                );
                size_k = size_k_ref.value;
                _HumanStringToKByteWithRangeCheck_result
              )
              # error popup, %1 and %2 are replaced by sizes
              Popup.Error(
                Builtins.sformat(
                  _(
                    "The size entered is invalid. Enter a size between %1 and %2."
                  ),
                  Storage.KByteToHumanString(min_size_k),
                  Storage.KByteToHumanString(max_size_k)
                )
              )
              UI.SetFocus(Id(:size_input))
              widget = :again
              next
            end
          when :manual_region
            s = Convert.to_integer(UI.QueryWidget(Id(:start_cyl), :Value))
            e = Convert.to_integer(UI.QueryWidget(Id(:end_cyl), :Value))
            region = [s, Ops.add(Ops.subtract(e, s), 1)]

            valid = Ops.greater_than(Region.Length(region), 0) &&
              Builtins.find(slots) { |slot2| Region.Inside(slot2, region) } != nil

            if !valid
              # error popup
              Popup.Error(_("The region entered is invalid."))
              UI.SetFocus(Id(:end_cyl))
              widget = :again
              next
            end
        end
    end
  end until widget == :abort || widget == :back || widget == :next

  if widget == :next
    case Convert.to_symbol(UI.QueryWidget(Id(:size), :Value))
      when :max_size
        Ops.set(data.value, "region", slot)
      when :manual_size
        num_cyl = Builtins.tointeger(
          Ops.add(
            Ops.divide(
              Ops.multiply(
                1024.0,
                Convert.convert(size_k, :from => "integer", :to => "float")
              ),
              Convert.convert(cyl_size, :from => "integer", :to => "float")
            ),
            0.5
          )
        )
        num_cyl = Integer.Clamp(num_cyl, min_num_cyl, max_num_cyl)
        Ops.set(data.value, "region", [Ops.get(slot, 0, 0), num_cyl])
      when :manual_region
        Ops.set(data.value, "region", region)
    end

    Ops.set(
      data.value,
      "size_k",
      Ops.divide(
        Ops.multiply(
          Region.Length(
            Convert.convert(
              Ops.get(data.value, "region") { [0, 0] },
              :from => "any",
              :to   => "list <const integer>"
            )
          ),
          cyl_size
        ),
        1024
      )
    )

    if Ops.get_symbol(data.value, "type", :unknown) == :extended
      widget = :finish
    end
  end

  Builtins.y2milestone(
    "MiniWorkflowStepPartitionSize data:%1 ret:%2",
    data.value,
    widget
  )

  widget
end

- (Object) MiniWorkflowStepPartitionSizeHelptext



161
162
163
164
165
166
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 161

def MiniWorkflowStepPartitionSizeHelptext
  # helptext
  helptext = _("<p>Choose the size for the new partition.</p>")

  helptext
end

- (Object) MiniWorkflowStepPartitionType(data)



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 40

def MiniWorkflowStepPartitionType(data)
  Builtins.y2milestone("MiniWorkflowStepPartitionType data:%1", data.value)

  type = Ops.get_symbol(data.value, "type", :unknown)
  slots = Ops.get_map(data.value, "slots", {})

  tmp = VBox()

  if Builtins.haskey(slots, :primary)
    # radio button text
    tmp = Builtins.add(
      tmp,
      term(
        :LeftRadioButton,
        Id(:primary),
        _("&Primary Partition"),
        type == :primary
      )
    )
  end

  if Builtins.haskey(slots, :extended)
    # radio button text
    tmp = Builtins.add(
      tmp,
      term(
        :LeftRadioButton,
        Id(:extended),
        _("&Extended Partition"),
        type == :extended
      )
    )
  end

  if Builtins.haskey(slots, :logical)
    # radio button text
    tmp = Builtins.add(
      tmp,
      term(
        :LeftRadioButton,
        Id(:logical),
        _("&Logical Partition"),
        type == :logical
      )
    )
  end

  # heading for a frame in a dialog
  contents = HVSquash(
    term(
      :FrameWithMarginBox,
      _("New Partition Type"),
      RadioButtonGroup(Id(:partition_type), tmp)
    )
  )

  MiniWorkflow.SetContents(
    Greasemonkey.Transform(contents),
    MiniWorkflowStepPartitionTypeHelptext()
  )
  MiniWorkflow.SetLastStep(false)

  widget = nil
  begin
    widget = MiniWorkflow.UserInput

    case widget
      when :next
        type = Convert.to_symbol(
          UI.QueryWidget(Id(:partition_type), :Value)
        )
    end
  end until widget == :abort || widget == :back || widget == :next

  if widget == :next
    Ops.set(data.value, "type", type)

    r = Storage.NextPartition(
      Ops.get_string(data.value, "disk_device", ""),
      Ops.get_symbol(data.value, "type", :none)
    )
    Ops.set(data.value, "device", Ops.get_string(r, "device", ""))

    if Builtins.haskey(data.value, "disk_udev_id")
      Ops.set(
        data.value,
        "udev_id",
        Builtins.maplist(Ops.get_list(data.value, "disk_udev_id", [])) do |s|
          Builtins.sformat("%1-part%2", s, Ops.get_integer(r, "nr", 0))
        end
      )
    end

    if Builtins.haskey(data.value, "disk_udev_path")
      Ops.set(
        data.value,
        "udev_path",
        Builtins.sformat(
          "%1-part%2",
          Ops.get_string(data.value, "disk_udev_path", ""),
          Ops.get_integer(r, "nr", 0)
        )
      )
    end

    if Ops.get_symbol(data.value, "type", :unknown) == :extended
      Ops.set(data.value, "fsid", Partitions.fsid_extended_win)
      Ops.set(data.value, "used_fs", :unknown)
    end
  end

  Builtins.y2milestone(
    "MiniWorkflowStepPartitionType data:%1 ret:%2",
    data.value,
    widget
  )

  widget
end

- (Object) MiniWorkflowStepPartitionTypeHelptext



32
33
34
35
36
37
# File '../../src/include/partitioning/ep-hd-dialogs.rb', line 32

def MiniWorkflowStepPartitionTypeHelptext
  # helptext
  helptext = _("<p>Choose the partition type for the new partition.</p>")

  helptext
end