Module: Yast::RestoreSummaryDialogInclude

Defined in:
../../src/include/restore/summary_dialog.rb

Instance Method Summary (collapse)

Instance Method Details

- (Symbol) DisplaySummaryDialog(text, detail_text, helptext, label, button)

Display summary dialog with optional details, it is possible to save dialog contents to file

Parameters:

  • text (String)

    Summary text

  • detail_text (String)

    Detailed summary text

  • helptext (String)

    Help text for wizard

  • label (String)

    Text in label

  • button (Symbol)

    Label for next button, possible values arenext (label is “Next”), ok ("Ok") orfinish (“Finish”)

Returns:

  • (Symbol)

    Id of pressed button (next,back, `abort)



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
# File '../../src/include/restore/summary_dialog.rb', line 124

def DisplaySummaryDialog(text, detail_text, helptext, label, button)
  contents = VBox(
    VSpacing(0.5),
    RichText(Id(:rt), text),
    VSpacing(0.5),
    # push button label
    HBox(
      CheckBox(
        Id(:details),
        Opt(:notify, :key_F2),
        _("&Show Details"),
        false
      ),
      HSpacing(3),
      # push button label
      PushButton(Id(:save), _("Sa&ve to File..."))
    ),
    VSpacing(1.0)
  )

  if button == :finish
    Wizard.SetNextButton(:next, Label.FinishButton)
  elsif button == :ok
    Wizard.SetNextButton(:next, Label.OKButton)
  elsif button == :next
    Wizard.RestoreNextButton
  else
    Builtins.y2warning("Unknown button: %1", button)
  end

  Wizard.SetContents(label, contents, helptext, true, true)

  ret = nil
  begin
    ret = UI.UserInput

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

    if ret == :details
      UI.ChangeWidget(Id(:rt), :Value, details == true ? detail_text : text)
    elsif ret == :save
      savefile = UI.AskForSaveFileName("/", "*", _("Save Summary to File"))

      if savefile != "" && savefile != nil
        # Create or empty the file
        SCR.Write(path(".target.string"), savefile, "")

        # BNC #460674
        # Due to the very ineffective all-in-one-run function, removing HTML
        # and writing thw whole file at once takes just too much time
        #
        # Fixed by going through the summary line by line (by <BR>s)

        tmpfile = Ops.add(Directory.tmpdir, "/restore_tmpfile")

        Builtins.y2milestone("Using tmpfile: %1", tmpfile)
        # Using tmpfile - there are more powerful tools for parsing text
        if SCR.Write(path(".target.string"), tmpfile, detail_text)
          if Convert.to_integer(
              SCR.Execute(
                path(".target.bash"),
                Builtins.sformat(
                  "perl -pi -e \"s/<BR>/\\n/g;\" '%1'",
                  String.Quote(tmpfile)
                )
              )
            ) == 0
            detail_text = Convert.to_string(
              SCR.Read(path(".target.string"), tmpfile)
            )
          end
        end

        Builtins.foreach(Builtins.splitstring(detail_text, "\n")) do |one_line|
          # <BR> == newline
          one_line = Ops.add(one_line, "\n")
          # Appending lines one by one
          SCR.Write(
            path(".backup.file_append"),
            [
              savefile,
              (
                one_line_ref = arg_ref(one_line);
                _RemoveTags_result = RemoveTags(one_line_ref);
                one_line = one_line_ref.value;
                _RemoveTags_result
              )
            ]
          )
        end

        Builtins.y2milestone("Summary saved to file: %1", savefile)
      end
    elsif ret == :cancel
      ret = :abort
    end
  end while ret != :next && ret != :abort && ret != :back


  Wizard.RestoreNextButton

  Convert.to_symbol(ret)
end

- (Object) initialize_restore_summary_dialog(include_target)



42
43
44
45
46
47
48
49
50
51
52
53
# File '../../src/include/restore/summary_dialog.rb', line 42

def initialize_restore_summary_dialog(include_target)
  Yast.import "UI"

  textdomain "restore"

  Yast.import "Wizard"

  Yast.import "Popup"
  Yast.import "Label"
  Yast.import "Directory"
  Yast.import "String"
end

- (String) RemoveTags(ret)

This function removes HTML tags from input string

Parameters:

  • input

    Input string

Returns:

  • (String)

    String without tags



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
# File '../../src/include/restore/summary_dialog.rb', line 59

def RemoveTags(ret)
  tagmapping = {
    "BR"      => "\n",
    "/P"      => "\n",
    "P"       => "",
    "B"       => "",
    "/B"      => "",
    "EM"      => "",
    "/EM"     => "",
    "I"       => "",
    "/I"      => "",
    "TT"      => "",
    "/TT"     => "",
    "/BIG"    => "",
    "BIG"     => "",
    "CODE"    => "/CODE",
    "STRONG"  => "",
    "/STRONG" => "",
    "PRE"     => "",
    "/PRE"    => "",
    "LARGE"   => "",
    "/LARGE"  => "",
    "HR"      => "",
    "H1"      => "",
    "/H1"     => "",
    "H2"      => "",
    "/H2"     => "",
    "H3"      => "",
    "/H3"     => ""
  }

  tag = nil
  taglower = nil

  Builtins.foreach(tagmapping) do |t, repl|
    tag = Ops.add(Ops.add("<", t), ">")
    while Builtins.issubstring(ret.value, tag)
      ret.value = Builtins.regexpsub(
        ret.value,
        Ops.add(Ops.add("(.*)", tag), "(.*)"),
        Ops.add(Ops.add("\\1", repl), "\\2")
      )
    end
    taglower = Builtins.tolower(tag)
    while Builtins.issubstring(ret.value, taglower)
      ret.value = Builtins.regexpsub(
        ret.value,
        Ops.add(Ops.add("(.*)", taglower), "(.*)"),
        Ops.add(Ops.add("\\1", repl), "\\2")
      )
    end
  end 


  ret.value
end