예제 #1
0
func main() {
	gtk.Init(nil)
	window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
	window.SetTitle("webkit")
	window.Connect("destroy", gtk.MainQuit)

	vbox := gtk.VBox(false, 1)

	entry := gtk.Entry()
	entry.SetText("http://golang.org/")
	vbox.PackStart(entry, false, false, 0)

	swin := gtk.ScrolledWindow(nil, nil)
	swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	swin.SetShadowType(gtk.GTK_SHADOW_IN)

	webview := webkit.WebView()
	webview.Connect("load-committed", func() {
		entry.SetText(webview.GetUri())
	})
	swin.Add(webview)

	vbox.Add(swin)

	entry.Connect("activate", func() {
		webview.LoadUri(entry.GetText())
	})
	button := gtk.ButtonWithLabel("load String")
	button.Clicked(func() {
		webview.LoadString("hello Go GTK!", "text/plain", "utf-8", ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.ButtonWithLabel("load HTML String")
	button.Clicked(func() {
		webview.LoadHtmlString(HTML_STRING, ".")
	})
	vbox.PackStart(button, false, false, 0)

	button = gtk.ButtonWithLabel("Google Maps")
	button.Clicked(func() {
		webview.LoadHtmlString(MAP_EMBED, ".")
	})
	vbox.PackStart(button, false, false, 0)

	window.Add(vbox)
	window.SetSizeRequest(600, 600)
	window.ShowAll()

	proxy := os.Getenv("HTTP_PROXY")
	if len(proxy) > 0 {
		soup_uri := webkit.SoupUri(proxy)
		webkit.GetDefaultSession().Set("proxy-uri", soup_uri)
		soup_uri.Free()
	}
	entry.Emit("activate")
	gtk.Main()
}
예제 #2
0
func (window *GhAuthWindow) build() {
	window.bindKeys()
	window.SetModal(true)
	window.SetTitle("Readmill Authentication")
	window.Connect("destroy", func() {
		config := models.Config()

		if config.AccessToken == "" {
			gtk.MainQuit()
		}
	})

	scrolledWindow := gtk.ScrolledWindow(nil, nil)
	scrolledWindow.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
	scrolledWindow.SetShadowType(gtk.GTK_SHADOW_IN)

	webview := webkit.WebView()
	webview.Connect("load-committed", func() {
		uri := webview.GetUri()
		matched, _ := regexp.MatchString(`^`+constants.READMILL_REDIRECT_URI+`/\?code=`, uri)

		if matched {
			webview.StopLoading()
			codeRegex, _ := regexp.Compile(`\?code=([^&]*)`)
			result := codeRegex.FindStringSubmatch(uri)
			code := result[1]
			token := readmilloauth.GetToken(constants.READMILL_CLIENT_ID, constants.READMILL_CLIENT_SECRET, constants.READMILL_REDIRECT_URI, code)
			userId := readmilloauth.GetUserId(token)

			config := models.Config()
			config.AccessToken = token
			config.UserId = userId
			config.Write()

			window.Destroy()
		}
	})
	scrolledWindow.Add(webview)

	authorizeUri := readmilloauth.AuthorizeUri(constants.READMILL_CLIENT_ID, constants.READMILL_REDIRECT_URI)
	webview.LoadUri(authorizeUri)

	window.Add(scrolledWindow)
	window.SetSizeRequest(500, 650)
}