summaryrefslogtreecommitdiff
authoreilers <eilers>2004-05-04 18:48:35 (UTC)
committer eilers <eilers>2004-05-04 18:48:35 (UTC)
commit04a7f91591987c01d312fbcaf6554ec6d728554d (patch) (side-by-side diff)
tree98e10bb02d2e6c663f9c632f5e67783085683954
parentaa7023b05a3355f5c3d81d6efcccd8c4e7f4348c (diff)
downloadopie-04a7f91591987c01d312fbcaf6554ec6d728554d.zip
opie-04a7f91591987c01d312fbcaf6554ec6d728554d.tar.gz
opie-04a7f91591987c01d312fbcaf6554ec6d728554d.tar.bz2
This is the reason, why I sometimes hate C++ ..
Fixed crash in find of OPimDateBookBackend_SQL
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/opimrecurrence.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opiepim/core/opimrecurrence.cpp b/libopie2/opiepim/core/opimrecurrence.cpp
index 98bd647..4b1d886 100644
--- a/libopie2/opiepim/core/opimrecurrence.cpp
+++ b/libopie2/opiepim/core/opimrecurrence.cpp
@@ -1,266 +1,266 @@
/*
This file is part of the Opie Project
Copyright (C) The Main Author <main-author@whereever.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
.>+-=
_;:, .> :=|. This program is free software; you can
.> <`_, > . <= redistribute it and/or modify it under
:`=1 )Y*s>-.-- : the terms of the GNU Library General Public
.="- .-=="i, .._ License as published by the Free Software
- . .-<_> .<> Foundation; either version 2 of the License,
._= =} : or (at your option) any later version.
.%`+i> _;_.
.i_,=:_. -<s. This program is distributed in the hope that
+ . -:. = it will be useful, but WITHOUT ANY WARRANTY;
: .. .:, . . . without even the implied warranty of
=_ + =;=|` MERCHANTABILITY or FITNESS FOR A
_.=:. : :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.= = ; Library General Public License for more
++= -. .` .: details.
: = ...= . :.=-
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "opimrecurrence.h"
/* OPIE */
#include <opie2/opimtimezone.h>
#include <qpe/timeconversion.h>
/* QT */
#include <qshared.h>
/* STD */
#include <time.h>
namespace Opie {
struct OPimRecurrence::Data : public QShared {
Data() : QShared() {
type = OPimRecurrence::NoRepeat;
freq = -1;
days = 0;
pos = 0;
create = QDateTime::currentDateTime();
hasEnd = FALSE;
end = QDate::currentDate();
}
char days; // Q_UINT8 for 8 seven days;)
OPimRecurrence::RepeatType type;
int freq;
int pos;
bool hasEnd : 1;
QDate end;
QDateTime create;
int rep;
QString app;
ExceptionList list;
QDate start;
};
OPimRecurrence::OPimRecurrence() {
data = new Data;
}
OPimRecurrence::OPimRecurrence( const QMap<int, QString>& map )
{
- OPimRecurrence();
+ data = new Data;
fromMap( map );
}
OPimRecurrence::OPimRecurrence( const OPimRecurrence& rec)
: data( rec.data )
{
data->ref();
}
OPimRecurrence::~OPimRecurrence() {
if ( data->deref() ) {
delete data;
data = 0l;
}
}
void OPimRecurrence::deref() {
if ( data->deref() ) {
delete data;
data = 0l;
}
}
bool OPimRecurrence::operator==( const OPimRecurrence& )const {
return false;
}
OPimRecurrence &OPimRecurrence::operator=( const OPimRecurrence& re) {
if ( *this == re ) return *this;
re.data->ref();
deref();
data = re.data;
return *this;
}
bool OPimRecurrence::doesRecur()const {
return !( type() == NoRepeat );
}
/*
* we try to be smart here
*
*/
bool OPimRecurrence::doesRecur( const QDate& date ) {
/* the day before the recurrance */
QDate da = date.addDays(-1);
QDate recur;
if (!nextOcurrence( da, recur ) )
return false;
return (recur == date);
}
// FIXME unuglify!
// GPL from Datebookdb.cpp
// FIXME exception list!
bool OPimRecurrence::nextOcurrence( const QDate& from, QDate& next ) {
bool stillLooking;
stillLooking = p_nextOccurrence( from, next );
while ( stillLooking && data->list.contains(next) )
stillLooking = p_nextOccurrence( next.addDays(1), next );
return stillLooking;
}
bool OPimRecurrence::p_nextOccurrence( const QDate& from, QDate& next ) {
// easy checks, first are we too far in the future or too far in the past?
QDate tmpDate;
int freq = frequency();
int diff, diff2, a;
int iday, imonth, iyear;
int dayOfWeek = 0;
int firstOfWeek = 0;
int weekOfMonth;
if (hasEndDate() && endDate() < from)
return FALSE;
if (start() >= from ) {
next = start();
return TRUE;
}
switch ( type() ) {
case Weekly:
/* weekly is just daily by 7 */
/* first convert the repeatPattern.Days() mask to the next
day of week valid after from */
dayOfWeek = from.dayOfWeek();
dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */
/* this is done in case freq > 1 and from in week not
for this round */
// firstOfWeek = 0; this is already done at decl.
while(!((1 << firstOfWeek) & days() ))
firstOfWeek++;
/* there is at least one 'day', or there would be no event */
while(!((1 << (dayOfWeek % 7)) & days() ))
dayOfWeek++;
dayOfWeek = dayOfWeek % 7; /* the actual day of week */
dayOfWeek -= start().dayOfWeek() -1;
firstOfWeek = firstOfWeek % 7; /* the actual first of week */
firstOfWeek -= start().dayOfWeek() -1;
// dayOfWeek may be negitive now
// day of week is number of days to add to start day
freq *= 7;
// FALL-THROUGH !!!!!
case Daily:
// the add is for the possible fall through from weekly */
if(start().addDays(dayOfWeek) > from) {
/* first week exception */
next = QDate(start().addDays(dayOfWeek) );
if ((next > endDate())
&& hasEndDate() )
return FALSE;
return TRUE;
}
/* if from is middle of a non-week */
diff = start().addDays(dayOfWeek).daysTo(from) % freq;
diff2 = start().addDays(firstOfWeek).daysTo(from) % freq;
if(diff != 0)
diff = freq - diff;
if(diff2 != 0)
diff2 = freq - diff2;
diff = QMIN(diff, diff2);
next = QDate(from.addDays(diff));
if ( (next > endDate())
&& hasEndDate() )
return FALSE;
return TRUE;
case MonthlyDay:
iday = from.day();
iyear = from.year();
imonth = from.month();
/* find equivelent day of month for this month */
dayOfWeek = start().dayOfWeek();
weekOfMonth = (start().day() - 1) / 7;
/* work out when the next valid month is */
a = from.year() - start().year();
a *= 12;
a = a + (imonth - start().month());
/* a is e.start()monthsFrom(from); */
if(a % freq) {
a = freq - (a % freq);
imonth = from.month() + a;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}
}
/* imonth is now the first month after or on
from that matches the frequency given */
/* find for this month */
tmpDate = QDate( iyear, imonth, 1 );
iday = 1;
iday += (7 + dayOfWeek - tmpDate.dayOfWeek()) % 7;
iday += 7 * weekOfMonth;
while (iday > tmpDate.daysInMonth()) {
imonth += freq;
if (imonth > 12) {
imonth--;
iyear += imonth / 12;
imonth = imonth % 12;
imonth++;
}