Automated with clang-tidy readability-identifier-naming (config added to .clang-tidy) plus scripted passes, per the updated rules now documented in CONTRIBUTING.md: - types (class/struct/enum/alias/template params): PascalCase - functions, variables, members: snake_case (incl. rational -> Rational) - private/protected members: trailing underscore; static member variables likewise (instance_, available_themes_) - constants and enum values: snake_case (kLinear -> k_linear, F32P -> f32p); ALL_CAPS reserved for macros - macros: OAK_ prefix (OLIVE_ADD_TEST/OLIVE_ASSERT/OLIVE_CONFIG -> OAK_ADD_TEST/OAK_ASSERT/OAK_CONFIG, GL_PREAMBLE -> OAK_GL_PREAMBLE, include guards -> OAK_*) - file names: all lowercase (Current/Plugin/OliveHost/OliveClip/ OlivePluginInstance -> current/plugin/olivehost/oliveclip/ oliveplugininstance) - getters share the member name sans underscore, setters set_foo() - Qt and third-party (OpenFX) virtual overrides and framework callbacks keep their original names (exempt in .clang-tidy) Manual follow-ups required where automation could not reach: - string-based QMetaObject/SIGNAL/SLOT references updated to renamed methods (AddTask, CreatedFile, DeleteSpecificFile, moveSelectionUp, ...) - macro bodies referencing renamed methods (OLIVE_CONFIG, NODE_DEFAULT_DESTRUCTOR, MANAGEDDISPLAYWIDGET_*) - self-shadowing locals renamed where signals/methods became same-named (size_changed, worker_count, selected_items, import param, filters) - third_party OFX member/namespace usages restored (OFX::Host::*, _created, _clipPrefsDirty, createInstance, clearPersistentMessage) - STL protocol aliases restored (const_iterator) with .clang-tidy ignore rules; qHash overloads restored Full build and test suite pass: ctest 4/4, ~1960 gtest cases green.
174 lines
3.5 KiB
C++
174 lines
3.5 KiB
C++
/***
|
|
|
|
Olive - Non-Linear Video Editor
|
|
Copyright (C) 2022 Olive Team
|
|
Modifications Copyright (C) 2025 mikesolar
|
|
|
|
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 OAK_DISKMANAGER_H
|
|
#define OAK_DISKMANAGER_H
|
|
|
|
#include <QMap>
|
|
#include <QMutex>
|
|
#include <QObject>
|
|
#include <QTimer>
|
|
|
|
#include "common/define.h"
|
|
#include "node/project.h"
|
|
|
|
namespace olive
|
|
{
|
|
|
|
class DiskCacheFolder : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
DiskCacheFolder(const QString &path, QObject *parent = nullptr);
|
|
|
|
virtual ~DiskCacheFolder() override;
|
|
|
|
bool clear_cache();
|
|
|
|
void accessed(const QString &filename);
|
|
|
|
void created_file(const QString &filename);
|
|
|
|
const QString &get_path() const
|
|
{
|
|
return path_;
|
|
}
|
|
|
|
void set_path(const QString &path);
|
|
|
|
qint64 get_limit() const
|
|
{
|
|
return limit_;
|
|
}
|
|
|
|
bool get_clear_on_close() const
|
|
{
|
|
return clear_on_close_;
|
|
}
|
|
|
|
void set_limit(qint64 l)
|
|
{
|
|
limit_ = l;
|
|
}
|
|
|
|
void set_clear_on_close(bool e)
|
|
{
|
|
clear_on_close_ = e;
|
|
}
|
|
|
|
bool delete_specific_file(const QString &f);
|
|
|
|
signals:
|
|
void deleted_frame(const QString &path, const QString &filename);
|
|
|
|
private:
|
|
struct HashTime {
|
|
qint64 file_size;
|
|
qint64 access_time;
|
|
};
|
|
|
|
bool delete_file_internal(QMap<QString, HashTime>::iterator hash_to_delete);
|
|
|
|
bool delete_least_recent();
|
|
|
|
void close_cache_folder();
|
|
|
|
QString path_;
|
|
|
|
QString index_path_;
|
|
|
|
QMap<QString, HashTime> disk_data_;
|
|
|
|
qint64 consumption_;
|
|
|
|
qint64 limit_;
|
|
|
|
bool clear_on_close_;
|
|
|
|
QTimer save_timer_;
|
|
|
|
private slots:
|
|
void save_disk_cache_index();
|
|
};
|
|
|
|
class DiskManager : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static void create_instance();
|
|
|
|
static void destroy_instance();
|
|
|
|
static DiskManager *instance();
|
|
|
|
bool clear_disk_cache(const QString &cache_folder);
|
|
|
|
DiskCacheFolder *get_default_cache_folder() const
|
|
{
|
|
// The first folder will always be the default
|
|
return open_folders_.first();
|
|
}
|
|
|
|
const QString &get_default_cache_path() const
|
|
{
|
|
return get_default_cache_folder()->get_path();
|
|
}
|
|
|
|
DiskCacheFolder *get_open_folder(const QString &path);
|
|
|
|
const QVector<DiskCacheFolder *> &get_open_folders() const
|
|
{
|
|
return open_folders_;
|
|
}
|
|
|
|
static bool show_disk_cache_change_confirmation_dialog(QWidget *parent);
|
|
|
|
static QString get_default_disk_cache_config_file();
|
|
|
|
static QString get_default_disk_cache_path();
|
|
|
|
void show_disk_cache_settings_dialog(DiskCacheFolder *folder, QWidget *parent);
|
|
void show_disk_cache_settings_dialog(const QString &path, QWidget *parent);
|
|
|
|
public slots:
|
|
void accessed(const QString &cache_folder, const QString &filename);
|
|
|
|
void created_file(const QString &cache_folder, const QString &filename);
|
|
|
|
void delete_specific_file(const QString &filename);
|
|
|
|
signals:
|
|
void deleted_frame(const QString &path, const QString &filename);
|
|
|
|
void invalidate_project(Project *p);
|
|
|
|
private:
|
|
DiskManager();
|
|
|
|
virtual ~DiskManager() override;
|
|
|
|
static DiskManager *instance_;
|
|
|
|
QVector<DiskCacheFolder *> open_folders_;
|
|
};
|
|
|
|
}
|
|
|
|
#endif // OAK_DISKMANAGER_H
|