Skip to content

Commit

Permalink
Initial support for multi product media
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Sep 11, 2017
1 parent b2e6ee1 commit 50bec6a
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/include/packager/repositories_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)

enter_again = false

# more products on the medium, let the user choose the products to install
if !Mode.auto && new_repos.size > 1
require "y2packager/product_location"
require "y2packager/dialogs/addon_selector"
products = new_repos.map { |r| Y2Packager::ProductLocation.new(r[0], r[1]) }

dialog = Y2Packager::Dialogs::AddonSelector.new(products)
ui = dialog.run

# abort/cancel/back/... => do not continue
return :cancel unless ui == :next

new_repos = dialog.selected_products.map { |p| [p.name, p.dir] }

# nothing selected
return :cancel if new_repos.empty?
end

Builtins.foreach(new_repos) do |repo|
next if enter_again
name = Ops.get(repo, 0, "")
Expand Down
115 changes: 115 additions & 0 deletions src/lib/y2packager/dialogs/addon_selector.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC, All Rights Reserved.
#
# 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.
# ------------------------------------------------------------------------------

require "yast"
require "ui/installation_dialog"

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

module Y2Packager
module Dialogs
# Dialog which shows the user available products on the medium
class AddonSelector < ::UI::InstallationDialog
include Yast::Logger

# @return [Array<Y2Packager::ProductLocation>] Products on the medium
attr_reader :products
# @return [Array<Y2Packager::ProductLocation>] User selected products
attr_reader :selected_products

# Constructor
#
# @param product [Array<Y2Packager::ProductLocation>] Products on the medium
def initialize(products)
super()
textdomain "packager"

@products = products
@selected_products = []
end

# Handler for the :next action
#
# This action happens when the user clicks the 'Next' button
def next_handler
read_user_selection
finish_dialog(:next)
end

# Handler for the :next action
# The default implementation asks for confirmation, here we abort only
# adding an addon-on, not the whole installation.
def abort_handler
finish_dialog(:abort)
end

# Text to display when the help button is pressed
#
# @return [String]
def help_text
# TRANSLATORS: help text (1/2)
_("<p>The selected repository contains several products in independent " \
"subdirectories. Select which products you want to install.</p>") +
# TRANSLATORS: help text (2/2)
_("<p>Note: If there are dependencies between the products you have " \
"to manually select the dependent products. The product dependencies "\
"cannot be automatically detected and checked.</p>")
end

private

attr_writer :selected_products

def selection_content
products.map(&:name)
end

# Dialog content
#
# @see ::UI::Dialog
def dialog_content
# do not stretch the MultiSelectionBox widget over the entire screen,
# squash it to as small as possible size...
HVSquash(
# ...and then set a resonable minimum size
MinSize(60, 16,
MultiSelectionBox(
Id("addon_repos"),

# TRANSLATORS: Product selection label (multi-selection box)
_("&Select Products to Install"),
selection_content
))
)
end

def read_user_selection
selected_items = Yast::UI.QueryWidget(Id("addon_repos"), :SelectedItems)

self.selected_products = selected_items.map do |s|
products.find { |p| p.name == s }
end

log.info("Selected products: #{selected_products.inspect}")
end

# Dialog title
#
# @see ::UI::Dialog
def dialog_title
# TODO: does it make sense also for the 3rd party addons?
_("Extension and Module Selection")
end
end
end
end
2 changes: 1 addition & 1 deletion src/lib/y2packager/dialogs/inst_product_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def next_handler
end
end

# Handler for the :next action
# Handler for the :back action
#
# This action happens when the user clicks the 'Back' button
def back_handler
Expand Down
31 changes: 31 additions & 0 deletions src/lib/y2packager/product_location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ------------------------------------------------------------------------------
# Copyright (c) 2017 SUSE LLC, All Rights Reserved.
#
# 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.
# ------------------------------------------------------------------------------

module Y2Packager
# This class represents a product located on a multi-repository medium
class ProductLocation
# @return [String] Products on the medium
attr_reader :name
# @return [String] User selected products
attr_reader :dir

# Constructor
#
# @param name [String] Product name
# @param dir [String] Location (path starting at the media root)
def initialize(name, dir)
super()
@name = name
@dir = dir
end
end
end

0 comments on commit 50bec6a

Please sign in to comment.