From db9f1887334f8f9e80066f559c368b8834cc02d6 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 18 Nov 2019 13:47:42 +0900 Subject: [PATCH] reimplemented infrastructure for autorecovery projects Foundation for a fairly simple but likely essential autorecovery process. Basically the same as what it was in 0.1.x but with a huge improvement: custom autorecovery intervals. Ironically there isn't any "saving" to be done just yet, but when there is, this infrastructure will be ready for it. --- app/config/config.cpp | 1 + app/core.cpp | 28 +++++++++++++++++++++++++++- app/core.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/app/config/config.cpp b/app/config/config.cpp index b87db7a89..443a4e752 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -53,6 +53,7 @@ void Config::SetDefaults() config_map_["DefaultStillLength"] = QVariant::fromValue(rational(2)); config_map_["HoverFocus"] = false; config_map_["AudioScrubbing"] = true; + config_map_["AutorecoveryInterval"] = 1; } void Config::Load() diff --git a/app/core.cpp b/app/core.cpp index 2382ee77d..c163d3b00 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -52,7 +52,8 @@ Core olive::core; Core::Core() : main_window_(nullptr), tool_(olive::tool::kPointer), - snapping_(true) + snapping_(true), + queue_autorecovery_(false) { } @@ -351,6 +352,19 @@ void Core::StartGUI(bool full_screen) // Initialize audio service AudioManager::CreateInstance(); + + // Start autorecovery timer using the config value as its interval + SetAutorecoveryInterval(Config::Current()["AutorecoveryInterval"].toInt()); + autorecovery_timer_.start(); +} + +void Core::SaveAutorecovery() +{ + if (queue_autorecovery_) { + // FIXME: Save autorecovery of projects open + + queue_autorecovery_ = false; + } } Project *Core::GetActiveProject() @@ -366,3 +380,15 @@ Project *Core::GetActiveProject() // Otherwise, return the project panel's project (which may be nullptr but in most cases shouldn't be) return active_project_panel->project(); } + +void Core::SetProjectModified() +{ + main_window()->setWindowModified(true); + queue_autorecovery_ = true; +} + +void Core::SetAutorecoveryInterval(int minutes) +{ + // Convert minutes to milliseconds + autorecovery_timer_.setInterval(minutes * 60000); +} diff --git a/app/core.h b/app/core.h index d14bb2fa7..e096752d4 100644 --- a/app/core.h +++ b/app/core.h @@ -22,6 +22,7 @@ #define CORE_H #include +#include #include "project/project.h" #include "project/projectviewmodel.h" @@ -113,6 +114,19 @@ public: */ Project* GetActiveProject(); + /** + * @brief Sets state to "modified" so that the GUI will prompt the user to save before closing + * + * Call this function whenever a change is made to a currently active project. Saving the project will automatically + * unset this. + */ + void SetProjectModified(); + + /** + * @brief Set how frequently an autorecovery should be saved (if the project has changed, see SetProjectModified()) + */ + void SetAutorecoveryInterval(int minutes); + public slots: /** * @brief Set the current application-wide tool @@ -226,6 +240,22 @@ private: */ bool snapping_; + /** + * @brief Internal value for whether to make an autorecovery next interval + * + * True if the project has changed since the last autorecovery and we should save next time. False if the project has + * not changed and saving another autorecovery would be a waste. + */ + bool queue_autorecovery_; + + /** + * @brief Internal timer for saving autorecovery files + */ + QTimer autorecovery_timer_; + +private slots: + void SaveAutorecovery(); + }; namespace olive {