Skip to content

Commit

Permalink
GUI Net: Add user bundles net-test Note
Browse files Browse the repository at this point in the history
Fixes Issue: clearlinux#635

The user used to mistakenly click on items in the additonal bundles
page having to wait long duration unecessarily if the network did not work.
This provides the user with a Note saying that selecting an additional
bundle requires a working internet connection

Signed-off-by: Karthik Prabhu Vinod <[email protected]>
  • Loading branch information
karthikprabhuvinod committed Feb 11, 2020
1 parent f65cd66 commit c964c76
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 56 deletions.
29 changes: 23 additions & 6 deletions gui/network_dialog_check.go → gui/network/network.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package gui
// Copyright © 2020 Intel Corporation
//
// SPDX-License-Identifier: GPL-3.0-only

package network

import (
"strings"
Expand All @@ -24,6 +28,14 @@ type networkTestDialog struct {
pbar *gtk.ProgressBar
}

type NetTestReturnCode int

const (
NetTestSuccess NetTestReturnCode = 0
NetTestFailure NetTestReturnCode = 1
NetTestErr NetTestReturnCode = 2
)

// createNetworkTestDialog creates a pop-up window for the network test
func createNetworkTestDialog() (*networkTestDialog, error) {
var err error
Expand All @@ -32,12 +44,12 @@ func createNetworkTestDialog() (*networkTestDialog, error) {

// 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
}
netDialog.box.SetHAlign(gtk.ALIGN_FILL)
netDialog.box.SetMarginBottom(common.TopBottomMargin)

// Create progress bar
netDialog.pbar, err = gtk.ProgressBarNew()
Expand Down Expand Up @@ -95,10 +107,10 @@ func createNetworkTestDialog() (*networkTestDialog, error) {
}

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

go func() {
Expand All @@ -121,7 +133,12 @@ func RunNetworkTest(md *model.SystemInstall) error {
}()
netDialog.dialog.Run()

return nil
if controller.NetworkPassing {
return NetTestSuccess, nil
}

return NetTestFailure, nil

}

// Desc will push a description box into the view for later marking
Expand Down
133 changes: 120 additions & 13 deletions gui/pages/bundle.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019 Intel Corporation
// Copyright © 2020 Intel Corporation
//
// SPDX-License-Identifier: GPL-3.0-only

Expand All @@ -14,6 +14,8 @@ import (
"github.com/gotk3/gotk3/gtk"

"github.com/clearlinux/clr-installer/controller"
"github.com/clearlinux/clr-installer/gui/common"
"github.com/clearlinux/clr-installer/gui/network"
"github.com/clearlinux/clr-installer/model"
"github.com/clearlinux/clr-installer/swupd"
"github.com/clearlinux/clr-installer/utils"
Expand All @@ -35,14 +37,23 @@ var (

// Bundle is a simple page to help with Bundle settings
type Bundle struct {
model *model.SystemInstall
controller Controller
bundles []*swupd.Bundle // Known bundles
box *gtk.Box // Main layout
checks *gtk.FlowBox // Where to store checks
scroll *gtk.ScrolledWindow // Scroll the checks
model *model.SystemInstall
windowController Controller
bundles []*swupd.Bundle // Known bundles
box *gtk.Box // Main layout
checks *gtk.FlowBox // Where to store checks
scroll *gtk.ScrolledWindow // Scroll the checks

selections []*gtk.CheckButton
clearPage bool
}

type decisionDialog struct {
box *gtk.Box
label *gtk.Label
dialog *gtk.Dialog
confirmButton *gtk.Widget
cancelButton *gtk.Widget
}

// LookupBundleIcon attempts to find the icon for the given bundle.
Expand Down Expand Up @@ -114,12 +125,85 @@ func createBundleWidget(bundle *swupd.Bundle) (*gtk.CheckButton, error) {
return check, nil
}

func createDecisionBox(model *model.SystemInstall, bundle *Bundle) (*decisionDialog, error) {
var err error
decisionMaker := &decisionDialog{}

decisionMaker.box, err = gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
if err != nil {
return nil, err
}
decisionMaker.box.SetHAlign(gtk.ALIGN_FILL)
decisionMaker.box.SetMarginBottom(common.TopBottomMargin)

text := utils.Locale.Get("This requires a working network connection.\nProceed with a network test?")
decisionMaker.label, err = common.SetLabel(text, "label-warning", 0.0)

if err != nil {
return nil, err
}
decisionMaker.label.SetUseMarkup(true)
decisionMaker.label.SetHAlign(gtk.ALIGN_START)
decisionMaker.box.PackStart(decisionMaker.label, false, true, 0)

decisionMaker.dialog, err = common.CreateDialogOkCancel(decisionMaker.box,
utils.Locale.Get("Network Required"), utils.Locale.Get("CONFIRM"), utils.Locale.Get("CANCEL"))

if err != nil {
return nil, err
}

decisionMaker.dialog.SetDeletable(false)

// Configure confirm button
decisionMaker.confirmButton, err = decisionMaker.dialog.GetWidgetForResponse(gtk.RESPONSE_OK)
if err != nil {
return nil, err
}

// Configure cancel button
decisionMaker.cancelButton, err = decisionMaker.dialog.GetWidgetForResponse(gtk.RESPONSE_CANCEL)
if err != nil {
return nil, err
}

_, err = decisionMaker.confirmButton.Connect("clicked", func() {
if ret, _ := network.RunNetworkTest(model); ret != network.NetTestSuccess {
bundle.clearPage = true
bundle.ResetChanges()
decisionMaker.dialog.Destroy()
return
}
bundle.clearPage = false
bundle.windowController.SetButtonState(ButtonConfirm, controller.NetworkPassing)
decisionMaker.dialog.Destroy()
})
if err != nil {
return nil, err
}

_, err = decisionMaker.cancelButton.Connect("clicked", func() {
bundle.clearPage = true
decisionMaker.dialog.Destroy()
bundle.ResetChanges()
})
if err != nil {
return nil, err
}

decisionMaker.confirmButton.SetSensitive(true)
decisionMaker.cancelButton.SetSensitive(true)
decisionMaker.dialog.ShowAll()

return decisionMaker, nil
}

// NewBundlePage returns a new BundlePage
func NewBundlePage(controller Controller, model *model.SystemInstall) (Page, error) {
func NewBundlePage(windowController Controller, model *model.SystemInstall) (Page, error) {
var err error
bundle := &Bundle{
controller: controller,
model: model,
windowController: windowController,
model: model,
}

// Load our bundles
Expand All @@ -140,7 +224,7 @@ func NewBundlePage(controller Controller, model *model.SystemInstall) (Page, err
if err != nil {
return nil, err
}
bundle.checks.SetSelectionMode(gtk.SELECTION_NONE)
bundle.checks.SetSelectionMode(gtk.SELECTION_MULTIPLE)
bundle.scroll, err = gtk.ScrolledWindowNew(nil, nil)
if err != nil {
return nil, err
Expand All @@ -160,6 +244,30 @@ func NewBundlePage(controller Controller, model *model.SystemInstall) (Page, err
bundle.selections = append(bundle.selections, wid)
}

for i := range bundle.selections {
if !controller.NetworkPassing {
if _, err := bundle.selections[i].Connect("toggled", func() {
if !controller.NetworkPassing && !bundle.clearPage {
// we dont want to fire any checkbox signals
// when we want to clear the page. if encounter
// clearPage set to true, we set to
// false so that it fire nexttime
// onwards
_, err := createDecisionBox(model, bundle)
if err != nil {
return
}
}

if !controller.NetworkPassing && bundle.clearPage {
bundle.clearPage = false
}
}); err != nil {
return nil, err
}
}
}

return bundle, nil
}

Expand Down Expand Up @@ -216,9 +324,8 @@ func (bundle *Bundle) ResetChanges() {
// Match selection to what's in the model
for n, b := range bundle.bundles {
bundle.selections[n].SetActive(bundle.model.ContainsUserBundle(b.Name))
bundle.selections[n].SetSensitive(controller.NetworkPassing)
}
bundle.controller.SetButtonState(ButtonConfirm, controller.NetworkPassing)
bundle.windowController.SetButtonState(ButtonConfirm, controller.NetworkPassing)
}

// GetConfiguredValue returns our current config
Expand Down
42 changes: 5 additions & 37 deletions gui/window.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019 Intel Corporation
// Copyright © 2020 Intel Corporation
//
// SPDX-License-Identifier: GPL-3.0-only

Expand All @@ -15,6 +15,7 @@ import (
"github.com/clearlinux/clr-installer/args"
"github.com/clearlinux/clr-installer/controller"
"github.com/clearlinux/clr-installer/gui/common"
"github.com/clearlinux/clr-installer/gui/network"
"github.com/clearlinux/clr-installer/gui/pages"
"github.com/clearlinux/clr-installer/log"
"github.com/clearlinux/clr-installer/model"
Expand Down Expand Up @@ -84,8 +85,6 @@ type Window struct {
cancel *gtk.Button // Cancel changes
}

warningLabel *gtk.Label // Warning label in footer

didInit bool // Whether initialized the view animation
pages map[int]gtk.IWidget // Mapping to each root page
scanInfo pages.ScanInfo // Information related to scanning the media
Expand Down Expand Up @@ -553,14 +552,6 @@ func (window *Window) UpdateFooter() error {
return err
}

// Warning label
warningTxt := utils.Locale.Get("Network check failed.")
if window.warningLabel, err = common.SetLabel(warningTxt, "label-warning", 0.0); err != nil {
return err
}
window.warningLabel.SetYAlign(0.25)
window.warningLabel.Hide()

// Create box for primary buttons
if window.buttons.boxPrimary, err = gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0); err != nil {
return err
Expand All @@ -575,7 +566,6 @@ func (window *Window) UpdateFooter() error {
}
window.buttons.boxSecondary.PackEnd(window.buttons.confirm, false, false, 4)
window.buttons.boxSecondary.PackEnd(window.buttons.cancel, false, false, 4)
window.buttons.boxSecondary.PackStart(window.warningLabel, false, false, 15)

// Add the boxes
window.buttons.stack.AddNamed(window.buttons.boxPrimary, "primary")
Expand Down Expand Up @@ -629,11 +619,6 @@ func (window *Window) closePage() {
func (window *Window) ActivatePage(page pages.Page) {
id := page.GetID()

// Hide the warning label on page transitions
if window.warningLabel != nil {
window.warningLabel.Hide()
}

// Customize common widgets based on the page being loaded
switch id {
case pages.PageIDWelcome:
Expand Down Expand Up @@ -665,7 +650,7 @@ func (window *Window) ActivatePage(page pages.Page) {
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 {
if _, err := network.RunNetworkTest(window.model); err != nil {
log.Warning("Error running network test: ", err)
}
return
Expand All @@ -676,24 +661,7 @@ func (window *Window) ActivatePage(page pages.Page) {
window.buttons.confirm.SetSensitive(false)
window.buttons.confirm.SetLabel(utils.Locale.Get("CONFIRM"))
window.buttons.cancel.SetLabel(utils.Locale.Get("CANCEL"))

if !controller.NetworkPassing {
// Launches network check pop-up on bundle page
_, err := glib.IdleAdd(func() {
if err := RunNetworkTest(window.model); err != nil {
log.Warning("Error running network test: ", err)
}
page.ResetChanges()

// Show no network warning
if !controller.NetworkPassing {
window.warningLabel.Show()
}
})
if err != nil {
log.ErrorError(err)
}
}
page.ResetChanges()
default:
window.menu.switcher.Hide()
window.banner.Hide()
Expand Down Expand Up @@ -879,7 +847,7 @@ func (window *Window) confirmInstall() {

// Valid network is required to install without offline content or additional bundles
if (!swupd.IsOfflineContent() || len(window.model.UserBundles) != 0) && !controller.NetworkPassing {
if err := RunNetworkTest(window.model); err != nil {
if ret, err := network.RunNetworkTest(window.model); ret == network.NetTestErr {
log.Warning("Error running network test: ", err)
return
}
Expand Down
7 changes: 7 additions & 0 deletions locale/en_US/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,10 @@ msgstr "Encrypted"

msgid "Allow installation over insecure connections (http:https://)"
msgstr "Allow installation over insecure connections (http:https://)"

#, c-format
msgid "This requires a working network connection.\nProceed with a network test?"
msgstr "This requires a working network connection.\nProceed with a network test?"

msgid "Network Required"
msgstr "Network Required"
7 changes: 7 additions & 0 deletions locale/es_MX/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -791,5 +791,12 @@ msgstr "Utilice la partición existente."
msgid "Encrypted"
msgstr "Encriptado"

#, c-format
msgid "Allow installation over insecure connections (http:https://)"
msgstr "Permitir la instalación a través de conexiones inseguras (http:https://)"

msgid "This requires a working network connection.\nProceed with a network test?"
msgstr "Esto requiere una conexión de red que funcione.\n¿Continuar con una prueba de red?"

msgid "Network Required"
msgstr "Red requerida"
7 changes: 7 additions & 0 deletions locale/zh_CN/LC_MESSAGES/clr-installer.po
Original file line number Diff line number Diff line change
Expand Up @@ -793,3 +793,10 @@ msgstr "加密"

msgid "Allow installation over insecure connections (http:https://)"
msgstr "允许在不安全的连接(http:https://)上安装"

#, c-format
msgid "This requires a working network connection.\nProceed with a network test?"
msgstr "这需要有效的网络连接\n进行网络测试"

msgid "Network Required"
msgstr "需要网络"

0 comments on commit c964c76

Please sign in to comment.