korganizer Library API Documentation

datechecker.cpp

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 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <qtimer.h> 00027 00028 #include <kdebug.h> 00029 #include <klocale.h> 00030 #include <kglobal.h> 00031 00032 #include "datechecker.h" 00033 00034 DateChecker::DateChecker( QObject *parent, const char *name ) 00035 : QObject( parent, name ), mUpdateTimer( 0 ) 00036 { 00037 enableRollover( FollowMonth ); 00038 } 00039 00040 DateChecker::~DateChecker() 00041 { 00042 } 00043 00044 void DateChecker::enableRollover( RolloverType r ) 00045 { 00046 switch( r ) { 00047 case None: 00048 if ( mUpdateTimer ) { 00049 mUpdateTimer->stop(); 00050 delete mUpdateTimer; 00051 mUpdateTimer = 0; 00052 } 00053 break; 00054 case FollowDay: 00055 case FollowMonth: 00056 if ( !mUpdateTimer ) { 00057 mUpdateTimer = new QTimer( this ); 00058 connect( mUpdateTimer, SIGNAL( timeout() ), 00059 SLOT( possiblyPastMidnight() ) ); 00060 } 00061 mUpdateTimer->start( 0, true ); 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, true ); 00094 } 00095 } 00096 00097 #include "datechecker.moc"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003