Class: Yast::MenuClient

Inherits:
Client
  • Object
show all
Defined in:
library/desktop/src/clients/menu.rb

Instance Method Summary collapse

Instance Method Details

#DisplaySplashObject



198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'library/desktop/src/clients/menu.rb', line 198

def DisplaySplash
  UI.OpenDialog(
    Opt(:defaultsize),
    VBox(
      VStretch(),
      # Message shown while loading modules information
      Label(_("Loading modules, please wait ...")),
      VStretch()
    )
  )

  nil
end

#Launch(modul) ⇒ Boolean

Returns true if control center is to be resatrted.

Returns:

  • (Boolean)

    true if control center is to be resatrted



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
# File 'library/desktop/src/clients/menu.rb', line 290

def Launch(modul)
  function = Ops.get_string(@Modules, [modul, "X-SuSE-YaST-Call"], "")
  argument = Ops.get_string(@Modules, [modul, "X-SuSE-YaST-Argument"], "")
  Builtins.y2debug("Calling: %1 (%2)", function, argument)

  display_info = UI.GetDisplayInfo
  textmode = Ops.get_boolean(display_info, "TextMode", false)

  if function != ""
    cmd = ""
    ret = nil

    # prevent shell injection when passing argument. But on other hand do
    # not pass empty argument which makes module think it is CLI (bsc#1121425)
    argument = argument.empty? ? "" : argument.shellescape

    # Use UI::RunInTerminal in text-mode only (#237332)
    if textmode
      cmd = Builtins.sformat("/sbin/yast %1 %2 >&2", function.shellescape, argument)
      ret = UI.RunInTerminal(cmd)
    else
      cmd = Builtins.sformat("/sbin/yast2 %1 %2 >&2", function.shellescape, argument)
      ret = SCR.Execute(path(".target.bash"), cmd)
    end
    Builtins.y2milestone("Got %1 from %2", ret, cmd)

    if function == "online_update" && ret != :cancel && ret != :abort &&
        FileUtils.Exists(@restart_you)
      Builtins.y2milestone("yast needs to be restarted - exiting...")
      SCR.Execute(
        path(".target.bash"),
        Builtins.sformat("/usr/bin/touch %1", @restart_file.shellescape)
      )
      return true
    end
  end
  false
end

#mainObject



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
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
189
190
191
192
193
194
195
196
# File 'library/desktop/src/clients/menu.rb', line 36

def main
  Yast.import "UI"

  textdomain "base"

  Yast.import "Desktop"
  Yast.import "Directory"
  Yast.import "FileUtils"
  Yast.import "Label"
  Yast.import "Popup"

  @Groups = {}
  @Modules = {}
  @root = false

  @restart_file = Ops.add(Directory.vardir, "/restart_menu")
  # file existing if yast2-online-update wants to be restarted
  @restart_you = Ops.add(Directory.vardir, "/selected_patches.ycp")

  DisplaySplash()

  @Values = [
    "GenericName",
    # not required: "Comment",
    "X-SuSE-YaST-Argument",
    "X-SuSE-YaST-Call",
    "X-SuSE-YaST-Group",
    "X-SuSE-YaST-SortKey",
    "X-SuSE-YaST-RootOnly",
    "X-SuSE-YaST-WSL",
    "Hidden"
  ]

  # always load the desktop files from the system root
  if WFM.scr_chrooted?
    # revert back the chrooting
    handle = Yast::WFM.SCROpen("chroot=/:scr", false)
    Yast::WFM.SCRSetDefault(handle)
  end

  Desktop.Read(@Values)
  @Groups = deep_copy(Desktop.Groups)
  @Modules = deep_copy(Desktop.Modules)
  Builtins.y2debug("Groups=%1", @Groups)
  Builtins.y2debug("Modules=%1", @Modules)

  @non_root_modules = []

  # create the list of modules available to non-root users
  Builtins.foreach(
    Convert.convert(@Modules, from: "map", to: "map <string, map>")
  ) do |name, params|
    @non_root_modules = Builtins.add(@non_root_modules, name) if Ops.get_string(params, "X-SuSE-YaST-RootOnly", "false") != "true"
  end
  Builtins.y2debug("non-root modules: %1", @non_root_modules)

  SCR.Execute(path(".target.remove"), @restart_file) if FileUtils.Exists(@restart_file)

  UI.CloseDialog

  OpenMenu()

  @GroupList = Desktop.GroupList

  # precache groups (#38363)
  @groups = Builtins.maplist(@GroupList) { |gr| Ops.get_string(gr, [0, 0]) }
  Builtins.y2debug("groups=%1", @groups)

  @modules = Builtins.listmap(@groups) do |gr|
    all_modules = Desktop.ModuleList(gr)
    # filter out root-only stuff if the user is not root (#246015)
    if !@root
      all_modules = Builtins.filter(all_modules) do |t|
        Builtins.contains(@non_root_modules, Ops.get_string(t, [0, 0], ""))
      end
    end
    { gr => all_modules }
  end
  Builtins.y2debug("modules=%1", @modules)

  @first = Ops.get(@groups, 0)
  Builtins.y2debug("first=%1", @first)

  # do not show groups containing no modules to the user (#309452)
  @GroupList = Builtins.filter(@GroupList) do |t|
    group = Ops.get_string(t, [0, 0], "")
    Ops.get(@modules, group) != []
  end

  # GroupList = [`item (`id ("Software"), "Software"), ...]
  UI.ReplaceWidget(
    Id(:groups_rep),
    SelectionBox(
      Id(:groups),
      Opt(:notify, :immediate, :keyEvents),
      "",
      @GroupList
    )
  )
  Builtins.y2debug("GroupList=%1", @GroupList)

  ReplaceModuleList(@first)
  UI.SetFocus(Id(:groups))

  loop do
    @event = UI.WaitForEvent
    @eventid = Ops.get(@event, "ID")
    # y2debug too constly: y2debug("event=%1", event);

    if Ops.is_symbol?(@eventid)
      if @eventid == :groups &&
          Ops.get_string(@event, "EventReason", "") == "SelectionChanged"
        @id = Convert.to_string(UI.QueryWidget(Id(:groups), :CurrentItem))
        # ReplaceModuleList(id);
        UI.ReplaceWidget(
          Id(:progs_rep),
          SelectionBox(
            Id(:progs),
            Opt(:notify, :keyEvents),
            "",
            Ops.get(@modules, @id, [])
          )
        )
        next
      elsif (@eventid == :progs || @eventid == :run) &&
          Ops.get_string(@event, "EventReason", "") == "Activated"
        @program = Convert.to_string(
          UI.QueryWidget(Id(:progs), :CurrentItem)
        )
        break if Launch(@program)
      elsif @eventid == :groups &&
          Ops.get_string(@event, "EventReason", "") == "Activated"
        UI.SetFocus(Id(:progs))
      elsif @eventid == :help
        ShowNcursesHelp()
      elsif @eventid == :quit || @eventid == :cancel
        break
      else
        Builtins.y2warning("Event or widget ID not handled: %1", @event)
      end
    elsif Ops.is_string?(@eventid)
      if Ops.get_symbol(@event, "FocusWidgetID", :none) == :groups &&
          @eventid == "CursorRight"
        UI.SetFocus(Id(:progs))
      elsif Ops.get_symbol(@event, "FocusWidgetID", :none) == :progs &&
          @eventid == "CursorLeft"
        UI.SetFocus(Id(:groups))
      else
        Builtins.y2warning("Event or widget ID not handled: %1", @event)
      end
    else
      Builtins.y2warning("Event or widget ID not handled: %1", @event)
    end
  end

  UI.CloseDialog

  # EOF

  nil
end

#OpenMenuObject



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
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
277
278
279
280
281
282
283
284
285
286
287
# File 'library/desktop/src/clients/menu.rb', line 212

def OpenMenu
  # check if user is root (#246015)
  output = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), "/usr/bin/id --user")
  )
  @root = Ops.get_string(output, "stdout", "") == "0\n"

  UI.OpenDialog(
    Opt(:defaultsize),
    VBox(
      HBox(
        HSpacing(1),
        Frame(
          "",
          VBox(
            VSpacing(0.4),
            HBox(
              HSpacing(2),
              # Heading for NCurses Control Center
              HCenter(Heading(_("YaST Control Center"))),
              HSpacing(2)
            ),
            VSpacing(0.4)
          )
        ),
        HSpacing(1.5)
      ),
      VSpacing(1.0),
      HBox(
        HSpacing(1),
        HWeight(
          30,
          ReplacePoint(
            Id(:groups_rep),
            SelectionBox(
              Id(:groups),
              Opt(:notify, :immediate, :keyEvents),
              "",
              []
            )
          )
        ),
        HSpacing(1),
        HWeight(
          70,
          ReplacePoint(
            Id(:progs_rep),
            SelectionBox(Id(:progs), Opt(:notify, :keyEvents), "", [])
          )
        ),
        HSpacing(1)
      ),
      VSpacing(1.0),
      HBox(
        HSpacing(1),
        PushButton(Id(:help), Opt(:key_F1), Label.HelpButton),
        HStretch(),
        PushButton(Id(:run), Opt(:defaultButton), _("Run")),
        PushButton(Id(:quit), Opt(:key_F9, :cancelButton), Label.QuitButton),
        HSpacing(1)
      ),
      VSpacing(1)
    )
  )

  # show popup when running as non-root
  if !@root
    Popup.Notify(
      _(
        "YaST2 Control Center is not running as root.\nYou can only see modules that do not require root privileges."
      )
    )
  end

  nil
end

#ReplaceModuleList(group) ⇒ Object



400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'library/desktop/src/clients/menu.rb', line 400

def ReplaceModuleList(group)
  # y2debug too costly: y2debug("group=%1", group);
  UI.ReplaceWidget(
    Id(:progs_rep),
    SelectionBox(
      Id(:progs),
      Opt(:notify, :keyEvents),
      "",
      Ops.get(@modules, group, [])
    )
  )

  nil
end

#ShowNcursesHelpObject



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
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
390
391
392
393
394
395
396
397
398
# File 'library/desktop/src/clients/menu.rb', line 329

def ShowNcursesHelp
  # NCurses (textmode) Control Center headline
  headline = _("Controlling YaST ncurses with the Keyboard")

  # NCurses Control Center help 1/
  help = _(
    "<p>1) <i>General</i><br>\n" \
    "Navigate through the dialog elements with [TAB] to go to\n" \
    "the next element and [SHIFT] (or [ALT]) + [TAB] to move backwards.\n" \
    "Select or activate elements with [SPACE] or [ENTER].\n" \
    "Some elements use arrow keys (e.g., to scroll in lists).</p>"
  ) +
    # NCurses Control Center help 2/10
    _(
      "<p>Tree navigation is also done by arrow keys. To open or close a " \
      "branch use [SPACE]. For modules showing a tree (might look like a list) " \
      "of configuration items on the left side use [ENTER] to get corresponding " \
      "dialog on the right.</p>"
    ) +
    # NCurses Control Center help 3/10
    _(
      "<p>Buttons are equipped with shortcut keys (the highlighted\nletter). Use [ALT] and the letter to activate the button.</p>"
    ) +
    # NCurses Control Center help 4/10
    _(
      "<p>Press [ESC] to close selection pop-ups (e.g., from\nmenu buttons) without choosing anything.</p>\n"
    ) +
    # NCurses Control Center help 5/10
    _(
      "<p>2) <i>Substitution of Keystrokes</i><br>\n" \
      "<p>Because the environment can affect the use of the keyboard,\n" \
      "there is more than one way to navigate the dialog pages.\n" \
      "If [TAB] and [SHIFT] (or [ALT]) + [TAB] do not work,\n" \
      "move focus forward with [CTRL] + [F] and backward with [CTRL] + [B].</p>"
    ) +
    # NCurses Control Center help 6/10
    _(
      "<p>If [ALT] + [letter] does not work,\n" \
      "try [ESC] + [letter]. Example: [ESC] + [H] for [ALT] + [H].\n" \
      "[ESC] + [TAB] is also a substitute for [ALT] + [TAB].</p>"
    ) +
    # NCurses Control Center help 7/10
    _(
      "<p>3) <i>Function Keys</i><br>\n" \
      "F keys provide a quick access to main functions. " \
      "The function key bindings for the current dialog are " \
      "shown in the bottom line.</p>"
    ) +
    # NCurses Control Center help 8/10
    _("<p>The F keys are usually connected to a certain action:</p>") +
    # NCurses Control Center help 9/10
    _(
      "F1  = Help<br>\n" \
      "F2  = Info or Description<br>\n" \
      "F3  = Add<br>\n" \
      "F4  = Edit or Configure<br>\n" \
      "F5  = Delete<br>\n" \
      "F6  = Test<br>\n" \
      "F7  = Expert or Advanced<br>\n" \
      "F8  = Back<br>\n" \
      "F9  = Abort or Cancel<br>\n" \
      "F10 = OK, Next, Finish, or Accept<br>"
    ) +
    # NCurses Control Center help 10/10
    _("<p>In some environments, all or some\nF keys are not available.</p>")

  Popup.LongText(headline, RichText(help), 60, 20)

  nil
end