Skip to content

Commit

Permalink
gui: Add network check to menu
Browse files Browse the repository at this point in the history
A network check page was added to the menu. Similarly to the TUI, the
network check page will launch a pop-up window and perform a network
check.

Signed-off-by: John Akre <[email protected]>
  • Loading branch information
John Akre committed Sep 23, 2019
1 parent 4cf88f9 commit 2b29ce8
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 1 deletion.
182 changes: 182 additions & 0 deletions gui/network_dialog_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package gui

import (
"time"

"github.com/clearlinux/clr-installer/controller"
"github.com/clearlinux/clr-installer/gui/common"
"github.com/clearlinux/clr-installer/log"
"github.com/clearlinux/clr-installer/model"
"github.com/clearlinux/clr-installer/progress"
"github.com/clearlinux/clr-installer/utils"
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
)

// networkTestDialog is a network test pop-up box
type networkTestDialog struct {
box *gtk.Box
label *gtk.Label
confirmButton *gtk.Widget
dialog *gtk.Dialog
pbar *gtk.ProgressBar
}

// createNetworkTestDialog creates a pop-up window for the network test
func createNetworkTestDialog() (*networkTestDialog, error) {
var err error
netDialog := &networkTestDialog{}
progress.Set(netDialog)

// Create box
netDialog.box, err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
netDialog.box.SetHAlign(gtk.ALIGN_FILL)
netDialog.box.SetMarginBottom(common.TopBottomMargin)
if err != nil {
log.Error("Error creating box", err)
return nil, err
}

// Create progress bar
netDialog.pbar, err = gtk.ProgressBarNew()
if err != nil {
return nil, err
}
_, err = glib.IdleAdd(func() {
netDialog.pbar.SetFraction(0.0)
})
if err != nil {
return nil, err
}
netDialog.pbar.SetHAlign(gtk.ALIGN_FILL)
netDialog.pbar.SetMarginBottom(12)
netDialog.pbar.SetMarginTop(12)
netDialog.pbar.SetPulseStep(0.3)
netDialog.box.PackStart(netDialog.pbar, false, false, 0)

// Create label
text := utils.Locale.Get("Testing connectivity")
netDialog.label, err = common.SetLabel(text, "label-warning", 0.0)
if err != nil {
log.Error("Error creating label", err)
return nil, err
}
netDialog.label.SetUseMarkup(true)
netDialog.label.SetHAlign(gtk.ALIGN_START)
netDialog.box.PackStart(netDialog.label, false, true, 0)

// Create dialog
netDialog.dialog, err = common.CreateDialogOneButton(netDialog.box, text, utils.Locale.Get("OK"), "button-confirm")
if err != nil {
log.Error("Error creating dialog", err)
return nil, err
}
netDialog.dialog.SetDeletable(false)

// Configure confirm button
netDialog.confirmButton, err = netDialog.dialog.GetWidgetForResponse(gtk.RESPONSE_OK)
if err != nil {
log.Error("Error getting confirm button", err)
return nil, err
}
_, err = netDialog.confirmButton.Connect("clicked", func() {
netDialog.dialog.Destroy()
})
if err != nil {
return nil, err
}
netDialog.confirmButton.SetSensitive(false)

netDialog.dialog.ShowAll()

return netDialog, nil
}

// RunNetworkTest creates pop-up window that runs a network check
func RunNetworkTest(md *model.SystemInstall) error {
netDialog, err := createNetworkTestDialog()
if err != nil {
return err
}

go func() {
if err = controller.ConfigureNetwork(md); err != nil {
// Network check failed
log.Error("Network Testing: %s", err)
}

// Automatically close the dialog on success
if controller.NetworkPassing {
time.Sleep(time.Second)
_, err = glib.IdleAdd(func() {
netDialog.dialog.Destroy()
})
if err != nil {
log.ErrorError(err)
netDialog.dialog.Destroy()
}
}
}()
netDialog.dialog.Run()

return nil
}

// Desc will push a description box into the view for later marking
func (netDialog *networkTestDialog) Desc(desc string) {
_, err := glib.IdleAdd(func() {
netDialog.label.SetText(desc)
netDialog.label.ShowAll()
})
if err != nil {
log.ErrorError(err)
return
}
}

// Failure handles failure to install
func (netDialog *networkTestDialog) Failure() {
_, err := glib.IdleAdd(func() {
netDialog.label.SetText(utils.Locale.Get("Network check failed."))
netDialog.confirmButton.SetSensitive(true)
netDialog.label.ShowAll()
})
if err != nil {
log.ErrorError(err)
return
}
}

// Success notes the install was successful
func (netDialog *networkTestDialog) Success() {
_, err := glib.IdleAdd(func() {
netDialog.label.SetText(utils.Locale.Get("Success"))
netDialog.confirmButton.SetSensitive(true)
netDialog.label.ShowAll()
})
if err != nil {
log.ErrorError(err)
return
}
}

// LoopWaitDuration will return the duration for step-waits
func (netDialog *networkTestDialog) LoopWaitDuration() time.Duration {
return common.LoopWaitDuration
}

// Partial handles an actual progress update
func (netDialog *networkTestDialog) Partial(total int, step int) {
return
}

// Step will step the progressbar in indeterminate mode
func (netDialog *networkTestDialog) Step() {
_, err := glib.IdleAdd(func() {
netDialog.pbar.Pulse()
})
if err != nil {
log.ErrorError(err)
return
}
}
3 changes: 3 additions & 0 deletions gui/pages/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const (
// PageIDBundle is the bundle page key
PageIDBundle = iota

// PageIDNetwork is the network check page key
PageIDNetwork = iota

// PageIDTelemetry is the telemetry page key
PageIDTelemetry = iota

Expand Down
66 changes: 66 additions & 0 deletions gui/pages/network_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package pages

import (
"github.com/clearlinux/clr-installer/model"
"github.com/clearlinux/clr-installer/utils"
"github.com/gotk3/gotk3/gtk"
)

// NetworkCheckPage is an empty page that creates a menu entry that triggers a network check.
type NetworkCheckPage struct {
}

// NewNetworkPage only exists to add a menu entry that creates a network test pop-up.
func NewNetworkPage(ctlr Controller, model *model.SystemInstall) (Page, error) {
return &NetworkCheckPage{}, nil
}

// ResetChanges will reset this page to match the model
func (page *NetworkCheckPage) ResetChanges() {
return
}

// IsDone checks if all the steps are completed
func (page *NetworkCheckPage) IsDone() bool {
return true
}

// IsRequired will return false as we have default values
func (page *NetworkCheckPage) IsRequired() bool {
return false
}

// GetID returns the ID for this page
func (page *NetworkCheckPage) GetID() int {
return PageIDNetwork
}

// GetIcon returns the icon for this page
func (page *NetworkCheckPage) GetIcon() string {
return "network-wireless-symbolic"
}

// GetRootWidget returns the root embeddable widget for this page
func (page *NetworkCheckPage) GetRootWidget() gtk.IWidget {
return nil
}

// GetSummary will return the summary for this page
func (page *NetworkCheckPage) GetSummary() string {
return utils.Locale.Get("Test Network Settings")
}

// GetTitle will return the title for this page
func (page *NetworkCheckPage) GetTitle() string {
return page.GetSummary()
}

// StoreChanges will store this pages changes into the model
func (page *NetworkCheckPage) StoreChanges() {
return
}

// GetConfiguredValue returns our current config
func (page *NetworkCheckPage) GetConfiguredValue() string {
return utils.Locale.Get("Test connectivity")
}
9 changes: 8 additions & 1 deletion gui/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ func (window *Window) createMenuPages() (*Window, error) {
pages.NewHostnamePage,
pages.NewConfigKernelPage,
pages.NewSwupdConfigPage,
pages.NewNetworkPage,

// always last
pages.NewInstallPage,
Expand Down Expand Up @@ -579,7 +580,6 @@ func (window *Window) closePage() {

// ActivatePage customizes common widgets and displays the page
func (window *Window) ActivatePage(page pages.Page) {
window.menu.currentPage = page
id := page.GetID()

// Customize common widgets based on the page being loaded
Expand Down Expand Up @@ -616,6 +616,12 @@ func (window *Window) ActivatePage(page pages.Page) {
window.buttons.confirm.GrabDefault()
window.buttons.confirm.SetLabel(utils.Locale.Get("YES"))
window.buttons.cancel.SetLabel(utils.Locale.Get("NO"))
case pages.PageIDNetwork:
// Launches network check pop-up without changing page
if err := RunNetworkTest(window.model); err != nil {
log.Warning("Error running network test: ", err)
}
return
default:
window.menu.switcher.Hide()
window.banner.Hide()
Expand All @@ -624,6 +630,7 @@ func (window *Window) ActivatePage(page pages.Page) {
window.buttons.confirm.SetLabel(utils.Locale.Get("CONFIRM"))
window.buttons.cancel.SetLabel(utils.Locale.Get("CANCEL"))
}
window.menu.currentPage = page
page.ResetChanges() // Allow page to take control now
window.rootStack.SetVisibleChild(window.pages[id]) // Set the root stack to show the new page
}
Expand Down
6 changes: 6 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ msgstr "Running %s hooks"
msgid "Testing connectivity"
msgstr "Testing connectivity"

msgid "Test connectivity"
msgstr "Test connectivity"

msgid "Test Network Settings"
msgstr "Test Network Settings"

#, c-format
msgid "Writing partition table to: %s"
msgstr "Writing partition table to: %s"
Expand Down
6 changes: 6 additions & 0 deletions locale/es_MX/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ msgstr "Ejecutando enlaces de %s"
msgid "Testing connectivity"
msgstr "Probando la conectividad"

msgid "Test connectivity"
msgstr "Conectividad de prueba"

msgid "Test Network Settings"
msgstr "Probar la configuración de red"

#, c-format
msgid "Writing partition table to: %s"
msgstr "Escribiendo la tabla de particiones en %s"
Expand Down
6 changes: 6 additions & 0 deletions locale/zh_CN/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ msgstr "正在运行 %s 钩子"
msgid "Testing connectivity"
msgstr "正在测试连接性"

msgid "Test connectivity"
msgstr "测试连接"

msgid "Test Network Settings"
msgstr "测试网络设置"

#, c-format
msgid "Writing partition table to: %s"
msgstr "正在将分区表写入:%s"
Expand Down

0 comments on commit 2b29ce8

Please sign in to comment.