Пример #1
0
func (u *gtkUI) handlePeerEvent(ev events.Peer) {
	identityWarning := func(cv conversationView) {
		cv.updateSecurityWarning()
		cv.showIdentityVerificationWarning(u)
	}

	switch ev.Type {
	case events.IQReceived:
		//TODO
		log.Printf("received iq: %v\n", ev.From)
	case events.OTREnded:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, func(cv conversationView) {
			cv.displayNotification(i18n.Local("Private conversation lost."))
			cv.updateSecurityWarning()
		})

	case events.OTRNewKeys:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, func(cv conversationView) {
			cv.displayNotificationVerifiedOrNot(i18n.Local("Private conversation started."), i18n.Local("Unverified conversation started."))
			identityWarning(cv)
		})

	case events.OTRRenewedKeys:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, func(cv conversationView) {
			cv.displayNotificationVerifiedOrNot(i18n.Local("Successfully refreshed the private conversation."), i18n.Local("Successfully refreshed the unverified private conversation."))
			identityWarning(cv)
		})

	case events.SubscriptionRequest:
		confirmDialog := authorizePresenceSubscriptionDialog(&u.window.Window, ev.From)

		doInUIThread(func() {
			responseType := gtk.ResponseType(confirmDialog.Run())
			switch responseType {
			case gtk.RESPONSE_YES:
				ev.Session.HandleConfirmOrDeny(ev.From, true)
			case gtk.RESPONSE_NO:
				ev.Session.HandleConfirmOrDeny(ev.From, false)
			default:
				// We got a different response, such as a close of the window. In this case we want
				// to keep the subscription request open
			}
			confirmDialog.Destroy()
		})
	case events.Subscribed:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Subscribed to %s\n", jid, ev.From)
		u.rosterUpdated()
	case events.Unsubscribe:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Unsubscribed from %s\n", jid, ev.From)
		u.rosterUpdated()
	}
}
Пример #2
0
func verifyFingerprintDialog(account *account, uid string, parent *gtk.Window) gtk.ResponseType {
	accountConfig := account.session.GetConfig()
	//TODO: review whether it should create new conversations
	//Anyway, if it has created the conversation this function could return
	//(there is no theirFP in this case)
	conversation, _ := account.session.EnsureConversationWith(uid)
	ourFp := conversation.OurFingerprint()
	theirFp := conversation.TheirFingerprint()

	dialog := buildVerifyFingerprintDialog(accountConfig.Account, ourFp, uid, theirFp)

	defer dialog.Destroy()

	dialog.SetTransientFor(parent)
	dialog.ShowAll()

	responseType := gtk.ResponseType(dialog.Run())
	switch responseType {
	case gtk.RESPONSE_YES:
		account.executeCmd(client.AuthorizeFingerprintCmd{
			Account:     accountConfig,
			Peer:        uid,
			Fingerprint: theirFp,
		})
	}

	return responseType
}
Пример #3
0
func (dialog *EditDialog) Run(fts *models.FilesTreeStore) (job *EditorJob, ok bool) {
	ok = (gtk.ResponseType(dialog.Dialog().Run()) == gtk.RESPONSE_OK)
	if ok {
		job = dialog.CollectJob()
		//log.Println("editEdit terminated: OK", job)
	}
	dialog.Dialog().Destroy()
	return
}
Пример #4
0
Файл: ui.go Проект: 0x27/coyim
func (u *gtkUI) feedbackDialog() {
	builder := builderForDefinition("Feedback")

	obj, _ := builder.GetObject("dialog")
	dialog := obj.(*gtk.MessageDialog)
	dialog.SetTransientFor(u.window)

	response := dialog.Run()
	if gtk.ResponseType(response) == gtk.RESPONSE_CLOSE {
		dialog.Destroy()
	}
}
Пример #5
0
func (u *gtkUI) handlePeerEvent(ev session.PeerEvent) {
	switch ev.Type {
	case session.IQReceived:
		//TODO
		log.Printf("received iq: %v\n", ev.From)
	case session.OTREnded:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWin, ok := account.getConversationWith(peer)
		if !ok {
			log.Println("Could not find a conversation window")
			return
		}

		convWin.updateSecurityWarning()
	case session.OTRNewKeys:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWin, ok := account.getConversationWith(peer)
		if !ok {
			log.Println("Could not find a conversation window")
			return
		}

		convWin.updateSecurityWarning()
		convWin.showIdentityVerificationWarning(u)
	case session.SubscriptionRequest:
		confirmDialog := authorizePresenceSubscriptionDialog(u.window, ev.From)

		doInUIThread(func() {
			responseType := gtk.ResponseType(confirmDialog.Run())
			switch responseType {
			case gtk.RESPONSE_YES:
				ev.Session.HandleConfirmOrDeny(ev.From, true)
			case gtk.RESPONSE_NO:
				ev.Session.HandleConfirmOrDeny(ev.From, false)
			default:
				// We got a different response, such as a close of the window. In this case we want
				// to keep the subscription request open
			}
			confirmDialog.Destroy()
		})
	case session.Subscribed:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Subscribed to %s\n", jid, ev.From)
		u.rosterUpdated()
	case session.Unsubscribe:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Unsubscribed from %s\n", jid, ev.From)
		u.rosterUpdated()
	}
}
Пример #6
0
func (u *gtkUI) runImporter() {
	importSettings := make(map[applicationAndAccount]bool)
	allImports := importer.TryImportAll()

	builder := builderForDefinition("Importer")

	win, _ := builder.GetObject("importerWindow")
	w := win.(*gtk.Dialog)

	store, _ := builder.GetObject("importAccountsStore")
	s := store.(*gtk.ListStore)

	for appName, v := range allImports {
		for _, vv := range v {
			for _, a := range vv.Accounts {
				it := s.Append()
				s.SetValue(it, 0, appName)
				s.SetValue(it, 1, a.Account)
				s.SetValue(it, 2, false)
			}
		}
	}

	rend, _ := builder.GetObject("import-this-account-renderer")
	rr := rend.(*gtk.CellRendererToggle)

	rr.Connect("toggled", func(_ interface{}, path string) {
		iter, _ := s.GetIterFromString(path)
		current, _ := valAt(s, iter, 2).(bool)
		app, _ := valAt(s, iter, 0).(string)
		acc, _ := valAt(s, iter, 1).(string)

		importSettings[applicationAndAccount{app, acc}] = !current

		s.SetValue(iter, 2, !current)
	})

	w.Connect("response", func(_ interface{}, rid int) {
		if gtk.ResponseType(rid) == gtk.RESPONSE_OK {
			u.doActualImportOf(importSettings, allImports)
		}
		w.Destroy()
	})

	u.connectShortcutsChildWindow(&w.Window)
	doInUIThread(func() {
		w.SetTransientFor(u.window)
		w.ShowAll()
	})
}
Пример #7
0
func (u *gtkUI) wouldYouLikeToEncryptYourFile(k func(bool)) {
	dialogID := "AskToEncrypt"
	builder := builderForDefinition(dialogID)

	dialogOb, _ := builder.GetObject(dialogID)
	encryptDialog := dialogOb.(*gtk.MessageDialog)
	encryptDialog.SetDefaultResponse(gtk.RESPONSE_YES)
	encryptDialog.SetTransientFor(u.window)

	responseType := gtk.ResponseType(encryptDialog.Run())
	result := responseType == gtk.RESPONSE_YES
	encryptDialog.Destroy()
	k(result)
}
Пример #8
0
func (u *gtkUI) confirmAccountRemoval(acc *config.Account, removeAccountFunc func(*config.Account)) {
	builder := builderForDefinition("ConfirmAccountRemoval")

	obj, _ := builder.GetObject("RemoveAccount")
	dialog := obj.(*gtk.MessageDialog)
	dialog.SetTransientFor(u.window)
	dialog.SetProperty("text", acc.Account)

	response := dialog.Run()
	if gtk.ResponseType(response) == gtk.RESPONSE_YES {
		removeAccountFunc(acc)
	}

	dialog.Destroy()
}
Пример #9
0
// empty fTypes means all types enabled
func runFileDialog(fTypes []FileType, toSave bool, announce string) (filename string, ok bool) {
	var action gtk.FileChooserAction
	var buttonText string
	if toSave {
		action = gtk.FILE_CHOOSER_ACTION_SAVE
		buttonText = "Save"
	} else {
		action = gtk.FILE_CHOOSER_ACTION_OPEN
		buttonText = "Open"
	}
	dialog, err := gtk.FileChooserDialogNewWith2Buttons(
		announce,
		nil,
		action,
		"Cancel",
		gtk.RESPONSE_CANCEL,
		buttonText,
		gtk.RESPONSE_OK)
	if err != nil {
		log.Printf("runFileDialog error: %s\n", err)
		return
	}
	if len(fTypes) == 0 {
		for _, t := range allFileTypes {
			fTypes = append(fTypes, t)
		}
	}
	if len(fTypes) == 1 {
		log.Printf("runFileDialog: set current to %s.\n", dirMgr.Current(fTypes[0]))
		dialog.SetCurrentFolder(dirMgr.Current(fTypes[0]))
	} else {
		log.Printf("runFileDialog: set current to %s.\n", backend.XmlRoot())
		dialog.SetCurrentFolder(backend.XmlRoot())
	}
	for _, ft := range fTypes {
		ff, _ := gtk.FileFilterNew()
		ff.SetName(descriptionFileTypes[ft])
		ff.AddPattern(fmt.Sprintf("*.%s", string(ft)))
		dialog.AddFilter(ff)
	}
	response := dialog.Run()
	ok = (gtk.ResponseType(response) == gtk.RESPONSE_OK)
	filename = dialog.GetFilename()
	dialog.Destroy()
	return
}
Пример #10
0
func (u *gtkUI) importFingerprintsForDialog(account *config.Account, w *gtk.Dialog) {
	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Import fingerprints"),
		&w.Window,
		gtk.FILE_CHOOSER_ACTION_OPEN,
		i18n.Local("_Cancel"),
		gtk.RESPONSE_CANCEL,
		i18n.Local("_Import"),
		gtk.RESPONSE_OK,
	)

	if gtk.ResponseType(dialog.Run()) == gtk.RESPONSE_OK {
		num, ok := u.importFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints imported"), fmt.Sprintf(i18n.Local("%d fingerprint(s) were imported correctly."), num))
		} else {
			u.notify(i18n.Local("Failure importing fingerprints"), fmt.Sprintf(i18n.Local("Couldn't import any fingerprints from %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Пример #11
0
func (f *registrationForm) renderForm(title, instructions string, fields []interface{}) error {
	f.addFields(fields)

	builder := builderForDefinition("RegistrationForm")

	obj, _ := builder.GetObject("dialog")
	dialog := obj.(*gtk.Dialog)
	dialog.SetTitle(title)

	obj, _ = builder.GetObject("instructions")
	label := obj.(*gtk.Label)
	label.SetText(instructions)
	label.SetSelectable(true)

	obj, _ = builder.GetObject("grid")
	grid := obj.(*gtk.Grid)

	for i, field := range f.fields {
		grid.Attach(field.label, 0, i+1, 1, 1)
		grid.Attach(field.widget, 1, i+1, 1, 1)
	}
	grid.ShowAll()

	dialog.SetTransientFor(f.parent)

	wait := make(chan error)
	doInUIThread(func() {
		resp := gtk.ResponseType(dialog.Run())
		switch resp {
		case gtk.RESPONSE_APPLY:
			wait <- f.accepted()
		default:
			wait <- errRegistrationAborted
		}

		dialog.Destroy()
	})

	return <-wait
}
Пример #12
0
func (u *gtkUI) showServerSelectionWindow() error {
	builder := builderForDefinition("AccountRegistration")
	obj, _ := builder.GetObject("dialog")

	d := obj.(*gtk.Dialog)
	defer d.Destroy()

	d.SetTransientFor(u.window)
	d.ShowAll()

	resp := d.Run()
	if gtk.ResponseType(resp) != gtk.RESPONSE_APPLY {
		return nil
	}

	obj, _ = builder.GetObject("server")
	iter, _ := obj.(*gtk.ComboBox).GetActiveIter()

	obj, _ = builder.GetObject("servers-model")
	val, _ := obj.(*gtk.ListStore).GetValue(iter, 0)
	server, _ := val.GetString()

	form := &registrationForm{
		parent: u.window,
		server: server,
	}

	saveFn := func() {
		u.addAndSaveAccountConfig(form.conf)
		if acc, ok := u.getAccountByID(form.conf.ID()); ok {
			acc.session.WantToBeOnline = true
			acc.Connect()
		}
	}

	go requestAndRenderRegistrationForm(form.server, form.renderForm, saveFn)

	return nil
}
Пример #13
0
func (u *gtkUI) exportFingerprintsForDialog(account *config.Account, w *gtk.Dialog) {
	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Export fingerprints"),
		&w.Window,
		gtk.FILE_CHOOSER_ACTION_SAVE,
		i18n.Local("_Cancel"),
		gtk.RESPONSE_CANCEL,
		i18n.Local("_Export"),
		gtk.RESPONSE_OK,
	)

	dialog.SetCurrentName("otr.fingerprints")

	if gtk.ResponseType(dialog.Run()) == gtk.RESPONSE_OK {
		ok := u.exportFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints exported"), i18n.Local("Fingerprints were exported correctly."))
		} else {
			u.notify(i18n.Local("Failure exporting fingerprints"), fmt.Sprintf(i18n.Local("Couldn't export fingerprints to %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Пример #14
0
func dialogAskBackend() {
	// Need to keep the string as it is for translation.
	str := "OpenGL allows you to use the hardware acceleration, reducing the CPU load to the minimum.\nIt also allows some pretty visual effects similar to Compiz.\nHowever, some cards and/or their drivers don't fully support it, which may prevent the dock from running correctly.\nDo you want to activate OpenGL ?\n (To not show this dialog, launch the dock from the Application menu,\n  or with the -o option to force OpenGL and -c to force cairo.)"

	dialog := newgtk.Dialog()
	dialog.SetTitle(tran.Slate("Use OpenGL in Cairo-Dock"))
	dialog.AddButton(tran.Slate("Yes"), gtk.RESPONSE_YES)
	dialog.AddButton(tran.Slate("No"), gtk.RESPONSE_NO)

	labelTxt := newgtk.Label(tran.Slate(str))

	content, _ := dialog.GetContentArea()
	content.PackStart(labelTxt, false, false, 0)

	askBox := newgtk.Box(gtk.ORIENTATION_HORIZONTAL, 3)
	content.PackStart(askBox, false, false, 0)

	labelSave := newgtk.Label(tran.Slate("Remember this choice"))
	check := newgtk.CheckButton()
	askBox.PackEnd(check, false, false, 0)
	askBox.PackEnd(labelSave, false, false, 0)

	dialog.ShowAll()

	answer := dialog.Run() // has its own main loop, so we can call it before gtk_main.
	remember := check.GetActive()
	dialog.Destroy()

	if answer == int(gtk.RESPONSE_NO) {
		gldi.GLBackendDeactivate()
	}

	if remember { // save user choice to file.
		value := ternary.String(gtk.ResponseType(answer) == gtk.RESPONSE_YES, "opengl", "cairo")
		updateHiddenFile("default backend", value)
	}
}
Пример #15
0
func verifyFingerprintDialog(account *account, uid string, parent *gtk.Window) gtk.ResponseType {
	accountConfig := account.session.GetConfig()
	conversation, _ := account.session.ConversationManager().EnsureConversationWith(uid)
	ourFp := conversation.OurFingerprint()
	theirFp := conversation.TheirFingerprint()

	dialog := buildVerifyFingerprintDialog(accountConfig.Account, ourFp, uid, theirFp)
	defer dialog.Destroy()

	dialog.SetTransientFor(parent)
	dialog.ShowAll()

	responseType := gtk.ResponseType(dialog.Run())
	switch responseType {
	case gtk.RESPONSE_YES:
		account.executeCmd(client.AuthorizeFingerprintCmd{
			Account:     accountConfig,
			Peer:        uid,
			Fingerprint: theirFp,
		})
	}

	return responseType
}
Пример #16
0
func (v *dialog) SetDefaultResponse(v1 gtki.ResponseType) {
	v.internal.SetDefaultResponse(gtk.ResponseType(v1))
}
Пример #17
0
func onFileChooserOpen(obj *gtk.Button, data fileChooserData) {
	var parent *gtk.Window

	var title string
	var action gtk.FileChooserAction

	switch data.key.Type {
	case cftype.KeyFolderSelector:
		title = tran.Slate("Pick up a directory")
		action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER

	case cftype.KeyImageSelector:
		title = tran.Slate("Pick up an image")
		action = gtk.FILE_CHOOSER_ACTION_OPEN

	default:
		title = tran.Slate("Pick up a file")
		action = gtk.FILE_CHOOSER_ACTION_OPEN
	}

	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(title, parent, action,
		"_OK", gtk.RESPONSE_OK, "_Cancel", gtk.RESPONSE_CANCEL)

	// Set the current folder to the current value in conf.
	value, _ := data.entry.GetText()
	if value == "" || value[0] != '/' {
		if data.key.IsType(cftype.KeyImageSelector) {
			println("need dir pictures")
			// dialog.SetCurrentFolder(filepath.Dir(value)) // g_get_user_special_dir (G_USER_DIRECTORY_PICTURES) :
		} else {
			println(os.Getenv("HOME"))
			dialog.SetCurrentFolder(os.Getenv("HOME"))
		}
	} else {
		dialog.SetCurrentFolder(filepath.Dir(value))
	}

	if data.key.IsType(cftype.KeyImageSelector) { // Add shortcuts to icons of the system.
		dialog.AddShortcutFolder("/usr/share/icons")
		dialog.AddShortcutFolder("/usr/share/pixmaps")
	}

	if data.key.IsType(cftype.KeyFileSelector, cftype.KeySoundSelector) { // Add shortcuts to system icons directories.
		filter := newgtk.FileFilter()
		filter.SetName(tran.Slate("All"))
		filter.AddPattern("*")
		dialog.AddFilter(filter)
	}

	if data.key.IsType(cftype.KeyFileSelector, cftype.KeyImageSelector) { // Preview and images filter.
		filter := newgtk.FileFilter()
		filter.SetName(tran.Slate("Image"))
		filter.AddPixbufFormats()
		dialog.AddFilter(filter)

		img := newgtk.Image()
		dialog.SetPreviewWidget(img)
		dialog.Connect("update-preview", onFileChooserUpdatePreview, img)
	}

	dialog.Show()
	answer := dialog.Run()
	if gtk.ResponseType(answer) == gtk.RESPONSE_OK {
		data.entry.SetText(dialog.GetFilename())
	}
	dialog.Destroy()
}
Пример #18
0
func (*RealGtk) FileChooserDialogNewWith2Buttons(title string, parent gtki.Window, action gtki.FileChooserAction, first_button_text string, first_button_id gtki.ResponseType, second_button_text string, second_button_id gtki.ResponseType) (gtki.FileChooserDialog, error) {
	return wrapFileChooserDialog(gtk.FileChooserDialogNewWith2Buttons(title, unwrapWindow(parent), gtk.FileChooserAction(action), first_button_text, gtk.ResponseType(first_button_id), second_button_text, gtk.ResponseType(second_button_id)))
}