From 629c1efba576ff1e1a6af437352903abda48368d Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 24 Apr 2022 12:34:34 +0200 Subject: [PATCH] IpcServer: Add addFile() --- gui/ipc.h | 3 ++- gui/ipcserver.cpp | 22 +++++++++++++++++++++- gui/ipcserver.h | 5 +++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/gui/ipc.h b/gui/ipc.h index f1ef8a3..b09a161 100644 --- a/gui/ipc.h +++ b/gui/ipc.h @@ -4,6 +4,7 @@ enum IPCCommand { DocOpen, - FileOpen + FileOpen, + AddFile, }; #endif // IPC_H diff --git a/gui/ipcserver.cpp b/gui/ipcserver.cpp index d7d8dc5..a92dc30 100644 --- a/gui/ipcserver.cpp +++ b/gui/ipcserver.cpp @@ -6,9 +6,15 @@ #include #include #include "ipcserver.h" +#include "common.h" +#include "databasefactory.h" +#include "../shared/logger.h" IpcServer::IpcServer() { + this->dbFactory = QSharedPointer(new DatabaseFactory(Common::databasePath())); + this->dbService = QSharedPointer(new SqliteDbService(*this->dbFactory.get())); + this->fileSaver = QSharedPointer(new FileSaver(*this->dbService.get())); connect(&this->spawningServer, &QLocalServer::newConnection, this, &IpcServer::spawnerNewConnection); } @@ -20,9 +26,10 @@ bool IpcServer::startSpawner(QString socketPath) bool IpcServer::docOpen(QString path, int pagenum) { + QSettings settings; QString command = settings.value("pdfviewer").toString(); - if(command != "" && command.contains("%p") && command.contains("%f")) + if(path.endsWith(".pdf") && command != "" && command.contains("%p") && command.contains("%f")) { QStringList splitted = command.split(" "); if(splitted.size() > 1) @@ -47,6 +54,19 @@ bool IpcServer::fileOpen(QString path) return QDesktopServices::openUrl(QUrl::fromLocalFile(path)); } +SaveFileResult IpcServer::addFile(QString file) +{ + try + { + return this->fileSaver->addFile(file); + } + catch(std::exception &e) + { + Logger::error() << e.what() << Qt::endl; + return PROCESSFAIL; + } +} + void IpcServer::spawnerNewConnection() { QScopedPointer socket{this->spawningServer.nextPendingConnection()}; diff --git a/gui/ipcserver.h b/gui/ipcserver.h index 7f86a8b..239afde 100644 --- a/gui/ipcserver.h +++ b/gui/ipcserver.h @@ -3,13 +3,18 @@ #include #include #include "ipc.h" +#include "filesaver.h" class IpcServer : public QObject { Q_OBJECT private: + QSharedPointer dbFactory; + QSharedPointer dbService; + QSharedPointer fileSaver; QLocalServer spawningServer; bool docOpen(QString path, int pagenum); bool fileOpen(QString path); + SaveFileResult addFile(QString file); private slots: void spawnerNewConnection();