Diffstat (limited to 'libopie2/opiepim/core/orecur.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/orecur.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/libopie2/opiepim/core/orecur.cpp b/libopie2/opiepim/core/orecur.cpp index 8c9ad46..f46f22e 100644 --- a/libopie2/opiepim/core/orecur.cpp +++ b/libopie2/opiepim/core/orecur.cpp | |||
@@ -1,132 +1,140 @@ | |||
1 | #include <time.h> | 1 | #include <time.h> |
2 | 2 | ||
3 | #include <qshared.h> | 3 | #include <qshared.h> |
4 | 4 | ||
5 | #include <qtopia/timeconversion.h> | 5 | #include <qtopia/timeconversion.h> |
6 | 6 | ||
7 | #include "otimezone.h" | 7 | #include "otimezone.h" |
8 | #include "orecur.h" | 8 | #include "orecur.h" |
9 | 9 | ||
10 | struct ORecur::Data : public QShared { | 10 | struct ORecur::Data : public QShared { |
11 | Data() : QShared() { | 11 | Data() : QShared() { |
12 | type = ORecur::NoRepeat; | 12 | type = ORecur::NoRepeat; |
13 | freq = -1; | 13 | freq = -1; |
14 | days = 0; | 14 | days = 0; |
15 | pos = 0; | 15 | pos = 0; |
16 | create = QDateTime::currentDateTime(); | 16 | create = QDateTime::currentDateTime(); |
17 | hasEnd = FALSE; | 17 | hasEnd = FALSE; |
18 | end = QDate::currentDate(); | 18 | end = QDate::currentDate(); |
19 | } | 19 | } |
20 | char days; // Q_UINT8 for 8 seven days;) | 20 | char days; // Q_UINT8 for 8 seven days;) |
21 | ORecur::RepeatType type; | 21 | ORecur::RepeatType type; |
22 | int freq; | 22 | int freq; |
23 | int pos; | 23 | int pos; |
24 | bool hasEnd : 1; | 24 | bool hasEnd : 1; |
25 | QDate end; | 25 | QDate end; |
26 | QDateTime create; | 26 | QDateTime create; |
27 | int rep; | 27 | int rep; |
28 | QString app; | 28 | QString app; |
29 | ExceptionList list; | 29 | ExceptionList list; |
30 | QDate start; | 30 | QDate start; |
31 | }; | 31 | }; |
32 | 32 | ||
33 | 33 | ||
34 | ORecur::ORecur() { | 34 | ORecur::ORecur() { |
35 | data = new Data; | 35 | data = new Data; |
36 | } | 36 | } |
37 | |||
38 | ORecur::ORecur( const QMap<int, QString>& map ) | ||
39 | { | ||
40 | ORecur(); | ||
41 | fromMap( map ); | ||
42 | } | ||
43 | |||
44 | |||
37 | ORecur::ORecur( const ORecur& rec) | 45 | ORecur::ORecur( const ORecur& rec) |
38 | : data( rec.data ) | 46 | : data( rec.data ) |
39 | { | 47 | { |
40 | data->ref(); | 48 | data->ref(); |
41 | } | 49 | } |
42 | ORecur::~ORecur() { | 50 | ORecur::~ORecur() { |
43 | if ( data->deref() ) { | 51 | if ( data->deref() ) { |
44 | delete data; | 52 | delete data; |
45 | data = 0l; | 53 | data = 0l; |
46 | } | 54 | } |
47 | } | 55 | } |
48 | void ORecur::deref() { | 56 | void ORecur::deref() { |
49 | if ( data->deref() ) { | 57 | if ( data->deref() ) { |
50 | delete data; | 58 | delete data; |
51 | data = 0l; | 59 | data = 0l; |
52 | } | 60 | } |
53 | } | 61 | } |
54 | bool ORecur::operator==( const ORecur& )const { | 62 | bool ORecur::operator==( const ORecur& )const { |
55 | return false; | 63 | return false; |
56 | } | 64 | } |
57 | ORecur &ORecur::operator=( const ORecur& re) { | 65 | ORecur &ORecur::operator=( const ORecur& re) { |
58 | if ( *this == re ) return *this; | 66 | if ( *this == re ) return *this; |
59 | 67 | ||
60 | re.data->ref(); | 68 | re.data->ref(); |
61 | deref(); | 69 | deref(); |
62 | data = re.data; | 70 | data = re.data; |
63 | 71 | ||
64 | return *this; | 72 | return *this; |
65 | } | 73 | } |
66 | bool ORecur::doesRecur()const { | 74 | bool ORecur::doesRecur()const { |
67 | return !( type() == NoRepeat ); | 75 | return !( type() == NoRepeat ); |
68 | } | 76 | } |
69 | /* | 77 | /* |
70 | * we try to be smart here | 78 | * we try to be smart here |
71 | * | 79 | * |
72 | */ | 80 | */ |
73 | bool ORecur::doesRecur( const QDate& date ) { | 81 | bool ORecur::doesRecur( const QDate& date ) { |
74 | /* the day before the recurrance */ | 82 | /* the day before the recurrance */ |
75 | QDate da = date.addDays(-1); | 83 | QDate da = date.addDays(-1); |
76 | 84 | ||
77 | QDate recur; | 85 | QDate recur; |
78 | if (!nextOcurrence( da, recur ) ) | 86 | if (!nextOcurrence( da, recur ) ) |
79 | return false; | 87 | return false; |
80 | 88 | ||
81 | return (recur == date); | 89 | return (recur == date); |
82 | } | 90 | } |
83 | // FIXME unuglify! | 91 | // FIXME unuglify! |
84 | // GPL from Datebookdb.cpp | 92 | // GPL from Datebookdb.cpp |
85 | // FIXME exception list! | 93 | // FIXME exception list! |
86 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { | 94 | bool ORecur::nextOcurrence( const QDate& from, QDate& next ) { |
87 | bool stillLooking; | 95 | bool stillLooking; |
88 | stillLooking = p_nextOccurrence( from, next ); | 96 | stillLooking = p_nextOccurrence( from, next ); |
89 | while ( stillLooking && data->list.contains(next) ) | 97 | while ( stillLooking && data->list.contains(next) ) |
90 | stillLooking = p_nextOccurrence( next.addDays(1), next ); | 98 | stillLooking = p_nextOccurrence( next.addDays(1), next ); |
91 | 99 | ||
92 | return stillLooking; | 100 | return stillLooking; |
93 | } | 101 | } |
94 | bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { | 102 | bool ORecur::p_nextOccurrence( const QDate& from, QDate& next ) { |
95 | 103 | ||
96 | // easy checks, first are we too far in the future or too far in the past? | 104 | // easy checks, first are we too far in the future or too far in the past? |
97 | QDate tmpDate; | 105 | QDate tmpDate; |
98 | int freq = frequency(); | 106 | int freq = frequency(); |
99 | int diff, diff2, a; | 107 | int diff, diff2, a; |
100 | int iday, imonth, iyear; | 108 | int iday, imonth, iyear; |
101 | int dayOfWeek = 0; | 109 | int dayOfWeek = 0; |
102 | int firstOfWeek = 0; | 110 | int firstOfWeek = 0; |
103 | int weekOfMonth; | 111 | int weekOfMonth; |
104 | 112 | ||
105 | 113 | ||
106 | if (hasEndDate() && endDate() < from) | 114 | if (hasEndDate() && endDate() < from) |
107 | return FALSE; | 115 | return FALSE; |
108 | 116 | ||
109 | if (start() >= from ) { | 117 | if (start() >= from ) { |
110 | next = start(); | 118 | next = start(); |
111 | return TRUE; | 119 | return TRUE; |
112 | } | 120 | } |
113 | 121 | ||
114 | switch ( type() ) { | 122 | switch ( type() ) { |
115 | case Weekly: | 123 | case Weekly: |
116 | /* weekly is just daily by 7 */ | 124 | /* weekly is just daily by 7 */ |
117 | /* first convert the repeatPattern.Days() mask to the next | 125 | /* first convert the repeatPattern.Days() mask to the next |
118 | day of week valid after from */ | 126 | day of week valid after from */ |
119 | dayOfWeek = from.dayOfWeek(); | 127 | dayOfWeek = from.dayOfWeek(); |
120 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ | 128 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ |
121 | 129 | ||
122 | /* this is done in case freq > 1 and from in week not | 130 | /* this is done in case freq > 1 and from in week not |
123 | for this round */ | 131 | for this round */ |
124 | // firstOfWeek = 0; this is already done at decl. | 132 | // firstOfWeek = 0; this is already done at decl. |
125 | while(!((1 << firstOfWeek) & days() )) | 133 | while(!((1 << firstOfWeek) & days() )) |
126 | firstOfWeek++; | 134 | firstOfWeek++; |
127 | 135 | ||
128 | /* there is at least one 'day', or there would be no event */ | 136 | /* there is at least one 'day', or there would be no event */ |
129 | while(!((1 << (dayOfWeek % 7)) & days() )) | 137 | while(!((1 << (dayOfWeek % 7)) & days() )) |
130 | dayOfWeek++; | 138 | dayOfWeek++; |
131 | 139 | ||
132 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ | 140 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ |