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/CMakeLists.txt | 3 + .../preferences/preferences_defaults.cpp | 50 ------ desktop-widgets/preferences/preferences_defaults.h | 4 - .../preferences/preferences_defaults.ui | 73 -------- desktop-widgets/preferences/preferences_graph.cpp | 2 - desktop-widgets/preferences/preferences_graph.ui | 7 - desktop-widgets/preferences/preferences_media.cpp | 89 ++++++++++ desktop-widgets/preferences/preferences_media.h | 30 ++++ desktop-widgets/preferences/preferences_media.ui | 192 +++++++++++++++++++++ desktop-widgets/preferences/preferencesdialog.cpp | 3 + 10 files changed, 317 insertions(+), 136 deletions(-) create mode 100644 desktop-widgets/preferences/preferences_media.cpp create mode 100644 desktop-widgets/preferences/preferences_media.h create mode 100644 desktop-widgets/preferences/preferences_media.ui (limited to 'desktop-widgets') diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index af6071934..c0b0de7ab 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -12,6 +12,7 @@ set(SUBSURFACE_PREFERENCES_UI preferences_units.ui preferences_georeference.ui preferences_language.ui + preferences_media.ui preferences_equipment.ui ) @@ -32,6 +33,8 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS preferences_graph.h preferences_language.cpp preferences_language.h + preferences_media.cpp + preferences_media.h preferences_network.cpp preferences_network.h preferences_cloud.cpp diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index e0df807b0..549475a23 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -47,46 +47,6 @@ void PreferencesDefaults::on_localDefaultFile_toggled(bool toggle) ui->chooseFile->setEnabled(toggle); } -void PreferencesDefaults::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 PreferencesDefaults::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 PreferencesDefaults::on_ffmpegExecutable_editingFinished() -{ - checkFfmpegExecutable(); -} - -void PreferencesDefaults::on_extractVideoThumbnails_toggled(bool toggled) -{ - ui->videoThumbnailPosition->setEnabled(toggled); - ui->ffmpegExecutable->setEnabled(toggled); - ui->ffmpegFile->setEnabled(toggled); -} - void PreferencesDefaults::on_resetRememberedDCs_clicked() { qPrefDiveComputer::set_vendor1(QString()); @@ -125,13 +85,6 @@ void PreferencesDefaults::refreshSettings() ui->btnUseDefaultFile->setEnabled(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE); ui->chooseFile->setEnabled(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE); - ui->videoThumbnailPosition->setEnabled(qPrefGeneral::extract_video_thumbnails()); - ui->ffmpegExecutable->setEnabled(qPrefGeneral::extract_video_thumbnails()); - ui->ffmpegFile->setEnabled(qPrefGeneral::extract_video_thumbnails()); - - ui->extractVideoThumbnails->setChecked(qPrefGeneral::extract_video_thumbnails()); - ui->videoThumbnailPosition->setValue(qPrefGeneral::extract_video_thumbnails_position()); - ui->ffmpegExecutable->setText(qPrefGeneral::ffmpeg_executable()); ui->extraEnvironmentalDefault->setChecked(prefs.extraEnvironmentalDefault); } @@ -146,9 +99,6 @@ void PreferencesDefaults::syncSettings() general->set_default_file_behavior(LOCAL_DEFAULT_FILE); else if (ui->cloudDefaultFile->isChecked()) general->set_default_file_behavior(CLOUD_DEFAULT_FILE); - general->set_extract_video_thumbnails(ui->extractVideoThumbnails->isChecked()); - general->set_extract_video_thumbnails_position(ui->videoThumbnailPosition->value()); - general->set_ffmpeg_executable(ui->ffmpegExecutable->text()); qPrefDisplay::set_divelist_font(ui->font->currentFont().toString()); qPrefDisplay::set_font_size(ui->fontsize->value()); diff --git a/desktop-widgets/preferences/preferences_defaults.h b/desktop-widgets/preferences/preferences_defaults.h index 48e633ceb..4c18fcdd9 100644 --- a/desktop-widgets/preferences/preferences_defaults.h +++ b/desktop-widgets/preferences/preferences_defaults.h @@ -20,15 +20,11 @@ public slots: void on_chooseFile_clicked(); void on_btnUseDefaultFile_toggled(bool toggled); void on_localDefaultFile_toggled(bool toggled); - void on_ffmpegFile_clicked(); - void on_ffmpegExecutable_editingFinished(); - void on_extractVideoThumbnails_toggled(bool toggled); void on_resetSettings_clicked(); void on_resetRememberedDCs_clicked(); private: Ui::PreferencesDefaults *ui; - void checkFfmpegExecutable(); }; diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui index 60b478206..50cb95b35 100644 --- a/desktop-widgets/preferences/preferences_defaults.ui +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -177,79 +177,6 @@ - - - - Video thumbnails - - - - 5 - - - 5 - - - 5 - - - - - ffmpeg executable - - - - - - - - - - - - ... - - - - - - - - - Extract at position - - - - - - - 100 - - - 20 - - - Qt::Horizontal - - - - - - - Extract video thumbnails - - - - - - - - - - - - - diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp index 54a63fd71..cdead91e0 100644 --- a/desktop-widgets/preferences/preferences_graph.cpp +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -50,7 +50,6 @@ void PreferencesGraph::refreshSettings() ui->pscrfactor->setValue(lrint(1000.0 / prefs.pscr_ratio)); ui->show_average_depth->setChecked(prefs.show_average_depth); - ui->auto_recalculate_thumbnails->setChecked(prefs.auto_recalculate_thumbnails); ui->show_icd->setChecked(prefs.show_icd); } @@ -59,7 +58,6 @@ void PreferencesGraph::syncSettings() qPrefGeneral::set_defaultsetpoint(lrint(ui->defaultSetpoint->value() * 1000.0)); qPrefGeneral::set_o2consumption(lrint(ui->psro2rate->value() *1000.0)); qPrefGeneral::set_pscr_ratio(lrint(1000.0 / ui->pscrfactor->value())); - qPrefGeneral::set_auto_recalculate_thumbnails(ui->auto_recalculate_thumbnails->isChecked()); qPrefPartialPressureGas::set_phe_threshold(ui->pheThreshold->value()); qPrefPartialPressureGas::set_po2_threshold_max(ui->po2ThresholdMax->value()); diff --git a/desktop-widgets/preferences/preferences_graph.ui b/desktop-widgets/preferences/preferences_graph.ui index ab7e12f87..9fd3a11c7 100644 --- a/desktop-widgets/preferences/preferences_graph.ui +++ b/desktop-widgets/preferences/preferences_graph.ui @@ -361,13 +361,6 @@ - - - - Recalculate thumbnails if older than media file - - - 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()); + +} diff --git a/desktop-widgets/preferences/preferences_media.h b/desktop-widgets/preferences/preferences_media.h new file mode 100644 index 000000000..c328d184b --- /dev/null +++ b/desktop-widgets/preferences/preferences_media.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef PREFERENCES_MEDIA_H +#define PREFERENCES_MEDIA_H + +#include +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesMedia; +} + +class PreferencesMedia : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesMedia(); + ~PreferencesMedia(); + void refreshSettings() override; + void syncSettings() override; +public slots: + void on_ffmpegFile_clicked(); + void on_ffmpegExecutable_editingFinished(); + void on_extractVideoThumbnails_toggled(bool toggled); +private: + Ui::PreferencesMedia *ui; + void checkFfmpegExecutable(); + +}; + +#endif + diff --git a/desktop-widgets/preferences/preferences_media.ui b/desktop-widgets/preferences/preferences_media.ui new file mode 100644 index 000000000..f82e6fdcb --- /dev/null +++ b/desktop-widgets/preferences/preferences_media.ui @@ -0,0 +1,192 @@ + + + PreferencesMedia + + + + 0 + 0 + 621 + 523 + + + + Form + + + + + + + + + + UPDATE THUMBNAILS + + + + + + + + + + + true + + + Photographs or videos are sometimes edited. If a photo is more recent than its thumbnail, checking the checkbox below will allow creating a new thumbnail after the media has been edited. + + + + + + + + Recalculate thumbnail if older than media file + + + + + + + + + + + + + + + + + + + + + + VIDEOS + + + + + + + + Video thumbnails + + + + 5 + + + 5 + + + 5 + + + + + + + + + true + + + One can view video files through thumbnail(s) in the Media tab, created using the external programm FFmpeg which needs to be installed on your machine. Check the checkbox below to allow this. Then, in the text box below, specify the path to FFmpeg. In Linux, a typical path is: /usr/bin/ffmpeg. If FFmpeg is installed in the system area of your computer, just type ffmpeg in the text box below. For more info see Appendix F of the User Manual. + + + + + + + + Extract video thumbnails + + + + + + + + Path to ffmpeg: + + + + + + + + + + + + ... + + + + + + + + + + + + + true + + + One can specify te relative position within the video from where the thumbnail is retrieved. Use the slider below do do that. + + + + + + + + Extract at position + + + + + + + + 100 + + + 20 + + + Qt::Horizontal + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 508321ac5..dd5adeb7b 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -10,6 +10,7 @@ #include "preferences_network.h" #include "preferences_cloud.h" #include "preferences_equipment.h" +#include "preferences_media.h" #include "core/qthelper.h" @@ -69,6 +70,8 @@ PreferencesDialog::PreferencesDialog() addPreferencePage(new PreferencesNetwork()); addPreferencePage(new PreferencesCloud()); addPreferencePage(new PreferencesEquipment()); + addPreferencePage(new PreferencesMedia()); + refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, -- cgit v1.2.3-70-g09d2