Skip to content

Commit

Permalink
Use the new Yast2::ServiceWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 13, 2018
1 parent 671d2f5 commit 97973ec
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 25 deletions.
59 changes: 48 additions & 11 deletions src/include/samba-server/complex.rb
Expand Up @@ -26,6 +26,10 @@
# Lukas Ocilka <locilka@suse.cz>
#
# $Id$

require "yast2/system_service"
require "yast2/compound_service"

module Yast
module SambaServerComplexInclude
def initialize_samba_server_complex(include_target)
Expand All @@ -39,10 +43,21 @@ def initialize_samba_server_complex(include_target)
Yast.import "Report"
Yast.import "FileUtils"
Yast.import "Popup"
Yast.import "Mode"

Yast.include include_target, "samba-server/helps.rb"
end

# Services to configure
#
# @return [Yast2::CompoundService]
def services
@services ||= Yast2::CompoundService.new(
Yast2::SystemService.find("nmb"),
Yast2::SystemService.find("smb")
)
end

# Read settings dialog
# @return `abort if aborted and `next otherwise
def ReadDialog
Expand All @@ -63,26 +78,27 @@ def ProgressStatus
end

# Write settings dialog
# @return `abort if aborted and `next otherwise
#
# @return [Symbol] :next when service is saved successfully
# :abort otherwise
def WriteDialog
Wizard.RestoreHelp(Ops.get_string(@HELPS, "write", ""))
# Bugzilla #120080 - 'reload' instead of 'restart'
# If there some connected users, SAMBA is running and should be running also after the Write() operation
# and the Progress was turned on before Writing SAMBA conf
connected_users = SambaService.ConnectedUsers
Builtins.y2milestone(
"Number of connected users: %1",
Builtins.size(connected_users)
)
report_restart_popup = Ops.greater_than(Builtins.size(connected_users), 0) &&
# If there some connected users, SAMBA is running and should be running
# also after the Write() operation and the Progress was turned on before
# Writing SAMBA conf
connected_users = SambaService.ConnectedUsers.count
Builtins.y2milestone("Number of connected users: %1", connected_users)

switch_to_reload = connected_users > 0 &&
SambaService.GetServiceRunning &&
SambaService.GetServiceAutoStart &&
ProgressStatus()

ret = SambaServer.Write(false)
ret = save_status(switch_to_reload)

# If popup should be shown and SAMBA is still/again running
if report_restart_popup && SambaService.GetServiceRunning
if switch_to_reload && SambaService.GetServiceRunning
# TRANSLATORS: a popup message
Report.Message(
_(
Expand All @@ -95,5 +111,26 @@ def WriteDialog
end
ret ? :next : :abort
end

# Saves service status (start mode and starts/stops the service)
#
# @note For AutoYaST and for command line actions, it uses the old way for
# backward compatibility, see {SambaServer#Write}. When the service is
# configured using the UI, it is directly saved. See
# {Yast2::SystemService#save}.
#
# @param switch_to_reload [Boolean] indicates if restart action must be
# replaced by reload. See the Bugzilla #120080 stated in #WriteDialog
# comments
#
# @return [Boolean] true if service is saved successfully; false otherwise
def save_status(switch_to_reload)
if Mode.auto || Mode.commandline
SambaServer.Write(false)
else
services.reload if services.action == :restart && switch_to_reload
services.save
end
end
end
end
31 changes: 17 additions & 14 deletions src/include/samba-server/dialogs.rb
Expand Up @@ -26,8 +26,12 @@
# Lukas Ocilka <locilka@suse.cz>
#
# $Id$

require "cwm/service_widget"

module Yast
module SambaServerDialogsInclude

def initialize_samba_server_dialogs(include_target)
Yast.import "UI"

Expand Down Expand Up @@ -87,6 +91,16 @@ def initialize_samba_server_dialogs(include_target)
@btrfs_available = nil
end

# Widget to define status and start mode of the services
#
# There are two involved services, `smb` and `nmb`. See
# {Yast::SambaServerComplexInclude#services}
#
# @return [::CWM::ServiceWidget]
def service_widget
@service_widget ||= ::CWM::ServiceWidget.new(services)
end

# routines

# check if snapper support is available (initial check)
Expand Down Expand Up @@ -1167,15 +1181,15 @@ def Installation_Conf_Tab
100,
VBox(
VSpacing(1),
"SERVICE START",
"service_widget",
VSpacing(1),
"FIREWALL",
VStretch()
)
),
HWeight(2, Empty())
),
"widget_names" => ["SERVICE START", "FIREWALL"]
"widget_names" => ["service_widget", "FIREWALL"]
},
"shares" => {
"header" => _("&Shares"),
Expand Down Expand Up @@ -1267,18 +1281,7 @@ def Installation_Conf_Tab
)

tabs_widget_descr = {
"SERVICE START" => CWMServiceStart.CreateAutoStartWidget(
{
"get_service_auto_start" => fun_ref(
SambaService.method(:GetServiceAutoStart),
"boolean ()"
),
"set_service_auto_start" => fun_ref(
SambaService.method(:SetServiceAutoStart),
"void (boolean)"
)
}
),
"service_widget" => service_widget.cwm_definition,
# BNC #247344, BNC #541958 (comment #18)
"FIREWALL" => CWMFirewallInterfaces.CreateOpenFirewallWidget(
{
Expand Down

0 comments on commit 97973ec

Please sign in to comment.