Skip to content

Commit

Permalink
move from client to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Aug 6, 2014
1 parent b777ccd commit f16da48
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 128 deletions.
123 changes: 8 additions & 115 deletions src/clients/inst_scc.rb
Expand Up @@ -36,19 +36,14 @@
require "registration/registration"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_selection_dialog"
require "registration/ui/addon_reg_codes_dialog"
require "registration/ui/local_server_dialog"

module Yast
class InstSccClient < Client
include Yast::Logger
extend Yast::I18n


# the maximum number of reg. codes displayed vertically,
# this is the limit for 80x25 textmode UI
# FIXME: move
MAX_REGCODES_PER_COLUMN = 8

# width of reg code input field widget
REG_CODE_WIDTH = 33

Expand Down Expand Up @@ -342,7 +337,7 @@ def scc_credentials_dialog

# help text for the main registration dialog
def scc_help_text
# TODO: improve the help text
# help text
_("Enter SUSE Customer Center credentials here to register the system to " \
"get updates and extensions.")
end
Expand Down Expand Up @@ -397,67 +392,6 @@ def select_addons
end


# create widgets for entering the addon reg codes
# FIXME moved
def addon_regcode_items(addons)
textmode = UI.TextMode
box = VBox()

addons.each do |addon|
box[box.size] = MinWidth(REG_CODE_WIDTH, InputField(Id(addon.identifier),
addon.label, @known_reg_codes.fetch(addon.identifier, "")))
# add extra spacing when there are just few addons, in GUI always
box[box.size] = VSpacing(1) if (addons.size < 5) || !textmode
end

box
end

# create content for the addon reg codes dialog
# FIXME moved
def addon_regcodes_dialog_content(addons)
# display the second column if needed
if addons.size > MAX_REGCODES_PER_COLUMN
# display only the addons which fit two column layout
display_addons = addons[0..2*MAX_REGCODES_PER_COLUMN - 1]

# round the half up (more items in the first column for odd number of items)
half = (display_addons.size + 1) / 2

box1 = addon_regcode_items(display_addons[0..half - 1])
box2 = HBox(
HSpacing(2),
addon_regcode_items(display_addons[half..-1])
)
else
box1 = addon_regcode_items(addons)
end

HBox(
HSpacing(Opt(:hstretch), 3),
VBox(
VStretch(),
Left(Label(n_(
"The extension you selected needs a separate registration code.",
"The extensions you selected need separate registration codes.",
addons.size
))),
Left(Label(n_(
"Enter the registration code into the field below.",
"Enter the registration codes into the fields below.",
addons.size
))),
VStretch(),
HBox(
box1,
box2 ? box2 : Empty()
),
VStretch()
),
HSpacing(Opt(:hstretch), 3)
)
end

# load available addons from SCC server
# the result is cached to avoid reloading when going back and forth in the
# installation workflow
Expand All @@ -476,36 +410,6 @@ def get_available_addons
@available_addons
end

# handle user input in the addon reg codes dialog
# FIXME: moved
def handle_register_addons_dialog(addons_with_codes)
continue_buttons = [:next, :back, :close, :abort]

ret = nil
while !continue_buttons.include?(ret) do
ret = UI.UserInput

if ret == :next
collect_addon_regcodes(addons_with_codes)

# register the add-ons
ret = nil unless register_selected_addons
end
end

return ret
end

# collect the entered reg codes from UI
# @return [Hash<Addon,String>] addon => reg. code mapping
# FIXME: moved
def collect_addon_regcodes(addons_with_codes)
pairs = addons_with_codes.map do |a|
[a.identifier, UI.QueryWidget(Id(a.identifier), :Value)]
end
@known_reg_codes.merge!(Hash[pairs])
end

# register all selected addons
def register_selected_addons
# create duplicate as array is modified in loop for registration order
Expand Down Expand Up @@ -544,11 +448,9 @@ def register_selected_addons

# run the addon reg codes dialog
def register_addons
missing_regcodes = @selected_addons.reject(&:free)

# if registering only add-ons which do not need a reg. code (like SDK)
# then simply start the registration
if missing_regcodes.empty?
if @selected_addons.all?(&:free)
Wizard.SetContents(
# dialog title
_("Register Extensions and Modules"),
Expand All @@ -562,21 +464,12 @@ def register_addons
# when registration fails go back
return register_selected_addons ? :next : :back
else
Wizard.SetContents(
# dialog title
_("Extension and Module Registration Codes"),
# display only the products which need a registration code
addon_regcodes_dialog_content(missing_regcodes),
# help text
_("<p>Enter registration codes for the requested extensions or modules.</p>\n"\
"<p>Registration codes are required for successfull registration." \
"If you cannot provide a registration code then go back and deselect " \
"the respective extension or module.</p>"),
GetInstArgs.enable_back || Mode.normal,
GetInstArgs.enable_next || Mode.normal
)
loop do
ret = ::Registration::UI::AddonRegCodesDialog.run(@selected_addons, @known_reg_codes)
return ret unless ret == :next

return handle_register_addons_dialog(missing_regcodes)
return :next if register_selected_addons
end
end
end

Expand Down
6 changes: 1 addition & 5 deletions src/lib/registration/ui/addon_reg_codes_dialog.rb
Expand Up @@ -14,11 +14,8 @@ class AddonRegCodesDialog

Yast.import "Mode"
Yast.import "GetInstArgs"
Yast.import "Popup"
Yast.import "Report"
Yast.import "UI"
Yast.import "Wizard"
Yast.import "Stage"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run(addons, known_reg_codes)
Expand Down Expand Up @@ -125,8 +122,7 @@ def addons_with_regcode
addons.reject(&:free)
end

# collect the entered reg codes from UI
# @return [Hash<Addon,String>] addon => reg. code mapping
# collect and update the entered reg codes from UI
def collect_addon_regcodes
pairs = addons_with_regcode.map do |a|
[a.identifier, Yast::UI.QueryWidget(Id(a.identifier), :Value)]
Expand Down
4 changes: 0 additions & 4 deletions src/lib/registration/ui/autoyast_addon_dialog.rb
Expand Up @@ -12,13 +12,9 @@ class AutoyastAddonDialog
include Yast::UIShortcuts
include Yast

Yast.import "Mode"
Yast.import "GetInstArgs"
Yast.import "Popup"
Yast.import "Report"
Yast.import "UI"
Yast.import "Wizard"
Yast.import "Stage"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run(addons)
Expand Down
3 changes: 0 additions & 3 deletions src/lib/registration/ui/autoyast_config_dialog.rb
Expand Up @@ -12,10 +12,7 @@ class AutoyastConfigDialog
include Yast::UIShortcuts
include Yast

Yast.import "Mode"
Yast.import "GetInstArgs"
Yast.import "Popup"
Yast.import "Report"
Yast.import "UI"
Yast.import "Wizard"
Yast.import "Label"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/registration/ui/autoyast_config_workflow.rb
Expand Up @@ -19,7 +19,8 @@ class AutoyastConfigWorkflow
include Yast::UIShortcuts
include Yast

Yast.import "UI"
Yast.import "Pkg"
Yast.import "Report"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run(config)
Expand Down

0 comments on commit f16da48

Please sign in to comment.