-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #103 from yast/casp_merge
Casp merge
- Loading branch information
Showing
6 changed files
with
192 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# 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 | ||
module Widgets | ||
class KeyboardSelection < CWM::SelectionBox | ||
# param default [String] ID for default keyboard layout if not selected. | ||
# Allowed values are defined in /usr/share/YaST2/data/keyboard_raw.ycp | ||
def initialize(default) | ||
textdomain "country" | ||
@default = default | ||
end | ||
|
||
def label | ||
# widget label | ||
_("&Keyboard Layout") | ||
end | ||
|
||
# forces widget to report immediatelly after value changed. | ||
def opt | ||
[:notify] | ||
end | ||
|
||
def init | ||
if Yast::Keyboard.user_decision | ||
self.value = Yast::Keyboard.current_kbd | ||
else | ||
self.value = @default | ||
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 | ||
Yast::Keyboard.GetKeyboardItems.map do |item| | ||
id, name, _enabled = item.params | ||
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 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/env rspec | ||
|
||
require_relative 'test_helper' | ||
require "y2country/widgets" | ||
|
||
describe Y2Country::Widgets::KeyboardSelection do | ||
subject { described_class.new("english-us") } | ||
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 "passes notify option to widget" do | ||
expect(subject.opt).to eq [:notify] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters