Commit 3cf51e78 authored by Viktor Porvaznik's avatar Viktor Porvaznik Committed by Viktor Porvaznik

Some work DBUS data transfer

parent c43add6b
......@@ -25,10 +25,11 @@
#include <QStandardItemModel>
#include <KAboutData>
#include <KLocalizedString>
#include <QDBusPendingReply>
#include <KLocalizedContext>
#include <KDBusService>
#include <QtQml>
#include "interfaces/dbusinterfaces.h"
class TableModel : public QAbstractTableModel
{
......@@ -39,6 +40,7 @@ private:
public:
TableModel() {
loadModel();
qDebug() << m_data << endl;
}
......@@ -97,6 +99,11 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override
{
QJsonObject newObject = m_data.at(index.row()).toObject();
newObject.insert(s_syncTableColumns[(role - Qt::UserRole)], value.toString());
m_data.replace(index.row(), newObject);
saveModel(m_data);
qDebug() << " SetData at " << index.row() << ";" << index.column() << ";" << role << value << endl;
switch (role) {
case Qt::EditRole:
......@@ -122,15 +129,38 @@ public:
}
public Q_SLOTS:
bool insertADefaultRow()
{
loadModel();
bool retValue = insertRows(rowCount(), 1);
saveModel(m_data);
return retValue;
};
bool removeSelectedRow(int row)
{
bool retValue = removeRows(row, 1);
saveModel(m_data);
return retValue;
};
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
{
beginRemoveRows(parent, row, row + (count - 1));
m_data.removeAt(row);
endRemoveRows();
return true;
};
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
{
beginInsertRows(parent, rowCount(), rowCount());
beginInsertRows(parent, row, row + (count - 1));
QJsonObject rowData;
rowData.insert("localPath", "");
rowData.insert("remotePath", "");
rowData.insert("direction", "DEFAULT");
rowData.insert("postSyncScript", "");
m_data.append(rowCount());
m_data.append(rowData);
endInsertRows();
return true;
};
......@@ -145,6 +175,37 @@ public Q_SLOTS:
m_data.append(row);
qDebug() << m_data << endl;
}
void saveModel(const QJsonArray& model)
{
qDebug() << model << endl;
}
void loadModel()
{
qDebug() << "Loading model" << endl;
FileSyncAppInterface *fileSyncAppInterface = new FileSyncAppInterface(this);
QDBusPendingReply<QVariantList> reply = fileSyncAppInterface->getConfiguration();
reply.waitForFinished();
if (reply.isValid())
{
QVariantList result = reply.value();
// QDBusVariant dbusVariant = qvariant_cast<QDBusVariant>(reply.value());
// QVariant result2 = dbusVariant.variant();
qDebug() << "Loaded model" << result << endl;
// retrieve the D-Bus variant
// retrieve the actual value stored in the D-Bus variant
// m_data = QJsonArray::fromVariantList(reply.value());
}
qDebug() << "Loaded model" << endl;
qDebug() << m_data << endl;
}
};
const QStringList TableModel::s_syncTableColumns = QStringList({"localPath", "remotePath", "direction", "postSyncScript"});
......@@ -164,8 +225,8 @@ int main(int argc, char *argv[])
TableModel *syncTableModel = new TableModel();
syncTableModel->addSyncItem("test1", "test2", "ONLY_DOWNLOAD", "test3");
syncTableModel->addSyncItem("t22est1", "te222st2", "NEWEST", "te2333st3");
// syncTableModel->addSyncItem("test1", "test2", "ONLY_DOWNLOAD", "test3");
// syncTableModel->addSyncItem("t22est1", "te222st2", "NEWEST", "te2333st3");
// QStandardItemModel syncTableModel(1,1,&app);
// syncTableModel.setHorizontalHeaderLabels(QStringList({QString("label1"), QString("label1"), QString("label1")}));
// QList<QStandardItem *> row;
......
......@@ -76,14 +76,19 @@ ApplicationWindow {
Menu {
id: contextMenu
property int selectedRow: -1
MenuItem {
text: qsTr('Add new row')
onTriggered: {
syncTableModel.insertRows(0,0)
syncTableModel.insertADefaultRow()
}
}
MenuItem {
text: qsTr('Delete this row')
onTriggered: {
console.log("Removing row " + contextMenu.selectedRow)
syncTableModel.removeSelectedRow(contextMenu.selectedRow)
}
}
}
......@@ -106,6 +111,9 @@ ApplicationWindow {
else if (mouse.button == Qt.RightButton)
{
console.log("Right" +styleData.row)
if (styleData.row) {
contextMenu.selectedRow = styleData.row
}
contextMenu.popup()
}
}
......@@ -116,15 +124,13 @@ ApplicationWindow {
title: "Local path"
width: 200
resizable: true
delegate: Quick.Item {
Quick.TextEdit {
id: textEdit
padding: 5
color: "lightsteelblue"
delegate: Quick.TextEdit {
padding: 5
color: "white"
anchors.fill: parent
selectByMouse: true
text: model.localPath
onEditingFinished: model.localPath = text
}
text: model.localPath
onEditingFinished: model.localPath = text
}
}
TableViewColumn {
......@@ -132,9 +138,8 @@ ApplicationWindow {
width: 200
resizable: true
delegate: Quick.TextEdit {
id: textEdit
padding: 5
color: "lightsteelblue"
color: "white"
text: model.remotePath
onEditingFinished: model.remotePath = text
}
......@@ -144,9 +149,10 @@ ApplicationWindow {
resizable: true
width: 200
delegate: Quick.TextEdit {
id: textEdit
padding: 5
color: "lightsteelblue"
color: "white"
anchors.fill: parent
selectByMouse: true
text: model.direction
onEditingFinished: model.direction = text
}
......@@ -155,9 +161,10 @@ ApplicationWindow {
title: "Post sync script"
resizable: true
delegate: Quick.TextEdit {
id: textEdit
padding: 5
color: "lightsteelblue"
color: "white"
anchors.fill: parent
selectByMouse: true
text: model.postSyncScript
onEditingFinished: model.postSyncScript = text
}
......
......@@ -12,6 +12,7 @@ add_executable(kdeconnect-filesync-daemon
../interfaces/filesyncapp_interface.cpp
../interfaces/sync_result.cpp
../interfaces/file_hash_array.cpp
../interfaces/json_types.cpp
${KDECONNECT_FILESYNC_DAEMON_SRCS})
target_link_libraries(kdeconnect-filesync-daemon
......
......@@ -27,11 +27,14 @@
#include <filesyncapp/interfaces/filesyncapp_interface.h>
#include <filesyncapp/interfaces/sync_result.h>
#include <filesyncapp/interfaces/file_hash_array.h>
#include <filesyncapp/interfaces/json_types.h>
int main(int argc, char *argv[])
{
FileSync::SyncResult::registerDbusType();
FileSync::FileHashArray::registerDbusType();
FileSync::JsonTypes::registerQJsonObjectTypeAsDbusType();
FileSync::JsonTypes::registerQJsonArrayTypeAsDbusType();
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("KDE Connect File Synchronization");
......
......@@ -42,12 +42,12 @@ FileSync::FileSyncDBusAdaptor::~FileSyncDBusAdaptor()
void
FileSync::FileSyncDBusAdaptor::processRequestedHashes(const QString &deviceId,
const QByteArray &hashArray)
const QVariantList &hashArray)
{
qCDebug(LOG_INTERFACES_DBUS) << QJsonDocument::fromJson(hashArray).array();
// qCDebug(LOG_INTERFACES_DBUS) << QJsonDocument::fromJson(hashArray).array();
// PROXY_HASH_LIST.arg(deviceId,
// hashArray.data().toStdList().tos);
m_daemon->processRequestedHashes(deviceId, QJsonDocument::fromJson(hashArray).array());
m_daemon->processRequestedHashes(deviceId, QJsonArray::fromVariantList(hashArray));
}
void FileSync::FileSyncDBusAdaptor::requestSync(const QString &deviceId,
......
......@@ -30,6 +30,7 @@
#include <daemon.h>
#include <filesyncapp/interfaces/sync_result.h>
#include <filesyncapp/interfaces/file_hash_array.h>
#include <filesyncapp/interfaces/json_types.h>
namespace FileSync
......@@ -56,7 +57,31 @@ namespace FileSync
Q_NOREPLY void
processRequestedHashes(const QString &deviceId,
const QByteArray &hashArray);
const QVariantList &hashArray);
QVariantList
getConfiguration() {
QJsonArray configuration;
QJsonObject configurationItem;
configurationItem.insert("localPath", "local");
configurationItem.insert("remotePath", "remote");
configurationItem.insert("direction", "TEST");
configurationItem.insert("postSyncScript", "");
configuration.append(configurationItem);
QJsonObject configurationItem2;
configurationItem2.insert("localPath", "local2");
configurationItem2.insert("remotePath", "remot2e");
configurationItem2.insert("direction", "TEST2");
configurationItem2.insert("postSyncScript", "3");
configuration.append(configurationItem2);
QStringList testlist({"test1", "test2"});
qDebug() << "prividing model" << configuration.toVariantList() << endl;
return configuration.toVariantList();
}
Q_SIGNALS:
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "json_types.h"
#include "qdebug.h"
#include <QDBusArgument>
#include <QJsonObject>
#include <QJsonArray>
QDBusArgument &
operator<<(QDBusArgument &argument, const QJsonObject &obj)
{
QStringList keys = obj.keys();
argument.beginMap(QVariant::String, QVariant::String);
for (QString &key : keys)
{
argument.beginMapEntry();
argument << key << obj.value(key).toString();
argument.endMapEntry();
}
argument.endMap();
return argument;
}
const QDBusArgument &
operator>>(const QDBusArgument &argument, QJsonObject &obj)
{
argument.beginMap();
obj = QJsonObject();
while (!argument.atEnd())
{
QString tmpKey;
QString tmpValue;
argument.beginMapEntry();
argument >> tmpKey >> tmpValue;
argument.endMapEntry();
obj.insert(tmpKey, tmpValue);
}
argument.endMap();
return argument;
}
QDBusArgument &
operator<<(QDBusArgument &argument, const QJsonArray &jsonArray)
{
if (jsonArray.first().isObject())
{
argument.beginArray(qMetaTypeId<QJsonObject>());
}
for (const QJsonValue &value : jsonArray)
{
argument.beginMapEntry();
if (value.isObject())
{
argument << value.toObject();
}
argument.endMapEntry();
}
argument.endMap();
return argument;
}
const QDBusArgument &
operator>>(const QDBusArgument &argument, QJsonArray &jsonArray)
{
argument.beginMap();
jsonArray = QJsonArray();
while (!argument.atEnd())
{
argument.beginMapEntry();
// if (argument.currentType() == QDBusArgument::MapType)
// {
QJsonObject tmpObj;
argument >> tmpObj;
jsonArray.append(tmpObj);
// }
argument.endMapEntry();
}
argument.endMap();
return argument;
}
void FileSync::JsonTypes::registerQJsonObjectTypeAsDbusType()
{
qDBusRegisterMetaType<QJsonObject>();
qRegisterMetaType<QJsonObject>();
}
void FileSync::JsonTypes::registerQJsonArrayTypeAsDbusType()
{
qDBusRegisterMetaType<QJsonArray>();
qRegisterMetaType<QJsonArray>();
}
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef FILESYNC_JSON_TYPES_H
#define FILESYNC_JSON_TYPES_H
#include <qdebug.h>
#include <QJsonObject>
#include <QVariantMap>
#include <QtDBus/QtDBus>
namespace FileSync
{
class JsonTypes
{
public:
static void registerQJsonObjectTypeAsDbusType();
static void registerQJsonArrayTypeAsDbusType();
};
};
Q_DECLARE_METATYPE(QJsonObject);
Q_DECLARE_METATYPE(QJsonArray);
#endif
\ No newline at end of file
......@@ -537,3 +537,8 @@ void ModelTest::rowsRemoved(const QModelIndex & parent, int start, int end)
Q_ASSERT(c.next == model->data(model->index(start, 0, c.parent)));
}
void FileSync::registerQJsonObjectTypeAsDbusType()
{
qDBusRegisterMetaType<QJsonObject>();
qRegisterMetaType<QJsonObject>();
}
......@@ -114,7 +114,7 @@ bool FileSyncPlugin::Plugin::receivePacket(const NetworkPacket &np)
document.setArray(hashArray);
qDebug() << "Processing hashArray." << document.toJson() << endl;
fileSyncAppInterface->processRequestedHashes(device()->id(), document.toJson());
fileSyncAppInterface->processRequestedHashes(device()->id(), hashArray.toVariantList());
}
return true;
}
......
Markdown is supported
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