commit affe7a92927bfdfce9bc00a2c1c72368d182b01c
parent cebda5a61dbed185bd9520e491ffc18c8682363b
Author: MTRNord <mtrnord1@gmail.com>
Date: Tue, 29 Aug 2017 01:21:51 +0200
Prepare Message UI's and add Option to send (currently locked to the Morpheus Room as no Room selection exists)
Signed-off-by: MTRNord <mtrnord1@gmail.com>
Diffstat:
6 files changed, 348 insertions(+), 9 deletions(-)
diff --git a/elements.go b/elements.go
@@ -0,0 +1,37 @@
+package main
+
+import (
+ "github.com/golang-commonmark/markdown"
+ "github.com/therecipe/qt/core"
+ "github.com/therecipe/qt/gui"
+ "github.com/therecipe/qt/uitools"
+ "github.com/therecipe/qt/widgets"
+)
+
+func AddMessage(body string, avatar *gui.QPixmap) *widgets.QWidget {
+ var widget = widgets.NewQWidget(nil, 0)
+
+ var loader = uitools.NewQUiLoader(nil)
+ var file = core.NewQFile2(":/qml/ui/message.ui")
+
+ file.Open(core.QIODevice__ReadOnly)
+ var messageWidget = loader.Load(file, widget)
+ file.Close()
+
+ var layout = widgets.NewQHBoxLayout()
+ layout.AddWidget(messageWidget, 1, core.Qt__AlignTop|core.Qt__AlignLeft)
+ widget.SetLayout(layout)
+ layout.SetSpacing(0)
+ layout.SetContentsMargins(0, 0, 0, 0)
+
+ avatarLogo := widgets.NewQLabelFromPointer(widget.FindChild("avatar", core.Qt__FindChildrenRecursively).Pointer())
+ messageContent := widgets.NewQLabelFromPointer(widget.FindChild("messageContent", core.Qt__FindChildrenRecursively).Pointer())
+
+ md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true))
+ mardownMessage := md.RenderToString([]byte(body))
+
+ messageContent.SetText(mardownMessage)
+ avatarLogo.SetPixmap(avatar)
+
+ return widget
+}
diff --git a/matrix/types.go b/matrix/types.go
@@ -0,0 +1,9 @@
+package matrix
+
+// HTMLMessage is the contents of a Matrix formated message event.
+type HTMLMessage struct {
+ MsgType string `json:"msgtype"`
+ Body string `json:"body"`
+ FormattedBody string `json:"formatted_body"`
+ Format string `json:"format"`
+}
diff --git a/qml/ui/chat.ui b/qml/ui/chat.ui
@@ -188,7 +188,7 @@
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_person_white_48px.svg</normaloff>:/qml/icons/ic_person_white_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -250,7 +250,7 @@
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_add_white_48px.svg</normaloff>:/qml/icons/ic_add_white_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -312,7 +312,7 @@
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_menu_white_48px.svg</normaloff>:/qml/icons/ic_menu_white_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -377,7 +377,7 @@
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_settings_white_48px.svg</normaloff>:/qml/icons/ic_settings_white_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -436,7 +436,7 @@
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_power_settings_new_white_48px.svg</normaloff>:/qml/icons/ic_power_settings_new_white_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -746,7 +746,7 @@ border-radius: 2px;</string>
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_phone_black_48px.svg</normaloff>:/qml/icons/ic_phone_black_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -784,7 +784,7 @@ border-radius: 2px;</string>
<string/>
</property>
<property name="icon">
- <iconset>
+ <iconset resource="../../rcc.qrc">
<normaloff>:/qml/icons/ic_video_call_black_48px.svg</normaloff>:/qml/icons/ic_video_call_black_48px.svg</iconset>
</property>
<property name="iconSize">
@@ -820,7 +820,7 @@ border-radius: 2px;</string>
<property name="widgetResizable">
<bool>true</bool>
</property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
+ <widget class="QWidget" name="messagesScrollAreaContent">
<property name="geometry">
<rect>
<x>0</x>
@@ -897,9 +897,15 @@ padding: 3px</string>
<property name="frame">
<bool>true</bool>
</property>
+ <property name="readOnly">
+ <bool>false</bool>
+ </property>
<property name="placeholderText">
<string>Send a Message (unecrypted)...</string>
</property>
+ <property name="clearButtonEnabled">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>
@@ -915,6 +921,8 @@ padding: 3px</string>
<zorder>sidebarWidget</zorder>
<zorder>RoomWidget</zorder>
</widget>
- <resources/>
+ <resources>
+ <include location="../../rcc.qrc"/>
+ </resources>
<connections/>
</ui>
diff --git a/qml/ui/message.ui b/qml/ui/message.ui
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>560</width>
+ <height>83</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <property name="styleSheet">
+ <string notr="true">background-color:transparent;</string>
+ </property>
+ <widget class="QWidget" name="widget" native="true">
+ <property name="geometry">
+ <rect>
+ <x>118</x>
+ <y>10</y>
+ <width>437</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="messageContent">
+ <property name="font">
+ <font>
+ <family>Arial</family>
+ <pointsize>12</pointsize>
+ <stylestrategy>PreferAntialias</stylestrategy>
+ </font>
+ </property>
+ <property name="styleSheet">
+ <string notr="true">background-color: rgb(242, 244, 248);
+border: 0;
+border-radius:5px;</string>
+ </property>
+ <property name="text">
+ <string>Test</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ <property name="margin">
+ <number>4</number>
+ </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="widget_2" native="true">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>84</width>
+ <height>84</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <widget class="QLabel" name="avatar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>84</width>
+ <height>84</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="pixmap">
+ <pixmap>../../../../../../../Downloads/avatar512.png</pixmap>
+ </property>
+ <property name="scaledContents">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/qml/ui/ownmessage.ui b/qml/ui/ownmessage.ui
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>560</width>
+ <height>83</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <widget class="QWidget" name="widget_2" native="true">
+ <property name="geometry">
+ <rect>
+ <x>476</x>
+ <y>0</y>
+ <width>84</width>
+ <height>84</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <widget class="QLabel" name="avatar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>84</width>
+ <height>84</height>
+ </rect>
+ </property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="pixmap">
+ <pixmap>../../../../../../../Downloads/avatar512.png</pixmap>
+ </property>
+ <property name="scaledContents">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </widget>
+ <widget class="QWidget" name="widget" native="true">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>437</width>
+ <height>61</height>
+ </rect>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="messageContent">
+ <property name="font">
+ <font>
+ <family>Arial</family>
+ <pointsize>12</pointsize>
+ <stylestrategy>PreferAntialias</stylestrategy>
+ </font>
+ </property>
+ <property name="styleSheet">
+ <string notr="true">background-color: rgb(121, 198, 246);
+border: 0;
+border-radius:5px;</string>
+ </property>
+ <property name="text">
+ <string>Test</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ <property name="margin">
+ <number>4</number>
+ </property>
+ <property name="openExternalLinks">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/uis.go b/uis.go
@@ -2,6 +2,7 @@ package main
import (
"github.com/Nordgedanken/Morpheus/matrix"
+ "github.com/golang-commonmark/markdown"
"github.com/matrix-org/gomatrix"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/gui"
@@ -11,6 +12,7 @@ import (
"log"
"strings"
"sync"
+ "time"
)
var username string
@@ -233,5 +235,49 @@ func NewMainUI(windowWidth, windowHeight int, cli *gomatrix.Client) *widgets.QWi
}
})
+ //Start Syncer!
+ syncer := cli.Syncer.(*gomatrix.DefaultSyncer)
+ customStore := gomatrix.NewInMemoryStore()
+ cli.Store = customStore
+ syncer.Store = customStore
+ syncer.OnEventType("m.room.message", func(ev *gomatrix.Event) {
+ localLog.Println("message:", ev.Content)
+ })
+
+ // Start Non-blocking sync
+ localLog.Println("Syncing now")
+ go func() {
+ for {
+ localLog.Println("sync")
+ if e := cli.Sync(); e != nil {
+ localLog.Println("Fatal Sync() error")
+ time.Sleep(10 * time.Second)
+ }
+ time.Sleep(10 * time.Second)
+ }
+ }()
+
+ messageInput := widgets.NewQLineEditFromPointer(widget.FindChild("MessageInput", core.Qt__FindChildrenRecursively).Pointer())
+ var message string
+ window.ConnectKeyPressEvent(func(ev *gui.QKeyEvent) {
+ if int(ev.Key()) == int(core.Qt__Key_Enter) || int(ev.Key()) == int(core.Qt__Key_Return) {
+ md := markdown.New(markdown.XHTMLOutput(true), markdown.Nofollow(true))
+ mardownMessage := md.RenderToString([]byte(message))
+ if mardownMessage == message {
+ cli.SendText("!zTIXGmDjyRcAqbrWab:matrix.ffslfl.net", message)
+ } else {
+ cli.SendMessageEvent("!zTIXGmDjyRcAqbrWab:matrix.ffslfl.net", "m.room.message", matrix.HTMLMessage{"m.text", message, mardownMessage, "org.matrix.custom.html"})
+ }
+ messageInput.Clear()
+ } else {
+ messageInput.KeyPressEventDefault(ev)
+ }
+ })
+ messageInput.ConnectTextChanged(func(value string) {
+ message = value
+ })
+
+ localLog.Println("Started Syncing")
+
return widget
}