Commit 8c3cab96 authored by Viktor Porvaznik's avatar Viktor Porvaznik Committed by Viktor Porvaznik

Fixed GUI

parent 0cee9428
......@@ -2,6 +2,8 @@ qt5_add_resources(KDECONNECT_FILESYNC_CLIENT_SRCS resources.qrc)
add_executable(kdeconnect-filesync-client
main.cpp
common.cpp
client.cpp
sync_table_model.cpp
../../filesyncapp/interfaces/json_types.cpp
${KDECONNECT_FILESYNC_CLIENT_SRCS})
......
/**
* 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 <QLoggingCategory>
#include <QThread>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <interfaces/dbusinterfaces.h>
#include "client.h"
#include "common.h"
#include "interfaces/dbusinterfaces.h"
Q_LOGGING_CATEGORY(LOG_CLIENT, "kdeconnect.filesyncapp.client");
FileSync::Client::Client(int &argc, char **argv) : QApplication(argc, argv)
{
startDaemonIfNotRunning();
}
FileSync::Client::~Client()
{
}
void FileSync::Client::startDaemonIfNotRunning() const
{
if (!isDeamonRunning())
{
qCDebug(LOG_CLIENT) << "Service "
<< FILESYNC_APP_DAEMON_SERVICE_NAME
<< " not running, starting ...";
QProcess::startDetached(START_FILESYNC_SERVICE_CMD);
while (!isDeamonRunning())
{
QThread::sleep(FILESYNC_APP_DAEMON_SLEEP);
}
}
}
bool FileSync::Client::isDeamonRunning() const
{
bool isRunning = false;
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
FILESYNC_APP_DAEMON_SERVICE_NAME))
{
isRunning = true;
}
return isRunning;
}
void FileSync::Client::requestSync(const QString &deviceId)
{
QStringList syncList;
syncList.append("ALL");
startDaemonIfNotRunning();
FileSyncAppInterface *fileSyncAppInterface = new FileSyncAppInterface(this);
fileSyncAppInterface->requestSync(deviceId, syncList);
}
/**
* 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_CLIENT_H
#define FILESYNC_CLIENT_H
#include <QApplication>
#include <QObject>
namespace FileSync
{
class Client : public QApplication
{
Q_OBJECT
public:
Client(int &argc, char **argv);
~Client();
void startDaemonIfNotRunning() const;
bool isDeamonRunning() const;
public Q_SLOTS:
void requestSync(const QString &deviceId);
};
}
#endif //FILESYNC_CLIENT_H
/**
* 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 "common.h"
/**
* 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_COMMON_H
#define FILESYNC_COMMON_H
#include <exception>
#include <QtCore/QString>
#include <QtCore/QProcess>
namespace FileSync
{
// Filesync plugin
static const QString FILESYNC_PLUGIN_DBUS_OBJ_PATH = "/modules/kdeconnect/devices/%1/filesync";
// Filesync app
static const int FILESYNC_APP_DAEMON_SLEEP = 1;
static const QString FILESYNC_APP_DAEMON_SERVICE_NAME = "org.kde.kdeconnect.standalone.filesync";
static const QString FILESYNC_APP_DAEMON_DBUS_OBJ_PATH = "/daemon";
static const QString FILESYNC_APP_DAEMON_INTERFACE = "org.kde.kdeconnect.standalone.filesync";
static const QString START_FILESYNC_SERVICE_CMD = "/data/kde/kdeconnect-kde/build/bin/kdeconnect-filesync-daemon";
}
#endif //FILESYNC_COMMON_H
......@@ -25,13 +25,14 @@
#include <KLocalizedString>
#include <QQmlContext>
#include "filesyncapp/interfaces/json_types.h"
#include "client.h"
#include "sync_table_model.h"
int main(int argc, char *argv[])
{
FileSync::JsonTypes::registerQJsonArrayTypeAsDbusType();
FileSync::JsonTypes::registerQJsonObjectTypeAsDbusType();
QApplication app(argc, argv);
FileSync::Client client(argc, argv);
QApplication::setApplicationName("KDE Connect File Synchronization Client");
QApplication::setApplicationVersion("0.1.0");
......@@ -39,15 +40,16 @@ int main(int argc, char *argv[])
parser.addHelpOption();
parser.addVersionOption();
parser.process(app);
parser.process(client);
QQmlApplicationEngine engine;
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
FileSync::SyncTableModel *syncTableModel = new FileSync::SyncTableModel();
engine.rootContext()->setContextProperty("syncTableModel", syncTableModel);
engine.rootContext()->setContextProperty("client", &client);
engine.load(QUrl("qrc:/qml/MainApplicationWindow.qml"));
return app.exec();
return client.exec();
}
#include "main.moc"
......@@ -30,6 +30,8 @@ ApplicationWindow {
visible: true
width: 800
property QtObject currentDevice: null
menuBar: MenuBar {
Menu {
title: qsTr("File")
......@@ -61,6 +63,9 @@ ApplicationWindow {
id: syncButton
anchors.right: parent.right
text: qsTr("Synchronize ALL")
onClicked: {
client.requestSync(mainWindow.currentDevice.id());
}
}
}
}
......@@ -104,14 +109,8 @@ ApplicationWindow {
anchors.fill: parent
acceptedButtons: Qt.RightButton
onClicked: {
console.log("Click")
if (mouse.button == Qt.LeftButton)
{
console.log("Left")
}
else if (mouse.button == Qt.RightButton)
if (mouse.button == Qt.RightButton)
{
console.log("Right" +styleData.row)
if (styleData.row) {
contextMenu.selectedRow = styleData.row
}
......@@ -186,15 +185,21 @@ ApplicationWindow {
}
onRowsInserted: if (devicesCombo.currentIndex < 0) {
devicesCombo.currentIndex = 0
currentDevice = devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null
mainWindow.currentDevice = devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null
}
}
property QtObject currentDevice: null
textRole: "display"
onActivated: {
currentDevice = devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null
syncTableModel.setDeviceId(currentDevice.id())
syncTableModel.loadModel(currentDevice.id())
onCurrentTextChanged: {
if (count > 0) {
mainWindow.currentDevice = devicesCombo.currentIndex >= 0 ? devicesModel.data(devicesModel.index(devicesCombo.currentIndex, 0), DevicesModel.DeviceRole) : null
if (currentDevice.isReachable()) {
syncTableModel.setDeviceId(mainWindow.currentDevice.id())
syncTableModel.loadModel(mainWindow.currentDevice.id())
console.log("dooo")
}
} else {
console.log("nothing")
}
}
}
}
......
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