Skip to content

Commit

Permalink
Fixes for changes to gotk3 v0.6.0
Browse files Browse the repository at this point in the history
Several API changes from gotk3 v0.4.0 to v0.6.0
which was a required bump to support building under golang 1.16.x.

Signed-off-by: Mark D Horn <[email protected]>
  • Loading branch information
mdhorn committed Jul 13, 2021
1 parent 198742b commit bd38c8b
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 270 deletions.
5 changes: 1 addition & 4 deletions gui/contentview.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ func NewContentView(controller pages.Controller) (*ContentView, error) {
// Ensure navigation works properly
view.list.SetSelectionMode(gtk.SELECTION_SINGLE)
view.list.SetActivateOnSingleClick(true)
_, err = view.list.Connect("row-activated", view.onRowActivated)
if err != nil {
return nil, err
}
_ = view.list.Connect("row-activated", view.onRowActivated)
view.scroll.Add(view.list)

return view, nil
Expand Down
44 changes: 10 additions & 34 deletions gui/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ func createNetworkTestDialog() (*networkTestDialog, error) {
if err != nil {
return nil, err
}
_, err = glib.IdleAdd(func() {
_ = 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)
Expand All @@ -88,17 +85,16 @@ func createNetworkTestDialog() (*networkTestDialog, error) {
netDialog.dialog.SetDeletable(false)

// Configure confirm button
netDialog.confirmButton, err = netDialog.dialog.GetWidgetForResponse(gtk.RESPONSE_OK)
var buttonIWidget gtk.IWidget
buttonIWidget, 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.confirmButton = buttonIWidget.ToWidget()
_ = netDialog.confirmButton.Connect("clicked", func() {
netDialog.dialog.Destroy()
})
if err != nil {
return nil, err
}
netDialog.confirmButton.SetSensitive(false)

netDialog.dialog.ShowAll()
Expand All @@ -122,13 +118,9 @@ func RunNetworkTest(md *model.SystemInstall) (NetTestReturnCode, error) {
// Automatically close the dialog on success
if controller.NetworkPassing {
time.Sleep(time.Second)
_, err = glib.IdleAdd(func() {
_ = glib.IdleAdd(func() {
netDialog.dialog.Destroy()
})
if err != nil {
log.ErrorError(err)
netDialog.dialog.Destroy()
}
}
}()
netDialog.dialog.Run()
Expand All @@ -142,44 +134,32 @@ func RunNetworkTest(md *model.SystemInstall) (NetTestReturnCode, error) {

// Desc will push a description box into the view for later marking
func (netDialog *networkTestDialog) Desc(desc string) {
_, err := glib.IdleAdd(func() {
_ = glib.IdleAdd(func() {
// The target prefix is used by the massinstaller to separate target,
// offline, and ISO content installs. It is unnecessary for the GUI.
desc = strings.TrimPrefix(desc, swupd.TargetPrefix)

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() {
_ = 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() {
_ = 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
Expand All @@ -194,11 +174,7 @@ func (netDialog *networkTestDialog) Partial(total int, step int) {

// Step will step the progressbar in indeterminate mode
func (netDialog *networkTestDialog) Step() {
_, err := glib.IdleAdd(func() {
_ = glib.IdleAdd(func() {
netDialog.pbar.Pulse()
})
if err != nil {
log.ErrorError(err)
return
}
}
23 changes: 9 additions & 14 deletions gui/pages/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,21 @@ func createDecisionBox(model *model.SystemInstall, bundle *Bundle) (*decisionDia
decisionMaker.dialog.SetDeletable(false)

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

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

_, err = decisionMaker.confirmButton.Connect("clicked", func() {
_ = decisionMaker.confirmButton.Connect("clicked", func() {
if ret, _ := network.RunNetworkTest(model); ret != network.NetTestSuccess {
bundle.clearPage = true
bundle.ResetChanges()
Expand All @@ -178,18 +181,12 @@ func createDecisionBox(model *model.SystemInstall, bundle *Bundle) (*decisionDia
bundle.windowController.SetButtonState(ButtonConfirm, controller.NetworkPassing)
decisionMaker.dialog.Destroy()
})
if err != nil {
return nil, err
}

_, err = decisionMaker.cancelButton.Connect("clicked", func() {
_ = 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)
Expand Down Expand Up @@ -246,7 +243,7 @@ func NewBundlePage(windowController Controller, model *model.SystemInstall) (Pag

for i := range bundle.selections {
if !controller.NetworkPassing {
if _, err := bundle.selections[i].Connect("toggled", func() {
_ = 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
Expand All @@ -262,9 +259,7 @@ func NewBundlePage(windowController Controller, model *model.SystemInstall) (Pag
if !controller.NetworkPassing && bundle.clearPage {
bundle.clearPage = false
}
}); err != nil {
return nil, err
}
})
}
}

Expand Down
101 changes: 31 additions & 70 deletions gui/pages/disk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
sc.AddClass("label-radio")
}
safeBox.PackStart(disk.safeButton, false, false, 0)
if _, err := disk.safeButton.Connect("toggled", func() {
_ = disk.safeButton.Connect("toggled", func() {
// REfactor the TUI code to also return when not active
if !disk.safeButton.GetActive() {
return
Expand All @@ -183,9 +183,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
log.Warning("Problem populating possible disk selections")
}
}
}); err != nil {
return nil, err
}
})

safeDescription := utils.Locale.Get("Install on an unallocated disk or alongside existing partitions.")
safeLabel, err := gtk.LabelNew(safeDescription)
Expand Down Expand Up @@ -216,7 +214,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
sc.AddClass("label-radio-warning")
}
destructiveBox.PackStart(disk.destructiveButton, false, false, 0)
if _, err := disk.destructiveButton.Connect("toggled", func() {
_ = disk.destructiveButton.Connect("toggled", func() {
// REfactor the TUI code to also return when not active
if !disk.destructiveButton.GetActive() {
return
Expand All @@ -234,9 +232,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
log.Warning("Problem populating possible disk selections")
}
}
}); err != nil {
return nil, err
}
})

destructiveDescription := utils.Locale.Get("Erase all data on selected media and install Clear Linux* OS.")
destructiveLabel, err := gtk.LabelNew(destructiveDescription)
Expand All @@ -259,9 +255,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
return nil, err
}

if _, err := disk.chooserCombo.Connect("changed", disk.onChooserComboChanged); err != nil {
log.Warning("Error connecting to entry")
}
_ = disk.chooserCombo.Connect("changed", disk.onChooserComboChanged)

// Add the renderers to the ComboBox
mediaRenderer, _ := gtk.CellRendererPixbufNew()
Expand Down Expand Up @@ -325,9 +319,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
disk.optionsGrid.Attach(disk.encryptCheck, 0, 1, 1, 1)

// Generate signal on encryptCheck button click
if _, err := disk.encryptCheck.Connect("clicked", disk.onEncryptClick); err != nil {
return nil, err
}
_ = disk.encryptCheck.Connect("clicked", disk.onEncryptClick)

// Buttons
disk.rescanButton, err = setButton(utils.Locale.Get("RESCAN MEDIA"), "button-page")
Expand All @@ -336,9 +328,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
}
disk.rescanButton.SetTooltipText(utils.Locale.Get("Rescan for changes to hot swappable media."))

if _, err = disk.rescanButton.Connect("clicked", disk.onRescanClick); err != nil {
return nil, err
}
_ = disk.rescanButton.Connect("clicked", disk.onRescanClick)

rescanBox, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
if err != nil {
Expand Down Expand Up @@ -386,9 +376,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
reqs := []string{"CLR_BOOT:vfat", "CLR_SWAP:linux-swap", "CLR_ROOT:ext*|xfs|f2fs"}
disk.advancedButton.SetTooltipText(utils.Locale.Get("Minimum requirements: %s", strings.Join(reqs, ", ")))
advancedBox.PackStart(disk.advancedButton, false, false, 0)
if _, err := disk.advancedButton.Connect("toggled", disk.advancedButtonToggled); err != nil {
return nil, err
}
_ = disk.advancedButton.Connect("toggled", disk.advancedButtonToggled)

advancedDescription := utils.Locale.Get("Use partitioning tool to configure and select media via partition names.")
advancedLabel, err := gtk.LabelNew(advancedDescription)
Expand All @@ -414,9 +402,7 @@ func NewDiskConfigPage(controller Controller, model *model.SystemInstall) (Page,
utils.Locale.Get(
"Launch the external partitioning tool to name the partitions to be used for the installation."))

if _, err = disk.partitionButton.Connect("clicked", disk.runDiskPartitionTool); err != nil {
return nil, err
}
_ = disk.partitionButton.Connect("clicked", disk.runDiskPartitionTool)

partitionBox, err := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
if err != nil {
Expand Down Expand Up @@ -659,36 +645,14 @@ func (disk *DiskConfig) createPassphraseDialog() {
disk.passphrase.SetVisibility(false)
disk.passphraseConfirm.SetVisibility(false)

if _, err := disk.passphrase.Connect("changed", disk.onPassphraseChange); err != nil {
log.Warning("Error connecting to entry")
return
}

if _, err := disk.passphrase.Connect("activate", disk.onPassphraseActive); err != nil {
log.Warning("Error connecting to entry")
return
}

if _, err := disk.passphrase.Connect("key-press-event", disk.onPassphraseKeyPress); err != nil {
log.Warning("Error connecting to entry")
return
}
_ = disk.passphrase.Connect("changed", disk.onPassphraseChange)
_ = disk.passphrase.Connect("activate", disk.onPassphraseActive)
_ = disk.passphrase.Connect("key-press-event", disk.onPassphraseKeyPress)

// Generate signal on PassphraseConfirm change
if _, err := disk.passphraseConfirm.Connect("changed", disk.onPassphraseChange); err != nil {
log.Warning("Error connecting to entry")
return
}

if _, err := disk.passphraseConfirm.Connect("activate", disk.onPassphraseActive); err != nil {
log.Warning("Error connecting to entry")
return
}

if _, err := disk.passphraseConfirm.Connect("key-press-event", disk.onPassphraseKeyPress); err != nil {
log.Warning("Error connecting to entry")
return
}
_ = disk.passphraseConfirm.Connect("changed", disk.onPassphraseChange)
_ = disk.passphraseConfirm.Connect("activate", disk.onPassphraseActive)
_ = disk.passphraseConfirm.Connect("key-press-event", disk.onPassphraseKeyPress)

disk.passphraseDialog, err = common.CreateDialog(contentBox, title)
if err != nil {
Expand All @@ -699,10 +663,7 @@ func (disk *DiskConfig) createPassphraseDialog() {
disk.passphraseDialog.AddActionWidget(disk.passphraseCancel, gtk.RESPONSE_CANCEL)
disk.passphraseDialog.AddActionWidget(disk.passphraseOK, gtk.RESPONSE_OK)

_, err = disk.passphraseDialog.Connect("response", disk.dialogResponse)
if err != nil {
log.Warning("Error connecting to dialog")
}
_ = disk.passphraseDialog.Connect("response", disk.dialogResponse)
}

func (disk *DiskConfig) onPassphraseChange(entry *gtk.Entry) {
Expand Down Expand Up @@ -767,19 +728,23 @@ func (disk *DiskConfig) onChooserComboChanged(combo *gtk.ComboBox) {
}

if iter, iterErr := combo.GetActiveIter(); iter != nil && iterErr == nil {
if model, modelErr := combo.GetModel(); modelErr == nil && model.GetNColumns() >= 2 {
// Extract from model
if valueObj, getErr := model.GetValue(iter, 2); getErr == nil && valueObj != nil {
if _, fType, typeErr := valueObj.Type(); typeErr == nil && fType == glib.TYPE_STRING {
if name, nameErr := valueObj.GetString(); nameErr == nil {
disk.tempSelectedTarget = name
log.Debug("ComboBox entry selected is: %v", name)
} else {
log.Warning("Failed to get model string from value: %v", nameErr)
if modelITreeModel, modelErr := combo.GetModel(); modelErr == nil {
if model := modelITreeModel.ToTreeModel(); model != nil && model.GetNColumns() >= 2 {
// Extract from model
if valueObj, getErr := model.GetValue(iter, 2); getErr == nil && valueObj != nil {
if _, fType, typeErr := valueObj.Type(); typeErr == nil && fType == glib.TYPE_STRING {
if name, nameErr := valueObj.GetString(); nameErr == nil {
disk.tempSelectedTarget = name
log.Debug("ComboBox entry selected is: %v", name)
} else {
log.Warning("Failed to get model string from value: %v", nameErr)
}
}
} else {
log.Warning("Failed to get ComboBox model value from iter: %v", getErr)
}
} else {
log.Warning("Failed to get ComboBox model value from iter: %v", getErr)
log.Warning("Failed to get ComboBox model: %v", modelErr)
}
} else {
log.Warning("Failed to get ComboBox model: %v", modelErr)
Expand Down Expand Up @@ -1306,11 +1271,7 @@ func (disk *DiskConfig) runDiskPartitionTool() {
return
}

_, err = dialog.Connect("response", disk.warningDialogResponse)
if err != nil {
log.Error("Error connecting to dialog", err)
return
}
_ = dialog.Connect("response", disk.warningDialogResponse)

dialog.ShowAll()
dialog.Run()
Expand Down
4 changes: 1 addition & 3 deletions gui/pages/hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ func NewHostnamePage(controller Controller, model *model.SystemInstall) (Page, e
page.box.PackStart(page.warning, false, false, 10)

// Generate signal on Hostname entry change
if _, err := page.entry.Connect("changed", page.onChange); err != nil {
return nil, err
}
_ = page.entry.Connect("changed", page.onChange)

return page, nil
}
Expand Down
Loading

0 comments on commit bd38c8b

Please sign in to comment.