Falkon Develop
Cross-platform Qt-based web browser
autosaver.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "autosaver.h"
19
20#include <QTimerEvent>
21#include <QCoreApplication>
22
23#define SAVE_DELAY 1000 * 10 // 10 seconds
24
25AutoSaver::AutoSaver(QObject* parent)
26 : QObject(parent)
27{
28 connect(qApp, &QCoreApplication::aboutToQuit, this, &AutoSaver::saveIfNecessary);
29}
30
32{
33 if (m_timer.isActive()) {
34 m_timer.stop();
35 Q_EMIT save();
36 }
37}
38
40{
41 if (!m_timer.isActive()) {
42 m_timer.start(SAVE_DELAY, this);
43 }
44}
45
46void AutoSaver::timerEvent(QTimerEvent* event)
47{
48 if (event->timerId() == m_timer.timerId()) {
49 m_timer.stop();
50 Q_EMIT save();
51 }
52
53 QObject::timerEvent(event);
54}
#define SAVE_DELAY
Definition: autosaver.cpp:23
AutoSaver(QObject *parent=nullptr)
Definition: autosaver.cpp:25
void changeOccurred()
Definition: autosaver.cpp:39
void save()
void saveIfNecessary()
Definition: autosaver.cpp:31