diff options
author | willemferguson <willemferguson@zoology.up.ac.za> | 2019-12-08 11:30:16 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-12-25 02:57:42 +0900 |
commit | 2ac279d12953ad840ade1c08d0eff5c2f4adb0b9 (patch) | |
tree | 9f2d70f50cb910803e260fa9d3bdad2687d820ad /desktop-widgets/preferences/preferences_media.cpp | |
parent | 3e853e37a5b0b9509fb92b1ddb3031f117578fb9 (diff) | |
download | subsurface-2ac279d12953ad840ade1c08d0eff5c2f4adb0b9.tar.gz |
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 <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'desktop-widgets/preferences/preferences_media.cpp')
-rw-r--r-- | desktop-widgets/preferences/preferences_media.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
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 <QApplication> +#include <QMessageBox> +#include <QSortFilterProxyModel> +#include <QFileDialog> +#include <QProcess> + +#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()); + +} |