summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core
authorzecke <zecke>2002-10-20 12:15:51 (UTC)
committer zecke <zecke>2002-10-20 12:15:51 (UTC)
commit82689364fd558ccd28253961204e6b3eb9e32b03 (patch) (side-by-side diff)
treeaec5a649346194aa76aaadd9c7418b700ac4d3d3 /libopie2/opiepim/core
parent7948b5910a098d05f4cc7d0fb14b0f216bf41358 (diff)
downloadopie-82689364fd558ccd28253961204e6b3eb9e32b03.zip
opie-82689364fd558ccd28253961204e6b3eb9e32b03.tar.gz
opie-82689364fd558ccd28253961204e6b3eb9e32b03.tar.bz2
Added ORecur which is a base class for Recurrance extracted from TT Event class
and a widget where you can set the Recurrance This will be used at least in Todolist and Datebook and in the common classes of OTodo and OEvent Fixed the SQL in multiple ways it's summary not description for example
Diffstat (limited to 'libopie2/opiepim/core') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/core/orecur.cpp127
-rw-r--r--libopie2/opiepim/core/orecur.h54
2 files changed, 181 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp
new file mode 100644
index 0000000..6c81f8f
--- a/dev/null
+++ b/libopie2/opiepim/core/orecur.cpp
@@ -0,0 +1,127 @@
+#include <qshared.h>
+
+#include <qtopia/timeconversion.h>
+
+#include "orecur.h"
+
+struct ORecur::Data : public QShared {
+ Data() : QShared() {
+ type = ORecur::NoRepeat;
+ freq = -1;
+ days = 0;
+ pos = 0;
+ create = -1;
+ hasEnd = FALSE;
+ end = 0;
+ }
+ char days; // Q_UINT8 for 8 seven days;)
+ ORecur::RepeatType type;
+ int freq;
+ int pos;
+ bool hasEnd : 1;
+ time_t end;
+ time_t create;
+};
+
+
+ORecur::ORecur() {
+ data = new Data;
+}
+ORecur::ORecur( const ORecur& rec)
+ : data( rec.data )
+{
+ data->ref();
+}
+ORecur::~ORecur() {
+ if ( data->deref() ) {
+ delete data;
+ data = 0l;
+ }
+}
+void ORecur::deref() {
+ if ( data->deref() ) {
+ delete data;
+ data = 0l;
+ }
+}
+bool ORecur::operator==( const ORecur& )const {
+ return false;
+}
+ORecur &ORecur::operator=( const ORecur& re) {
+ re.data->ref();
+ deref();
+ data = re.data;
+
+ return *this;
+}
+ORecur::RepeatType ORecur::type()const{
+ return data->type;
+}
+int ORecur::frequency()const {
+ return data->freq;
+}
+int ORecur::position()const {
+ return data->pos;
+}
+char ORecur::days() const{
+ return data->days;
+}
+bool ORecur::hasEndDate()const {
+ return data->hasEnd;
+}
+QDate ORecur::endDate()const {
+ return TimeConversion::fromUTC( data->end ).date();
+}
+time_t ORecur::endDateUTC()const {
+ return data->end;
+}
+time_t ORecur::createTime()const {
+ return data->create;
+}
+void ORecur::setType( const RepeatType& z) {
+ checkOrModify();
+ data->type = z;
+}
+void ORecur::setFrequency( int freq ) {
+ checkOrModify();
+ data->freq = freq;
+}
+void ORecur::setPosition( int pos ) {
+ checkOrModify();
+ data->pos = pos;
+}
+void ORecur::setDays( char c ) {
+ checkOrModify();
+ data->days = c;
+}
+void ORecur::setEndDate( const QDate& dt) {
+ checkOrModify();
+ data->end = TimeConversion::toUTC( dt );
+}
+void ORecur::setEndDateUTC( time_t t) {
+ checkOrModify();
+ data->end = t;
+}
+void ORecur::setCreateTime( time_t t) {
+ checkOrModify();
+ data->create = t;
+}
+void ORecur::setHasEndDate( bool b) {
+ checkOrModify();
+ data->hasEnd = b;
+}
+void ORecur::checkOrModify() {
+ if ( data->count != 1 ) {
+ data->deref();
+ Data* d2 = new Data;
+ d2->days = data->days;
+ d2->type = data->type;
+ d2->freq = data->freq;
+ d2->pos = data->pos;
+ d2->hasEnd = data->hasEnd;
+ d2->end = data->end;
+ d2->create = data->create;
+ data = d2;
+ }
+}
+
diff --git a/libopie2/opiepim/core/orecur.h b/libopie2/opiepim/core/orecur.h
new file mode 100644
index 0000000..89258f8
--- a/dev/null
+++ b/libopie2/opiepim/core/orecur.h
@@ -0,0 +1,54 @@
+/*
+ * GPL from TT
+ */
+
+#ifndef OPIE_RECUR_H
+#define OPIE_RECUR_H
+
+#include <sys/types.h>
+
+#include <qdatetime.h>
+
+
+
+class ORecur {
+public:
+ enum RepeatType{ NoRepeat = -1, Daily, Weekly, MonthlyDay,
+ MonthlyDate, Yearly };
+ enum Days { MON = 0x01, TUE = 0x02, WED = 0x04, THU = 0x08,
+ FRI = 0x10, SAT = 0x20, SUN = 0x40 };
+ ORecur();
+ ORecur( const ORecur& );
+ ~ORecur();
+
+ ORecur &operator=( const ORecur& );
+ bool operator==(const ORecur& )const;
+ RepeatType type()const;
+ int frequency()const;
+ int position()const;
+ char days()const;
+ bool hasEndDate()const;
+ QDate endDate()const;
+ time_t endDateUTC()const;
+ time_t createTime()const;
+
+ void setType( const RepeatType& );
+ void setFrequency( int freq );
+ void setPosition( int pos );
+ void setDays( char c);
+ void setEndDate( const QDate& dt );
+ void setEndDateUTC( time_t );
+ void setCreateTime( time_t );
+ void setHasEndDate( bool b );
+private:
+ void deref();
+ inline void checkOrModify();
+
+
+ class Data;
+ Data* data;
+ class ORecurPrivate;
+ ORecurPrivate *d;
+};
+
+#endif