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 1, 2014
1 parent fcdfb74 commit 19ef310
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 154 deletions.
156 changes: 2 additions & 154 deletions src/clients/scc_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
require "registration/helpers"
require "registration/connect_helpers"
require "registration/ui/autoyast_addon_dialog"
require "registration/ui/autoyast_config_dialog"
require "registration/ui/addon_selection_dialog"
require "registration/ui/addon_eula_dialog"
require "registration/ui/addon_reg_codes_dialog"
Expand Down Expand Up @@ -285,161 +286,8 @@ def addons_reg_codes
:next
end

def refresh_widget_state
enabled = UI.QueryWidget(Id(:do_registration), :Value)
all_widgets = [ :reg_server_cert, :email, :reg_code, :slp_discovery,
:install_updates, :addons, :reg_server_cert_fingerprint_type,
:reg_server_cert_fingerprint ]

all_widgets.each do |w|
UI.ChangeWidget(Id(w), :Enabled, enabled)
end

slp_enabled = UI.QueryWidget(Id(:slp_discovery), :Value)
UI.ChangeWidget(Id(:reg_server), :Enabled, !slp_enabled && enabled)

fingeprint_enabled = UI.QueryWidget(Id(:reg_server_cert_fingerprint_type), :Value) != :none
UI.ChangeWidget(Id(:reg_server_cert_fingerprint), :Enabled, fingeprint_enabled && enabled)
end

def configure_registration
caption = _("Product Registration")
help_text = "<p><b>#{caption}</b></p>"
help_text += _(
"<p>Product registration includes your product in SUSE Customer Center database,\n"+
"enabling you to get online updates and technical support.\n"+
"To register while installing automatically, select <b>Run Product Registration</b>.</p>"
)
help_text += _(
"<p>If your network deploys a custom registration server, set the correct URL of the server\n" +
"and the location of the SMT certificate in <b>SMT Server Settings</b>. Refer\n" +
"to your SMT manual for further assistance.</p>"
)

regsettings = VBox(
Left(
CheckBox(Id(:do_registration), Opt(:notify), _("Register the Product"),
@config.do_registration)
)
)

reg_code_settings = VBox(
# Translators: Text for UI Label - capitalized
Frame(_("Registration"),
VBox(
MinWidth(32, InputField(Id(:email), _("&E-mail Address"), @config.email)),
VSpacing(0.4),
MinWidth(32, InputField(Id(:reg_code), _("Registration &Code"),
@config.reg_code)),
VSpacing(0.4),
Left(CheckBox(Id(:install_updates),
_("Install Available Updates from Update Repositories"),
@config.install_updates))
)
)
)

server_settings = VBox(
# Translators: Text for UI Label - capitalized
Frame(_("Server Settings"),
VBox(
VSpacing(0.2),
Left(CheckBox(Id(:slp_discovery), Opt(:notify),
_("Find Registration Server Using SLP Discovery"),
@config.slp_discovery)),
VSpacing(0.4),
# Translators: Text for UI Label - capitalized
InputField(Id(:reg_server), Opt(:hstretch),
_("Use Specific Server URL Instead of the Default"),
@config.reg_server),
VSpacing(0.4),
# Translators: Text for UI Label - capitalized
InputField(
Id(:reg_server_cert),
Opt(:hstretch),
_("Optional SSL Server Certificate URL"),
@config.reg_server_cert
),
VSpacing(0.4),
Left(
ComboBox(
Id(:reg_server_cert_fingerprint_type),
Opt(:notify),
# Translators: Text for UI Label - capitalized
_("Optional SSL Server Certificate Fingerprint"),
[
Item(Id(:none), _("none"),
@config.reg_server_cert_fingerprint_type != "SHA1" &&
@config.reg_server_cert_fingerprint_type != "SHA256"),
Item(Id("SHA1"), "SHA1", @config.reg_server_cert_fingerprint_type == "SHA1"),
Item(Id("SHA256"), "SHA256", @config.reg_server_cert_fingerprint_type == "SHA256")
]
)
),
InputField(
Id(:reg_server_cert_fingerprint),
Opt(:hstretch),
# Translators: Text for UI Label - capitalized
_("SSL Certificate Fingerprint"),
@config.reg_server_cert_fingerprint
)
)
)
)

contents = VBox(
VSpacing(1),
regsettings,
HBox(
HSpacing(2),
VBox(
VSpacing(1),
reg_code_settings,
VSpacing(1),
server_settings,
VSpacing(0.4),
PushButton(Id(:addons), _("Register Extensions or Modules...")),
VSpacing(0.4)
)
)
)

Wizard.CreateDialog
Wizard.SetContents(caption, contents, help_text, false, true)
Wizard.SetNextButton(:next, Label.FinishButton)

refresh_widget_state

begin
ret = UI.UserInput
log.info "ret: #{ret}"

case ret
when :do_registration, :slp_discovery, :reg_server_cert_fingerprint_type
refresh_widget_state
when :abort, :cancel
break if Popup.ReallyAbort(true)
when :next
# TODO FIXME: input validation
end
end until ret == :next || ret == :back || ret == :addons

if ret == :next || ret == :addons
data_widgets = [ :do_registration, :reg_server, :reg_server_cert,
:email, :reg_code, :slp_discovery, :install_updates
]

data = data_widgets.map do |w|
[w.to_s, UI.QueryWidget(Id(w), :Value)]
end

import_data = Hash[data]
# keep the current addons
import_data["addons"] = @config.addons
@config.import(import_data)
end

ret
::Registration::UI::AutoyastConfigDialog.run(@config)
end

# find registration server via SLP
Expand Down
214 changes: 214 additions & 0 deletions src/lib/registration/ui/autoyast_config_dialog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@

require "yast"
require "registration/addon"
require "registration/helpers"

module Registration
module UI

class AutoyastConfigDialog
include Yast::Logger
include Yast::I18n
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"

# create a new dialog for accepting importing a SSL certificate and run it
def self.run(config)
dialog = AutoyastConfigDialog.new(config)
dialog.run
end

def initialize(config)
textdomain "registration"

@config = config
end

# display the extension selection dialog and wait for a button click
# @return [Symbol] user input (:import, :cancel)
def run
caption = _("Product Registration")
help_text = "<p><b>#{caption}</b></p>"
help_text += _(
"<p>Product registration includes your product in SUSE Customer Center database,\n"+
"enabling you to get online updates and technical support.\n"+
"To register while installing automatically, select <b>Run Product Registration</b>.</p>"
)
help_text += _(
"<p>If your network deploys a custom registration server, set the correct URL of the server\n" +
"and the location of the SMT certificate in <b>SMT Server Settings</b>. Refer\n" +
"to your SMT manual for further assistance.</p>"
)

#FIXME
Wizard.CreateDialog
Wizard.SetContents(caption, content, help_text, false, true)
Wizard.SetNextButton(:next, Label.FinishButton)

refresh_widget_state

ret = handle_dialog

Wizard.RestoreNextButton

ret
end

private

attr_reader :config

def content
regsettings = VBox(
Left(
CheckBox(Id(:do_registration), Opt(:notify), _("Register the Product"),
config.do_registration)
)
)

reg_code_settings = VBox(
# Translators: Text for UI Label - capitalized
Frame(_("Registration"),
VBox(
MinWidth(32, InputField(Id(:email), _("&E-mail Address"), config.email)),
VSpacing(0.4),
MinWidth(32, InputField(Id(:reg_code), _("Registration &Code"),
config.reg_code)),
VSpacing(0.4),
Left(CheckBox(Id(:install_updates),
_("Install Available Updates from Update Repositories"),
config.install_updates))
)
)
)

server_settings = VBox(
# Translators: Text for UI Label - capitalized
Frame(_("Server Settings"),
VBox(
VSpacing(0.2),
Left(CheckBox(Id(:slp_discovery), Opt(:notify),
_("Find Registration Server Using SLP Discovery"),
config.slp_discovery)),
VSpacing(0.4),
# Translators: Text for UI Label - capitalized
InputField(Id(:reg_server), Opt(:hstretch),
_("Use Specific Server URL Instead of the Default"),
config.reg_server),
VSpacing(0.4),
# Translators: Text for UI Label - capitalized
InputField(
Id(:reg_server_cert),
Opt(:hstretch),
_("Optional SSL Server Certificate URL"),
config.reg_server_cert
),
VSpacing(0.4),
Left(
ComboBox(
Id(:reg_server_cert_fingerprint_type),
Opt(:notify),
# Translators: Text for UI Label - capitalized
_("Optional SSL Server Certificate Fingerprint"),
[
Item(Id(:none), _("none"),
config.reg_server_cert_fingerprint_type != "SHA1" &&
config.reg_server_cert_fingerprint_type != "SHA256"),
Item(Id("SHA1"), "SHA1", config.reg_server_cert_fingerprint_type == "SHA1"),
Item(Id("SHA256"), "SHA256", config.reg_server_cert_fingerprint_type == "SHA256")
]
)
),
InputField(
Id(:reg_server_cert_fingerprint),
Opt(:hstretch),
# Translators: Text for UI Label - capitalized
_("SSL Certificate Fingerprint"),
config.reg_server_cert_fingerprint
)
)
)
)

VBox(
VSpacing(1),
regsettings,
HBox(
HSpacing(2),
VBox(
VSpacing(1),
reg_code_settings,
VSpacing(1),
server_settings,
VSpacing(0.4),
PushButton(Id(:addons), _("Register Extensions or Modules...")),
VSpacing(0.4)
)
)
)
end

def refresh_widget_state
enabled = Yast::UI.QueryWidget(Id(:do_registration), :Value)
all_widgets = [ :reg_server_cert, :email, :reg_code, :slp_discovery,
:install_updates, :addons, :reg_server_cert_fingerprint_type,
:reg_server_cert_fingerprint ]

all_widgets.each do |w|
Yast::UI.ChangeWidget(Id(w), :Enabled, enabled)
end

slp_enabled = Yast::UI.QueryWidget(Id(:slp_discovery), :Value)
Yast::UI.ChangeWidget(Id(:reg_server), :Enabled, !slp_enabled && enabled)

fingeprint_enabled = Yast::UI.QueryWidget(Id(:reg_server_cert_fingerprint_type), :Value) != :none
Yast::UI.ChangeWidget(Id(:reg_server_cert_fingerprint), :Enabled, fingeprint_enabled && enabled)
end

def handle_dialog
begin
ret = Yast::UI.UserInput
log.info "ret: #{ret}"

case ret
when :do_registration, :slp_discovery, :reg_server_cert_fingerprint_type
refresh_widget_state
when :abort, :cancel
break if Popup.ReallyAbort(true)
when :next
# TODO FIXME: input validation
end
end until ret == :next || ret == :back || ret == :addons

if ret == :next || ret == :addons
data_widgets = [ :do_registration, :reg_server, :reg_server_cert,
:email, :reg_code, :slp_discovery, :install_updates,
:reg_server_cert_fingerprint_type, :reg_server_cert_fingerprint
]

data = data_widgets.map do |w|
[w.to_s, Yast::UI.QueryWidget(Id(w), :Value)]
end

import_data = Hash[data]
# keep the current addons
import_data["addons"] = config.addons
config.import(import_data)
end

ret

end

end
end
end

0 comments on commit 19ef310

Please sign in to comment.