Commit e87fb6da authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix selection of default applications to edit audio/image files

parent dbd28417
Pipeline #183140 passed with stage
in 6 minutes and 21 seconds
......@@ -58,6 +58,10 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include <KRatingPainter>
#include <KXMLGUIFactory>
#include <kwidgetsaddons_version.h>
#include <KService>
#include <KIO/ApplicationLauncherJob>
#include <KIO/JobUiDelegate>
#include <KOpenWithDialog>
#include <QActionGroup>
#include <QCryptographicHash>
......@@ -3991,19 +3995,71 @@ void Bin::slotOpenClipExtern()
showTitleWidget(clip);
break;
case ClipType::Image:
if (KdenliveSettings::defaultimageapp().isEmpty()) {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open images in the Settings dialog"));
} else {
{
if (KdenliveSettings::defaultimageappId().isEmpty() && !KdenliveSettings::defaultimageapp().isEmpty()) {
// Keep for compatibility
QProcess::startDetached(KdenliveSettings::defaultimageapp(), {clip->url()});
break;
}
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultimageappId());
if (service == nullptr) {
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default image editor"), QString(), this);
if (dlg->exec() == QDialog::Accepted) {
service = dlg->service();
if (service) {
QString appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
KdenliveSettings::setDefaultimageapp(appName);
KdenliveSettings::setDefaultimageappId(service->storageId());
}
}
delete dlg;
}
break;
case ClipType::Audio:
if (KdenliveSettings::defaultaudioapp().isEmpty()) {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
if (service) {
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls({QUrl::fromLocalFile(clip->url())});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
} else {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open image files in the Settings dialog"));
}
}
break;
case ClipType::Audio:
{
if (KdenliveSettings::defaultaudioappId().isEmpty() && !KdenliveSettings::defaultaudioapp().isEmpty()) {
// Keep for compatibility
QProcess::startDetached(KdenliveSettings::defaultaudioapp(), {clip->url()});
break;
}
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultaudioappId());
if (service == nullptr) {
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default audio editor"), QString(), this);
if (dlg->exec() == QDialog::Accepted) {
service = dlg->service();
if (service) {
QString appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
KdenliveSettings::setDefaultaudioapp(appName);
KdenliveSettings::setDefaultaudioappId(service->storageId());
}
}
delete dlg;
}
break;
if (service) {
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls({QUrl::fromLocalFile(clip->url())});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
} else {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
}
}
break;
default:
break;
}
......
......@@ -330,6 +330,20 @@ void KdenliveSettingsDialog::initEnviromentPage()
m_configEnv.kcfg_proxythreads->setMaximum(qMax(1, QThread::idealThreadCount() - 1));
// Default apps
if (!KdenliveSettings::defaultaudioappId().isEmpty()) {
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultaudioappId());
if (service) {
m_configEnv.kp_audio->setIcon(QIcon::fromTheme(service->icon()));
}
}
if (!KdenliveSettings::defaultimageappId().isEmpty()) {
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultimageappId());
if (service) {
m_configEnv.kp_image->setIcon(QIcon::fromTheme(service->icon()));
}
}
// Script rendering folder
m_configEnv.videofolderurl->setMode(KFile::Directory);
m_configEnv.videofolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_videofolder"));
......@@ -836,22 +850,64 @@ void KdenliveSettingsDialog::showPage(int page, int option)
void KdenliveSettingsDialog::slotEditAudioApplication()
{
KService::Ptr service;
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default audio editor"), m_configEnv.kcfg_defaultaudioapp->text(), this);
QString appName;
if (!KdenliveSettings::defaultaudioappId().isEmpty()) {
// Find app name from service
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultaudioappId());
if (service) {
appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
}
}
if (appName.isEmpty()) {
appName = m_configEnv.kcfg_defaultaudioapp->text();
}
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default audio editor"), appName, this);
if (dlg->exec() == QDialog::Accepted) {
service = dlg->service();
m_configEnv.kcfg_defaultaudioapp->setText(KIO::DesktopExecParser::executablePath(service->exec()));
KService::Ptr service = dlg->service();
if (service) {
appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
m_configEnv.kcfg_defaultaudioapp->setText(appName);
m_configEnv.kp_audio->setIcon(QIcon::fromTheme(service->icon()));
m_audioAppId = service->storageId();
}
}
delete dlg;
}
void KdenliveSettingsDialog::slotEditImageApplication()
{
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default image editor"), m_configEnv.kcfg_defaultimageapp->text(), this);
QString appName;
if (!KdenliveSettings::defaultimageappId().isEmpty()) {
// Find app name from service
KService::Ptr service = KService::serviceByStorageId(KdenliveSettings::defaultimageappId());
if (service) {
appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
}
}
if (appName.isEmpty()) {
appName = m_configEnv.kcfg_defaultimageapp->text();
}
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default image editor"), appName, this);
if (dlg->exec() == QDialog::Accepted) {
KService::Ptr service = dlg->service();
m_configEnv.kcfg_defaultimageapp->setText(KIO::DesktopExecParser::executablePath(service->exec()));
if (service) {
appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
m_configEnv.kcfg_defaultimageapp->setText(appName);
m_configEnv.kp_image->setIcon(QIcon::fromTheme(service->icon()));
m_imageAppId = service->storageId();
}
}
delete dlg;
}
......@@ -1018,6 +1074,14 @@ void KdenliveSettingsDialog::updateSettings()
}
}
// Default apps
if (m_configEnv.kcfg_defaultaudioapp->text() != KdenliveSettings::defaultaudioapp()) {
KdenliveSettings::setDefaultaudioappId(m_audioAppId);
}
if (m_configEnv.kcfg_defaultimageapp->text() != KdenliveSettings::defaultimageapp()) {
KdenliveSettings::setDefaultimageappId(m_imageAppId);
}
if (m_configCapture.kcfg_v4l_format->currentIndex() != int(KdenliveSettings::v4l_format())) {
saveCurrentV4lProfile();
KdenliveSettings::setV4l_format(0);
......
......@@ -134,6 +134,8 @@ private:
EncodingProfilesChooser *m_decklinkProfiles;
EncodingProfilesChooser *m_v4lProfiles;
EncodingProfilesChooser *m_grabProfiles;
QString m_audioAppId;
QString m_imageAppId;
void initDevices();
void loadTranscodeProfiles();
void saveTranscodeProfiles();
......
......@@ -624,31 +624,31 @@ void Wizard::slotCheckPrograms(QString &infos, QString &warnings)
// set up some default applications
QString program;
if (KdenliveSettings::defaultimageapp().isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("gimp"));
if (program.isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("krita"));
}
if (!program.isEmpty()) {
KdenliveSettings::setDefaultimageapp(program);
}
}
if (KdenliveSettings::defaultaudioapp().isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("audacity"));
if (program.isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("traverso"));
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("gimp"));
if (service == nullptr) {
service = KService::serviceByDesktopName(QStringLiteral("krita"));
}
if (!program.isEmpty()) {
KdenliveSettings::setDefaultaudioapp(program);
if (service != nullptr) {
QString appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
KdenliveSettings::setDefaultimageapp(appName);
KdenliveSettings::setDefaultimageappId(service->storageId());
}
}
if (KdenliveSettings::defaultaudioapp().isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("audacity"));
if (program.isEmpty()) {
program = QStandardPaths::findExecutable(QStringLiteral("traverso"));
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("audacity"));
if (service == nullptr) {
service = KService::serviceByDesktopName(QStringLiteral("traverso"));
}
if (!program.isEmpty()) {
KdenliveSettings::setDefaultaudioapp(program);
if (service != nullptr) {
QString appName = service->property(QStringLiteral("Name"), QVariant::String).toString();
if (appName.isEmpty()) {
appName = service->desktopEntryName();
}
KdenliveSettings::setDefaultaudioapp(appName);
KdenliveSettings::setDefaultaudioappId(service->storageId());
}
}
......
......@@ -603,7 +603,17 @@
</entry>
<entry name="defaultaudioapp" type="String">
<label>Default audio editing application.</label>
<label>Default audio editing application name.</label>
<default></default>
</entry>
<entry name="defaultaudioappId" type="String">
<label>Default audio editing application service id.</label>
<default></default>
</entry>
<entry name="defaultimageappId" type="String">
<label>Default image editing application service id.</label>
<default></default>
</entry>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment