author | zautrix <zautrix> | 2004-10-14 10:19:14 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-14 10:19:14 (UTC) |
commit | dddcb44c8428e9054a91eea0c7483ee88ee03452 (patch) (unidiff) | |
tree | 0c6b26192c70f8cfccd00f527f56a39109a11f2d | |
parent | 3d79ab275374292196c7d032ffd2e321841c8cb0 (diff) | |
download | kdepimpi-dddcb44c8428e9054a91eea0c7483ee88ee03452.zip kdepimpi-dddcb44c8428e9054a91eea0c7483ee88ee03452.tar.gz kdepimpi-dddcb44c8428e9054a91eea0c7483ee88ee03452.tar.bz2 |
phone calendar fixes
-rw-r--r-- | libkcal/phoneformat.cpp | 7 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 2 |
2 files changed, 5 insertions, 4 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 3555dc6..281434e 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -43,591 +43,592 @@ | |||
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 _WIN32_ |
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 | int ret = PhoneAccess::readFromPhone( fileName ); | 299 | if ( ! PhoneAccess::readFromPhone( fileName )) { |
300 | if ( ret != 0 ) { | ||
301 | qDebug("Error::command returned %d", ret); | ||
302 | return false; | 300 | return false; |
303 | } | 301 | } |
304 | VCalFormat vfload; | 302 | VCalFormat vfload; |
305 | vfload.setLocalTime ( true ); | 303 | vfload.setLocalTime ( true ); |
306 | qDebug("loading file ..."); | 304 | qDebug("loading file ..."); |
307 | 305 | ||
308 | if ( ! vfload.load( calendar, fileName ) ) | 306 | if ( ! vfload.load( calendar, fileName ) ) |
309 | return false; | 307 | return false; |
310 | QPtrList<Event> er = calendar->rawEvents(); | 308 | QPtrList<Event> er = calendar->rawEvents(); |
311 | Event* ev = er.first(); | 309 | Event* ev = er.first(); |
312 | qDebug("reading events... "); | 310 | qDebug("reading events... "); |
313 | while ( ev ) { | 311 | while ( ev ) { |
314 | QStringList cat = ev->categories(); | 312 | QStringList cat = ev->categories(); |
315 | if ( cat.contains( "MeetingDEF" )) { | 313 | if ( cat.contains( "MeetingDEF" )) { |
316 | ev->setCategories( QStringList() ); | 314 | ev->setCategories( QStringList() ); |
317 | } | 315 | } |
318 | int id = ev->pilotId(); | 316 | int id = ev->pilotId(); |
319 | Event *event; | 317 | Event *event; |
320 | event = existingCal->event( mProfileName ,QString::number( id ) ); | 318 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
321 | if ( event ) { | 319 | if ( event ) { |
322 | event = (Event*)event->clone(); | 320 | event = (Event*)event->clone(); |
323 | copyEvent( event, ev ); | 321 | copyEvent( event, ev ); |
324 | calendar->deleteEvent( ev ); | 322 | calendar->deleteEvent( ev ); |
325 | calendar->addEvent( event); | 323 | calendar->addEvent( event); |
326 | } | 324 | } |
327 | else | 325 | else |
328 | event = ev; | 326 | event = ev; |
329 | uint cSum; | 327 | uint cSum; |
330 | cSum = PhoneFormat::getCsumEvent( event ); | 328 | cSum = PhoneFormat::getCsumEvent( event ); |
331 | event->setCsum( mProfileName, QString::number( cSum )); | 329 | event->setCsum( mProfileName, QString::number( cSum )); |
332 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 330 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
333 | event->setID( mProfileName,QString::number( id ) ); | 331 | event->setID( mProfileName,QString::number( id ) ); |
334 | ev = er.next(); | 332 | ev = er.next(); |
335 | } | 333 | } |
336 | { | 334 | { |
337 | qDebug("reading todos... "); | 335 | qDebug("reading todos... "); |
338 | QPtrList<Todo> tr = calendar->rawTodos(); | 336 | QPtrList<Todo> tr = calendar->rawTodos(); |
339 | Todo* ev = tr.first(); | 337 | Todo* ev = tr.first(); |
340 | while ( ev ) { | 338 | while ( ev ) { |
341 | 339 | ||
342 | QStringList cat = ev->categories(); | 340 | QStringList cat = ev->categories(); |
343 | if ( cat.contains( "MeetingDEF" )) { | 341 | if ( cat.contains( "MeetingDEF" )) { |
344 | ev->setCategories( QStringList() ); | 342 | ev->setCategories( QStringList() ); |
345 | } | 343 | } |
346 | int id = ev->pilotId(); | 344 | int id = ev->pilotId(); |
347 | Todo *event; | 345 | Todo *event; |
348 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | 346 | event = existingCal->todo( mProfileName ,QString::number( id ) ); |
349 | if ( event ) { | 347 | if ( event ) { |
350 | //qDebug("copy todo %s ", event->summary().latin1()); | 348 | //qDebug("copy todo %s ", event->summary().latin1()); |
351 | 349 | ||
352 | event = (Todo*)event->clone(); | 350 | event = (Todo*)event->clone(); |
353 | copyTodo( event, ev ); | 351 | copyTodo( event, ev ); |
354 | calendar->deleteTodo( ev ); | 352 | calendar->deleteTodo( ev ); |
355 | calendar->addTodo( event); | 353 | calendar->addTodo( event); |
356 | } | 354 | } |
357 | else | 355 | else |
358 | event = ev; | 356 | event = ev; |
359 | uint cSum; | 357 | uint cSum; |
360 | cSum = PhoneFormat::getCsumTodo( event ); | 358 | cSum = PhoneFormat::getCsumTodo( event ); |
361 | event->setCsum( mProfileName, QString::number( cSum )); | 359 | event->setCsum( mProfileName, QString::number( cSum )); |
362 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 360 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
363 | event->setID( mProfileName,QString::number( id ) ); | 361 | event->setID( mProfileName,QString::number( id ) ); |
364 | ev = tr.next(); | 362 | ev = tr.next(); |
365 | } | 363 | } |
366 | } | 364 | } |
367 | return true; | 365 | return true; |
368 | } | 366 | } |
369 | void PhoneFormat::copyEvent( Event* to, Event* from ) | 367 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
370 | { | 368 | { |
371 | if ( from->dtStart().isValid() ) | 369 | if ( from->dtStart().isValid() ) |
372 | to->setDtStart( from->dtStart() ); | 370 | to->setDtStart( from->dtStart() ); |
373 | if ( from->dtEnd().isValid() ) | 371 | if ( from->dtEnd().isValid() ) |
374 | to->setDtEnd( from->dtEnd() ); | 372 | to->setDtEnd( from->dtEnd() ); |
375 | if ( !from->location().isEmpty() ) | 373 | if ( !from->location().isEmpty() ) |
376 | to->setLocation( from->location() ); | 374 | to->setLocation( from->location() ); |
377 | if ( !from->description().isEmpty() ) | 375 | if ( !from->description().isEmpty() ) |
378 | to->setDescription( from->description() ); | 376 | to->setDescription( from->description() ); |
379 | if ( !from->summary().isEmpty() ) | 377 | if ( !from->summary().isEmpty() ) |
380 | to->setSummary( from->summary() ); | 378 | to->setSummary( from->summary() ); |
381 | 379 | ||
382 | if ( from->alarms().count() ) { | 380 | if ( from->alarms().count() ) { |
383 | to->clearAlarms(); | 381 | to->clearAlarms(); |
384 | Alarm *a = from->alarms().first(); | 382 | Alarm *a = from->alarms().first(); |
385 | Alarm *b = to->newAlarm( ); | 383 | Alarm *b = to->newAlarm( ); |
386 | b->setEnabled( a->enabled() ); | 384 | b->setEnabled( a->enabled() ); |
387 | if ( a->hasStartOffset() ) { | 385 | if ( a->hasStartOffset() ) { |
388 | b->setStartOffset( a->startOffset() ); | 386 | b->setStartOffset( a->startOffset() ); |
389 | } | 387 | } |
390 | if ( a->hasTime() ) | 388 | if ( a->hasTime() ) |
391 | b->setTime( a->time() ); | 389 | b->setTime( a->time() ); |
392 | 390 | ||
393 | } | 391 | } |
394 | QStringList cat = to->categories(); | 392 | QStringList cat = to->categories(); |
395 | QStringList catFrom = from->categories(); | 393 | QStringList catFrom = from->categories(); |
396 | QString nCat; | 394 | QString nCat; |
397 | int iii; | 395 | int iii; |
398 | for ( iii = 0; iii < catFrom.count();++iii ) { | 396 | for ( iii = 0; iii < catFrom.count();++iii ) { |
399 | nCat = catFrom[iii]; | 397 | nCat = catFrom[iii]; |
400 | if ( !nCat.isEmpty() ) | 398 | if ( !nCat.isEmpty() ) |
401 | if ( !cat.contains( nCat )) { | 399 | if ( !cat.contains( nCat )) { |
402 | cat << nCat; | 400 | cat << nCat; |
403 | } | 401 | } |
404 | } | 402 | } |
405 | to->setCategories( cat ); | 403 | to->setCategories( cat ); |
406 | Recurrence * r = new Recurrence( *from->recurrence(),to); | 404 | Recurrence * r = new Recurrence( *from->recurrence(),to); |
407 | to->setRecurrence( r ) ; | 405 | to->setRecurrence( r ) ; |
408 | 406 | ||
409 | 407 | ||
410 | } | 408 | } |
411 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) | 409 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
412 | { | 410 | { |
413 | if ( from->dtStart().isValid() ) | 411 | if ( from->dtStart().isValid() ) |
414 | to->setDtStart( from->dtStart() ); | 412 | to->setDtStart( from->dtStart() ); |
415 | if ( from->dtDue().isValid() ) | 413 | if ( from->dtDue().isValid() ) |
416 | to->setDtDue( from->dtDue() ); | 414 | to->setDtDue( from->dtDue() ); |
417 | if ( !from->location().isEmpty() ) | 415 | if ( !from->location().isEmpty() ) |
418 | to->setLocation( from->location() ); | 416 | to->setLocation( from->location() ); |
419 | if ( !from->description().isEmpty() ) | 417 | if ( !from->description().isEmpty() ) |
420 | to->setDescription( from->description() ); | 418 | to->setDescription( from->description() ); |
421 | if ( !from->summary().isEmpty() ) | 419 | if ( !from->summary().isEmpty() ) |
422 | to->setSummary( from->summary() ); | 420 | to->setSummary( from->summary() ); |
423 | 421 | ||
424 | if ( from->alarms().count() ) { | 422 | if ( from->alarms().count() ) { |
425 | to->clearAlarms(); | 423 | to->clearAlarms(); |
426 | Alarm *a = from->alarms().first(); | 424 | Alarm *a = from->alarms().first(); |
427 | Alarm *b = to->newAlarm( ); | 425 | Alarm *b = to->newAlarm( ); |
428 | b->setEnabled( a->enabled() ); | 426 | b->setEnabled( a->enabled() ); |
429 | if ( a->hasStartOffset() ) | 427 | if ( a->hasStartOffset() ) |
430 | b->setStartOffset( a->startOffset() ); | 428 | b->setStartOffset( a->startOffset() ); |
431 | if ( a->hasTime() ) | 429 | if ( a->hasTime() ) |
432 | b->setTime( a->time() ); | 430 | b->setTime( a->time() ); |
433 | } | 431 | } |
434 | 432 | ||
435 | QStringList cat = to->categories(); | 433 | QStringList cat = to->categories(); |
436 | QStringList catFrom = from->categories(); | 434 | QStringList catFrom = from->categories(); |
437 | QString nCat; | 435 | QString nCat; |
438 | int iii; | 436 | int iii; |
439 | for ( iii = 0; iii < catFrom.count();++iii ) { | 437 | for ( iii = 0; iii < catFrom.count();++iii ) { |
440 | nCat = catFrom[iii]; | 438 | nCat = catFrom[iii]; |
441 | if ( !nCat.isEmpty() ) | 439 | if ( !nCat.isEmpty() ) |
442 | if ( !cat.contains( nCat )) { | 440 | if ( !cat.contains( nCat )) { |
443 | cat << nCat; | 441 | cat << nCat; |
444 | } | 442 | } |
445 | } | 443 | } |
446 | to->setCategories( cat ); | 444 | to->setCategories( cat ); |
447 | if ( from->isCompleted() ) { | 445 | if ( from->isCompleted() ) { |
448 | to->setCompleted( true ); | 446 | to->setCompleted( true ); |
449 | if( from->completed().isValid() ) | 447 | if( from->completed().isValid() ) |
450 | to->setCompleted( from->completed() ); | 448 | to->setCompleted( from->completed() ); |
451 | } else { | 449 | } else { |
452 | // set percentcomplete only, if to->isCompleted() | 450 | // set percentcomplete only, if to->isCompleted() |
453 | if ( to->isCompleted() ) | 451 | if ( to->isCompleted() ) |
454 | to->setPercentComplete(from->percentComplete()); | 452 | to->setPercentComplete(from->percentComplete()); |
455 | } | 453 | } |
456 | if( to->priority() == 2 && from->priority() == 1 ) | 454 | if( to->priority() == 2 && from->priority() == 1 ) |
457 | ; //skip | 455 | ; //skip |
458 | else if (to->priority() == 4 && from->priority() == 5 ) | 456 | else if (to->priority() == 4 && from->priority() == 5 ) |
459 | ; | 457 | ; |
460 | else | 458 | else |
461 | to->setPriority(from->priority()); | 459 | to->setPriority(from->priority()); |
462 | 460 | ||
463 | } | 461 | } |
464 | #include <qcstring.h> | 462 | #include <qcstring.h> |
465 | 463 | ||
466 | void PhoneFormat::afterSave( Incidence* inc) | 464 | void PhoneFormat::afterSave( Incidence* inc) |
467 | { | 465 | { |
468 | uint csum; | 466 | uint csum; |
469 | inc->removeID( mProfileName ); | 467 | inc->removeID( mProfileName ); |
470 | if ( inc->type() == "Event") | 468 | if ( inc->type() == "Event") |
471 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 469 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
472 | else | 470 | else |
473 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 471 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
474 | inc->setCsum( mProfileName, QString::number( csum )); | 472 | inc->setCsum( mProfileName, QString::number( csum )); |
475 | 473 | ||
476 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 474 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
477 | 475 | ||
478 | } | 476 | } |
479 | 477 | ||
480 | bool PhoneFormat::writeToPhone( Calendar * calendar) | 478 | bool PhoneFormat::writeToPhone( Calendar * calendar) |
481 | { | 479 | { |
482 | #ifdef _WIN32_ | 480 | #ifdef _WIN32_ |
483 | QString fileName = locateLocal("tmp", "tempfile.vcs"); | 481 | QString fileName = locateLocal("tmp", "tempfile.vcs"); |
484 | #else | 482 | #else |
485 | QString fileName = "/tmp/kdepimtemp.vcs"; | 483 | QString fileName = "/tmp/kdepimtemp.vcs"; |
486 | #endif | 484 | #endif |
487 | 485 | ||
488 | VCalFormat vfsave; | 486 | VCalFormat vfsave; |
489 | vfsave.setLocalTime ( true ); | 487 | vfsave.setLocalTime ( true ); |
488 | QString id = calendar->timeZoneId(); | ||
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 | return PhoneAccess::writeToPhone( fileName ); | 493 | return PhoneAccess::writeToPhone( fileName ); |
493 | } | 494 | } |
494 | bool PhoneFormat::save( Calendar *calendar) | 495 | bool PhoneFormat::save( Calendar *calendar) |
495 | { | 496 | { |
496 | QLabel status ( i18n(" Opening device ..."), 0 ); | 497 | QLabel status ( i18n(" Opening device ..."), 0 ); |
497 | int w = status.sizeHint().width()+20 ; | 498 | int w = status.sizeHint().width()+20 ; |
498 | if ( w < 200 ) w = 230; | 499 | if ( w < 200 ) w = 230; |
499 | int h = status.sizeHint().height()+20 ; | 500 | int h = status.sizeHint().height()+20 ; |
500 | int dw = QApplication::desktop()->width(); | 501 | int dw = QApplication::desktop()->width(); |
501 | int dh = QApplication::desktop()->height(); | 502 | int dh = QApplication::desktop()->height(); |
502 | status.setCaption(i18n("Writing to phone...") ); | 503 | status.setCaption(i18n("Writing to phone...") ); |
503 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 504 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
504 | status.show(); | 505 | status.show(); |
505 | status.raise(); | 506 | status.raise(); |
506 | qApp->processEvents(); | 507 | qApp->processEvents(); |
507 | QString message; | 508 | QString message; |
508 | 509 | ||
509 | // 1 remove events which should be deleted | 510 | // 1 remove events which should be deleted |
510 | QPtrList<Event> er = calendar->rawEvents(); | 511 | QPtrList<Event> er = calendar->rawEvents(); |
511 | Event* ev = er.first(); | 512 | Event* ev = er.first(); |
512 | while ( ev ) { | 513 | while ( ev ) { |
513 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 514 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
514 | calendar->deleteEvent( ev ); | 515 | calendar->deleteEvent( ev ); |
515 | } else { | 516 | } else { |
516 | 517 | ||
517 | } | 518 | } |
518 | ev = er.next(); | 519 | ev = er.next(); |
519 | } | 520 | } |
520 | // 2 remove todos which should be deleted | 521 | // 2 remove todos which should be deleted |
521 | QPtrList<Todo> tl = calendar->rawTodos(); | 522 | QPtrList<Todo> tl = calendar->rawTodos(); |
522 | Todo* to = tl.first(); | 523 | Todo* to = tl.first(); |
523 | while ( to ) { | 524 | while ( to ) { |
524 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 525 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
525 | calendar->deleteTodo( to ); | 526 | calendar->deleteTodo( to ); |
526 | } else { | 527 | } else { |
527 | if ( to->isCompleted()) { | 528 | if ( to->isCompleted()) { |
528 | calendar->deleteTodo( to ); | 529 | calendar->deleteTodo( to ); |
529 | } | 530 | } |
530 | } | 531 | } |
531 | to = tl.next(); | 532 | to = tl.next(); |
532 | } | 533 | } |
533 | // 3 save file | 534 | // 3 save file |
534 | if ( !writeToPhone( calendar ) ) | 535 | if ( !writeToPhone( calendar ) ) |
535 | return false; | 536 | return false; |
536 | 537 | ||
537 | // 5 reread data | 538 | // 5 reread data |
538 | message = i18n(" Rereading all data ... "); | 539 | message = i18n(" Rereading all data ... "); |
539 | status.setText ( message ); | 540 | status.setText ( message ); |
540 | qApp->processEvents(); | 541 | qApp->processEvents(); |
541 | CalendarLocal* calendarTemp = new CalendarLocal(); | 542 | CalendarLocal* calendarTemp = new CalendarLocal(); |
542 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 543 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
543 | if ( ! load( calendarTemp,calendar) ){ | 544 | if ( ! load( calendarTemp,calendar) ){ |
544 | qDebug("error reloading calendar "); | 545 | qDebug("error reloading calendar "); |
545 | delete calendarTemp; | 546 | delete calendarTemp; |
546 | return false; | 547 | return false; |
547 | } | 548 | } |
548 | // 6 compare data | 549 | // 6 compare data |
549 | 550 | ||
550 | //algo 6 compare event | 551 | //algo 6 compare event |
551 | er = calendar->rawEvents(); | 552 | er = calendar->rawEvents(); |
552 | ev = er.first(); | 553 | ev = er.first(); |
553 | message = i18n(" Comparing event # "); | 554 | message = i18n(" Comparing event # "); |
554 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 555 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
555 | Event* ev1; | 556 | Event* ev1; |
556 | int procCount = 0; | 557 | int procCount = 0; |
557 | while ( ev ) { | 558 | while ( ev ) { |
558 | //qDebug("event new ID %s",ev->summary().latin1()); | 559 | //qDebug("event new ID %s",ev->summary().latin1()); |
559 | status.setText ( message + QString::number ( ++procCount ) ); | 560 | status.setText ( message + QString::number ( ++procCount ) ); |
560 | qApp->processEvents(); | 561 | qApp->processEvents(); |
561 | uint csum; | 562 | uint csum; |
562 | csum = PhoneFormat::getCsumEvent( ev ); | 563 | csum = PhoneFormat::getCsumEvent( ev ); |
563 | QString cSum = QString::number( csum ); | 564 | QString cSum = QString::number( csum ); |
564 | //ev->setCsum( mProfileName, cSum ); | 565 | //ev->setCsum( mProfileName, cSum ); |
565 | //qDebug("Event cSum %s ", cSum.latin1()); | 566 | //qDebug("Event cSum %s ", cSum.latin1()); |
566 | ev1 = er1.first(); | 567 | ev1 = er1.first(); |
567 | while ( ev1 ) { | 568 | while ( ev1 ) { |
568 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 569 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
569 | er1.remove( ev1 ); | 570 | er1.remove( ev1 ); |
570 | afterSave( ev ); | 571 | afterSave( ev ); |
571 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 572 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
572 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); | 573 | //qDebug("Event found on phone for %s ", ev->summary().latin1()); |
573 | 574 | ||
574 | break; | 575 | break; |
575 | } | 576 | } |
576 | ev1 = er1.next(); | 577 | ev1 = er1.next(); |
577 | } | 578 | } |
578 | if ( ! ev1 ) { | 579 | if ( ! ev1 ) { |
579 | // ev->removeID(mProfileName); | 580 | // ev->removeID(mProfileName); |
580 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 581 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
581 | } | 582 | } |
582 | 583 | ||
583 | 584 | ||
584 | ev = er.next(); | 585 | ev = er.next(); |
585 | } | 586 | } |
586 | //algo 6 compare todo | 587 | //algo 6 compare todo |
587 | tl = calendar->rawTodos(); | 588 | tl = calendar->rawTodos(); |
588 | to = tl.first(); | 589 | to = tl.first(); |
589 | procCount = 0; | 590 | procCount = 0; |
590 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 591 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
591 | Todo* to1 ; | 592 | Todo* to1 ; |
592 | message = i18n(" Comparing todo # "); | 593 | message = i18n(" Comparing todo # "); |
593 | while ( to ) { | 594 | while ( to ) { |
594 | status.setText ( message + QString::number ( ++procCount ) ); | 595 | status.setText ( message + QString::number ( ++procCount ) ); |
595 | qApp->processEvents(); | 596 | qApp->processEvents(); |
596 | uint csum; | 597 | uint csum; |
597 | csum = PhoneFormat::getCsumTodo( to ); | 598 | csum = PhoneFormat::getCsumTodo( to ); |
598 | QString cSum = QString::number( csum ); | 599 | QString cSum = QString::number( csum ); |
599 | //to->setCsum( mProfileName, cSum ); | 600 | //to->setCsum( mProfileName, cSum ); |
600 | //qDebug("Todo cSum %s ", cSum.latin1()); | 601 | //qDebug("Todo cSum %s ", cSum.latin1()); |
601 | Todo* to1 = tl1.first(); | 602 | Todo* to1 = tl1.first(); |
602 | while ( to1 ) { | 603 | while ( to1 ) { |
603 | if ( to1->getCsum( mProfileName ) == cSum ) { | 604 | if ( to1->getCsum( mProfileName ) == cSum ) { |
604 | tl1.remove( to1 ); | 605 | tl1.remove( to1 ); |
605 | afterSave( to ); | 606 | afterSave( to ); |
606 | to->setID(mProfileName, to1->getID(mProfileName) ); | 607 | to->setID(mProfileName, to1->getID(mProfileName) ); |
607 | break; | 608 | break; |
608 | } | 609 | } |
609 | to1 = tl1.next(); | 610 | to1 = tl1.next(); |
610 | } | 611 | } |
611 | if ( ! to1 ) { | 612 | if ( ! to1 ) { |
612 | //to->removeID(mProfileName); | 613 | //to->removeID(mProfileName); |
613 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 614 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
614 | } | 615 | } |
615 | 616 | ||
616 | to = tl.next(); | 617 | to = tl.next(); |
617 | } | 618 | } |
618 | delete calendarTemp; | 619 | delete calendarTemp; |
619 | return true; | 620 | return true; |
620 | 621 | ||
621 | 622 | ||
622 | 623 | ||
623 | } | 624 | } |
624 | 625 | ||
625 | 626 | ||
626 | QString PhoneFormat::toString( Calendar * ) | 627 | QString PhoneFormat::toString( Calendar * ) |
627 | { | 628 | { |
628 | return QString::null; | 629 | return QString::null; |
629 | } | 630 | } |
630 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 631 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
631 | { | 632 | { |
632 | return false; | 633 | return false; |
633 | } | 634 | } |
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index 5fafa1f..8298aa6 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp | |||
@@ -1,173 +1,173 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
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 | 22 | ||
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 <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include <kmessagebox.h> | 31 | #include <kmessagebox.h> |
32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
33 | #include "phoneaccess.h" | 33 | #include "phoneaccess.h" |
34 | 34 | ||
35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) | 35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) |
36 | { | 36 | { |
37 | #ifdef _WIN32_ | 37 | #ifdef _WIN32_ |
38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; | 38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; |
39 | #else | 39 | #else |
40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; | 40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; |
41 | #endif | 41 | #endif |
42 | //qDebug("save %d ", load ); | 42 | //qDebug("save %d ", load ); |
43 | QString content = "[gammu]\n";; | 43 | QString content = "[gammu]\n";; |
44 | bool write = false; | 44 | bool write = false; |
45 | bool addPort = true, addConnection = true, addModel = true; | 45 | bool addPort = true, addConnection = true, addModel = true; |
46 | QFile file( fileName ); | 46 | QFile file( fileName ); |
47 | if ( QFile::exists( fileName) ) { | 47 | if ( QFile::exists( fileName) ) { |
48 | if (!file.open( IO_ReadOnly ) ) { | 48 | if (!file.open( IO_ReadOnly ) ) { |
49 | qDebug("Error: cannot open %s ", fileName.latin1() ); | 49 | qDebug("Error: cannot open %s ", fileName.latin1() ); |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | QString line; | 52 | QString line; |
53 | while ( file.readLine( line, 1024 ) > 0 ) { | 53 | while ( file.readLine( line, 1024 ) > 0 ) { |
54 | //qDebug("*%s* ", line.latin1() ); | 54 | //qDebug("*%s* ", line.latin1() ); |
55 | if ( line.left(7 ) == "[gammu]" ) { | 55 | if ( line.left(7 ) == "[gammu]" ) { |
56 | ; | 56 | ; |
57 | } else | 57 | } else |
58 | if ( line.left(4 ) == "port" ) { | 58 | if ( line.left(4 ) == "port" ) { |
59 | if ( line == "port = " + device+"\n" ) { | 59 | if ( line == "port = " + device+"\n" ) { |
60 | content += line ; | 60 | content += line ; |
61 | addPort = false; | 61 | addPort = false; |
62 | //qDebug("port found" ); | 62 | //qDebug("port found" ); |
63 | } | 63 | } |
64 | 64 | ||
65 | } else if ( line.left(5 ) == "model" ) { | 65 | } else if ( line.left(5 ) == "model" ) { |
66 | if ( line == "model = " + model +"\n") { | 66 | if ( line == "model = " + model +"\n") { |
67 | content += line ; | 67 | content += line ; |
68 | addModel = false; | 68 | addModel = false; |
69 | //qDebug("model found" ); | 69 | //qDebug("model found" ); |
70 | } | 70 | } |
71 | 71 | ||
72 | } else if ( line.left( 10 ) == "connection" ) { | 72 | } else if ( line.left( 10 ) == "connection" ) { |
73 | if ( line == "connection = " + connection +"\n") { | 73 | if ( line == "connection = " + connection +"\n") { |
74 | addConnection = false; | 74 | addConnection = false; |
75 | content += line ; | 75 | content += line ; |
76 | //qDebug("con found" ); | 76 | //qDebug("con found" ); |
77 | } | 77 | } |
78 | 78 | ||
79 | } else { | 79 | } else { |
80 | content += line ; | 80 | content += line ; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | file.close(); | 83 | file.close(); |
84 | } else { | 84 | } else { |
85 | if ( ! connection.isEmpty() ) { | 85 | if ( ! connection.isEmpty() ) { |
86 | addConnection = true; | 86 | addConnection = true; |
87 | } | 87 | } |
88 | if ( ! device.isEmpty() ) { | 88 | if ( ! device.isEmpty() ) { |
89 | addPort = true; | 89 | addPort = true; |
90 | 90 | ||
91 | } | 91 | } |
92 | if ( ! model.isEmpty() ) { | 92 | if ( ! model.isEmpty() ) { |
93 | addModel = true; | 93 | addModel = true; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | if ( addConnection ) { | 97 | if ( addConnection ) { |
98 | write = true; | 98 | write = true; |
99 | content += "connection = "; | 99 | content += "connection = "; |
100 | content += connection; | 100 | content += connection; |
101 | content += "\n"; | 101 | content += "\n"; |
102 | } | 102 | } |
103 | if ( addPort ) { | 103 | if ( addPort ) { |
104 | write = true; | 104 | write = true; |
105 | content += "port = "; | 105 | content += "port = "; |
106 | content += device; | 106 | content += device; |
107 | content += "\n"; | 107 | content += "\n"; |
108 | 108 | ||
109 | } | 109 | } |
110 | if ( addModel ) { | 110 | if ( addModel ) { |
111 | write = true; | 111 | write = true; |
112 | content += "model = "; | 112 | content += "model = "; |
113 | content += model; | 113 | content += model; |
114 | content += "\n"; | 114 | content += "\n"; |
115 | } | 115 | } |
116 | if ( write ) { | 116 | if ( write ) { |
117 | if (!file.open( IO_WriteOnly ) ) { | 117 | if (!file.open( IO_WriteOnly ) ) { |
118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); | 118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | qDebug("Writing file %s ", fileName.latin1() ); | 121 | qDebug("Writing file %s ", fileName.latin1() ); |
122 | QTextStream ts( &file ); | 122 | QTextStream ts( &file ); |
123 | ts << content ; | 123 | ts << content ; |
124 | file.close(); | 124 | file.close(); |
125 | } | 125 | } |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | bool PhoneAccess::writeToPhone( QString fileName) | 130 | bool PhoneAccess::writeToPhone( QString fileName) |
131 | { | 131 | { |
132 | 132 | ||
133 | #ifdef DESKTOP_VERSION | 133 | #ifdef DESKTOP_VERSION |
134 | #ifdef _WIN32_ | 134 | #ifdef _WIN32_ |
135 | QString command ="kammu --restore " + fileName ; | 135 | QString command ="kammu --restore " + fileName ; |
136 | #else | 136 | #else |
137 | QString command ="./kammu --restore " + fileName ; | 137 | QString command ="./kammu --restore " + fileName ; |
138 | #endif | 138 | #endif |
139 | #else | 139 | #else |
140 | QString command ="kammu --restore " + fileName ; | 140 | QString command ="kammu --restore " + fileName ; |
141 | #endif | 141 | #endif |
142 | int ret; | 142 | int ret; |
143 | while ( (ret = system ( command.latin1())) != 0 ) { | 143 | while ( (ret = system ( command.latin1())) != 0 ) { |
144 | qDebug("Error S::command returned %d.", ret); | 144 | qDebug("Error S::command returned %d.", ret); |
145 | int retval = KMessageBox::warningContinueCancel(0, | 145 | int retval = KMessageBox::warningContinueCancel(0, |
146 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); | 146 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); |
147 | if ( retval != KMessageBox::Continue ) | 147 | if ( retval != KMessageBox::Continue ) |
148 | return false; | 148 | return false; |
149 | } | 149 | } |
150 | return true; | 150 | return true; |
151 | } | 151 | } |
152 | bool PhoneAccess::readFromPhone( QString fileName) | 152 | bool PhoneAccess::readFromPhone( QString fileName) |
153 | { | 153 | { |
154 | 154 | ||
155 | #ifdef DESKTOP_VERSION | 155 | #ifdef DESKTOP_VERSION |
156 | #ifdef _WIN32_ | 156 | #ifdef _WIN32_ |
157 | QString command ="kammu --backup " + fileName + " -yes" ; | 157 | QString command ="kammu --backup " + fileName + " -yes" ; |
158 | #else | 158 | #else |
159 | QString command ="./kammu --backup " + fileName + " -yes" ; | 159 | QString command ="./kammu --backup " + fileName + " -yes" ; |
160 | #endif | 160 | #endif |
161 | #else | 161 | #else |
162 | QString command ="kammu --backup " + fileName + " -yes" ; | 162 | QString command ="kammu --backup " + fileName + " -yes" ; |
163 | #endif | 163 | #endif |
164 | int ret; | 164 | int ret; |
165 | while ( (ret = system ( command.latin1())) != 0 ) { | 165 | while ( (ret = system ( command.latin1())) != 0 ) { |
166 | qDebug("Error S::command returned %d.", ret); | 166 | qDebug("Error reading from phone:Command returned %d", ret); |
167 | int retval = KMessageBox::warningContinueCancel(0, | 167 | int retval = KMessageBox::warningContinueCancel(0, |
168 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); | 168 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KDE/Pim phone access"),i18n("Retry"),i18n("Cancel")); |
169 | if ( retval != KMessageBox::Continue ) | 169 | if ( retval != KMessageBox::Continue ) |
170 | return false; | 170 | return false; |
171 | } | 171 | } |
172 | return true; | 172 | return true; |
173 | } | 173 | } |