korganizer
datechecker.cpp
Go to the documentation of this file.00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2002 Adriaan de Groot <groot@kde.org> 00005 Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org> 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License along 00018 with this program; if not, write to the Free Software Foundation, Inc., 00019 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00020 00021 As a special exception, permission is given to link this program 00022 with any edition of Qt, and distribute the resulting executable, 00023 without including the source code for Qt in the source distribution. 00024 */ 00025 00026 #include "datechecker.h" 00027 00028 #include <kdebug.h> 00029 #include <klocale.h> 00030 #include <kglobal.h> 00031 00032 #include <QTimer> 00033 00034 DateChecker::DateChecker( QObject *parent ) : QObject( parent ), mUpdateTimer( 0 ) 00035 { 00036 enableRollover( FollowMonth ); 00037 } 00038 00039 DateChecker::~DateChecker() 00040 { 00041 } 00042 00043 void DateChecker::enableRollover( RolloverType r ) 00044 { 00045 switch( r ) { 00046 case None: 00047 if ( mUpdateTimer ) { 00048 mUpdateTimer->stop(); 00049 delete mUpdateTimer; 00050 mUpdateTimer = 0; 00051 } 00052 break; 00053 case FollowDay: 00054 case FollowMonth: 00055 if ( !mUpdateTimer ) { 00056 mUpdateTimer = new QTimer( this ); 00057 connect( mUpdateTimer, SIGNAL( timeout() ), 00058 SLOT( possiblyPastMidnight() ) ); 00059 } 00060 mUpdateTimer->setSingleShot( true ); 00061 mUpdateTimer->start( 0 ); 00062 mLastDayChecked = QDate::currentDate(); 00063 } 00064 mUpdateRollover = r; 00065 } 00066 00067 void DateChecker::passedMidnight() 00068 { 00069 QDate today = QDate::currentDate(); 00070 00071 if ( today.month() != mLastDayChecked.month() ) { 00072 if ( mUpdateRollover == FollowMonth ) { 00073 emit monthPassed( today ); 00074 } 00075 } 00076 emit dayPassed( today ); 00077 } 00078 00079 void DateChecker::possiblyPastMidnight() 00080 { 00081 if ( mLastDayChecked != QDate::currentDate() ) { 00082 passedMidnight(); 00083 mLastDayChecked = QDate::currentDate(); 00084 } 00085 // Set the timer to go off 1 second after midnight 00086 // or after 8 minutes, whichever comes first. 00087 if ( mUpdateTimer ) { 00088 QTime now = QTime::currentTime(); 00089 QTime midnight = QTime( 23, 59, 59 ); 00090 int msecsWait = qMin( 480000, now.msecsTo( midnight ) + 2000 ); 00091 00092 mUpdateTimer->stop(); 00093 mUpdateTimer->start( msecsWait ); 00094 } 00095 } 00096 00097 #include "datechecker.moc"
KDE 4.5 API Reference