korganizer
datechecker.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00086
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"
|