Class: Yast::DontShowAgainClass
- Inherits:
-
Module
- Object
- Module
- Yast::DontShowAgainClass
- Defined in:
- ../../library/general/src/modules/DontShowAgain.rb
Instance Method Summary (collapse)
-
- (Hash <String, Hash <String, Hash{String => Object>} >) GetCurrentConfigurationMap
Returns the current configuration map.
-
- (Object) GetDefaultReturn(params)
Return the default return value for question that should not be shown again.
-
- (Boolean) GetShowQuestionAgain(params)
Returns whether the question should be shown again.
-
- (Object) LazyLoadCurrentConf
Function that reads the current configuration if it hasn't been read already.
- - (Object) main
-
- (Boolean) RemoveShowQuestionAgain(params)
Removes one entry defined with map params.
-
- (Object) SaveCurrentConfiguration
Saves the current configuration into the configuration file.
-
- (Boolean) SetDefaultReturn(params, default_return)
Sets the default return value for the question that should not be shown.
-
- (Boolean) SetShowQuestionAgain(params, new_value)
Sets and stores whether the question should be shown again.
Instance Method Details
- (Hash <String, Hash <String, Hash{String => Object>} >) GetCurrentConfigurationMap
Returns the current configuration map
360 361 362 363 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 360 def GetCurrentConfigurationMap LazyLoadCurrentConf() deep_copy(@current_configuration) end |
- (Object) GetDefaultReturn(params)
Return the default return value for question that should not be shown again
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 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 258 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 return 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) return nil end # <--- repositories ---> end |
- (Boolean) GetShowQuestionAgain(params)
Returns whether the question should be shown again
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 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 146 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 return 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) return nil end end |
- (Object) LazyLoadCurrentConf
Function that reads the current configuration if it hasn't been read already. It must be called before every Get or Set command.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 73 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 |
- (Object) main
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 68 69 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 33 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 |
- (Boolean) RemoveShowQuestionAgain(params)
Removes one entry defined with map params
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 370 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) != nil && Ops.get(@current_configuration, [q_type, q_ident]) != nil && Ops.get(@current_configuration, [q_type, q_ident, q_url]) != nil Ops.set(@current_configuration, [q_type, q_ident, q_url], nil) SaveCurrentConfiguration() end return 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 else Builtins.y2error("'%1' is an unknown type", q_type) return false end end |
- (Object) SaveCurrentConfiguration
Saves the current configuration into the configuration file
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 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 99 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 mustn't be nil or empty to be reused if != nil && != {} # Creating map from the base if Ops.get(new_configuration, dont_show_type) == nil Ops.set(new_configuration, dont_show_type, {}) end if Ops.get(new_configuration, [dont_show_type, popup_type]) == nil Ops.set(new_configuration, [dont_show_type, popup_type], {}) end Ops.set( new_configuration, [dont_show_type, popup_type, url], ) 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 |
- (Boolean) SetDefaultReturn(params, default_return)
Sets the default return value for the question that should not be shown
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 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 300 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 if Ops.get(@current_configuration, q_type) == nil Ops.set(@current_configuration, q_type, {}) end if Ops.get(@current_configuration, [q_type, q_ident]) == nil Ops.set(@current_configuration, [q_type, q_ident], {}) end if Ops.get(@current_configuration, [q_type, q_ident, q_url]) == nil Ops.set(@current_configuration, [q_type, q_ident, q_url], {}) end # 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 if conf_changed return SaveCurrentConfiguration() else return nil end end |
- (Boolean) SetShowQuestionAgain(params, new_value)
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.
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 |
# File '../../library/general/src/modules/DontShowAgain.rb', line 197 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 if Ops.get(@current_configuration, q_type) == nil Ops.set(@current_configuration, q_type, {}) end if Ops.get(@current_configuration, [q_type, q_ident]) == nil Ops.set(@current_configuration, [q_type, q_ident], {}) end if Ops.get(@current_configuration, [q_type, q_ident, q_url]) == nil Ops.set(@current_configuration, [q_type, q_ident, q_url], {}) end # 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 if conf_changed return SaveCurrentConfiguration() else return nil end end |