From 2ac279d12953ad840ade1c08d0eff5c2f4adb0b9 Mon Sep 17 00:00:00 2001 From: willemferguson Date: Sun, 8 Dec 2019 11:30:16 +0200 Subject: Pereferences UI: add media tab Remove the preference settings dealing with thumbnails (currently under General preferences and Profile preferences) and put them in a newly-created Media preference tab. Signed-off-by: willemferguson Signed-off-by: Dirk Hohndel --- desktop-widgets/preferences/preferences_media.cpp | 89 +++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 desktop-widgets/preferences/preferences_media.cpp (limited to 'desktop-widgets/preferences/preferences_media.cpp') diff --git a/desktop-widgets/preferences/preferences_media.cpp b/desktop-widgets/preferences/preferences_media.cpp new file mode 100644 index 000000000..47a6285dd --- /dev/null +++ b/desktop-widgets/preferences/preferences_media.cpp @@ -0,0 +1,89 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "preferences_media.h" +#include "ui_preferences_media.h" +#include "core/settings/qPrefMedia.h" +#include "core/qthelper.h" + +#include +#include +#include +#include +#include + +#include "qt-models/models.h" + +PreferencesMedia::PreferencesMedia() : AbstractPreferencesWidget(tr("Media"), QIcon(":preferences-media-icon"), 8) +{ + ui = new Ui::PreferencesMedia(); + ui->setupUi(this); + +} + +PreferencesMedia::~PreferencesMedia() +{ + delete ui; +} + +void PreferencesMedia::checkFfmpegExecutable() +{ + QString s = ui->ffmpegExecutable->text().trimmed(); + + // If the user didn't provide a string they probably didn't intend to run ffmeg, + // so let's not give an error message. + if (s.isEmpty()) + return; + + // Try to execute ffmpeg. But wait at most 2 sec for startup and execution + // so that the UI doesn't hang unnecessarily. + QProcess ffmpeg; + ffmpeg.start(s); + if (!ffmpeg.waitForStarted(2000) || !ffmpeg.waitForFinished(3000)) + QMessageBox::warning(this, tr("Warning"), tr("Couldn't execute ffmpeg at given location. Thumbnailing will not work.")); +} + +void PreferencesMedia::on_ffmpegFile_clicked() +{ + QFileInfo fi(system_default_filename()); + QString ffmpegFileName = QFileDialog::getOpenFileName(this, tr("Select ffmpeg executable")); + + if (!ffmpegFileName.isEmpty()) { + ui->ffmpegExecutable->setText(ffmpegFileName); + checkFfmpegExecutable(); + } +} + +void PreferencesMedia::on_ffmpegExecutable_editingFinished() +{ + checkFfmpegExecutable(); +} + +void PreferencesMedia::on_extractVideoThumbnails_toggled(bool toggled) +{ + ui->videoThumbnailPosition->setEnabled(toggled); + ui->ffmpegExecutable->setEnabled(toggled); + ui->ffmpegFile->setEnabled(toggled); +} + +void PreferencesMedia::refreshSettings() +{ + ui->videoThumbnailPosition->setEnabled(qPrefMedia::extract_video_thumbnails()); + ui->ffmpegExecutable->setEnabled(qPrefMedia::extract_video_thumbnails()); + ui->ffmpegFile->setEnabled(qPrefMedia::extract_video_thumbnails()); + + ui->extractVideoThumbnails->setChecked(qPrefMedia::extract_video_thumbnails()); + ui->videoThumbnailPosition->setValue(qPrefMedia::extract_video_thumbnails_position()); + ui->ffmpegExecutable->setText(qPrefMedia::ffmpeg_executable()); + + ui->auto_recalculate_thumbnails->setChecked(prefs.auto_recalculate_thumbnails); + +} + +void PreferencesMedia::syncSettings() +{ + auto media = qPrefMedia::instance(); + media->set_extract_video_thumbnails(ui->extractVideoThumbnails->isChecked()); + media->set_extract_video_thumbnails_position(ui->videoThumbnailPosition->value()); + media->set_ffmpeg_executable(ui->ffmpegExecutable->text()); + qPrefMedia::set_auto_recalculate_thumbnails(ui->auto_recalculate_thumbnails->isChecked()); + +} -- cgit v1.2.3-70-g09d2