Document autosave facility

preferencesAboutTextFull
Ilia Ryabokon 11 years ago
parent c53320d6e8
commit ab828a1824
  1. 54
      src/board/UBBoardController.cpp
  2. 17
      src/board/UBBoardController.h
  3. 3
      src/core/UBApplication.cpp
  4. 3
      src/core/UBDownloadThread.cpp
  5. 1
      src/core/UBSettings.cpp
  6. 2
      src/core/UBSettings.h

@ -108,6 +108,7 @@ UBBoardController::UBBoardController(UBMainWindow* mainWindow)
, mMovingSceneIndex(-1)
, mActionGroupText(tr("Group"))
, mActionUngroupText(tr("Ungroup"))
, mAutosaveTimer(0)
{
mZoomFactor = UBSettings::settings()->boardZoomFactor->get().toDouble();
@ -395,6 +396,21 @@ void UBBoardController::stopScript()
freezeW3CWidgets(true);
}
void UBBoardController::saveData(SaveFlags fls)
{
bool verbose = fls | sf_showProgress;
if (verbose) {
UBApplication::showMessage("Saving document...");
}
if (mActiveScene && mActiveScene->isModified()) {
persistCurrentScene();
}
if (verbose) {
UBApplication::showMessage("Document has just been saved...");
}
}
void UBBoardController::initToolbarTexts()
{
QList<QAction*> allToolbarActions;
@ -1647,6 +1663,14 @@ void UBBoardController::adjustDisplayViews()
}
int UBBoardController::autosaveTimeoutFromSettings()
{
int value = UBSettings::settings()->timerInterval->get().toInt();
int minute = 60 * 1000;
return value * minute;
}
void UBBoardController::changeBackground(bool isDark, bool isCrossed)
{
bool currentIsDark = mActiveScene->isDarkBackground();
@ -1768,6 +1792,36 @@ void UBBoardController::documentSceneChanged(UBDocumentProxy* pDocumentProxy, in
}
}
void UBBoardController::autosaveTimeout()
{
if (UBApplication::applicationController->displayMode() != UBApplicationController::Board) {
//perform autosave only in board mode
return;
}
saveData(sf_showProgress);
}
void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md)
{
// int timerInterval = autosaveTimeoutFromSettings();
int timerInterval = 50000;
if (!timerInterval) {
return;
}
if (!mAutosaveTimer) {
mAutosaveTimer = new QTimer(this);
connect(mAutosaveTimer, SIGNAL(timeout()), this, SLOT(autosaveTimeout()));
}
if (md == UBApplicationController::Board) {
mAutosaveTimer->start(timerInterval);
} else if (mAutosaveTimer->isActive()) {
mAutosaveTimer->stop();
}
}
void UBBoardController::closing()
{
mIsClosing = true;

@ -32,6 +32,7 @@
#include <QObject>
#include "document/UBDocumentContainer.h"
#include "core/UBApplicationController.h"
class UBMainWindow;
class UBApplication;
@ -59,6 +60,13 @@ class UBBoardController : public UBDocumentContainer
{
Q_OBJECT
public:
enum SaveFlag {
sf_none = 0x0,
sf_showProgress = 0x1
};
Q_DECLARE_FLAGS(SaveFlags, SaveFlag)
public:
UBBoardController(UBMainWindow *mainWindow);
virtual ~UBBoardController();
@ -240,6 +248,8 @@ class UBBoardController : public UBDocumentContainer
void startScript();
void stopScript();
void saveData(SaveFlags fls = sf_none);
signals:
void newPageAdded();
void activeSceneChanged();
@ -267,10 +277,15 @@ class UBBoardController : public UBDocumentContainer
void undoRedoStateChange(bool canUndo);
void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
private slots:
void autosaveTimeout();
void appMainModeChanged(UBApplicationController::MainMode);
private:
void updatePageSizeState();
void saveViewState();
void adjustDisplayViews();
int autosaveTimeoutFromSettings();
UBMainWindow *mMainWindow;
UBGraphicsScene* mActiveScene;
@ -298,6 +313,8 @@ class UBBoardController : public UBDocumentContainer
QString mActionGroupText;
QString mActionUngroupText;
QTimer *mAutosaveTimer;
private slots:
void stylusToolDoubleClicked(int tool);
void boardViewResized(QResizeEvent* event);

@ -339,7 +339,8 @@ int UBApplication::exec(const QString& pFileToImport)
connect(applicationController, SIGNAL(desktopMode(bool)),
boardController->paletteManager(), SLOT(slot_changeDesktopMode(bool)));
connect(applicationController, SIGNAL(mainModeChanged(UBApplicationController::MainMode))
, boardController, SLOT(appMainModeChanged(UBApplicationController::MainMode)));
connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), applicationController, SLOT(showDesktop(bool)));
connect(mainWindow->actionDesktop, SIGNAL(triggered(bool)), this, SLOT(stopScript()));

@ -22,9 +22,6 @@
* along with OpenBoard. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QNetworkProxy>
#include <QNetworkDiskCache>

@ -352,6 +352,7 @@ void UBSettings::init()
boardShowToolsPalette = new UBSetting(this, "Board", "ShowToolsPalette", "false");
magnifierDrawingMode = new UBSetting(this, "Board", "MagnifierDrawingMode", "0");
timerInterval = new UBSetting(this, "Board", "Timer interval", "5");
svgViewBoxMargin = new UBSetting(this, "SVG", "ViewBoxMargin", "50");

@ -373,6 +373,8 @@ class UBSettings : public QObject
UBSetting* libIconSize;
UBSetting* magnifierDrawingMode;
UBSetting* timerInterval;
public slots:
void setPenWidthIndex(int index);

Loading…
Cancel
Save