Skip to content

Commit

Permalink
add keyboard widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Dec 1, 2016
1 parent b8509e2 commit 14026cd
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
6 changes: 5 additions & 1 deletion keyboard/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ ydata_DATA = \
desktop_DATA = \
desktop/keyboard.desktop

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(ydata_DATA) $(desktop_DATA)
ylibdir = @ylibdir@/y2country
ylib_DATA = \
lib/y2country/widgets.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(ydata_DATA) $(desktop_DATA) $(ylib_DATA)

include $(top_srcdir)/Makefile.am.common
76 changes: 76 additions & 0 deletions keyboard/src/lib/y2country/widgets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------

require "yast"
require "cwm/widget"

Yast.import "Keyboard"

module Y2Country
class KeyboardSelectionWidget < CWM::SelectionBox
def initialize
textdomain "country"
end

def label
# widget label
_("&Keyboard Layout")
end

def init
if Yast::Keyboard.user_decision
self.value = Yast::Keyboard.current_kbd
else
self.value = "english-us"
Yast::Keyboard.Set(value)
end
end

def handle
Yast::Keyboard.Set(value)
end

def store
handle
end

def items
# a bit tricky as method return incompatible data
res = Yast::Keyboard.GetKeyboardItems
res.map! do |item|
values = item.params
id, name, *_ = values
id = id.params.first
[id, name]
end
end

def help
# help text for keyboard selection widget
_(
"<p>\n" \
"Choose the <b>Keyboard layout</b> to be used during\n" \
"installation and on the installed system.\n" \
"</p>\n"
)
end
end
end
64 changes: 64 additions & 0 deletions keyboard/test/widgets_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env rspec

require_relative 'test_helper'
require "y2country/widgets"

describe Y2Country::KeyboardSelectionWidget do
it "has label" do
expect(subject.label).to be_a(::String)
end

it "has help" do
expect(subject.help).to be_a(::String)
end

it "enlists all available keyboard layoout" do
expect(subject.items).to include(["english-us", "English (US)"])
end

it "changes keyboard layout when value changed" do
expect(Yast::Keyboard).to receive(:Set)

subject.handle
end

it "stores keyboard layout" do
expect(Yast::Keyboard).to receive(:Set)

subject.store
end

context "when keyboard layout already set" do
before do
allow(Yast::Keyboard).to receive(:user_decision).and_return(true)
end

it "initizalizes widget to previous selection" do
allow(Yast::Keyboard).to receive(:current_kbd).and_return("english-uk")

expect(subject).to receive(:value=).with("english-uk")

subject.init
end
end

context "when keyboard layout not yet set" do
before do
allow(Yast::Keyboard).to receive(:user_decision).and_return(false)
end

it "initizalizes widget to english us layout" do
expect(subject).to receive(:value=).with("english-us")

subject.init
end

it "initializes that default layout" do
expect(subject).to receive(:value).and_return("english-us")

expect(Yast::Keyboard).to receive(:Set).with("english-us")

subject.init
end
end
end

0 comments on commit 14026cd

Please sign in to comment.