Skip to content

Commit

Permalink
Switch to Installation::Widgets::Overview.new(client: "foo_proposal")
Browse files Browse the repository at this point in the history
they turned out to be similar enough to work as instances of the same class
  • Loading branch information
mvidner committed Jan 25, 2017
1 parent b5e13fd commit da31d29
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 100 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -215,6 +215,7 @@ ylibdialog_DATA = \
ylibwidgetdir = "${yast2dir}/lib/installation/widgets"
ylibwidget_DATA = \
lib/installation/widgets/mocked.rb \
lib/installation/widgets/overview.rb \
lib/installation/widgets/system_role.rb

EXTRA_DIST = $(module_DATA) $(client_DATA) $(ynclude_DATA) $(scrconf_DATA) $(schemafiles_DATA) $(desktop_DATA) $(fillup_DATA) $(ylibdialog_DATA) $(ylib_DATA) $(ylibtransfer_DATA)
Expand Down
9 changes: 5 additions & 4 deletions src/lib/installation/clients/inst_casp_overview.rb
Expand Up @@ -24,6 +24,7 @@
require "ui/widgets"
require "tune/widgets"

require "installation/widgets/overview"
require "installation/widgets/system_role"
# FIXME: prototype only
require "installation/widgets/mocked"
Expand Down Expand Up @@ -127,12 +128,12 @@ def content
Tune::Widgets::SystemInformation.new
),
upper_right: VBox(
::Widgets::PartitioningOverview.new,
::Widgets::BootloaderOverview.new
Installation::Widgets::Overview.new(client: "partitions_proposal"),
Installation::Widgets::Overview.new(client: "bootloader_proposal")
),
lower_right: VBox(
::Widgets::NetworkOverview.new,
::Widgets::KdumpOverview.new
Installation::Widgets::Overview.new(client: "network_proposal"),
Installation::Widgets::Overview.new(client: "kdump_proposal")
)
)
end
Expand Down
96 changes: 0 additions & 96 deletions src/lib/installation/widgets/mocked.rb
Expand Up @@ -16,99 +16,3 @@ def label
end
end

module Widgets
class Overview < CWM::CustomWidget
def contents
VBox(
Left(PushButton(Id(button_id), label)),
* items.map { |i| Left(Label(" * #{i}")) }
)
end

def label
d = Yast::WFM.CallFunction(proposal_client, ["Description", {}])
d["menu_title"]
end

def items
d = Yast::WFM.CallFunction(proposal_client,
[
"MakeProposal",
{"simple_mode" => true}
])
d["label_proposal"]
end

def handle(_event)
Yast::WFM.CallFunction(proposal_client, ["AskUser", {}])
:redraw
end

private

def button_id
self.class.to_s
end
end

class PartitioningOverview < Overview
def initialize
textdomain "storage"
end

def proposal_client
"partitions_proposal"
end

def label
# FIXME: The storage subsystem is locked by an unknown app...
if ENV["FAKE_STORAGE"]
"&Partitioning"
else
super
end
end

def items
if ENV["FAKE_STORAGE"]
["Standard"]
else
super
end
end
end

class BootloaderOverview < Overview
def initialize
textdomain "bootloader"

Yast.import "Bootloader"
end

def proposal_client
"bootloader_proposal"
end
end

class NetworkOverview < Overview
def initialize
textdomain "network"
end

def proposal_client
"network_proposal"
end
end

class KdumpOverview < Overview
def initialize
textdomain "kdump"

Yast.import "Kdump"
end

def proposal_client
"kdump_proposal"
end
end
end
74 changes: 74 additions & 0 deletions src/lib/installation/widgets/overview.rb
@@ -0,0 +1,74 @@
# encoding: utf-8

# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC
#
#
# 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 SUSE.
#
# To contact SUSE about this file by physical or electronic mail, you may find
# current contact information at www.suse.com.
# ------------------------------------------------------------------------------

require "yast"
require "cwm/widget"

module Installation
module Widgets
# A widget for an all-in-one installation dialog.
# It uses the `simple_mode` of {Installation::ProposalClient#make_proposal}
class Overview < CWM::CustomWidget
attr_reader :proposal_client

# @param client [String] A proposal client implementing simple_mode,
# eg. "bootloader_proposal"
def initialize(client:)
@proposal_client = client
# by default widget_id is the class name; must differentiate instances
self.widget_id = "overview_" + client
end

def contents
VBox(
Left(PushButton(Id(button_id), label)),
* items.map { |i| Left(Label(" * #{i}")) }
)
end

def label
d = Yast::WFM.CallFunction(proposal_client, ["Description", {}])
d["menu_title"]
end

def items
d = Yast::WFM.CallFunction(proposal_client,
[
"MakeProposal",
{"simple_mode" => true}
])
d["label_proposal"]
end

def handle(_event)
Yast::WFM.CallFunction(proposal_client, ["AskUser", {}])
:redraw
end

private

def button_id
# an arbitrary unique id
"ask_" + proposal_client
end
end
end
end

0 comments on commit da31d29

Please sign in to comment.