Documentation: Menus.docbook Composer menu Message and correcct formatting.
[kdepim.git] / korganizer / datechecker.cpp
blob4da68f06b83830fa218bc9954df6ef6a76ab3254
1 /*
2 This file is part of KOrganizer.
4 Copyright (c) 2002 Adriaan de Groot <groot@kde.org>
5 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 As a special exception, permission is given to link this program
22 with any edition of Qt, and distribute the resulting executable,
23 without including the source code for Qt in the source distribution.
26 #include "datechecker.h"
28 #include <QTimer>
30 DateChecker::DateChecker( QObject *parent ) : QObject( parent ), mUpdateTimer( 0 )
32 enableRollover( FollowMonth );
35 DateChecker::~DateChecker()
39 void DateChecker::enableRollover( RolloverType r )
41 switch( r ) {
42 case None:
43 if ( mUpdateTimer ) {
44 mUpdateTimer->stop();
45 delete mUpdateTimer;
46 mUpdateTimer = 0;
48 break;
49 case FollowDay:
50 case FollowMonth:
51 if ( !mUpdateTimer ) {
52 mUpdateTimer = new QTimer( this );
53 connect( mUpdateTimer, SIGNAL(timeout()),
54 SLOT(possiblyPastMidnight()) );
56 mUpdateTimer->setSingleShot( true );
57 mUpdateTimer->start( 0 );
58 mLastDayChecked = QDate::currentDate();
60 mUpdateRollover = r;
63 void DateChecker::passedMidnight()
65 QDate today = QDate::currentDate();
67 if ( today.month() != mLastDayChecked.month() ) {
68 if ( mUpdateRollover == FollowMonth ) {
69 emit monthPassed( today );
72 emit dayPassed( today );
75 void DateChecker::possiblyPastMidnight()
77 if ( mLastDayChecked != QDate::currentDate() ) {
78 passedMidnight();
79 mLastDayChecked = QDate::currentDate();
81 // Set the timer to go off 1 second after midnight
82 // or after 8 minutes, whichever comes first.
83 if ( mUpdateTimer ) {
84 QTime now = QTime::currentTime();
85 QTime midnight = QTime( 23, 59, 59 );
86 int msecsWait = qMin( 480000, now.msecsTo( midnight ) + 2000 );
88 mUpdateTimer->stop();
89 mUpdateTimer->start( msecsWait );
93 #include "datechecker.moc"