-
Notifications
You must be signed in to change notification settings - Fork 15
/
keyboard.rb
128 lines (113 loc) · 3.78 KB
/
keyboard.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
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
require "yast"
require_relative "../dialogs/layout_selector"
require_relative "../strategies/systemd_strategy"
require_relative "../strategies/yast_proposal_strategy"
require_relative "../keyboard_layout"
require "y2keyboard/keyboards"
module Yast
class KeyboardClient < Client
def main
textdomain "country"
Yast.import "Arch"
Yast.import "CommandLine"
Yast.import "Keyboard"
# The command line description map
@cmdline = {
"id" => "keyboard",
# TRANSLATORS: command line help text for Securoty module
"help" => _("Keyboard configuration."),
"guihandler" => fun_ref(method(:KeyboardSequence), "any ()"),
"initialize" => fun_ref(method(:KeyboardRead), "boolean ()"),
"finish" => fun_ref(method(:KeyboardWrite), "boolean ()"),
"actions" => {
"summary" => {
"handler" => fun_ref(
method(:KeyboardSummaryHandler),
"boolean (map)"
),
# command line help text for 'summary' action
"help" => _("Keyboard configuration summary."),
"readonly" => true
},
"set" => {
"handler" => fun_ref(method(:KeyboardSetHandler), "boolean (map)"),
# command line help text for 'set' action
"help" => _("Set new values for keyboard configuration.")
},
"list" => {
"handler" => fun_ref(method(:KeyboardListHandler), "boolean (map)"),
# command line help text for 'list' action
"help" => _("List all available keyboard layouts."),
"readonly" => true
}
},
"options" => {
"layout" => {
# command line help text for 'set layout' option
"help" => _("New keyboard layout"),
"type" => "string"
}
},
"mappings" => { "summary" => [], "set" => ["layout"], "list" => [] }
}
CommandLine.Run(@cmdline)
end
# read keyboard settings
def KeyboardRead
Keyboard.Read
true
end
# write keyboard settings
def KeyboardWrite
Keyboard.Save
true
end
# the keyboard configuration sequence
def KeyboardSequence
# dont ask for keyboard on S/390
return :next if Arch.s390
Yast::KeyboardClient.setup
end
# Handler for keyboard summary
def KeyboardSummaryHandler(options)
# summary label
CommandLine.Print(_("Current Keyboard Layout: %s" % Keyboard.current_kbd))
true
end
# Handler for listing keyboard layouts
def KeyboardListHandler(options)
Keyboard.Selection.each do |code, name|
CommandLine.Print(Builtins.sformat("%1 (%2)", code, name))
end
true
end
# Handler for changing keyboard settings
def KeyboardSetHandler(options)
keyboard = options["layout"] || ""
if keyboard == "" || !Keyboard.Selection.key?(keyboard)
# TRANSLATORS: error message (%1 is given layout); do not translate 'list'
CommandLine.Print(
_("Keyboard layout '%s' is invalid. Use a 'list' command to see possible values." % keyboard)
)
false
else
Keyboard.Set(keyboard)
Keyboard.Modified
true
end
end
def self.setup
Yast.import "Stage"
Yast.import "Mode"
if Yast::Stage.initial || Yast::Mode.config
# In installation mode or AY configuration mode
strategy = Y2Keyboard::Strategies::YastProposalStrategy.new
else
# running system --> using systemd
strategy = Y2Keyboard::Strategies::SystemdStrategy.new
end
Y2Keyboard::KeyboardLayout.use(strategy, Keyboards.all_keyboards)
Y2Keyboard::Dialogs::LayoutSelector.new.run
end
end
end