2
* Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301 USA
20
/****************************************************************************
22
** Copyright (C) 2007-2008 Trolltech ASA. All rights reserved.
24
** This file is part of the demonstration applications of the Qt Toolkit.
26
** This file may be used under the terms of the GNU General Public
27
** License versions 2.0 or 3.0 as published by the Free Software
28
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
29
** included in the packaging of this file. Alternatively you may (at
30
** your option) use any later version of the GNU General Public
31
** License if such license has been publicly approved by Trolltech ASA
32
** (or its successors, if any) and the KDE Free Qt Foundation. In
33
** addition, as a special exception, Trolltech gives you certain
34
** additional rights. These rights are described in the Trolltech GPL
35
** Exception version 1.2, which can be found at
36
** http://www.trolltech.com/products/qt/gplexception/ and in the file
37
** GPL_EXCEPTION.txt in this package.
39
** Please review the following information to ensure GNU General
40
** Public Licensing requirements will be met:
41
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
42
** you are unsure which license is appropriate for your use, please
43
** review the following information:
44
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
45
** or contact the sales department at sales@trolltech.com.
47
** In addition, as a special exception, Trolltech, as the sole
48
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
49
** Integration plug-in the right for the Qt/Eclipse Integration to
50
** link to functionality provided by Qt Designer and its related
53
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
54
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
55
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
58
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
59
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
61
****************************************************************************/
63
#include "autosaver.h"
66
#include <qcoreapplication.h>
67
#include <qmetaobject.h>
71
#define AUTOSAVE_IN 1000 * 3 // seconds
72
#define MAXWAIT 1000 * 15 // seconds
74
AutoSaver::AutoSaver(QObject *parent) : QObject(parent)
79
AutoSaver::~AutoSaver()
81
if (m_timer.isActive()) {
82
qWarning() << "AutoSaver: still active when destroyed, changes not saved.";
83
if (parent() && parent()->metaObject())
84
qWarning() << parent() << parent()->metaObject()->className() << "should call saveIfNeccessary";
88
void AutoSaver::changeOccurred()
90
if (m_firstChange.isNull())
91
m_firstChange.start();
93
if (m_firstChange.elapsed() > MAXWAIT) {
96
m_timer.start(AUTOSAVE_IN, this);
100
void AutoSaver::timerEvent(QTimerEvent *event)
102
if (event->timerId() == m_timer.timerId()) {
105
QObject::timerEvent(event);
109
void AutoSaver::saveIfNeccessary()
111
if (!m_timer.isActive())
114
m_firstChange = QTime();
115
if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) {
116
qWarning() << "AutoSaver: error invoking slot save() on parent";