...
 
Commits (3)
......@@ -4,7 +4,7 @@ add_executable(kdeconnect-filesync-client
main.cpp
sync_table_model.cpp
../../filesyncapp/interfaces/json_types.cpp
${KDECONNECT_FILESYNC_CLIENT_SRCS} sync_table_model.cpp sync_table_model.h)
${KDECONNECT_FILESYNC_CLIENT_SRCS})
target_link_libraries(kdeconnect-filesync-client
kdeconnectinterfaces
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_SYNC_TABLE_MODEL_H
#define KDECONNECT_SYNC_TABLE_MODEL_H
#ifndef FILESYNC_SYNC_TABLE_MODEL_H
#define FILESYNC_SYNC_TABLE_MODEL_H
#include <QObject>
#include <QModelIndex>
......@@ -75,4 +75,4 @@ namespace FileSync
};
}
#endif //KDECONNECT_SYNC_TABLE_MODEL_H
#endif //FILESYNC_SYNC_TABLE_MODEL_H
......@@ -13,7 +13,6 @@ add_executable(kdeconnect-filesync-daemon
singleton_pool.cpp
../interfaces/filesyncapp_interface.cpp
../interfaces/sync_result.cpp
../interfaces/file_hash_array.cpp
../interfaces/json_types.cpp
${KDECONNECT_FILESYNC_DAEMON_SRCS})
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "log.h"
#include "common.h"
#include <QLoggingCategory>
#include <QtCore/QCryptographicHash>
......@@ -29,10 +30,8 @@ int
FileSync::Util::runCommand(const QString &commandToRun, QString &stdout,
QString &stderr)
{
qCDebug(LOG_UTIL) << "Executing command: "
<< commandToRun;
QProcess process;
D(LOG_UTIL, "Executing command: " << commandToRun);
process.start(commandToRun);
process.waitForFinished(-1);
......@@ -72,29 +71,21 @@ QList<QString> FileSync::Util::scanDir(const QString &rootElement)
QDir rootDir(rootElement);
QList<QFileInfo> allEntries = rootDir.entryInfoList(
QDir::AllEntries | QDir::NoDotAndDotDot);
qCDebug(LOG_UTIL) << "Scanning " << rootElement
<< " size " << allEntries.size();
for (QFileInfo &entry : allEntries)
{
if (entry.isDir())
{
qCDebug(LOG_UTIL) << "Dir "
<< entry.absoluteFilePath();
files.append(scanDir(entry.absoluteFilePath()));
}
else if (entry.isFile())
{
qCDebug(LOG_UTIL) << "File "
<< entry.absoluteFilePath();
files.append(entry.absoluteFilePath());
}
}
}
else
{
throw std::runtime_error(
QString("Can not scan, path is not a directory! (%1)").arg(
rootElement).toStdString());
E(LOG_UTIL, UTIL_NOT_A_DIRECTORY.arg(rootElement));
}
return files;
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_COMMON_H
#define KDECONNECT_COMMON_H
#ifndef FILESYNC_COMMON_H
#define FILESYNC_COMMON_H
#include <exception>
#include <QLoggingCategory>
......@@ -45,7 +45,7 @@ namespace FileSync
// Interfaces
static const QString PROXY_SYNC_REQUEST = "Sync requested on proxy for deviceId %1 sync list (%2)";
static const QString PROXY_HASH_LIST = "Hash list on proxy for deviceId %1 file list (%2)";
static const QString PROXY_HASH_LIST = "Hashes received for device: %1 file list: ";
// Sync log
static const QString LOG_DATETIME_FORMAT = "dd-MM-yyyy hh:mm:ss.zzz";
......@@ -66,6 +66,8 @@ namespace FileSync
// Errors
static const QString DBUS_REGISTRATION_FAILED = "D-Bus registration failed for service %1";
static const QString EXECUTOR_NO_EXECUTOR_FOR_DEVICE = "No executor for device %1 exists or is not running!";
static const QString NO_INSTANCE_AVAILABLE_ERROR = "No instance available, for the first time initialization please provide 'deviceId'!";
static const QString EXEC_ERROR = "Script execution failed, exit code %1";
static const QString INCONSISTENT_PATHS_ERROR = "Inconsistent paths settings, '%1' is a directory but '%2' is not!";
......@@ -83,6 +85,8 @@ namespace FileSync
static const QString SYNC_DETERMINATION_BY_MTIME = "Files (%1) and (%2) synchronized for the first time, using mod_time as decisive parameter";
static const QString SYNC_COMPLETED = "Synchronization completed!\n%1 files synchronized with %2 errors\n\nFor details see log at %3\n";
static const QString UTIL_NOT_A_DIRECTORY = "Can not scan, path: %1; not a directory!";
class Util
{
public:
......@@ -104,4 +108,4 @@ namespace FileSync
};
}
#endif //KDECONNECT_COMMON_H
#endif //FILESYNC_COMMON_H
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_CONFIG_H
#define KDECONNECT_CONFIG_H
#ifndef FILESYNC_CONFIG_H
#define FILESYNC_CONFIG_H
#include <string>
#include <QJsonArray>
......@@ -61,4 +61,4 @@ namespace FileSync
};
}
#endif //KDECONNECT_CONFIG_H
#endif //FILESYNC_CONFIG_H
......@@ -29,7 +29,8 @@ FileSync::Daemon::Daemon()
}
FileSync::Daemon::~Daemon()
{}
{
}
void FileSync::Daemon::requestSync(const QString &deviceId,
const QStringList &syncList)
......@@ -41,6 +42,7 @@ void FileSync::Daemon::requestSync(const QString &deviceId,
if (existingExecutor != m_executors.end() &&
!existingExecutor.value()->isRunning())
{
W(LOG_DAEMON, "An ongoing sync is progress, discarding this sync request");
syncOngoing = true;
}
else if (existingExecutor != m_executors.end() &&
......@@ -48,61 +50,64 @@ void FileSync::Daemon::requestSync(const QString &deviceId,
{
disconnect(existingExecutor.value(),
&FileSync::Executor::notifyDaemon, this,
&Daemon::relayNotification);
&Daemon::sendResultNotification);
delete existingExecutor.value();
m_executors.remove(deviceId);
}
if (!syncOngoing)
{
I(LOG_DAEMON, "Starting new synchronization ...");
FileSync::Executor *executor = new FileSync::Executor(deviceId,
syncList);
connect(executor, &FileSync::Executor::notifyDaemon, this,
&Daemon::relayNotification);
&Daemon::sendResultNotification);
m_executors.insert(deviceId, executor);
executor->start();
}
}
void FileSync::Daemon::processRequestedHashes(const QString &deviceId,
const QJsonArray &hashArray)
void FileSync::Daemon::setHashes(const QString &deviceId,
const QJsonArray &hashArray)
{
qDebug() << "Processing hashes." << endl;
D(LOG_DAEMON,
"Processing hashes for device: " << deviceId << " hashes: " << hashArray);
QMap<QString, Executor *>::iterator existingExecutor = m_executors.find(
deviceId);
if (existingExecutor != m_executors.end() &&
existingExecutor.value()->isExecuting())
{
qDebug() << "Processing hashes1." << hashArray << endl;
existingExecutor.value()->hashesReady(hashArray);
qDebug() << "Processing hashes2." << endl;
}
else
{
E(LOG_DAEMON, EXECUTOR_NO_EXECUTOR_FOR_DEVICE.arg(deviceId));
}
}
QJsonArray
FileSync::Daemon::getConfiguration(const QString &deviceId)
{
D(LOG_DAEMON, "Configuration requested for device: " << deviceId);
QJsonArray deviceConfig = FileSync::Config::instance(deviceId).data();
qCDebug(LOG_DAEMON) << "Configuration for device " << deviceId
<< " requested: " << deviceConfig;
D(LOG_DAEMON, "Sending configuration: " << deviceConfig);
return deviceConfig;
}
bool FileSync::Daemon::setConfiguration(const QString &deviceId,
const QJsonArray &newConfig)
{
D(LOG_DAEMON, "Configuration recieved for device: " << deviceId);
FileSync::Config::instance(deviceId).setData(newConfig);
FileSync::Config::instance(deviceId).saveConfig();
qCDebug(LOG_DAEMON) << "Configuration for device " << deviceId
<< " saved: " << newConfig;
D(LOG_DAEMON, "Configuration requested for device: " << deviceId);
return true;
}
void FileSync::Daemon::relayNotification(const FileSync::SyncResult &syncResult)
void FileSync::Daemon::sendResultNotification(
const FileSync::SyncResult &syncResult)
{
qDebug() << "Relaying signal." << endl;
D(LOG_DAEMON, "Broadcasting result notification: " << syncResult.toVariant());
Q_EMIT notifySynchronizationResult(syncResult);
}
......
......@@ -47,8 +47,8 @@ namespace FileSync
void requestSync(const QString &deviceId, const QStringList &syncList);
void
processRequestedHashes(const QString &deviceId,
const QJsonArray &hashArray);
setHashes(const QString &deviceId,
const QJsonArray &hashArray);
QJsonArray
getConfiguration(const QString &deviceId);
......@@ -57,7 +57,7 @@ namespace FileSync
setConfiguration(const QString &deviceId,
const QJsonArray &newConfig);
void relayNotification(const FileSync::SyncResult &syncResult);
void sendResultNotification(const FileSync::SyncResult &syncResult);
Q_SIGNALS:
......@@ -65,4 +65,4 @@ namespace FileSync
};
}
#endif
\ No newline at end of file
#endif //FILESYNC_DAEMOM_H
\ No newline at end of file
......@@ -18,10 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <executor.h>
#include <log.h>
#include <sync_operation.h>
#include "log.h"
#include "config.h"
#include "index.h"
#include "executor.h"
#include "sync_operation.h"
Q_LOGGING_CATEGORY(LOG_EXECUTOR, "kdeconnect.filesyncapp.daemon.executor");
......@@ -31,7 +31,9 @@ FileSync::Executor::Executor(const QString &deviceId,
: m_deviceId(deviceId), m_syncList(syncList),
m_executionResult(QString(), 0, 0, QStringList())
{
loadConfig();
Log::instance(m_deviceId);
Config::instance(m_deviceId);
Index::instance(m_deviceId);
}
FileSync::Executor::~Executor()
......@@ -48,9 +50,6 @@ void FileSync::Executor::run()
LOG_I(LOG_EXECUTOR, QString("Sync starting..."));
/*
* Create new mounter
*/
m_sftpMounter = new SftpMounter(m_deviceId);
connect(m_sftpMounter, &SftpMounter::sftpReady, this,
&Executor::resumeAfterWaitForSftp);
......@@ -67,7 +66,7 @@ void FileSync::Executor::run()
exit(1);
}
QJsonArray toSync = m_config.value("toSync").toArray();
QJsonArray toSync = Config::instance(m_deviceId).data();
QJsonArray *fileSyncList = new QJsonArray();
for (const QJsonValue &value: toSync)
{
......@@ -147,9 +146,8 @@ FileSync::SyncResult FileSync::Executor::determineAndPerformSyncOperation(
((operation->getType() == SyncOperation::FROM_REMOTE) ||
(operation->getType() == SyncOperation::FROM_LOCAL)))
{
qCDebug(LOG_EXECUTOR)
<< "Executing post install script "
<< postSyncScript;
LOG_I(LOG_EXECUTOR, "Executing post install script "
<< postSyncScript);
if (!executePostSyncScript(postSyncScript, operation->getType(),
localPath,
remotePath))
......@@ -167,24 +165,6 @@ FileSync::SyncResult FileSync::Executor::determineAndPerformSyncOperation(
}
void FileSync::Executor::loadConfig()
{
QFile configFile(CONFIG_FILE_PATH.arg(
QStandardPaths::writableLocation(QStandardPaths::HomeLocation),
m_deviceId));
if (!QFileInfo(configFile).exists())
{
LOG_E(LOG_EXECUTOR, "Configuration file does not exist!");
}
if (!configFile.open(QIODevice::ReadOnly))
{
LOG_E(LOG_EXECUTOR, "Can not open configuration file!");
}
m_config = QJsonDocument::fromJson(configFile.readAll()).object();
LOG_D(LOG_EXECUTOR, "Configuration opened");
configFile.close();
}
bool FileSync::Executor::isExecuting()
{
// m_runningMutex.lock();
......@@ -197,15 +177,12 @@ bool FileSync::Executor::isExecuting()
void FileSync::Executor::abortDueToSftpError(const QString &error)
{
qDebug() << "Sftp failed, aborting executor thread" << endl;
qCritical() << error << endl;
LOG_E(LOG_EXECUTOR, "Sftp failed, aborting executor!");
delete m_sftpMounter;
m_sftpMounter = nullptr;
m_sshfsReadyMutex.lock();
m_sshfsReady.wakeAll();
m_sshfsReadyMutex.unlock();
}
void FileSync::Executor::resumeAfterWaitForSftp(
......@@ -214,20 +191,16 @@ void FileSync::Executor::resumeAfterWaitForSftp(
m_remoteSystemMountPoint = remoteSystemMountPoint;
delete m_sftpMounter;
m_sftpMounter = nullptr;
m_sshfsReadyMutex.lock();
m_sshfsReady.wakeAll();
m_sshfsReadyMutex.unlock();
qCDebug(LOG_EXECUTOR) << "Sftp ready, waking up executor thread";
LOG_D(LOG_EXECUTOR, "Sftp ready, waking up executor thread");
}
void FileSync::Executor::hashesReady(const QJsonArray &hashList)
{
qCDebug(LOG_EXECUTOR) << "Hashes ready, waking up executor thread";
LOG_D(LOG_EXECUTOR, "Hashes ready, waking up executor thread");
m_hashList = hashList;
// m_hashRequestWaitLoop.exit(0);
m_hashesReadyMutex.lock();
m_hashesReady.wakeAll();
m_hashesReadyMutex.unlock();
......
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILESYNC_SYNC_EXECUTOR_H
#define FILESYNC_SYNC_EXECUTOR_H
#ifndef FILESYNC_EXECUTOR_H
#define FILESYNC_EXECUTOR_H
#include <qdebug.h>
#include <QObject>
......@@ -51,12 +51,10 @@ namespace FileSync
bool m_running;
QMutex m_runningMutex;
SyncResult m_executionResult;
QJsonObject m_config;
QString m_remoteSystemMountPoint;
SftpMounter *m_sftpMounter;
bool m_errorOccured;
QJsonArray m_hashList;
QEventLoop m_hashRequestWaitLoop;
SyncResult determineAndPerformSyncOperation(const QJsonArray &fileSyncList, const QJsonArray &fileHashList);
......@@ -67,8 +65,6 @@ namespace FileSync
void run() override;
void loadConfig();
bool isExecuting();
public Q_SLOTS:
......@@ -116,4 +112,4 @@ namespace FileSync
};
}
#endif
\ No newline at end of file
#endif //FILESYNC_EXECUTOR_H
\ No newline at end of file
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -51,9 +51,8 @@ void FileSync::Index::init(const QString &fsPath, const QString &deviceId)
indexFile.setFileName(fsPath);
if (!indexFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
qCDebug(LOG_INDEX)
<< FileSync::INDEX_READ_OPEN_ERROR.arg(indexFile.fileName(),
indexFile.errorString());
E(LOG_INDEX, FileSync::INDEX_READ_OPEN_ERROR.arg(indexFile.fileName(),
indexFile.errorString()));
}
else
{
......@@ -75,19 +74,17 @@ FileSync::Index::createIfNotExisting(const QString &fsPath,
if (!root.exists(indexFileInfo.dir().absolutePath()))
{
root.mkpath(indexFileInfo.dir().absolutePath());
qCDebug(LOG_INDEX) << "Creating dir "
<< indexFileInfo.dir().absolutePath();
I(LOG_INDEX, "Creating dir "
<< indexFileInfo.dir().absolutePath());
}
writeDefaultData(fsPath);
qCDebug(LOG_INDEX)
<< "Creating new sync index for the device " << deviceId;
I(LOG_INDEX, "Creating new sync index for the device " << deviceId);
}
else
{
qCDebug(LOG_INDEX)
<< FileSync::INDEX_ALREADY_EXISTS.arg(deviceId);
I(LOG_INDEX, FileSync::INDEX_ALREADY_EXISTS.arg(deviceId));
}
}
......@@ -98,9 +95,8 @@ void FileSync::Index::writeToFs(const QString &fsPath,
indexFile.setFileName(fsPath);
if (!indexFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
qCDebug(LOG_INDEX)
<< FileSync::INDEX_WRITE_OPEN_ERROR.arg(indexFile.fileName(),
indexFile.errorString());
E(LOG_INDEX, FileSync::INDEX_WRITE_OPEN_ERROR.arg(indexFile.fileName(),
indexFile.errorString()));
}
else
{
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_SYNC_INDEX_H
#define KDECONNECT_SYNC_INDEX_H
#ifndef FILESYNC_INDEX_H
#define FILESYNC_INDEX_H
#include <QtCore/QArgument>
#include <QString>
......@@ -63,4 +63,4 @@ namespace FileSync
};
}
#endif //KDECONNECT_SYNC_INDEX_H
#endif //FILESYNC_INDEX_H
......@@ -18,9 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// TODO all defs
#ifndef KDECONNECT_SYNC_LOG_H
#define KDECONNECT_SYNC_LOG_H
#ifndef FILESYNC_LOG_H
#define FILESYNC_LOG_H
#include <string>
#include <QString>
......@@ -61,6 +60,12 @@ namespace FileSync
const QString getLogLevelAsString(LogLevel logLevel);
static void throwError(const QString message)
{
throw std::runtime_error(message.toLocal8Bit().data()); \
}
private:
void logMessage(const QString &message, LogLevel level);
......@@ -85,7 +90,7 @@ namespace FileSync
}
#define W(logCategory, message) { \
qCWarning(logCategory) << qMessage; \
qCWarning(logCategory) << message; \
}
#define E(logCategory, message) { \
......@@ -113,4 +118,4 @@ namespace FileSync
throw std::runtime_error(qMessage.toStdString()); \
}
#endif //KDECONNECT_SYNC_LOG_H
#endif //FILESYNC_LOG_H
......@@ -27,15 +27,17 @@
#include "common.h"
#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>
Q_LOGGING_CATEGORY(LOG_MAIN, "kdeconnect.filesyncapp.main");
// TODO optimize imports and remove unused ones
//TODO all strings to consts
int main(int argc, char *argv[])
{
FileSync::SyncResult::registerDbusType();
FileSync::FileHashArray::registerDbusType();
FileSync::JsonTypes::registerQJsonObjectTypeAsDbusType();
FileSync::JsonTypes::registerQJsonArrayTypeAsDbusType();
......
......@@ -18,9 +18,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <log.h>
#include <sftp_mounter.h>
Q_LOGGING_CATEGORY(LOG_SSHFS,"kdeconnect.filesyncapp.daemon.sshfs");
Q_LOGGING_CATEGORY(LOG_SFTP_MOUNTER, "kdeconnect.filesyncapp.daemon.sftp");
FileSync::SftpMounter::SftpMounter(const QString &deviceId) : m_deviceId(
deviceId)
......@@ -36,7 +37,7 @@ void FileSync::SftpMounter::run()
QEventLoop loop;
if (!isRemoteSystemRootAvailable(m_deviceId))
{
qCDebug(LOG_SSHFS) << "Remote root not accessible, trying to re-mount";
W(LOG_SFTP_MOUNTER, "Remote root not accessible, trying to re-mount");
QDBusConnection::sessionBus().connect("org.kde.kdeconnect",
FileSync::SFTP_PLUGIN_DBUS_OBJ_PATH.arg(
m_deviceId),
......@@ -48,7 +49,7 @@ void FileSync::SftpMounter::run()
this);
sftpDbusInterface->mount();
// TODO timeout
// TODO implement mount timeout
loop.exec();
}
mountOperationComplete();
......@@ -64,7 +65,7 @@ bool FileSync::SftpMounter::isRemoteSystemRootAvailable(const QString &deviceId)
FileSync::SSHFS_MOUNT_ROOT.arg(m_remoteSystemMountPoint, ""));
if (remoteSystemRoot.exists())
{
qCDebug(LOG_SSHFS) << "Remote root already accessible";
I(LOG_SFTP_MOUNTER, "Remote root already accessible");
available = true;
}
}
......@@ -91,14 +92,14 @@ QString FileSync::SftpMounter::findMountFolderForDevice(const QString &deviceId)
if (mountTarget.contains(deviceId))
{
retValue = mountTarget;
qCDebug(LOG_SSHFS) << "Found mount point for device "
<< deviceId << "(" << mountTarget
<< ")";
I(LOG_SFTP_MOUNTER, "Found mount point for device "
<< deviceId << "(" << mountTarget
<< ")");
}
else
{
qCDebug(LOG_SSHFS) << "Mount point for device "
<< deviceId << " not found";
I(LOG_SFTP_MOUNTER, "Mount point for device "
<< deviceId << " not found");
}
}
}
......@@ -120,18 +121,17 @@ bool FileSync::SftpMounter::waitForRemoteRoot(QString deviceId, int timeout)
{
if (remoteSystemRoot.exists())
{
qCDebug(LOG_SSHFS)
<< "SSHFS mount ready and remote root"
<< remoteSystemRoot.absolutePath()
<< "accessible";
I(LOG_SFTP_MOUNTER, "SSHFS mount ready and remote root"
<< remoteSystemRoot.absolutePath()
<< "accessible");
break;
}
else
{
QThread::sleep(1);
qCDebug(LOG_SSHFS)
<< "Waiting for remote root" << remoteSystemRoot.absolutePath()
<< "to become available ...";
I(LOG_SFTP_MOUNTER,
"Waiting for remote root" << remoteSystemRoot.absolutePath()
<< "to become available ...");
}
}
}
......@@ -141,7 +141,7 @@ bool FileSync::SftpMounter::waitForRemoteRoot(QString deviceId, int timeout)
void FileSync::SftpMounter::mountOperationComplete()
{
qCDebug(LOG_SSHFS) << "Device SSHFS mount completed";
I(LOG_SFTP_MOUNTER, "Device SSHFS mount completed");
// Wait till remote root becomes accessible (or not)
if (waitForRemoteRoot(m_deviceId, FileSync::REMOTE_ROOT_TIMEOUT))
......@@ -153,7 +153,7 @@ void FileSync::SftpMounter::mountOperationComplete()
{
QString error("Sync can not start, remote root unavailable!");
Q_EMIT sftpError(error);
qCCritical(LOG_SSHFS) << error;
E(LOG_SFTP_MOUNTER, error);
}
}
......
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FILESYNC_SSHFS_H
#define FILESYNC_SSHFS_H
#ifndef FILESYNC_SFTP_MOUNTER_H
#define FILESYNC_SFTP_MOUNTER_H
#include <qdebug.h>
#include <QObject>
......@@ -30,11 +30,6 @@
#include "interfaces/dbusinterfaces.h"
#include "filesyncapp/interfaces/sync_result.h"
#include "common.h"
// TODO optimize imports and remove unused ones
// TODO rename files
//TODO all strings to consts
namespace FileSync
{
......@@ -68,4 +63,4 @@ namespace FileSync
};
}
#endif
\ No newline at end of file
#endif //FILESYNC_SFTP_MOUNTER_H
\ No newline at end of file
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_SINGLETON_POOL_H
#define KDECONNECT_SINGLETON_POOL_H
#ifndef FILESYNC_SINGLETON_POOL_H
#define FILESYNC_SINGLETON_POOL_H
#import <QString>
#import <QMap>
......@@ -83,4 +83,4 @@ namespace FileSync
template<class T>
QMap<QString, T *> *FileSync::SingletonPool<T>::s_instances = NULL;
#endif //KDECONNECT_SINGLETON_POOL_H
#endif //FILESYNC_SINGLETON_POOL_H
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -43,7 +43,7 @@ QPair<QString, QString> FileSync::SyncOperation::getHashRecord() const
}
void FileSync::SyncOperation::setHashRecord(const QString &newHashRecordKey,
const QString &newHashRecordValue)
const QString &newHashRecordValue)
{
m_indexRecordKey = newHashRecordKey;
m_indexRecordValue = newHashRecordValue;
......
/**
* Copyright 2019 Viktor Porvaznik <viktor.porvaznik@piceacode.eu>
* 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
......@@ -18,8 +18,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KDECONNECT_SYNC_OPERATION_H
#define KDECONNECT_SYNC_OPERATION_H
#ifndef FILESYNC_SYNC_OPERATION_H
#define FILESYNC_SYNC_OPERATION_H
#include <QtCore/QString>
#include <QtCore/QPair>
......@@ -31,7 +31,7 @@ namespace FileSync
public:
enum SyncOperationType
{
UNKNOWN=0, NONE, CONFLICT, FROM_REMOTE, FROM_LOCAL
UNKNOWN = 0, NONE, CONFLICT, FROM_REMOTE, FROM_LOCAL
};
SyncOperation();
......@@ -54,4 +54,4 @@ namespace FileSync
};
}
#endif //KDECONNECT_SYNC_OPERATION_H
#endif //FILESYNC_SYNC_OPERATION_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 <QDBusArgument>
#include <QObject>
#include <QJsonArray>
#include "file_hash_array.h"
FileSync::FileHashArray::FileHashArray()
{
}
FileSync::FileHashArray::FileHashArray(const QVariantList &data) : m_data(data)
{
}
FileSync::FileHashArray::FileHashArray(const FileSync::FileHashArray &other)
: m_data(other.data())
{
}
FileSync::FileHashArray &
FileSync::FileHashArray::operator=(const FileSync::FileHashArray &other)
{
this->m_data= other.data();
return *this;
}
QDBusArgument &
operator<<(QDBusArgument &argument,
const FileSync::FileHashArray &fileHashArray)
{
argument.beginStructure();
argument << fileHashArray.data();
argument.endStructure();
return argument;
}
const QDBusArgument &
operator>>(const QDBusArgument &argument,
FileSync::FileHashArray &fileHashArray)
{
QVariantList tmpList;
argument.beginStructure();
argument >> tmpList;
argument.endStructure();
fileHashArray = FileSync::FileHashArray(tmpList);
return argument;
}
void FileSync::FileHashArray::registerDbusType()
{
qDBusRegisterMetaType<FileHashArray>();
qRegisterMetaType<FileHashArray>();
}
QVariantList FileSync::FileHashArray::data() const
{
return m_data;
}
/**
* 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_FILE_HASH_ARRAY_H
#define FILESYNC_FILE_HASH_ARRAY_H
#include <qdebug.h>
#include <QObject>
#include <QJsonArray>
#include <QDBusAbstractAdaptor>
#include <QDBusMetaType>
#include <QDBusArgument>
#include <QVariantMap>
namespace FileSync
{
class FileHashArray : public QObject
{
Q_OBJECT
private:
QVariantList m_data;
public:
FileHashArray();
FileHashArray(const QVariantList &data);
FileHashArray(const FileHashArray &other);
FileHashArray &operator=(const FileHashArray &other);
QVariantList data() const;
static void registerDbusType();
};
};
Q_DECLARE_METATYPE(FileSync::FileHashArray);
#endif
\ No newline at end of file
......@@ -22,7 +22,6 @@
#include <QJsonDocument>
#include <filesyncapp/interfaces/filesyncapp_interface.h>
#include <filesyncapp/interfaces/file_hash_array.h>
#include <log.h>
#include <common.h>
......@@ -41,48 +40,44 @@ FileSync::FileSyncDBusAdaptor::~FileSyncDBusAdaptor()
}
void
FileSync::FileSyncDBusAdaptor::processRequestedHashes(const QString &deviceId,
const QVariantList &hashArray)
FileSync::FileSyncDBusAdaptor::setHashes(const QString &deviceId,
const QVariantList &hashArray)
{
// TODO better log message
qCDebug(LOG_INTERFACES_DBUS) << PROXY_HASH_LIST.arg(deviceId);
m_daemon->processRequestedHashes(deviceId,
QJsonArray::fromVariantList(hashArray));
D(LOG_INTERFACES_DBUS, PROXY_HASH_LIST.arg(deviceId) << hashArray);
m_daemon->setHashes(deviceId,
QJsonArray::fromVariantList(hashArray));
}
void FileSync::FileSyncDBusAdaptor::requestSync(const QString &deviceId,
const QStringList &syncList)
{
qCDebug(LOG_INTERFACES_DBUS) <<
PROXY_SYNC_REQUEST.arg(deviceId,
syncList.join("; "));
D(LOG_INTERFACES_DBUS, PROXY_SYNC_REQUEST.arg(deviceId, syncList.join("; ")));
m_daemon->requestSync(deviceId, syncList);
}
QVariantList
FileSync::FileSyncDBusAdaptor::getConfiguration(const QString &deviceId)
{
D(LOG_INTERFACES_DBUS, "Configuration requested for device: " << deviceId);
QVariantList deviceConfig;
QJsonArray toSync = m_daemon->getConfiguration(deviceId);
for (const QJsonValue &value : toSync)
{
deviceConfig.append(value.toObject());
}
qCDebug(LOG_INTERFACES_DBUS) << "Configuration for device " << deviceId
<< " requested: " << deviceConfig;
D(LOG_INTERFACES_DBUS, "Sending configuration: " << deviceConfig);
return deviceConfig;
}
bool FileSync::FileSyncDBusAdaptor::setConfiguration(const QString &deviceId,
const QVariantList &deviceConfig)
{
D(LOG_INTERFACES_DBUS,
"Configuration received for device: " << deviceId << "; configuration: "
<< deviceConfig);
QJsonArray newConfig = FileSync::JsonTypes::convertQVariantListToQJsonArray(
deviceConfig);
m_daemon->setConfiguration(deviceId, newConfig);
qCDebug(LOG_INTERFACES_DBUS) << "Configuration for device " << deviceId
<< " saved: " << newConfig;
return true;
}
......@@ -31,15 +31,12 @@
#include <singleton_pool.h>
#include <config.h>
#include <filesyncapp/interfaces/sync_result.h>
#include <filesyncapp/interfaces/file_hash_array.h>
#include <filesyncapp/interfaces/json_types.h>
namespace FileSync
{
class SyncResult;
class FileHashArray;
class FileSyncDBusAdaptor : public QDBusAbstractAdaptor
{
Q_OBJECT
......@@ -58,8 +55,8 @@ namespace FileSync
requestSync(const QString &deviceId, const QStringList &syncList);
Q_NOREPLY void
processRequestedHashes(const QString &deviceId,
const QVariantList &hashArray);
setHashes(const QString &deviceId,
const QVariantList &hashArray);
QVariantList
getConfiguration(const QString &deviceId);
......
......@@ -94,9 +94,9 @@ operator>>(const QDBusArgument &argument, QJsonArray &jsonArray)
argument.beginMapEntry();
if (argument.currentType() == QDBusArgument::MapType)
{
QJsonObject tmpObj;
argument >> tmpObj;
jsonArray.append(tmpObj);
QJsonObject tmpObj;
argument >> tmpObj;
jsonArray.append(tmpObj);
}
argument.endMapEntry();
}
......@@ -123,7 +123,6 @@ FileSync::JsonTypes::convertQVariantToQJsonObject(const QVariant &variant)
QJsonObject jsonObject;
const QDBusArgument &dBusArgument = variant.value<QDBusArgument>();
dBusArgument >> jsonObject;
qDebug() << "jsonObject " << jsonObject;
return jsonObject;
}
......
......@@ -3,7 +3,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(kdeconnect_filesync_SRCS
filesync_plugin.cpp
../../filesyncapp/interfaces/sync_result.cpp
../../filesyncapp/interfaces/file_hash_array.cpp
)
kdeconnect_add_plugin(kdeconnect_filesync JSON kdeconnect_filesync.json SOURCES ${kdeconnect_filesync_SRCS})
......
......@@ -33,7 +33,6 @@
#include "filesync_constants.h"
#include "filesync_plugin.h"
#include "filesyncapp/interfaces/sync_result.h"
#include <filesyncapp/interfaces/file_hash_array.h>
K_PLUGIN_FACTORY_WITH_JSON(KdeConnectPluginFactory, "kdeconnect_filesync.json",
registerPlugin<FileSyncPlugin::Plugin>();)
......@@ -48,7 +47,6 @@ FileSyncPlugin::Plugin::Plugin(QObject *parent, const QVariantList &args)
<< device()->name();
FileSync::SyncResult::registerDbusType();
FileSync::FileHashArray::registerDbusType();
startDaemonIfNotRunning();
......@@ -114,7 +112,7 @@ bool FileSyncPlugin::Plugin::receivePacket(const NetworkPacket &np)
document.setArray(hashArray);
qDebug() << "Processing hashArray." << document.toJson() << endl;
fileSyncAppInterface->processRequestedHashes(device()->id(), hashArray.toVariantList());
fileSyncAppInterface->setHashes(device()->id(), hashArray.toVariantList());
}
return true;
}
......