func (u *gtkUI) editProxy(proxy string, w *gtk.Dialog, onSave func(net.Proxy), onCancel func()) { prox := net.ParseProxy(proxy) b := builderForDefinition("EditProxy") dialog := getObjIgnoringErrors(b, "EditProxy").(*gtk.Dialog) scheme := getObjIgnoringErrors(b, "protocol-type").(*gtk.ComboBoxText) user := getObjIgnoringErrors(b, "user").(*gtk.Entry) pass := getObjIgnoringErrors(b, "password").(*gtk.Entry) server := getObjIgnoringErrors(b, "server").(*gtk.Entry) port := getObjIgnoringErrors(b, "port").(*gtk.Entry) net.GetProxyTypeNames(func(name string) { scheme.AppendText(name) }) scheme.SetActive(net.FindProxyTypeFor(prox.Scheme)) if prox.User != nil { user.SetText(*prox.User) } if prox.Pass != nil { pass.SetText(*prox.Pass) } server.SetText(prox.Host) if prox.Port != nil { port.SetText(*prox.Port) } b.ConnectSignals(map[string]interface{}{ "on_save_signal": func() { userTxt, _ := user.GetText() passTxt, _ := pass.GetText() servTxt, _ := server.GetText() portTxt, _ := port.GetText() prox.Scheme = net.GetProxyTypeFor(scheme.GetActiveText()) prox.User = orNil(userTxt) prox.Pass = orNil(passTxt) prox.Host = servTxt prox.Port = orNil(portTxt) go onSave(prox) dialog.Destroy() }, "on_cancel_signal": func() { go onCancel() dialog.Destroy() }, }) dialog.SetTransientFor(w) dialog.ShowAll() }
func (u *gtkUI) editProxy(proxy string, w gtki.Dialog, onSave func(net.Proxy), onCancel func()) { prox := net.ParseProxy(proxy) b := newBuilder("EditProxy") dialog := b.getObj("EditProxy").(gtki.Dialog) scheme := b.getObj("protocol-type").(gtki.ComboBoxText) user := b.getObj("user").(gtki.Entry) pass := b.getObj("password").(gtki.Entry) server := b.getObj("server").(gtki.Entry) serverLabel := b.getObj("serverLabel").(gtki.Label) port := b.getObj("port").(gtki.Entry) portLabel := b.getObj("portLabel").(gtki.Label) path := b.getObj("path").(gtki.Entry) pathLabel := b.getObj("pathLabel").(gtki.Label) getProxyTypeNames(func(name string) { scheme.AppendText(name) }) scheme.SetActive(findProxyTypeFor(prox.Scheme)) if prox.User != nil { user.SetText(*prox.User) } if prox.Pass != nil { pass.SetText(*prox.Pass) } if prox.Host != nil { server.SetText(*prox.Host) } if prox.Port != nil { port.SetText(*prox.Port) } if prox.Path != nil { path.SetText(*prox.Path) } isUD := getProxyTypeFor(scheme.GetActiveText()) == "socks5+unix" updateSensitivity(isUD, path, pathLabel) updateSensitivity(!isUD, server, serverLabel, port, portLabel) b.ConnectSignals(map[string]interface{}{ "on_protocol_type_changed": func() { isUD := getProxyTypeFor(scheme.GetActiveText()) == "socks5+unix" updateSensitivity(isUD, path, pathLabel) updateSensitivity(!isUD, server, serverLabel, port, portLabel) }, "on_save_signal": func() { userTxt, _ := user.GetText() passTxt, _ := pass.GetText() servTxt, _ := server.GetText() portTxt, _ := port.GetText() pathTxt, _ := path.GetText() prox.Scheme = getProxyTypeFor(scheme.GetActiveText()) isUD := prox.Scheme == "socks5+unix" prox.User = orNil(userTxt) prox.Pass = orNil(passTxt) if isUD { prox.Path = orNil(pathTxt) } else { prox.Host = orNil(servTxt) prox.Port = orNil(portTxt) } go onSave(prox) dialog.Destroy() }, "on_cancel_signal": func() { go onCancel() dialog.Destroy() }, }) dialog.SetTransientFor(w) dialog.ShowAll() }
func (u *gtkUI) accountDialog(s access.Session, account *config.Account, saveFunction func()) { data := getBuilderAndAccountDialogDetails() data.otherSettings.SetActive(u.config.AdvancedOptions) data.acc.SetText(account.Account) data.server.SetText(account.Server) if account.Port == 0 { account.Port = 5222 } data.port.SetText(strconv.Itoa(account.Port)) for _, px := range account.Proxies { iter := data.proxies.Append() data.proxies.SetValue(iter, 0, net.ParseProxy(px).ForPresentation()) data.proxies.SetValue(iter, 1, px) } data.fingerprintsMessage.SetSelectable(true) m := i18n.Local("Your fingerprints for %s:\n%s") message := fmt.Sprintf(m, account.Account, formattedFingerprintsFor(s)) data.fingerprintsMessage.SetText(message) p2, _ := data.notebook.GetNthPage(1) p3, _ := data.notebook.GetNthPage(2) p4, _ := data.notebook.GetNthPage(3) failures := 0 editProxy := func(iter *gtk.TreeIter, onCancel func()) { val, _ := data.proxies.GetValue(iter, 1) realProxyData, _ := val.GetString() u.editProxy(realProxyData, data.dialog, func(p net.Proxy) { data.proxies.SetValue(iter, 0, p.ForPresentation()) data.proxies.SetValue(iter, 1, p.ForProcessing()) }, onCancel) } data.builder.ConnectSignals(map[string]interface{}{ "on_toggle_other_settings": func() { otherSettings := data.otherSettings.GetActive() u.setShowAdvancedSettings(otherSettings) data.notebook.SetShowTabs(otherSettings) if otherSettings { p2.Show() p3.Show() p4.Show() } else { p2.Hide() p3.Hide() p4.Hide() } }, "on_save_signal": func() { accTxt, _ := data.acc.GetText() passTxt, _ := data.pass.GetText() servTxt, _ := data.server.GetText() portTxt, _ := data.port.GetText() isJid, err := verifyXmppAddress(accTxt) if !isJid && failures > 0 { failures++ return } if !isJid { notification := buildBadUsernameNotification(err) data.notificationArea.Add(notification) notification.ShowAll() failures++ log.Printf(err) return } account.Account = accTxt account.Server = servTxt if passTxt != "" { account.Password = passTxt } convertedPort, e := strconv.Atoi(portTxt) if len(strings.TrimSpace(portTxt)) == 0 || e != nil { convertedPort = 5222 } account.Port = convertedPort newProxies := []string{} iter, ok := data.proxies.GetIterFirst() for ok { vv, _ := data.proxies.GetValue(iter, 1) newProxy, _ := vv.GetString() newProxies = append(newProxies, newProxy) ok = data.proxies.IterNext(iter) } account.Proxies = newProxies go saveFunction() data.dialog.Destroy() }, "on_edit_proxy_signal": func() { ts, _ := data.proxiesView.GetSelection() var iter gtk.TreeIter if ts.GetSelected(nil, &iter) { editProxy(&iter, func() {}) } }, "on_remove_proxy_signal": func() { ts, _ := data.proxiesView.GetSelection() var iter gtk.TreeIter if ts.GetSelected(nil, &iter) { data.proxies.Remove(&iter) } }, "on_add_proxy_signal": func() { iter := data.proxies.Append() data.proxies.SetValue(iter, 0, "tor-auto://") data.proxies.SetValue(iter, 1, "tor-auto://") ts, _ := data.proxiesView.GetSelection() ts.SelectIter(iter) editProxy(iter, func() { data.proxies.Remove(iter) }) }, "on_edit_activate_proxy_signal": func(_ *gtk.TreeView, path *gtk.TreePath) { iter, err := data.proxies.GetIter(path) if err == nil { editProxy(iter, func() {}) } }, "on_cancel_signal": func() { u.buildAccountsMenu() data.dialog.Destroy() }, "on_import_key_signal": func() { u.importKeysForDialog(account, data.dialog) }, "on_import_fpr_signal": func() { u.importFingerprintsForDialog(account, data.dialog) }, "on_export_key_signal": func() { u.exportKeysForDialog(account, data.dialog) }, "on_export_fpr_signal": func() { u.exportFingerprintsForDialog(account, data.dialog) }, }) data.dialog.SetTransientFor(u.window) data.dialog.ShowAll() data.notebook.SetCurrentPage(0) data.notebook.SetShowTabs(u.config.AdvancedOptions) if !u.config.AdvancedOptions { p2.Hide() p3.Hide() p4.Hide() } }