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

Get rid of KOpenWithDialog to select default external applications (doesn not...

Get rid of KOpenWithDialog to select default external applications (doesn not work on Windows/Mac), make path to glaxnimate configurable
parent d9d2d81e
Pipeline #204390 passed with stage
in 12 minutes and 29 seconds
......@@ -61,6 +61,7 @@ SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#include <KOpenWithDialog>
#include <KRatingPainter>
#include <KService>
#include <KUrlRequesterDialog>
#include <KXMLGUIFactory>
#include <kwidgetsaddons_version.h>
......@@ -3188,7 +3189,7 @@ void Bin::setupMenu()
QIcon::fromTheme(QStringLiteral("kdenlive-add-text-clip")));
setupAddClipAction(addClipMenu, ClipType::TextTemplate, QStringLiteral("add_text_template_clip"), i18n("Add Template Title…"),
QIcon::fromTheme(QStringLiteral("kdenlive-add-text-clip")));
setupAddClipAction(addClipMenu, ClipType::Animation, QStringLiteral("add_animation_clip"), i18n("Add Animation…"),
setupAddClipAction(addClipMenu, ClipType::Animation, QStringLiteral("add_animation_clip"), i18n("Create Animation…"),
QIcon::fromTheme(QStringLiteral("motion_path_animations")));
QAction *downloadResourceAction =
addAction(QStringLiteral("download_resource"), i18n("Online Resources"), QIcon::fromTheme(QStringLiteral("edit-download")));
......@@ -4019,73 +4020,42 @@ void Bin::slotOpenClipExtern()
showTitleWidget(clip);
break;
case ClipType::Image: {
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());
}
if (KdenliveSettings::defaultimageapp().isEmpty()) {
QUrl url = KUrlRequesterDialog::getUrl(QUrl(), this, i18n("Enter path for your image editing application"));
if (!url.isEmpty()) {
KdenliveSettings::setDefaultimageapp(url.toLocalFile());
}
delete dlg;
}
if (service) {
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls({QUrl::fromLocalFile(clip->url())});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
if (!KdenliveSettings::defaultimageapp().isEmpty()) {
QProcess::startDetached(KdenliveSettings::defaultimageapp(), {clip->url()});
} else {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open image files in the Settings dialog"));
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open image files"));
}
} 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());
}
if (KdenliveSettings::defaultaudioapp().isEmpty()) {
QUrl url = KUrlRequesterDialog::getUrl(QUrl(), this, i18n("Enter path for your audio editing application"));
if (!url.isEmpty()) {
KdenliveSettings::setDefaultaudioapp(url.toLocalFile());
}
delete dlg;
}
if (service) {
auto *job = new KIO::ApplicationLauncherJob(service);
job->setUrls({QUrl::fromLocalFile(clip->url())});
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
job->start();
if (!KdenliveSettings::defaultaudioapp().isEmpty()) {
QProcess::startDetached(KdenliveSettings::defaultaudioapp(), {clip->url()});
} else {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog"));
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a default application to open audio files"));
}
} break;
case ClipType::Animation: {
QString glaxBinary = QStandardPaths::findExecutable(QStringLiteral("glaxnimate"));
if (glaxBinary.isEmpty()) {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please install Glaxnimate to edit Lottie animations"));
if (KdenliveSettings::glaxnimatePath().isEmpty()) {
QUrl url = KUrlRequesterDialog::getUrl(QUrl(), this, i18n("Enter path to the Glaxnimate application"));
if (!url.isEmpty()) {
KdenliveSettings::setGlaxnimatePath(url.toLocalFile());
}
}
if (KdenliveSettings::glaxnimatePath().isEmpty()) {
QProcess::startDetached(KdenliveSettings::glaxnimatePath(), {clip->url()});
} else {
QProcess::startDetached(glaxBinary, {clip->url()});
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please set a path for the Glaxnimate application"));
}
} break;
default:
......
......@@ -148,6 +148,10 @@ void ClipCreationDialog::createColorClip(KdenliveDoc *doc, const QString &parent
void ClipCreationDialog::createAnimationClip(KdenliveDoc *doc, const QString &parentId)
{
if (KdenliveSettings::glaxnimatePath().isEmpty()) {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please install Glaxnimate to edit Lottie animations."));
return;
}
QDir dir(doc->projectDataFolder());
QString fileName("animation-0001.json");
if (dir.cd("animations")) {
......@@ -215,12 +219,7 @@ void ClipCreationDialog::createAnimationClip(KdenliveDoc *doc, const QString &pa
QTextStream out(&file);
out << templateJson;
file.close();
QString glaxBinary = QStandardPaths::findExecutable(QStringLiteral("glaxnimate"));
if (glaxBinary.isEmpty()) {
KMessageBox::sorry(QApplication::activeWindow(), i18n("Please install Glaxnimate to edit Lottie animations."));
return;
}
QProcess::startDetached(glaxBinary, {fileName});
QProcess::startDetached(KdenliveSettings::glaxnimatePath(), {fileName});
// Add clip to project
QDomDocument xml;
QDomElement prod = xml.createElement(QStringLiteral("producer"));
......
......@@ -325,20 +325,6 @@ 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 files folder
m_configEnv.videofolderurl->setMode(KFile::Directory);
m_configEnv.videofolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_videofolder"));
......@@ -354,6 +340,7 @@ void KdenliveSettingsDialog::initEnviromentPage()
connect(m_configEnv.kp_image, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditImageApplication);
connect(m_configEnv.kp_audio, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditAudioApplication);
connect(m_configEnv.kp_anim, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditGlaxnimateApplication);
m_page2 = addPage(p2, i18n("Environment"), QStringLiteral("application-x-executable-script"));
}
......@@ -845,66 +832,26 @@ void KdenliveSettingsDialog::showPage(int page, int option)
void KdenliveSettingsDialog::slotEditAudioApplication()
{
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) {
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();
}
QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::defaultaudioapp()), this, i18n("Enter path to the audio editing application"));
if (!url.isEmpty()) {
KdenliveSettings::setDefaultaudioapp(url.toLocalFile());
}
delete dlg;
}
void KdenliveSettingsDialog::slotEditImageApplication()
{
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();
QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::defaultimageapp()), this, i18n("Enter path to the image editing application"));
if (!url.isEmpty()) {
KdenliveSettings::setDefaultimageapp(url.toLocalFile());
}
QPointer<KOpenWithDialog> dlg = new KOpenWithDialog(QList<QUrl>(), i18n("Select default image editor"), appName, this);
if (dlg->exec() == QDialog::Accepted) {
KService::Ptr service = dlg->service();
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();
}
}
void KdenliveSettingsDialog::slotEditGlaxnimateApplication()
{
QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::glaxnimatePath()), this, i18n("Enter path to the Glaxnimate application"));
if (!url.isEmpty()) {
KdenliveSettings::setGlaxnimatePath(url.toLocalFile());
}
delete dlg;
}
void KdenliveSettingsDialog::slotCheckShuttle(int state)
......@@ -1069,14 +1016,6 @@ 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);
......
......@@ -65,6 +65,7 @@ private slots:
void slotUpdateShuttleDevice(int ix = 0);
void slotEditImageApplication();
void slotEditAudioApplication();
void slotEditGlaxnimateApplication();
void slotReadAudioDevices();
void slotUpdateGrabRegionStatus();
void slotCheckAlsaDriver();
......@@ -134,8 +135,6 @@ private:
EncodingProfilesChooser *m_decklinkProfiles;
EncodingProfilesChooser *m_v4lProfiles;
EncodingProfilesChooser *m_grabProfiles;
QString m_audioAppId;
QString m_imageAppId;
void initDevices();
void loadTranscodeProfiles();
void saveTranscodeProfiles();
......
......@@ -613,31 +613,47 @@ void Wizard::slotCheckPrograms(QString &infos, QString &warnings)
// set up some default applications
QString program;
if (KdenliveSettings::defaultimageapp().isEmpty()) {
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("gimp"));
if (service == nullptr) {
service = KService::serviceByDesktopName(QStringLiteral("krita"));
QString imageBinary = QStandardPaths::findExecutable(QStringLiteral("gimp"));
#ifdef Q_OS_WIN
if (imageBinary.isEmpty()) {
imageBinary = QStandardPaths::findExecutable(QStringLiteral("gimp"), {"C:/Program Files/Gimp", "C:/Program Files (x86)/Gimp"});
}
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());
#endif
if (imageBinary.isEmpty()) {
imageBinary = QStandardPaths::findExecutable(QStringLiteral("krita"));
}
#ifdef Q_OS_WIN
if (imageBinary.isEmpty()) {
imageBinary = QStandardPaths::findExecutable(QStringLiteral("krita"), {"C:/Program Files/Krita", "C:/Program Files (x86)/Krita"});
}
#endif
if (!imageBinary.isEmpty()) {
KdenliveSettings::setDefaultimageapp(imageBinary);
}
}
if (KdenliveSettings::defaultaudioapp().isEmpty()) {
KService::Ptr service = KService::serviceByDesktopName(QStringLiteral("audacity"));
if (service == nullptr) {
service = KService::serviceByDesktopName(QStringLiteral("traverso"));
QString audioBinary = QStandardPaths::findExecutable(QStringLiteral("audacity"));
#ifdef Q_OS_WIN
if (audioBinary.isEmpty()) {
audioBinary = QStandardPaths::findExecutable(QStringLiteral("audacity"), {"C:/Program Files/Audacity", "C:/Program Files (x86)/Audacity"});
}
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());
#endif
if (audioBinary.isEmpty()) {
audioBinary = QStandardPaths::findExecutable(QStringLiteral("traverso"));
}
if (!audioBinary.isEmpty()) {
KdenliveSettings::setDefaultaudioapp(audioBinary);
}
}
if (KdenliveSettings::glaxnimatePath().isEmpty()) {
QString animBinary = QStandardPaths::findExecutable(QStringLiteral("glaxnimate"));
#ifdef Q_OS_WIN
if (animBinary.isEmpty()) {
animBinary = QStandardPaths::findExecutable(QStringLiteral("glaxnimate"), {"C:/Program Files/Glaxnimate", "C:/Program Files (x86)/Glaxnimate"});
}
#endif
if (!animBinary.isEmpty()) {
KdenliveSettings::setGlaxnimatePath(animBinary);
}
}
......
......@@ -607,13 +607,8 @@
<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>
<entry name="glaxnimatePath" type="String">
<label>Path to the Glaxnimate application.</label>
<default></default>
</entry>
......
......@@ -265,20 +265,6 @@
<string>Default Apps</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Image editing:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="kcfg_defaultimageapp">
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="kp_image">
<property name="text">
......@@ -295,6 +281,19 @@
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="kcfg_defaultaudioapp">
<property name="placeholderText">
<string>Path to audio editing application</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="kcfg_defaultimageapp">
<property name="placeholderText">
<string>Path to image editing application</string>
</property>
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
......@@ -307,7 +306,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -320,6 +319,34 @@
</property>
</spacer>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Image editing:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Animation editing:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="kcfg_glaxnimatePath">
<property name="placeholderText">
<string>Path to Glaxnimate executable</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="kp_anim">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
......
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