// AskLocationConfirm search the list of cities matching the provided name // and shows a dialog with the list of locations for the user to choose. // When validated, the config file is updated and ...(TODO: need reload, to check). // If no data is found, the user is sent back to the AskLocationText dialog with // the text he provided. // func (app *Applet) AskLocationConfirm(locstr string) { if locstr == "" { app.SetLocationCode("", "*AUTODETECT*") return } locations, e := weather.FindLocation(locstr) if app.Log().Err(e, "FindLocation") { app.ShowDialog("Find location: "+e.Error(), 10) return } if len(locations) == 0 { // Try again. app.AskLocationText(locstr) return } var ids []string for _, loc := range locations { ids = append(ids, loc.Name) } e = app.PopupDialog(cdtype.DialogData{ Message: app.Translate("Select your location:"), Widget: cdtype.DialogWidgetList{ Values: ids, }, Buttons: "ok;cancel", Callback: cdtype.DialogCallbackValidInt(func(id int) { app.SetLocationCode(locations[id].ID, locations[id].Name) }), }) app.Log().Err(e, "popup AskLocation") }
// DialogCategory prepares a dialog to ask the category assigned to next downloads. // func (m *Manager) DialogCategory(filterFormats FuncFilterFormats, callDialog FuncPopupDialog, callDL DownloadFunc, vid *Video) { ids := []string{"", "Go Game", "Info"} sel := 0 for k, v := range ids { if m.category == v { sel = k break } } e := callDialog(cdtype.DialogData{ Message: vid.Name + "\n\nSelect category:", Widget: cdtype.DialogWidgetList{ Values: ids, InitialValue: sel, }, Buttons: "ok;cancel", Callback: cdtype.DialogCallbackValidInt(func(id int) { if id < len(ids) { // Shouldn't be out of range, but just to be safe... m.category = ids[id] vid.Category = m.category m.DialogQuality(filterFormats, callDialog, callDL, vid) } }), }) m.log.Err(e, "popup") }
func (app *AppTest) ExampleAppIcon_popupDialogListFixed() { app.PopupDialog(cdtype.DialogData{ Message: "Please choose:", UseMarkup: true, Widget: cdtype.DialogWidgetList{ Values: []string{"entry 1", "entry two", "or more"}, InitialValue: int32(2), }, Buttons: "ok;cancel", Callback: cdtype.DialogCallbackValidInt(func(id int) { app.Log().Info("ID", id) // ... do something with your validated value ... }), }) }
// DialogQuality prepares a dialog to ask the desired quality and download. // func (m *Manager) DialogQuality(filterFormats FuncFilterFormats, callDialog FuncPopupDialog, callDL DownloadFunc, vid *Video) { if vid.Name == "" { var e error vid.Name, e = vid.filer.Title() if m.log.Err(e, "videodl: missing title") { return } } formats, e := vid.filer.Formats() if m.log.Err(e, "format") || len(formats) == 0 { return } // formats = append(formats, // Format{Res: QualityBestFound.String(), Code: "best"}, // Format{Res: QualityBestPossible.String()}, // ) // Reduce list of formats. formats = filterFormats(formats) var ids []string for _, form := range formats { size := "?" if form.Size > 0 { size = strconv.Itoa(form.Size) } ids = append(ids, size+" MB\t"+ form.Extension+"\t"+form.Resolution+"\t"+ form.AudioEncoding+"\t"+form.VideoEncoding, ) } ids = append(ids, "Category: "+m.category) if vid.Format != nil { if vid.Format.needDeleteFile == "" { vid.Format.needDeleteFile = vid.Extension } else { vid.Format.needDeleteFile = "" } ids = append(ids, "Delete current file: "+ternary.String(vid.Format.needDeleteFile != "", "Yes", "No")) } e = callDialog(cdtype.DialogData{ Message: vid.Name + "\n\nSelect quality:", // UseMarkup: true, Widget: cdtype.DialogWidgetList{ Values: ids, InitialValue: 0, }, Buttons: "ok;cancel", Callback: cdtype.DialogCallbackValidInt(func(id int) { switch { case id > len(formats)+1: m.log.NewErr("ID out of range", "videodl DialogQuality") case id == len(formats)+1: if vid.Format == nil { m.log.NewErr("select delete file but format missing", "videodl DialogQuality") } else { m.DialogQuality(filterFormats, callDialog, callDL, vid) } case id == len(formats): m.DialogCategory(filterFormats, callDialog, callDL, vid) default: callDL(vid, formats[id]) } }), }) m.log.Err(e, "popup") }