From 7df52b7fd5d22826c5580fcd2927bbc3cadad143 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Thu, 9 Jan 2020 15:51:59 +1100 Subject: [PATCH] added disk preferences pane and the ability to set the disk cache location --- app/common/filefunctions.cpp | 6 +- app/config/config.cpp | 4 + app/dialog/preferences/preferences.cpp | 11 +-- app/dialog/preferences/preferences.h | 46 ----------- app/dialog/preferences/tabs/CMakeLists.txt | 2 + .../preferences/tabs/preferencesdisktab.cpp | 77 +++++++++++++++++++ .../preferences/tabs/preferencesdisktab.h | 31 ++++++++ app/widget/slider/sliderbase.cpp | 18 ++++- app/widget/slider/sliderbase.h | 7 ++ 9 files changed, 144 insertions(+), 58 deletions(-) create mode 100644 app/dialog/preferences/tabs/preferencesdisktab.cpp create mode 100644 app/dialog/preferences/tabs/preferencesdisktab.h diff --git a/app/common/filefunctions.cpp b/app/common/filefunctions.cpp index 9678da570..dcebb68db 100644 --- a/app/common/filefunctions.cpp +++ b/app/common/filefunctions.cpp @@ -27,6 +27,8 @@ #include #include +#include "config/config.h" + QString GetUniqueFileIdentifier(const QString &filename) { QFileInfo info(filename); @@ -48,7 +50,7 @@ QString GetUniqueFileIdentifier(const QString &filename) QString GetMediaIndexLocation() { - QDir local_appdata_dir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); + QDir local_appdata_dir(Config::Current()["DiskCachePath"].toString()); QDir media_index_dir = local_appdata_dir.filePath("mediaindex"); @@ -65,7 +67,7 @@ QString GetMediaIndexFilename(const QString &filename) QString GetMediaCacheLocation() { - QDir local_appdata_dir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); + QDir local_appdata_dir(Config::Current()["DiskCachePath"].toString()); QDir media_cache_dir = local_appdata_dir.filePath("mediacache"); diff --git a/app/config/config.cpp b/app/config/config.cpp index e09e7ad99..52258a73a 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "common/autoscroll.h" @@ -73,6 +74,9 @@ void Config::SetDefaults() config_map_["AutoscaleByDefault"] = false; config_map_["Autoscroll"] = AutoScroll::kPage; + config_map_["DiskCachePath"] = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + config_map_["DiskCacheSize"] = 20.0; + config_map_["DefaultSequenceWidth"] = 1920; config_map_["DefaultSequenceHeight"] = 1080; config_map_["DefaultSequenceFrameRate"] = QVariant::fromValue(rational(1001, 30000)); diff --git a/app/dialog/preferences/preferences.cpp b/app/dialog/preferences/preferences.cpp index 4575c23ef..3197d3eef 100644 --- a/app/dialog/preferences/preferences.cpp +++ b/app/dialog/preferences/preferences.cpp @@ -30,6 +30,7 @@ #include "tabs/preferencesbehaviortab.h" #include "tabs/preferencesappearancetab.h" #include "tabs/preferencesplaybacktab.h" +#include "tabs/preferencesdisktab.h" #include "tabs/preferencesaudiotab.h" #include "tabs/preferenceskeyboardtab.h" @@ -51,6 +52,7 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, QMenuBar* main_menu_bar) : AddTab(new PreferencesGeneralTab(), tr("General")); AddTab(new PreferencesAppearanceTab(), tr("Appearance")); AddTab(new PreferencesBehaviorTab(), tr("Behavior")); + AddTab(new PreferencesDiskTab(), tr("Disk")); AddTab(new PreferencesPlaybackTab(), tr("Playback")); AddTab(new PreferencesAudioTab(), tr("Audio")); AddTab(new PreferencesKeyboardTab(main_menu_bar), tr("Keyboard")); @@ -71,15 +73,6 @@ PreferencesDialog::PreferencesDialog(QWidget *parent, QMenuBar* main_menu_bar) : } -void PreferencesDialog::AddBoolPair(QCheckBox *ui, bool *value, bool restart_required) -{ - bool_ui.append(ui); - bool_value.append(value); - bool_restart_required.append(restart_required); - - ui->setChecked(*value); -} - void PreferencesDialog::accept() { foreach (PreferencesTab* tab, tabs_) { diff --git a/app/dialog/preferences/preferences.h b/app/dialog/preferences/preferences.h index 5e44c43bb..330a1fd01 100644 --- a/app/dialog/preferences/preferences.h +++ b/app/dialog/preferences/preferences.h @@ -65,52 +65,6 @@ private: QList tabs_; - /** - * @brief Stored default Sequence object - * - * Default Sequence settings are loaded into an actual Sequence object that can be loaded into NewSequenceDialog - * for the sake of familiarity with the user. - */ - //Sequence default_sequence; - - /** - * @brief Add an automated QCheckBox+boolean value pair - * - * Many preferences are simple true/false (or on/off) options. Rather than adding a QCheckBox for each one and - * manually setting its checked value to the configuration setting (and vice versa when saving), this convenience - * function will add it to an automated set of checkboxes, automatically setting the checked state to the current - * setting, and then saving the new checked state back to the setting when the user accepts the changes (clicks OK). - * - * @param ui - * - * A valid QCheckBox item. This function does not take ownership of the QWidget or place it in a layout anywhere. - * - * @param value - * - * A pointer to the Boolean value this QCheckBox should be shared with. The QCheckBox widget's checked state will be - * set to the value of this pointer. - * - * @param restart_required - * - * Defaults to FALSE, set this to TRUE if changing this setting should prompt the user for a restart of Olive before - * the setting change takes effect. - */ - void AddBoolPair(QCheckBox* ui, bool* value, bool restart_required = false); - - /** - * @brief Internal array managed by AddBoolPair(). Do not access this directly. - */ - QVector bool_ui; - - /** - * @brief Internal array managed by AddBoolPair(). Do not access this directly. - */ - QVector bool_value; - - /** - * @brief Internal array managed by AddBoolPair(). Do not access this directly. - */ - QVector bool_restart_required; }; #endif // PREFERENCESDIALOG_H diff --git a/app/dialog/preferences/tabs/CMakeLists.txt b/app/dialog/preferences/tabs/CMakeLists.txt index 10f978449..e381fb72f 100644 --- a/app/dialog/preferences/tabs/CMakeLists.txt +++ b/app/dialog/preferences/tabs/CMakeLists.txt @@ -20,6 +20,8 @@ set(OLIVE_SOURCES dialog/preferences/tabs/preferencesgeneraltab.cpp dialog/preferences/tabs/preferencesbehaviortab.h dialog/preferences/tabs/preferencesbehaviortab.cpp + dialog/preferences/tabs/preferencesdisktab.h + dialog/preferences/tabs/preferencesdisktab.cpp dialog/preferences/tabs/preferencesappearancetab.h dialog/preferences/tabs/preferencesappearancetab.cpp dialog/preferences/tabs/preferencesplaybacktab.h diff --git a/app/dialog/preferences/tabs/preferencesdisktab.cpp b/app/dialog/preferences/tabs/preferencesdisktab.cpp new file mode 100644 index 000000000..08fba125a --- /dev/null +++ b/app/dialog/preferences/tabs/preferencesdisktab.cpp @@ -0,0 +1,77 @@ +#include "preferencesdisktab.h" + +#include +#include +#include +#include +#include + +PreferencesDiskTab::PreferencesDiskTab() +{ + QVBoxLayout* outer_layout = new QVBoxLayout(this); + + QGridLayout* layout = new QGridLayout(); + outer_layout->addLayout(layout); + + int row = 0; + + layout->addWidget(new QLabel(tr("Disk Cache Location:")), row, 0); + + disk_cache_location_ = new QLineEdit(); + disk_cache_location_->setText(Config::Current()["DiskCachePath"].toString()); + connect(disk_cache_location_, &QLineEdit::textChanged, this, &PreferencesDiskTab::DiskCacheLineEditChanged); + layout->addWidget(disk_cache_location_, row, 1); + + QPushButton* browse_btn = new QPushButton(tr("Browse")); + connect(browse_btn, &QPushButton::clicked, this, &PreferencesDiskTab::BrowseDiskCachePath); + layout->addWidget(browse_btn, row, 2); + + row++; + + layout->addWidget(new QLabel(tr("Maximum Disk Cache:")), row, 0); + + maximum_cache_slider_ = new FloatSlider(); + maximum_cache_slider_->SetSuffix(QStringLiteral(" GB")); + maximum_cache_slider_->SetMinimum(1.0); + maximum_cache_slider_->SetValue(Config::Current()["DiskCacheSize"].toDouble()); + layout->addWidget(maximum_cache_slider_, row, 1, 1, 2); + + row++; + + QPushButton* clear_cache_btn = new QPushButton(tr("Clear Disk Cache")); + connect(clear_cache_btn, &QPushButton::clicked, this, &PreferencesDiskTab::ClearDiskCache); + layout->addWidget(clear_cache_btn, row, 1, 1, 2); + + outer_layout->addStretch(); +} + +void PreferencesDiskTab::Accept() +{ + Config::Current()["DiskCachePath"] = disk_cache_location_->text(); + Config::Current()["DiskCacheSize"] = maximum_cache_slider_->GetValue(); +} + +void PreferencesDiskTab::DiskCacheLineEditChanged() +{ + QString entered_dir = disk_cache_location_->text(); + + if (!entered_dir.isEmpty() && !QDir(entered_dir).exists()) { + disk_cache_location_->setStyleSheet(QStringLiteral("color: red;")); + } else { + disk_cache_location_->setStyleSheet(QString()); + } +} + +void PreferencesDiskTab::BrowseDiskCachePath() +{ + QString dir = QFileDialog::getExistingDirectory(this); + + if (!dir.isEmpty()) { + disk_cache_location_->setText(dir); + } +} + +void PreferencesDiskTab::ClearDiskCache() +{ + qDebug() << "Clear" << Config::Current()["DiskCachePath"]; +} diff --git a/app/dialog/preferences/tabs/preferencesdisktab.h b/app/dialog/preferences/tabs/preferencesdisktab.h new file mode 100644 index 000000000..37a2eae01 --- /dev/null +++ b/app/dialog/preferences/tabs/preferencesdisktab.h @@ -0,0 +1,31 @@ +#ifndef PREFERENCESDISKTAB_H +#define PREFERENCESDISKTAB_H + +#include + +#include "preferencestab.h" +#include "widget/slider/floatslider.h" + +class PreferencesDiskTab : public PreferencesTab +{ + Q_OBJECT +public: + PreferencesDiskTab(); + + virtual void Accept() override; + +private: + QLineEdit* disk_cache_location_; + + FloatSlider* maximum_cache_slider_; + +private slots: + void DiskCacheLineEditChanged(); + + void BrowseDiskCachePath(); + + void ClearDiskCache(); + +}; + +#endif // PREFERENCESDISKTAB_H diff --git a/app/widget/slider/sliderbase.cpp b/app/widget/slider/sliderbase.cpp index 828a32737..5ed495980 100644 --- a/app/widget/slider/sliderbase.cpp +++ b/app/widget/slider/sliderbase.cpp @@ -96,6 +96,18 @@ bool SliderBase::IsDragging() const return dragged_; } +void SliderBase::SetPrefix(const QString &s) +{ + prefix_ = s; + UpdateLabel(value_); +} + +void SliderBase::SetSuffix(const QString &s) +{ + suffix_ = s; + UpdateLabel(value_); +} + const QVariant &SliderBase::Value() { if (dragged_) { @@ -163,7 +175,11 @@ void SliderBase::UpdateLabel(const QVariant &v) if (tristate_) { label_->setText("---"); } else { - label_->setText(ValueToString(v)); + QString comp = prefix_; + comp.append(ValueToString(v)); + comp.append(suffix_); + + label_->setText(comp); } } diff --git a/app/widget/slider/sliderbase.h b/app/widget/slider/sliderbase.h index fe24b0be0..a54372df4 100644 --- a/app/widget/slider/sliderbase.h +++ b/app/widget/slider/sliderbase.h @@ -49,6 +49,9 @@ public: bool IsDragging() const; + void SetPrefix(const QString& s); + void SetSuffix(const QString& s); + signals: void ValueChanged(QVariant v); @@ -102,6 +105,10 @@ private: bool tristate_; + QString prefix_; + + QString suffix_; + private slots: void LabelPressed();