-rw-r--r-- | library/datebookdb.cpp | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp index 188d8e1..e4ec2bf 100644 --- a/library/datebookdb.cpp +++ b/library/datebookdb.cpp | |||
@@ -1,161 +1,156 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qasciidict.h> | 21 | #include <qasciidict.h> |
22 | #include <qfile.h> | ||
23 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
24 | #include <qstring.h> | ||
25 | #include <qtextcodec.h> | ||
26 | #include <qtextstream.h> | ||
27 | #include <qtl.h> | 23 | #include <qtl.h> |
28 | 24 | ||
29 | #include <qpe/alarmserver.h> | 25 | #include <qpe/alarmserver.h> |
30 | #include <qpe/global.h> | 26 | #include <qpe/global.h> |
31 | #include "datebookdb.h" | 27 | #include "datebookdb.h" |
32 | #include <qpe/stringutil.h> | 28 | #include <qpe/stringutil.h> |
33 | #include <qpe/timeconversion.h> | ||
34 | 29 | ||
35 | #include <errno.h> | 30 | #include <errno.h> |
36 | #include <stdlib.h> | 31 | #include <stdlib.h> |
37 | 32 | ||
38 | 33 | ||
39 | class DateBookDBPrivate | 34 | class DateBookDBPrivate |
40 | { | 35 | { |
41 | public: | 36 | public: |
42 | bool clean; // indcate whether we need to write to disk... | 37 | bool clean; // indcate whether we need to write to disk... |
43 | }; | 38 | }; |
44 | 39 | ||
45 | 40 | ||
46 | // Helper functions | 41 | // Helper functions |
47 | 42 | ||
48 | static QString dateBookJournalFile() | 43 | static QString dateBookJournalFile() |
49 | { | 44 | { |
50 | QString str = getenv("HOME"); | 45 | QString str = getenv("HOME"); |
51 | return QString( str +"/.caljournal" ); | 46 | return QString( str +"/.caljournal" ); |
52 | } | 47 | } |
53 | 48 | ||
54 | static QString dateBookFilename() | 49 | static QString dateBookFilename() |
55 | { | 50 | { |
56 | return Global::applicationFileName("datebook","datebook.xml"); | 51 | return Global::applicationFileName("datebook","datebook.xml"); |
57 | } | 52 | } |
58 | 53 | ||
59 | /* Calculating the next event of a recuring event is actually | 54 | /* Calculating the next event of a recuring event is actually |
60 | computationally inexpensive, esp. compared to checking each day | 55 | computationally inexpensive, esp. compared to checking each day |
61 | individually. There are bad worse cases for say the 29th of | 56 | individually. There are bad worse cases for say the 29th of |
62 | february or the 31st of some other months. However | 57 | february or the 31st of some other months. However |
63 | these are still bounded */ | 58 | these are still bounded */ |
64 | bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) | 59 | bool nextOccurance(const Event &e, const QDate &from, QDateTime &next) |
65 | { | 60 | { |
66 | // easy checks, first are we too far in the future or too far in the past? | 61 | // easy checks, first are we too far in the future or too far in the past? |
67 | QDate tmpDate; | 62 | QDate tmpDate; |
68 | int freq = e.repeatPattern().frequency; | 63 | int freq = e.repeatPattern().frequency; |
69 | int diff, diff2, a; | 64 | int diff, diff2, a; |
70 | int iday, imonth, iyear; | 65 | int iday, imonth, iyear; |
71 | int dayOfWeek = 0; | 66 | int dayOfWeek = 0; |
72 | int firstOfWeek = 0; | 67 | int firstOfWeek = 0; |
73 | int weekOfMonth; | 68 | int weekOfMonth; |
74 | 69 | ||
75 | 70 | ||
76 | if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from) | 71 | if (e.repeatPattern().hasEndDate && e.repeatPattern().endDate() < from) |
77 | return FALSE; | 72 | return FALSE; |
78 | 73 | ||
79 | if (e.start() >= from) { | 74 | if (e.start() >= from) { |
80 | next = e.start(); | 75 | next = e.start(); |
81 | return TRUE; | 76 | return TRUE; |
82 | } | 77 | } |
83 | 78 | ||
84 | switch ( e.repeatPattern().type ) { | 79 | switch ( e.repeatPattern().type ) { |
85 | case Event::Weekly: | 80 | case Event::Weekly: |
86 | /* weekly is just daily by 7 */ | 81 | /* weekly is just daily by 7 */ |
87 | /* first convert the repeatPattern.Days() mask to the next | 82 | /* first convert the repeatPattern.Days() mask to the next |
88 | day of week valid after from */ | 83 | day of week valid after from */ |
89 | dayOfWeek = from.dayOfWeek(); | 84 | dayOfWeek = from.dayOfWeek(); |
90 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ | 85 | dayOfWeek--; /* we want 0-6, doco for above specs 1-7 */ |
91 | 86 | ||
92 | /* this is done in case freq > 1 and from in week not | 87 | /* this is done in case freq > 1 and from in week not |
93 | for this round */ | 88 | for this round */ |
94 | // firstOfWeek = 0; this is already done at decl. | 89 | // firstOfWeek = 0; this is already done at decl. |
95 | while(!((1 << firstOfWeek) & e.repeatPattern().days)) | 90 | while(!((1 << firstOfWeek) & e.repeatPattern().days)) |
96 | firstOfWeek++; | 91 | firstOfWeek++; |
97 | 92 | ||
98 | 93 | ||
99 | 94 | ||
100 | /* there is at least one 'day', or there would be no event */ | 95 | /* there is at least one 'day', or there would be no event */ |
101 | while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days)) | 96 | while(!((1 << (dayOfWeek % 7)) & e.repeatPattern().days)) |
102 | dayOfWeek++; | 97 | dayOfWeek++; |
103 | 98 | ||
104 | 99 | ||
105 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ | 100 | dayOfWeek = dayOfWeek % 7; /* the actual day of week */ |
106 | dayOfWeek -= e.start().date().dayOfWeek() -1; | 101 | dayOfWeek -= e.start().date().dayOfWeek() -1; |
107 | 102 | ||
108 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ | 103 | firstOfWeek = firstOfWeek % 7; /* the actual first of week */ |
109 | firstOfWeek -= e.start().date().dayOfWeek() -1; | 104 | firstOfWeek -= e.start().date().dayOfWeek() -1; |
110 | 105 | ||
111 | // dayOfWeek may be negitive now | 106 | // dayOfWeek may be negitive now |
112 | // day of week is number of days to add to start day | 107 | // day of week is number of days to add to start day |
113 | 108 | ||
114 | freq *= 7; | 109 | freq *= 7; |
115 | // FALL-THROUGH !!!!! | 110 | // FALL-THROUGH !!!!! |
116 | case Event::Daily: | 111 | case Event::Daily: |
117 | // the add is for the possible fall through from weekly */ | 112 | // the add is for the possible fall through from weekly */ |
118 | if(e.start().date().addDays(dayOfWeek) > from) { | 113 | if(e.start().date().addDays(dayOfWeek) > from) { |
119 | /* first week exception */ | 114 | /* first week exception */ |
120 | next = QDateTime(e.start().date().addDays(dayOfWeek), | 115 | next = QDateTime(e.start().date().addDays(dayOfWeek), |
121 | e.start().time()); | 116 | e.start().time()); |
122 | if ((next.date() > e.repeatPattern().endDate()) | 117 | if ((next.date() > e.repeatPattern().endDate()) |
123 | && e.repeatPattern().hasEndDate) | 118 | && e.repeatPattern().hasEndDate) |
124 | return FALSE; | 119 | return FALSE; |
125 | return TRUE; | 120 | return TRUE; |
126 | } | 121 | } |
127 | /* if from is middle of a non-week */ | 122 | /* if from is middle of a non-week */ |
128 | 123 | ||
129 | diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq; | 124 | diff = e.start().date().addDays(dayOfWeek).daysTo(from) % freq; |
130 | diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq; | 125 | diff2 = e.start().date().addDays(firstOfWeek).daysTo(from) % freq; |
131 | 126 | ||
132 | if(diff != 0) | 127 | if(diff != 0) |
133 | diff = freq - diff; | 128 | diff = freq - diff; |
134 | if(diff2 != 0) | 129 | if(diff2 != 0) |
135 | diff2 = freq - diff2; | 130 | diff2 = freq - diff2; |
136 | diff = QMIN(diff, diff2); | 131 | diff = QMIN(diff, diff2); |
137 | 132 | ||
138 | next = QDateTime(from.addDays(diff), e.start().time()); | 133 | next = QDateTime(from.addDays(diff), e.start().time()); |
139 | if ( (next.date() > e.repeatPattern().endDate()) | 134 | if ( (next.date() > e.repeatPattern().endDate()) |
140 | && e.repeatPattern().hasEndDate ) | 135 | && e.repeatPattern().hasEndDate ) |
141 | return FALSE; | 136 | return FALSE; |
142 | return TRUE; | 137 | return TRUE; |
143 | case Event::MonthlyDay: | 138 | case Event::MonthlyDay: |
144 | iday = from.day(); | 139 | iday = from.day(); |
145 | iyear = from.year(); | 140 | iyear = from.year(); |
146 | imonth = from.month(); | 141 | imonth = from.month(); |
147 | /* find equivelent day of month for this month */ | 142 | /* find equivelent day of month for this month */ |
148 | dayOfWeek = e.start().date().dayOfWeek(); | 143 | dayOfWeek = e.start().date().dayOfWeek(); |
149 | weekOfMonth = (e.start().date().day() - 1) / 7; | 144 | weekOfMonth = (e.start().date().day() - 1) / 7; |
150 | 145 | ||
151 | /* work out when the next valid month is */ | 146 | /* work out when the next valid month is */ |
152 | a = from.year() - e.start().date().year(); | 147 | a = from.year() - e.start().date().year(); |
153 | a *= 12; | 148 | a *= 12; |
154 | a = a + (imonth - e.start().date().month()); | 149 | a = a + (imonth - e.start().date().month()); |
155 | /* a is e.start()monthsFrom(from); */ | 150 | /* a is e.start()monthsFrom(from); */ |
156 | if(a % freq) { | 151 | if(a % freq) { |
157 | a = freq - (a % freq); | 152 | a = freq - (a % freq); |
158 | imonth = from.month() + a; | 153 | imonth = from.month() + a; |
159 | if (imonth > 12) { | 154 | if (imonth > 12) { |
160 | imonth--; | 155 | imonth--; |
161 | iyear += imonth / 12; | 156 | iyear += imonth / 12; |