added disk preferences pane and the ability to set the disk cache location

This commit is contained in:
itsmattkc
2020-01-09 15:51:59 +11:00
parent b233bdf8c9
commit 7df52b7fd5
9 changed files with 144 additions and 58 deletions
+4 -2
View File
@@ -27,6 +27,8 @@
#include <QFileInfo>
#include <QStandardPaths>
#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");
+4
View File
@@ -24,6 +24,7 @@
#include <QDebug>
#include <QDir>
#include <QMessageBox>
#include <QStandardPaths>
#include <QXmlStreamWriter>
#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));
+2 -9
View File
@@ -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_) {
-46
View File
@@ -65,52 +65,6 @@ private:
QList<PreferencesTab*> 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<QCheckBox*> bool_ui;
/**
* @brief Internal array managed by AddBoolPair(). Do not access this directly.
*/
QVector<bool*> bool_value;
/**
* @brief Internal array managed by AddBoolPair(). Do not access this directly.
*/
QVector<bool> bool_restart_required;
};
#endif // PREFERENCESDIALOG_H
@@ -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
@@ -0,0 +1,77 @@
#include "preferencesdisktab.h"
#include <QDir>
#include <QFileDialog>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
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"];
}
@@ -0,0 +1,31 @@
#ifndef PREFERENCESDISKTAB_H
#define PREFERENCESDISKTAB_H
#include <QLineEdit>
#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
+17 -1
View File
@@ -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);
}
}
+7
View File
@@ -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();