Skip to content

Commit

Permalink
Add application selected with Other... to the db as an option for the…
Browse files Browse the repository at this point in the history
… MIME type
  • Loading branch information
probonopd committed Aug 14, 2023
1 parent dd5f71a commit 11860a1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/ApplicationSelectionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 11860a1

Please sign in to comment.