Class: Yast::DontShowAgainClass

Inherits:
Module
  • Object
show all
Defined in:
library/general/src/modules/DontShowAgain.rb

Instance Method Summary collapse

Instance Method Details

#GetCurrentConfigurationMapHash <String, Hash <String, Hash{String => Object>} >

Returns the current configuration map

Returns:

  • (Hash <String, Hash <String, Hash{String => Object>} >)

    with the current configuration

See Also:

  • #current_configuration


334
335
336
337
# File 'library/general/src/modules/DontShowAgain.rb', line 334

def GetCurrentConfigurationMap
  LazyLoadCurrentConf()
  deep_copy(@current_configuration)
end

#GetDefaultReturn(params) ⇒ Object

Return the default return value for question that should not be shown again

Parameters:

  • map (string, string)

    of params

Returns:

  • (Object)

    default return value

See Also:

  • #current_configuration


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
# File 'library/general/src/modules/DontShowAgain.rb', line 242

def GetDefaultReturn(params)
  params = deep_copy(params)
  LazyLoadCurrentConf()
  q_type = Ops.get(params, "q_type")

  # <--- repositories --->
  # Parameters, $[
  #     "q_type"  : "inst-source",             // mandatory
  #     "q_ident" : "Question Identification", // mandatory
  #     "q_url" : "URL"                        // optional
  # ];
  # <--- repositories --->
  if q_type == "inst-source"
    q_ident = Ops.get(params, "q_ident")
    q_url = Ops.get(params, "q_url")

    if Ops.get(@current_configuration, q_type).nil? ||
        Ops.get(@current_configuration, [q_type, q_ident]).nil? ||
        Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil? ||
        Ops.get(@current_configuration, [q_type, q_ident, q_url, "return"]).nil?
      return nil
    end

    Ops.get(
      @current_configuration,
      [q_type, q_ident, q_url, "return"]
    )

    # Add another types here...
  else
    Builtins.y2error("'%1' is an unknown type", q_type)
    nil
  end
  # <--- repositories --->
end

#GetShowQuestionAgain(params) ⇒ Boolean

Returns whether the question should be shown again

Parameters:

  • map (string, string)

    of params

Returns:

  • (Boolean)

    it should be shown

See Also:

  • #current_configuration


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
# File 'library/general/src/modules/DontShowAgain.rb', line 140

def GetShowQuestionAgain(params)
  params = deep_copy(params)
  LazyLoadCurrentConf()
  q_type = Ops.get(params, "q_type")

  # <--- repositories --->
  # Parameters, $[
  #     "q_type"  : "inst-source",             // mandatory
  #     "q_ident" : "Question Identification", // mandatory
  #     "q_url" : "URL"                        // optional
  # ];
  if q_type == "inst-source"
    q_ident = Ops.get(params, "q_ident")
    q_url = Ops.get(params, "q_url")

    if q_ident.nil?
      Builtins.y2error("'q_ident' is a mandatory parameter")
      return nil
    end

    if Ops.get(@current_configuration, q_type).nil? ||
        Ops.get(@current_configuration, [q_type, q_ident]).nil? ||
        Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil? ||
        Ops.get(
          @current_configuration,
          [q_type, q_ident, q_url, "show_again"]
        ).nil?
      return nil
    end

    Ops.get_boolean(
      @current_configuration,
      [q_type, q_ident, q_url, "show_again"]
    )
    # <--- repositories --->

    # Add another types here...
  else
    Builtins.y2error("'%1' is an unknown type", q_type)
    nil
  end
end

#LazyLoadCurrentConfObject

Function that reads the current configuration if it hasn't been read already. It must be called before every Get or Set command.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'library/general/src/modules/DontShowAgain.rb', line 71

def LazyLoadCurrentConf
  if !@already_read
    if FileUtils.Exists(@conf_file) && FileUtils.IsFile(@conf_file)
      Builtins.y2milestone("Reading %1 file", @conf_file)
      # Read and evaluate the current configuration
      read_conf = Convert.convert(
        SCR.Read(path(".target.ycp"), @conf_file),
        from: "any",
        to:   "map <string, map <string, map <string, any>>>"
      )
      @current_configuration = deep_copy(read_conf) if !read_conf.nil?
    else
      Builtins.y2milestone(
        "Configuration file %1 doesn't exist, there's no current configuration.",
        @conf_file
      )
    end

    # Configuration mustn't be read again
    @already_read = true
  end

  nil
end

#mainObject



31
32
33
34
35
36
37
38
39
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
# File 'library/general/src/modules/DontShowAgain.rb', line 31

def main
  textdomain "base"

  Yast.import "Directory"
  Yast.import "FileUtils"

  # Module for that stores and returns the information for
  # "Don't Show This Dialog/Question Again"

  # File with the current configuration
  @conf_file = Ops.add(Directory.vardir, "/dont_show_again.conf")

  # Current configuration map
  #
  #
  # **Structure:**
  #
  #     $[
  #          // question type
  #          "inst-source" : $[
  #              // question identification (MD5sum of the question in the future?)
  #              "-question-ident-" : $[
  #                  // url of the file or directory
  #                  "ftp://abc.xyz/rtf" : $[
  #                      // show the dialog again
  #                      "show_again" : false,
  #                      // additional question return
  #                      "return" : true,
  #                  ]
  #              ]
  #          ]
  #      ]
  @current_configuration = {}

  # Configuration has already been read
  @already_read = false
end

#RemoveShowQuestionAgain(params) ⇒ Boolean

Removes one entry defined with map params

Parameters:

  • map (string, string)

    of params

Returns:

  • (Boolean)

    if success

See Also:

  • #current_configuration


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'library/general/src/modules/DontShowAgain.rb', line 344

def RemoveShowQuestionAgain(params)
  params = deep_copy(params)
  LazyLoadCurrentConf()
  q_type = Ops.get(params, "q_type")

  if q_type == "inst-source"
    q_ident = Ops.get(params, "q_ident")
    q_url = Ops.get(params, "q_url")

    if !Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil?
      Ops.set(@current_configuration, [q_type, q_ident, q_url], nil)
      SaveCurrentConfiguration()
    end

    Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil?
  else
    Builtins.y2error("'%1' is an unknown type", q_type)
    false
  end
end

#SaveCurrentConfigurationObject

Saves the current configuration into the configuration file



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
# File 'library/general/src/modules/DontShowAgain.rb', line 97

def SaveCurrentConfiguration
  LazyLoadCurrentConf()

  # Removing nil entries from the configuration
  new_configuration = {}

  Builtins.foreach(@current_configuration) do |dont_show_type, records|
    # Defined and known type
    if dont_show_type == "inst-source"
      # Every popup type
      Builtins.foreach(records) do |popup_type, one_record|
        # Every URL
        Builtins.foreach(one_record) do |url, record_options|
          # Record mustn't be nil or empty to be reused
          if !record_options.nil? && record_options != {}
            # Creating map from the base
            Ops.set(new_configuration, dont_show_type, {}) if Ops.get(new_configuration, dont_show_type).nil?
            Ops.set(new_configuration, [dont_show_type, popup_type], {}) if Ops.get(new_configuration, [dont_show_type, popup_type]).nil?

            Ops.set(
              new_configuration,
              [dont_show_type, popup_type, url],
              record_options
            )
          end
        end
      end
      # Unknown type
    else
      Ops.set(new_configuration, dont_show_type, records)
    end
  end

  @current_configuration = deep_copy(new_configuration)

  SCR.Write(path(".target.ycp"), @conf_file, @current_configuration)
end

#SetDefaultReturn(params, default_return) ⇒ Boolean

Sets the default return value for the question that should not be shown

Parameters:

  • map (string, string)

    of params

  • any

    default return

Returns:

  • (Boolean)

    if success

See Also:

  • #current_configuration


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
# File 'library/general/src/modules/DontShowAgain.rb', line 284

def SetDefaultReturn(params, default_return)
  params = deep_copy(params)
  default_return = deep_copy(default_return)
  LazyLoadCurrentConf()
  q_type = Ops.get(params, "q_type")
  # Always set to 'true' if the configuration is changed
  conf_changed = false

  # <--- repositories --->
  # Parameters, $[
  #     "q_type"  : "inst-source",             // mandatory
  #     "q_ident" : "Question Identification", // mandatory
  #     "q_url" : "URL"                        // optional
  # ];
  if q_type == "inst-source"
    q_ident = Ops.get(params, "q_ident")
    q_url = Ops.get(params, "q_url")

    if q_ident.nil?
      Builtins.y2error("'q_ident' is a mandatory parameter")
      return nil
    end

    # building the configuration map
    Ops.set(@current_configuration, q_type, {}) if Ops.get(@current_configuration, q_type).nil?
    Ops.set(@current_configuration, [q_type, q_ident], {}) if Ops.get(@current_configuration, [q_type, q_ident]).nil?
    Ops.set(@current_configuration, [q_type, q_ident, q_url], {}) if Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil?

    # save the new value into the configuration
    conf_changed = true
    Ops.set(
      @current_configuration,
      [q_type, q_ident, q_url, "return"],
      default_return
    )
    # <--- repositories --->

    # Add another types here...
  else
    Builtins.y2error("'%1' is an unknown type", q_type)
    return nil
  end

  conf_changed ? SaveCurrentConfiguration() : nil
end

#SetShowQuestionAgain(params, new_value) ⇒ Boolean

Sets and stores whether the question should be shown again. If it should be, the result is not stored since the 'show again' is the default value.

Parameters:

  • map (string, string)

    of params

  • boolean

    show again

Returns:

  • (Boolean)

    if success

See Also:

  • #current_configuration


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
# File 'library/general/src/modules/DontShowAgain.rb', line 191

def SetShowQuestionAgain(params, new_value)
  params = deep_copy(params)
  LazyLoadCurrentConf()
  q_type = Ops.get(params, "q_type")
  # Always set to 'true' if the configuration is changed
  conf_changed = false

  # <--- repositories --->
  # Parameters, $[
  #     "q_type"  : "inst-source",             // mandatory
  #     "q_ident" : "Question Identification", // mandatory
  #     "q_url" : "URL"                        // optional
  # ];
  if q_type == "inst-source"
    q_ident = Ops.get(params, "q_ident")
    q_url = Ops.get(params, "q_url")

    if q_ident.nil?
      Builtins.y2error("'q_ident' is a mandatory parameter")
      return nil
    end

    # building the configuration map
    Ops.set(@current_configuration, q_type, {}) if Ops.get(@current_configuration, q_type).nil?
    Ops.set(@current_configuration, [q_type, q_ident], {}) if Ops.get(@current_configuration, [q_type, q_ident]).nil?
    Ops.set(@current_configuration, [q_type, q_ident, q_url], {}) if Ops.get(@current_configuration, [q_type, q_ident, q_url]).nil?

    # save the new value into the configuration
    conf_changed = true
    Ops.set(
      @current_configuration,
      [q_type, q_ident, q_url, "show_again"],
      new_value
    )
    # <--- repositories --->

    # Add another types here...
  else
    Builtins.y2error("'%1' is an unknown type", q_type)
    return nil
  end

  conf_changed ? SaveCurrentConfiguration() : nil
end