From 36b2d1fe7ff1690c4478094f386933d7d0a71cf1 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sun, 16 Oct 2016 09:56:49 +0200 Subject: [PATCH] Add autosave --- src/Application/Application.cpp | 19 ++++++++++++++++++- src/Application/Application.h | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index b8bcf32..4a8511b 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -29,6 +29,9 @@ Application::Application(){ }else{ _isSSHConnection = false; } + + _lastSaveTime = 0.0f; + _autoSaveInterval = 60.0f; } void Application::setup(){ @@ -59,6 +62,15 @@ void Application::setup(){ void Application::update(){ _state->update(this); + + // Autosave, do it only of the mode is not presentation mode + if(_state != PresentationMode::instance()){ + float timeNow = ofGetElapsedTimef(); + if(timeNow - _lastSaveTime > _autoSaveInterval){ + saveProject(); + _lastSaveTime = timeNow; + } + } } ApplicationBaseMode * Application::getState(){ @@ -122,7 +134,7 @@ void Application::onKeyPressed(ofKeyEventArgs & args){ break; case 's': - _surfaceManager.saveXmlSettings(SettingsLoader::instance()->getLastLoadedFilename()); + saveProject(); break; case 'z': @@ -184,6 +196,11 @@ void Application::addFboSource(FboSource * fboSource){ _mediaServer.addFboSource(fboSource); } +void Application::saveProject(){ + ofLogNotice("Application::saveProject", "Saving project..."); + _surfaceManager.saveXmlSettings(SettingsLoader::instance()->getLastLoadedFilename()); +} + void Application::setState(ApplicationBaseMode * st){ _state = st; } diff --git a/src/Application/Application.h b/src/Application/Application.h index be57a21..a67e31f 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -58,6 +58,7 @@ class Application : public KeyListener { void addFboSource(FboSource & fboSource); void addFboSource(FboSource * fboSource); + void saveProject(); bool loadXmlSettings(string fileName); bool isShiftKeyDown(); @@ -95,6 +96,9 @@ class Application : public KeyListener { bool _shiftKeyDown; bool _isSSHConnection; + float _lastSaveTime; + float _autoSaveInterval; + string _keySequence; };