Warning, file /multimedia/kdenlive/src/dialogs/kdenlivesettingsdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2021 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003 
0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "kdenlivesettingsdialog.h"
0008 #include "clipcreationdialog.h"
0009 #include "core.h"
0010 #include "dialogs/profilesdialog.h"
0011 #include "doc/kdenlivedoc.h"
0012 #include "kdenlivesettings.h"
0013 #include "mainwindow.h"
0014 #include "monitor/monitor.h"
0015 #include "monitor/monitorproxy.h"
0016 #include "profiles/profilemodel.hpp"
0017 #include "profiles/profilerepository.hpp"
0018 #include "profilesdialog.h"
0019 #include "project/dialogs/guidecategories.h"
0020 #include "project/dialogs/profilewidget.h"
0021 #include "timeline2/view/timelinecontroller.h"
0022 #include "timeline2/view/timelinewidget.h"
0023 #include "wizard.h"
0024 
0025 #ifdef USE_V4L
0026 #include "capture/v4lcapture.h"
0027 #endif
0028 
0029 #include "KLocalizedString"
0030 #include "kdenlive_debug.h"
0031 #include <KArchive>
0032 #include <KArchiveDirectory>
0033 #include <KIO/DesktopExecParser>
0034 #include <KIO/FileCopyJob>
0035 #include <kio_version.h>
0036 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
0037 #include <KIO/JobUiDelegateFactory>
0038 #else
0039 #include <KIO/JobUiDelegate>
0040 #endif
0041 #include "utils/KMessageBox_KdenliveCompat.h"
0042 #include <KIO/OpenUrlJob>
0043 #include <KLineEdit>
0044 #include <KMessageBox>
0045 #include <KOpenWithDialog>
0046 #include <KService>
0047 #include <KTar>
0048 #include <KUrlRequesterDialog>
0049 #include <KZip>
0050 
0051 #include <QAction>
0052 #include <QDir>
0053 #include <QGuiApplication>
0054 #include <QInputDialog>
0055 #include <QRegularExpression>
0056 #include <QScreen>
0057 #include <QSize>
0058 #include <QThread>
0059 #include <QTimer>
0060 #include <QtConcurrent>
0061 
0062 #include <cstdio>
0063 #include <cstdlib>
0064 #include <fcntl.h>
0065 #include <unistd.h>
0066 
0067 #ifdef USE_JOGSHUTTLE
0068 #include "jogshuttle/jogaction.h"
0069 #include "jogshuttle/jogshuttleconfig.h"
0070 #include <QStandardPaths>
0071 #include <linux/input.h>
0072 #include <memory>
0073 #endif
0074 
0075 SpeechList::SpeechList(QWidget *parent)
0076     : QListWidget(parent)
0077 {
0078     setAlternatingRowColors(true);
0079     setAcceptDrops(true);
0080     setDropIndicatorShown(true);
0081     viewport()->setAcceptDrops(true);
0082 }
0083 
0084 QStringList SpeechList::mimeTypes() const
0085 {
0086     return QStringList() << QStringLiteral("text/uri-list");
0087 }
0088 
0089 void SpeechList::dropEvent(QDropEvent *event)
0090 {
0091     const QMimeData *qMimeData = event->mimeData();
0092     if (qMimeData->hasUrls()) {
0093         QList<QUrl> urls = qMimeData->urls();
0094         if (!urls.isEmpty()) {
0095             emit getDictionary(urls.takeFirst());
0096         }
0097     }
0098 }
0099 
0100 KdenliveSettingsDialog::KdenliveSettingsDialog(QMap<QString, QString> mappable_actions, bool gpuAllowed, QWidget *parent)
0101     : KConfigDialog(parent, QStringLiteral("settings"), KdenliveSettings::self())
0102     , m_modified(false)
0103     , m_shuttleModified(false)
0104     , m_voskUpdated(false)
0105     , m_mappable_actions(std::move(mappable_actions))
0106 {
0107     KdenliveSettings::setV4l_format(0);
0108 
0109     initMiscPage();
0110     initProjectPage();
0111     initProxyPage();
0112 
0113     QWidget *p3 = new QWidget;
0114     m_configTimeline.setupUi(p3);
0115     m_page3 = addPage(p3, i18n("Timeline"), QStringLiteral("video-display"));
0116 
0117     initEnviromentPage();
0118 
0119     QWidget *p10 = new QWidget;
0120     m_configColors.setupUi(p10);
0121     m_page10 = addPage(p10, i18n("Colors and Guides"), QStringLiteral("color-management"));
0122     m_guidesCategories = new GuideCategories(nullptr, this);
0123     QVBoxLayout *guidesLayout = new QVBoxLayout(m_configColors.guides_box);
0124     guidesLayout->addWidget(m_guidesCategories);
0125 
0126     QWidget *p11 = new QWidget;
0127     m_configSpeech.setupUi(p11);
0128     m_page11 = addPage(p11, i18n("Speech To Text"), QStringLiteral("text-speak"));
0129 
0130     QWidget *p6 = new QWidget;
0131     m_configSdl.setupUi(p6);
0132     m_page6 = addPage(p6, i18n("Playback"), QStringLiteral("media-playback-start"));
0133 
0134     QWidget *p4 = new QWidget;
0135     m_configCapture.setupUi(p4);
0136     m_decklinkProfiles = new EncodingProfilesChooser(this, EncodingProfilesManager::DecklinkCapture, false, QStringLiteral("decklink_profile"));
0137     m_configCapture.decklink_profile_box->addWidget(m_decklinkProfiles);
0138     m_v4lProfiles = new EncodingProfilesChooser(this, EncodingProfilesManager::V4LCapture, false, QStringLiteral("v4l_profile"));
0139     m_configCapture.v4l_profile_box->addWidget(m_v4lProfiles);
0140     m_grabProfiles = new EncodingProfilesChooser(this, EncodingProfilesManager::ScreenCapture, false, QStringLiteral("grab_profile"));
0141     m_configCapture.screen_grab_profile_box->addWidget(m_grabProfiles);
0142     m_page4 = addPage(p4, i18n("Capture"), QStringLiteral("media-record"));
0143 
0144     initDevices();
0145     initCapturePage();
0146     initJogShuttlePage();
0147     initTranscodePage();
0148 
0149     initSdlPage(gpuAllowed);
0150     initSpeechPage();
0151 
0152     // Config dialog size
0153     KSharedConfigPtr config = KSharedConfig::openConfig();
0154     KConfigGroup settingsGroup(config, "settings");
0155     QSize optimalSize;
0156 
0157     if (!settingsGroup.exists() || !settingsGroup.hasKey("dialogSize")) {
0158         const QSize screenSize = (QGuiApplication::primaryScreen()->availableSize() * 0.9);
0159         const QSize targetSize = QSize(1024, 700);
0160         optimalSize = targetSize.boundedTo(screenSize);
0161     } else {
0162         optimalSize = settingsGroup.readEntry("dialogSize", QVariant(size())).toSize();
0163     }
0164     resize(optimalSize);
0165 }
0166 
0167 // static
0168 bool KdenliveSettingsDialog::getBlackMagicDeviceList(QComboBox *devicelist, bool force)
0169 {
0170     if (!force && !KdenliveSettings::decklink_device_found()) {
0171         return false;
0172     }
0173     Mlt::Profile profile;
0174     Mlt::Producer bm(profile, "decklink");
0175     int found_devices = 0;
0176     if (bm.is_valid()) {
0177         bm.set("list_devices", 1);
0178         found_devices = bm.get_int("devices");
0179     } else {
0180         KdenliveSettings::setDecklink_device_found(false);
0181     }
0182     if (found_devices <= 0) {
0183         devicelist->setEnabled(false);
0184         return false;
0185     }
0186     KdenliveSettings::setDecklink_device_found(true);
0187     for (int i = 0; i < found_devices; ++i) {
0188         char *tmp = qstrdup(QStringLiteral("device.%1").arg(i).toUtf8().constData());
0189         devicelist->addItem(bm.get(tmp));
0190         delete[] tmp;
0191     }
0192     return true;
0193 }
0194 
0195 // static
0196 bool KdenliveSettingsDialog::initAudioRecDevice()
0197 {
0198     QStringList audioDevices = pCore->getAudioCaptureDevices();
0199 
0200     // show a hint to the user to know what to check for in case the device list are empty (common issue)
0201     m_configCapture.labelNoAudioDevices->setVisible(audioDevices.empty());
0202 
0203     m_configCapture.kcfg_defaultaudiocapture->addItems(audioDevices);
0204     connect(m_configCapture.kcfg_defaultaudiocapture, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [&]() {
0205         QString currentDevice = m_configCapture.kcfg_defaultaudiocapture->currentText();
0206         KdenliveSettings::setDefaultaudiocapture(currentDevice);
0207     });
0208     QString selectedDevice = KdenliveSettings::defaultaudiocapture();
0209     int selectedIndex = m_configCapture.kcfg_defaultaudiocapture->findText(selectedDevice);
0210     if (!selectedDevice.isEmpty() && selectedIndex > -1) {
0211         m_configCapture.kcfg_defaultaudiocapture->setCurrentIndex(selectedIndex);
0212     }
0213     return true;
0214 }
0215 
0216 void KdenliveSettingsDialog::initMiscPage()
0217 {
0218     QWidget *p1 = new QWidget;
0219     m_configMisc.setupUi(p1);
0220     m_page1 = addPage(p1, i18n("Misc"), QStringLiteral("configure"));
0221 
0222     m_configMisc.kcfg_use_exiftool->setEnabled(!QStandardPaths::findExecutable(QStringLiteral("exiftool")).isEmpty());
0223 
0224     static const QRegularExpression reg(R"((\+|-)?\d{2}:\d{2}:\d{2}(:||,)\d{2})");
0225     QValidator *validator = new QRegularExpressionValidator(reg, this);
0226     m_configMisc.kcfg_color_duration->setInputMask(pCore->timecode().mask());
0227     m_configMisc.kcfg_color_duration->setValidator(validator);
0228     m_configMisc.kcfg_title_duration->setInputMask(pCore->timecode().mask());
0229     m_configMisc.kcfg_title_duration->setValidator(validator);
0230     m_configMisc.kcfg_transition_duration->setInputMask(pCore->timecode().mask());
0231     m_configMisc.kcfg_transition_duration->setValidator(validator);
0232     m_configMisc.kcfg_mix_duration->setInputMask(pCore->timecode().mask());
0233     m_configMisc.kcfg_mix_duration->setValidator(validator);
0234     m_configMisc.kcfg_image_duration->setInputMask(pCore->timecode().mask());
0235     m_configMisc.kcfg_image_duration->setValidator(validator);
0236     m_configMisc.kcfg_sequence_duration->setInputMask(pCore->timecode().mask());
0237     m_configMisc.kcfg_sequence_duration->setValidator(validator);
0238     m_configMisc.kcfg_fade_duration->setInputMask(pCore->timecode().mask());
0239     m_configMisc.kcfg_fade_duration->setValidator(validator);
0240     m_configMisc.kcfg_subtitle_duration->setInputMask(pCore->timecode().mask());
0241     m_configMisc.kcfg_subtitle_duration->setValidator(validator);
0242 
0243     m_configMisc.preferredcomposite->clear();
0244     m_configMisc.preferredcomposite->addItem(i18n("auto"));
0245     m_configMisc.preferredcomposite->addItems(KdenliveSettings::compositingList());
0246 
0247     if (!KdenliveSettings::preferredcomposite().isEmpty()) {
0248         int ix = m_configMisc.preferredcomposite->findText(KdenliveSettings::preferredcomposite());
0249         if (ix > -1) {
0250             m_configMisc.preferredcomposite->setCurrentIndex(ix);
0251         }
0252     }
0253     connect(m_configMisc.preferredcomposite, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [&]() {
0254         if (m_configMisc.preferredcomposite->currentText() != KdenliveSettings::preferredcomposite()) {
0255             KdenliveSettings::setPreferredcomposite(m_configMisc.preferredcomposite->currentText());
0256             int mode = pCore->currentDoc()->getDocumentProperty(QStringLiteral("compositing")).toInt();
0257             pCore->window()->getCurrentTimeline()->controller()->switchCompositing(mode);
0258             pCore->currentDoc()->setModified();
0259         }
0260     });
0261 }
0262 
0263 void KdenliveSettingsDialog::initProjectPage()
0264 {
0265     QWidget *p8 = new QWidget;
0266     m_configProject.setupUi(p8);
0267     // Timeline preview
0268     QString currentPreviewData =
0269         KdenliveSettings::previewparams().isEmpty() ? QString() : QString("%1;%2").arg(KdenliveSettings::previewparams(), KdenliveSettings::previewextension());
0270     m_tlPreviewProfiles = new EncodingTimelinePreviewProfilesChooser(p8, true, currentPreviewData, false);
0271     m_configProject.preview_profile_box->addWidget(m_tlPreviewProfiles);
0272     auto *vbox = new QVBoxLayout;
0273     m_pw = new ProfileWidget(this);
0274     vbox->addWidget(m_pw);
0275     connect(m_pw, &ProfileWidget::profileChanged, this, [this]() { m_tlPreviewProfiles->filterPreviewProfiles(m_pw->selectedProfile()); });
0276     m_configProject.profile_box->setLayout(vbox);
0277     m_configProject.profile_box->setTitle(i18n("Select the Default Profile (preset)"));
0278     // Select profile
0279     m_pw->loadProfile(KdenliveSettings::default_profile().isEmpty() ? pCore->getCurrentProfile()->path() : KdenliveSettings::default_profile());
0280     m_tlPreviewProfiles->filterPreviewProfiles(m_pw->selectedProfile());
0281     connect(m_tlPreviewProfiles, &EncodingTimelinePreviewProfilesChooser::currentIndexChanged, this, &KdenliveSettingsDialog::slotDialogModified);
0282     connect(m_pw, &ProfileWidget::profileChanged, this, &KdenliveSettingsDialog::slotDialogModified);
0283     m_configProject.projecturl->setMode(KFile::Directory);
0284     m_configProject.projecturl->setUrl(QUrl::fromLocalFile(KdenliveSettings::defaultprojectfolder()));
0285     connect(m_configProject.kcfg_customprojectfolder, &QCheckBox::toggled, m_configProject.projecturl, &KUrlRequester::setEnabled);
0286     connect(m_configProject.kcfg_videotracks, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [this]() {
0287         if (m_configProject.kcfg_videotracks->value() + m_configProject.kcfg_audiotracks->value() <= 0) {
0288             m_configProject.kcfg_videotracks->setValue(1);
0289         }
0290     });
0291     connect(m_configProject.kcfg_audiotracks, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [this]() {
0292         if (m_configProject.kcfg_videotracks->value() + m_configProject.kcfg_audiotracks->value() <= 0) {
0293             m_configProject.kcfg_audiotracks->setValue(1);
0294         }
0295     });
0296 
0297     m_page8 = addPage(p8, i18n("Project Defaults"), QStringLiteral("project-defaults"));
0298 }
0299 
0300 void KdenliveSettingsDialog::initProxyPage()
0301 {
0302     QWidget *p9 = new QWidget;
0303     m_configProxy.setupUi(p9);
0304     m_proxyProfiles = new EncodingProfilesChooser(p9, EncodingProfilesManager::ProxyClips, true, QStringLiteral("proxy_profile"));
0305     m_configProxy.proxy_profile_box->addWidget(m_proxyProfiles);
0306     addPage(p9, i18n("Proxy Clips"), QStringLiteral("zoom-out"));
0307     connect(m_configProxy.kcfg_generateproxy, &QAbstractButton::toggled, m_configProxy.kcfg_proxyminsize, &QWidget::setEnabled);
0308     m_configProxy.kcfg_proxyminsize->setEnabled(KdenliveSettings::generateproxy());
0309     connect(m_configProxy.kcfg_generateimageproxy, &QAbstractButton::toggled, m_configProxy.kcfg_proxyimageminsize, &QWidget::setEnabled);
0310     m_configProxy.kcfg_proxyimageminsize->setEnabled(KdenliveSettings::generateimageproxy());
0311     loadExternalProxyProfiles();
0312 }
0313 
0314 void KdenliveSettingsDialog::initEnviromentPage()
0315 {
0316     QWidget *p2 = new QWidget;
0317     m_configEnv.setupUi(p2);
0318     m_configEnv.mltpathurl->setMode(KFile::Directory);
0319     m_configEnv.mltpathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_mltpath"));
0320     m_configEnv.rendererpathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_rendererpath"));
0321     m_configEnv.ffmpegurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffmpegpath"));
0322     m_configEnv.ffplayurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffplaypath"));
0323     m_configEnv.ffprobeurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffprobepath"));
0324     m_configEnv.mediainfourl->lineEdit()->setObjectName(QStringLiteral("kcfg_mediainfopath"));
0325     m_configEnv.tmppathurl->setMode(KFile::Directory);
0326     m_configEnv.tmppathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_currenttmpfolder"));
0327     m_configEnv.capturefolderurl->setMode(KFile::Directory);
0328     m_configEnv.capturefolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_capturefolder"));
0329     m_configEnv.capturefolderurl->setEnabled(KdenliveSettings::capturetoprojectfolder() == 2);
0330     m_configEnv.kcfg_capturetoprojectfolder->setItemText(0, i18n("Use default folder: %1", QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)));
0331     if (KdenliveSettings::customprojectfolder()) {
0332         m_configEnv.kcfg_capturetoprojectfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
0333     } else {
0334         m_configEnv.kcfg_capturetoprojectfolder->setItemText(1, i18n("Always use active project folder"));
0335     }
0336     connect(m_configEnv.kcfg_capturetoprojectfolder, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
0337             &KdenliveSettingsDialog::slotEnableCaptureFolder);
0338 
0339     // Library folder
0340     m_configEnv.libraryfolderurl->setMode(KFile::Directory);
0341     m_configEnv.libraryfolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_libraryfolder"));
0342     m_configEnv.libraryfolderurl->setEnabled(!KdenliveSettings::librarytodefaultfolder());
0343     m_configEnv.libraryfolderurl->setPlaceholderText(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/library"));
0344     m_configEnv.kcfg_librarytodefaultfolder->setToolTip(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/library"));
0345     connect(m_configEnv.kcfg_librarytodefaultfolder, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEnableLibraryFolder);
0346 
0347     m_configEnv.kcfg_proxythreads->setMaximum(qMax(1, QThread::idealThreadCount() - 1));
0348 
0349     // Script rendering files folder
0350     m_configEnv.videofolderurl->setMode(KFile::Directory);
0351     m_configEnv.videofolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_videofolder"));
0352     m_configEnv.videofolderurl->setEnabled(KdenliveSettings::videotodefaultfolder() == 2);
0353     m_configEnv.videofolderurl->setPlaceholderText(QStandardPaths::writableLocation(QStandardPaths::MoviesLocation));
0354     m_configEnv.kcfg_videotodefaultfolder->setItemText(0, i18n("Use default folder: %1", QStandardPaths::writableLocation(QStandardPaths::MoviesLocation)));
0355     if (KdenliveSettings::customprojectfolder()) {
0356         m_configEnv.kcfg_videotodefaultfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
0357     } else {
0358         m_configEnv.kcfg_videotodefaultfolder->setItemText(1, i18n("Always use active project folder"));
0359     }
0360     connect(m_configEnv.kcfg_videotodefaultfolder, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &KdenliveSettingsDialog::slotEnableVideoFolder);
0361 
0362     // Mime types
0363     QStringList mimes = ClipCreationDialog::getExtensions();
0364     std::sort(mimes.begin(), mimes.end());
0365     m_configEnv.supportedmimes->setPlainText(mimes.join(QLatin1Char(' ')));
0366 
0367     connect(m_configEnv.kp_image, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditImageApplication);
0368     connect(m_configEnv.kp_audio, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditAudioApplication);
0369     connect(m_configEnv.kp_anim, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditGlaxnimateApplication);
0370 
0371     m_page2 = addPage(p2, i18n("Environment"), QStringLiteral("application-x-executable-script"));
0372 }
0373 
0374 void KdenliveSettingsDialog::initCapturePage()
0375 {
0376     // Remove ffmpeg tab, unused
0377     m_configCapture.tabWidget->removeTab(0);
0378     m_configCapture.label->setVisible(false);
0379     m_configCapture.kcfg_defaultcapture->setVisible(false);
0380     // m_configCapture.tabWidget->removeTab(2);
0381 #ifdef USE_V4L
0382 
0383     // Video 4 Linux device detection
0384     for (int i = 0; i < 10; ++i) {
0385         QString path = QStringLiteral("/dev/video") + QString::number(i);
0386         if (QFile::exists(path)) {
0387             QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
0388             if (!deviceInfo.isEmpty()) {
0389                 m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
0390                 m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
0391             }
0392         }
0393     }
0394     connect(m_configCapture.kcfg_detectedv4ldevices, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0395             &KdenliveSettingsDialog::slotUpdatev4lDevice);
0396     connect(m_configCapture.kcfg_v4l_format, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0397             &KdenliveSettingsDialog::slotUpdatev4lCaptureProfile);
0398     connect(m_configCapture.config_v4l, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditVideo4LinuxProfile);
0399 
0400     slotUpdatev4lDevice();
0401 #endif
0402 
0403     m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
0404 #ifdef Q_WS_MAC
0405     m_configCapture.tabWidget->setEnabled(false);
0406     m_configCapture.kcfg_defaultcapture->setEnabled(false);
0407     m_configCapture.label->setText(i18n("Capture is not yet available on Mac OS X."));
0408 #endif
0409 
0410     connect(m_configCapture.kcfg_grab_capture_type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0411             &KdenliveSettingsDialog::slotUpdateGrabRegionStatus);
0412 
0413     slotUpdateGrabRegionStatus();
0414 
0415     // audio capture channels
0416     m_configCapture.audiocapturechannels->clear();
0417     m_configCapture.audiocapturechannels->addItem(i18n("Mono (1 channel)"), 1);
0418     m_configCapture.audiocapturechannels->addItem(i18n("Stereo (2 channels)"), 2);
0419 
0420     int channelsIndex = m_configCapture.audiocapturechannels->findData(KdenliveSettings::audiocapturechannels());
0421     m_configCapture.audiocapturechannels->setCurrentIndex(qMax(channelsIndex, 0));
0422     connect(m_configCapture.audiocapturechannels, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [&]() { updateButtons(); });
0423     // audio capture sample rate
0424     m_configCapture.audiocapturesamplerate->clear();
0425     m_configCapture.audiocapturesamplerate->addItem(i18n("44100 Hz"), 44100);
0426     m_configCapture.audiocapturesamplerate->addItem(i18n("48000 Hz"), 48000);
0427 
0428     int sampleRateIndex = m_configCapture.audiocapturesamplerate->findData(KdenliveSettings::audiocapturesamplerate());
0429     m_configCapture.audiocapturesamplerate->setCurrentIndex(qMax(sampleRateIndex, 0));
0430     connect(m_configCapture.audiocapturesamplerate, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [&]() { updateButtons(); });
0431 
0432     m_configCapture.labelNoAudioDevices->setVisible(false);
0433 
0434     initAudioRecDevice();
0435     getBlackMagicDeviceList(m_configCapture.kcfg_decklink_capturedevice);
0436 }
0437 
0438 void KdenliveSettingsDialog::initJogShuttlePage()
0439 {
0440     QWidget *p5 = new QWidget;
0441     m_configShuttle.setupUi(p5);
0442 #ifdef USE_JOGSHUTTLE
0443     connect(m_configShuttle.kcfg_enableshuttle, &QCheckBox::stateChanged, this, &KdenliveSettingsDialog::slotCheckShuttle);
0444     connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
0445     connect(m_configShuttle.toolBtnReload, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotReloadShuttleDevices);
0446 
0447     slotCheckShuttle(static_cast<int>(KdenliveSettings::enableshuttle()));
0448     m_configShuttle.shuttledisabled->hide();
0449 
0450     // Store the button pointers into an array for easier handling them in the other functions.
0451     // TODO: impl enumerator or live with cut and paste :-)))
0452     setupJogshuttleBtns(KdenliveSettings::shuttledevice());
0453 #if false
0454     m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
0455     m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
0456     m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
0457     m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
0458     m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
0459     m_shuttle_buttons.push_back(m_configShuttle.shuttle6);
0460     m_shuttle_buttons.push_back(m_configShuttle.shuttle7);
0461     m_shuttle_buttons.push_back(m_configShuttle.shuttle8);
0462     m_shuttle_buttons.push_back(m_configShuttle.shuttle9);
0463     m_shuttle_buttons.push_back(m_configShuttle.shuttle10);
0464     m_shuttle_buttons.push_back(m_configShuttle.shuttle11);
0465     m_shuttle_buttons.push_back(m_configShuttle.shuttle12);
0466     m_shuttle_buttons.push_back(m_configShuttle.shuttle13);
0467     m_shuttle_buttons.push_back(m_configShuttle.shuttle14);
0468     m_shuttle_buttons.push_back(m_configShuttle.shuttle15);
0469 #endif
0470 
0471 #else  /* ! USE_JOGSHUTTLE */
0472     m_configShuttle.kcfg_enableshuttle->hide();
0473     m_configShuttle.kcfg_enableshuttle->setDisabled(true);
0474 #endif /* USE_JOGSHUTTLE */
0475     m_page5 = addPage(p5, i18n("JogShuttle"), QStringLiteral("dialog-input-devices"));
0476 }
0477 
0478 void KdenliveSettingsDialog::initTranscodePage()
0479 {
0480     QWidget *p7 = new QWidget;
0481     m_configTranscode.setupUi(p7);
0482     m_page7 = addPage(p7, i18n("Transcode"), QStringLiteral("edit-copy"));
0483 
0484     connect(m_configTranscode.button_add, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotAddTranscode);
0485     connect(m_configTranscode.button_delete, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotDeleteTranscode);
0486     connect(m_configTranscode.profiles_list, &QListWidget::itemChanged, this, &KdenliveSettingsDialog::slotDialogModified);
0487     connect(m_configTranscode.profiles_list, &QListWidget::currentRowChanged, this, &KdenliveSettingsDialog::slotSetTranscodeProfile);
0488     connect(m_configTranscode.profile_description, &QLineEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
0489     connect(m_configTranscode.profile_extension, &QLineEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
0490     connect(m_configTranscode.profile_parameters, &QPlainTextEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
0491     connect(m_configTranscode.profile_audioonly, &QCheckBox::stateChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
0492 
0493     connect(m_configTranscode.button_update, &QAbstractButton::pressed, this, &KdenliveSettingsDialog::slotUpdateTranscodingProfile);
0494 
0495     m_configTranscode.profile_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
0496     loadTranscodeProfiles();
0497 }
0498 
0499 void KdenliveSettingsDialog::initSdlPage(bool gpuAllowed)
0500 {
0501     connect(m_configSdl.reload_blackmagic, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotReloadBlackMagic);
0502     // m_configSdl.kcfg_openglmonitors->setHidden(true);
0503     connect(m_configSdl.fullscreen_monitor, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0504             &KdenliveSettingsDialog::slotDialogModified);
0505     connect(m_configSdl.kcfg_audio_driver, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0506             &KdenliveSettingsDialog::slotCheckAlsaDriver);
0507     connect(m_configSdl.kcfg_audio_backend, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
0508             &KdenliveSettingsDialog::slotCheckAudioBackend);
0509 
0510     // enable GPU accel only if Movit is found
0511     m_configSdl.kcfg_gpu_accel->setEnabled(gpuAllowed);
0512     m_configSdl.kcfg_gpu_accel->setToolTip(i18n("GPU processing needs MLT compiled with Movit and Rtaudio modules"));
0513     if (!getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
0514         // No blackmagic card found
0515         m_configSdl.kcfg_external_display->setEnabled(false);
0516     }
0517 }
0518 
0519 bool KdenliveSettingsDialog::getBlackMagicOutputDeviceList(QComboBox *devicelist, bool force)
0520 {
0521     if (!force && !KdenliveSettings::decklink_device_found()) {
0522         return false;
0523     }
0524     Mlt::Profile profile;
0525     Mlt::Consumer bm(profile, "decklink");
0526     int found_devices = 0;
0527     if (bm.is_valid()) {
0528         bm.set("list_devices", 1);
0529         found_devices = bm.get_int("devices");
0530     } else {
0531         KdenliveSettings::setDecklink_device_found(false);
0532     }
0533     if (found_devices <= 0) {
0534         devicelist->setEnabled(false);
0535         return false;
0536     }
0537     KdenliveSettings::setDecklink_device_found(true);
0538     for (int i = 0; i < found_devices; ++i) {
0539         char *tmp = qstrdup(QStringLiteral("device.%1").arg(i).toUtf8().constData());
0540         devicelist->addItem(bm.get(tmp));
0541         delete[] tmp;
0542     }
0543     devicelist->addItem(QStringLiteral("test"));
0544     return true;
0545 }
0546 
0547 void KdenliveSettingsDialog::setupJogshuttleBtns(const QString &device)
0548 {
0549     QList<QComboBox *> list;
0550     QList<QLabel *> list1;
0551 
0552     list << m_configShuttle.shuttle1;
0553     list << m_configShuttle.shuttle2;
0554     list << m_configShuttle.shuttle3;
0555     list << m_configShuttle.shuttle4;
0556     list << m_configShuttle.shuttle5;
0557     list << m_configShuttle.shuttle6;
0558     list << m_configShuttle.shuttle7;
0559     list << m_configShuttle.shuttle8;
0560     list << m_configShuttle.shuttle9;
0561     list << m_configShuttle.shuttle10;
0562     list << m_configShuttle.shuttle11;
0563     list << m_configShuttle.shuttle12;
0564     list << m_configShuttle.shuttle13;
0565     list << m_configShuttle.shuttle14;
0566     list << m_configShuttle.shuttle15;
0567 
0568     list1 << m_configShuttle.label_2;  // #1
0569     list1 << m_configShuttle.label_4;  // #2
0570     list1 << m_configShuttle.label_3;  // #3
0571     list1 << m_configShuttle.label_7;  // #4
0572     list1 << m_configShuttle.label_5;  // #5
0573     list1 << m_configShuttle.label_6;  // #6
0574     list1 << m_configShuttle.label_8;  // #7
0575     list1 << m_configShuttle.label_9;  // #8
0576     list1 << m_configShuttle.label_10; // #9
0577     list1 << m_configShuttle.label_11; // #10
0578     list1 << m_configShuttle.label_12; // #11
0579     list1 << m_configShuttle.label_13; // #12
0580     list1 << m_configShuttle.label_14; // #13
0581     list1 << m_configShuttle.label_15; // #14
0582     list1 << m_configShuttle.label_16; // #15
0583 
0584     for (int i = 0; i < list.count(); ++i) {
0585         list[i]->hide();
0586         list1[i]->hide();
0587     }
0588 #ifdef USE_JOGSHUTTLE
0589     if (!m_configShuttle.kcfg_enableshuttle->isChecked()) {
0590         return;
0591     }
0592     int keysCount = JogShuttle::keysCount(device);
0593 
0594     for (int i = 0; i < keysCount; ++i) {
0595         m_shuttle_buttons.push_back(list[i]);
0596         list[i]->show();
0597         list1[i]->show();
0598     }
0599 
0600     // populate the buttons with the current configuration. The items are sorted
0601     // according to the user-selected language, so they do not appear in random order.
0602     QMap<QString, QString> mappable_actions(m_mappable_actions);
0603     QList<QString> action_names = mappable_actions.keys();
0604     QList<QString>::Iterator iter = action_names.begin();
0605     // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
0606     while (iter != action_names.end()) {
0607         // qCDebug(KDENLIVE_LOG) << *iter;
0608         ++iter;
0609     }
0610 
0611     // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
0612 
0613     std::sort(action_names.begin(), action_names.end());
0614     iter = action_names.begin();
0615     while (iter != action_names.end()) {
0616         // qCDebug(KDENLIVE_LOG) << *iter;
0617         ++iter;
0618     }
0619     // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
0620 
0621     // Here we need to compute the action_id -> index-in-action_names. We iterate over the
0622     // action_names, as the sorting may depend on the user-language.
0623     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
0624     QMap<QString, int> action_pos;
0625     for (const QString &action_id : qAsConst(actions_map)) {
0626         // This loop find out at what index is the string that would map to the action_id.
0627         for (int i = 0; i < action_names.size(); ++i) {
0628             if (mappable_actions[action_names.at(i)] == action_id) {
0629                 action_pos[action_id] = i;
0630                 break;
0631             }
0632         }
0633     }
0634 
0635     int i = 0;
0636     for (QComboBox *button : qAsConst(m_shuttle_buttons)) {
0637         button->addItems(action_names);
0638         connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
0639         ++i;
0640         if (i < actions_map.size()) {
0641             button->setCurrentIndex(action_pos[actions_map[i]]);
0642         }
0643     }
0644 #else
0645     Q_UNUSED(device)
0646 #endif
0647 }
0648 
0649 KdenliveSettingsDialog::~KdenliveSettingsDialog() = default;
0650 
0651 void KdenliveSettingsDialog::slotUpdateGrabRegionStatus()
0652 {
0653     m_configCapture.region_group->setHidden(m_configCapture.kcfg_grab_capture_type->currentIndex() != 1);
0654 }
0655 
0656 void KdenliveSettingsDialog::slotEnableCaptureFolder(int ix)
0657 {
0658     m_configEnv.capturefolderurl->setEnabled(ix == 2);
0659 }
0660 
0661 void KdenliveSettingsDialog::slotEnableLibraryFolder()
0662 {
0663     m_configEnv.libraryfolderurl->setEnabled(!m_configEnv.kcfg_librarytodefaultfolder->isChecked());
0664 }
0665 
0666 void KdenliveSettingsDialog::slotEnableVideoFolder(int ix)
0667 {
0668     m_configEnv.videofolderurl->setEnabled(ix == 2);
0669 }
0670 
0671 void KdenliveSettingsDialog::initDevices()
0672 {
0673     // Fill audio drivers
0674     m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
0675 #if defined(Q_OS_WIN)
0676     // TODO: i18n
0677     m_configSdl.kcfg_audio_driver->addItem("DirectSound", "directsound");
0678     m_configSdl.kcfg_audio_driver->addItem("WinMM", "winmm");
0679     m_configSdl.kcfg_audio_driver->addItem("Wasapi", "wasapi");
0680 #elif !defined(Q_WS_MAC)
0681     m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
0682     m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulseaudio");
0683     m_configSdl.kcfg_audio_driver->addItem(i18n("PipeWire"), "pipewire");
0684     m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
0685     // m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
0686     m_configSdl.kcfg_audio_driver->addItem(i18n("Esound Daemon"), "esd");
0687     m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS Daemon"), "artsc");
0688 #endif
0689 
0690     if (!KdenliveSettings::audiodrivername().isEmpty())
0691         for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); ++i) {
0692             if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
0693                 m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
0694                 KdenliveSettings::setAudio_driver(uint(i));
0695             }
0696         }
0697 
0698     // Fill the list of audio playback / recording devices
0699     m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
0700     m_configCapture.kcfg_v4l_alsadevice->addItem(i18n("Default"), "default");
0701     if (!QStandardPaths::findExecutable(QStringLiteral("aplay")).isEmpty()) {
0702         m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
0703         m_readProcess.setProgram(QStringLiteral("aplay"), QStringList() << QStringLiteral("-l"));
0704         connect(&m_readProcess, &KProcess::readyReadStandardOutput, this, &KdenliveSettingsDialog::slotReadAudioDevices);
0705         m_readProcess.execute(5000);
0706     } else {
0707         // If aplay is not installed on the system, parse the /proc/asound/pcm file
0708         QFile file(QStringLiteral("/proc/asound/pcm"));
0709         if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
0710             QTextStream stream(&file);
0711             QString line = stream.readLine();
0712             QString deviceId;
0713             while (!line.isNull()) {
0714                 if (line.contains(QStringLiteral("playback"))) {
0715                     deviceId = line.section(QLatin1Char(':'), 0, 0);
0716                     m_configSdl.kcfg_audio_device->addItem(line.section(QLatin1Char(':'), 1, 1), QStringLiteral("plughw:%1,%2")
0717                                                                                                      .arg(deviceId.section(QLatin1Char('-'), 0, 0).toInt())
0718                                                                                                      .arg(deviceId.section(QLatin1Char('-'), 1, 1).toInt()));
0719                 }
0720                 if (line.contains(QStringLiteral("capture"))) {
0721                     deviceId = line.section(QLatin1Char(':'), 0, 0);
0722                     m_configCapture.kcfg_v4l_alsadevice->addItem(
0723                         line.section(QLatin1Char(':'), 1, 1).simplified(),
0724                         QStringLiteral("hw:%1,%2").arg(deviceId.section(QLatin1Char('-'), 0, 0).toInt()).arg(deviceId.section(QLatin1Char('-'), 1, 1).toInt()));
0725                 }
0726                 line = stream.readLine();
0727             }
0728             file.close();
0729         } else {
0730             qCDebug(KDENLIVE_LOG) << " / / / /CANNOT READ PCM";
0731         }
0732     }
0733 
0734     // Add pulseaudio capture option
0735     m_configCapture.kcfg_v4l_alsadevice->addItem(i18n("PulseAudio"), "pulse");
0736 
0737     if (!KdenliveSettings::audiodevicename().isEmpty()) {
0738         // Select correct alsa device
0739         int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
0740         m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
0741         KdenliveSettings::setAudio_device(ix);
0742     }
0743 
0744     if (!KdenliveSettings::v4l_alsadevicename().isEmpty()) {
0745         // Select correct alsa device
0746         int ix = m_configCapture.kcfg_v4l_alsadevice->findData(KdenliveSettings::v4l_alsadevicename());
0747         m_configCapture.kcfg_v4l_alsadevice->setCurrentIndex(ix);
0748         KdenliveSettings::setV4l_alsadevice(ix);
0749     }
0750 
0751     m_configSdl.kcfg_audio_backend->addItem(i18n("SDL"), KdenliveSettings::sdlAudioBackend());
0752     if (KdenliveSettings::consumerslist().isEmpty()) {
0753         Mlt::Properties *consumers = pCore->getMltRepository()->consumers();
0754         QStringList consumersItemList;
0755         consumersItemList.reserve(consumers->count());
0756         for (int i = 0; i < consumers->count(); ++i) {
0757             consumersItemList << consumers->get_name(i);
0758         }
0759         delete consumers;
0760         KdenliveSettings::setConsumerslist(consumersItemList);
0761     }
0762     if (KdenliveSettings::consumerslist().contains("rtaudio")) {
0763         m_configSdl.kcfg_audio_backend->addItem(i18n("RtAudio"), "rtaudio");
0764     }
0765 
0766     if (!KdenliveSettings::audiobackend().isEmpty()) {
0767         int ix = m_configSdl.kcfg_audio_backend->findData(KdenliveSettings::audiobackend());
0768         m_configSdl.kcfg_audio_backend->setCurrentIndex(ix);
0769         KdenliveSettings::setAudio_backend(ix);
0770     }
0771     slotCheckAudioBackend();
0772 
0773     // Fill monitors data
0774     fillMonitorData();
0775     connect(qApp, &QApplication::screenAdded, this, &KdenliveSettingsDialog::fillMonitorData);
0776     connect(qApp, &QApplication::screenRemoved, this, &KdenliveSettingsDialog::fillMonitorData);
0777     loadCurrentV4lProfileInfo();
0778 }
0779 
0780 void KdenliveSettingsDialog::fillMonitorData()
0781 {
0782     QSignalBlocker bk(m_configSdl.fullscreen_monitor);
0783     m_configSdl.fullscreen_monitor->clear();
0784     m_configSdl.fullscreen_monitor->addItem(i18n("auto"));
0785     int ix = 0;
0786     for (const QScreen *screen : qApp->screens()) {
0787         QString screenName = screen->name().isEmpty() ? i18n("Monitor %1", ix + 1) : QString("%1: %2").arg(ix + 1).arg(screen->name());
0788         if (!screen->model().isEmpty()) {
0789             screenName.append(QString(" - %1").arg(screen->model()));
0790         }
0791         if (!screen->manufacturer().isEmpty()) {
0792             screenName.append(QString(" (%1)").arg(screen->manufacturer()));
0793         }
0794         m_configSdl.fullscreen_monitor->addItem(screenName, QString("%1:%2").arg(QString::number(ix), screen->serialNumber()));
0795         ix++;
0796     }
0797     if (!KdenliveSettings::fullscreen_monitor().isEmpty()) {
0798         int ix = m_configSdl.fullscreen_monitor->findData(KdenliveSettings::fullscreen_monitor());
0799         if (ix > -1) {
0800             m_configSdl.fullscreen_monitor->setCurrentIndex(ix);
0801         } else {
0802             // Monitor not found, reset
0803             m_configSdl.fullscreen_monitor->setCurrentIndex(0);
0804             KdenliveSettings::setFullscreen_monitor(QString());
0805         }
0806     }
0807 }
0808 
0809 void KdenliveSettingsDialog::slotReadAudioDevices()
0810 {
0811     QString result = QString(m_readProcess.readAllStandardOutput());
0812     // qCDebug(KDENLIVE_LOG) << "// / / / / / READING APLAY: ";
0813     // qCDebug(KDENLIVE_LOG) << result;
0814     const QStringList lines = result.split(QLatin1Char('\n'));
0815     for (const QString &devicestr : lines) {
0816         ////qCDebug(KDENLIVE_LOG) << "// READING LINE: " << data;
0817         if (!devicestr.startsWith(QLatin1Char(' ')) && devicestr.count(QLatin1Char(':')) > 1) {
0818             QString card = devicestr.section(QLatin1Char(':'), 0, 0).section(QLatin1Char(' '), -1);
0819             QString device = devicestr.section(QLatin1Char(':'), 1, 1).section(QLatin1Char(' '), -1);
0820             m_configSdl.kcfg_audio_device->addItem(devicestr.section(QLatin1Char(':'), -1).simplified(), QStringLiteral("plughw:%1,%2").arg(card, device));
0821             m_configCapture.kcfg_v4l_alsadevice->addItem(devicestr.section(QLatin1Char(':'), -1).simplified(), QStringLiteral("hw:%1,%2").arg(card, device));
0822         }
0823     }
0824 }
0825 
0826 void KdenliveSettingsDialog::showPage(int page, int option)
0827 {
0828     switch (page) {
0829     case 1:
0830         setCurrentPage(m_page1);
0831         break;
0832     case 2:
0833         setCurrentPage(m_page2);
0834         break;
0835     case 3:
0836         setCurrentPage(m_page3);
0837         break;
0838     case 4:
0839         setCurrentPage(m_page4);
0840         m_configCapture.tabWidget->setCurrentIndex(option);
0841         break;
0842     case 5:
0843         setCurrentPage(m_page5);
0844         break;
0845     case 6:
0846         setCurrentPage(m_page6);
0847         break;
0848     case 7:
0849         setCurrentPage(m_page7);
0850         break;
0851     case 8:
0852         setCurrentPage(m_page11);
0853         m_stt->checkDependencies();
0854         break;
0855     default:
0856         setCurrentPage(m_page1);
0857     }
0858 }
0859 
0860 void KdenliveSettingsDialog::slotEditAudioApplication()
0861 {
0862     QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::defaultaudioapp()), this, i18n("Enter path to the audio editing application"));
0863     if (!url.isEmpty()) {
0864         m_configEnv.kcfg_defaultaudioapp->setText(url.toLocalFile());
0865     }
0866 }
0867 
0868 void KdenliveSettingsDialog::slotEditImageApplication()
0869 {
0870     QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::defaultimageapp()), this, i18n("Enter path to the image editing application"));
0871     if (!url.isEmpty()) {
0872         m_configEnv.kcfg_defaultimageapp->setText(url.toLocalFile());
0873     }
0874 }
0875 
0876 void KdenliveSettingsDialog::slotEditGlaxnimateApplication()
0877 {
0878     QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(KdenliveSettings::glaxnimatePath()), this, i18n("Enter path to the Glaxnimate application"));
0879     if (!url.isEmpty()) {
0880         m_configEnv.kcfg_glaxnimatePath->setText(url.toLocalFile());
0881     }
0882 }
0883 
0884 void KdenliveSettingsDialog::slotCheckShuttle(int state)
0885 {
0886 #ifdef USE_JOGSHUTTLE
0887     m_configShuttle.config_group->setEnabled(state != Qt::Unchecked);
0888     m_configShuttle.shuttledevicelist->clear();
0889 
0890     QStringList devNames = KdenliveSettings::shuttledevicenames();
0891     QStringList devPaths = KdenliveSettings::shuttledevicepaths();
0892 
0893     if (devNames.count() != devPaths.count()) {
0894         return;
0895     }
0896     for (int i = 0; i < devNames.count(); ++i) {
0897         m_configShuttle.shuttledevicelist->addItem(devNames.at(i), devPaths.at(i));
0898     }
0899     if (state != Qt::Unchecked) {
0900         setupJogshuttleBtns(m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString());
0901     }
0902 #else
0903     Q_UNUSED(state)
0904 #endif /* USE_JOGSHUTTLE */
0905 }
0906 
0907 void KdenliveSettingsDialog::slotUpdateShuttleDevice(int ix)
0908 {
0909 #ifdef USE_JOGSHUTTLE
0910     QString device = m_configShuttle.shuttledevicelist->itemData(ix).toString();
0911     // KdenliveSettings::setShuttledevice(device);
0912     setupJogshuttleBtns(device);
0913     m_configShuttle.kcfg_shuttledevice->setText(device);
0914 #else
0915     Q_UNUSED(ix)
0916 #endif /* USE_JOGSHUTTLE */
0917 }
0918 
0919 void KdenliveSettingsDialog::updateWidgets()
0920 {
0921 // Revert widgets to last saved state (for example when user pressed "Cancel")
0922 // //qCDebug(KDENLIVE_LOG) << "// // // KCONFIG Revert called";
0923 #ifdef USE_JOGSHUTTLE
0924     // revert jog shuttle device
0925     if (m_configShuttle.shuttledevicelist->count() > 0) {
0926         for (int i = 0; i < m_configShuttle.shuttledevicelist->count(); ++i) {
0927             if (m_configShuttle.shuttledevicelist->itemData(i) == KdenliveSettings::shuttledevice()) {
0928                 m_configShuttle.shuttledevicelist->setCurrentIndex(i);
0929                 break;
0930             }
0931         }
0932     }
0933 
0934     // Revert jog shuttle buttons
0935     QList<QString> action_names = m_mappable_actions.keys();
0936     std::sort(action_names.begin(), action_names.end());
0937     QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
0938     QMap<QString, int> action_pos;
0939     for (const QString &action_id : qAsConst(actions_map)) {
0940         // This loop find out at what index is the string that would map to the action_id.
0941         for (int i = 0; i < action_names.size(); ++i) {
0942             if (m_mappable_actions[action_names[i]] == action_id) {
0943                 action_pos[action_id] = i;
0944                 break;
0945             }
0946         }
0947     }
0948     int i = 0;
0949     for (QComboBox *button : qAsConst(m_shuttle_buttons)) {
0950         ++i;
0951         if (i < actions_map.size()) {
0952             button->setCurrentIndex(action_pos[actions_map[i]]);
0953         }
0954     }
0955 #endif /* USE_JOGSHUTTLE */
0956 }
0957 
0958 void KdenliveSettingsDialog::accept()
0959 {
0960     if (m_pw->selectedProfile().isEmpty()) {
0961         KMessageBox::error(this, i18n("Please select a video profile"));
0962         return;
0963     }
0964     KConfigDialog::accept();
0965 }
0966 
0967 void KdenliveSettingsDialog::updateExternalApps()
0968 {
0969     m_configEnv.kcfg_defaultimageapp->setText(KdenliveSettings::defaultimageapp());
0970     m_configEnv.kcfg_defaultaudioapp->setText(KdenliveSettings::defaultaudioapp());
0971     m_configEnv.kcfg_glaxnimatePath->setText(KdenliveSettings::glaxnimatePath());
0972 }
0973 
0974 void KdenliveSettingsDialog::updateSettings()
0975 {
0976     // Save changes to settings (for example when user pressed "Apply" or "Ok")
0977     // //qCDebug(KDENLIVE_LOG) << "// // // KCONFIG UPDATE called";
0978     if (m_pw->selectedProfile().isEmpty()) {
0979         KMessageBox::error(this, i18n("Please select a video profile"));
0980         return;
0981     }
0982     KdenliveSettings::setDefault_profile(m_pw->selectedProfile());
0983 
0984     if (m_configEnv.ffmpegurl->text().isEmpty()) {
0985         QString infos;
0986         QString warnings;
0987         Wizard::slotCheckPrograms(infos, warnings);
0988         m_configEnv.ffmpegurl->setText(KdenliveSettings::ffmpegpath());
0989         m_configEnv.ffplayurl->setText(KdenliveSettings::ffplaypath());
0990         m_configEnv.ffprobeurl->setText(KdenliveSettings::ffprobepath());
0991     }
0992     if (m_configEnv.mediainfourl->text().isEmpty()) {
0993         m_configEnv.mediainfourl->setText(KdenliveSettings::mediainfopath());
0994     }
0995 
0996     if (m_configTimeline.kcfg_trackheight->value() == 0) {
0997         QFont ft = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
0998         // Default unit for timeline.qml objects size
0999         int baseUnit = qMax(28, qRound(QFontInfo(ft).pixelSize() * 1.8));
1000         int trackHeight = qMax(50, int(2.2 * baseUnit + 6));
1001         m_configTimeline.kcfg_trackheight->setValue(trackHeight);
1002     } else if (m_configTimeline.kcfg_trackheight->value() != KdenliveSettings::trackheight()) {
1003         QFont ft = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
1004         // Default unit for timeline.qml objects size
1005         int baseUnit = qMax(28, qRound(QFontInfo(ft).pixelSize() * 1.8));
1006         if (m_configTimeline.kcfg_trackheight->value() < baseUnit) {
1007             m_configTimeline.kcfg_trackheight->setValue(baseUnit);
1008         }
1009     }
1010 
1011     bool resetConsumer = false;
1012     bool fullReset = false;
1013     bool updateLibrary = false;
1014 
1015     // Guide categories
1016     const QStringList updatedGuides = m_guidesCategories->updatedGuides();
1017     if (KdenliveSettings::guidesCategories() != updatedGuides) {
1018         KdenliveSettings::setGuidesCategories(updatedGuides);
1019     }
1020 
1021     /*if (m_configShuttle.shuttledevicelist->count() > 0) {
1022     QString device = m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString();
1023     if (device != KdenliveSettings::shuttledevice()) KdenliveSettings::setShuttledevice(device);
1024     }*/
1025     m_tlPreviewProfiles->hideMessage();
1026     if (m_configProject.projecturl->url().toLocalFile() != KdenliveSettings::defaultprojectfolder()) {
1027         KdenliveSettings::setDefaultprojectfolder(m_configProject.projecturl->url().toLocalFile());
1028         if (!KdenliveSettings::sameprojectfolder()) {
1029             m_configEnv.kcfg_videotodefaultfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
1030             m_configEnv.kcfg_capturetoprojectfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
1031         }
1032     }
1033 
1034     if (m_configProject.kcfg_customprojectfolder->isChecked() != KdenliveSettings::customprojectfolder()) {
1035         if (KdenliveSettings::customprojectfolder()) {
1036             m_configEnv.kcfg_videotodefaultfolder->setItemText(1, i18n("Always use active project folder"));
1037             m_configEnv.kcfg_capturetoprojectfolder->setItemText(1, i18n("Always use active project folder"));
1038         } else {
1039             m_configEnv.kcfg_videotodefaultfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
1040             m_configEnv.kcfg_capturetoprojectfolder->setItemText(1, i18n("Always use project folder: %1", KdenliveSettings::defaultprojectfolder()));
1041         }
1042     }
1043 
1044     if (m_configSdl.fullscreen_monitor->currentData().toString() != KdenliveSettings::fullscreen_monitor()) {
1045         KdenliveSettings::setFullscreen_monitor(m_configSdl.fullscreen_monitor->currentData().toString());
1046     }
1047 
1048     if (m_configEnv.capturefolderurl->url().toLocalFile() != KdenliveSettings::capturefolder()) {
1049         KdenliveSettings::setCapturefolder(m_configEnv.capturefolderurl->url().toLocalFile());
1050     }
1051 
1052     // Library default folder
1053     if (m_configEnv.kcfg_librarytodefaultfolder->isChecked() != KdenliveSettings::librarytodefaultfolder()) {
1054         KdenliveSettings::setLibrarytodefaultfolder(m_configEnv.kcfg_librarytodefaultfolder->isChecked());
1055         updateLibrary = true;
1056     }
1057 
1058     if (m_configEnv.libraryfolderurl->url().toLocalFile() != KdenliveSettings::libraryfolder()) {
1059         KdenliveSettings::setLibraryfolder(m_configEnv.libraryfolderurl->url().toLocalFile());
1060         if (!KdenliveSettings::librarytodefaultfolder()) {
1061             updateLibrary = true;
1062         }
1063     }
1064 
1065     if (m_configCapture.kcfg_v4l_format->currentIndex() != int(KdenliveSettings::v4l_format())) {
1066         saveCurrentV4lProfile();
1067         KdenliveSettings::setV4l_format(0);
1068     }
1069 
1070     // Check if screengrab is fullscreen
1071     if (m_configCapture.kcfg_grab_capture_type->currentIndex() != KdenliveSettings::grab_capture_type()) {
1072         KdenliveSettings::setGrab_capture_type(m_configCapture.kcfg_grab_capture_type->currentIndex());
1073         emit updateFullScreenGrab();
1074     }
1075 
1076     // Check audio capture changes
1077     if (KdenliveSettings::audiocapturechannels() != m_configCapture.audiocapturechannels->currentData().toInt() ||
1078         KdenliveSettings::audiocapturevolume() != m_configCapture.kcfg_audiocapturevolume->value() ||
1079         KdenliveSettings::audiocapturesamplerate() != m_configCapture.audiocapturesamplerate->currentData().toInt()) {
1080         KdenliveSettings::setAudiocapturechannels(m_configCapture.audiocapturechannels->currentData().toInt());
1081         KdenliveSettings::setAudiocapturevolume(m_configCapture.kcfg_audiocapturevolume->value());
1082         KdenliveSettings::setAudiocapturesamplerate(m_configCapture.audiocapturesamplerate->currentData().toInt());
1083         emit resetAudioMonitoring();
1084     }
1085 
1086     // Check encoding profiles
1087     // FFmpeg
1088     QString string = m_v4lProfiles->currentParams();
1089     if (string != KdenliveSettings::v4l_parameters()) {
1090         KdenliveSettings::setV4l_parameters(string);
1091     }
1092     string = m_v4lProfiles->currentExtension();
1093     if (string != KdenliveSettings::v4l_extension()) {
1094         KdenliveSettings::setV4l_extension(string);
1095     }
1096 
1097     // screengrab
1098     string = m_grabProfiles->currentParams();
1099     if (string != KdenliveSettings::grab_parameters()) {
1100         KdenliveSettings::setGrab_parameters(string);
1101     }
1102     string = m_grabProfiles->currentExtension();
1103     if (string != KdenliveSettings::grab_extension()) {
1104         KdenliveSettings::setGrab_extension(string);
1105     }
1106 
1107     // decklink
1108     string = m_decklinkProfiles->currentParams();
1109     if (string != KdenliveSettings::decklink_parameters()) {
1110         KdenliveSettings::setDecklink_parameters(string);
1111     }
1112     string = m_decklinkProfiles->currentExtension();
1113     if (string != KdenliveSettings::decklink_extension()) {
1114         KdenliveSettings::setDecklink_extension(string);
1115     }
1116 
1117     // proxies
1118     string = m_proxyProfiles->currentParams();
1119     if (string != KdenliveSettings::proxyparams()) {
1120         KdenliveSettings::setProxyparams(string);
1121     }
1122     string = m_proxyProfiles->currentExtension();
1123     if (string != KdenliveSettings::proxyextension()) {
1124         KdenliveSettings::setProxyextension(string);
1125     }
1126 
1127     // external proxies
1128     QString profilestr = m_configProxy.kcfg_external_proxy_profile->currentData().toString();
1129     if (!profilestr.isEmpty() && (profilestr != KdenliveSettings::externalProxyProfile())) {
1130         KdenliveSettings::setExternalProxyProfile(profilestr);
1131     }
1132 
1133     // timeline preview
1134     string = m_tlPreviewProfiles->currentParams();
1135     if (string != KdenliveSettings::previewparams()) {
1136         KdenliveSettings::setPreviewparams(string);
1137     }
1138     string = m_tlPreviewProfiles->currentExtension();
1139     if (string != KdenliveSettings::previewextension()) {
1140         KdenliveSettings::setPreviewextension(string);
1141     }
1142 
1143     if (updateLibrary) {
1144         emit updateLibraryFolder();
1145     }
1146 
1147     QString value = m_configCapture.kcfg_v4l_alsadevice->currentData().toString();
1148     if (value != KdenliveSettings::v4l_alsadevicename()) {
1149         KdenliveSettings::setV4l_alsadevicename(value);
1150     }
1151 
1152     if (m_configSdl.kcfg_external_display->isChecked() != KdenliveSettings::external_display()) {
1153         KdenliveSettings::setExternal_display(m_configSdl.kcfg_external_display->isChecked());
1154         resetConsumer = true;
1155         fullReset = true;
1156     } else if (KdenliveSettings::external_display() &&
1157                KdenliveSettings::blackmagic_output_device() != m_configSdl.kcfg_blackmagic_output_device->currentIndex()) {
1158         resetConsumer = true;
1159         fullReset = true;
1160     }
1161 
1162     value = m_configSdl.kcfg_audio_driver->currentData().toString();
1163     if (value != KdenliveSettings::audiodrivername()) {
1164         KdenliveSettings::setAudiodrivername(value);
1165         resetConsumer = true;
1166     }
1167 
1168     if (value == QLatin1String("alsa")) {
1169         // Audio device setting is only valid for alsa driver
1170         value = m_configSdl.kcfg_audio_device->currentData().toString();
1171         if (value != KdenliveSettings::audiodevicename()) {
1172             KdenliveSettings::setAudiodevicename(value);
1173             resetConsumer = true;
1174         }
1175     } else if (!KdenliveSettings::audiodevicename().isEmpty()) {
1176         KdenliveSettings::setAudiodevicename(QString());
1177         resetConsumer = true;
1178     }
1179 
1180     value = m_configSdl.kcfg_audio_backend->currentData().toString();
1181     if (value != KdenliveSettings::audiobackend()) {
1182         KdenliveSettings::setAudiobackend(value);
1183         resetConsumer = true;
1184         fullReset = true;
1185     }
1186 
1187     if (m_configColors.kcfg_window_background->color() != KdenliveSettings::window_background()) {
1188         KdenliveSettings::setWindow_background(m_configColors.kcfg_window_background->color());
1189         emit updateMonitorBg();
1190     }
1191 
1192     if (m_configColors.kcfg_thumbColor1->color() != KdenliveSettings::thumbColor1() ||
1193         m_configColors.kcfg_thumbColor2->color() != KdenliveSettings::thumbColor2()) {
1194         KdenliveSettings::setThumbColor1(m_configColors.kcfg_thumbColor1->color());
1195         KdenliveSettings::setThumbColor2(m_configColors.kcfg_thumbColor2->color());
1196         emit pCore->window()->getCurrentTimeline()->controller()->colorsChanged();
1197         pCore->getMonitor(Kdenlive::ClipMonitor)->refreshAudioThumbs();
1198     }
1199 
1200     if (m_configColors.kcfg_overlayColor->color() != KdenliveSettings::overlayColor()) {
1201         KdenliveSettings::setOverlayColor(m_configColors.kcfg_overlayColor->color());
1202         pCore->getMonitor(Kdenlive::ProjectMonitor)->getControllerProxy()->colorsChanged();
1203         pCore->getMonitor(Kdenlive::ClipMonitor)->getControllerProxy()->colorsChanged();
1204     }
1205 
1206     if (m_configMisc.kcfg_tabposition->currentIndex() != KdenliveSettings::tabposition()) {
1207         KdenliveSettings::setTabposition(m_configMisc.kcfg_tabposition->currentIndex());
1208     }
1209 
1210     if (m_configTimeline.kcfg_displayallchannels->isChecked() != KdenliveSettings::displayallchannels()) {
1211         KdenliveSettings::setDisplayallchannels(m_configTimeline.kcfg_displayallchannels->isChecked());
1212         emit audioThumbFormatChanged();
1213         pCore->getMonitor(Kdenlive::ClipMonitor)->refreshAudioThumbs();
1214     }
1215 
1216     if (m_modified) {
1217         // The transcoding profiles were modified, save.
1218         m_modified = false;
1219         saveTranscodeProfiles();
1220     }
1221 
1222 #ifdef USE_JOGSHUTTLE
1223     m_shuttleModified = false;
1224 
1225     QStringList actions;
1226     actions << QStringLiteral("monitor_pause"); // the Job rest position action.
1227     for (QComboBox *button : qAsConst(m_shuttle_buttons)) {
1228         actions << m_mappable_actions[button->currentText()];
1229     }
1230     QString maps = JogShuttleConfig::actionMap(actions);
1231     // fprintf(stderr, "Shuttle config: %s\n", JogShuttleConfig::actionMap(actions).toLatin1().constData());
1232     if (KdenliveSettings::shuttlebuttons() != maps) {
1233         KdenliveSettings::setShuttlebuttons(maps);
1234     }
1235 #endif
1236 
1237     bool restart = false;
1238     if (m_configSdl.kcfg_gpu_accel->isChecked() != KdenliveSettings::gpu_accel()) {
1239         // GPU setting was changed, we need to restart Kdenlive or everything will be corrupted
1240         if (KMessageBox::warningContinueCancel(this, i18n("Kdenlive must be restarted to change this setting")) == KMessageBox::Continue) {
1241             restart = true;
1242         } else {
1243             m_configSdl.kcfg_gpu_accel->setChecked(KdenliveSettings::gpu_accel());
1244         }
1245     }
1246 
1247     if (m_configTimeline.kcfg_trackheight->value() != KdenliveSettings::trackheight()) {
1248         KdenliveSettings::setTrackheight(m_configTimeline.kcfg_trackheight->value());
1249         emit resetView();
1250     }
1251 
1252     if (m_configTimeline.kcfg_autoscroll->isChecked() != KdenliveSettings::autoscroll()) {
1253         KdenliveSettings::setAutoscroll(m_configTimeline.kcfg_autoscroll->isChecked());
1254         emit pCore->autoScrollChanged();
1255     }
1256 
1257     if (m_configTimeline.kcfg_pauseonseek->isChecked() != KdenliveSettings::pauseonseek()) {
1258         KdenliveSettings::setPauseonseek(m_configTimeline.kcfg_pauseonseek->isChecked());
1259     }
1260 
1261     if (m_configTimeline.kcfg_seekonaddeffect->isChecked() != KdenliveSettings::seekonaddeffect()) {
1262         KdenliveSettings::setSeekonaddeffect(m_configTimeline.kcfg_seekonaddeffect->isChecked());
1263     }
1264 
1265     if (m_configTimeline.kcfg_scrollvertically->isChecked() != KdenliveSettings::scrollvertically()) {
1266         KdenliveSettings::setScrollvertically(m_configTimeline.kcfg_scrollvertically->isChecked());
1267         emit pCore->window()->getCurrentTimeline()->controller()->scrollVerticallyChanged();
1268     }
1269 
1270     // Mimes
1271     if (m_configEnv.kcfg_addedExtensions->text() != KdenliveSettings::addedExtensions()) {
1272         // Update list
1273         KdenliveSettings::setAddedExtensions(m_configEnv.kcfg_addedExtensions->text());
1274         QStringList mimes = ClipCreationDialog::getExtensions();
1275         std::sort(mimes.begin(), mimes.end());
1276         m_configEnv.supportedmimes->setPlainText(mimes.join(QLatin1Char(' ')));
1277     }
1278 
1279     // proxy/transcode max concurrent jobs
1280     if (m_configEnv.kcfg_proxythreads->value() != KdenliveSettings::proxythreads()) {
1281         KdenliveSettings::setProxythreads(m_configEnv.kcfg_proxythreads->value());
1282         pCore->taskManager.updateConcurrency();
1283     }
1284 
1285     KConfigDialog::settingsChangedSlot();
1286     // KConfigDialog::updateSettings();
1287     if (resetConsumer) {
1288         emit doResetConsumer(fullReset);
1289     }
1290     if (restart) {
1291         emit restartKdenlive();
1292     }
1293     emit checkTabPosition();
1294 
1295     // remembering Config dialog size
1296     KSharedConfigPtr config = KSharedConfig::openConfig();
1297     KConfigGroup settingsGroup(config, "settings");
1298     settingsGroup.writeEntry("dialogSize", QVariant(size()));
1299 }
1300 
1301 void KdenliveSettingsDialog::slotCheckAlsaDriver()
1302 {
1303     QString value = m_configSdl.kcfg_audio_driver->currentData().toString();
1304     m_configSdl.kcfg_audio_device->setEnabled(value == QLatin1String("alsa"));
1305 }
1306 
1307 void KdenliveSettingsDialog::slotCheckAudioBackend()
1308 {
1309     bool isSdl = m_configSdl.kcfg_audio_backend->currentData().toString().startsWith(QLatin1String("sdl"));
1310     m_configSdl.label_audio_driver->setEnabled(isSdl);
1311     m_configSdl.kcfg_audio_driver->setEnabled(isSdl);
1312     m_configSdl.label_audio_device->setEnabled(isSdl);
1313     m_configSdl.kcfg_audio_device->setEnabled(isSdl);
1314 }
1315 
1316 void KdenliveSettingsDialog::loadTranscodeProfiles()
1317 {
1318     KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("kdenlivetranscodingrc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
1319     KConfigGroup transConfig(config, "Transcoding");
1320     // read the entries
1321     m_configTranscode.profiles_list->blockSignals(true);
1322     m_configTranscode.profiles_list->clear();
1323     QMap<QString, QString> profiles = transConfig.entryMap();
1324     QMapIterator<QString, QString> i(profiles);
1325     while (i.hasNext()) {
1326         i.next();
1327         auto *item = new QListWidgetItem(i.key());
1328         QString profilestr = i.value();
1329         if (profilestr.contains(QLatin1Char(';'))) {
1330             item->setToolTip(profilestr.section(QLatin1Char(';'), 1, 1));
1331         }
1332         item->setData(Qt::UserRole, profilestr);
1333         m_configTranscode.profiles_list->addItem(item);
1334         // item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
1335     }
1336     m_configTranscode.profiles_list->blockSignals(false);
1337     m_configTranscode.profiles_list->setCurrentRow(0);
1338 }
1339 
1340 void KdenliveSettingsDialog::saveTranscodeProfiles()
1341 {
1342     QString transcodeFile = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/kdenlivetranscodingrc");
1343     KSharedConfigPtr config = KSharedConfig::openConfig(transcodeFile);
1344     KConfigGroup transConfig(config, "Transcoding");
1345     // read the entries
1346     transConfig.deleteGroup();
1347     int max = m_configTranscode.profiles_list->count();
1348     for (int i = 0; i < max; ++i) {
1349         QListWidgetItem *item = m_configTranscode.profiles_list->item(i);
1350         transConfig.writeEntry(item->text(), item->data(Qt::UserRole).toString());
1351     }
1352     config->sync();
1353 }
1354 
1355 void KdenliveSettingsDialog::slotAddTranscode()
1356 {
1357     bool ok;
1358     QString presetName =
1359         QInputDialog::getText(this, i18nc("@title:window", "Enter Preset Name"), i18n("Enter the name of this preset:"), QLineEdit::Normal, QString(), &ok);
1360     if (!ok) return;
1361     if (!m_configTranscode.profiles_list->findItems(presetName, Qt::MatchExactly).isEmpty()) {
1362         KMessageBox::error(this, i18n("A profile with that name already exists"));
1363         return;
1364     }
1365     QListWidgetItem *item = new QListWidgetItem(presetName);
1366     QString profilestr = m_configTranscode.profile_parameters->toPlainText();
1367     profilestr.append(" %1." + m_configTranscode.profile_extension->text());
1368     profilestr.append(';');
1369     if (!m_configTranscode.profile_description->text().isEmpty()) {
1370         profilestr.append(m_configTranscode.profile_description->text());
1371     }
1372     if (m_configTranscode.profile_audioonly->isChecked()) {
1373         profilestr.append(";audio");
1374     }
1375     item->setData(Qt::UserRole, profilestr);
1376     m_configTranscode.profiles_list->addItem(item);
1377     m_configTranscode.profiles_list->setCurrentItem(item);
1378     slotDialogModified();
1379 }
1380 
1381 void KdenliveSettingsDialog::slotUpdateTranscodingProfile()
1382 {
1383     QListWidgetItem *item = m_configTranscode.profiles_list->currentItem();
1384     if (!item) {
1385         return;
1386     }
1387     m_configTranscode.button_update->setEnabled(false);
1388     QString profilestr = m_configTranscode.profile_parameters->toPlainText();
1389     profilestr.append(" %1." + m_configTranscode.profile_extension->text());
1390     profilestr.append(';');
1391     if (!m_configTranscode.profile_description->text().isEmpty()) {
1392         profilestr.append(m_configTranscode.profile_description->text());
1393     }
1394     if (m_configTranscode.profile_audioonly->isChecked()) {
1395         profilestr.append(QStringLiteral(";audio"));
1396     }
1397     item->setData(Qt::UserRole, profilestr);
1398     slotDialogModified();
1399 }
1400 
1401 void KdenliveSettingsDialog::slotDeleteTranscode()
1402 {
1403     QListWidgetItem *item = m_configTranscode.profiles_list->currentItem();
1404     if (item == nullptr) {
1405         return;
1406     }
1407     delete item;
1408     slotDialogModified();
1409 }
1410 
1411 void KdenliveSettingsDialog::slotEnableTranscodeUpdate()
1412 {
1413     if (!m_configTranscode.profile_box->isEnabled()) {
1414         return;
1415     }
1416     bool allow = true;
1417     if (m_configTranscode.profile_extension->text().isEmpty()) {
1418         allow = false;
1419     }
1420     m_configTranscode.button_update->setEnabled(allow);
1421 }
1422 
1423 void KdenliveSettingsDialog::slotSetTranscodeProfile()
1424 {
1425     m_configTranscode.profile_box->setEnabled(false);
1426     m_configTranscode.button_update->setEnabled(false);
1427     m_configTranscode.profile_description->clear();
1428     m_configTranscode.profile_extension->clear();
1429     m_configTranscode.profile_parameters->clear();
1430     m_configTranscode.profile_audioonly->setChecked(false);
1431     QListWidgetItem *item = m_configTranscode.profiles_list->currentItem();
1432     if (!item) {
1433         return;
1434     }
1435     QString profilestr = item->data(Qt::UserRole).toString();
1436     if (profilestr.contains(QLatin1Char(';'))) {
1437         m_configTranscode.profile_description->setText(profilestr.section(QLatin1Char(';'), 1, 1));
1438         if (profilestr.section(QLatin1Char(';'), 2, 2) == QLatin1String("audio")) {
1439             m_configTranscode.profile_audioonly->setChecked(true);
1440         }
1441         profilestr = profilestr.section(QLatin1Char(';'), 0, 0).simplified();
1442     }
1443     m_configTranscode.profile_extension->setText(profilestr.section(QLatin1Char('.'), -1));
1444     m_configTranscode.profile_parameters->setPlainText(profilestr.section(QLatin1Char(' '), 0, -2));
1445     m_configTranscode.profile_box->setEnabled(true);
1446 }
1447 
1448 void KdenliveSettingsDialog::slotShuttleModified()
1449 {
1450 #ifdef USE_JOGSHUTTLE
1451     QStringList actions;
1452     actions << QStringLiteral("monitor_pause"); // the Job rest position action.
1453     for (QComboBox *button : qAsConst(m_shuttle_buttons)) {
1454         actions << m_mappable_actions[button->currentText()];
1455     }
1456     QString maps = JogShuttleConfig::actionMap(actions);
1457     m_shuttleModified = KdenliveSettings::shuttlebuttons() != maps;
1458 #endif
1459     KConfigDialog::updateButtons();
1460 }
1461 
1462 void KdenliveSettingsDialog::slotDialogModified()
1463 {
1464     m_modified = true;
1465     KConfigDialog::updateButtons();
1466 }
1467 
1468 // virtual
1469 bool KdenliveSettingsDialog::hasChanged()
1470 {
1471     if (m_modified || m_shuttleModified) {
1472         return true;
1473     }
1474     if (KdenliveSettings::audiocapturechannels() != m_configCapture.audiocapturechannels->currentData().toInt()) {
1475         return true;
1476     }
1477     if (KdenliveSettings::audiocapturesamplerate() != m_configCapture.audiocapturesamplerate->currentData().toInt()) {
1478         return true;
1479     }
1480     return KConfigDialog::hasChanged();
1481 }
1482 
1483 void KdenliveSettingsDialog::slotUpdatev4lDevice()
1484 {
1485     QString device = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex()).toString();
1486     if (!device.isEmpty()) {
1487         m_configCapture.kcfg_video4vdevice->setText(device);
1488     }
1489     QString info = m_configCapture.kcfg_detectedv4ldevices->itemData(m_configCapture.kcfg_detectedv4ldevices->currentIndex(), Qt::UserRole + 1).toString();
1490 
1491     m_configCapture.kcfg_v4l_format->blockSignals(true);
1492     m_configCapture.kcfg_v4l_format->clear();
1493 
1494     QString vl4ProfilePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/video4linux");
1495     if (QFile::exists(vl4ProfilePath)) {
1496         m_configCapture.kcfg_v4l_format->addItem(i18n("Current settings"));
1497     }
1498 
1499     QStringList pixelformats = info.split('>', Qt::SkipEmptyParts);
1500     QString itemSize;
1501     QStringList itemRates;
1502     for (int i = 0; i < pixelformats.count(); ++i) {
1503         QString format = pixelformats.at(i).section(QLatin1Char(':'), 0, 0);
1504         QStringList sizes = pixelformats.at(i).split(':', Qt::SkipEmptyParts);
1505         sizes.takeFirst();
1506         for (int j = 0; j < sizes.count(); ++j) {
1507             itemSize = sizes.at(j).section(QLatin1Char('='), 0, 0);
1508             itemRates = sizes.at(j).section(QLatin1Char('='), 1, 1).split(QLatin1Char(','), Qt::SkipEmptyParts);
1509             for (int k = 0; k < itemRates.count(); ++k) {
1510                 m_configCapture.kcfg_v4l_format->addItem(
1511                     QLatin1Char('[') + format + QStringLiteral("] ") + itemSize + QStringLiteral(" (") + itemRates.at(k) + QLatin1Char(')'),
1512                     QStringList() << format << itemSize.section('x', 0, 0) << itemSize.section('x', 1, 1) << itemRates.at(k).section(QLatin1Char('/'), 0, 0)
1513                                   << itemRates.at(k).section(QLatin1Char('/'), 1, 1));
1514             }
1515         }
1516     }
1517     m_configCapture.kcfg_v4l_format->blockSignals(false);
1518     slotUpdatev4lCaptureProfile();
1519 }
1520 
1521 void KdenliveSettingsDialog::slotUpdatev4lCaptureProfile()
1522 {
1523     QStringList info = m_configCapture.kcfg_v4l_format->itemData(m_configCapture.kcfg_v4l_format->currentIndex(), Qt::UserRole).toStringList();
1524     if (info.isEmpty()) {
1525         // No auto info, display the current ones
1526         loadCurrentV4lProfileInfo();
1527         return;
1528     }
1529     m_configCapture.p_size->setText(info.at(1) + QLatin1Char('x') + info.at(2));
1530     m_configCapture.p_fps->setText(info.at(3) + QLatin1Char('/') + info.at(4));
1531     m_configCapture.p_aspect->setText(QStringLiteral("1/1"));
1532     m_configCapture.p_display->setText(info.at(1) + QLatin1Char('/') + info.at(2));
1533     m_configCapture.p_colorspace->setText(ProfileRepository::getColorspaceDescription(601));
1534     m_configCapture.p_progressive->setText(i18n("Progressive"));
1535 
1536     QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/"));
1537     if (!dir.exists() || !dir.exists(QStringLiteral("video4linux"))) {
1538         saveCurrentV4lProfile();
1539     }
1540 }
1541 
1542 void KdenliveSettingsDialog::loadCurrentV4lProfileInfo()
1543 {
1544     QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/"));
1545     if (!dir.exists()) {
1546         dir.mkpath(QStringLiteral("."));
1547     }
1548     if (!ProfileRepository::get()->profileExists(dir.absoluteFilePath(QStringLiteral("video4linux")))) {
1549         // No default formats found, build one
1550         std::unique_ptr<ProfileParam> prof(new ProfileParam(pCore->getCurrentProfile().get()));
1551         prof->m_width = 320;
1552         prof->m_height = 200;
1553         prof->m_frame_rate_num = 15;
1554         prof->m_frame_rate_den = 1;
1555         prof->m_display_aspect_num = 4;
1556         prof->m_display_aspect_den = 3;
1557         prof->m_sample_aspect_num = 1;
1558         prof->m_sample_aspect_den = 1;
1559         prof->m_progressive = true;
1560         prof->m_colorspace = 601;
1561         ProfileRepository::get()->saveProfile(prof.get(), dir.absoluteFilePath(QStringLiteral("video4linux")));
1562     }
1563     auto &prof = ProfileRepository::get()->getProfile(dir.absoluteFilePath(QStringLiteral("video4linux")));
1564     m_configCapture.p_size->setText(QString::number(prof->width()) + QLatin1Char('x') + QString::number(prof->height()));
1565     m_configCapture.p_fps->setText(QString::number(prof->frame_rate_num()) + QLatin1Char('/') + QString::number(prof->frame_rate_den()));
1566     m_configCapture.p_aspect->setText(QString::number(prof->sample_aspect_num()) + QLatin1Char('/') + QString::number(prof->sample_aspect_den()));
1567     m_configCapture.p_display->setText(QString::number(prof->display_aspect_num()) + QLatin1Char('/') + QString::number(prof->display_aspect_den()));
1568     m_configCapture.p_colorspace->setText(ProfileRepository::getColorspaceDescription(prof->colorspace()));
1569     if (prof->progressive()) {
1570         m_configCapture.p_progressive->setText(i18n("Progressive"));
1571     }
1572 }
1573 
1574 void KdenliveSettingsDialog::saveCurrentV4lProfile()
1575 {
1576     std::unique_ptr<ProfileParam> profile(new ProfileParam(pCore->getCurrentProfile().get()));
1577     profile->m_description = QStringLiteral("Video4Linux capture");
1578     profile->m_colorspace = ProfileRepository::getColorspaceFromDescription(m_configCapture.p_colorspace->text());
1579     profile->m_width = m_configCapture.p_size->text().section('x', 0, 0).toInt();
1580     profile->m_height = m_configCapture.p_size->text().section('x', 1, 1).toInt();
1581     profile->m_sample_aspect_num = m_configCapture.p_aspect->text().section(QLatin1Char('/'), 0, 0).toInt();
1582     profile->m_sample_aspect_den = m_configCapture.p_aspect->text().section(QLatin1Char('/'), 1, 1).toInt();
1583     profile->m_display_aspect_num = m_configCapture.p_display->text().section(QLatin1Char('/'), 0, 0).toInt();
1584     profile->m_display_aspect_den = m_configCapture.p_display->text().section(QLatin1Char('/'), 1, 1).toInt();
1585     profile->m_frame_rate_num = m_configCapture.p_fps->text().section(QLatin1Char('/'), 0, 0).toInt();
1586     profile->m_frame_rate_den = m_configCapture.p_fps->text().section(QLatin1Char('/'), 1, 1).toInt();
1587     profile->m_progressive = m_configCapture.p_progressive->text() == i18n("Progressive");
1588     QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/"));
1589     if (!dir.exists()) {
1590         dir.mkpath(QStringLiteral("."));
1591     }
1592     ProfileRepository::get()->saveProfile(profile.get(), dir.absoluteFilePath(QStringLiteral("video4linux")));
1593 }
1594 
1595 void KdenliveSettingsDialog::loadExternalProxyProfiles()
1596 {
1597     // load proxy profiles
1598     KConfig conf(QStringLiteral("externalproxies.rc"), KConfig::CascadeConfig, QStandardPaths::AppDataLocation);
1599     KConfigGroup group(&conf, "proxy");
1600     QMap<QString, QString> values = group.entryMap();
1601     QMapIterator<QString, QString> k(values);
1602     QString currentItem = KdenliveSettings::externalProxyProfile();
1603     m_configProxy.kcfg_external_proxy_profile->blockSignals(true);
1604     m_configProxy.kcfg_external_proxy_profile->clear();
1605     while (k.hasNext()) {
1606         k.next();
1607         if (!k.key().isEmpty()) {
1608             if (k.value().contains(QLatin1Char(';'))) {
1609                 m_configProxy.kcfg_external_proxy_profile->addItem(k.key(), k.value());
1610             }
1611         }
1612     }
1613     if (!currentItem.isEmpty()) {
1614         m_configProxy.kcfg_external_proxy_profile->setCurrentIndex(m_configProxy.kcfg_external_proxy_profile->findText(currentItem));
1615     }
1616     m_configProxy.kcfg_external_proxy_profile->blockSignals(false);
1617 }
1618 
1619 void KdenliveSettingsDialog::slotEditVideo4LinuxProfile()
1620 {
1621     QString vl4ProfilePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/profiles/video4linux");
1622     QPointer<ProfilesDialog> w = new ProfilesDialog(vl4ProfilePath, true);
1623     if (w->exec() == QDialog::Accepted) {
1624         // save and update profile
1625         loadCurrentV4lProfileInfo();
1626     }
1627     delete w;
1628 }
1629 
1630 void KdenliveSettingsDialog::slotReloadBlackMagic()
1631 {
1632     getBlackMagicDeviceList(m_configCapture.kcfg_decklink_capturedevice, true);
1633     if (!getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device, true)) {
1634         // No blackmagic card found
1635         m_configSdl.kcfg_external_display->setEnabled(false);
1636     }
1637     m_configSdl.kcfg_external_display->setEnabled(KdenliveSettings::decklink_device_found());
1638 }
1639 
1640 void KdenliveSettingsDialog::checkProfile()
1641 {
1642     m_pw->loadProfile(KdenliveSettings::default_profile().isEmpty() ? pCore->getCurrentProfile()->path() : KdenliveSettings::default_profile());
1643 }
1644 
1645 void KdenliveSettingsDialog::slotReloadShuttleDevices()
1646 {
1647 #ifdef USE_JOGSHUTTLE
1648     QString devDirStr = QStringLiteral("/dev/input/by-id");
1649     QDir devDir(devDirStr);
1650     if (!devDir.exists()) {
1651         devDirStr = QStringLiteral("/dev/input");
1652     }
1653 
1654     QStringList devNamesList;
1655     QStringList devPathList;
1656     m_configShuttle.shuttledevicelist->clear();
1657 
1658     DeviceMap devMap = JogShuttle::enumerateDevices(devDirStr);
1659     DeviceMapIter iter = devMap.begin();
1660     while (iter != devMap.end()) {
1661         m_configShuttle.shuttledevicelist->addItem(iter.key(), iter.value());
1662         devNamesList << iter.key();
1663         devPathList << iter.value();
1664         ++iter;
1665     }
1666     KdenliveSettings::setShuttledevicenames(devNamesList);
1667     KdenliveSettings::setShuttledevicepaths(devPathList);
1668     QTimer::singleShot(200, this, [&]() { slotUpdateShuttleDevice(); });
1669 #endif // USE_JOGSHUTTLE
1670 }
1671 
1672 void KdenliveSettingsDialog::initSpeechPage()
1673 {
1674     m_stt = new SpeechToText();
1675     PythonDependencyMessage *msg = new PythonDependencyMessage(this, m_stt);
1676     m_configSpeech.message_layout->addWidget(msg);
1677 
1678     connect(m_stt, &SpeechToText::dependenciesAvailable, this, [&]() {
1679         if (m_speechListWidget->count() == 0) {
1680             doShowSpeechMessage(i18n("Please add a speech model."), KMessageWidget::Information);
1681         }
1682     });
1683     connect(m_stt, &SpeechToText::dependenciesMissing, this, [&](const QStringList &) { m_configSpeech.speech_info->animatedHide(); });
1684 
1685     m_voskAction = new QAction(i18n("Install missing dependencies"), this);
1686     m_speechListWidget = new SpeechList(this);
1687     connect(m_speechListWidget, &SpeechList::getDictionary, this, &KdenliveSettingsDialog::getDictionary);
1688     QVBoxLayout *l = new QVBoxLayout(m_configSpeech.list_frame);
1689     l->setContentsMargins(0, 0, 0, 0);
1690     l->addWidget(m_speechListWidget);
1691     m_configSpeech.speech_info->setWordWrap(true);
1692     connect(m_configSpeech.check_vosk, &QPushButton::clicked, this, [this]() {
1693         m_configSpeech.check_vosk->setEnabled(false);
1694         m_stt->checkDependencies();
1695         if (m_stt->missingDependencies().isEmpty()) {
1696             m_stt->checkVersions();
1697         }
1698         m_configSpeech.check_vosk->setEnabled(true);
1699     });
1700 
1701     m_stt->checkDependencies();
1702     connect(m_configSpeech.custom_vosk_folder, &QCheckBox::stateChanged, this, [this](int state) {
1703         m_configSpeech.vosk_folder->setEnabled(state != Qt::Unchecked);
1704         if (state == Qt::Unchecked) {
1705             // Clear custom folder
1706             m_configSpeech.vosk_folder->clear();
1707             KdenliveSettings::setVosk_folder_path(QString());
1708             slotParseVoskDictionaries();
1709         }
1710     });
1711     connect(m_configSpeech.vosk_folder, &KUrlRequester::urlSelected, this, [this](const QUrl &url) {
1712         KdenliveSettings::setVosk_folder_path(url.toLocalFile());
1713         slotParseVoskDictionaries();
1714     });
1715     m_configSpeech.models_url->setText(
1716         i18n("Download speech models from: <a href=\"https://alphacephei.com/vosk/models\">https://alphacephei.com/vosk/models</a>"));
1717     connect(m_configSpeech.models_url, &QLabel::linkActivated, this, [&](const QString &contents) {
1718         qDebug() << "=== LINK CLICKED: " << contents;
1719         auto *job = new KIO::OpenUrlJob(QUrl(contents));
1720 #if KIO_VERSION >= QT_VERSION_CHECK(5, 98, 0)
1721         job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1722 #else
1723         job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1724 #endif
1725         // methods like setRunExecutables, setSuggestedFilename, setEnableExternalBrowser, setFollowRedirections
1726         // exist in both classes
1727         job->start();
1728     });
1729     connect(m_configSpeech.button_add, &QToolButton::clicked, this, [this]() { this->getDictionary(); });
1730     connect(m_configSpeech.button_delete, &QToolButton::clicked, this, &KdenliveSettingsDialog::removeDictionary);
1731     connect(this, &KdenliveSettingsDialog::parseDictionaries, this, &KdenliveSettingsDialog::slotParseVoskDictionaries);
1732     slotParseVoskDictionaries();
1733 }
1734 
1735 void KdenliveSettingsDialog::doShowSpeechMessage(const QString &message, int messageType)
1736 {
1737     m_configSpeech.speech_info->setMessageType(static_cast<KMessageWidget::MessageType>(messageType));
1738     m_configSpeech.speech_info->setText(message);
1739     m_configSpeech.speech_info->animatedShow();
1740 }
1741 
1742 void KdenliveSettingsDialog::getDictionary(const QUrl &sourceUrl)
1743 {
1744     QUrl url = KUrlRequesterDialog::getUrl(sourceUrl, this, i18n("Enter url for the new dictionary"));
1745     if (url.isEmpty()) {
1746         return;
1747     }
1748     if (!url.isLocalFile()) {
1749         KIO::FileCopyJob *copyjob = KIO::file_copy(url, QUrl::fromLocalFile(QDir::temp().absoluteFilePath(url.fileName())));
1750         doShowSpeechMessage(i18n("Downloading model…"), KMessageWidget::Information);
1751         connect(copyjob, &KIO::FileCopyJob::result, this, &KdenliveSettingsDialog::downloadModelFinished);
1752     } else {
1753         processArchive(url.toLocalFile());
1754     }
1755 }
1756 
1757 void KdenliveSettingsDialog::removeDictionary()
1758 {
1759     if (!KdenliveSettings::vosk_folder_path().isEmpty()) {
1760         doShowSpeechMessage(i18n("We do not allow deleting custom folder models, please do it manually."), KMessageWidget::Warning);
1761         return;
1762     }
1763     QString modelDirectory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
1764     QDir dir(modelDirectory);
1765     if (!dir.cd(QStringLiteral("speechmodels"))) {
1766         doShowSpeechMessage(i18n("Cannot access dictionary folder."), KMessageWidget::Warning);
1767         return;
1768     }
1769 
1770     if (!m_speechListWidget->currentItem()) {
1771         return;
1772     }
1773     QString currentModel = m_speechListWidget->currentItem()->text();
1774     if (!currentModel.isEmpty() && dir.cd(currentModel)) {
1775         if (KMessageBox::questionTwoActions(this, i18n("Delete folder:\n%1", dir.absolutePath()), {}, KStandardGuiItem::del(), KStandardGuiItem::cancel()) ==
1776             KMessageBox::PrimaryAction) {
1777             // Make sure we don't accidentally delete a folder that is not ours
1778             if (dir.absolutePath().contains(QLatin1String("speechmodels"))) {
1779                 dir.removeRecursively();
1780                 slotParseVoskDictionaries();
1781             }
1782         }
1783     }
1784 }
1785 
1786 void KdenliveSettingsDialog::downloadModelFinished(KJob *job)
1787 {
1788     qDebug() << "=== DOWNLOAD FINISHED!!";
1789     if (job->error() == 0 || job->error() == 112) {
1790         qDebug() << "=== NO ERROR ON DWNLD!!";
1791         auto *jb = static_cast<KIO::FileCopyJob *>(job);
1792         if (jb) {
1793             qDebug() << "=== JOB FOUND!!";
1794             QString archiveFile = jb->destUrl().toLocalFile();
1795             processArchive(archiveFile);
1796         } else {
1797             qDebug() << "=== JOB NOT FOUND!!";
1798             m_configSpeech.speech_info->setMessageType(KMessageWidget::Warning);
1799             m_configSpeech.speech_info->setText(i18n("Download error"));
1800         }
1801     } else {
1802         qDebug() << "=== GOT JOB ERROR: " << job->error();
1803         m_configSpeech.speech_info->setMessageType(KMessageWidget::Warning);
1804         m_configSpeech.speech_info->setText(i18n("Download error %1", job->errorString()));
1805     }
1806 }
1807 
1808 void KdenliveSettingsDialog::processArchive(const QString &archiveFile)
1809 {
1810     QMimeDatabase db;
1811     QMimeType type = db.mimeTypeForFile(archiveFile);
1812     std::unique_ptr<KArchive> archive;
1813     if (type.inherits(QStringLiteral("application/zip"))) {
1814         archive = std::make_unique<KZip>(archiveFile);
1815     } else {
1816         archive = std::make_unique<KTar>(archiveFile);
1817     }
1818     QString modelDirectory = KdenliveSettings::vosk_folder_path();
1819     QDir dir;
1820     if (modelDirectory.isEmpty()) {
1821         modelDirectory = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
1822         dir = QDir(modelDirectory);
1823         dir.mkdir(QStringLiteral("speechmodels"));
1824         if (!dir.cd(QStringLiteral("speechmodels"))) {
1825             doShowSpeechMessage(i18n("Cannot access dictionary folder."), KMessageWidget::Warning);
1826             return;
1827         }
1828     } else {
1829         dir = QDir(modelDirectory);
1830     }
1831     if (archive->open(QIODevice::ReadOnly)) {
1832         doShowSpeechMessage(i18n("Extracting archive…"), KMessageWidget::Information);
1833         const KArchiveDirectory *archiveDir = archive->directory();
1834         if (!archiveDir->copyTo(dir.absolutePath())) {
1835             qDebug() << "=== Error extracting archive!!";
1836         } else {
1837             QFile::remove(archiveFile);
1838             emit parseDictionaries();
1839             doShowSpeechMessage(i18n("New dictionary installed."), KMessageWidget::Positive);
1840         }
1841     } else {
1842         // Test if it is a folder
1843         QDir testDir(archiveFile);
1844         if (testDir.exists()) {
1845         }
1846         qDebug() << "=== CANNOT OPEN ARCHIVE!!";
1847     }
1848 }
1849 
1850 void KdenliveSettingsDialog::slotParseVoskDictionaries()
1851 {
1852     m_speechListWidget->clear();
1853     QStringList final = m_stt->parseVoskDictionaries();
1854     m_speechListWidget->addItems(final);
1855     if (!KdenliveSettings::vosk_folder_path().isEmpty()) {
1856         m_configSpeech.custom_vosk_folder->setChecked(true);
1857         m_configSpeech.vosk_folder->setUrl(QUrl::fromLocalFile(KdenliveSettings::vosk_folder_path()));
1858     }
1859     if (!final.isEmpty() && m_stt->missingDependencies().isEmpty()) {
1860         m_configSpeech.speech_info->animatedHide();
1861     } else if (final.isEmpty()) {
1862         doShowSpeechMessage(i18n("Please add a speech model."), KMessageWidget::Information);
1863     }
1864 }