-rw-r--r-- | libkcal/calendar.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 88351eb..dcfee5d 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,254 +1,255 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | 33 | #include "syncdefines.h" |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | Calendar::Calendar() | 37 | Calendar::Calendar() |
38 | { | 38 | { |
39 | 39 | ||
40 | init(); | 40 | init(); |
41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); | 41 | setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); |
42 | } | 42 | } |
43 | 43 | ||
44 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
45 | { | 45 | { |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mModified = false; | 56 | mModified = false; |
57 | 57 | ||
58 | // Setup default filter, which does nothing | 58 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 59 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 60 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 61 | mFilter->setEnabled(false); |
62 | 62 | ||
63 | // initialize random numbers. This is a hack, and not | 63 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 64 | // even that good of one at that. |
65 | // srandom(time(0)); | 65 | // srandom(time(0)); |
66 | 66 | ||
67 | // user information... | 67 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 68 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 69 | setEmail(i18n("unknown@nowhere")); |
70 | 70 | ||
71 | #if 0 | 71 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 72 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 75 | extern long int timezone; |
76 | struct tm *now; | 76 | struct tm *now; |
77 | time_t curtime; | 77 | time_t curtime; |
78 | curtime = time(0); | 78 | curtime = time(0); |
79 | now = localtime(&curtime); | 79 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 80 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 81 | if (now->tm_isdst) |
82 | hourOff += 1; | 82 | hourOff += 1; |
83 | QString tzStr; | 83 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 84 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 85 | hourOff, |
86 | abs((timezone / 60) % 60)); | 86 | abs((timezone / 60) % 60)); |
87 | 87 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 88 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 89 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 90 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 91 | } else { |
92 | tzStr = tmpStr; | 92 | tzStr = tmpStr; |
93 | } | 93 | } |
94 | 94 | ||
95 | // if daylight savings has changed since last load time, we need | 95 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 96 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 97 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 98 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 99 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 101 | } |
102 | 102 | ||
103 | setTimeZone(tzStr); | 103 | setTimeZone(tzStr); |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | // KOPrefs::instance()->writeConfig(); | 106 | // KOPrefs::instance()->writeConfig(); |
107 | } | 107 | } |
108 | 108 | ||
109 | Calendar::~Calendar() | 109 | Calendar::~Calendar() |
110 | { | 110 | { |
111 | delete mDefaultFilter; | 111 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | 112 | if ( mUndoIncidence ) |
113 | delete mUndoIncidence; | 113 | delete mUndoIncidence; |
114 | } | 114 | } |
115 | 115 | ||
116 | const QString &Calendar::getOwner() const | 116 | const QString &Calendar::getOwner() const |
117 | { | 117 | { |
118 | return mOwner; | 118 | return mOwner; |
119 | } | 119 | } |
120 | 120 | ||
121 | bool Calendar::undoDeleteIncidence() | 121 | bool Calendar::undoDeleteIncidence() |
122 | { | 122 | { |
123 | if (!mUndoIncidence) | 123 | if (!mUndoIncidence) |
124 | return false; | 124 | return false; |
125 | addIncidence(mUndoIncidence); | 125 | addIncidence(mUndoIncidence); |
126 | mUndoIncidence = 0; | 126 | mUndoIncidence = 0; |
127 | return true; | ||
127 | } | 128 | } |
128 | void Calendar::setOwner(const QString &os) | 129 | void Calendar::setOwner(const QString &os) |
129 | { | 130 | { |
130 | int i; | 131 | int i; |
131 | mOwner = os; | 132 | mOwner = os; |
132 | i = mOwner.find(','); | 133 | i = mOwner.find(','); |
133 | if (i != -1) | 134 | if (i != -1) |
134 | mOwner = mOwner.left(i); | 135 | mOwner = mOwner.left(i); |
135 | 136 | ||
136 | setModified( true ); | 137 | setModified( true ); |
137 | } | 138 | } |
138 | 139 | ||
139 | void Calendar::setTimeZone(const QString & tz) | 140 | void Calendar::setTimeZone(const QString & tz) |
140 | { | 141 | { |
141 | bool neg = FALSE; | 142 | bool neg = FALSE; |
142 | int hours, minutes; | 143 | int hours, minutes; |
143 | QString tmpStr(tz); | 144 | QString tmpStr(tz); |
144 | 145 | ||
145 | if (tmpStr.left(1) == "-") | 146 | if (tmpStr.left(1) == "-") |
146 | neg = TRUE; | 147 | neg = TRUE; |
147 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 148 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
148 | tmpStr.remove(0, 1); | 149 | tmpStr.remove(0, 1); |
149 | hours = tmpStr.left(2).toInt(); | 150 | hours = tmpStr.left(2).toInt(); |
150 | if (tmpStr.length() > 2) | 151 | if (tmpStr.length() > 2) |
151 | minutes = tmpStr.right(2).toInt(); | 152 | minutes = tmpStr.right(2).toInt(); |
152 | else | 153 | else |
153 | minutes = 0; | 154 | minutes = 0; |
154 | mTimeZone = (60*hours+minutes); | 155 | mTimeZone = (60*hours+minutes); |
155 | if (neg) | 156 | if (neg) |
156 | mTimeZone = -mTimeZone; | 157 | mTimeZone = -mTimeZone; |
157 | mLocalTime = false; | 158 | mLocalTime = false; |
158 | 159 | ||
159 | setModified( true ); | 160 | setModified( true ); |
160 | } | 161 | } |
161 | 162 | ||
162 | QString Calendar::getTimeZoneStr() const | 163 | QString Calendar::getTimeZoneStr() const |
163 | { | 164 | { |
164 | if (mLocalTime) | 165 | if (mLocalTime) |
165 | return ""; | 166 | return ""; |
166 | QString tmpStr; | 167 | QString tmpStr; |
167 | int hours = abs(mTimeZone / 60); | 168 | int hours = abs(mTimeZone / 60); |
168 | int minutes = abs(mTimeZone % 60); | 169 | int minutes = abs(mTimeZone % 60); |
169 | bool neg = mTimeZone < 0; | 170 | bool neg = mTimeZone < 0; |
170 | 171 | ||
171 | tmpStr.sprintf("%c%.2d%.2d", | 172 | tmpStr.sprintf("%c%.2d%.2d", |
172 | (neg ? '-' : '+'), | 173 | (neg ? '-' : '+'), |
173 | hours, minutes); | 174 | hours, minutes); |
174 | return tmpStr; | 175 | return tmpStr; |
175 | } | 176 | } |
176 | 177 | ||
177 | void Calendar::setTimeZone(int tz) | 178 | void Calendar::setTimeZone(int tz) |
178 | { | 179 | { |
179 | mTimeZone = tz; | 180 | mTimeZone = tz; |
180 | mLocalTime = false; | 181 | mLocalTime = false; |
181 | 182 | ||
182 | setModified( true ); | 183 | setModified( true ); |
183 | } | 184 | } |
184 | 185 | ||
185 | int Calendar::getTimeZone() const | 186 | int Calendar::getTimeZone() const |
186 | { | 187 | { |
187 | return mTimeZone; | 188 | return mTimeZone; |
188 | } | 189 | } |
189 | 190 | ||
190 | void Calendar::setTimeZoneId(const QString &id) | 191 | void Calendar::setTimeZoneId(const QString &id) |
191 | { | 192 | { |
192 | mTimeZoneId = id; | 193 | mTimeZoneId = id; |
193 | mLocalTime = false; | 194 | mLocalTime = false; |
194 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 195 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
195 | if ( mTimeZone > 1000) | 196 | if ( mTimeZone > 1000) |
196 | setLocalTime(); | 197 | setLocalTime(); |
197 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 198 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
198 | setModified( true ); | 199 | setModified( true ); |
199 | } | 200 | } |
200 | 201 | ||
201 | QString Calendar::timeZoneId() const | 202 | QString Calendar::timeZoneId() const |
202 | { | 203 | { |
203 | return mTimeZoneId; | 204 | return mTimeZoneId; |
204 | } | 205 | } |
205 | 206 | ||
206 | void Calendar::setLocalTime() | 207 | void Calendar::setLocalTime() |
207 | { | 208 | { |
208 | //qDebug("Calendar::setLocalTime() "); | 209 | //qDebug("Calendar::setLocalTime() "); |
209 | mLocalTime = true; | 210 | mLocalTime = true; |
210 | mTimeZone = 0; | 211 | mTimeZone = 0; |
211 | mTimeZoneId = ""; | 212 | mTimeZoneId = ""; |
212 | 213 | ||
213 | setModified( true ); | 214 | setModified( true ); |
214 | } | 215 | } |
215 | 216 | ||
216 | bool Calendar::isLocalTime() const | 217 | bool Calendar::isLocalTime() const |
217 | { | 218 | { |
218 | return mLocalTime; | 219 | return mLocalTime; |
219 | } | 220 | } |
220 | 221 | ||
221 | const QString &Calendar::getEmail() | 222 | const QString &Calendar::getEmail() |
222 | { | 223 | { |
223 | return mOwnerEmail; | 224 | return mOwnerEmail; |
224 | } | 225 | } |
225 | 226 | ||
226 | void Calendar::setEmail(const QString &e) | 227 | void Calendar::setEmail(const QString &e) |
227 | { | 228 | { |
228 | mOwnerEmail = e; | 229 | mOwnerEmail = e; |
229 | 230 | ||
230 | setModified( true ); | 231 | setModified( true ); |
231 | } | 232 | } |
232 | 233 | ||
233 | void Calendar::setFilter(CalFilter *filter) | 234 | void Calendar::setFilter(CalFilter *filter) |
234 | { | 235 | { |
235 | mFilter = filter; | 236 | mFilter = filter; |
236 | } | 237 | } |
237 | 238 | ||
238 | CalFilter *Calendar::filter() | 239 | CalFilter *Calendar::filter() |
239 | { | 240 | { |
240 | return mFilter; | 241 | return mFilter; |
241 | } | 242 | } |
242 | 243 | ||
243 | QPtrList<Incidence> Calendar::incidences() | 244 | QPtrList<Incidence> Calendar::incidences() |
244 | { | 245 | { |
245 | QPtrList<Incidence> incidences; | 246 | QPtrList<Incidence> incidences; |
246 | 247 | ||
247 | Incidence *i; | 248 | Incidence *i; |
248 | 249 | ||
249 | QPtrList<Event> e = events(); | 250 | QPtrList<Event> e = events(); |
250 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 251 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
251 | 252 | ||
252 | QPtrList<Todo> t = todos(); | 253 | QPtrList<Todo> t = todos(); |
253 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 254 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
254 | 255 | ||