summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/core/orecur.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/core/orecur.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/core/orecur.cpp76
1 files changed, 71 insertions, 5 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp
index 033f264..5e2da25 100644
--- a/libopie2/opiepim/core/orecur.cpp
+++ b/libopie2/opiepim/core/orecur.cpp
@@ -24,22 +24,26 @@
-- :-=` 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 <time.h>
+#include "orecur.h"
-#include <qshared.h>
+/* OPIE */
+#include <opie2/otimezone.h>
+#include <qpe/timeconversion.h>
-#include <qtopia/timeconversion.h>
+/* QT */
+#include <qshared.h>
-#include <opie2/otimezone.h>
-#include <opie2/orecur.h>
+/* STD */
+#include <time.h>
namespace Opie {
+
struct ORecur::Data : public QShared {
Data() : QShared() {
type = ORecur::NoRepeat;
freq = -1;
days = 0;
pos = 0;
@@ -74,39 +78,51 @@ ORecur::ORecur( const QMap<int, QString>& map )
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) {
if ( *this == re ) return *this;
re.data->ref();
deref();
data = re.data;
return *this;
}
+
+
bool ORecur::doesRecur()const {
return !( type() == NoRepeat );
}
+
+
/*
* we try to be smart here
*
*/
bool ORecur::doesRecur( const QDate& date ) {
/* the day before the recurrance */
@@ -115,23 +131,27 @@ bool ORecur::doesRecur( const QDate& date ) {
QDate recur;
if (!nextOcurrence( da, recur ) )
return false;
return (recur == date);
}
+
+
// FIXME unuglify!
// GPL from Datebookdb.cpp
// FIXME exception list!
bool ORecur::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 ORecur::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;
@@ -398,85 +418,129 @@ bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) {
return FALSE;
return TRUE;
default:
return FALSE;
}
}
+
+
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 data->end;
}
+
+
QDate ORecur::start()const{
return data->start;
}
+
+
QDateTime ORecur::createdDateTime()const {
return data->create;
}
+
+
int ORecur::repetition()const {
return data->rep;
}
+
+
QString ORecur::service()const {
return data->app;
}
+
+
ORecur::ExceptionList& ORecur::exceptions() {
return data->list;
}
+
+
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 = dt;
}
+
+
void ORecur::setCreatedDateTime( const QDateTime& t) {
checkOrModify();
data->create = t;
}
+
+
void ORecur::setHasEndDate( bool b) {
checkOrModify();
data->hasEnd = b;
}
+
+
void ORecur::setRepitition( int rep ) {
checkOrModify();
data->rep = rep;
}
+
+
void ORecur::setService( const QString& app ) {
checkOrModify();
data->app = app;
}
+
+
void ORecur::setStart( const QDate& dt ) {
checkOrModify();
data->start = dt;
}
+
+
void ORecur::checkOrModify() {
if ( data->count != 1 ) {
data->deref();
Data* d2 = new Data;
d2->days = data->days;
d2->type = data->type;
@@ -489,12 +553,14 @@ void ORecur::checkOrModify() {
d2->app = data->app;
d2->list = data->list;
d2->start = data->start;
data = d2;
}
}
+
+
QString ORecur::toString()const {
QString buf;
QMap<int, QString> recMap = toMap();
buf += " rtype=\"";
buf += recMap[ORecur::RType];