author | zautrix <zautrix> | 2004-10-18 09:08:13 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-18 09:08:13 (UTC) |
commit | 56990d318b15eacf7d3cc7425ab62f68da099ddf (patch) (unidiff) | |
tree | b2f021bd75bc6a08fa8fc51a07ce1755b8e4a95e /libkcal | |
parent | 1712d92ea25b220273859d985bc7211fa7a97a39 (diff) | |
download | kdepimpi-56990d318b15eacf7d3cc7425ab62f68da099ddf.zip kdepimpi-56990d318b15eacf7d3cc7425ab62f68da099ddf.tar.gz kdepimpi-56990d318b15eacf7d3cc7425ab62f68da099ddf.tar.bz2 |
fix of tmp file path for desktop version
-rw-r--r-- | libkcal/phoneformat.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 101db57..900fc04 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,620 +1,620 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@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 <qdatetime.h> | 22 | #include <qdatetime.h> |
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qmessagebox.h> | 27 | #include <qmessagebox.h> |
28 | #include <qclipboard.h> | 28 | #include <qclipboard.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qtextcodec.h> | 31 | #include <qtextcodec.h> |
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qlabel.h> | 33 | #include <qlabel.h> |
34 | 34 | ||
35 | #include <kdebug.h> | 35 | #include <kdebug.h> |
36 | #include <klocale.h> | 36 | #include <klocale.h> |
37 | #include <kglobal.h> | 37 | #include <kglobal.h> |
38 | #include <kmessagebox.h> | 38 | #include <kmessagebox.h> |
39 | #include <phoneaccess.h> | 39 | #include <phoneaccess.h> |
40 | 40 | ||
41 | #include "calendar.h" | 41 | #include "calendar.h" |
42 | #include "alarm.h" | 42 | #include "alarm.h" |
43 | #include "recurrence.h" | 43 | #include "recurrence.h" |
44 | #include "calendarlocal.h" | 44 | #include "calendarlocal.h" |
45 | 45 | ||
46 | #include "phoneformat.h" | 46 | #include "phoneformat.h" |
47 | #include "syncdefines.h" | 47 | #include "syncdefines.h" |
48 | 48 | ||
49 | using namespace KCal; | 49 | using namespace KCal; |
50 | class PhoneParser : public QObject | 50 | class PhoneParser : public QObject |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | PhoneParser( ) { | 53 | PhoneParser( ) { |
54 | ; | 54 | ; |
55 | } | 55 | } |
56 | 56 | ||
57 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 57 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
58 | { | 58 | { |
59 | QString datestr; | 59 | QString datestr; |
60 | QString timestr; | 60 | QString timestr; |
61 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 61 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
62 | QDateTime dt; | 62 | QDateTime dt; |
63 | if (useTZ) | 63 | if (useTZ) |
64 | dt = dti.addSecs ( -(offset*60)); | 64 | dt = dti.addSecs ( -(offset*60)); |
65 | else | 65 | else |
66 | dt = dti; | 66 | dt = dti; |
67 | if(dt.date().isValid()){ | 67 | if(dt.date().isValid()){ |
68 | const QDate& date = dt.date(); | 68 | const QDate& date = dt.date(); |
69 | datestr.sprintf("%04d%02d%02d", | 69 | datestr.sprintf("%04d%02d%02d", |
70 | date.year(), date.month(), date.day()); | 70 | date.year(), date.month(), date.day()); |
71 | } | 71 | } |
72 | if(dt.time().isValid()){ | 72 | if(dt.time().isValid()){ |
73 | const QTime& time = dt.time(); | 73 | const QTime& time = dt.time(); |
74 | timestr.sprintf("T%02d%02d%02d", | 74 | timestr.sprintf("T%02d%02d%02d", |
75 | time.hour(), time.minute(), time.second()); | 75 | time.hour(), time.minute(), time.second()); |
76 | } | 76 | } |
77 | return datestr + timestr; | 77 | return datestr + timestr; |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
81 | }; | 81 | }; |
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 85 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
86 | { | 86 | { |
87 | mProfileName = profileName; | 87 | mProfileName = profileName; |
88 | PhoneAccess::writeConfig( device, connection, model ); | 88 | PhoneAccess::writeConfig( device, connection, model ); |
89 | } | 89 | } |
90 | 90 | ||
91 | PhoneFormat::~PhoneFormat() | 91 | PhoneFormat::~PhoneFormat() |
92 | { | 92 | { |
93 | } | 93 | } |
94 | 94 | ||
95 | #if 0 | 95 | #if 0 |
96 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 96 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
97 | { | 97 | { |
98 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 98 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
99 | s->ConfigNum = 1; | 99 | s->ConfigNum = 1; |
100 | GSM_Config *cfg = &s->Config[0]; | 100 | GSM_Config *cfg = &s->Config[0]; |
101 | if ( ! mConnection.isEmpty() ) { | 101 | if ( ! mConnection.isEmpty() ) { |
102 | cfg->Connection = strdup(mConnection.latin1()); | 102 | cfg->Connection = strdup(mConnection.latin1()); |
103 | cfg->DefaultConnection = false; | 103 | cfg->DefaultConnection = false; |
104 | qDebug("Connection set %s ", cfg->Connection ); | 104 | qDebug("Connection set %s ", cfg->Connection ); |
105 | 105 | ||
106 | } | 106 | } |
107 | if ( ! mDevice.isEmpty() ) { | 107 | if ( ! mDevice.isEmpty() ) { |
108 | cfg->Device = strdup(mDevice.latin1()); | 108 | cfg->Device = strdup(mDevice.latin1()); |
109 | cfg->DefaultDevice = false; | 109 | cfg->DefaultDevice = false; |
110 | qDebug("Device set %s ", cfg->Device); | 110 | qDebug("Device set %s ", cfg->Device); |
111 | 111 | ||
112 | } | 112 | } |
113 | if ( ! mModel.isEmpty() ) { | 113 | if ( ! mModel.isEmpty() ) { |
114 | strcpy(cfg->Model,mModel.latin1() ); | 114 | strcpy(cfg->Model,mModel.latin1() ); |
115 | cfg->DefaultModel = false; | 115 | cfg->DefaultModel = false; |
116 | qDebug("Model set %s ",cfg->Model ); | 116 | qDebug("Model set %s ",cfg->Model ); |
117 | } | 117 | } |
118 | int error=GSM_InitConnection(s,3); | 118 | int error=GSM_InitConnection(s,3); |
119 | return error; | 119 | return error; |
120 | } | 120 | } |
121 | #endif | 121 | #endif |
122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 122 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
123 | { | 123 | { |
124 | QStringList attList; | 124 | QStringList attList; |
125 | if ( todo->hasDueDate() ) | 125 | if ( todo->hasDueDate() ) |
126 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 126 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
127 | attList << todo->summary(); | 127 | attList << todo->summary(); |
128 | QString completedString = "no"; | 128 | QString completedString = "no"; |
129 | if ( todo->isCompleted() ) | 129 | if ( todo->isCompleted() ) |
130 | completedString = "yes"; | 130 | completedString = "yes"; |
131 | attList << completedString; | 131 | attList << completedString; |
132 | int prio = todo->priority(); | 132 | int prio = todo->priority(); |
133 | if( prio == 2 ) prio = 1; | 133 | if( prio == 2 ) prio = 1; |
134 | if (prio == 4 ) prio = 5 ; | 134 | if (prio == 4 ) prio = 5 ; |
135 | attList << QString::number( prio ); | 135 | attList << QString::number( prio ); |
136 | QString alarmString = "na"; | 136 | QString alarmString = "na"; |
137 | Alarm *alarm; | 137 | Alarm *alarm; |
138 | if ( todo->alarms().count() > 0 ) { | 138 | if ( todo->alarms().count() > 0 ) { |
139 | alarm = todo->alarms().first(); | 139 | alarm = todo->alarms().first(); |
140 | if ( alarm->enabled() ) { | 140 | if ( alarm->enabled() ) { |
141 | alarmString = QString::number(alarm->offset() ); | 141 | alarmString = QString::number(alarm->offset() ); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | attList << alarmString; | 144 | attList << alarmString; |
145 | attList << todo->categoriesStr(); | 145 | attList << todo->categoriesStr(); |
146 | attList << todo->secrecyStr(); | 146 | attList << todo->secrecyStr(); |
147 | return PhoneFormat::getCsum(attList ); | 147 | return PhoneFormat::getCsum(attList ); |
148 | 148 | ||
149 | } | 149 | } |
150 | ulong PhoneFormat::getCsumEvent( Event* event ) | 150 | ulong PhoneFormat::getCsumEvent( Event* event ) |
151 | { | 151 | { |
152 | QStringList attList; | 152 | QStringList attList; |
153 | attList << PhoneParser::dtToString ( event->dtStart() ); | 153 | attList << PhoneParser::dtToString ( event->dtStart() ); |
154 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 154 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
155 | attList << event->summary(); | 155 | attList << event->summary(); |
156 | attList << event->location(); | 156 | attList << event->location(); |
157 | QString alarmString = "na"; | 157 | QString alarmString = "na"; |
158 | Alarm *alarm; | 158 | Alarm *alarm; |
159 | if ( event->alarms().count() > 0 ) { | 159 | if ( event->alarms().count() > 0 ) { |
160 | alarm = event->alarms().first(); | 160 | alarm = event->alarms().first(); |
161 | if ( alarm->enabled() ) { | 161 | if ( alarm->enabled() ) { |
162 | alarmString = QString::number( alarm->offset() ); | 162 | alarmString = QString::number( alarm->offset() ); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | attList << alarmString; | 165 | attList << alarmString; |
166 | Recurrence* rec = event->recurrence(); | 166 | Recurrence* rec = event->recurrence(); |
167 | QStringList list; | 167 | QStringList list; |
168 | bool writeEndDate = false; | 168 | bool writeEndDate = false; |
169 | switch ( rec->doesRecur() ) | 169 | switch ( rec->doesRecur() ) |
170 | { | 170 | { |
171 | case Recurrence::rDaily: // 0 | 171 | case Recurrence::rDaily: // 0 |
172 | list.append( "0" ); | 172 | list.append( "0" ); |
173 | list.append( QString::number( rec->frequency() ));//12 | 173 | list.append( QString::number( rec->frequency() ));//12 |
174 | list.append( "0" ); | 174 | list.append( "0" ); |
175 | list.append( "0" ); | 175 | list.append( "0" ); |
176 | writeEndDate = true; | 176 | writeEndDate = true; |
177 | break; | 177 | break; |
178 | case Recurrence::rWeekly:// 1 | 178 | case Recurrence::rWeekly:// 1 |
179 | list.append( "1" ); | 179 | list.append( "1" ); |
180 | list.append( QString::number( rec->frequency()) );//12 | 180 | list.append( QString::number( rec->frequency()) );//12 |
181 | list.append( "0" ); | 181 | list.append( "0" ); |
182 | { | 182 | { |
183 | int days = 0; | 183 | int days = 0; |
184 | QBitArray weekDays = rec->days(); | 184 | QBitArray weekDays = rec->days(); |
185 | int i; | 185 | int i; |
186 | for( i = 1; i <= 7; ++i ) { | 186 | for( i = 1; i <= 7; ++i ) { |
187 | if ( weekDays[i-1] ) { | 187 | if ( weekDays[i-1] ) { |
188 | days += 1 << (i-1); | 188 | days += 1 << (i-1); |
189 | } | 189 | } |
190 | } | 190 | } |
191 | list.append( QString::number( days ) ); | 191 | list.append( QString::number( days ) ); |
192 | } | 192 | } |
193 | //pending weekdays | 193 | //pending weekdays |
194 | writeEndDate = true; | 194 | writeEndDate = true; |
195 | 195 | ||
196 | break; | 196 | break; |
197 | case Recurrence::rMonthlyPos:// 2 | 197 | case Recurrence::rMonthlyPos:// 2 |
198 | list.append( "2" ); | 198 | list.append( "2" ); |
199 | list.append( QString::number( rec->frequency()) );//12 | 199 | list.append( QString::number( rec->frequency()) );//12 |
200 | 200 | ||
201 | writeEndDate = true; | 201 | writeEndDate = true; |
202 | { | 202 | { |
203 | int count = 1; | 203 | int count = 1; |
204 | QPtrList<Recurrence::rMonthPos> rmp; | 204 | QPtrList<Recurrence::rMonthPos> rmp; |
205 | rmp = rec->monthPositions(); | 205 | rmp = rec->monthPositions(); |
206 | if ( rmp.first()->negative ) | 206 | if ( rmp.first()->negative ) |
207 | count = 5 - rmp.first()->rPos - 1; | 207 | count = 5 - rmp.first()->rPos - 1; |
208 | else | 208 | else |
209 | count = rmp.first()->rPos - 1; | 209 | count = rmp.first()->rPos - 1; |
210 | list.append( QString::number( count ) ); | 210 | list.append( QString::number( count ) ); |
211 | 211 | ||
212 | } | 212 | } |
213 | 213 | ||
214 | list.append( "0" ); | 214 | list.append( "0" ); |
215 | break; | 215 | break; |
216 | case Recurrence::rMonthlyDay:// 3 | 216 | case Recurrence::rMonthlyDay:// 3 |
217 | list.append( "3" ); | 217 | list.append( "3" ); |
218 | list.append( QString::number( rec->frequency()) );//12 | 218 | list.append( QString::number( rec->frequency()) );//12 |
219 | list.append( "0" ); | 219 | list.append( "0" ); |
220 | list.append( "0" ); | 220 | list.append( "0" ); |
221 | writeEndDate = true; | 221 | writeEndDate = true; |
222 | break; | 222 | break; |
223 | case Recurrence::rYearlyMonth://4 | 223 | case Recurrence::rYearlyMonth://4 |
224 | list.append( "4" ); | 224 | list.append( "4" ); |
225 | list.append( QString::number( rec->frequency()) );//12 | 225 | list.append( QString::number( rec->frequency()) );//12 |
226 | list.append( "0" ); | 226 | list.append( "0" ); |
227 | list.append( "0" ); | 227 | list.append( "0" ); |
228 | writeEndDate = true; | 228 | writeEndDate = true; |
229 | break; | 229 | break; |
230 | 230 | ||
231 | default: | 231 | default: |
232 | list.append( "255" ); | 232 | list.append( "255" ); |
233 | list.append( QString() ); | 233 | list.append( QString() ); |
234 | list.append( "0" ); | 234 | list.append( "0" ); |
235 | list.append( QString() ); | 235 | list.append( QString() ); |
236 | list.append( "0" ); | 236 | list.append( "0" ); |
237 | list.append( "20991231T000000" ); | 237 | list.append( "20991231T000000" ); |
238 | break; | 238 | break; |
239 | } | 239 | } |
240 | if ( writeEndDate ) { | 240 | if ( writeEndDate ) { |
241 | 241 | ||
242 | if ( rec->endDate().isValid() ) { // 15 + 16 | 242 | if ( rec->endDate().isValid() ) { // 15 + 16 |
243 | list.append( "1" ); | 243 | list.append( "1" ); |
244 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 244 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
245 | } else { | 245 | } else { |
246 | list.append( "0" ); | 246 | list.append( "0" ); |
247 | list.append( "20991231T000000" ); | 247 | list.append( "20991231T000000" ); |
248 | } | 248 | } |
249 | 249 | ||
250 | } | 250 | } |
251 | attList << list.join(""); | 251 | attList << list.join(""); |
252 | attList << event->categoriesStr(); | 252 | attList << event->categoriesStr(); |
253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); | 253 | //qDebug("csum cat %s", event->categoriesStr().latin1()); |
254 | 254 | ||
255 | attList << event->secrecyStr(); | 255 | attList << event->secrecyStr(); |
256 | return PhoneFormat::getCsum(attList ); | 256 | return PhoneFormat::getCsum(attList ); |
257 | } | 257 | } |
258 | ulong PhoneFormat::getCsum( const QStringList & attList) | 258 | ulong PhoneFormat::getCsum( const QStringList & attList) |
259 | { | 259 | { |
260 | int max = attList.count(); | 260 | int max = attList.count(); |
261 | ulong cSum = 0; | 261 | ulong cSum = 0; |
262 | int j,k,i; | 262 | int j,k,i; |
263 | int add; | 263 | int add; |
264 | for ( i = 0; i < max ; ++i ) { | 264 | for ( i = 0; i < max ; ++i ) { |
265 | QString s = attList[i]; | 265 | QString s = attList[i]; |
266 | if ( ! s.isEmpty() ){ | 266 | if ( ! s.isEmpty() ){ |
267 | j = s.length(); | 267 | j = s.length(); |
268 | for ( k = 0; k < j; ++k ) { | 268 | for ( k = 0; k < j; ++k ) { |
269 | int mul = k +1; | 269 | int mul = k +1; |
270 | add = s[k].unicode (); | 270 | add = s[k].unicode (); |
271 | if ( k < 16 ) | 271 | if ( k < 16 ) |
272 | mul = mul * mul; | 272 | mul = mul * mul; |
273 | int ii = i+1; | 273 | int ii = i+1; |
274 | add = add * mul *ii*ii*ii; | 274 | add = add * mul *ii*ii*ii; |
275 | cSum += add; | 275 | cSum += add; |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | //QString dump = attList.join(","); | 280 | //QString dump = attList.join(","); |
281 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 281 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
282 | 282 | ||
283 | return cSum; | 283 | return cSum; |
284 | 284 | ||
285 | } | 285 | } |
286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 286 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
287 | #include <stdlib.h> | 287 | #include <stdlib.h> |
288 | #define DEBUGMODE false | 288 | #define DEBUGMODE false |
289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 289 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
290 | { | 290 | { |
291 | 291 | ||
292 | QString fileName; | 292 | QString fileName; |
293 | #ifdef _WIN32_ | 293 | #ifdef DESKTOP_VERSION |
294 | fileName = locateLocal("tmp", "phonefile.vcs"); | 294 | fileName = locateLocal("tmp", "phonefile.vcs"); |
295 | #else | 295 | #else |
296 | fileName = "/tmp/phonefile.vcs"; | 296 | fileName = "/tmp/phonefile.vcs"; |
297 | #endif | 297 | #endif |
298 | QString command; | 298 | QString command; |
299 | if ( ! PhoneAccess::readFromPhone( fileName )) { | 299 | if ( ! PhoneAccess::readFromPhone( fileName )) { |
300 | return false; | 300 | return false; |
301 | } | 301 | } |
302 | VCalFormat vfload; | 302 | VCalFormat vfload; |
303 | vfload.setLocalTime ( true ); | 303 | vfload.setLocalTime ( true ); |
304 | qDebug("loading file ..."); | 304 | qDebug("loading file ..."); |
305 | 305 | ||
306 | if ( ! vfload.load( calendar, fileName ) ) | 306 | if ( ! vfload.load( calendar, fileName ) ) |
307 | return false; | 307 | return false; |
308 | QPtrList<Event> er = calendar->rawEvents(); | 308 | QPtrList<Event> er = calendar->rawEvents(); |
309 | Event* ev = er.first(); | 309 | Event* ev = er.first(); |
310 | qDebug("reading events... "); | 310 | qDebug("reading events... "); |
311 | while ( ev ) { | 311 | while ( ev ) { |
312 | QStringList cat = ev->categories(); | 312 | QStringList cat = ev->categories(); |
313 | if ( cat.contains( "MeetingDEF" )) { | 313 | if ( cat.contains( "MeetingDEF" )) { |
314 | ev->setCategories( QStringList() ); | 314 | ev->setCategories( QStringList() ); |
315 | } else | 315 | } else |
316 | if ( cat.contains( "Birthday" )) { | 316 | if ( cat.contains( "Birthday" )) { |
317 | ev->setFloats( true ); | 317 | ev->setFloats( true ); |
318 | QDate da = ev->dtStart().date(); | 318 | QDate da = ev->dtStart().date(); |
319 | ev->setDtStart( QDateTime( da) ); | 319 | ev->setDtStart( QDateTime( da) ); |
320 | ev->setDtEnd( QDateTime( da.addDays(1)) ); | 320 | ev->setDtEnd( QDateTime( da.addDays(1)) ); |
321 | 321 | ||
322 | } | 322 | } |
323 | uint cSum; | 323 | uint cSum; |
324 | cSum = PhoneFormat::getCsumEvent( ev ); | 324 | cSum = PhoneFormat::getCsumEvent( ev ); |
325 | int id = ev->pilotId(); | 325 | int id = ev->pilotId(); |
326 | Event *event; | 326 | Event *event; |
327 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 327 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
328 | if ( event ) { | 328 | if ( event ) { |
329 | event = (Event*)event->clone(); | 329 | event = (Event*)event->clone(); |
330 | copyEvent( event, ev ); | 330 | copyEvent( event, ev ); |
331 | calendar->deleteEvent( ev ); | 331 | calendar->deleteEvent( ev ); |
332 | calendar->addEvent( event); | 332 | calendar->addEvent( event); |
333 | } | 333 | } |
334 | else | 334 | else |
335 | event = ev; | 335 | event = ev; |
336 | event->setCsum( mProfileName, QString::number( cSum )); | 336 | event->setCsum( mProfileName, QString::number( cSum )); |
337 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 337 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
338 | event->setID( mProfileName,QString::number( id ) ); | 338 | event->setID( mProfileName,QString::number( id ) ); |
339 | ev = er.next(); | 339 | ev = er.next(); |
340 | } | 340 | } |
341 | { | 341 | { |
342 | qDebug("reading todos... "); | 342 | qDebug("reading todos... "); |
343 | QPtrList<Todo> tr = calendar->rawTodos(); | 343 | QPtrList<Todo> tr = calendar->rawTodos(); |
344 | Todo* ev = tr.first(); | 344 | Todo* ev = tr.first(); |
345 | while ( ev ) { | 345 | while ( ev ) { |
346 | 346 | ||
347 | QStringList cat = ev->categories(); | 347 | QStringList cat = ev->categories(); |
348 | if ( cat.contains( "MeetingDEF" )) { | 348 | if ( cat.contains( "MeetingDEF" )) { |
349 | ev->setCategories( QStringList() ); | 349 | ev->setCategories( QStringList() ); |
350 | } | 350 | } |
351 | int id = ev->pilotId(); | 351 | int id = ev->pilotId(); |
352 | uint cSum; | 352 | uint cSum; |
353 | cSum = PhoneFormat::getCsumTodo( ev ); | 353 | cSum = PhoneFormat::getCsumTodo( ev ); |
354 | Todo *event; | 354 | Todo *event; |
355 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 355 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
356 | if ( event ) { | 356 | if ( event ) { |
357 | //qDebug("copy todo %s ", event->summary().latin1()); | 357 | //qDebug("copy todo %s ", event->summary().latin1()); |
358 | 358 | ||
359 | event = (Todo*)event->clone(); | 359 | event = (Todo*)event->clone(); |
360 | copyTodo( event, ev ); | 360 | copyTodo( event, ev ); |
361 | calendar->deleteTodo( ev ); | 361 | calendar->deleteTodo( ev ); |
362 | calendar->addTodo( event); | 362 | calendar->addTodo( event); |
363 | } | 363 | } |
364 | else | 364 | else |
365 | event = ev; | 365 | event = ev; |
366 | event->setCsum( mProfileName, QString::number( cSum )); | 366 | event->setCsum( mProfileName, QString::number( cSum )); |
367 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 367 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
368 | event->setID( mProfileName,QString::number( id ) ); | 368 | event->setID( mProfileName,QString::number( id ) ); |
369 | ev = tr.next(); | 369 | ev = tr.next(); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | return true; | 372 | return true; |
373 | } | 373 | } |
374 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 374 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
375 | { | 375 | { |
376 | if ( from->dtStart().isValid() ) | 376 | if ( from->dtStart().isValid() ) |
377 | to->setDtStart( from->dtStart() ); | 377 | to->setDtStart( from->dtStart() ); |
378 | if ( from->dtEnd().isValid() ) | 378 | if ( from->dtEnd().isValid() ) |
379 | to->setDtEnd( from->dtEnd() ); | 379 | to->setDtEnd( from->dtEnd() ); |
380 | if ( !from->location().isEmpty() ) | 380 | if ( !from->location().isEmpty() ) |
381 | to->setLocation( from->location() ); | 381 | to->setLocation( from->location() ); |
382 | if ( !from->description().isEmpty() ) | 382 | if ( !from->description().isEmpty() ) |
383 | to->setDescription( from->description() ); | 383 | to->setDescription( from->description() ); |
384 | if ( !from->summary().isEmpty() ) | 384 | if ( !from->summary().isEmpty() ) |
385 | to->setSummary( from->summary() ); | 385 | to->setSummary( from->summary() ); |
386 | 386 | ||
387 | if ( from->alarms().count() ) { | 387 | if ( from->alarms().count() ) { |
388 | to->clearAlarms(); | 388 | to->clearAlarms(); |
389 | Alarm *a = from->alarms().first(); | 389 | Alarm *a = from->alarms().first(); |
390 | Alarm *b = to->newAlarm( ); | 390 | Alarm *b = to->newAlarm( ); |
391 | b->setEnabled( a->enabled() ); | 391 | b->setEnabled( a->enabled() ); |
392 | b->setStartOffset(Duration( a->offset() ) ); | 392 | b->setStartOffset(Duration( a->offset() ) ); |
393 | 393 | ||
394 | } | 394 | } |
395 | QStringList cat = to->categories(); | 395 | QStringList cat = to->categories(); |
396 | QStringList catFrom = from->categories(); | 396 | QStringList catFrom = from->categories(); |
397 | QString nCat; | 397 | QString nCat; |
398 | int iii; | 398 | int iii; |
399 | for ( iii = 0; iii < catFrom.count();++iii ) { | 399 | for ( iii = 0; iii < catFrom.count();++iii ) { |
400 | nCat = catFrom[iii]; | 400 | nCat = catFrom[iii]; |
401 | if ( !nCat.isEmpty() ) | 401 | if ( !nCat.isEmpty() ) |
402 | if ( !cat.contains( nCat )) { | 402 | if ( !cat.contains( nCat )) { |
403 | cat << nCat; | 403 | cat << nCat; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | to->setCategories( cat ); | 406 | to->setCategories( cat ); |
407 | if ( from->doesRecur() ) { | 407 | if ( from->doesRecur() ) { |
408 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 408 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
409 | to->setRecurrence( r ) ; | 409 | to->setRecurrence( r ) ; |
410 | } | 410 | } |
411 | 411 | ||
412 | 412 | ||
413 | } | 413 | } |
414 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 414 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
415 | { | 415 | { |
416 | if ( from->hasStartDate() ) { | 416 | if ( from->hasStartDate() ) { |
417 | to->setHasStartDate( true ); | 417 | to->setHasStartDate( true ); |
418 | to->setDtStart( from->dtStart() ); | 418 | to->setDtStart( from->dtStart() ); |
419 | } | 419 | } |
420 | if ( from->hasDueDate() ){ | 420 | if ( from->hasDueDate() ){ |
421 | to->setHasDueDate( true ); | 421 | to->setHasDueDate( true ); |
422 | to->setDtDue( from->dtDue() ); | 422 | to->setDtDue( from->dtDue() ); |
423 | } | 423 | } |
424 | if ( !from->location().isEmpty() ) | 424 | if ( !from->location().isEmpty() ) |
425 | to->setLocation( from->location() ); | 425 | to->setLocation( from->location() ); |
426 | if ( !from->description().isEmpty() ) | 426 | if ( !from->description().isEmpty() ) |
427 | to->setDescription( from->description() ); | 427 | to->setDescription( from->description() ); |
428 | if ( !from->summary().isEmpty() ) | 428 | if ( !from->summary().isEmpty() ) |
429 | to->setSummary( from->summary() ); | 429 | to->setSummary( from->summary() ); |
430 | 430 | ||
431 | if ( from->alarms().count() ) { | 431 | if ( from->alarms().count() ) { |
432 | to->clearAlarms(); | 432 | to->clearAlarms(); |
433 | Alarm *a = from->alarms().first(); | 433 | Alarm *a = from->alarms().first(); |
434 | Alarm *b = to->newAlarm( ); | 434 | Alarm *b = to->newAlarm( ); |
435 | b->setEnabled( a->enabled() ); | 435 | b->setEnabled( a->enabled() ); |
436 | b->setStartOffset(Duration( a->offset() ) ); | 436 | b->setStartOffset(Duration( a->offset() ) ); |
437 | } | 437 | } |
438 | 438 | ||
439 | QStringList cat = to->categories(); | 439 | QStringList cat = to->categories(); |
440 | QStringList catFrom = from->categories(); | 440 | QStringList catFrom = from->categories(); |
441 | QString nCat; | 441 | QString nCat; |
442 | int iii; | 442 | int iii; |
443 | for ( iii = 0; iii < catFrom.count();++iii ) { | 443 | for ( iii = 0; iii < catFrom.count();++iii ) { |
444 | nCat = catFrom[iii]; | 444 | nCat = catFrom[iii]; |
445 | if ( !nCat.isEmpty() ) | 445 | if ( !nCat.isEmpty() ) |
446 | if ( !cat.contains( nCat )) { | 446 | if ( !cat.contains( nCat )) { |
447 | cat << nCat; | 447 | cat << nCat; |
448 | } | 448 | } |
449 | } | 449 | } |
450 | to->setCategories( cat ); | 450 | to->setCategories( cat ); |
451 | if ( from->isCompleted() ) { | 451 | if ( from->isCompleted() ) { |
452 | to->setCompleted( true ); | 452 | to->setCompleted( true ); |
453 | if( from->completed().isValid() ) | 453 | if( from->completed().isValid() ) |
454 | to->setCompleted( from->completed() ); | 454 | to->setCompleted( from->completed() ); |
455 | } else { | 455 | } else { |
456 | // set percentcomplete only, if to->isCompleted() | 456 | // set percentcomplete only, if to->isCompleted() |
457 | if ( to->isCompleted() ) | 457 | if ( to->isCompleted() ) |
458 | to->setPercentComplete(from->percentComplete()); | 458 | to->setPercentComplete(from->percentComplete()); |
459 | } | 459 | } |
460 | if( to->priority() == 2 && from->priority() == 1 ) | 460 | if( to->priority() == 2 && from->priority() == 1 ) |
461 | ; //skip | 461 | ; //skip |
462 | else if (to->priority() == 4 && from->priority() == 5 ) | 462 | else if (to->priority() == 4 && from->priority() == 5 ) |
463 | ; | 463 | ; |
464 | else | 464 | else |
465 | to->setPriority(from->priority()); | 465 | to->setPriority(from->priority()); |
466 | 466 | ||
467 | } | 467 | } |
468 | #include <qcstring.h> | 468 | #include <qcstring.h> |
469 | 469 | ||
470 | void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) | 470 | void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum) |
471 | { | 471 | { |
472 | inc->setID( mProfileName, id ); | 472 | inc->setID( mProfileName, id ); |
473 | inc->setCsum( mProfileName, csum); | 473 | inc->setCsum( mProfileName, csum); |
474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
475 | 475 | ||
476 | } | 476 | } |
477 | 477 | ||
478 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 478 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
479 | { | 479 | { |
480 | #ifdef _WIN32_ | 480 | #ifdef DESKTOP_VERSION |
481 | QString fileName = locateLocal("tmp", "phonefile.vcs"); | 481 | QString fileName = locateLocal("tmp", "phonefile.vcs"); |
482 | #else | 482 | #else |
483 | QString fileName = "/tmp/phonefile.vcs"; | 483 | QString fileName = "/tmp/phonefile.vcs"; |
484 | #endif | 484 | #endif |
485 | 485 | ||
486 | VCalFormat vfsave; | 486 | VCalFormat vfsave; |
487 | vfsave.setLocalTime ( true ); | 487 | vfsave.setLocalTime ( true ); |
488 | QString id = calendar->timeZoneId(); | 488 | QString id = calendar->timeZoneId(); |
489 | calendar->setLocalTime(); | 489 | calendar->setLocalTime(); |
490 | if ( ! vfsave.save( calendar, fileName ) ) | 490 | if ( ! vfsave.save( calendar, fileName ) ) |
491 | return false; | 491 | return false; |
492 | calendar->setTimeZoneId( id ); | 492 | calendar->setTimeZoneId( id ); |
493 | return PhoneAccess::writeToPhone( fileName ); | 493 | return PhoneAccess::writeToPhone( fileName ); |
494 | } | 494 | } |
495 | bool PhoneFormat::save( Calendar *calendar) | 495 | bool PhoneFormat::save( Calendar *calendar) |
496 | { | 496 | { |
497 | 497 | ||
498 | 498 | ||
499 | // 1 remove events which should be deleted | 499 | // 1 remove events which should be deleted |
500 | QPtrList<Event> er = calendar->rawEvents(); | 500 | QPtrList<Event> er = calendar->rawEvents(); |
501 | Event* ev = er.first(); | 501 | Event* ev = er.first(); |
502 | while ( ev ) { | 502 | while ( ev ) { |
503 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 503 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
504 | calendar->deleteEvent( ev ); | 504 | calendar->deleteEvent( ev ); |
505 | } else { | 505 | } else { |
506 | 506 | ||
507 | } | 507 | } |
508 | ev = er.next(); | 508 | ev = er.next(); |
509 | } | 509 | } |
510 | // 2 remove todos which should be deleted | 510 | // 2 remove todos which should be deleted |
511 | QPtrList<Todo> tl = calendar->rawTodos(); | 511 | QPtrList<Todo> tl = calendar->rawTodos(); |
512 | Todo* to = tl.first(); | 512 | Todo* to = tl.first(); |
513 | while ( to ) { | 513 | while ( to ) { |
514 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 514 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
515 | calendar->deleteTodo( to ); | 515 | calendar->deleteTodo( to ); |
516 | } else { | 516 | } else { |
517 | if ( to->isCompleted()) { | 517 | if ( to->isCompleted()) { |
518 | calendar->deleteTodo( to ); | 518 | calendar->deleteTodo( to ); |
519 | } | 519 | } |
520 | } | 520 | } |
521 | to = tl.next(); | 521 | to = tl.next(); |
522 | } | 522 | } |
523 | // 3 save file | 523 | // 3 save file |
524 | if ( !writeToPhone( calendar ) ) | 524 | if ( !writeToPhone( calendar ) ) |
525 | return false; | 525 | return false; |
526 | QLabel status ( i18n(" Opening device ..."), 0 ); | 526 | QLabel status ( i18n(" Opening device ..."), 0 ); |
527 | int w = status.sizeHint().width()+20 ; | 527 | int w = status.sizeHint().width()+20 ; |
528 | if ( w < 200 ) w = 230; | 528 | if ( w < 200 ) w = 230; |
529 | int h = status.sizeHint().height()+20 ; | 529 | int h = status.sizeHint().height()+20 ; |
530 | int dw = QApplication::desktop()->width(); | 530 | int dw = QApplication::desktop()->width(); |
531 | int dh = QApplication::desktop()->height(); | 531 | int dh = QApplication::desktop()->height(); |
532 | status.setCaption(i18n("Writing to phone...") ); | 532 | status.setCaption(i18n("Writing to phone...") ); |
533 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 533 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
534 | QString message; | 534 | QString message; |
535 | status.show(); | 535 | status.show(); |
536 | status.raise(); | 536 | status.raise(); |
537 | qApp->processEvents(); | 537 | qApp->processEvents(); |
538 | // 5 reread data | 538 | // 5 reread data |
539 | message = i18n(" Rereading all data ... "); | 539 | message = i18n(" Rereading all data ... "); |
540 | status.setText ( message ); | 540 | status.setText ( message ); |
541 | qApp->processEvents(); | 541 | qApp->processEvents(); |
542 | CalendarLocal* calendarTemp = new CalendarLocal(); | 542 | CalendarLocal* calendarTemp = new CalendarLocal(); |
543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
544 | if ( ! load( calendarTemp,calendar) ){ | 544 | if ( ! load( calendarTemp,calendar) ){ |
545 | qDebug("error reloading calendar "); | 545 | qDebug("error reloading calendar "); |
546 | delete calendarTemp; | 546 | delete calendarTemp; |
547 | return false; | 547 | return false; |
548 | } | 548 | } |
549 | // 6 compare data | 549 | // 6 compare data |
550 | 550 | ||
551 | //algo 6 compare event | 551 | //algo 6 compare event |
552 | er = calendar->rawEvents(); | 552 | er = calendar->rawEvents(); |
553 | ev = er.first(); | 553 | ev = er.first(); |
554 | message = i18n(" Comparing event # "); | 554 | message = i18n(" Comparing event # "); |
555 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 555 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
556 | Event* ev1; | 556 | Event* ev1; |
557 | int procCount = 0; | 557 | int procCount = 0; |
558 | while ( ev ) { | 558 | while ( ev ) { |
559 | //qDebug("event new ID %s",ev->summary().latin1()); | 559 | //qDebug("event new ID %s",ev->summary().latin1()); |
560 | status.setText ( message + QString::number ( ++procCount ) ); | 560 | status.setText ( message + QString::number ( ++procCount ) ); |
561 | qApp->processEvents(); | 561 | qApp->processEvents(); |
562 | ev1 = er1.first(); | 562 | ev1 = er1.first(); |
563 | while ( ev1 ) { | 563 | while ( ev1 ) { |
564 | if ( ev->contains( ev1 ) ) { | 564 | if ( ev->contains( ev1 ) ) { |
565 | afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); | 565 | afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName)); |
566 | er1.remove( ev1 ); | 566 | er1.remove( ev1 ); |
567 | break; | 567 | break; |
568 | } | 568 | } |
569 | ev1 = er1.next(); | 569 | ev1 = er1.next(); |
570 | } | 570 | } |
571 | if ( ! ev1 ) { | 571 | if ( ! ev1 ) { |
572 | // ev->removeID(mProfileName); | 572 | // ev->removeID(mProfileName); |
573 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 573 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
577 | ev = er.next(); | 577 | ev = er.next(); |
578 | } | 578 | } |
579 | //algo 6 compare todo | 579 | //algo 6 compare todo |
580 | tl = calendar->rawTodos(); | 580 | tl = calendar->rawTodos(); |
581 | to = tl.first(); | 581 | to = tl.first(); |
582 | procCount = 0; | 582 | procCount = 0; |
583 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 583 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
584 | Todo* to1 ; | 584 | Todo* to1 ; |
585 | message = i18n(" Comparing todo # "); | 585 | message = i18n(" Comparing todo # "); |
586 | while ( to ) { | 586 | while ( to ) { |
587 | status.setText ( message + QString::number ( ++procCount ) ); | 587 | status.setText ( message + QString::number ( ++procCount ) ); |
588 | qApp->processEvents(); | 588 | qApp->processEvents(); |
589 | Todo* to1 = tl1.first(); | 589 | Todo* to1 = tl1.first(); |
590 | while ( to1 ) { | 590 | while ( to1 ) { |
591 | if ( to->contains( to1 ) ) { | 591 | if ( to->contains( to1 ) ) { |
592 | afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); | 592 | afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName)); |
593 | tl1.remove( to1 ); | 593 | tl1.remove( to1 ); |
594 | break; | 594 | break; |
595 | } | 595 | } |
596 | to1 = tl1.next(); | 596 | to1 = tl1.next(); |
597 | } | 597 | } |
598 | if ( ! to1 ) { | 598 | if ( ! to1 ) { |
599 | //to->removeID(mProfileName); | 599 | //to->removeID(mProfileName); |
600 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 600 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
601 | } | 601 | } |
602 | 602 | ||
603 | to = tl.next(); | 603 | to = tl.next(); |
604 | } | 604 | } |
605 | delete calendarTemp; | 605 | delete calendarTemp; |
606 | return true; | 606 | return true; |
607 | 607 | ||
608 | 608 | ||
609 | 609 | ||
610 | } | 610 | } |
611 | 611 | ||
612 | 612 | ||
613 | QString PhoneFormat::toString( Calendar * ) | 613 | QString PhoneFormat::toString( Calendar * ) |
614 | { | 614 | { |
615 | return QString::null; | 615 | return QString::null; |
616 | } | 616 | } |
617 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 617 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
618 | { | 618 | { |
619 | return false; | 619 | return false; |
620 | } | 620 | } |