Beispiel #1
0
func (ui *Ui) initDeviceView() *gtk.Box {
	vbox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	ui.deviceBox = vbox

	hbox, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
	vbox.PackStart(hbox, false, true, 20)

	img, _ := gtk.ImageNew()
	hbox.PackStart(img, false, true, 0)
	ui.deviceIcon = img

	nameBox, _ := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0)
	hbox.PackStart(nameBox, true, true, 0)

	l, _ := gtk.LabelNew("")
	l.Set("xalign", 0)
	nameBox.PackStart(l, true, true, 0)
	ui.deviceNameLabel = l

	l, _ = gtk.LabelNew("")
	l.Set("xalign", 0)
	nameBox.PackStart(l, true, true, 0)
	ui.deviceStatusLabel = l

	browseBtn, _ := gtk.ButtonNewFromIconName("document-open-symbolic", gtk.ICON_SIZE_BUTTON)
	hbox.PackStart(browseBtn, false, false, 0)
	ui.browseBtn = browseBtn

	browseBtn.Connect("clicked", func() {
		log.Println("Browse device", ui.selectedDevice)
		ui.plugins.Sftp.SendStartBrowsing(ui.selectedDevice)
	})

	pairBtn, _ := gtk.ButtonNew()
	hbox.PackStart(pairBtn, false, false, 5)
	ui.pairBtn = pairBtn

	pairBtn.Connect("clicked", func() {
		log.Println("Pair/unpair device", ui.selectedDevice)

		if ui.selectedDevice.Paired {
			ui.engine.UnpairDevice(ui.selectedDevice)
		} else {
			ui.engine.PairDevice(ui.selectedDevice)
		}
	})

	return vbox
}
func handleImagePreviewMessage(parent *ChatWindow, msg *prot.Message) IMessage {
	from := msg.GetFrom()
	msgType := checkMessageType(from)

	msgId := msg.GetId()
	preview := path.Join(goline.TempDirPath, "preview", msgId)
	meta := msg.GetContentMetadata()

	var url string
	if checkFileNotExist(preview) {
		if meta["PUBLIC"] == "TRUE" {
			url = meta["PREVIEW_URL"]
		} else {
			url = api.LINE_OBJECT_STORAGE_URL + msgId + "/preview"
		}
		err := downloadFile(url, preview)
		if err != nil {
			goline.LoggerPrintln(err)
			return NewTextMessage(parent, msgType, from, "Failed to download preview.")
		}
	}

	image, err := gtk.ImageNew()
	if err != nil {
		goline.LoggerPanicln(err)
	}
	image.SetFromFile(preview)

	if meta["PUBLIC"] == "TRUE" {
		url = meta["DOWNLOAD_URL"]
	} else {
		url = api.LINE_OBJECT_STORAGE_URL + msgId
	}

	return NewDownloadableMessage(parent, msgType, from, msgId, url, "", image)
}