Class: Yast::SlideShowCallbacksClass

Inherits:
Module
  • Object
show all
Includes:
Logger
Defined in:
src/modules/SlideShowCallbacks.rb,
src/modules/SlideShowCallbacks.rb

Overview

Provides the Callbacks for SlideShow

Instance Method Summary collapse

Instance Method Details

#CallbackSourceChange(source, media) ⇒ Object

change of repository source: 0 .. n-1 media: 1 .. n


470
471
472
473
474
475
476
477
478
479
480
# File 'src/modules/SlideShowCallbacks.rb', line 470

def CallbackSourceChange(source, media)
  PackageCallbacks.SourceChange(source, media) # inform PackageCallbacks about the change
  PackageSlideShow.SetCurrentCdNo(source, media)
  PackageSlideShow.UpdateCurrentPackageProgress(0)
  PackageSlideShow.UpdateAllCdProgress(false)

  # display remaining packages
  PackageSlideShow.DisplayGlobalProgress

  nil
end

#DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting) ⇒ Object

Callback that will be called by the packager for each RPM as it is being installed or deleted. Note: The packager doesn't call this directly - the corresponding wrapper callbacks do and pass the “deleting” flag as appropriate.


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

def DisplayStartInstall(pkg_name, pkg_location, pkg_description, pkg_size, deleting)
  PackageSlideShow.SlideDisplayStart(
    pkg_name,
    pkg_location,
    pkg_description,
    pkg_size,
    deleting
  )
  HandleInput()

  # warn user about exhausted diskspace during installation (not if deleting packages)
  if !deleting && @ask_again
    pkgdu = Pkg.PkgDU(@pkg_inprogress)

    Builtins.y2debug("PkgDU(%1): %2", @pkg_inprogress, pkgdu)

    if !pkgdu.nil?
      # check each mount point
      Builtins.foreach(pkgdu) do |part, data|
        # skip read-only partitions, the package cannot be installed anyway
        if Ops.get(data, 3, 0) == 1
          Builtins.y2debug("Skipping read-only partition %1", part)
          next
        end
        # add slash if missing (needed for target_dir)
        if part != "/" && Ops.greater_or_equal(Builtins.size(part), 1) &&
            Builtins.substring(part, 0, 1) != "/"
          part = Ops.add("/", part)
        end
        target_dir = Ops.add(Installation.destdir, part)
        disk_available = Pkg.TargetAvailable(target_dir)
        Builtins.y2debug(
          "partition: %1 (%2), available: %3",
          part,
          target_dir,
          disk_available
        )
        if Ops.less_than(disk_available, Ops.get(data, 2, 0))
          Builtins.y2warning(
            "Not enought free space in %1 (%2): available: %3, required: %4",
            part,
            target_dir,
            disk_available,
            Ops.get(data, 2, 0)
          )

          cont = YesNoAgainWarning(
            # warning popup - %1 is directory name (e.g. /boot)
            Builtins.sformat(
              _(
                "The disk space in partition %1 is nearly exhausted.\n" \
                  "Continue with the installation?"
              ),
              part
            )
          )

          SlideShow.SetUserAbort(true) if !cont

          # don't check the other partitions
          raise Break
        end
      end
    else
      # disk usage for each partition is not known
      # assume that all files will be installed into the root directory
      disk_available = Pkg.TargetAvailable(Installation.destdir)

      Builtins.y2milestone(
        "Available space (%1): %2",
        Installation.destdir,
        disk_available
      )

      if Ops.less_than(disk_available, pkg_size)
        Builtins.y2warning(
          "Not enough free space in %1: available: %2, required: %3",
          Installation.destdir,
          disk_available,
          pkg_size
        )

        cont = YesNoAgainWarning(
          # yes-no popup
          _(
            "The disk space is nearly exhausted.\nContinue with the installation?"
          )
        )

        SlideShow.SetUserAbort(true) if !cont
      end
    end
  end

  nil
end

#DonePackage(error, reason) ⇒ Object

at end of install just to override the PackageCallbacks default (which does a 'CloseDialog' :-})


393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'src/modules/SlideShowCallbacks.rb', line 393

def DonePackage(error, reason)
  return "I" if SlideShow.GetUserAbort
  PackageSlideShow.UpdateCurrentPackageProgress(100)

  ret = ""
  if error.nonzero?
    ret = PackageCallbacks.DonePackage(error, reason)
  # put additional rpm output to the installation log
  elsif !reason.nil? && Ops.greater_than(Builtins.size(reason), 0)
    Builtins.y2milestone("Additional RPM output: %1", reason)
    SlideShow.AppendMessageToInstLog(reason)
  end

  if Builtins.size(ret).zero? ||
      Builtins.tolower(Builtins.substring(ret, 0, 1)) != "r"
    PackageSlideShow.SlideDisplayDone(
      PackageCallbacks._package_name,
      PackageCallbacks._package_size,
      PackageCallbacks._deleting_package
    )
  end
  ret
end

#DoneProvide(error, reason, name) ⇒ Object

during file providal


101
102
103
104
105
106
107
108
109
110
111
# File 'src/modules/SlideShowCallbacks.rb', line 101

def DoneProvide(error, reason, name)
  if @_remote_provide
    PackageSlideShow.UpdateCurrentPackageProgress(100)
    PackageSlideShow.DoneProvide(error, reason, name)
    @_remote_provide = false
  end
  return "C" if SlideShow.GetUserAbort
  return PackageCallbacks.DoneProvide(error, reason, name) if error.nonzero?

  ""
end

#FinishDeltaProvideObject

at end of file providal


444
445
446
# File 'src/modules/SlideShowCallbacks.rb', line 444

def FinishDeltaProvide
  nil
end

#HandleInputObject

Check for user button presses and handle them.


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

def HandleInput
  # any button = SlideShow::debug ? UI::PollInput() : UI::TimeoutUserInput( 10 );
  button = UI.PollInput

  # in case of cancel ask user if he really wants to quit installation
  if button == :abort || button == :cancel
    if Mode.normal
      SlideShow.SetUserAbort(
        Popup.AnyQuestion(
          Popup.NoHeadline,
          # popup yes-no
          _("Do you really want\nto quit the installation?"),
          Label.YesButton,
          Label.NoButton,
          :focus_no
        )
      )
    elsif Stage.initial
      SlideShow.SetUserAbort(Popup.ConfirmAbort(:unusable)) # Mode::update (), Stage::cont ()
    else
      SlideShow.SetUserAbort(Popup.ConfirmAbort(:incomplete))
    end

    SlideShow.AppendMessageToInstLog(_("Aborted")) if SlideShow.GetUserAbort
  else
    SlideShow.HandleInput(button)
  end

  nil
end

#InstallSlideShowCallbacksObject

Install callbacks for slideshow.


518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'src/modules/SlideShowCallbacks.rb', line 518

def InstallSlideShowCallbacks
  Builtins.y2milestone("InstallSlideShowCallbacks")

  Pkg.CallbackStartPackage(
    fun_ref(
      method(:StartPackage),
      "void (string, string, string, integer, boolean)"
    )
  )
  Pkg.CallbackProgressPackage(
    fun_ref(method(:ProgressPackage), "boolean (integer)")
  )
  Pkg.CallbackDonePackage(
    fun_ref(method(:DonePackage), "string (integer, string)")
  )

  Pkg.CallbackStartProvide(
    fun_ref(method(:StartProvide), "void (string, integer, boolean)")
  )
  Pkg.CallbackProgressProvide(
    fun_ref(method(:ProgressProvide), "boolean (integer)")
  )
  Pkg.CallbackDoneProvide(
    fun_ref(method(:DoneProvide), "string (integer, string, string)")
  )
  Pkg.CallbackProgressDownload(
    fun_ref(
      method(:ProgressDownload),
      "boolean (integer, integer, integer)"
    )
  )

  Pkg.CallbackSourceChange(
    fun_ref(method(:CallbackSourceChange), "void (integer, integer)")
  )

  Pkg.CallbackStartDeltaDownload(
    fun_ref(method(:StartDeltaProvide), "void (string, integer)")
  )
  Pkg.CallbackProgressDeltaDownload(
    fun_ref(method(:ProgressProvide), "boolean (integer)")
  )
  Pkg.CallbackProblemDeltaDownload(
    fun_ref(method(:ProblemDeltaDownload), "void (string)")
  )
  Pkg.CallbackFinishDeltaDownload(
    fun_ref(method(:FinishDeltaProvide), "void ()")
  )

  Pkg.CallbackStartDeltaApply(
    fun_ref(method(:StartDeltaApply), "void (string)")
  )
  Pkg.CallbackProgressDeltaApply(
    fun_ref(method(:ProgressDeltaApply), "void (integer)")
  )
  Pkg.CallbackProblemDeltaApply(
    fun_ref(method(:ProblemDeltaApply), "void (string)")
  )
  Pkg.CallbackFinishDeltaApply(
    fun_ref(method(:FinishDeltaProvide), "void ()")
  )

  Pkg.CallbackScriptStart(
    fun_ref(method(:ScriptStart), "void (string, string, string, string)")
  )
  Pkg.CallbackScriptProgress(
    fun_ref(method(:ScriptProgress), "boolean (boolean, string)")
  )
  Pkg.CallbackScriptProblem(
    fun_ref(method(:ScriptProblem), "string (string)")
  )
  Pkg.CallbackScriptFinish(fun_ref(method(:ScriptFinish), "void ()"))

  Pkg.CallbackMessage(
    fun_ref(
      PackageCallbacks.method(:Message),
      "boolean (string, string, string, string)"
    )
  )

  Pkg.CallbackMediaChange(
    fun_ref(
      method(:MediaChange),
      "string (string, string, string, string, integer, string, integer, " \
        "string, boolean, list <string>, integer)"
    )
  )

  nil
end

#mainObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'src/modules/SlideShowCallbacks.rb', line 9

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

  textdomain "packager"

  Yast.import "Installation"
  Yast.import "Label"
  Yast.import "Mode"
  Yast.import "Stage"
  Yast.import "PackageCallbacks"
  Yast.import "Popup"
  Yast.import "SlideShow"
  Yast.import "PackageSlideShow"
  Yast.import "Message"
  Yast.import "Directory"
  Yast.import "URL"

  @_remote_provide = false

  @pkg_inprogress = ""

  # never show the disk space warning popup during autoinstallation
  @ask_again = Mode.autoinst ? false : true
  # true == continue with the installtion
  @user_input = true
end

#MediaChange(error_code, error, url, product, current, current_label, wanted, wanted_label, double_sided, devices, current_device) ⇒ Object


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

def MediaChange(error_code, error, url, product, current, current_label,
  wanted, wanted_label, double_sided, devices, current_device)
  devices = deep_copy(devices)
  SlideShow.StopTimer if !Mode.normal

  ret = PackageCallbacks.MediaChange(
    error_code,
    error,
    url,
    product,
    current,
    current_label,
    wanted,
    wanted_label,
    double_sided,
    devices,
    current_device
  )

  if !Mode.normal
    SlideShow.StartTimer

    # moved from PackageCallbacks
    # skip it when there is a popup at the top (see bnc#622286)
    if (ret == "" || URL.Check(ret)) && UI.WidgetExists(:contents)
      PackageSlideShow.SetCurrentCdNo(
        PackageCallbacks._current_source,
        wanted
      )
    end
  end

  ret
end

#Message(patch_name, patch_version, patch_arch, message) ⇒ Object


175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'src/modules/SlideShowCallbacks.rb', line 175

def Message(patch_name, patch_version, patch_arch, message)
  patch_full_name = PackageCallbacks.FormatPatchName(
    patch_name,
    patch_version,
    patch_arch
  )
  Builtins.y2milestone("Message (%1): %2", patch_full_name, message)

  if patch_full_name != ""
    # label, %1 is patch name with version and architecture
    patch_full_name = Builtins.sformat(_("Patch %1\n\n"), patch_full_name)
  end

  Popup.LongMessage(Ops.add(patch_full_name, message))

  nil
end

#ProblemDeltaApply(descr) ⇒ Object


457
458
459
460
461
462
463
464
# File 'src/modules/SlideShowCallbacks.rb', line 457

def ProblemDeltaApply(descr)
  # error in installation log, %1 is detail error description
  SlideShow.AppendMessageToInstLog(
    Builtins.sformat(_("Failed to apply delta RPM: %1"), descr)
  )

  nil
end

#ProblemDeltaDownload(descr) ⇒ Object


448
449
450
451
452
453
454
455
# File 'src/modules/SlideShowCallbacks.rb', line 448

def ProblemDeltaDownload(descr)
  # error in installation log, %1 is detail error description
  SlideShow.AppendMessageToInstLog(
    Builtins.sformat(_("Failed to download delta RPM: %1"), descr)
  )

  nil
end

#ProgressDeltaApply(percent) ⇒ Object

during file providal


437
438
439
440
441
# File 'src/modules/SlideShowCallbacks.rb', line 437

def ProgressDeltaApply(percent)
  PackageSlideShow.UpdateCurrentPackageProgress(percent)

  nil
end

#ProgressDownload(percent, bps_avg, bps_current) ⇒ Object


89
90
91
92
93
94
95
96
97
98
# File 'src/modules/SlideShowCallbacks.rb', line 89

def ProgressDownload(percent, bps_avg, bps_current)
  PackageSlideShow.UpdateCurrentPackageRateProgress(
    percent,
    bps_avg,
    bps_current
  )

  HandleInput()
  !SlideShow.GetUserAbort
end

#ProgressPackage(pkg_percent) ⇒ Object

ProgressPackage percent


377
378
379
380
381
382
383
384
385
386
387
388
389
# File 'src/modules/SlideShowCallbacks.rb', line 377

def ProgressPackage(pkg_percent)
  HandleInput()

  if !SlideShow.GetUserAbort
    PackageSlideShow.UpdateCurrentPackageProgress(pkg_percent)
  end

  if SlideShow.GetUserAbort
    Builtins.y2milestone("Aborted at %1%%", pkg_percent)
  end

  !SlideShow.GetUserAbort
end

#ProgressProvide(percent) ⇒ Object

during file providal


83
84
85
86
87
# File 'src/modules/SlideShowCallbacks.rb', line 83

def ProgressProvide(percent)
  PackageSlideShow.UpdateCurrentPackageProgress(percent) if @_remote_provide
  HandleInput()
  !SlideShow.GetUserAbort
end

#RemoveSlideShowCallbacksObject

Remove callbacks for slideshow. Should be in SlideShowCallbacks but that doesn't work at the moment.


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

def RemoveSlideShowCallbacks
  Builtins.y2milestone("RemoveSlideShowCallbacks")

  Pkg.CallbackStartPackage(nil)
  Pkg.CallbackProgressPackage(nil)
  Pkg.CallbackDonePackage(nil)

  Pkg.CallbackStartProvide(nil)
  Pkg.CallbackProgressProvide(nil)
  Pkg.CallbackDoneProvide(nil)

  Pkg.CallbackSourceChange(nil)

  Pkg.CallbackStartDeltaDownload(nil)
  Pkg.CallbackProgressDeltaDownload(nil)
  Pkg.CallbackProblemDeltaDownload(nil)
  Pkg.CallbackFinishDeltaDownload(nil)

  Pkg.CallbackStartDeltaApply(nil)
  Pkg.CallbackProgressDeltaApply(nil)
  Pkg.CallbackProblemDeltaApply(nil)
  Pkg.CallbackFinishDeltaApply(nil)

  Pkg.CallbackScriptStart(nil)
  Pkg.CallbackScriptProgress(nil)
  Pkg.CallbackScriptProblem(nil)
  Pkg.CallbackScriptFinish(nil)

  Pkg.CallbackMessage(nil)

  nil
end

#ScriptFinishObject


169
170
171
172
173
# File 'src/modules/SlideShowCallbacks.rb', line 169

def ScriptFinish
  Builtins.y2milestone("ScriptFinish")

  nil
end

#ScriptProblem(description) ⇒ Object


164
165
166
167
# File 'src/modules/SlideShowCallbacks.rb', line 164

def ScriptProblem(description)
  # display Abort/Retry/Ignore popup
  PackageCallbacks.ScriptProblem(description)
end

#ScriptProgress(ping, output) ⇒ Object


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'src/modules/SlideShowCallbacks.rb', line 139

def ScriptProgress(ping, output)
  Builtins.y2milestone("ScriptProgress: ping:%1, output: %2", ping, output)

  if !output.nil? && output != ""
    # remove the trailing new line character
    if Builtins.substring(output, Ops.subtract(Builtins.size(output), 1), 1) == "\n"
      output = Builtins.substring(
        output,
        0,
        Ops.subtract(Builtins.size(output), 1)
      )
    end

    # add the output to the log widget
    SlideShow.AppendMessageToInstLog(output)
  end

  input = UI.PollInput
  Builtins.y2milestone("input: %1", input)

  return false if input == :abort || input == :close

  true
end

#ScriptStart(patch_name, patch_version, patch_arch, script_path) ⇒ Object


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

def ScriptStart(patch_name, patch_version, patch_arch, script_path)
  patch_full_name = PackageCallbacks.FormatPatchName(
    patch_name,
    patch_version,
    patch_arch
  )
  Builtins.y2milestone(
    "ScriptStart: patch:%1, script:%2",
    patch_full_name,
    script_path
  )

  # reset the progressbar
  if UI.WidgetExists(:progressCurrentPackage)
    UI.ChangeWidget(:progressCurrentPackage, :Label, patch_full_name)
    UI.ChangeWidget(:progressCurrentPackage, :Value, 0)
  end

  # message in the installation log widget, %1 is a patch name which contains the script
  log_line = Builtins.sformat(_("Starting script %1"), patch_full_name)

  SlideShow.AppendMessageToInstLog(log_line)

  nil
end

#StartDeltaApply(name) ⇒ Object

at start of file providal


430
431
432
433
434
# File 'src/modules/SlideShowCallbacks.rb', line 430

def StartDeltaApply(name)
  PackageSlideShow.SlideDeltaApplyStart(name)

  nil
end

#StartDeltaProvide(name, archivesize) ⇒ Object

at start of file providal


418
419
420
421
422
423
424
425
426
427
# File 'src/modules/SlideShowCallbacks.rb', line 418

def StartDeltaProvide(name, archivesize)
  PackageSlideShow.SlideGenericProvideStart(
    name, # remote
    archivesize,
    _("Downloading delta RPM %1 (download size %2)"),
    true
  )

  nil
end

#StartPackage(name, location, summary, install_size, is_delete) ⇒ Object

at start of package install


365
366
367
368
369
370
371
372
373
# File 'src/modules/SlideShowCallbacks.rb', line 365

def StartPackage(name, location, summary, install_size, is_delete)
  PackageCallbacks._package_name = name
  PackageCallbacks._package_size = install_size
  PackageCallbacks._deleting_package = is_delete

  DisplayStartInstall(name, location, summary, install_size, is_delete)

  nil
end

#StartProvide(name, archivesize, remote) ⇒ Object

at start of file providal


73
74
75
76
77
78
79
80
# File 'src/modules/SlideShowCallbacks.rb', line 73

def StartProvide(name, archivesize, remote)
  @pkg_inprogress = name
  @_remote_provide = remote

  PackageSlideShow.SlideProvideStart(name, archivesize, remote)

  nil
end

#YesNoAgainWarning(message) ⇒ Object


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

def YesNoAgainWarning(message)
  return @user_input if !@ask_again

  icon = Empty()

  # show the warning icon if possible
  ui_capabilities = UI.GetDisplayInfo

  if Ops.get_boolean(ui_capabilities, "HasLocalImageSupport", false)
    icon = Image(
      Ops.add(Directory.icondir, "32x32/apps/msg_warning.png"),
      ""
    )
  end

  content = MarginBox(
    1.5,
    0.5,
    VBox(
      HBox(
        VCenter(icon),
        HSpacing(1),
        VCenter(Heading(Label.WarningMsg)),
        HStretch()
      ),
      VSpacing(0.2),
      Left(Label(message)),
      VSpacing(0.2),
      Left(CheckBox(Id(:dont_ask), Message.DoNotShowMessageAgain)),
      VSpacing(0.5),
      YesNoButtonBox()
    )
  )

  UI.OpenDialog(Opt(:decorated), content)

  ret = UI.UserInput

  @ask_again = !Convert.to_boolean(UI.QueryWidget(Id(:dont_ask), :Value))

  if !@ask_again
    # remember the user input
    @user_input = ret == :yes
  end

  UI.CloseDialog

  ret == :yes
end

#YesNoButtonBoxObject


slide show


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'src/modules/SlideShowCallbacks.rb', line 196

def YesNoButtonBox
  yes_button = PushButton(Id(:yes), Opt(:key_F10), Label.YesButton)
  no_button = PushButton(
    Id(:no_button),
    Opt(:default, :key_F9),
    Label.NoButton
  )

  HBox(
    HStretch(),
    HWeight(1, yes_button),
    HSpacing(2),
    HWeight(1, no_button),
    HStretch()
  )
end