Class: Yast::DefaultDesktopClass

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

Overview

Handling of default desktop selection

Constant Summary collapse

PROPOSAL_ID =
"DefaultDesktopPatterns".freeze
DEFAULT_VALUES =

Defaults when something in control file is not defined

{ # rubocop:disable Style/MutableConstant default_proc conflict
  "order"   => 99,
  "desktop" => "unknown"
}

Instance Method Summary collapse

Instance Method Details

#DescriptionString

Get the description of the currently selected desktop for the summary


393
394
395
396
397
398
399
400
401
# File 'src/modules/DefaultDesktop.rb', line 393

def Description
  Init()

  return "" unless @desktop

  ProductControl.GetTranslatedText(
    Ops.get_string(@all_desktops, [@desktop, "label_id"], "")
  )
end

#DesktopString

Get the currently set default desktop, nil if none set


268
269
270
271
272
# File 'src/modules/DefaultDesktop.rb', line 268

def Desktop
  Init()

  @desktop
end

#desktop_entry(control_file_entry) ⇒ Object


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'src/modules/DefaultDesktop.rb', line 86

def desktop_entry(control_file_entry)
  desktop_label = control_file_entry["label_id"] || DEFAULT_VALUES["label_id"]
  # required keys
  one_desktop = {
    # BNC #449818, after switching the language name should change too
    "label_id" => desktop_label,
    "label"    => ProductControl.GetTranslatedText(desktop_label)
  }
  ["desktop", "logon", "cursor", "order"].each do |key|
    one_desktop[key] = control_file_entry[key] || DEFAULT_VALUES[key]
  end
  ["packages", "patterns"].each do |key|
    one_desktop[key] = (control_file_entry[key] || "").split
  end
  # 'description' is optional
  if control_file_entry["description_id"]
    one_desktop["description_id"] = control_file_entry["description_id"]
    one_desktop["description"] =
      ProductControl.GetTranslatedText(one_desktop["description_id"])
  end

  one_desktop
end

#ForceReinitObject

Forces new initialization…


191
192
193
194
195
196
# File 'src/modules/DefaultDesktop.rb', line 191

def ForceReinit
  @initialized = false
  Init()

  nil
end

#GetAllDesktopsMapHash{String => map}

Returns map of pre-defined default system tasks


217
218
219
220
221
# File 'src/modules/DefaultDesktop.rb', line 217

def GetAllDesktopsMap
  Init()

  deep_copy(@all_desktops)
end

#InitObject

Initialize default desktop from control file if specified there


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

def Init
  if @initialized == true
    Builtins.y2debug("Already initialized")
    return
  end

  @initialized = true

  # See BNC #424678
  if @all_desktops.nil?
    Builtins.y2milestone("Getting supported desktops from control file")

    desktops_from_cf = []
    # supported_desktops migh be undefined
    any_desktops_from_cf = ProductFeatures.GetFeature(
      "software",
      "supported_desktops"
    )

    if any_desktops_from_cf != "" && any_desktops_from_cf != ""
      desktops_from_cf = Convert.convert(
        any_desktops_from_cf,
        from: "any",
        to:   "list <map>"
      )
    end

    @all_desktops = {}
    one_desktop = {}
    desktop_name = ""

    Builtins.foreach(desktops_from_cf) do |one_desktop_cf|
      desktop_name = Ops.get_string(one_desktop_cf, "name", "")
      if desktop_name == ""
        Builtins.y2error("Missing 'name' in %1", one_desktop_cf)
        next
      end
      desktop_label = Ops.get_string(one_desktop_cf, "label_id") do
        (
          one_desktop_cf_ref = arg_ref(one_desktop_cf)
          result = MissingKey(one_desktop_cf_ref, "label_id")
          one_desktop_cf = one_desktop_cf_ref.value
          result
        )
      end
      # required keys
      one_desktop = {
        "desktop"  => Ops.get(one_desktop_cf, "desktop") do
          (
            one_desktop_cf_ref = arg_ref(one_desktop_cf)
            result = MissingKey(one_desktop_cf_ref, "desktop")
            one_desktop_cf = one_desktop_cf_ref.value
            result
          )
        end,
        "logon"    => Ops.get(one_desktop_cf, "logon") do
          (
            one_desktop_cf_ref = arg_ref(one_desktop_cf)
            result = MissingKey(one_desktop_cf_ref, "logon")
            one_desktop_cf = one_desktop_cf_ref.value
            result
          )
        end,
        "cursor"   => Ops.get(one_desktop_cf, "cursor") do
          (
            one_desktop_cf_ref = arg_ref(one_desktop_cf)
            result = MissingKey(one_desktop_cf_ref, "logon")
            one_desktop_cf = one_desktop_cf_ref.value
            result
          )
        end,
        "packages" => Builtins.splitstring(
          Ops.get_string(one_desktop_cf, "packages", ""),
          " \t\n"
        ),
        "patterns" => Builtins.splitstring(
          Ops.get_string(one_desktop_cf, "patterns", ""),
          " \t\n"
        ),
        "order"    => Ops.get(one_desktop_cf, "order") do
          (
            one_desktop_cf_ref = arg_ref(one_desktop_cf)
            result = MissingKey(one_desktop_cf_ref, "order")
            one_desktop_cf = one_desktop_cf_ref.value
            result
          )
        end,
        # BNC #449818, after switching the language name should change too
        "label_id" => desktop_label,
        "label"    => ProductControl.GetTranslatedText(desktop_label)
      }
      # 'icon' in optional
      if Builtins.haskey(one_desktop_cf, "icon")
        Ops.set(
          one_desktop,
          "icon",
          Ops.get_string(one_desktop_cf, "icon", "")
        )
      end
      # 'description' is optional
      if Builtins.haskey(one_desktop_cf, "description_id")
        description_id = Ops.get_string(
          one_desktop_cf,
          "description_id",
          ""
        )

        Ops.set(
          one_desktop,
          "description",
          ProductControl.GetTranslatedText(description_id)
        )
        # BNC #449818, after switching the language description should change too
        Ops.set(one_desktop, "description_id", description_id)
      end
      # bnc #431251
      # If this desktop is selected, do not deselect patterns
      if Builtins.haskey(one_desktop_cf, "do_not_deselect_patterns")
        Ops.set(
          one_desktop,
          "do_not_deselect_patterns",
          Ops.get_boolean(one_desktop_cf, "do_not_deselect_patterns", false)
        )
      end
      Ops.set(@all_desktops, desktop_name, one_desktop)
    end
  end

  default_desktop = ProductFeatures.GetStringFeature(
    "software",
    "default_desktop"
  )
  default_desktop = nil if default_desktop == ""

  Builtins.y2milestone("Default desktop: '%1'", default_desktop)
  SetDesktop(default_desktop)

  nil
end

#mainObject


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

def main
  Yast.import "Pkg"

  textdomain "packager"

  Yast.import "ProductFeatures"
  Yast.import "ProductControl"
  Yast.import "Installation"
  Yast.import "PackagesProposal"
  Yast.import "Mode"

  # All desktop definitions are taken from control file
  # @see GetAllDesktopsMap
  @all_desktops = nil

  # Desktop which was selected in the desktop selection dialog.
  # Must be defined in control file in section software->supported_desktops.
  @desktop = nil

  @initialized = false

  @packages_proposal_ID_patterns = "DefaultDesktopPatterns"
end

#MissingKey(desktop_def, key) ⇒ Object


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'src/modules/DefaultDesktop.rb', line 32

def MissingKey(desktop_def, key)
  Builtins.y2warning(
    "Wrong desktop def, missing '%1' key: %2",
    key,
    desktop_def.value
  )

  case key
  when "order"
    99
  when "desktop"
    "unknown"
  else
    ""
  end
end

#PatternsToDeselectObject

Get patterns which should be NOT selected for currently selected desktop


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

def PatternsToDeselect
  Init()

  # patterns which must be selected
  patterns_to_select = PatternsToSelect()

  patterns_to_deselect = []

  # bnc #431251
  # A dummy desktop is selected, do not deselect already selected patterns
  if Ops.get_boolean(
    @all_desktops,
    [@desktop, "do_not_deselect_patterns"],
    false
  ) == true
    Builtins.y2milestone(
      "Desktop %1 has 'do_not_deselect_patterns' set",
      @desktop
    )
  else
    # go through all known system task definitions
    Builtins.foreach(GetAllDesktopsMap()) do |_one_desktop, desktop_descr|
      # all patterns required by a system type
      Builtins.foreach(Ops.get_list(desktop_descr, "patterns", [])) do |one_pattern|
        # if not required, add it to 'to deselect'
        if !one_pattern.nil? &&
            !Builtins.contains(patterns_to_select, one_pattern)
          patterns_to_deselect = Builtins.add(
            patterns_to_deselect,
            one_pattern
          )
        end
      end
    end
  end

  Builtins.y2milestone(
    "Patterns to deselect '%1' -> %2",
    @desktop,
    patterns_to_deselect
  )

  deep_copy(patterns_to_deselect)
end

#PatternsToSelectObject

Get patterns which should be selected for currently selected desktop


338
339
340
341
342
# File 'src/modules/DefaultDesktop.rb', line 338

def PatternsToSelect
  Init()

  Ops.get_list(@all_desktops, [@desktop, "patterns"], [])
end

#PrefferedWindowManagerString

Get preffered window/desktop manager for the selected desktop


330
331
332
333
334
# File 'src/modules/DefaultDesktop.rb', line 330

def PrefferedWindowManager
  Init()

  Ops.get_string(@all_desktops, [@desktop, "desktop"], "")
end

#SelectedDesktopsObject

Return list installed desktops or desktop selected for installation.

See Also:


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

def SelectedDesktops
  Init()

  Pkg.TargetInit(Installation.destdir, true)
  Pkg.SourceStartManager(true)
  Pkg.PkgSolve(true)

  all_sel_or_inst_patterns = Builtins.maplist(
    Pkg.ResolvableProperties("", :pattern, "")
  ) do |one_pattern|
    if Ops.get_symbol(one_pattern, "status", :unknown) == :selected ||
        Ops.get_symbol(one_pattern, "status", :unknown) == :installed
      next Ops.get_string(one_pattern, "name", "")
    end
  end

  # all selected or installed patterns
  all_sel_or_inst_patterns = Builtins.filter(all_sel_or_inst_patterns) do |one_pattern|
    !one_pattern.nil?
  end

  selected_desktops = []
  selected = true

  Builtins.foreach(GetAllDesktopsMap()) do |desktop_name, desktop_def|
    selected = true
    Builtins.foreach(Ops.get_list(desktop_def, "patterns", [])) do |one_pattern|
      if !Builtins.contains(all_sel_or_inst_patterns, one_pattern)
        selected = false
        next
      end
    end
    if selected
      selected_desktops = Builtins.add(selected_desktops, desktop_name)
    end
  end

  deep_copy(selected_desktops)
end

#SelectedPackagesObject

Deprecated: Packages are not selected by a desktop selection only patterns bnc#866724


324
325
326
# File 'src/modules/DefaultDesktop.rb', line 324

def SelectedPackages
  []
end

#SelectedPatternsObject


318
319
320
# File 'src/modules/DefaultDesktop.rb', line 318

def SelectedPatterns
  PackagesProposal.GetResolvables(@packages_proposal_ID_patterns, :pattern, optional: true)
end

#SetDesktop(new_desktop) ⇒ Object

Set the default desktop


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

def SetDesktop(new_desktop)
  Init()

  if new_desktop.nil?
    # Reset the selected patterns
    Builtins.y2milestone("Reseting DefaultDesktop")
    @desktop = nil

    # Do not overwrite the autoyast pattern selection by
    # the default desktop pattern selection (bnc#888981)
    unless Mode.autoinst
      PackagesProposal.SetResolvables(
        @packages_proposal_ID_patterns,
        :pattern,
        [],
        optional: true
      )
    end
  elsif !Builtins.haskey(@all_desktops, new_desktop)
    Builtins.y2error("Attempting to set desktop to unknown %1", new_desktop)
  else
    @desktop = new_desktop

    Builtins.y2milestone("New desktop has been set: %1", @desktop)

    # Do not overwrite the autoyast pattern selection by
    # the default desktop pattern selection (bnc#888981)
    if !@desktop.nil? && @desktop != "" && !Mode.autoinst
      # Require new patterns and packages
      PackagesProposal.SetResolvables(
        @packages_proposal_ID_patterns,
        :pattern,
        Ops.get_list(@all_desktops, [@desktop, "patterns"], []),
        optional: true
      )
    end
  end

  nil
end