kdenlivesettingsdialog.cpp 74.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
 *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

20
#include "kdenlivesettingsdialog.h"
Nicolas Carion's avatar
Nicolas Carion committed
21
#include "clipcreationdialog.h"
Nicolas Carion's avatar
linting  
Nicolas Carion committed
22
#include "core.h"
23
#include "dialogs/profilesdialog.h"
Nicolas Carion's avatar
Nicolas Carion committed
24
#include "encodingprofilesdialog.h"
25
#include "kdenlivesettings.h"
26 27 28
#include "mainwindow.h"
#include "timeline2/view/timelinewidget.h"
#include "timeline2/view/timelinecontroller.h"
Nicolas Carion's avatar
linting  
Nicolas Carion committed
29
#include "profiles/profilemodel.hpp"
30
#include "profiles/profilerepository.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
31 32
#include "profilesdialog.h"
#include "project/dialogs/profilewidget.h"
33
#include "wizard.h"
34

Vincent Pinon's avatar
Vincent Pinon committed
35 36 37
#ifdef USE_V4L
#include "capture/v4lcapture.h"
#endif
38

Nicolas Carion's avatar
Nicolas Carion committed
39
#include "kdenlive_debug.h"
40
#include "klocalizedstring.h"
41
#include <KIO/DesktopExecParser>
42
#include <KLineEdit>
Nicolas Carion's avatar
Nicolas Carion committed
43
#include <KMessageBox>
44
#include <KOpenWithDialog>
Nicolas Carion's avatar
Nicolas Carion committed
45
#include <KService>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
46
#include <QAction>
47
#include <QDir>
Akhil K Gangadharan's avatar
Akhil K Gangadharan committed
48 49
#include <QGuiApplication>
#include <QScreen>
50 51 52
#include <QSize>
#include <QThread>
#include <QTimer>
Nicolas Carion's avatar
Nicolas Carion committed
53 54
#include <cstdio>
#include <cstdlib>
Nicolas Carion's avatar
Nicolas Carion committed
55
#include <fcntl.h>
56
#include <unistd.h>
57

58
#ifdef USE_JOGSHUTTLE
59 60
#include "jogshuttle/jogaction.h"
#include "jogshuttle/jogshuttleconfig.h"
61
#include <QStandardPaths>
Nicolas Carion's avatar
Nicolas Carion committed
62
#include <linux/input.h>
63
#endif
64

Nicolas Carion's avatar
Nicolas Carion committed
65
KdenliveSettingsDialog::KdenliveSettingsDialog(QMap<QString, QString> mappable_actions, bool gpuAllowed, QWidget *parent)
66 67 68
    : KConfigDialog(parent, QStringLiteral("settings"), KdenliveSettings::self())
    , m_modified(false)
    , m_shuttleModified(false)
Nicolas Carion's avatar
Nicolas Carion committed
69
    , m_mappable_actions(std::move(mappable_actions))
70
{
71
    KdenliveSettings::setV4l_format(0);
72 73
    QWidget *p1 = new QWidget;
    m_configMisc.setupUi(p1);
74
    m_page1 = addPage(p1, i18n("Misc"));
75
    m_page1->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
76

77
    m_configMisc.kcfg_use_exiftool->setEnabled(!QStandardPaths::findExecutable(QStringLiteral("exiftool")).isEmpty());
78

79 80
    QWidget *p8 = new QWidget;
    m_configProject.setupUi(p8);
81
    m_page8 = addPage(p8, i18n("Project Defaults"));
Nicolas Carion's avatar
Nicolas Carion committed
82
    auto *vbox = new QVBoxLayout;
83 84 85
    m_pw = new ProfileWidget(this);
    vbox->addWidget(m_pw);
    m_configProject.profile_box->setLayout(vbox);
86
    m_configProject.profile_box->setTitle(i18n("Select the default profile (preset)"));
87
    // Select profile
88
    m_pw->loadProfile(KdenliveSettings::default_profile().isEmpty() ? pCore->getCurrentProfile()->path() : KdenliveSettings::default_profile());
89
    connect(m_pw, &ProfileWidget::profileChanged, this, &KdenliveSettingsDialog::slotDialogModified);
90
    m_page8->setIcon(QIcon::fromTheme(QStringLiteral("project-defaults")));
91 92
    m_configProject.projecturl->setMode(KFile::Directory);
    m_configProject.projecturl->setUrl(QUrl::fromLocalFile(KdenliveSettings::defaultprojectfolder()));
93 94 95 96 97 98 99 100 101 102
    connect(m_configProject.kcfg_videotracks, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this]() {
        if (m_configProject.kcfg_videotracks->value() + m_configProject.kcfg_audiotracks->value() <= 0) {
            m_configProject.kcfg_videotracks->setValue(1);
        }
    });
    connect(m_configProject.kcfg_audiotracks, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this] () {
        if (m_configProject.kcfg_videotracks->value() + m_configProject.kcfg_audiotracks->value() <= 0) {
            m_configProject.kcfg_audiotracks->setValue(1);
        }
    });
103 104 105

    QWidget *p9 = new QWidget;
    m_configProxy.setupUi(p9);
106
    KPageWidgetItem *page9 = addPage(p9, i18n("Proxy Clips"));
107 108 109 110 111 112
    page9->setIcon(QIcon::fromTheme(QStringLiteral("zoom-out")));
    connect(m_configProxy.kcfg_generateproxy, &QAbstractButton::toggled, m_configProxy.kcfg_proxyminsize, &QWidget::setEnabled);
    m_configProxy.kcfg_proxyminsize->setEnabled(KdenliveSettings::generateproxy());
    connect(m_configProxy.kcfg_generateimageproxy, &QAbstractButton::toggled, m_configProxy.kcfg_proxyimageminsize, &QWidget::setEnabled);
    m_configProxy.kcfg_proxyimageminsize->setEnabled(KdenliveSettings::generateimageproxy());
    loadExternalProxyProfiles();
113

114
    QWidget *p3 = new QWidget;
115
    m_configTimeline.setupUi(p3);
116
    m_page3 = addPage(p3, i18n("Timeline"));
117
    m_page3->setIcon(QIcon::fromTheme(QStringLiteral("video-display")));
118 119 120 121

    QWidget *p2 = new QWidget;
    m_configEnv.setupUi(p2);
    m_configEnv.mltpathurl->setMode(KFile::Directory);
122 123 124 125 126
    m_configEnv.mltpathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_mltpath"));
    m_configEnv.rendererpathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_rendererpath"));
    m_configEnv.ffmpegurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffmpegpath"));
    m_configEnv.ffplayurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffplaypath"));
    m_configEnv.ffprobeurl->lineEdit()->setObjectName(QStringLiteral("kcfg_ffprobepath"));
127
    m_configEnv.tmppathurl->setMode(KFile::Directory);
128
    m_configEnv.tmppathurl->lineEdit()->setObjectName(QStringLiteral("kcfg_currenttmpfolder"));
129
    m_configEnv.capturefolderurl->setMode(KFile::Directory);
130
    m_configEnv.capturefolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_capturefolder"));
131
    m_configEnv.capturefolderurl->setEnabled(!KdenliveSettings::capturetoprojectfolder());
Laurent Montel's avatar
Laurent Montel committed
132
    connect(m_configEnv.kcfg_capturetoprojectfolder, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEnableCaptureFolder);
133 134 135 136
    // Library folder
    m_configEnv.libraryfolderurl->setMode(KFile::Directory);
    m_configEnv.libraryfolderurl->lineEdit()->setObjectName(QStringLiteral("kcfg_libraryfolder"));
    m_configEnv.libraryfolderurl->setEnabled(!KdenliveSettings::librarytodefaultfolder());
137
    m_configEnv.kcfg_librarytodefaultfolder->setToolTip(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/library"));
Laurent Montel's avatar
Laurent Montel committed
138
    connect(m_configEnv.kcfg_librarytodefaultfolder, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEnableLibraryFolder);
139

140 141
    // Mime types
    QStringList mimes = ClipCreationDialog::getExtensions();
142
    std::sort(mimes.begin(), mimes.end());
Laurent Montel's avatar
Laurent Montel committed
143
    m_configEnv.supportedmimes->setPlainText(mimes.join(QLatin1Char(' ')));
144

145
    m_page2 = addPage(p2, i18n("Environment"));
146
    m_page2->setIcon(QIcon::fromTheme(QStringLiteral("application-x-executable-script")));
147

148 149 150 151 152
    QWidget *p10 = new QWidget;
    m_configColors.setupUi(p10);
    m_page10 = addPage(p10, i18n("Colors"));
    m_page10->setIcon(QIcon::fromTheme(QStringLiteral("color-management")));
    
153 154
    QWidget *p4 = new QWidget;
    m_configCapture.setupUi(p4);
155
    // Remove ffmpeg tab, unused
156
    m_configCapture.tabWidget->removeTab(0);
157 158 159
    m_configCapture.label->setVisible(false);
    m_configCapture.kcfg_defaultcapture->setVisible(false);
    //m_configCapture.tabWidget->removeTab(2);
160
#ifdef USE_V4L
161

162
    // Video 4 Linux device detection
Laurent Montel's avatar
Laurent Montel committed
163
    for (int i = 0; i < 10; ++i) {
Laurent Montel's avatar
Laurent Montel committed
164
        QString path = QStringLiteral("/dev/video") + QString::number(i);
165
        if (QFile::exists(path)) {
166
            QStringList deviceInfo = V4lCaptureHandler::getDeviceName(path);
167 168 169 170
            if (!deviceInfo.isEmpty()) {
                m_configCapture.kcfg_detectedv4ldevices->addItem(deviceInfo.at(0), path);
                m_configCapture.kcfg_detectedv4ldevices->setItemData(m_configCapture.kcfg_detectedv4ldevices->count() - 1, deviceInfo.at(1), Qt::UserRole + 1);
            }
171 172
        }
    }
173
    connect(m_configCapture.kcfg_detectedv4ldevices, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
174
            &KdenliveSettingsDialog::slotUpdatev4lDevice);
175
    connect(m_configCapture.kcfg_v4l_format, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
176
            &KdenliveSettingsDialog::slotUpdatev4lCaptureProfile);
Laurent Montel's avatar
Laurent Montel committed
177
    connect(m_configCapture.config_v4l, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditVideo4LinuxProfile);
178 179

    slotUpdatev4lDevice();
180
#endif
181

182
    m_page4 = addPage(p4, i18n("Capture"));
183
    m_page4->setIcon(QIcon::fromTheme(QStringLiteral("media-record")));
184
    m_configCapture.tabWidget->setCurrentIndex(KdenliveSettings::defaultcapture());
Alberto Villa's avatar
Alberto Villa committed
185
#ifdef Q_WS_MAC
186 187
    m_configCapture.tabWidget->setEnabled(false);
    m_configCapture.kcfg_defaultcapture->setEnabled(false);
Alberto Villa's avatar
Alberto Villa committed
188
    m_configCapture.label->setText(i18n("Capture is not yet available on Mac OS X."));
189
#endif
190

191 192
    QWidget *p5 = new QWidget;
    m_configShuttle.setupUi(p5);
193
#ifdef USE_JOGSHUTTLE
194
    m_configShuttle.toolBtnReload->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
Laurent Montel's avatar
Laurent Montel committed
195
    connect(m_configShuttle.kcfg_enableshuttle, &QCheckBox::stateChanged, this, &KdenliveSettingsDialog::slotCheckShuttle);
196
    connect(m_configShuttle.shuttledevicelist, SIGNAL(activated(int)), this, SLOT(slotUpdateShuttleDevice(int)));
Laurent Montel's avatar
Laurent Montel committed
197
    connect(m_configShuttle.toolBtnReload, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotReloadShuttleDevices);
198

Nicolas Carion's avatar
Nicolas Carion committed
199
    slotCheckShuttle(static_cast<int>(KdenliveSettings::enableshuttle()));
200
    m_configShuttle.shuttledisabled->hide();
201 202

    // Store the button pointers into an array for easier handling them in the other functions.
203
    // TODO: impl enumerator or live with cut and paste :-)))
204 205
    setupJogshuttleBtns(KdenliveSettings::shuttledevice());
#if 0
206 207 208 209 210
    m_shuttle_buttons.push_back(m_configShuttle.shuttle1);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle2);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle3);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle4);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle5);
211 212 213 214 215
    m_shuttle_buttons.push_back(m_configShuttle.shuttle6);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle7);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle8);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle9);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle10);
216 217 218 219 220
    m_shuttle_buttons.push_back(m_configShuttle.shuttle11);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle12);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle13);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle14);
    m_shuttle_buttons.push_back(m_configShuttle.shuttle15);
221
#endif
222

Nicolas Carion's avatar
Nicolas Carion committed
223
#else  /* ! USE_JOGSHUTTLE */
224 225 226
    m_configShuttle.kcfg_enableshuttle->hide();
    m_configShuttle.kcfg_enableshuttle->setDisabled(true);
#endif /* USE_JOGSHUTTLE */
227
    m_page5 = addPage(p5, i18n("JogShuttle"));
228
    m_page5->setIcon(QIcon::fromTheme(QStringLiteral("dialog-input-devices")));
229

230 231
    QWidget *p6 = new QWidget;
    m_configSdl.setupUi(p6);
232
    m_configSdl.reload_blackmagic->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh")));
Laurent Montel's avatar
Laurent Montel committed
233
    connect(m_configSdl.reload_blackmagic, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotReloadBlackMagic);
234

Nicolas Carion's avatar
Nicolas Carion committed
235
    // m_configSdl.kcfg_openglmonitors->setHidden(true);
236

237
    m_page6 = addPage(p6, i18n("Playback"));
238
    m_page6->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
239

240 241
    QWidget *p7 = new QWidget;
    m_configTranscode.setupUi(p7);
242
    m_page7 = addPage(p7, i18n("Transcode"));
243
    m_page7->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
244

Laurent Montel's avatar
Laurent Montel committed
245 246 247 248
    connect(m_configTranscode.button_add, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotAddTranscode);
    connect(m_configTranscode.button_delete, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotDeleteTranscode);
    connect(m_configTranscode.profiles_list, &QListWidget::itemChanged, this, &KdenliveSettingsDialog::slotDialogModified);
    connect(m_configTranscode.profiles_list, &QListWidget::currentRowChanged, this, &KdenliveSettingsDialog::slotSetTranscodeProfile);
249

Laurent Montel's avatar
Laurent Montel committed
250 251 252 253 254
    connect(m_configTranscode.profile_name, &QLineEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
    connect(m_configTranscode.profile_description, &QLineEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
    connect(m_configTranscode.profile_extension, &QLineEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
    connect(m_configTranscode.profile_parameters, &QPlainTextEdit::textChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
    connect(m_configTranscode.profile_audioonly, &QCheckBox::stateChanged, this, &KdenliveSettingsDialog::slotEnableTranscodeUpdate);
255

Laurent Montel's avatar
Laurent Montel committed
256
    connect(m_configTranscode.button_update, &QAbstractButton::pressed, this, &KdenliveSettingsDialog::slotUpdateTranscodingProfile);
257

258
    m_configTranscode.profile_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
Alberto Villa's avatar
Alberto Villa committed
259

Laurent Montel's avatar
Laurent Montel committed
260 261
    connect(m_configEnv.kp_image, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditImageApplication);
    connect(m_configEnv.kp_audio, &QAbstractButton::clicked, this, &KdenliveSettingsDialog::slotEditAudioApplication);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
262

263
    loadEncodingProfiles();
264

265
    connect(m_configSdl.kcfg_audio_driver, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
266
            &KdenliveSettingsDialog::slotCheckAlsaDriver);
267
    connect(m_configSdl.kcfg_audio_backend, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
268
            &KdenliveSettingsDialog::slotCheckAudioBackend);
269
    initDevices();
270
    connect(m_configCapture.kcfg_grab_capture_type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
271
            &KdenliveSettingsDialog::slotUpdateGrabRegionStatus);
272

273
    slotUpdateGrabRegionStatus();
274
    loadTranscodeProfiles();
275

276
    // decklink profile
277
    QAction *act = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure profiles"), this);
278
    act->setData(4);
Laurent Montel's avatar
Laurent Montel committed
279
    connect(act, &QAction::triggered, this, &KdenliveSettingsDialog::slotManageEncodingProfile);
280
    m_configCapture.decklink_manageprofile->setDefaultAction(act);
281
    m_configCapture.decklink_showprofileinfo->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
282 283 284
    m_configCapture.decklink_parameters->setVisible(false);
    m_configCapture.decklink_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
    m_configCapture.decklink_parameters->setPlainText(KdenliveSettings::decklink_parameters());
285
    connect(m_configCapture.kcfg_decklink_profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
286
            &KdenliveSettingsDialog::slotUpdateDecklinkProfile);
Laurent Montel's avatar
Laurent Montel committed
287
    connect(m_configCapture.decklink_showprofileinfo, &QAbstractButton::clicked, m_configCapture.decklink_parameters, &QWidget::setVisible);
288

289
    // ffmpeg profile
290
    m_configCapture.v4l_showprofileinfo->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
291 292 293
    m_configCapture.v4l_parameters->setVisible(false);
    m_configCapture.v4l_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
    m_configCapture.v4l_parameters->setPlainText(KdenliveSettings::v4l_parameters());
294

295
    act = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure profiles"), this);
296
    act->setData(2);
Laurent Montel's avatar
Laurent Montel committed
297
    connect(act, &QAction::triggered, this, &KdenliveSettingsDialog::slotManageEncodingProfile);
298
    m_configCapture.v4l_manageprofile->setDefaultAction(act);
299
    connect(m_configCapture.kcfg_v4l_profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
300
            &KdenliveSettingsDialog::slotUpdateV4lProfile);
Laurent Montel's avatar
Laurent Montel committed
301
    connect(m_configCapture.v4l_showprofileinfo, &QAbstractButton::clicked, m_configCapture.v4l_parameters, &QWidget::setVisible);
302

303
    // screen grab profile
304
    m_configCapture.grab_showprofileinfo->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
305 306 307
    m_configCapture.grab_parameters->setVisible(false);
    m_configCapture.grab_parameters->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 4);
    m_configCapture.grab_parameters->setPlainText(KdenliveSettings::grab_parameters());
308
    act = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure profiles"), this);
309
    act->setData(3);
Laurent Montel's avatar
Laurent Montel committed
310
    connect(act, &QAction::triggered, this, &KdenliveSettingsDialog::slotManageEncodingProfile);
311
    m_configCapture.grab_manageprofile->setDefaultAction(act);
312
    connect(m_configCapture.kcfg_grab_profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
313
            &KdenliveSettingsDialog::slotUpdateGrabProfile);
Laurent Montel's avatar
Laurent Montel committed
314
    connect(m_configCapture.grab_showprofileinfo, &QAbstractButton::clicked, m_configCapture.grab_parameters, &QWidget::setVisible);
Alberto Villa's avatar
Alberto Villa committed
315

316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    // audio capture channels
    m_configCapture.audiocapturechannels->clear();
    m_configCapture.audiocapturechannels->addItem(i18n("Mono (1 channel)"), 1);
    m_configCapture.audiocapturechannels->addItem(i18n("Stereo (2 channels)"), 2);

    int channelsIndex = m_configCapture.audiocapturechannels->findData(KdenliveSettings::audiocapturechannels());
    m_configCapture.audiocapturechannels->setCurrentIndex(qMax(channelsIndex, 0));
    connect(m_configCapture.audiocapturechannels, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
            &KdenliveSettingsDialog::slotUpdateAudioCaptureChannels);

    // audio capture sample rate
    m_configCapture.audiocapturesamplerate->clear();
    m_configCapture.audiocapturesamplerate->addItem(i18n("44100 Hz"), 44100);
    m_configCapture.audiocapturesamplerate->addItem(i18n("48000 Hz"), 48000);

    int sampleRateIndex = m_configCapture.audiocapturesamplerate->findData(KdenliveSettings::audiocapturesamplerate());
    m_configCapture.audiocapturesamplerate->setCurrentIndex(qMax(sampleRateIndex, 0));
    connect(m_configCapture.audiocapturesamplerate, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
            &KdenliveSettingsDialog::slotUpdateAudioCaptureSampleRate);

    m_configCapture.labelNoAudioDevices->setVisible(false);

338
    // Timeline preview
339
    act = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure profiles"), this);
340
    act->setData(1);
Laurent Montel's avatar
Laurent Montel committed
341
    connect(act, &QAction::triggered, this, &KdenliveSettingsDialog::slotManageEncodingProfile);
342
    m_configProject.preview_manageprofile->setDefaultAction(act);
343
    connect(m_configProject.kcfg_preview_profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
344
            &KdenliveSettingsDialog::slotUpdatePreviewProfile);
Laurent Montel's avatar
Laurent Montel committed
345
    connect(m_configProject.preview_showprofileinfo, &QAbstractButton::clicked, m_configProject.previewparams, &QWidget::setVisible);
346 347 348
    m_configProject.previewparams->setVisible(false);
    m_configProject.previewparams->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 3);
    m_configProject.previewparams->setPlainText(KdenliveSettings::previewparams());
349
    m_configProject.preview_showprofileinfo->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
350
    m_configProject.preview_showprofileinfo->setToolTip(i18n("Show default timeline preview parameters"));
351
    m_configProject.preview_manageprofile->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
352 353
    m_configProject.preview_manageprofile->setToolTip(i18n("Manage timeline preview profiles"));
    m_configProject.kcfg_preview_profile->setToolTip(i18n("Select default timeline preview profile"));
354

355
    // proxy profile stuff
356 357 358 359 360 361 362 363
    m_configProxy.proxy_showprofileinfo->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
    m_configProxy.proxy_showprofileinfo->setToolTip(i18n("Show default profile parameters"));
    m_configProxy.proxy_manageprofile->setIcon(QIcon::fromTheme(QStringLiteral("configure")));
    m_configProxy.proxy_manageprofile->setToolTip(i18n("Manage proxy profiles"));
    m_configProxy.kcfg_proxy_profile->setToolTip(i18n("Select default proxy profile"));
    m_configProxy.proxyparams->setVisible(false);
    m_configProxy.proxyparams->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 3);
    m_configProxy.proxyparams->setPlainText(KdenliveSettings::proxyparams());
364

365
    act = new QAction(QIcon::fromTheme(QStringLiteral("configure")), i18n("Configure profiles"), this);
366
    act->setData(0);
Laurent Montel's avatar
Laurent Montel committed
367
    connect(act, &QAction::triggered, this, &KdenliveSettingsDialog::slotManageEncodingProfile);
368
    m_configProxy.proxy_manageprofile->setDefaultAction(act);
369

370
    connect(m_configProxy.proxy_showprofileinfo, &QAbstractButton::clicked, m_configProxy.proxyparams, &QWidget::setVisible);
371
    connect(m_configProxy.kcfg_proxy_profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
Nicolas Carion's avatar
Nicolas Carion committed
372
            &KdenliveSettingsDialog::slotUpdateProxyProfile);
373 374 375

    slotUpdateProxyProfile(-1);
    slotUpdateV4lProfile(-1);
376
    slotUpdateGrabProfile(-1);
377
    slotUpdateDecklinkProfile(-1);
378

379 380
    // enable GPU accel only if Movit is found
    m_configSdl.kcfg_gpu_accel->setEnabled(gpuAllowed);
381
    m_configSdl.kcfg_gpu_accel->setToolTip(i18n("GPU processing needs MLT compiled with Movit and Rtaudio modules"));
Alberto Villa's avatar
Alberto Villa committed
382

383 384
    getBlackMagicDeviceList(m_configCapture.kcfg_decklink_capturedevice);
    if (!getBlackMagicOutputDeviceList(m_configSdl.kcfg_blackmagic_output_device)) {
385
        // No blackmagic card found
386
        m_configSdl.kcfg_external_display->setEnabled(false);
387
    }
388 389
    
    initAudioRecDevice();
Akhil K Gangadharan's avatar
Akhil K Gangadharan committed
390

391
    // Config dialog size
Akhil K Gangadharan's avatar
Akhil K Gangadharan committed
392 393 394 395
    KSharedConfigPtr config = KSharedConfig::openConfig();
    KConfigGroup settingsGroup(config, "settings");
    QSize optimalSize;

396 397
    if (!settingsGroup.exists() || !settingsGroup.hasKey("dialogSize")) {
        const QSize screenSize = (QGuiApplication::primaryScreen()->availableSize() * 0.9);
Akhil K Gangadharan's avatar
Akhil K Gangadharan committed
398 399
        const QSize targetSize = QSize(1024, 700);
        optimalSize = targetSize.boundedTo(screenSize);
400 401
    } else {
        optimalSize = settingsGroup.readEntry("dialogSize", QVariant(size())).toSize();
Akhil K Gangadharan's avatar
Akhil K Gangadharan committed
402 403
    }
    resize(optimalSize);
404 405
}

406
// static
407
bool KdenliveSettingsDialog::getBlackMagicDeviceList(QComboBox *devicelist, bool force)
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
{
    if (!force && !KdenliveSettings::decklink_device_found()) {
        return false;
    }
    Mlt::Profile profile;
    Mlt::Producer bm(profile, "decklink");
    int found_devices = 0;
    if (bm.is_valid()) {
        bm.set("list_devices", 1);
        found_devices = bm.get_int("devices");
    } else {
        KdenliveSettings::setDecklink_device_found(false);
    }
    if (found_devices <= 0) {
        devicelist->setEnabled(false);
        return false;
    }
    KdenliveSettings::setDecklink_device_found(true);
    for (int i = 0; i < found_devices; ++i) {
        char *tmp = qstrdup(QStringLiteral("device.%1").arg(i).toUtf8().constData());
        devicelist->addItem(bm.get(tmp));
        delete[] tmp;
    }
    return true;
}

434 435 436 437
// static
bool KdenliveSettingsDialog::initAudioRecDevice()
{
    QStringList audioDevices = pCore->getAudioCaptureDevices();
438 439 440 441

    //show a hint to the user to know what to check for in case the device list are empty (common issue)
    m_configCapture.labelNoAudioDevices->setVisible(audioDevices.empty());

442 443 444 445 446 447 448 449 450 451 452 453 454 455
    m_configCapture.kcfg_defaultaudiocapture->addItems(audioDevices);
    connect(m_configCapture.kcfg_defaultaudiocapture, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [&]() {
        QString currentDevice = m_configCapture.kcfg_defaultaudiocapture->currentText();
        KdenliveSettings::setDefaultaudiocapture(currentDevice);
    });
    QString selectedDevice = KdenliveSettings::defaultaudiocapture();
    int selectedIndex = m_configCapture.kcfg_defaultaudiocapture->findText(selectedDevice);
    if (!selectedDevice.isEmpty() && selectedIndex > -1) {
        m_configCapture.kcfg_defaultaudiocapture->setCurrentIndex(selectedIndex);
    }
    return true;
}

bool KdenliveSettingsDialog::getBlackMagicOutputDeviceList(QComboBox *devicelist, bool force)
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
{
    if (!force && !KdenliveSettings::decklink_device_found()) {
        return false;
    }
    Mlt::Profile profile;
    Mlt::Consumer bm(profile, "decklink");
    int found_devices = 0;
    if (bm.is_valid()) {
        bm.set("list_devices", 1);
        found_devices = bm.get_int("devices");
    } else {
        KdenliveSettings::setDecklink_device_found(false);
    }
    if (found_devices <= 0) {
        devicelist->setEnabled(false);
        return false;
    }
    KdenliveSettings::setDecklink_device_found(true);
    for (int i = 0; i < found_devices; ++i) {
        char *tmp = qstrdup(QStringLiteral("device.%1").arg(i).toUtf8().constData());
        devicelist->addItem(bm.get(tmp));
        delete[] tmp;
    }
    devicelist->addItem(QStringLiteral("test"));
    return true;
}

Laurent Montel's avatar
Laurent Montel committed
483
void KdenliveSettingsDialog::setupJogshuttleBtns(const QString &device)
484
{
485
    QList<QComboBox *> list;
486
    QList<QLabel *> list1;
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503

    list << m_configShuttle.shuttle1;
    list << m_configShuttle.shuttle2;
    list << m_configShuttle.shuttle3;
    list << m_configShuttle.shuttle4;
    list << m_configShuttle.shuttle5;
    list << m_configShuttle.shuttle6;
    list << m_configShuttle.shuttle7;
    list << m_configShuttle.shuttle8;
    list << m_configShuttle.shuttle9;
    list << m_configShuttle.shuttle10;
    list << m_configShuttle.shuttle11;
    list << m_configShuttle.shuttle12;
    list << m_configShuttle.shuttle13;
    list << m_configShuttle.shuttle14;
    list << m_configShuttle.shuttle15;

Nicolas Carion's avatar
Nicolas Carion committed
504 505 506 507 508 509 510 511
    list1 << m_configShuttle.label_2;  // #1
    list1 << m_configShuttle.label_4;  // #2
    list1 << m_configShuttle.label_3;  // #3
    list1 << m_configShuttle.label_7;  // #4
    list1 << m_configShuttle.label_5;  // #5
    list1 << m_configShuttle.label_6;  // #6
    list1 << m_configShuttle.label_8;  // #7
    list1 << m_configShuttle.label_9;  // #8
512 513 514 515 516 517 518 519
    list1 << m_configShuttle.label_10; // #9
    list1 << m_configShuttle.label_11; // #10
    list1 << m_configShuttle.label_12; // #11
    list1 << m_configShuttle.label_13; // #12
    list1 << m_configShuttle.label_14; // #13
    list1 << m_configShuttle.label_15; // #14
    list1 << m_configShuttle.label_16; // #15

520
    for (int i = 0; i < list.count(); ++i) {
521 522 523
        list[i]->hide();
        list1[i]->hide();
    }
524
#ifdef USE_JOGSHUTTLE
525 526 527
    if (!m_configShuttle.kcfg_enableshuttle->isChecked()) {
        return;
    }
528 529
    int keysCount = JogShuttle::keysCount(device);

530
    for (int i = 0; i < keysCount; ++i) {
531 532 533 534 535 536 537 538 539
        m_shuttle_buttons.push_back(list[i]);
        list[i]->show();
        list1[i]->show();
    }

    // populate the buttons with the current configuration. The items are sorted
    // according to the user-selected language, so they do not appear in random order.
    QMap<QString, QString> mappable_actions(m_mappable_actions);
    QList<QString> action_names = mappable_actions.keys();
540
    QList<QString>::Iterator iter = action_names.begin();
Nicolas Carion's avatar
Nicolas Carion committed
541
    // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
542
    while (iter != action_names.end()) {
Nicolas Carion's avatar
Nicolas Carion committed
543
        // qCDebug(KDENLIVE_LOG) << *iter;
544 545 546
        ++iter;
    }

Nicolas Carion's avatar
Nicolas Carion committed
547
    // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
548

549
    std::sort(action_names.begin(), action_names.end());
550 551
    iter = action_names.begin();
    while (iter != action_names.end()) {
Nicolas Carion's avatar
Nicolas Carion committed
552
        // qCDebug(KDENLIVE_LOG) << *iter;
553 554
        ++iter;
    }
Nicolas Carion's avatar
Nicolas Carion committed
555
    // qCDebug(KDENLIVE_LOG) << "::::::::::::::::";
556 557 558 559 560

    // Here we need to compute the action_id -> index-in-action_names. We iterate over the
    // action_names, as the sorting may depend on the user-language.
    QStringList actions_map = JogShuttleConfig::actionMap(KdenliveSettings::shuttlebuttons());
    QMap<QString, int> action_pos;
Vincent Pinon's avatar
Vincent Pinon committed
561
    for (const QString &action_id : qAsConst(actions_map)) {
562 563 564 565 566 567 568 569 570 571
        // This loop find out at what index is the string that would map to the action_id.
        for (int i = 0; i < action_names.size(); ++i) {
            if (mappable_actions[action_names.at(i)] == action_id) {
                action_pos[action_id] = i;
                break;
            }
        }
    }

    int i = 0;
Vincent Pinon's avatar
Vincent Pinon committed
572
    for (QComboBox *button : qAsConst(m_shuttle_buttons)) {
573 574 575
        button->addItems(action_names);
        connect(button, SIGNAL(activated(int)), this, SLOT(slotShuttleModified()));
        ++i;
576
        if (i < actions_map.size()) {
577
            button->setCurrentIndex(action_pos[actions_map[i]]);
578
        }
579
    }
Vincent Pinon's avatar
Vincent Pinon committed
580 581
#else
    Q_UNUSED(device)
582
#endif
583 584
}

Nicolas Carion's avatar
Nicolas Carion committed
585
KdenliveSettingsDialog::~KdenliveSettingsDialog() = default;
586

587
void KdenliveSettingsDialog::slotUpdateGrabRegionStatus()
588
{
589
    m_configCapture.region_group->setHidden(m_configCapture.kcfg_grab_capture_type->currentIndex() != 1);
590
}
591

592 593 594 595 596
void KdenliveSettingsDialog::slotEnableCaptureFolder()
{
    m_configEnv.capturefolderurl->setEnabled(!m_configEnv.kcfg_capturetoprojectfolder->isChecked());
}

597 598 599 600 601
void KdenliveSettingsDialog::slotEnableLibraryFolder()
{
    m_configEnv.libraryfolderurl->setEnabled(!m_configEnv.kcfg_librarytodefaultfolder->isChecked());
}

602 603
void KdenliveSettingsDialog::initDevices()
{
604 605
    // Fill audio drivers
    m_configSdl.kcfg_audio_driver->addItem(i18n("Automatic"), QString());
606 607 608 609 610 611
#if defined(Q_OS_WIN)
    //TODO: i18n
    m_configSdl.kcfg_audio_driver->addItem("DirectSound", "directsound");
    m_configSdl.kcfg_audio_driver->addItem("WinMM", "winmm");
    m_configSdl.kcfg_audio_driver->addItem("Wasapi", "wasapi");
#elif !defined(Q_WS_MAC)
612
    m_configSdl.kcfg_audio_driver->addItem(i18n("ALSA"), "alsa");
613 614 615
    m_configSdl.kcfg_audio_driver->addItem(i18n("PulseAudio"), "pulseaudio");
    m_configSdl.kcfg_audio_driver->addItem(i18n("OSS"), "dsp");
    //m_configSdl.kcfg_audio_driver->addItem(i18n("OSS with DMA access"), "dma");
616 617
    m_configSdl.kcfg_audio_driver->addItem(i18n("Esound daemon"), "esd");
    m_configSdl.kcfg_audio_driver->addItem(i18n("ARTS daemon"), "artsc");
618
#endif
619

620
    if (!KdenliveSettings::audiodrivername().isEmpty())
621
        for (int i = 1; i < m_configSdl.kcfg_audio_driver->count(); ++i) {
622 623
            if (m_configSdl.kcfg_audio_driver->itemData(i).toString() == KdenliveSettings::audiodrivername()) {
                m_configSdl.kcfg_audio_driver->setCurrentIndex(i);
Nicolas Carion's avatar
Nicolas Carion committed
624
                KdenliveSettings::setAudio_driver((uint)i);
625 626
            }
        }
627

628
    // Fill the list of audio playback / recording devices
629
    m_configSdl.kcfg_audio_device->addItem(i18n("Default"), QString());
630
    m_configCapture.kcfg_v4l_alsadevice->addItem(i18n("Default"), "default");
631
    if (!QStandardPaths::findExecutable(QStringLiteral("aplay")).isEmpty()) {
632
        m_readProcess.setOutputChannelMode(KProcess::OnlyStdoutChannel);
633
        m_readProcess.setProgram(QStringLiteral("aplay"), QStringList() << QStringLiteral("-l"));
Laurent Montel's avatar
Laurent Montel committed
634
        connect(&m_readProcess, &KProcess::readyReadStandardOutput, this, &KdenliveSettingsDialog::slotReadAudioDevices);
635 636 637
        m_readProcess.execute(5000);
    } else {
        // If aplay is not installed on the system, parse the /proc/asound/pcm file
638
        QFile file(QStringLiteral("/proc/asound/pcm"));
639
        if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
640
            QTextStream stream(&file);
641
            QString line = stream.readLine();
642
            QString deviceId;
643
            while (!line.isNull()) {
644
                if (line.contains(QStringLiteral("playback"))) {
Laurent Montel's avatar
Laurent Montel committed
645
                    deviceId = line.section(QLatin1Char(':'), 0, 0);
Nicolas Carion's avatar
Nicolas Carion committed
646 647 648
                    m_configSdl.kcfg_audio_device->addItem(line.section(QLatin1Char(':'), 1, 1), QStringLiteral("plughw:%1,%2")
                                                                                                     .arg(deviceId.section(QLatin1Char('-'), 0, 0).toInt())
                                                                                                     .arg(deviceId.section(QLatin1Char('-'), 1, 1).toInt()));
649
                }
650
                if (line.contains(QStringLiteral("capture"))) {
Laurent Montel's avatar
Laurent Montel committed
651
                    deviceId = line.section(QLatin1Char(':'), 0, 0);
Nicolas Carion's avatar
Nicolas Carion committed
652 653 654
                    m_configCapture.kcfg_v4l_alsadevice->addItem(
                        line.section(QLatin1Char(':'), 1, 1).simplified(),
                        QStringLiteral("hw:%1,%2").arg(deviceId.section(QLatin1Char('-'), 0, 0).toInt()).arg(deviceId.section(QLatin1Char('-'), 1, 1).toInt()));
655
                }
656
                line = stream.readLine();
657
            }
658
            file.close();
659 660 661
        } else {
            qCDebug(KDENLIVE_LOG) << " / / / /CANNOT READ PCM";
        }
662
    }
663

664 665
    // Add pulseaudio capture option
    m_configCapture.kcfg_v4l_alsadevice->addItem(i18n("PulseAudio"), "pulse");
666

667 668
    if (!KdenliveSettings::audiodevicename().isEmpty()) {
        // Select correct alsa device
669 670 671
        int ix = m_configSdl.kcfg_audio_device->findData(KdenliveSettings::audiodevicename());
        m_configSdl.kcfg_audio_device->setCurrentIndex(ix);
        KdenliveSettings::setAudio_device(ix);
672
    }
Alberto Villa's avatar
Alberto Villa committed
673

674 675 676 677 678 679 680
    if (!KdenliveSettings::v4l_alsadevicename().isEmpty()) {
        // Select correct alsa device
        int ix = m_configCapture.kcfg_v4l_alsadevice->findData(KdenliveSettings::v4l_alsadevicename());
        m_configCapture.kcfg_v4l_alsadevice->setCurrentIndex(ix);
        KdenliveSettings::setV4l_alsadevice(ix);
    }

681
    m_configSdl.kcfg_audio_backend->addItem(i18n("SDL"), KdenliveSettings::sdlAudioBackend());
682 683 684 685 686 687 688
    m_configSdl.kcfg_audio_backend->addItem(i18n("RtAudio"), "rtaudio");

    if (!KdenliveSettings::audiobackend().isEmpty()) {
        int ix = m_configSdl.kcfg_audio_backend->findData(KdenliveSettings::audiobackend());
        m_configSdl.kcfg_audio_backend->setCurrentIndex(ix);
        KdenliveSettings::setAudio_backend(ix);
    }
689
    m_configSdl.group_sdl->setEnabled(KdenliveSettings::audiobackend().startsWith(QLatin1String("sdl")));
690

691
    loadCurrentV4lProfileInfo();
692 693
}

694 695
void KdenliveSettingsDialog::slotReadAudioDevices()
{
696
    QString result = QString(m_readProcess.readAllStandardOutput());
Nicolas Carion's avatar
Nicolas Carion committed
697 698
    // qCDebug(KDENLIVE_LOG) << "// / / / / / READING APLAY: ";
    // qCDebug(KDENLIVE_LOG) << result;
Laurent Montel's avatar
Laurent Montel committed
699
    const QStringList lines = result.split(QLatin1Char('\n'));
700
    for (const QString &devicestr : lines) {
Laurent Montel's avatar
Laurent Montel committed
701
        ////qCDebug(KDENLIVE_LOG) << "// READING LINE: " << data;
702 703 704
        if (!devicestr.startsWith(QLatin1Char(' ')) && devicestr.count(QLatin1Char(':')) > 1) {
            QString card = devicestr.section(QLatin1Char(':'), 0, 0).section(QLatin1Char(' '), -1);
            QString device = devicestr.section(QLatin1Char(':'), 1, 1).section(QLatin1Char(' '), -1);
705
            m_configSdl.kcfg_audio_device->addItem(devicestr.section(QLatin1Char(':'), -1).simplified(), QStringLiteral("plughw:%1,%2").arg(card).arg(device));
Nicolas Carion's avatar
Nicolas Carion committed
706 707
            m_configCapture.kcfg_v4l_alsadevice->addItem(devicestr.section(QLatin1Char(':'), -1).simplified(),
                                                         QStringLiteral("hw:%1,%2").arg(card).arg(device));
708
        }
709 710 711
    }
}

712 713
void KdenliveSettingsDialog::showPage(int page, int option)
{
714 715
    switch (page) {
    case 1:
716
        setCurrentPage(m_page1);
717 718
        break;
    case 2:
719
        setCurrentPage(m_page2);
720 721
        break;
    case 3:
722
        setCurrentPage(m_page3);
723 724
        break;
    case 4:
Ray Lehtiniemi's avatar