diff options
author | Jon Ander Peñalba <jonan88@gmail.com> | 2010-09-20 22:35:58 +0200 |
---|---|---|
committer | Jon Ander Peñalba <jonan88@gmail.com> | 2010-09-20 22:35:58 +0200 |
commit | 66fb43cdefd0de3946f8d6c931f4568384bdf57b (patch) | |
tree | 30c36d1e65f337a4004f1e3901baa972584c53f8 /src/history/autosaver.cpp | |
parent | Merge commit 'refs/merge-requests/216' of git://gitorious.org/rekonq/mainline... (diff) | |
download | rekonq-66fb43cdefd0de3946f8d6c931f4568384bdf57b.tar.xz |
History autosaver improved to be more general and less hackish
Diffstat (limited to 'src/history/autosaver.cpp')
-rw-r--r-- | src/history/autosaver.cpp | 67 |
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(); +} |