aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qml.qrc2
-rw-r--r--rwa-support-desktopapp.pro4
-rw-r--r--src/RWAHostModel.cpp37
-rw-r--r--src/RWAHostModel.h23
-rw-r--r--src/main.cpp14
-rw-r--r--src/main.qml27
-rw-r--r--src/main_qmladaptor.cpp94
-rw-r--r--src/main_qmladaptor.h18
-rw-r--r--src/scenes/add_server_wizard/add_server_wizard.cpp10
-rw-r--r--src/scenes/add_server_wizard/add_server_wizard.h5
-rw-r--r--src/session.cpp1
11 files changed, 225 insertions, 10 deletions
diff --git a/qml.qrc b/qml.qrc
index 5c8d030..07b6bd2 100644
--- a/qml.qrc
+++ b/qml.qrc
@@ -17,6 +17,8 @@
<file>src/session.h</file>
<file>src/RWAHost.h</file>
<file>src/RWAHost.cpp</file>
+ <file>src/RWAHostModel.h</file>
+ <file>src/RWAHostModel.cpp</file>
<file>src/DBusAPI.h</file>
<file>src/DBusAPI.cpp</file>
<file>src/ListItem.qml</file>
diff --git a/rwa-support-desktopapp.pro b/rwa-support-desktopapp.pro
index 5c3f24d..a15c4bd 100644
--- a/rwa-support-desktopapp.pro
+++ b/rwa-support-desktopapp.pro
@@ -48,14 +48,16 @@ SOURCES += src/main.cpp \
src/RWADBusAdaptor.cpp \
src/session.cpp \
src/scenes/add_server_wizard/add_server_wizard.cpp \
+ src/RWAHostModel.cpp \
src/RWAHost.cpp \
- src/DBusAPI.cpp
+ src/DBusAPI.cpp \
HEADERS += src/RWADBusAdaptor.h \
src/main_qmladaptor.h \
src/RWADBusAdaptor.h \
src/session.h \
src/scenes/add_server_wizard/add_server_wizard.h \
+ src/RWAHostModel.h \
src/RWAHost.h \
src/DBusAPI.h
diff --git a/src/RWAHostModel.cpp b/src/RWAHostModel.cpp
new file mode 100644
index 0000000..5f62adc
--- /dev/null
+++ b/src/RWAHostModel.cpp
@@ -0,0 +1,37 @@
+#include "RWAHostModel.h"
+
+RWAHostModel::RWAHostModel(QObject *parent) {
+ Q_UNUSED(parent)
+}
+
+int RWAHostModel::rowCount(const QModelIndex& parent) const {
+ Q_UNUSED(parent);
+ return mDatas.size();
+}
+
+int RWAHostModel::columnCount(const QModelIndex& parent) const {
+ Q_UNUSED(parent);
+ return 1;
+}
+
+QVariant RWAHostModel::data(const QModelIndex &index, int role) const
+ {
+ if (!index.isValid())
+ return QVariant();
+ if ( role == Qt::DisplayRole) {
+ return mDatas[index.row()];
+ }
+ return QVariant();
+}
+
+void RWAHostModel::populate() {
+ beginResetModel();
+ mDatas.clear();
+ RWAHost *host1 = new RWAHost("uuid-1", "Erster Server", "url1");
+ RWAHost *host2 = new RWAHost("uuid-2", "Zweiter Server", "url2");
+ RWAHost *host3 = new RWAHost("uuid-3", "Dritter Server", "url3");
+ mDatas.append(host1->alias());
+ mDatas.append(host2->alias());
+ mDatas.append(host3->alias());
+ endResetModel();
+}
diff --git a/src/RWAHostModel.h b/src/RWAHostModel.h
new file mode 100644
index 0000000..8697df2
--- /dev/null
+++ b/src/RWAHostModel.h
@@ -0,0 +1,23 @@
+#ifndef RWAHOSTMODEL_H
+#define RWAHOSTMODEL_H
+
+#include <QObject>
+#include <QAbstractListModel>
+
+#include "RWAHost.h"
+
+class RWAHostModel : public QAbstractListModel {
+ Q_OBJECT
+
+public:
+ explicit RWAHostModel(QObject * parent = nullptr);
+ int rowCount(const QModelIndex& parent = QModelIndex()) const;
+ int columnCount(const QModelIndex& parent = QModelIndex()) const;
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+ void populate();
+
+private:
+ QStringList mDatas;
+};
+
+#endif // RWAHOSTMODEL_H
diff --git a/src/main.cpp b/src/main.cpp
index 3339840..b85c3fc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -39,6 +39,7 @@
#include "RWADBusAdaptor.cpp"
#include "session.h"
#include "scenes/add_server_wizard/add_server_wizard.h"
+#include "RWAHostModel.h"
#include "RWAHost.h"
#define BUILD_TIME __DATE__ " " __TIME__
@@ -86,6 +87,13 @@ int main(int argc, char *argv[]) {
// Make mainqmladaptor available to QML
engine.rootContext()->setContextProperty("mainqmladaptor", main_gui.data());
+ QScopedPointer<DBusAPI> _dbus_api (new DBusAPI());
+ QObject::connect(_dbus_api.data(),
+ SIGNAL(serviceGetWebAppHostsResponse(QJsonDocument*)),
+ main_gui.data(),
+ SLOT(get_web_app_hosts_response(QJsonDocument*)));
+ _dbus_api.data()->get_web_app_hosts_request();
+
engine.load(QUrl(QStringLiteral("qrc:/src/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
@@ -102,9 +110,13 @@ int main(int argc, char *argv[]) {
engine.rootObjects().takeFirst(),
SLOT(showWindow()));
- QScopedPointer<Add_Server_wizard> wizard (new Add_Server_wizard(&app));
+ QObject::connect(engine.rootObjects().takeFirst()->findChild<QObject*>("sidebar_drawer"),
+ SIGNAL(rwaHostSelected(QString)),
+ main_gui.data(),
+ SLOT(onRwaHostSelected(QString)));
// Make add_server_wizard available to QML
+ QScopedPointer<Add_Server_wizard> wizard (new Add_Server_wizard(&app, main_gui.data()));
engine.rootContext()->setContextProperty("add_server_wizard", wizard.data());
return app.exec();
diff --git a/src/main.qml b/src/main.qml
index 3574a8c..8a19d54 100644
--- a/src/main.qml
+++ b/src/main.qml
@@ -182,8 +182,9 @@ ApplicationWindow {
*/
Drawer {
id: sidebar_drawer
- y: top_menu_bar_frame.height
+ objectName: "sidebar_drawer"
+ y: top_menu_bar_frame.height
width: !inPortrait ? Math.min(300, Math.max(200, window.width * 0.333)) : (window.width * 0.5)
height: window.height - top_menu_bar_frame.height
@@ -194,6 +195,9 @@ ApplicationWindow {
margins: -2
visible: !inPortrait
+ signal rwaHostSelected(string host_uuid)
+ property bool rwaHostIsSelected: false
+
ListView {
id: sidebar_listview
boundsBehavior: Flickable.StopAtBounds
@@ -202,6 +206,21 @@ ApplicationWindow {
anchors.fill: parent
model: mainModel
+ header: ComboBox {
+ id: server_chooser
+ objectName: "server_chooser"
+ width: parent.width
+ height: 50
+ model: mainqmladaptor.rwaHostModel
+
+ textRole: "alias"
+ onCurrentIndexChanged: {
+ var rwa_host = mainqmladaptor.rwaHostModel
+ sidebar_drawer.rwaHostSelected(rwa_host[currentIndex].uuid)
+ sidebar_drawer.rwaHostIsSelected = true
+ }
+ }
+
footer: ItemDelegate {
id: footer
text: " " + qsTr("Settings")
@@ -234,6 +253,9 @@ ApplicationWindow {
main_content_replace(scene_url, StackView.Transition)
}
+
+ // Disabled till a RWAHost object is selected.
+ enabled: sidebar_drawer.rwaHostIsSelected
}
ListItem {
text: " " + qsTr("Remote View")
@@ -244,6 +266,9 @@ ApplicationWindow {
main_content_replace(scene_url, StackView.Transition)
}
+
+ // Disabled till a RWAHost object is selected.
+ enabled: sidebar_drawer.rwaHostIsSelected
}
ListItem {
text: " " + qsTr("Add RWA-Server")
diff --git a/src/main_qmladaptor.cpp b/src/main_qmladaptor.cpp
index b34c9d4..d75b15c 100644
--- a/src/main_qmladaptor.cpp
+++ b/src/main_qmladaptor.cpp
@@ -30,6 +30,100 @@ MainQMLAdaptor::MainQMLAdaptor(QObject *parent, QQmlApplicationEngine* engine) :
Q_ASSERT(engine != nullptr);
_engine = engine;
+ _rwaHostModel = new QList<QObject*>;
+}
+
+void MainQMLAdaptor::onRwaHostSelected(QString host_uuid) {
+ Q_ASSERT(host_uuid != "");
+
+ RWAHost *_host = nullptr;
+ for (int i = 0; i < getRWAHostModel().size(); i++) {
+ QObject *obj = getRWAHostModel().value(i);
+ RWAHost *host = qobject_cast<RWAHost *>(obj);
+ Q_ASSERT(host != nullptr);
+
+ if (host->uuid() == host_uuid) {
+ _host = host;
+ }
+ }
+ Q_ASSERT(_host != nullptr);
+
+ qDebug() << "RWAHost was selected!" << _host->uuid() << "aka" << _host->alias();
+}
+
+void MainQMLAdaptor::setRWAHostModel(QList<QObject*> rwa_hosts) {
+
+ _rwaHostModel = &rwa_hosts;
+ emit rwaHostModelChanged(rwa_hosts);
+}
+
+void MainQMLAdaptor::addRWAHost(RWAHost *rwa_host) {
+ _rwaHostModel->append(rwa_host);
+ emit rwaHostModelChanged(*_rwaHostModel);
+}
+
+QList<QObject*> MainQMLAdaptor::getRWAHostModel() {
+ return *_rwaHostModel;
+}
+
+void MainQMLAdaptor::get_web_app_hosts_response(QJsonDocument *doc) {
+ Q_ASSERT(doc != nullptr);
+
+ // Get the QJsonObject
+ QJsonObject jObject = doc->object();
+ QVariantMap mainMap = jObject.toVariantMap();
+
+ // Status of request
+ QString request_status = mainMap["status"].toString();
+ if (request_status == "success") {
+ // Building host_objects
+ QJsonArray host_objects = jObject.value("hosts").toArray();
+
+ foreach (const QJsonValue &host_object, host_objects) {
+ QString host_uuid = host_object["uuid"].toString();
+ QString host_alias = host_object["alias"].toString();
+ QString host_url = host_object["url"].toString();
+
+ if (host_url == "" || host_uuid == "") {
+ // This two values are required and can't be omitted.
+ QString reason = tr("A host object in the response of D-Bus "
+ "service lacks a necessary value. (host_url or host_uuid)");
+ qCritical().noquote() << tr("An error occured while adding a new host:")
+ << reason;
+ //emit step1Failed(reason);
+
+ return;
+ }
+
+ if (host_alias == "") {
+ qDebug().noquote() << QString("An alias for the host wasn't delivered "
+ "so just use '%0' as alias.").arg(host_url);
+ host_alias = host_url;
+ }
+
+ // Now built RWAHost object.
+ RWAHost *rwa_host = new RWAHost(host_uuid, host_alias, host_url);
+ addRWAHost(rwa_host);
+
+ qInfo().noquote() << QString(tr("Successfully added new RWAHost '%0'")).arg(rwa_host->alias());
+ }
+ } else {
+ QString reason = tr("An error occured while adding a new host:");
+ qCritical().noquote() << reason;
+
+ QString type = mainMap["type"].toString();
+ if (type != "") {
+ reason = QString(tr("The error is not clear. The session service "
+ "responded with status type '%0'")).arg(type);
+ qCritical().noquote() << reason;
+ } else {
+ reason = QString(tr("The error is not clear. The session service "
+ "responded with no status type!"));
+ qCritical().noquote() << reason;
+ }
+
+ return;
+ }
}
bool MainQMLAdaptor::setConnectButtonEnabled(bool enabled) {
diff --git a/src/main_qmladaptor.h b/src/main_qmladaptor.h
index 3c6e75b..8701fc9 100644
--- a/src/main_qmladaptor.h
+++ b/src/main_qmladaptor.h
@@ -32,11 +32,18 @@
#include <QMessageBox>
#include <QApplication>
#include <QClipboard>
+#include <QJsonObject>
+#include <QJsonDocument>
+#include <QJsonArray>
+
+#include "RWAHost.h"
class MainQMLAdaptor : public QObject
{
Q_OBJECT
// this makes url available as a QML property
+ Q_PROPERTY(QList<QObject*> rwaHostModel READ getRWAHostModel WRITE setRWAHostModel NOTIFY rwaHostModelChanged)
+ // this makes url available as a QML property
Q_PROPERTY(QString url READ getURL WRITE setURL NOTIFY urlChanged)
// this makes pin available as a QML property
Q_PROPERTY(QString pin READ getPin WRITE setPin NOTIFY pinChanged)
@@ -67,6 +74,7 @@ public:
QString getMessageDialogText();
QMessageBox::Icon getMessageDialogIcon();
bool getShowMessageDialog();
+
signals:
void showMessageDialogChanged(bool show);
void messageDialogTextChanged(QString text);
@@ -82,6 +90,8 @@ signals:
void urlChanged(QString URL);
void sessionIDChanged(QString session_id);
+ void rwaHostModelChanged(QList<QObject*>);
+
void onCloseSignal();
void showToastSignal(QString text, QString durationMs);
@@ -90,6 +100,8 @@ protected:
QString _url;
QString _pin;
QString _session_id;
+ QList<QObject*>* _rwaHostModel;
+
private:
QQmlApplicationEngine* _engine;
@@ -102,13 +114,19 @@ public slots:
void handleCopyToClipboardButtonClick(QString copy_data);
void handleConnectButtonClick(bool checked);
+ void get_web_app_hosts_response(QJsonDocument *doc);
+
void setPin(QString pin);
void setURL(QString URL);
void setSessionID(QString session_id);
+ void setRWAHostModel(QList<QObject*>);
+ void addRWAHost(RWAHost *rwa_host);
QString getURL();
QString getPin();
QString getSessionID();
+ QList<QObject*> getRWAHostModel();
+ void onRwaHostSelected(QString host_uuid);
void onCloseHandler();
void showToast(QString text, uint durationMs = 3000);
diff --git a/src/scenes/add_server_wizard/add_server_wizard.cpp b/src/scenes/add_server_wizard/add_server_wizard.cpp
index bd1dd3c..d06108c 100644
--- a/src/scenes/add_server_wizard/add_server_wizard.cpp
+++ b/src/scenes/add_server_wizard/add_server_wizard.cpp
@@ -23,16 +23,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-#include <QDebug>
-#include <QtDBus>
-#include <QDBusPendingCallWatcher>
-
#include "add_server_wizard.h"
#include "../../RWADBusAdaptor.h"
#include "../../RWAHost.h"
-Add_Server_wizard::Add_Server_wizard(QObject *parent) : QObject(parent) {
+Add_Server_wizard::Add_Server_wizard(QObject *parent, MainQMLAdaptor *main_gui) : QObject(parent) {
+ Q_ASSERT(main_gui != nullptr);
+
_dbus_api = new DBusAPI();
+ _main_gui = main_gui;
// _dbus_api --serviceAddWebAppHostResponse-> this.add_web_app_host_response()
QObject::connect(_dbus_api,
@@ -96,6 +95,7 @@ void Add_Server_wizard::add_web_app_host_response(QJsonDocument *doc) {
// Now built RWAHost object.
QScopedPointer<RWAHost> rwa_host (new RWAHost(host_uuid, host_alias, host_url));
+ _main_gui->addRWAHost(rwa_host.data());
qInfo() << "Successfully added a new RWAHost.";
emit step1Success();
diff --git a/src/scenes/add_server_wizard/add_server_wizard.h b/src/scenes/add_server_wizard/add_server_wizard.h
index 554f6af..e4d62df 100644
--- a/src/scenes/add_server_wizard/add_server_wizard.h
+++ b/src/scenes/add_server_wizard/add_server_wizard.h
@@ -30,16 +30,19 @@
#include "../../RWADBusAdaptor.h"
#include "../../DBusAPI.h"
+#include "../../main_qmladaptor.h"
class Add_Server_wizard : public QObject
{
Q_OBJECT
public:
- explicit Add_Server_wizard(QObject *parent = nullptr);
+ explicit Add_Server_wizard(QObject *parent = nullptr,
+ MainQMLAdaptor *main_gui = nullptr);
void add_server(QString host_url);
private:
DBusAPI *_dbus_api;
+ MainQMLAdaptor *_main_gui;
signals:
void step1Success();
diff --git a/src/session.cpp b/src/session.cpp
index 14b6575..32aca7d 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -82,7 +82,6 @@ Session::Session(QObject *parent, MainQMLAdaptor* main_gui, RWAHost *host) : QOb
this,
SLOT(status_response(QJsonDocument*)));
-
this->init_vars();
}