cache: moved disk settings to a separate dialog

This way the cache settings can be accessed in both ProjectProperties and
Preferences.
This commit is contained in:
itsmattkc
2020-08-10 20:30:11 +10:00
parent 192ea45a24
commit 03e33227b3
9 changed files with 230 additions and 55 deletions
+1
View File
@@ -17,6 +17,7 @@
add_subdirectory(about)
add_subdirectory(actionsearch)
add_subdirectory(color)
add_subdirectory(diskcache)
add_subdirectory(export)
add_subdirectory(footageproperties)
add_subdirectory(keyframeproperties)
+22
View File
@@ -0,0 +1,22 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2019 Olive Team
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
dialog/diskcache/diskcachedialog.h
dialog/diskcache/diskcachedialog.cpp
PARENT_SCOPE
)
+107
View File
@@ -0,0 +1,107 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "diskcachedialog.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QMessageBox>
#include "config/config.h"
OLIVE_NAMESPACE_ENTER
DiskCacheDialog::DiskCacheDialog(DiskCacheFolder *folder, QWidget* parent) :
QDialog(parent),
folder_(folder)
{
QGridLayout* layout = new QGridLayout(this);
int row = 0;
layout->addWidget(new QLabel(tr("Disk Cache: %1").arg(folder->GetPath())), row, 0, 1, 2);
setWindowTitle(tr("Disk Cache Settings"));
row++;
layout->addWidget(new QLabel(tr("Maximum Disk Cache:")), row, 0);
maximum_cache_slider_ = new FloatSlider();
maximum_cache_slider_->SetFormat(tr("%1 GB"));
maximum_cache_slider_->SetMinimum(1.0);
maximum_cache_slider_->SetValue(static_cast<double>(folder->GetLimit()) / static_cast<double>(kBytesInGigabyte));
layout->addWidget(maximum_cache_slider_, row, 1);
row++;
clear_cache_btn_ = new QPushButton(tr("Clear Disk Cache"));
connect(clear_cache_btn_, &QPushButton::clicked, this, &DiskCacheDialog::ClearDiskCache);
layout->addWidget(clear_cache_btn_, row, 1);
row++;
clear_disk_cache_ = new QCheckBox(tr("Automatically clear disk cache on close"));
clear_disk_cache_->setChecked(folder->GetClearOnClose());
layout->addWidget(clear_disk_cache_, row, 1);
row++;
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttons, &QDialogButtonBox::accepted, this, &DiskCacheDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &DiskCacheDialog::reject);
layout->addWidget(buttons, row, 0, 1, 2);
}
void DiskCacheDialog::accept()
{
qint64 new_disk_cache_limit = qRound64(maximum_cache_slider_->GetValue() * kBytesInGigabyte);
if (new_disk_cache_limit != folder_->GetLimit()) {
folder_->SetLimit(new_disk_cache_limit);
}
if (folder_->GetClearOnClose() != clear_disk_cache_->isChecked()) {
folder_->SetClearOnClose(clear_disk_cache_->isChecked());
}
QDialog::accept();
}
void DiskCacheDialog::ClearDiskCache()
{
if (QMessageBox::question(this,
tr("Clear Disk Cache"),
tr("Are you sure you want to clear the disk cache in '%1'?").arg(Config::Current()["DiskCachePath"].toString()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
clear_cache_btn_->setEnabled(false);
if (DiskManager::instance()->ClearDiskCache(folder_->GetPath())) {
clear_cache_btn_->setText(tr("Disk Cache Cleared"));
} else {
QMessageBox::information(this,
tr("Clear Disk Cache"),
tr("Disk cache failed to fully clear. You may have to delete the cache files manually."),
QMessageBox::Ok);
clear_cache_btn_->setText(tr("Disk Cache Partially Cleared"));
}
}
}
OLIVE_NAMESPACE_EXIT
+58
View File
@@ -0,0 +1,58 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef DISKCACHEDIALOG_H
#define DISKCACHEDIALOG_H
#include <QCheckBox>
#include <QDialog>
#include <QPushButton>
#include "render/diskmanager.h"
#include "widget/slider/floatslider.h"
OLIVE_NAMESPACE_ENTER
class DiskCacheDialog : public QDialog
{
Q_OBJECT
public:
DiskCacheDialog(DiskCacheFolder* folder, QWidget* parent = nullptr);
public slots:
virtual void accept() override;
private:
DiskCacheFolder* folder_;
FloatSlider* maximum_cache_slider_;
QCheckBox* clear_disk_cache_;
QPushButton* clear_cache_btn_;
private slots:
void ClearDiskCache();
};
OLIVE_NAMESPACE_EXIT
#endif // DISKCACHEDIALOG_H
@@ -52,26 +52,14 @@ PreferencesDiskTab::PreferencesDiskTab()
row++;
disk_management_layout->addWidget(new QLabel(tr("Maximum Disk Cache:")), row, 0);
maximum_cache_slider_ = new FloatSlider();
maximum_cache_slider_->SetFormat(tr("%1 GB"));
maximum_cache_slider_->SetMinimum(1.0);
maximum_cache_slider_->SetValue(static_cast<double>(default_disk_cache_folder_->GetLimit()) / static_cast<double>(kBytesInGigabyte));
disk_management_layout->addWidget(maximum_cache_slider_, row, 1);
QPushButton* disk_cache_settings_btn = new QPushButton(tr("Disk Cache Settings"));
connect(disk_cache_settings_btn, &QPushButton::clicked, this, [this](){
DiskManager::instance()->ShowDiskCacheSettingsDialog(disk_cache_location_->text(), this);
});
disk_management_layout->addWidget(disk_cache_settings_btn, row, 1);
row++;
clear_cache_btn_ = new QPushButton(tr("Clear Disk Cache"));
connect(clear_cache_btn_, &QPushButton::clicked, this, &PreferencesDiskTab::ClearDiskCache);
disk_management_layout->addWidget(clear_cache_btn_, row, 1);
row++;
clear_disk_cache_ = new QCheckBox(tr("Automatically clear disk cache on close"));
clear_disk_cache_->setChecked(default_disk_cache_folder_->GetClearOnClose());
disk_management_layout->addWidget(clear_disk_cache_, row, 1);
QGroupBox* cache_behavior = new QGroupBox(tr("Cache Behavior"));
outer_layout->addWidget(cache_behavior);
QGridLayout* cache_behavior_layout = new QGridLayout(cache_behavior);
@@ -125,37 +113,8 @@ void PreferencesDiskTab::Accept()
default_disk_cache_folder_->SetPath(disk_cache_location_->text());
}
qint64 new_disk_cache_limit = qRound64(maximum_cache_slider_->GetValue() * kBytesInGigabyte);
if (new_disk_cache_limit != default_disk_cache_folder_->GetLimit()) {
default_disk_cache_folder_->SetLimit(new_disk_cache_limit);
}
if (default_disk_cache_folder_->GetClearOnClose() != clear_disk_cache_->isChecked()) {
default_disk_cache_folder_->SetClearOnClose(clear_disk_cache_->isChecked());
}
Config::Current()["DiskCacheBehind"] = QVariant::fromValue(rational::fromDouble(cache_behind_slider_->GetValue()));
Config::Current()["DiskCacheAhead"] = QVariant::fromValue(rational::fromDouble(cache_ahead_slider_->GetValue()));
}
void PreferencesDiskTab::ClearDiskCache()
{
if (QMessageBox::question(this,
tr("Clear Disk Cache"),
tr("Are you sure you want to clear the disk cache in '%1'?").arg(Config::Current()["DiskCachePath"].toString()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
clear_cache_btn_->setEnabled(false);
if (DiskManager::instance()->ClearDiskCache(default_disk_cache_folder_->GetPath())) {
clear_cache_btn_->setText(tr("Disk Cache Cleared"));
} else {
QMessageBox::information(this,
tr("Clear Disk Cache"),
tr("Disk cache failed to fully clear. You may have to delete the cache files manually."),
QMessageBox::Ok);
clear_cache_btn_->setText(tr("Disk Cache Partially Cleared"));
}
}
}
OLIVE_NAMESPACE_EXIT
@@ -45,21 +45,12 @@ public:
private:
PathWidget* disk_cache_location_;
FloatSlider* maximum_cache_slider_;
FloatSlider* cache_ahead_slider_;
FloatSlider* cache_behind_slider_;
QCheckBox* clear_disk_cache_;
QPushButton* clear_cache_btn_;
DiskCacheFolder* default_disk_cache_folder_;
private slots:
void ClearDiskCache();
};
OLIVE_NAMESPACE_EXIT
@@ -124,6 +124,19 @@ ProjectPropertiesDialog::ProjectPropertiesDialog(Project* p, QWidget *parent) :
cache_layout->addWidget(cache_path_);
QPushButton* disk_cache_settings_btn = new QPushButton(tr("Disk Cache Settings"));
connect(disk_cache_settings_btn, &QPushButton::clicked, this, [this](){
if (disk_cache_use_default_btn_->isChecked()) {
DiskManager::instance()->ShowDiskCacheSettingsDialog(DiskManager::instance()->GetDefaultCacheFolder(), this);
} else if (disk_cache_store_alongside_project_btn_->isChecked()) {
// FIXME:
QMessageBox::information(this, QString(), tr("\"Store alignside project\" functionality not implemented yet"));
} else {
DiskManager::instance()->ShowDiskCacheSettingsDialog(cache_path_->text(), this);
}
});
cache_layout->addWidget(disk_cache_settings_btn);
tabs->addTab(cache_group, tr("Disk Cache"));
}
@@ -152,6 +165,7 @@ void ProjectPropertiesDialog::accept()
if (disk_cache_use_default_btn_->isChecked()) {
// Keep new cache path empty, which means default
} else if (disk_cache_store_alongside_project_btn_->isChecked()) {
// FIXME:
QMessageBox::information(this, QString(), tr("\"Store alignside project\" functionality not implemented yet"));
return;
} else {
+20
View File
@@ -31,6 +31,7 @@
#include "common/filefunctions.h"
#include "config/config.h"
#include "core.h"
#include "dialog/diskcache/diskcachedialog.h"
OLIVE_NAMESPACE_ENTER
@@ -165,6 +166,25 @@ QString DiskManager::GetDefaultDiskCachePath()
return QDir(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)).filePath("mediacache");
}
void DiskManager::ShowDiskCacheSettingsDialog(DiskCacheFolder *folder, QWidget *parent)
{
DiskCacheDialog d(folder, parent);
d.exec();
}
void DiskManager::ShowDiskCacheSettingsDialog(const QString &path, QWidget *parent)
{
if (!FileFunctions::DirectoryIsValid(path, true)) {
QMessageBox::critical(parent, tr("Disk Cache Error"),
tr("Failed to open disk cache at \"%1\". Try a different folder.").arg(path));
return;
}
DiskCacheFolder* folder = GetOpenFolder(path);
ShowDiskCacheSettingsDialog(folder, parent);
}
DiskCacheFolder::DiskCacheFolder(const QString &path, QObject *parent) :
QObject(parent)
{
+3
View File
@@ -135,6 +135,9 @@ public:
static QString GetDefaultDiskCachePath();
void ShowDiskCacheSettingsDialog(DiskCacheFolder* folder, QWidget* parent);
void ShowDiskCacheSettingsDialog(const QString& path, QWidget* parent);
public slots:
void Accessed(const QString& cache_folder, const QByteArray& hash);