summaryrefslogtreecommitdiff
path: root/src/history/autosaver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/history/autosaver.cpp')
-rw-r--r--src/history/autosaver.cpp67
1 files changed, 33 insertions, 34 deletions
diff --git a/src/history/autosaver.cpp b/src/history/autosaver.cpp
index 83b3f6b0..3b966b52 100644
--- a/src/history/autosaver.cpp
+++ b/src/history/autosaver.cpp
@@ -25,73 +25,72 @@
* ============================================================ */
-
-
// Self Includes
#include "autosaver.h"
#include "autosaver.moc"
// Qt Includes
#include <QtCore/QMetaObject>
+#include <QtCore/QTimerEvent>
+#include <QtCore/QBasicTimer>
+#include <QtCore/QTime>
-#define AUTOSAVE_IN 1000 * 3 // seconds
-#define MAXWAIT 1000 * 15 // seconds
+const int AUTOSAVE_TIME = 1000 * 3; // seconds
+const int MAX_TIME_LIMIT = 1000 * 15; // seconds
-AutoSaver::AutoSaver(QObject *parent) : QObject(parent)
+AutoSaver::AutoSaver(QObject *parent)
+ : QObject(parent)
+ , m_timer(new QBasicTimer)
+ , m_firstChange(new QTime)
{
- Q_ASSERT(parent);
}
AutoSaver::~AutoSaver()
{
- if (m_timer.isActive())
- {
+ if (m_timer->isActive())
kDebug() << "AutoSaver: still active when destroyed, changes not saved.";
- }
+
+ delete m_firstChange;
+ delete m_timer;
+}
+
+
+void AutoSaver::saveIfNeccessary()
+{
+ if (m_timer->isActive())
+ save();
}
void AutoSaver::changeOccurred()
{
- if (m_firstChange.isNull())
- m_firstChange.start();
+ if (m_firstChange->isNull())
+ m_firstChange->start();
- if (m_firstChange.elapsed() > MAXWAIT)
- {
- saveIfNeccessary();
- }
+ if (m_firstChange->elapsed() > MAX_TIME_LIMIT)
+ save();
else
- {
- m_timer.start(AUTOSAVE_IN, this);
- }
+ m_timer->start(AUTOSAVE_TIME, this);
}
void AutoSaver::timerEvent(QTimerEvent *event)
{
- if (event->timerId() == m_timer.timerId())
- {
- saveIfNeccessary();
- }
+ if (event->timerId() == m_timer->timerId())
+ save();
else
- {
QObject::timerEvent(event);
- }
}
-void AutoSaver::saveIfNeccessary()
+void AutoSaver::save()
{
- if (!m_timer.isActive())
- return;
- m_timer.stop();
- m_firstChange = QTime();
- if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection))
- {
- kDebug() << "AutoSaver: error invoking slot save() on parent";
- }
-}
+ m_timer->stop();
+ delete m_firstChange;
+ m_firstChange = new QTime;
+ emit saveNeeded();
+}