diff --git a/app/dialog/CMakeLists.txt b/app/dialog/CMakeLists.txt
index 1eed0ae0a..442f760e0 100644
--- a/app/dialog/CMakeLists.txt
+++ b/app/dialog/CMakeLists.txt
@@ -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)
diff --git a/app/dialog/diskcache/CMakeLists.txt b/app/dialog/diskcache/CMakeLists.txt
new file mode 100644
index 000000000..6ca59d549
--- /dev/null
+++ b/app/dialog/diskcache/CMakeLists.txt
@@ -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 .
+
+set(OLIVE_SOURCES
+ ${OLIVE_SOURCES}
+ dialog/diskcache/diskcachedialog.h
+ dialog/diskcache/diskcachedialog.cpp
+ PARENT_SCOPE
+)
diff --git a/app/dialog/diskcache/diskcachedialog.cpp b/app/dialog/diskcache/diskcachedialog.cpp
new file mode 100644
index 000000000..6e542b7c3
--- /dev/null
+++ b/app/dialog/diskcache/diskcachedialog.cpp
@@ -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 .
+
+***/
+
+#include "diskcachedialog.h"
+
+#include
+#include
+#include
+#include
+
+#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(folder->GetLimit()) / static_cast(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
diff --git a/app/dialog/diskcache/diskcachedialog.h b/app/dialog/diskcache/diskcachedialog.h
new file mode 100644
index 000000000..69c3a20f3
--- /dev/null
+++ b/app/dialog/diskcache/diskcachedialog.h
@@ -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 .
+
+***/
+
+#ifndef DISKCACHEDIALOG_H
+#define DISKCACHEDIALOG_H
+
+#include
+#include
+#include
+
+#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
diff --git a/app/dialog/preferences/tabs/preferencesdisktab.cpp b/app/dialog/preferences/tabs/preferencesdisktab.cpp
index ea167d0c9..fef948409 100644
--- a/app/dialog/preferences/tabs/preferencesdisktab.cpp
+++ b/app/dialog/preferences/tabs/preferencesdisktab.cpp
@@ -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(default_disk_cache_folder_->GetLimit()) / static_cast(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
diff --git a/app/dialog/preferences/tabs/preferencesdisktab.h b/app/dialog/preferences/tabs/preferencesdisktab.h
index c087abca6..5eb7438b7 100644
--- a/app/dialog/preferences/tabs/preferencesdisktab.h
+++ b/app/dialog/preferences/tabs/preferencesdisktab.h
@@ -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
diff --git a/app/dialog/projectproperties/projectproperties.cpp b/app/dialog/projectproperties/projectproperties.cpp
index abddcc295..5a8713f5c 100644
--- a/app/dialog/projectproperties/projectproperties.cpp
+++ b/app/dialog/projectproperties/projectproperties.cpp
@@ -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 {
diff --git a/app/render/diskmanager.cpp b/app/render/diskmanager.cpp
index d8883ca89..2cdbf2024 100644
--- a/app/render/diskmanager.cpp
+++ b/app/render/diskmanager.cpp
@@ -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)
{
diff --git a/app/render/diskmanager.h b/app/render/diskmanager.h
index 6c46082c8..71ff30bac 100644
--- a/app/render/diskmanager.h
+++ b/app/render/diskmanager.h
@@ -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);