IpcServer: Add addFile()
This commit is contained in:
parent
d73674937d
commit
629c1efba5
@ -4,6 +4,7 @@
|
|||||||
enum IPCCommand
|
enum IPCCommand
|
||||||
{
|
{
|
||||||
DocOpen,
|
DocOpen,
|
||||||
FileOpen
|
FileOpen,
|
||||||
|
AddFile,
|
||||||
};
|
};
|
||||||
#endif // IPC_H
|
#endif // IPC_H
|
||||||
|
@ -6,9 +6,15 @@
|
|||||||
#include <QLocalSocket>
|
#include <QLocalSocket>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include "ipcserver.h"
|
#include "ipcserver.h"
|
||||||
|
#include "common.h"
|
||||||
|
#include "databasefactory.h"
|
||||||
|
#include "../shared/logger.h"
|
||||||
|
|
||||||
IpcServer::IpcServer()
|
IpcServer::IpcServer()
|
||||||
{
|
{
|
||||||
|
this->dbFactory = QSharedPointer<DatabaseFactory>(new DatabaseFactory(Common::databasePath()));
|
||||||
|
this->dbService = QSharedPointer<SqliteDbService>(new SqliteDbService(*this->dbFactory.get()));
|
||||||
|
this->fileSaver = QSharedPointer<FileSaver>(new FileSaver(*this->dbService.get()));
|
||||||
connect(&this->spawningServer, &QLocalServer::newConnection, this, &IpcServer::spawnerNewConnection);
|
connect(&this->spawningServer, &QLocalServer::newConnection, this, &IpcServer::spawnerNewConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,9 +26,10 @@ bool IpcServer::startSpawner(QString socketPath)
|
|||||||
|
|
||||||
bool IpcServer::docOpen(QString path, int pagenum)
|
bool IpcServer::docOpen(QString path, int pagenum)
|
||||||
{
|
{
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString command = settings.value("pdfviewer").toString();
|
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(" ");
|
QStringList splitted = command.split(" ");
|
||||||
if(splitted.size() > 1)
|
if(splitted.size() > 1)
|
||||||
@ -47,6 +54,19 @@ bool IpcServer::fileOpen(QString path)
|
|||||||
return QDesktopServices::openUrl(QUrl::fromLocalFile(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()
|
void IpcServer::spawnerNewConnection()
|
||||||
{
|
{
|
||||||
QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()};
|
QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()};
|
||||||
|
@ -3,13 +3,18 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QLocalServer>
|
#include <QLocalServer>
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
|
#include "filesaver.h"
|
||||||
class IpcServer : public QObject
|
class IpcServer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
QSharedPointer<DatabaseFactory> dbFactory;
|
||||||
|
QSharedPointer<SqliteDbService> dbService;
|
||||||
|
QSharedPointer<FileSaver> fileSaver;
|
||||||
QLocalServer spawningServer;
|
QLocalServer spawningServer;
|
||||||
bool docOpen(QString path, int pagenum);
|
bool docOpen(QString path, int pagenum);
|
||||||
bool fileOpen(QString path);
|
bool fileOpen(QString path);
|
||||||
|
SaveFileResult addFile(QString file);
|
||||||
private slots:
|
private slots:
|
||||||
void spawnerNewConnection();
|
void spawnerNewConnection();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user