IpcServer: Remove docOpen(), fileOpen(). MainWindow will do it

As it is no longer subject to sandboxing as a whole, it is not
restricted and thus, should call these functions itself
This commit is contained in:
Albert S. 2022-05-17 19:22:59 +02:00
parent 830226ae59
commit fe29641d0a
2 changed files with 5 additions and 74 deletions

View File

@ -12,9 +12,6 @@
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);
} }
@ -24,49 +21,6 @@ bool IpcServer::startSpawner(QString socketPath)
return this->spawningServer.listen(socketPath); return this->spawningServer.listen(socketPath);
} }
bool IpcServer::docOpen(QString path, int pagenum)
{
QSettings settings;
QString command = settings.value("pdfviewer").toString();
if(path.endsWith(".pdf") && command != "" && command.contains("%p") && command.contains("%f"))
{
QStringList splitted = command.split(" ");
if(splitted.size() > 1)
{
QString cmd = splitted[0];
QStringList args = splitted.mid(1);
args.replaceInStrings("%f", path);
args.replaceInStrings("%p", QString::number(pagenum));
QProcess::startDetached(cmd, args);
}
}
else
{
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
return true;
}
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() void IpcServer::spawnerNewConnection()
{ {
QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()}; QScopedPointer<QLocalSocket> socket{this->spawningServer.nextPendingConnection()};
@ -78,31 +32,13 @@ void IpcServer::spawnerNewConnection()
} }
QDataStream stream(socket.get()); QDataStream stream(socket.get());
IPCCommand command; IPCCommand command;
QStringList args;
stream >> command; stream >> command;
stream >> args; if(command == GeneratePreviews)
if(args.size() < 1)
{ {
stream << "invalid"; RenderConfig renderConfig;
return; QVector<RenderTarget> targets;
} stream >> renderConfig;
if(command == DocOpen) stream >> targets;
{
if(args.size() < 2)
{
stream << "invalid";
return;
}
docOpen(args[0], args[1].toInt());
}
if(command == FileOpen)
{
if(args.size() < 1)
{
stream << "invalid";
return;
}
fileOpen(args[0]);
} }
} }
} }

View File

@ -8,12 +8,7 @@ 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 fileOpen(QString path);
SaveFileResult addFile(QString file); SaveFileResult addFile(QString file);
private slots: private slots:
void spawnerNewConnection(); void spawnerNewConnection();