diff --git a/Desktop.qml b/Desktop.qml index 6a3150b8..d9a0127e 100644 --- a/Desktop.qml +++ b/Desktop.qml @@ -1,387 +1,388 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ // Skeleton from https://github.com/achipa/outqross_blog.git // Almost everything has been re-adapted import QtQuick 2.7 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.2 import QtQuick.Window 2.2 import QtQuick.Dialogs 1.2 import QtQuick.Layouts 1.1 import Qt.labs.settings 1.0 import QtGraphicalEffects 1.0 import KDE.Ruqola.Ruqola 1.0 import KDE.Ruqola.DDPClient 1.0 import KDE.Ruqola.Notification 1.0 // import "Log.js" as Log // import "Data.js" as Data ApplicationWindow { property int margin: 11 property string statusText property string lightGreen: "#6ab141"; property string darkGreen: "#00613a"; property string selectedRoomID: ""; id: appid title: qsTr("Ruqola") width: 800 height: 600 visible: true Shortcut { sequence: StandardKey.Quit context: Qt.ApplicationShortcut onActivated: Qt.quit() } Login { id: loginTab visible: (Ruqola.loginStatus == DDPClient.LoginFailed || Ruqola.loginStatus == DDPClient.LoggedOut) -// visible: (Ruqola.loginStatus != DDPClient.LoggedIn) anchors.fill:parent z: 10 serverURL: Ruqola.serverURL username: Ruqola.userName onAccepted: { Ruqola.password = loginTab.password; Ruqola.userName = loginTab.username; Ruqola.serverURL = loginTab.serverURL; +// DDPClient.loginType = Password; Ruqola.tryLogin(); } onOauthAccepted: { +// DDPClient.loginType = Google; Ruqola.tryOAuthLogin(); } } BusyIndicator { id: busy anchors.centerIn: parent visible: Ruqola.loginStatus == DDPClient.LoggingIn } Item { id: mainWidget anchors.fill: parent visible: !loginTab.visible Rectangle { id: userBox anchors.top: parent.top width: parent.width anchors.left: parent.left anchors.right: roomsList.right height: 40 color: darkGreen Text { verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignRight anchors.rightMargin: 10 anchors.fill: parent font.pointSize: 12 color: "white" text: "Hello, " + Ruqola.userName } } RoomsView { anchors.top: userBox.bottom anchors.left: parent.left anchors.bottom: parent.bottom anchors.margins: 0 width: 200 height: appid.height id: roomsList model: Ruqola.roomModel() visible: parent.visible selectedRoomID: appid.selectedRoomID; onRoomSelected: { if (roomID == selectedRoomID) { return; } console.log("Choosing room", roomID); appid.selectedRoomID = roomID; activeChat.model = Ruqola.getModelForRoom(roomID) topicWidget.selectedRoom = Ruqola.getRoom(roomID) } onCountChanged: { // console.log("We have", roomsList.count, "rooms") } LinearGradient { id: greenGradient anchors.fill: parent start: Qt.point(0, 0) end: Qt.point(roomsList.width, 0) gradient: Gradient { GradientStop { position: 0.0; color: "#6ab141" } GradientStop { position: 1.0; color: "#00613a" } } z: -1; } Button { id: logoutButton anchors.bottom: parent.bottom anchors.left: parent.left anchors.leftMargin: 20 anchors.bottomMargin: 20 width: 150 height: 30 text: qsTr("LogOut") onClicked: Ruqola.logOut(); } } //RoomsView Item { anchors.right: parent.right anchors.left: roomsList.right anchors.top: parent.top anchors.bottom: input.top id: chatView Rectangle { id: topicWidget color: "#fff" anchors.top: parent.top anchors.right: parent.right anchors.left: parent.left height: nameLabel.height + topicLabel.height property var selectedRoom; Text { id: nameLabel text: "#" + parent.selectedRoom.name font.pointSize: 18 verticalAlignment: Text.AlignVCenter anchors.leftMargin: 20 height: 40 // height: font.pixelSize + 10 anchors.top: parent.top anchors.left: parent.left anchors.right: parent.right } Text { id: topicLabel text: topicWidget.selectedRoom.topic anchors.top: nameLabel.bottom anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right horizontalAlignment: Text.AlignHCenter height: font.pixelSize + 10 } } ScrollView { anchors.right: parent.right anchors.left: parent.left anchors.top: topicWidget.bottom anchors.bottom: parent.bottom verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn // visible: parent.visible && (Ruqola.loginStatus != DDPClient.LoggingIn) // visible: !greeter.visible ListView { id: activeChat // model: Ruqola.getModelForRoom(selectedRoomID) onCountChanged: { // console.log("changed") // var newIndex = count - 1 // last index // positionViewAtEnd() positionViewAtIndex(count - 1, ListView.Beginning) // currentIndex = newIndex } // Component.onCompleted: positionViewAtEnd() Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning) // onSelectedRoomIDChanged: { console.log("CHANGED"); activeChat.positionViewAtEnd(); } // model: myModel anchors.fill:parent visible : count > 0 z: -1 // ScrollBar.vertical: ScrollBar { } delegate: Message { i_messageText: messageText i_username: username i_systemMessage: systemMessage i_systemMessageType: type //width: parent.width } } } } //Item chatView Item { anchors.bottom: parent.bottom anchors.left: roomsList.right anchors.right: parent.right id: input height: 40 TextField { id: messageLine anchors.left: parent.left anchors.bottom: parent.bottom anchors.top: parent.top anchors.right: emoticonsButton.left placeholderText: if (Ruqola.loginStatus != DDPClient.LoggedIn || (selectedRoomID=="")){ qsTr("Please Select a room") } else{ qsTr("Enter message") } // height: 2.7*font.pixelSize property string type: "text"; onAccepted: { if (text != "" && Ruqola.loginStatus == DDPClient.LoggedIn && !(selectedRoomID=="")) { Ruqola.sendMessage(selectedRoomID, text, type); text = ""; } } } Button { anchors.bottom: parent.bottom anchors.top: parent.top anchors.right: attachmentsButton.left width: 50 id : emoticonsButton iconName: "emoticonsButton" iconSource: "qrc:/Emoticon.png" visible: true } Button { anchors.bottom: parent.bottom anchors.top: parent.top anchors.right: parent.right width: 50 id : attachmentsButton iconName: "attachmentsButton" iconSource: "qrc:/attach-button.jpg" visible: true onClicked: Ruqola.attachmentButtonClicked(); } }//Item input }// mainWidget Item - Image { - id: receivedImage - source:" " - width: 60 - height: 80 - fillMode: Image.PreserveAspectFit -// visible: //only when an image is recieved from server - sourceSize.width: 1024 - sourceSize.height: 1024 - } +// Image { +// id: receivedImage +// source:" " +// width: 60 +// height: 80 +// fillMode: Image.PreserveAspectFit +//// visible: //only when an image is recieved from server +// sourceSize.width: 1024 +// sourceSize.height: 1024 +// } Rectangle { z: -10 anchors.fill: parent color: "white" } onClosing: { console.log("Minimizing to systray..."); hide(); } function toggleShow() { if (visible) { hide(); } else { show(); raise(); requestActivate(); } } Component.onCompleted: { systrayIcon.activated.connect(toggleShow); systrayIcon.messageClicked.connect(toggleShow); // roomsList.model = Ruqola.roomModel(); // timer.start(); // timer.fire(); } /* Timer { id: timer interval: 1000 onTriggered: { // console.log("FIRE"); switch (Ruqola.loginStatus) { case Ruqola.NotConnected: statusText = qsTr("Not connected."); break; case Ruqola.LoggedIn: statusText = qsTr("Connected to " + Ruqola.serverURL); break; } } repeat: true }*/ // onStatusTextChanged: timer.restart(); } diff --git a/Login.qml b/Login.qml index a697ca4b..7d33b490 100644 --- a/Login.qml +++ b/Login.qml @@ -1,138 +1,139 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ import QtQuick 2.7 import QtQuick.Controls 1.3 Item { property alias username: usernameField.text; property alias password: passField.text; property alias serverURL: urlField.text; signal accepted() signal oauthAccepted() Keys.onPressed: { if (event.key === Qt.Key_Enter) { acceptingButton.clicked(); } else if (event.key === StandardKey.Escape) { } } id: loginForm // color: "#eeeeee" implicitHeight: 400 implicitWidth: 300 Column { id: form anchors.centerIn: parent width: 0.8*parent.width spacing: 3 Text { text: "Ruqola Log in" color: "#555" id: loginLabel font.pixelSize: 40 horizontalAlignment: Text.AlignHCenter width: parent.width } Item { id: spacer width: 30 height: 30 } Text { width: parent.width text:"Rocket Chat Server" } TextField { id: urlField // text: loginForm.serverURL width: parent.width placeholderText: qsTr("Enter address of the server") } Text { id:username width: parent.width text:"Enter your username" } TextField { width: parent.width id: usernameField placeholderText: qsTr("Enter username") } Text { id: passLabel width: parent.width text:"Enter your password" } TextField { width: parent.width id:passField echoMode: TextInput.Password inputMethodHints: Qt.ImhHiddenText placeholderText: qsTr("Enter password") } Item { id: spacer2 width: 30 height: 30 } Button { id: acceptingButton width: parent.width text: qsTr("Log in") enabled: (passField.text && urlField.text && usernameField.text) onClicked: loginForm.accepted() isDefault: true } Button { id: oauthButton width: parent.width text: qsTr("Log in with Google Account") // enabled: (passField.text && urlField.text && usernameField.text) onClicked: loginForm.oauthAccepted() + visible: false } } // Component.onCompleted: { // acceptingButton.clicked.connect(loginForm.accepted) // } } diff --git a/src/authentication.cpp b/src/authentication.cpp index 66f00b5a..6ba9d37b 100644 --- a/src/authentication.cpp +++ b/src/authentication.cpp @@ -1,112 +1,116 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "ruqola.h" #include "authentication.h" +#include "ddpclient.h" #include #include Authentication::Authentication() { getDataFromJson(); } -void Authentication::OAuthLogin() { - QJsonObject authKeys; - authKeys["credentialToken"] = m_client_id; - authKeys["credentialSecret"] = m_client_secret; - - Ruqola::self()->ddp()->method("login", QJsonDocument(authKeys)); - - QJsonArray requestPermissions; - requestPermissions.append("email"); - - bool requestOfflineToken = true; - - QString scope = QString("openID profile email"); - - QUuid state; - state = state.createUuid(); - QSettings s; - s.setValue("stateRandomNumber", state); - - QJsonObject loginUrlParameters; - loginUrlParameters["client_id"] = m_client_id; - loginUrlParameters["response_type"] = QString("code"); - loginUrlParameters["scope"] = scope; - loginUrlParameters["state"] = state.toString(); - - QString username = s.value("username").toString(); - QString loginHint = username; - - QString loginStyle = QString("redirect"); - QString redirectUrl = s.value("redirectUrl").toString(); - - QJsonObject json; - json["requestPermissions"] = requestPermissions; - json["requestOfflineToken"] = requestOfflineToken; - json["loginUrlParameters"] = loginUrlParameters; - json["loginHint"] = loginHint; - json["loginStyle"] = loginStyle; - json["redirectUrl"] = redirectUrl; - -// Ruqola::self()->ddp()->method("login", QJsonDocument(json)); - -} - - void Authentication::getDataFromJson(){ - QDir cacheDir(":/src/client_secret.json"); + QDir cacheDir(":/src"); if (!cacheDir.exists(cacheDir.path())) { cacheDir.mkpath(cacheDir.path()); } QFile f(cacheDir.absoluteFilePath("client_secret.json")); QString val; if (f.open(QIODevice::ReadOnly | QIODevice::Text)) { val = f.readAll(); } QJsonDocument document = QJsonDocument::fromJson(val.toUtf8()); QJsonObject object = document.object(); const auto settingsObject = object["web"].toObject(); const QUrl authUri(settingsObject["auth_uri"].toString()); - const auto clientId = settingsObject["client_id"].toString(); const QUrl tokenUri(settingsObject["token_uri"].toString()); + const auto clientID = settingsObject["client_id"].toString(); const auto clientSecret(settingsObject["client_secret"].toString()); const auto redirectUrls = settingsObject["redirect_uris"].toArray(); const QUrl redirectUrl(redirectUrls[0].toString()); +/* + QString clientID = QString("143580046552-s4rmnq5mg008u76id0d3rl63od985hc6.apps.googleusercontent.com"); + QString clientSecret = QString("nyVm19iOjjtldcCZJ-7003xg"); + QString redirectUrl = QString("http://localhost:8080/cb/_oauth/google?close"); +*/ QSettings s; - s.setValue("clientID", clientId); - m_client_id = clientId; + s.setValue("clientID", clientID); + m_clientID = clientID; s.setValue("clientSecret", clientSecret); - m_client_secret = clientSecret; + m_clientSecret = clientSecret; s.setValue("redirectUrl", redirectUrl); } + +void Authentication::OAuthLogin() { + + QJsonObject auth; + QJsonObject authKeys; + authKeys["credentialToken"] = m_clientID; + authKeys["credentialSecret"] = m_clientSecret; + + auth["oauth"] = authKeys; + qDebug() << "-------------------------"; + qDebug() << "-------------------------"; + qDebug() << "OAuth Json" << auth; + Ruqola::self()->ddp()->method("login", QJsonDocument(auth)); + + QJsonArray requestPermissions; + requestPermissions.append("email"); + + QUuid state; + state = state.createUuid(); + QSettings s; + s.setValue("stateRandomNumber", state); + + QJsonObject loginUrlParameters; + loginUrlParameters["client_id"] = m_clientID; + loginUrlParameters["response_type"] = QString("code"); + loginUrlParameters["scope"] = QString("openID profile email"); + loginUrlParameters["state"] = state.toString(); + + QJsonObject json; + json["requestPermissions"] = requestPermissions; + json["requestOfflineToken"] = true; + json["loginUrlParameters"] = loginUrlParameters; + json["loginHint"] = s.value("username").toString(); + json["loginStyle"] = QString("redirect"); + json["redirectUrl"] = s.value("redirectUrl").toString(); + +// qDebug() << "OAuth Json" << json; +// Ruqola::self()->ddp()->method("login", QJsonDocument(json)); + +} + + //#include "authentication.moc" diff --git a/src/authentication.h b/src/authentication.h index 36320c1a..9a2161c9 100644 --- a/src/authentication.h +++ b/src/authentication.h @@ -1,62 +1,62 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef AUTHENTICATION_H #define AUTHENTICATION_H #include #include class Authentication { public: Authentication(); /** * @brief Extract info from Google Json API */ void getDataFromJson(); /** * @brief Call DDPClient's @method method with OAuth params */ void OAuthLogin(); /** * @brief Make requests to Google on behalf of user using access token */ void sendApiRequest(); private slots: void onGranted(); private: bool m_authGranted; - QString m_client_id; - QString m_client_secret; + QString m_clientID; + QString m_clientSecret; QOAuth2AuthorizationCodeFlow * m_google; }; #endif // AUTHENTICATION_H diff --git a/src/ddpclient.cpp b/src/ddpclient.cpp index b061f6a3..4e649e38 100644 --- a/src/ddpclient.cpp +++ b/src/ddpclient.cpp @@ -1,308 +1,317 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "ddpclient.h" #include "ruqola.h" #include #include #include void process_test(QJsonDocument doc) { qDebug() << "Callback test:" << doc; qDebug() << "End callback"; } void login_callback(QJsonDocument doc) { qDebug() << "LOGIN:" << doc; Ruqola::self()->setAuthToken(doc.object().value("token").toString()); qDebug() << "End callback"; } void DDPClient::resume_login_callback(QJsonDocument doc) { qDebug() << "LOGIN:" << doc; Ruqola::self()->setAuthToken(doc.object().value("token").toString()); qDebug() << "End callback"; } void empty_callback(QJsonDocument doc) { Q_UNUSED(doc); } DDPClient::DDPClient(const QString& url, QObject* parent) : QObject(parent), m_url(url), m_uid(1), m_loginJob(0), m_loginStatus(NotConnected), + m_loginType(Password), m_connected(false), m_attemptedPasswordLogin(false), m_attemptedTokenLogin(false) { m_webSocket.ignoreSslErrors(); connect(&m_webSocket, &QWebSocket::connected, this, &DDPClient::onWSConnected); connect(&m_webSocket, &QWebSocket::textMessageReceived, this, &DDPClient::onTextMessageReceived); - connect(&m_webSocket, &QWebSocket::disconnected, this, &DDPClient::WSclosed); + connect(&m_webSocket, &QWebSocket::disconnected, this, &DDPClient::onWSclosed); connect(Ruqola::self(), &Ruqola::serverURLChanged, this, &DDPClient::onServerURLChange); if (!url.isEmpty()) { m_webSocket.open(QUrl("wss://"+url+"/websocket")); } qDebug() << "Trying to connect to URL" << url; } DDPClient::~DDPClient() { m_webSocket.close(); } void DDPClient::onServerURLChange() { if (Ruqola::self()->serverURL() != m_url || !m_webSocket.isValid()) { if (m_webSocket.isValid()) { m_webSocket.flush(); m_webSocket.close(); } m_url = Ruqola::self()->serverURL(); m_webSocket.open(QUrl("wss://"+m_url+"/websocket")); connect(&m_webSocket, &QWebSocket::connected, this, &DDPClient::onWSConnected); - qDebug() << "Reconnecting" << m_url; //<< m_webSocket.st; + qDebug() << "Reconnecting" << m_url; } } DDPClient::LoginStatus DDPClient::loginStatus() const { return m_loginStatus; } +void DDPClient::setLoginStatus(DDPClient::LoginStatus l) +{ + qDebug() << "Setting login status to" << l; + m_loginStatus = l; + emit loginStatusChanged(); + + // reset flags + if (l == LoginFailed) { + m_attemptedPasswordLogin = false; + m_attemptedTokenLogin = false; + } +} + + +DDPClient::LoginType DDPClient::loginType() const +{ + return m_loginType; +} + +void DDPClient::setLoginType(DDPClient::LoginType t) +{ + qDebug() << "Setting login type to" << t; + m_loginType = t; + emit loginTypeChanged(); +} + bool DDPClient::isConnected() const { return m_connected; } bool DDPClient::isLoggedIn() const { return m_loginStatus == LoggedIn; } QString DDPClient::cachePath() const { return QStandardPaths::writableLocation(QStandardPaths::CacheLocation); } QQueue> DDPClient::messageQueue() { return m_messageQueue; } unsigned int DDPClient::method(const QString& m, const QJsonDocument& params, DDPClient::MessageType messageType) { return method(m, params, empty_callback, messageType); } unsigned int DDPClient::method(const QString& method, const QJsonDocument& params, std::function callback, DDPClient::MessageType messageType) { QJsonObject json; json["msg"] = "method"; json["method"] = method; json["id"] = QString::number(m_uid); if (params.isArray()){ json["params"] = params.array(); } else if (params.isObject()) { QJsonArray arr; arr.append(params.object()); json["params"] = arr; } qint64 bytes = m_webSocket.sendTextMessage(QJsonDocument(json).toJson(QJsonDocument::Compact)); if (bytes < json.length()) { qDebug() << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; qDebug() << m_webSocket.isValid() << m_webSocket.error() << m_webSocket.requestUrl(); if(messageType==DDPClient::Persistent){ m_messageQueue.enqueue(qMakePair(method,params)); Ruqola::self()->messageQueue()->processQueue(); } } else { qDebug() << "Successfully sent " << json; } m_callbackHash[m_uid] = callback; m_uid++; return m_uid - 1 ; } void DDPClient::subscribe(const QString& collection, const QJsonArray& params) { QJsonObject json; json["msg"] = "sub"; json["id"] = QString::number(m_uid); json["name"] = collection; json["params"] = params; qint64 bytes = m_webSocket.sendTextMessage(QJsonDocument(json).toJson(QJsonDocument::Compact)); if (bytes < json.length()) { qDebug() << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; } m_uid++; } void DDPClient::onTextMessageReceived(QString message) { QJsonDocument response = QJsonDocument::fromJson(message.toUtf8()); if (!response.isNull() && response.isObject()) { QJsonObject root = response.object(); + QString messageType = root.value("msg").toString(); if (messageType == "updated") { - } else if (messageType == "result") { + } else if (messageType == "result") { + unsigned id = root.value("id").toString().toInt(); - if (m_callbackHash.contains(id)) { - std::function callback = m_callbackHash.take(id); + if (m_callbackHash.contains(id)) { + std::function callback = m_callbackHash.take(id); - callback( QJsonDocument(root.value("result").toObject()) ); - } + callback( QJsonDocument(root.value("result").toObject()) ); + } emit result(id, QJsonDocument(root.value("result").toObject())); if (id == m_loginJob) { - if (root.value("error").toObject().value("error").toInt() == 403) { + + if (root.value("error").toObject().value("error").toInt() == 403) { qDebug() << "Wrong password or token expired"; - + login(); // Let's keep trying to log in - } else { + } else { Ruqola::self()->setAuthToken(root.value("result").toObject().value("token").toString()); - setLoginStatus(DDPClient::LoggedIn); - } + } } - } else if (messageType == "connected") { qDebug() << "Connected"; m_connected = true; emit connectedChanged(); setLoginStatus(DDPClient::LoggingIn); + //Ruqola::self()->authentication()->OAuthLogin(); + login(); // Try to resume auth token login } else if (messageType == "error") { qDebug() << "ERROR!!" << message; } else if (messageType == "ping") { qDebug() << "Ping - Pong"; QJsonObject pong; pong["msg"] = "pong"; m_webSocket.sendBinaryMessage(QJsonDocument(pong).toJson(QJsonDocument::Compact)); } else if (messageType == "added"){ qDebug() << "ADDING" <password().isEmpty()) { - + // If we have a password and we couldn't log in, let's stop here if (m_attemptedPasswordLogin) { setLoginStatus(LoginFailed); return; } - m_attemptedPasswordLogin = true; QJsonObject user; user["username"] = Ruqola::self()->userName(); QJsonObject json; json["password"] = Ruqola::self()->password(); json["user"] = user; m_loginJob = method("login", QJsonDocument(json)); - } else if (!Ruqola::self()->authToken().isEmpty() && !m_attemptedTokenLogin) { m_attemptedPasswordLogin = true; QJsonObject json; json["resume"] = Ruqola::self()->authToken(); m_loginJob = method("login", QJsonDocument(json)); } else { setLoginStatus(LoginFailed); } } -void DDPClient::logOut() -{ - m_webSocket.close(); -} - void DDPClient::onWSConnected() { qDebug() << "Websocket connected at URL" << m_url; QJsonArray supportedVersions; supportedVersions.append("1"); QJsonObject protocol; protocol["msg"] = "connect"; protocol["version"] = "1"; protocol["support"] = supportedVersions; QByteArray serialize = QJsonDocument(protocol).toJson(QJsonDocument::Compact); qint64 bytes = m_webSocket.sendTextMessage(serialize); if (bytes < serialize.length()) { - qDebug() << "ERROR! I couldn't send all of my message. This is a bug! (try again)"; + qDebug() << "onWSConnected: ERROR! I couldn't send all of my message. This is a bug! (try again)"; } else { qDebug() << "Successfully sent " << serialize; } } -void DDPClient::WSclosed() +void DDPClient::onWSclosed() { qDebug() << "WebSocket CLOSED" << m_webSocket.closeReason() << m_webSocket.error() << m_webSocket.closeCode(); setLoginStatus(NotConnected); } diff --git a/src/ddpclient.h b/src/ddpclient.h index 69414999..e143fd90 100644 --- a/src/ddpclient.h +++ b/src/ddpclient.h @@ -1,198 +1,204 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef DDPCLIENT_H #define DDPCLIENT_H -// #include -// #include -// #include - #include #include #include class QJsonObject; class QJsonDocument; class QUrl; class QWebSocket; class DDPClient : public QObject { Q_OBJECT public: enum LoginStatus { NotConnected, LoggingIn, LoggedIn, LoginFailed, LoggedOut }; Q_ENUM(LoginStatus) enum MessageType { Persistent, Ephemeral }; + enum LoginType { + Password, + Google + }; + DDPClient(const QString &url = QString(), QObject *parent = 0); ~DDPClient(); /** * @brief Call a method with name @param method and parameters @param params and @param messageType with an empty callback * * @param method The name of the method to call Rocket.Chat API for * @param params The parameters * @param messageType The type of message * @return unsigned int, the ID of the called method */ unsigned method(const QString &method, const QJsonDocument ¶ms, DDPClient::MessageType messageType = DDPClient::Ephemeral); /** * @brief Send message over network * * @param method The name of the method to call Rocket.Chat API for * @param params The parameters * @param callback The pointer to callback function * @param messageType The type of message * @return unsigned int, the ID of the called method */ unsigned method(const QString &method, const QJsonDocument ¶ms, std::function callback, DDPClient::MessageType messageType = DDPClient::Ephemeral); /** * @brief Subscribes to a collection with name @param collection and parameters @param params * * @param collection The name of the collection * @param params The parameters */ void subscribe(const QString &collection, const QJsonArray ¶ms); /** * @brief Calls method to log in the user with valid username and password */ Q_INVOKABLE void login(); /** * @brief Closes the websocket connection */ void logOut(); /** * @brief Check whether websocket is connected at url * * @return true if connected, else false */ bool isConnected() const; /** * @brief Check whether user is logged in * * @return true if user is logged in, else false */ bool isLoggedIn() const; /** * @brief Reconnects the websocket to new url */ void onServerURLChange(); /** * @brief Returns the queue used to cache unsent messages * *@return QQueue>, The m_messageQueue object */ QQueue> messageQueue(); /** * @brief Returns standard cache path * *@def QString path */ QString cachePath() const; signals: void connectedChanged(); void loginStatusChanged(); + void loginTypeChanged(); void disconnected(); void added(QJsonObject item); void changed(QJsonObject item); /** * @brief Emitted whenever a result is received * * @param id The ID received in the method() call * @param result The response sent by server */ void result(unsigned id, QJsonDocument result); private slots: void onWSConnected(); void onTextMessageReceived(QString message); - void WSclosed(); + void onWSclosed(); private: LoginStatus loginStatus() const; void setLoginStatus(LoginStatus l); + LoginType loginType() const; + Q_INVOKABLE void setLoginType(LoginType t); + void resume_login_callback(QJsonDocument doc); QString m_url; QWebSocket m_webSocket; /** * @brief Unique message ID for each message sent over network */ unsigned m_uid; /** * @brief Stores callback function associated with each message * * @def QHash unsigned messageID and std::function pointer to callback */ QHash > m_callbackHash; unsigned m_loginJob; LoginStatus m_loginStatus; + LoginType m_loginType; bool m_connected; bool m_attemptedPasswordLogin; bool m_attemptedTokenLogin; /** * @brief Abstract queue for all requests regarding network management * * @def QPair QString method and QJsonDocument params */ QQueue> m_messageQueue; friend class Ruqola; }; // #include "ddpclient.moc" #endif // DDPCLIENT_H diff --git a/src/notification.h b/src/notification.h index de31c493..6c454e56 100644 --- a/src/notification.h +++ b/src/notification.h @@ -1,55 +1,54 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef NOTIFICATION_H #define NOTIFICATION_H #include #include #include class Notification: public QSystemTrayIcon { Q_OBJECT public: Notification(); private: - /** * @brief Create actions to be displayed in tray icon menu */ void createActions(); /** * @brief Creates tray icon consisting of actions */ void createTrayIcon(); QAction *m_quitAction; QMenu *m_trayIconMenu; }; #endif // NOTIFICATION_H diff --git a/src/rocketchatbackend.h b/src/rocketchatbackend.h index 923da37b..ebf9597a 100644 --- a/src/rocketchatbackend.h +++ b/src/rocketchatbackend.h @@ -1,58 +1,59 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef ROCKETCHATBACKEND_H #define ROCKETCHATBACKEND_H #include #include #include "roommodel.h" class DDPClient; class RocketChatBackend : public QObject { Q_OBJECT public: RocketChatBackend(QObject *parent = 0); ~RocketChatBackend(); /** * @brief Adds incoming message from server to appropriate room * * @param messages The Json containing the message */ static void processIncomingMessages(QJsonArray messages); private slots: void onAdded(QJsonObject object); void onChanged(QJsonObject object); void onLoggedIn(); void onLoginStatusChanged(); void onUserIDChanged(); private: // RoomModel *m_rooms; + }; #endif // ROCKETCHATBACKEND_H diff --git a/src/roommodel.h b/src/roommodel.h index a212f752..cf2f1c0c 100644 --- a/src/roommodel.h +++ b/src/roommodel.h @@ -1,219 +1,209 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef ROOMMODEL_H #define ROOMMODEL_H #include #include class Room { public: -// Room(const Room &room) -// { -// // this->parent = room.parent(); -// } // To be used in ID find: message ID inline bool operator==(const Room &other) const { return other.id == id; } + // To be used in sorted insert: timestamp inline bool operator<(const Room &other) const { return name < other.name; } /** * @brief Return room name * * @return QString, The name of the room */ QString getName() const { return name; } /** * @brief Return topic name * * @return QString, The name of the topic of room */ QString getTopic() const { return topic; } -// private: -// friend class RoomModel; -// friend class RoomWrapper; - - -// When you add a field, please remember to also add relevant code -// to the enum declaration, roleNames, fromJSon and serialize - //Room Object Fields // _id QString id; // t (can take values "d" , "c" or "p") QString type; // name QString name; // u QString userName; QString userID; // topic QString topic; // muted - collection of muted users by its usernames QString mutedUsers; //QStringList // jitsiTimeout qint64 jitsiTimeout; // ro - read-only chat or not bool ro; int unread; bool selected = false; }; class RoomWrapper : public QObject { Q_PROPERTY(QString name READ getName NOTIFY nameChanged) Q_PROPERTY(QString topic READ getTopic NOTIFY topicChanged) Q_OBJECT public: RoomWrapper(QObject *parent = 0); RoomWrapper(const Room &r, QObject *parent = 0); QString getName() { return m_name; } QString getTopic() { return m_topic; } signals: void nameChanged(); void topicChanged(); private: QString m_name, m_topic, m_id; int m_unread; bool m_selected; }; class RoomModel : public QAbstractListModel { Q_OBJECT public: enum RoomRoles { RoomName = Qt::UserRole + 1, RoomSelected, RoomID, RoomUnread, RoomType, RoomUserName, //created by UserName RoomUserID, RoomTopic, RoomMuted, RoomJitsiTimeout, RoomRO }; RoomModel(QObject *parent = 0); virtual ~RoomModel(); virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; // void setCurrentRoom(const QString &newRoom); // QString getCurrentRoom() const; /** * @brief Constructs room object from @param roomID and @param roomName and @param selected, then calls @method addRoom * * @param roomID The unique room ID * @param roomName The name of the room * @param selected True if room if @param roomID is selected, else false */ Q_INVOKABLE void addRoom(const QString& roomID, const QString& roomName, bool selected = false); /** * @brief Adds a room to m_roomsList with @param room * * @param room The room to be added */ void addRoom(const Room& room); /** * @brief Finds a room with @param roomID in m_roomsList * * @param roomID The ID of the room to find * @return RoomWrapper Pointer, The pointer to room with @param roomID in m_roomsList, if exists. Else return a new RoomWrapper object */ RoomWrapper* findRoom(const QString &roomID) const; /** * @brief Constructs Message object from QJsonObject * * @param source The Json containing room attributes * @return Room object, The room constructed from Json */ static Room fromJSon(const QJsonObject &source); /** * @brief Constructs QBytearray from Message object * * @param message The Room object * @return QByteArray, The Json containing room attributes */ static QByteArray serialize(const Room &r); -// void setActiveRoom(const QString &activeRoom); -//Clear data and refill it with data in the cache, if there is + //void setActiveRoom(const QString &activeRoom); + + //Clear data and refill it with data in the cache, if there is void reset(); void clear(); protected: virtual QHash roleNames() const; private: QVector m_roomsList; -// QHash< QString, Room > m_roomsHash; + //QHash< QString, Room > m_roomsHash; }; #endif // ROOMMODEL_H diff --git a/src/ruqola.cpp b/src/ruqola.cpp index 3f2999e1..b4b0a7cf 100644 --- a/src/ruqola.cpp +++ b/src/ruqola.cpp @@ -1,315 +1,323 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "ruqola.h" #include "roommodel.h" #include "ddpclient.h" #include "notification.h" #include "messagequeue.h" #include #include #include #include Ruqola *Ruqola::m_self = 0; QString Ruqola::authToken() const { return m_authToken; } QString Ruqola::userName() const { return m_userName; } QString Ruqola::userID() const { return m_userID; } QString Ruqola::password() const { return m_password; } void Ruqola::setAuthToken(const QString& token) { qDebug() << "Setting token to" << token; QSettings s; m_authToken = token; s.setValue("authToken", token); } void Ruqola::setPassword(const QString& password) { m_password = password; } void Ruqola::setUserName(const QString& username) { m_userName = username; QSettings s; s.setValue("username", username); emit userNameChanged(); } void Ruqola::setUserID(const QString& userID) { m_userName = userID; QSettings s; s.setValue("userID", userID); emit userIDChanged(); } RoomModel * Ruqola::roomModel() { if (!m_roomModel) { qDebug() << "creating new RoomModel"; m_roomModel = new RoomModel(this); qDebug() << m_roomModel; } return m_roomModel; } DDPClient * Ruqola::ddp() { if (!m_ddp) { m_ddp = new DDPClient(serverURL()); connect(m_ddp, &DDPClient::loginStatusChanged, this, &Ruqola::loginStatusChanged); } return m_ddp; } MessageQueue * Ruqola::messageQueue() { if (!m_messageQueue) { m_messageQueue = new MessageQueue(); // retry to send any unsent messages Ruqola::self()->messageQueue()->processQueue(); } return m_messageQueue; } Notification * Ruqola::notification() { if (!m_notification) { m_notification = new Notification(); m_notification->show(); } return m_notification; } Authentication * Ruqola::authentication() { if (!m_authentication) { m_authentication = new Authentication(); } return m_authentication; } void Ruqola::attachmentButtonClicked() { QString fileName = QFileDialog::getOpenFileName(Q_NULLPTR, "Select one or more files to open", QDir::homePath(), "Images (*.png *.jpeg *.jpg)"); qDebug() << "Selected Image " << fileName; QFile file(fileName); if (!file.open(QFile::ReadOnly)) { qDebug() << "Cannot open the selected file"; return; } const QString message = QString::fromLatin1(file.readAll().toBase64()); const QString roomID("3cGRyFLWgnPL7B79n"); //hard code roomID for now const QString type("image"); sendMessage(roomID, message, type); } void Ruqola::sendMessage(const QString &roomID, const QString &message, const QString &type) { QJsonObject json; json["rid"] = roomID; json["msg"] = message; json["type"] = type; ddp()->method("sendMessage", QJsonDocument(json), DDPClient::Persistent); } MessageModel * Ruqola::getModelForRoom(const QString& roomID) { if (m_messageModels.contains(roomID)) { return m_messageModels.value(roomID); } else { m_messageModels[roomID] = new MessageModel(roomID, this); return m_messageModels[roomID]; } } QString Ruqola::serverURL() const { return m_serverURL; } void Ruqola::setServerURL(const QString& serverURL) { if (m_serverURL == serverURL) { return; } QSettings s; s.setValue("serverURL", serverURL); m_serverURL = serverURL; emit serverURLChanged(); } DDPClient::LoginStatus Ruqola::loginStatus() { if (m_ddp) { return ddp()->loginStatus(); } else { return DDPClient::LoggedOut; } } + void Ruqola::tryLogin() { qDebug() << "Attempting login" << userName() << "on" << serverURL(); // Reset model views foreach (const QString key, m_messageModels.keys()) { MessageModel *m = m_messageModels.take(key); delete m; } delete m_ddp; m_ddp = 0; - // In the meantime, load cache... - m_roomModel->reset(); - // This creates a new ddp() object. // DDP will automatically try to connect and login. ddp(); + + // In the meantime, load cache... + //if(Ruqola::self()->ddp()->isConnected() && Ruqola::self()->loginStatus() == DDPClient::LoggedIn) { + m_roomModel->reset(); + //} } void Ruqola::tryOAuthLogin() { // Reset model views foreach (const QString key, m_messageModels.keys()) { MessageModel *m = m_messageModels.take(key); delete m; } delete m_ddp; m_ddp = 0; - // In the meantime, load cache... + // This creates a new ddp() object. + // DDP will automatically try to connect and login. + ddp(); + m_roomModel->reset(); - ddp(); - m_authentication->OAuthLogin(); + if(Ruqola::self()->ddp()->isConnected()){ + m_authentication->OAuthLogin(); + } } void Ruqola::logOut() { QSettings s; s.setValue("authToken", QString("")); setAuthToken(QString("")); setPassword(QString("")); foreach (const QString key, m_messageModels.keys()) { MessageModel *m = m_messageModels.take(key); delete m; } m_roomModel->clear(); QJsonObject user; user["username"] = Ruqola::self()->userName(); QJsonObject json; json["user"] = user; Ruqola::self()->ddp()->method("logout", QJsonDocument(json)); delete m_ddp; m_ddp = 0; emit loginStatusChanged(); - qDebug() << "Successfully loged out!"; + qDebug() << "Successfully logged out!"; } QString Ruqola::cacheBasePath() const { if (m_serverURL.isEmpty()) { return QString(); } return QStandardPaths::writableLocation(QStandardPaths::CacheLocation)+'/'+m_serverURL; } RoomWrapper * Ruqola::getRoom(const QString& roomID) { return roomModel()->findRoom(roomID); } Ruqola::Ruqola(QObject* parent): QObject(parent), m_ddp(0), m_messageQueue(0), m_roomModel(0), m_notification(0), m_authentication(0) { QSettings s; m_serverURL = s.value("serverURL", "demo.rocket.chat").toString(); m_userName = s.value("username").toString(); m_userID = s.value("userID").toString(); m_authToken = s.value("authToken").toString(); } Ruqola * Ruqola::self() { if (!m_self) { m_self = new Ruqola; // Create DDP object so we try to connect at startup m_self->ddp(); // Clear rooms data and refill it with data in the cache, if there is m_self->roomModel()->reset(); // Create systray to show notifications m_self->notification(); //Initialize the messageQueue object m_self->messageQueue(); + //Initialize the OAuth object m_self->authentication(); } return m_self; } diff --git a/src/ruqola.h b/src/ruqola.h index c7d9c753..d36f87e9 100644 --- a/src/ruqola.h +++ b/src/ruqola.h @@ -1,165 +1,164 @@ /* * * Copyright 2016 Riccardo Iaconelli * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef USERDATA_H #define USERDATA_H #include #include #include #include "ddpclient.h" #include "roommodel.h" #include "messagemodel.h" #include "notification.h" #include "messagequeue.h" #include "authentication.h" class QString; class Ruqola: public QObject { Q_OBJECT Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) Q_PROPERTY(QString userID READ userID WRITE setUserID NOTIFY userIDChanged) Q_PROPERTY(QString serverURL READ serverURL WRITE setServerURL NOTIFY serverURLChanged) Q_PROPERTY(QString password WRITE setPassword) -// Q_PROPERTY (bool connected READ connected NOTIFY connectedChanged) Q_PROPERTY(DDPClient::LoginStatus loginStatus READ loginStatus NOTIFY loginStatusChanged) // Q_PROPERTY(QString activeRoom READ activeRoom WRITE setActiveRoom NOTIFY activeRoomChanged) public: /** * @brief Singleton provider * * @return Returns the singleton object m_self */ static Ruqola* self(); void setUserName(const QString &username); QString userName() const; void setUserID(const QString &userID); QString userID() const; void setPassword(const QString &password); QString password() const; void setAuthToken(const QString &token); QString authToken() const; bool connected(); DDPClient::LoginStatus loginStatus(); QString serverURL() const; void setServerURL(const QString &serverURL); // QString activeRoom() const; // void setActiveRoom(const QString &activeRoom); DDPClient *ddp(); Notification *notification(); MessageQueue *messageQueue(); Authentication *authentication(); Q_INVOKABLE RoomModel *roomModel(); /** * @brief Constructs a Json with @param roomID and @param message and @param type, then calls DDPClient's method to send text message over the network */ Q_INVOKABLE void sendMessage(const QString &roomID, const QString &message, const QString &type); /** * @brief Returns a model for room with ID @param roomID * * @return MessageModel Pointer, model for room */ Q_INVOKABLE MessageModel* getModelForRoom(const QString &roomID); /** * @brief Reset models, load cache and call DDPClient's object to automatically try to connect and log in via username and password */ Q_INVOKABLE void tryLogin(); /** * @brief Clear models, stores cache and logs out the user */ Q_INVOKABLE void logOut(); /** * @brief Reset models, load cache and call DDPClient's object to automatically try to connect and log in via Google account */ Q_INVOKABLE void tryOAuthLogin(); /** * @brief Finds room with @param roomID * * @return RoomWrapper Pointer, The room model for @param roomID */ Q_INVOKABLE RoomWrapper* getRoom(const QString &roomID); Q_INVOKABLE void attachmentButtonClicked(); /** * @brief Returns standard cache path * * @return QString, The standard cache path */ QString cacheBasePath() const; signals: void userNameChanged(); void userIDChanged(); void serverURLChanged(); void loginStatusChanged(); private: Ruqola(QObject *parent = 0); static Ruqola *m_self; QString m_password; QString m_userName; QString m_userID; QString m_authToken; QString m_serverURL; DDPClient *m_ddp; MessageQueue *m_messageQueue; RoomModel *m_roomModel; Notification *m_notification; Authentication *m_authentication; QHash< QString, MessageModel * > m_messageModels; }; inline static QObject *ruqola_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) Q_UNUSED(scriptEngine) Ruqola *userData = Ruqola::self(); return userData; } #endif // USERDATA_H