summaryrefslogtreecommitdiff
path: root/libopie/pim
authorzecke <zecke>2003-02-21 20:08:44 (UTC)
committer zecke <zecke>2003-02-21 20:08:44 (UTC)
commite09381c4b3d482c6b553a61c5fb0502a089dcc5f (patch) (side-by-side diff)
treec336a21f6b00e09989de5309ca8bb933c9494b09 /libopie/pim
parent3b37e71ad7dd41555763d15a16c691b503780de8 (diff)
downloadopie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.zip
opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.gz
opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.bz2
-Fix hasRecurrence()
-Add the Access(Backend) of DateBook
Diffstat (limited to 'libopie/pim') (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/odatebookaccess.cpp37
-rw-r--r--libopie/pim/odatebookaccess.h32
-rw-r--r--libopie/pim/odatebookaccessbackend.cpp156
-rw-r--r--libopie/pim/odatebookaccessbackend.h32
-rw-r--r--libopie/pim/oevent.cpp13
-rw-r--r--libopie/pim/oevent.h6
6 files changed, 266 insertions, 10 deletions
diff --git a/libopie/pim/odatebookaccess.cpp b/libopie/pim/odatebookaccess.cpp
new file mode 100644
index 0000000..5f97e7c
--- a/dev/null
+++ b/libopie/pim/odatebookaccess.cpp
@@ -0,0 +1,37 @@
+#include "obackendfactory.h"
+#include "odatebookaccess.h"
+
+ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
+ : OPimAccessTemplate<OEvent>( back )
+{
+ if (!back )
+ back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null );
+
+ m_backEnd = back;
+}
+ODateBookAccess::~ODateBookAccess() {
+}
+ODateBookAccess::List ODateBookAccess::rawEvents()const {
+ QArray<int> ints = m_backEnd->rawEvents();
+
+ List lis( ints, this );
+ return lis;
+}
+ODateBookAccess::List ODateBookAccess::rawRepeats()const {
+ QArray<int> ints = m_backEnd->rawRepeats();
+
+ List lis( ints, this );
+ return lis;
+}
+ODateBookAccess::List ODateBookAccess::nonRepeats()const {
+ QArray<int> ints = m_backEnd->nonRepeats();
+
+ List lis( ints, this );
+ return lis;
+}
+OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDate& from, const QDate& to ) {
+ return m_backEnd->effecticeEvents( from, to );
+}
+OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDateTime& start ) {
+ return m_backEnd->effecticeEvents( start );
+}
diff --git a/libopie/pim/odatebookaccess.h b/libopie/pim/odatebookaccess.h
new file mode 100644
index 0000000..3f2c728
--- a/dev/null
+++ b/libopie/pim/odatebookaccess.h
@@ -0,0 +1,32 @@
+#ifndef OPIE_DATE_BOOK_ACCESS_H
+#define OPIE_DATE_BOOK_ACCESS_H
+
+#include "odatebookaccessbackend.h"
+#include "opimaccesstemplate.h"
+
+#include "oevent.h"
+
+class ODateBookAccess : public OPimAccessTemplate<OEvent> {
+public:
+ ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
+ ~ODateBookAccess();
+
+ /** return all events */
+ List rawEvents()const;
+
+ /** return repeating events */
+ List rawRepeats()const;
+
+ /** return non repeating events */
+ List nonRepeats()const;
+
+ OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
+ OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
+
+private:
+ ODateBookAccessBackend* m_backEnd;
+ class Private;
+ Private* d;
+};
+
+#endif
diff --git a/libopie/pim/odatebookaccessbackend.cpp b/libopie/pim/odatebookaccessbackend.cpp
new file mode 100644
index 0000000..8fa1a68
--- a/dev/null
+++ b/libopie/pim/odatebookaccessbackend.cpp
@@ -0,0 +1,156 @@
+#include <qtl.h>
+
+#include "orecur.h"
+
+#include "odatebookaccessbackend.h"
+
+namespace {
+/* a small helper to get all NonRepeating events for a range of time */
+ void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events,
+ const QDate& from, const QDate& to ) {
+ QDateTime dtStart, dtEnd;
+
+ for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
+ dtStart = (*it).startDateTime();
+ dtEnd = (*it).endDateTime();
+
+ /*
+ * If in range
+ */
+ if (dtStart.date() >= from && dtEnd.date() <= to ) {
+ OEffectiveEvent eff;
+ eff.setEvent( (*it) );
+ eff.setDate( dtStart.date() );
+ eff.setStartTime( dtStart.time() );
+
+ /* if not on the same day */
+ if ( dtStart.date() != dtEnd.date() )
+ eff.setEndTime( QTime(23, 59, 0 ) );
+ else
+ eff.setEndTime( dtEnd.time() );
+
+ tmpList.append( eff );
+ }
+
+ /* we must also check for end date information... */
+ if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
+ QDateTime dt = dtStart.addDays( 1 );
+ dt.setTime( QTime(0, 0, 0 ) );
+ QDateTime dtStop;
+ if ( dtEnd > to )
+ dtStop = to;
+ else
+ dtStop = dtEnd;
+
+ while ( dt <= dtStop ) {
+ OEffectiveEvent eff;
+ eff.setEvent( (*it) );
+ eff.setDate( dt.date() );
+
+ if ( dt >= from ) {
+ eff.setStartTime( QTime(0, 0, 0 ) );
+ if ( dt.date() == dtEnd.date() )
+ eff.setEndTime( dtEnd.time() );
+ else
+ eff.setEndTime( QTime(23, 59, 0 ) );
+ tmpList.append( eff );
+ }
+ dt = dt.addDays( 1 );
+ }
+ }
+ }
+ }
+
+ void repeat( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& list,
+ const QDate& from, const QDate& to ) {
+ QDate repeat;
+ for ( OEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
+ int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
+ QDate itDate = from.addDays(-dur );
+ ORecur rec = (*it).recurrence();
+ if ( !rec.hasEndDate() || rec.endDate() > to ) {
+ rec.setEndDate( to );
+ rec.setHasEndDate( true );
+ }
+ while (rec.nextOcurrence(itDate, repeat ) ) {
+ if (repeat > to ) break;
+ OEffectiveEvent eff;
+ eff.setDate( repeat );
+ if ( (*it).isAllDay() ) {
+ eff.setStartTime( QTime(0, 0, 0 ) );
+ eff.setEndTime( QTime(23, 59, 59 ) );
+ }else {
+ /* we only occur by days, not hours/minutes/seconds. Hence
+ * the actual end and start times will be the same for
+ * every repeated event. For multi day events this is
+ * fixed up later if on wronge day span
+ */
+ eff.setStartTime( (*it).startDateTime().time() );
+ eff.setEndTime( (*it).endDateTime().time() );
+ }
+ if ( dur != 0 ) {
+ // multi-day repeating events
+ QDate sub_it = QMAX( repeat, from );
+ QDate startDate = repeat;
+ QDate endDate = startDate.addDays( dur );
+
+ while ( sub_it <= endDate && sub_it <= to ) {
+ OEffectiveEvent tmpEff = eff;
+ tmpEff.setEvent( (*it) );
+ if ( sub_it != startDate )
+ tmpEff.setStartTime( QTime(0, 0, 0 ) );
+ if ( sub_it != endDate )
+ tmpEff.setEndTime( QTime( 23, 59, 59 ) );
+
+ tmpEff.setDate( sub_it );
+ tmpEff.setEffectiveDates( startDate, endDate );
+ tmpList.append( tmpEff );
+
+ sub_it = sub_it.addDays( 1 );
+ }
+ itDate = endDate;
+ }else {
+ eff.setEvent( (*it) );
+ tmpList.append( eff );
+ itDate = repeat.addDays( 1 );
+ }
+ }
+ }
+ }
+}
+
+ODateBookAccessBackend::ODateBookAccessBackend()
+ : OPimAccessBackend<OEvent>()
+{
+
+}
+ODateBookAccessBackend::~ODateBookAccessBackend() {
+
+}
+OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDate& from,
+ const QDate& to ) {
+ OEffectiveEvent::ValueList tmpList;
+ OEvent::ValueList list = directNonRepeats();
+
+ events( tmpList, list, from, to );
+ repeat( tmpList, directRawRepeats(),from,to );
+
+ list = directRawRepeats();
+
+ qHeapSort( tmpList );
+ return tmpList;
+}
+OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDateTime& dt ) {
+ OEffectiveEvent::ValueList day = effecticeEvents( dt.date(), dt.date() );
+ OEffectiveEvent::ValueList::Iterator it;
+
+ OEffectiveEvent::ValueList tmpList;
+ QDateTime dtTmp;
+ for ( it = day.begin(); it != day.end(); ++it ) {
+ dtTmp = QDateTime( (*it).date(), (*it).startTime() );
+ if ( QABS(dt.secsTo(dtTmp) ) < 60 )
+ tmpList.append( (*it) );
+ }
+
+ return tmpList;
+}
diff --git a/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h
new file mode 100644
index 0000000..eb6e8fb
--- a/dev/null
+++ b/libopie/pim/odatebookaccessbackend.h
@@ -0,0 +1,32 @@
+#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H
+#define OPIE_DATE_BOOK_ACCESS_BACKEND_H
+
+#include <qarray.h>
+
+#include "opimaccessbackend.h"
+#include "oevent.h"
+
+class ODateBookAccessBackend : public OPimAccessBackend<OEvent> {
+public:
+ typedef int UID;
+ ODateBookAccessBackend();
+ ~ODateBookAccessBackend();
+
+ virtual QArray<UID> rawEvents()const = 0;
+ virtual QArray<UID> rawRepeats()const = 0;
+ virtual QArray<UID> nonRepeats() const = 0;
+
+ /**
+ * these two methods are used if you do not implement
+ * effectiveEvents...
+ */
+ virtual OEvent::ValueList directNonRepeats() = 0;
+ virtual OEvent::ValueList directRawRepeats() = 0;
+
+ /* is implemented by default but you can reimplement it*/
+ virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
+ virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
+
+};
+
+#endif
diff --git a/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp
index 71b9441..aaae3b2 100644
--- a/libopie/pim/oevent.cpp
+++ b/libopie/pim/oevent.cpp
@@ -1,55 +1,53 @@
#include <qshared.h>
#include <qpe/palmtopuidgen.h>
#include <qpe/categories.h>
#include "orecur.h"
#include "opimresolver.h"
#include "opimnotifymanager.h"
#include "oevent.h"
-namespace OCalendarHelper {
- static int week( const QDate& date) {
+int OCalendarHelper::week( const QDate& date) {
// Calculates the week this date is in within that
// month. Equals the "row" is is in in the month view
int week = 1;
QDate tmp( date.year(), date.month(), 1 );
if ( date.dayOfWeek() < tmp.dayOfWeek() )
++week;
week += ( date.day() - 1 ) / 7;
return week;
}
- static int occurence( const QDate& date) {
+int OCalendarHelper::ocurrence( const QDate& date) {
// calculates the number of occurrances of this day of the
// week till the given date (e.g 3rd Wednesday of the month)
return ( date.day() - 1 ) / 7 + 1;
}
- static int dayOfWeek( char day ) {
+int OCalendarHelper::dayOfWeek( char day ) {
int dayOfWeek = 1;
char i = ORecur::MON;
while ( !( i & day ) && i <= ORecur::SUN ) {
i <<= 1;
++dayOfWeek;
}
return dayOfWeek;
}
- static int monthDiff( const QDate& first, const QDate& second ) {
+int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
return ( second.year() - first.year() ) * 12 +
second.month() - first.month();
}
-}
struct OEvent::Data : public QShared {
Data() : QShared() {
recur = 0;
manager = 0;
isAllDay = false;
}
~Data() {
delete manager;
delete recur;
}
QString description;
@@ -121,25 +119,26 @@ ORecur OEvent::recurrence()const {
data->recur = new ORecur;
return *data->recur;
}
void OEvent::setRecurrence( const ORecur& rec) {
changeOrModify();
if (data->recur )
(*data->recur) = rec;
else
data->recur = new ORecur( rec );
}
bool OEvent::hasRecurrence()const {
- return data->recur;
+ if (!data->recur ) return false;
+ return data->recur->doesRecur();
}
QString OEvent::note()const {
return data->note;
}
void OEvent::setNote( const QString& note ) {
changeOrModify();
data->note = note;
}
QDateTime OEvent::createdDateTime()const {
return data->created;
}
void OEvent::setCreatedDateTime( const QDateTime& time ) {
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h
index 4489be7..c718e2e 100644
--- a/libopie/pim/oevent.h
+++ b/libopie/pim/oevent.h
@@ -4,38 +4,38 @@
#define OPIE_PIM_EVENT_H
#include <qstring.h>
#include <qdatetime.h>
#include <qvaluelist.h>
#include <qpe/recordfields.h>
#include <qpe/palmtopuidgen.h>
#include "otimezone.h"
#include "opimrecord.h"
-namespace OCalendarHelper {
+struct OCalendarHelper {
/** calculate the week number of the date */
static int week( const QDate& );
/** calculate the occurence of week days since the start of the month */
static int ocurrence( const QDate& );
// returns the dayOfWeek for the *first* day it finds (ignores
// any further days!). Returns 1 (Monday) if there isn't any day found
static int dayOfWeek( char day );
/** returns the diff of month */
static int monthDiff( const QDate& first, const QDate& second );
-}
+};
class OPimNotifyManager;
class ORecur;
class OEvent : public OPimRecord {
public:
typedef QValueList<OEvent> ValueList;
enum RecordFields {
Uid = Qtopia::UID_ID,
Category = Qtopia::CATEGORY_ID,
Description,
Location,
Alarm,
@@ -130,25 +130,25 @@ private:
Data* data;
class Private;
Private* priv;
};
/**
* AN Event can span through multiple days. We split up a multiday eve
*/
class OEffectiveEvent {
public:
- QValueList<OEffectiveEvent> ValueList;
+ typedef QValueList<OEffectiveEvent> ValueList;
enum Position { MidWay, Start, End, StartEnd };
// If we calculate the effective event of a multi-day event
// we have to figure out whether we are at the first day,
// at the end, or anywhere else ("middle"). This is important
// for the start/end times (00:00/23:59)
// MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
// day event
// Start: start time -> 23:59
// End: 00:00 -> end time
// Start | End == StartEnd: for single-day events (default)
// here we draw start time -> end time
OEffectiveEvent();