summaryrefslogtreecommitdiff
path: root/libopie
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
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') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/libopie.pro4
-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.cpp57
-rw-r--r--libopie/pim/oevent.h6
7 files changed, 292 insertions, 32 deletions
diff --git a/libopie/libopie.pro b/libopie/libopie.pro
index 2b843c1..70399ea 100644
--- a/libopie/libopie.pro
+++ b/libopie/libopie.pro
@@ -38,6 +38,8 @@ HEADERS = ofontmenu.h \
pim/opimresolver.h \
pim/oevent.h \
pim/otimezone.h \
+ pim/odatebookaccess.h \
+ pim/odatebookaccessbackend.h \
orecurrancewidget.h \
oticker.h
# pim/otodoaccesssql.h \
@@ -75,6 +77,8 @@ SOURCES = ofontmenu.cc \
pim/opimresolver.cpp \
pim/oevent.cpp \
pim/otimezone.cpp \
+ pim/odatebookaccess.cpp \
+ pim/odatebookaccessbackend.cpp \
orecurrancewidget.cpp \
oticker.cpp
# pim/otodoaccesssql.cpp \
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
@@ -9,37 +9,35 @@
#include "oevent.h"
-namespace OCalendarHelper {
- static int 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;
+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;
+ week += ( date.day() - 1 ) / 7;
- return week;
- }
- static int occurence( 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 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 ) {
- return ( second.year() - first.year() ) * 12 +
- second.month() - first.month();
+ return week;
+}
+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;
+}
+int OCalendarHelper::dayOfWeek( char day ) {
+ int dayOfWeek = 1;
+ char i = ORecur::MON;
+ while ( !( i & day ) && i <= ORecur::SUN ) {
+ i <<= 1;
+ ++dayOfWeek;
}
+ return dayOfWeek;
+}
+int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
+ return ( second.year() - first.year() ) * 12 +
+ second.month() - first.month();
}
struct OEvent::Data : public QShared {
@@ -130,7 +128,8 @@ void OEvent::setRecurrence( const ORecur& rec) {
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;
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
@@ -13,7 +13,7 @@
#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 */
@@ -26,7 +26,7 @@ namespace OCalendarHelper {
/** returns the diff of month */
static int monthDiff( const QDate& first, const QDate& second );
-}
+};
class OPimNotifyManager;
class ORecur;
@@ -139,7 +139,7 @@ private:
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,