From 11860a1865b1c9223236f8db76899aec058fa67a Mon Sep 17 00:00:00 2001 From: probonopd Date: Mon, 14 Aug 2023 18:40:07 +0200 Subject: [PATCH] Add application selected with Other... to the db as an option for the MIME type --- src/ApplicationSelectionDialog.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ApplicationSelectionDialog.cpp b/src/ApplicationSelectionDialog.cpp index 870ea7c..1ed3dd0 100644 --- a/src/ApplicationSelectionDialog.cpp +++ b/src/ApplicationSelectionDialog.cpp @@ -58,9 +58,33 @@ ApplicationSelectionDialog::ApplicationSelectionDialog(QString *fileOrProtocol, QStringList args; args << QFileInfo(selectedFile).absoluteFilePath(); args << *fileOrProtocol; + + // Symlink the chosen application to the launch "database" + // so that it can be set as the default application later on + QString symlinkPath = QString("%1/%2").arg(DbManager::localShareLaunchApplicationsPath).arg(QFileInfo(selectedFile).fileName()); + if (!QDir(DbManager::localShareLaunchApplicationsPath).exists()) { + QDir().mkdir(DbManager::localShareLaunchApplicationsPath); + } + if (!QFile::exists(symlinkPath) + && !QFile::link(selectedFile, symlinkPath)) { + QMessageBox::critical(this, tr("Error"), tr("Could not create symlink from %1 to %2").arg(selectedFile).arg(symlinkPath)); + } + // Symlink the chosen application from the symlink we just created to the MIME type path + QString mimePath = QString("%1/%2") + .arg(DbManager::localShareLaunchMimePath) + .arg(QString(*mimeType).replace("/", "_")); + if (!QDir(mimePath).exists()) { + QDir().mkdir(mimePath); + } + QString mimeSymlinkPath = QString("%1/%2").arg(mimePath).arg(QFileInfo(selectedFile).fileName()); + if (!QFile::exists(mimeSymlinkPath) + && !QFile::link(symlinkPath, mimeSymlinkPath)) { + QMessageBox::critical(this, tr("Error"), tr("Could not create symlink from %1 to %2").arg(symlinkPath).arg(mimeSymlinkPath)); + } + + this->hide(); Launcher launcher; launcher.launch(args); - QApplication::quit(); } }