Commit 693a2d3d authored by armin's avatar armin
Browse files

added server selection dialog, as well as parts of the logic

parent 87329fbe
Subproject commit 1a449b715b7a116b4234ffc2c93b477c03bb0c1a
Subproject commit f9c8a18139d7fca63f68047119c9c5ff865396d9
QT += qml quick core network websockets sql quickcontrols2 multimedia svg xml concurrent
SOURCES += \
main.cpp
main.cpp \
serverselector.cpp
HEADERS += config.h
HEADERS += config.h \
serverselector.h
RESOURCES += qml.qrc\
fonts.qrc\
......
......@@ -24,6 +24,7 @@
#include "CustomModels/usermodel.h"
#include "CustomModels/messagemodel.h"
#include "utils.h"
#include "serverselector.h"
#ifdef Q_OS_ANDROID
#include <signal.h>
......@@ -72,7 +73,7 @@ int main( int argc, char *argv[] )
#ifdef Q_OS_ANDROID
QAndroidJniObject errorStringJni = QAndroidJniObject::fromString(storage->getSetting("ERROR"));
QAndroidJniObject::callStaticMethod<void>("at/gv/ucom/MainActivity", "catchError","(Ljava/lang/String;)V",errorStringJni.object<jstring>());
QAndroidJniObject::callStaticMethod<void>("com/osalliance/rocketchatMobile/MainActivity", "catchError","(Ljava/lang/String;)V",errorStringJni.object<jstring>());
#endif
}
}
......@@ -99,6 +100,7 @@ int main( int argc, char *argv[] )
}else{
qWarning()<<"could not open translation file: "<<"qtquickcontrols_"+language;
}
QQmlApplicationEngine engine;
QSharedPointer<RocketChatServerData> server(
......@@ -107,7 +109,9 @@ int main( int argc, char *argv[] )
userModel, channelModel, groupsModel, groupsModel,messageModel )
);
RocketChat rocketChat( &app );
rocketChat.registerServer( server );
ServerSelector serverSelector(server);
QObject::connect(&serverSelector,&ServerSelector::serverSelected,&rocketChat,&RocketChat::registerServer);
//rocketChat.registerServer( server );
QQmlContext *context = engine.rootContext();
......@@ -115,6 +119,7 @@ int main( int argc, char *argv[] )
QString buildDate(__DATE__ );
QString serverAdress(SERVERADRESS);
context->setContextProperty( "rocketChatController", &rocketChat );
context->setContextProperty( "serverSelector", &serverSelector );
#ifdef QT_DEBUG
context->setContextProperty( "debug", QVariant(true) );
#else
......
......@@ -129,5 +129,8 @@
<file>res/customemojis.svg</file>
<file>res/customemojis_white.svg</file>
<file>qml/popups/JitsiMeetMissing.qml</file>
<file>qml/pages/ServerSelectionPage.qml</file>
<file>qml/popups/AddServerEntry.qml</file>
<file>qml/popups/DeleteEntry.qml</file>
</qresource>
</RCC>
......@@ -45,12 +45,21 @@ ApplicationWindow {
JitsiMeetMissing{
id: jitsiMeetMissing
}
AddServerEntry{
id:addServerEntry
}
Component {
id: loginComponent
LoginPage {
}
}
Component {
id:serverSelectionComponent
ServerSelectionPage {
}
}
ListModel {
id: uploadsModel
}
......@@ -61,7 +70,7 @@ ApplicationWindow {
property bool mainViewPushed: false
property bool channelPushed: false
id: mainStack
initialItem: loginComponent
initialItem: serverSelectionComponent
function reset() {
rocketChatController.setUsername("default","")
rocketChatController.setPassword("default","")
......@@ -69,7 +78,7 @@ ApplicationWindow {
mainStack.clear()
mainViewPushed = false
channelPushed = false
mainStack.push(loginComponent)
mainStack.push(serverSelectionComponent)
}
function toMainView() {
if (!mainViewPushed) {
......
......@@ -21,6 +21,7 @@ Item {
showLoginForm = false
connectionIndicator.visible = true
loginStatus.text = ""
switchServerButton.visible = false
}
function checkConnectionState() {
......@@ -147,6 +148,20 @@ Item {
color: Colors.white
textColor: Colors.primary
}
StdButton {
id: switchServerButton
anchors.left: parent.left
anchors.right: parent.right
text: qsTr("switch Server")
checked: false
checkable: false
color: Colors.white
textColor: Colors.primary
onPressed: {
mainStack.pop()
}
}
BusyIndicator {
id: connectionIndicator
visible: true
......@@ -204,6 +219,8 @@ Item {
loginStatus.text = qsTr("username or password wrong")
connectionIndicator.visible = false
loginPage.showLoginForm = true
switchServerButton.visible = true
}
onServerConnected: {
connectStatus.text = "connected"
......
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import QtQml.Models 2.2
import "qrc:/qml/navigation"
import "qrc:/qml/various"
import "qrc:/qml/popups"
import "qrc:/qml/style"
Page {
DeleteEntry{
id:deletePopup
}
ListModel{
id:serverListModel
}
ListView {
anchors.bottom: addServerButton.top
anchors.bottomMargin: 25
anchors.top:parent.top
anchors.left: parent.left
anchors.right: parent.right
spacing: 1
clip:true
id: serverListView
model:serverListModel
delegate: MouseArea {
//color: Colors.grey
height: 58
anchors.left: parent.left
anchors.right: parent.right
onPressAndHold: {
console.log("test")
deletePopup.x = mouse.x
deletePopup.y = parent.y
deletePopup.open()
}
onPressed: {
serverSelector.selectServer(model.address)
mainStack.push("qrc:/qml/pages/LoginPage.qml")
}
Rectangle {
color: Colors.grey
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.bottomMargin: 1
Row {
leftPadding: 26
anchors.left:parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: 14
Column {
leftPadding: 15
spacing: 2
anchors.verticalCenter: parent.verticalCenter
Text {
id: serverName
text: model.name
font.bold: true
textFormat: Text.PlainText
font.family: Fonts.opensans.name
font.pointSize: Fonts.largeFontSize
smooth: true
color: "black"
}
}
}
}
Rectangle {
anchors.bottom: parent.bottom
id: bottomLine
anchors.left: parent.left
anchors.right: parent.right
height: 1
//color: "#dfdfdf"
color: Colors.separatorGrey
}
}
}
StdButton{
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: 30
anchors.rightMargin: 30
anchors.bottomMargin: 25
text:qsTr("add server")
id: addServerButton
onPressed: {
addServerEntry.open()
}
}
Connections{
target: serverSelector
onNewServerList:{
serverListModel.clear()
serverListModel.append(list)
}
}
Component.onCompleted: {
var list = serverSelector.getServerList()
serverListModel.append(list)
}
}
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import "qrc:/qml/various"
import "qrc:/qml/style"
Popup {
id: serverSelectionPopup
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
width: 600
height: 200
x: Screen.width/2 - serverSelectionPopup.width/2
y: Screen.height/2 - serverSelectionPopup.height/2
Column{
anchors.horizontalCenter: parent.horizontalCenter
width: 500
TextField {
anchors.left: parent.left
anchors.right: parent.right
id: serverName
color: Colors.fontColor
font.pointSize: Fonts.largeFontSize
leftPadding: 5
rightPadding: 5
bottomPadding: 5
horizontalAlignment: TextField.AlignLeft
verticalAlignment: TextField.AlignBottom
selectByMouse: true
text: ""
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText|
Qt.ImhPreferLowercase
focus: true
placeholderText: qsTr("server name")
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 30
color: "transparent"
Rectangle {
height: 1
width: parent.width
color: Colors.white
anchors.bottom: parent.bottom
}
}
}
TextField {
anchors.left: parent.left
anchors.right: parent.right
id: serverAddress
color: Colors.fontColor
font.pointSize: Fonts.largeFontSize
leftPadding: 5
rightPadding: 5
bottomPadding: 5
horizontalAlignment: TextField.AlignLeft
verticalAlignment: TextField.AlignBottom
selectByMouse: true
text: ""
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText|
Qt.ImhPreferLowercase
focus: true
placeholderText: qsTr("server address")
background: Rectangle {
implicitWidth: parent.width
implicitHeight: 30
color: "transparent"
Rectangle {
height: 1
width: parent.width
color: Colors.white
anchors.bottom: parent.bottom
}
}
}
Row{
anchors.horizontalCenter: parent.horizontalCenter
StdButton{
text: qsTr("add")
onPressed: {
serverSelector.addServer(serverName.text,serverAddress.text)
serverSelectionPopup.close()
}
}
StdButton{
text: qsTr("cancel")
onPressed: {
serverSelectionPopup.close()
}
}
}
}
onOpened: {
serverName.clear()
serverAddress.clear()
}
}
......@@ -3,7 +3,7 @@ import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import "qrc:/qml/various"
import "../javascript/print.js" as Print
import "qrc:/javascript/print.js" as Print
Popup {
id: addUsersToRoomPopup
......
import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import QtQuick.Window 2.2
import "qrc:/qml/various"
import "qrc:/qml/style"
Popup {
StdButton{
text:qsTr("delete")
onClicked: {
console.log("test2")
}
}
}
#include "serverselector.h"
ServerSelector::ServerSelector( QSharedPointer<RocketChatServerData> pServer)
{
mServer = pServer;
QVariantMap map;
map["name"] = "FairChat";
map["address"] = "chat.fairkom.net";
mServers.append(map);
}
void ServerSelector::selectServer( QString pServerAddress )
{
mServer->setServerAddress(pServerAddress);
emit serverSelected(mServer);
}
void ServerSelector::addServer( QString pName, QString pServer )
{
QVariantMap map;
map["name"] = pName;
map["address"] = pServer;
mServers.append(map);
QByteArray temp;
QDataStream out(temp);
out<<mServers;
mSettings.setValue("servers",temp);
mSettings.sync();
emit newServerList(mServers);
}
QVariantList ServerSelector::getServerList()
{
return mServers;
}
void ServerSelector::removeServer( QString pServerAddress )
{
}
#ifndef SERVERSELECTOR_H
#define SERVERSELECTOR_H
#include <QObject>
#include <QMap>
#include <QSettings>
#include "rocketchatserver.h"
class ServerSelector : public QObject
{
Q_OBJECT
public:
explicit ServerSelector( QSharedPointer<RocketChatServerData> pServer);
Q_INVOKABLE void selectServer( QString pServerAddress );
Q_INVOKABLE void addServer( QString pName, QString pServer );
Q_INVOKABLE QVariantList getServerList();
Q_INVOKABLE void removeServer( QString pServerAddress );
private:
QSharedPointer<RocketChatServerData> mServer;
QVariantList mServers;
QSettings mSettings;
signals:
void serverSelected(QSharedPointer<RocketChatServerData> server);
void newServerList(QVariantList list);
public slots:
};
#endif // SERVERSELECTOR_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment