author | zautrix <zautrix> | 2004-08-30 07:47:56 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-30 07:47:56 (UTC) |
commit | b36bcd92b643c87ee5e2bfc39076ea56abf4c7d2 (patch) (unidiff) | |
tree | 99223dd8edf0e00a4f060610ea0642f915cf4703 /libkcal | |
parent | 78f44f13835e3fa501997f485b505b193bd474f5 (diff) | |
download | kdepimpi-b36bcd92b643c87ee5e2bfc39076ea56abf4c7d2.zip kdepimpi-b36bcd92b643c87ee5e2bfc39076ea56abf4c7d2.tar.gz kdepimpi-b36bcd92b643c87ee5e2bfc39076ea56abf4c7d2.tar.bz2 |
Changes in gammu connection
-rw-r--r-- | libkcal/incidence.cpp | 5 | ||||
-rw-r--r-- | libkcal/incidence.h | 2 | ||||
-rw-r--r-- | libkcal/phoneformat.cpp | 1464 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 14 | ||||
-rw-r--r-- | libkcal/vcalformat.cpp | 5 | ||||
-rw-r--r-- | libkcal/vcalformat.h | 5 |
6 files changed, 194 insertions, 1301 deletions
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index d9bda64..56c9801 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -489,96 +489,101 @@ QStringList Incidence::secrecyList() | |||
489 | } | 489 | } |
490 | 490 | ||
491 | 491 | ||
492 | QPtrList<Alarm> Incidence::alarms() const | 492 | QPtrList<Alarm> Incidence::alarms() const |
493 | { | 493 | { |
494 | return mAlarms; | 494 | return mAlarms; |
495 | } | 495 | } |
496 | 496 | ||
497 | Alarm* Incidence::newAlarm() | 497 | Alarm* Incidence::newAlarm() |
498 | { | 498 | { |
499 | Alarm* alarm = new Alarm(this); | 499 | Alarm* alarm = new Alarm(this); |
500 | mAlarms.append(alarm); | 500 | mAlarms.append(alarm); |
501 | // updated(); | 501 | // updated(); |
502 | return alarm; | 502 | return alarm; |
503 | } | 503 | } |
504 | 504 | ||
505 | void Incidence::addAlarm(Alarm *alarm) | 505 | void Incidence::addAlarm(Alarm *alarm) |
506 | { | 506 | { |
507 | mAlarms.append(alarm); | 507 | mAlarms.append(alarm); |
508 | updated(); | 508 | updated(); |
509 | } | 509 | } |
510 | 510 | ||
511 | void Incidence::removeAlarm(Alarm *alarm) | 511 | void Incidence::removeAlarm(Alarm *alarm) |
512 | { | 512 | { |
513 | mAlarms.removeRef(alarm); | 513 | mAlarms.removeRef(alarm); |
514 | updated(); | 514 | updated(); |
515 | } | 515 | } |
516 | 516 | ||
517 | void Incidence::clearAlarms() | 517 | void Incidence::clearAlarms() |
518 | { | 518 | { |
519 | mAlarms.clear(); | 519 | mAlarms.clear(); |
520 | updated(); | 520 | updated(); |
521 | } | 521 | } |
522 | 522 | ||
523 | bool Incidence::isAlarmEnabled() const | 523 | bool Incidence::isAlarmEnabled() const |
524 | { | 524 | { |
525 | Alarm* alarm; | 525 | Alarm* alarm; |
526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 526 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
527 | if (alarm->enabled()) | 527 | if (alarm->enabled()) |
528 | return true; | 528 | return true; |
529 | } | 529 | } |
530 | return false; | 530 | return false; |
531 | } | 531 | } |
532 | 532 | ||
533 | Recurrence *Incidence::recurrence() const | 533 | Recurrence *Incidence::recurrence() const |
534 | { | 534 | { |
535 | return mRecurrence; | 535 | return mRecurrence; |
536 | } | 536 | } |
537 | void Incidence::setRecurrence( Recurrence * r) | ||
538 | { | ||
539 | delete mRecurrence; | ||
540 | mRecurrence = r; | ||
541 | } | ||
537 | 542 | ||
538 | void Incidence::setLocation(const QString &location) | 543 | void Incidence::setLocation(const QString &location) |
539 | { | 544 | { |
540 | if (mReadOnly) return; | 545 | if (mReadOnly) return; |
541 | mLocation = location; | 546 | mLocation = location; |
542 | updated(); | 547 | updated(); |
543 | } | 548 | } |
544 | 549 | ||
545 | QString Incidence::location() const | 550 | QString Incidence::location() const |
546 | { | 551 | { |
547 | return mLocation; | 552 | return mLocation; |
548 | } | 553 | } |
549 | 554 | ||
550 | ushort Incidence::doesRecur() const | 555 | ushort Incidence::doesRecur() const |
551 | { | 556 | { |
552 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 557 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
553 | else return Recurrence::rNone; | 558 | else return Recurrence::rNone; |
554 | } | 559 | } |
555 | 560 | ||
556 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 561 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
557 | { | 562 | { |
558 | QDateTime incidenceStart = dt; | 563 | QDateTime incidenceStart = dt; |
559 | *ok = false; | 564 | *ok = false; |
560 | if ( doesRecur() ) { | 565 | if ( doesRecur() ) { |
561 | bool last; | 566 | bool last; |
562 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 567 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
563 | int count = 0; | 568 | int count = 0; |
564 | if ( !last ) { | 569 | if ( !last ) { |
565 | while ( !last ) { | 570 | while ( !last ) { |
566 | ++count; | 571 | ++count; |
567 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 572 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
568 | if ( recursOn( incidenceStart.date() ) ) { | 573 | if ( recursOn( incidenceStart.date() ) ) { |
569 | last = true; // exit while llop | 574 | last = true; // exit while llop |
570 | } else { | 575 | } else { |
571 | if ( last ) { // no alarm on last recurrence | 576 | if ( last ) { // no alarm on last recurrence |
572 | return QDateTime (); | 577 | return QDateTime (); |
573 | } | 578 | } |
574 | int year = incidenceStart.date().year(); | 579 | int year = incidenceStart.date().year(); |
575 | // workaround for bug in recurrence | 580 | // workaround for bug in recurrence |
576 | if ( count == 100 || year < 1980 || year > 5000 ) { | 581 | if ( count == 100 || year < 1980 || year > 5000 ) { |
577 | return QDateTime (); | 582 | return QDateTime (); |
578 | } | 583 | } |
579 | incidenceStart = incidenceStart.addSecs( 1 ); | 584 | incidenceStart = incidenceStart.addSecs( 1 ); |
580 | } | 585 | } |
581 | } | 586 | } |
582 | } else { | 587 | } else { |
583 | return QDateTime (); | 588 | return QDateTime (); |
584 | } | 589 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index d1972cb..7dc6f10 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -200,97 +200,97 @@ class Incidence : public IncidenceBase | |||
200 | QPtrList<Attachment> attachments(const QString& mime) const; | 200 | QPtrList<Attachment> attachments(const QString& mime) const; |
201 | 201 | ||
202 | /** sets the event's status the value specified. See the enumeration | 202 | /** sets the event's status the value specified. See the enumeration |
203 | * above for possible values. */ | 203 | * above for possible values. */ |
204 | void setSecrecy(int); | 204 | void setSecrecy(int); |
205 | /** return the event's secrecy. */ | 205 | /** return the event's secrecy. */ |
206 | int secrecy() const; | 206 | int secrecy() const; |
207 | /** return the event's secrecy in string format. */ | 207 | /** return the event's secrecy in string format. */ |
208 | QString secrecyStr() const; | 208 | QString secrecyStr() const; |
209 | /** return list of all availbale secrecy classes */ | 209 | /** return list of all availbale secrecy classes */ |
210 | static QStringList secrecyList(); | 210 | static QStringList secrecyList(); |
211 | /** return human-readable name of secrecy class */ | 211 | /** return human-readable name of secrecy class */ |
212 | static QString secrecyName(int); | 212 | static QString secrecyName(int); |
213 | 213 | ||
214 | /** returns TRUE if the date specified is one on which the event will | 214 | /** returns TRUE if the date specified is one on which the event will |
215 | * recur. */ | 215 | * recur. */ |
216 | bool recursOn(const QDate &qd) const; | 216 | bool recursOn(const QDate &qd) const; |
217 | 217 | ||
218 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 218 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
219 | 219 | ||
220 | /** set resources used, such as Office, Car, etc. */ | 220 | /** set resources used, such as Office, Car, etc. */ |
221 | void setResources(const QStringList &resources); | 221 | void setResources(const QStringList &resources); |
222 | /** return list of current resources */ | 222 | /** return list of current resources */ |
223 | QStringList resources() const; | 223 | QStringList resources() const; |
224 | 224 | ||
225 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 225 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
226 | void setPriority(int priority); | 226 | void setPriority(int priority); |
227 | /** get the event's priority */ | 227 | /** get the event's priority */ |
228 | int priority() const; | 228 | int priority() const; |
229 | 229 | ||
230 | /** All alarms that are associated with this incidence */ | 230 | /** All alarms that are associated with this incidence */ |
231 | QPtrList<Alarm> alarms() const; | 231 | QPtrList<Alarm> alarms() const; |
232 | /** Create a new alarm which is associated with this incidence */ | 232 | /** Create a new alarm which is associated with this incidence */ |
233 | Alarm* newAlarm(); | 233 | Alarm* newAlarm(); |
234 | /** Add an alarm which is associated with this incidence */ | 234 | /** Add an alarm which is associated with this incidence */ |
235 | void addAlarm(Alarm*); | 235 | void addAlarm(Alarm*); |
236 | /** Remove an alarm that is associated with this incidence */ | 236 | /** Remove an alarm that is associated with this incidence */ |
237 | void removeAlarm(Alarm*); | 237 | void removeAlarm(Alarm*); |
238 | /** Remove all alarms that are associated with this incidence */ | 238 | /** Remove all alarms that are associated with this incidence */ |
239 | void clearAlarms(); | 239 | void clearAlarms(); |
240 | /** return whether any alarm associated with this incidence is enabled */ | 240 | /** return whether any alarm associated with this incidence is enabled */ |
241 | bool isAlarmEnabled() const; | 241 | bool isAlarmEnabled() const; |
242 | 242 | ||
243 | /** | 243 | /** |
244 | Return the recurrence rule associated with this incidence. If there is | 244 | Return the recurrence rule associated with this incidence. If there is |
245 | none, returns an appropriate (non-0) object. | 245 | none, returns an appropriate (non-0) object. |
246 | */ | 246 | */ |
247 | Recurrence *recurrence() const; | 247 | Recurrence *recurrence() const; |
248 | 248 | void setRecurrence(Recurrence * r); | |
249 | /** | 249 | /** |
250 | Forward to Recurrence::doesRecur(). | 250 | Forward to Recurrence::doesRecur(). |
251 | */ | 251 | */ |
252 | ushort doesRecur() const; | 252 | ushort doesRecur() const; |
253 | 253 | ||
254 | /** set the event's/todo's location. Do _not_ use it with journal */ | 254 | /** set the event's/todo's location. Do _not_ use it with journal */ |
255 | void setLocation(const QString &location); | 255 | void setLocation(const QString &location); |
256 | /** return the event's/todo's location. Do _not_ use it with journal */ | 256 | /** return the event's/todo's location. Do _not_ use it with journal */ |
257 | QString location() const; | 257 | QString location() const; |
258 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 258 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
259 | bool hasStartDate() const; | 259 | bool hasStartDate() const; |
260 | /** sets the event's hasStartDate value. */ | 260 | /** sets the event's hasStartDate value. */ |
261 | void setHasStartDate(bool f); | 261 | void setHasStartDate(bool f); |
262 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 262 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
263 | bool cancelled() const; | 263 | bool cancelled() const; |
264 | void setCancelled( bool b ); | 264 | void setCancelled( bool b ); |
265 | 265 | ||
266 | protected: | 266 | protected: |
267 | QPtrList<Alarm> mAlarms; | 267 | QPtrList<Alarm> mAlarms; |
268 | private: | 268 | private: |
269 | int mRevision; | 269 | int mRevision; |
270 | bool mCancelled; | 270 | bool mCancelled; |
271 | 271 | ||
272 | // base components of jounal, event and todo | 272 | // base components of jounal, event and todo |
273 | QDateTime mCreated; | 273 | QDateTime mCreated; |
274 | QString mDescription; | 274 | QString mDescription; |
275 | QString mSummary; | 275 | QString mSummary; |
276 | QStringList mCategories; | 276 | QStringList mCategories; |
277 | Incidence *mRelatedTo; | 277 | Incidence *mRelatedTo; |
278 | QString mRelatedToUid; | 278 | QString mRelatedToUid; |
279 | QPtrList<Incidence> mRelations; | 279 | QPtrList<Incidence> mRelations; |
280 | DateList mExDates; | 280 | DateList mExDates; |
281 | QPtrList<Attachment> mAttachments; | 281 | QPtrList<Attachment> mAttachments; |
282 | QStringList mResources; | 282 | QStringList mResources; |
283 | bool mHasStartDate; // if todo has associated start date | 283 | bool mHasStartDate; // if todo has associated start date |
284 | 284 | ||
285 | int mSecrecy; | 285 | int mSecrecy; |
286 | int mPriority; // 1 = highest, 2 = less, etc. | 286 | int mPriority; // 1 = highest, 2 = less, etc. |
287 | 287 | ||
288 | //QPtrList<Alarm> mAlarms; | 288 | //QPtrList<Alarm> mAlarms; |
289 | Recurrence *mRecurrence; | 289 | Recurrence *mRecurrence; |
290 | 290 | ||
291 | QString mLocation; | 291 | QString mLocation; |
292 | }; | 292 | }; |
293 | 293 | ||
294 | bool operator==( const Incidence&, const Incidence& ); | 294 | bool operator==( const Incidence&, const Incidence& ); |
295 | 295 | ||
296 | } | 296 | } |
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 1769b37..0bc9125 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -1,662 +1,168 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@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 <qxml.h> | 32 | #include <qxml.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 | 38 | ||
39 | #include "calendar.h" | 39 | #include "calendar.h" |
40 | #include "alarm.h" | 40 | #include "alarm.h" |
41 | #include "recurrence.h" | 41 | #include "recurrence.h" |
42 | #include "calendarlocal.h" | 42 | #include "calendarlocal.h" |
43 | 43 | ||
44 | #include "phoneformat.h" | 44 | #include "phoneformat.h" |
45 | #include "syncdefines.h" | 45 | #include "syncdefines.h" |
46 | 46 | ||
47 | using namespace KCal; | 47 | using namespace KCal; |
48 | |||
49 | class PhoneParser : public QObject | 48 | class PhoneParser : public QObject |
50 | { | 49 | { |
51 | public: | 50 | public: |
52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { | 51 | PhoneParser( ) { |
53 | ; | 52 | ; |
54 | } | 53 | } |
55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) | 54 | |
56 | { | ||
57 | |||
58 | int id = ToDo->Location; | ||
59 | Todo *todo; | ||
60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); | ||
61 | if (todo ) | ||
62 | todo = (Todo *)todo->clone(); | ||
63 | else | ||
64 | todo = new Todo; | ||
65 | todo->setID( mProfileName,QString::number( id ) ); | ||
66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
67 | int priority; | ||
68 | switch (ToDo->Priority) { | ||
69 | case GSM_Priority_Low : priority = 5; break; | ||
70 | case GSM_Priority_Medium : priority = 3; break; | ||
71 | case GSM_Priority_High : priority = 1; break; | ||
72 | default :priority = 3 ;break; | ||
73 | } | ||
74 | todo->setPriority( priority ); | ||
75 | GSM_Phone_Functions*Phone; | ||
76 | Phone=s->Phone.Functions; | ||
77 | int j; | ||
78 | GSM_DateTime* dtp; | ||
79 | bool alarm = false; | ||
80 | QDateTime alarmDt; | ||
81 | GSM_Category Category; | ||
82 | int error; | ||
83 | for (j=0;j<ToDo->EntriesNum;j++) { | ||
84 | |||
85 | //qDebug(" for todo %d",ToDo->Location ); | ||
86 | switch (ToDo->Entries[j].EntryType) { | ||
87 | case TODO_END_DATETIME: | ||
88 | dtp = &ToDo->Entries[j].Date ; | ||
89 | todo->setDtDue (fromGSM ( dtp )); | ||
90 | break; | ||
91 | case TODO_COMPLETED: | ||
92 | if ( ToDo->Entries[j].Number == 1 ) { | ||
93 | todo->setCompleted( true ); | ||
94 | } | ||
95 | else { | ||
96 | todo->setCompleted( false ); | ||
97 | } | ||
98 | break; | ||
99 | case TODO_ALARM_DATETIME: | ||
100 | dtp = &ToDo->Entries[j].Date ; | ||
101 | alarm = true; | ||
102 | alarmDt = fromGSM ( dtp ); | ||
103 | break; | ||
104 | case TODO_SILENT_ALARM_DATETIME: | ||
105 | dtp = &ToDo->Entries[j].Date ; | ||
106 | alarm = true; | ||
107 | alarmDt = fromGSM ( dtp ); | ||
108 | break; | ||
109 | case TODO_TEXT: | ||
110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); | ||
111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); | ||
112 | break; | ||
113 | case TODO_PRIVATE: | ||
114 | if ( ToDo->Entries[j].Number == 1 ) | ||
115 | todo->setSecrecy( Incidence::SecrecyPrivate ); | ||
116 | else | ||
117 | todo->setSecrecy( Incidence::SecrecyPublic ); | ||
118 | break; | ||
119 | case TODO_CATEGORY: | ||
120 | Category.Location = ToDo->Entries[j].Number; | ||
121 | Category.Type = Category_ToDo; | ||
122 | error=Phone->GetCategory(s, &Category); | ||
123 | if (error == ERR_NONE) { | ||
124 | QStringList cat = todo->categories(); | ||
125 | QString nCat = QString ( (const char*)Category.Name ); | ||
126 | if ( !nCat.isEmpty() ) | ||
127 | if ( !cat.contains( nCat )) { | ||
128 | cat << nCat; | ||
129 | todo->setCategories( cat ); | ||
130 | } | ||
131 | } | ||
132 | break; | ||
133 | case TODO_CONTACTID: | ||
134 | #if 0 | ||
135 | // not supported | ||
136 | entry.Location = ToDo->Entries[j].Number; | ||
137 | entry.MemoryType = MEM_ME; | ||
138 | error=Phone->GetMemory(s, &entry); | ||
139 | if (error == ERR_NONE) { | ||
140 | name = GSM_PhonebookGetEntryName(&entry); | ||
141 | if (name != NULL) { | ||
142 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); | ||
143 | } else { | ||
144 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); | ||
145 | } | ||
146 | } else { | ||
147 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); | ||
148 | } | ||
149 | #endif | ||
150 | break; | ||
151 | case TODO_PHONE: | ||
152 | #if 0 | ||
153 | // not supported | ||
154 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); | ||
155 | #endif | ||
156 | break; | ||
157 | } | ||
158 | } | ||
159 | QString alarmString = "na"; | ||
160 | if ( alarm ) { | ||
161 | Alarm *alarm; | ||
162 | if ( todo->alarms().count() > 0 ) | ||
163 | alarm = todo->alarms().first(); | ||
164 | else { | ||
165 | alarm = new Alarm( todo ); | ||
166 | todo->addAlarm( alarm ); | ||
167 | } | ||
168 | alarm->setType( Alarm::Audio ); | ||
169 | alarm->setEnabled( true ); | ||
170 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); | ||
171 | alarm->setStartOffset( -alarmOffset ); | ||
172 | alarmString = QString::number( alarmOffset ); | ||
173 | } else { | ||
174 | Alarm *alarm; | ||
175 | if ( todo->alarms().count() > 0 ) { | ||
176 | alarm = todo->alarms().first(); | ||
177 | alarm->setType( Alarm::Audio ); | ||
178 | alarm->setStartOffset( -60*15 ); | ||
179 | alarm->setEnabled( false ); | ||
180 | } | ||
181 | } | ||
182 | // csum ***************************************** | ||
183 | uint cSum; | ||
184 | cSum = PhoneFormat::getCsumTodo( todo ); | ||
185 | todo->setCsum( mProfileName, QString::number( cSum )); | ||
186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
187 | mCalendar->addTodo( todo); | ||
188 | |||
189 | return true; | ||
190 | } | ||
191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) | ||
192 | { | ||
193 | |||
194 | int id = Note->Location; | ||
195 | Event *event; | ||
196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); | ||
197 | if ( event ) | ||
198 | event = (Event*)event->clone(); | ||
199 | else | ||
200 | event = new Event; | ||
201 | event->setID( mProfileName,QString::number( id ) ); | ||
202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
203 | |||
204 | |||
205 | int i = 0; | ||
206 | bool repeating = false; | ||
207 | int repeat_dayofweek = -1; | ||
208 | int repeat_day = -1; | ||
209 | int repeat_weekofmonth = -1; | ||
210 | int repeat_month = -1; | ||
211 | int repeat_frequency = -1; | ||
212 | int rec_type = -1; | ||
213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | ||
214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | ||
215 | GSM_DateTime* dtp; | ||
216 | bool alarm = false; | ||
217 | QDateTime alarmDt; | ||
218 | repeat_startdate.Day= 0; | ||
219 | repeat_stopdate.Day = 0; | ||
220 | for (i=0;i<Note->EntriesNum;i++) { | ||
221 | |||
222 | //qDebug(" for ev"); | ||
223 | switch (Note->Entries[i].EntryType) { | ||
224 | case CAL_START_DATETIME: | ||
225 | dtp = &Note->Entries[i].Date ; | ||
226 | if ( dtp->Hour > 24 ) { | ||
227 | event->setFloats( true ); | ||
228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | ||
229 | } else { | ||
230 | event->setDtStart (fromGSM ( dtp )); | ||
231 | |||
232 | } | ||
233 | //Note->Entries[i].Date.Hour = 5; | ||
234 | break; | ||
235 | case CAL_END_DATETIME: | ||
236 | dtp = &Note->Entries[i].Date ; | ||
237 | if ( dtp->Hour > 24 ) { | ||
238 | event->setFloats( true ); | ||
239 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | ||
240 | } else { | ||
241 | event->setDtEnd (fromGSM ( dtp )); | ||
242 | } | ||
243 | break; | ||
244 | case CAL_ALARM_DATETIME: | ||
245 | dtp = &Note->Entries[i].Date ; | ||
246 | alarm = true; | ||
247 | alarmDt = fromGSM ( dtp ); | ||
248 | break; | ||
249 | case CAL_SILENT_ALARM_DATETIME: | ||
250 | dtp = &Note->Entries[i].Date ; | ||
251 | alarm = true; | ||
252 | alarmDt = fromGSM ( dtp ); | ||
253 | break; | ||
254 | case CAL_RECURRANCE: | ||
255 | rec_type = Note->Entries[i].Number; | ||
256 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); | ||
257 | break; | ||
258 | case CAL_TEXT: | ||
259 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); | ||
260 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); | ||
261 | break; | ||
262 | case CAL_LOCATION: | ||
263 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); | ||
264 | break; | ||
265 | case CAL_PHONE: | ||
266 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); | ||
267 | break; | ||
268 | case CAL_PRIVATE: | ||
269 | if ( Note->Entries[i].Number == 1 ) | ||
270 | event->setSecrecy( Incidence::SecrecyPrivate ); | ||
271 | else | ||
272 | event->setSecrecy( Incidence::SecrecyPublic ); | ||
273 | |||
274 | break; | ||
275 | case CAL_CONTACTID: | ||
276 | #if 0 | ||
277 | entry.Location = Note->Entries[i].Number; | ||
278 | entry.MemoryType = MEM_ME; | ||
279 | error=Phone->GetMemory(&s, &entry); | ||
280 | if (error == ERR_NONE) { | ||
281 | name = GSM_PhonebookGetEntryName(&entry); | ||
282 | if (name != NULL) { | ||
283 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); | ||
284 | } else { | ||
285 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | ||
286 | } | ||
287 | } else { | ||
288 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | ||
289 | } | ||
290 | #endif | ||
291 | break; | ||
292 | case CAL_REPEAT_DAYOFWEEK: | ||
293 | repeat_dayofweek = Note->Entries[i].Number; | ||
294 | repeating = true; | ||
295 | break; | ||
296 | case CAL_REPEAT_DAY: | ||
297 | repeat_day = Note->Entries[i].Number; | ||
298 | repeating = true; | ||
299 | break; | ||
300 | case CAL_REPEAT_WEEKOFMONTH: | ||
301 | repeat_weekofmonth = Note->Entries[i].Number; | ||
302 | repeating = true; | ||
303 | break; | ||
304 | case CAL_REPEAT_MONTH: | ||
305 | repeat_month = Note->Entries[i].Number; | ||
306 | repeating = true; | ||
307 | break; | ||
308 | case CAL_REPEAT_FREQUENCY: | ||
309 | repeat_frequency = Note->Entries[i].Number; | ||
310 | repeating = true; | ||
311 | break; | ||
312 | case CAL_REPEAT_STARTDATE: | ||
313 | repeat_startdate = Note->Entries[i].Date; | ||
314 | repeating = true; | ||
315 | break; | ||
316 | case CAL_REPEAT_STOPDATE: | ||
317 | repeat_stopdate = Note->Entries[i].Date; | ||
318 | repeating = true; | ||
319 | break; | ||
320 | } | ||
321 | } | ||
322 | #if 0 | ||
323 | event->setDescription( attList[4] ); | ||
324 | bool repeating = false; | ||
325 | int repeat_dayofweek = -1; | ||
326 | int repeat_day = -1; | ||
327 | int repeat_weekofmonth = -1; | ||
328 | int repeat_month = -1; | ||
329 | int repeat_frequency = -1; | ||
330 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | ||
331 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | ||
332 | |||
333 | #endif | ||
334 | |||
335 | QString recurString = "no"; | ||
336 | if ( repeating && repeat_frequency != -1) { | ||
337 | recurString = "y"; | ||
338 | if ( repeat_dayofweek >= 0 ) | ||
339 | recurString += "dow" + QString::number (repeat_dayofweek); | ||
340 | if ( repeat_day >= 0 ) | ||
341 | recurString += "d" + QString::number (repeat_day); | ||
342 | if ( repeat_weekofmonth >= 0 ) | ||
343 | recurString += "w" + QString::number (repeat_weekofmonth); | ||
344 | if ( repeat_month >= 0 ) | ||
345 | recurString += "m" + QString::number ( repeat_month ); | ||
346 | if ( repeat_frequency >= 0 ) | ||
347 | recurString += "f" + QString::number (repeat_frequency ); | ||
348 | |||
349 | int rtype = 0; | ||
350 | // qDebug("recurs "); | ||
351 | QDate startDate, endDate; | ||
352 | if ( repeat_startdate.Day > 0 ) { | ||
353 | startDate = datefromGSM ( &repeat_startdate ); | ||
354 | event->setDtStart(QDateTime ( startDate, event->dtStart().time())); | ||
355 | } else { | ||
356 | startDate = event->dtStart().date(); | ||
357 | } | ||
358 | int freq = repeat_frequency; | ||
359 | bool hasEndDate = false; | ||
360 | if ( repeat_stopdate.Day > 0 ) { | ||
361 | endDate = datefromGSM ( &repeat_stopdate ); | ||
362 | hasEndDate = true; | ||
363 | } | ||
364 | |||
365 | uint weekDaysNum = repeat_dayofweek ; | ||
366 | // 1 == monday, 7 == sunday | ||
367 | QBitArray weekDays( 7 ); | ||
368 | int i; | ||
369 | int bb = 1; | ||
370 | for( i = 1; i <= 7; ++i ) { | ||
371 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | ||
372 | bb = 2 << (i-1); | ||
373 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | ||
374 | } | ||
375 | // qDebug("next "); | ||
376 | int pos = 0; | ||
377 | Recurrence *r = event->recurrence(); | ||
378 | /* | ||
379 | 0 daily; | ||
380 | 1 weekly;x | ||
381 | 2 monthpos;x | ||
382 | 3 monthlyday; | ||
383 | 4 rYearlyMont | ||
384 | bool repeating = false; | ||
385 | int repeat_dayofweek = -1; | ||
386 | int repeat_day = -1; | ||
387 | int repeat_weekofmonth = -1; | ||
388 | int repeat_month = -1; | ||
389 | int repeat_frequency = -1; | ||
390 | */ | ||
391 | int dayOfWeek = startDate.dayOfWeek(); | ||
392 | if ( repeat_weekofmonth >= 0 ) { | ||
393 | rtype = 2; // ************************ 2 MonthlyPos | ||
394 | pos = repeat_weekofmonth; | ||
395 | if ( repeat_dayofweek >= 0 ) | ||
396 | dayOfWeek = repeat_dayofweek; | ||
397 | if (repeat_month > 0) { | ||
398 | if ( repeat_month != event->dtStart().date().month() ) { | ||
399 | QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); | ||
400 | event->setDtStart(QDateTime ( date , event->dtStart().time()) ); | ||
401 | } | ||
402 | if ( freq == 1 ) | ||
403 | freq = 12; | ||
404 | } | ||
405 | } else if ( repeat_dayofweek >= 0 ) { | ||
406 | rtype = 1;// ************************ 1 Weekly | ||
407 | } else if ( repeat_day >= 0 ) { | ||
408 | if ( repeat_month > 0) { | ||
409 | rtype = 4; | ||
410 | } else { | ||
411 | rtype = 3; | ||
412 | } | ||
413 | } else { | ||
414 | rtype = 0 ; | ||
415 | } | ||
416 | |||
417 | if ( rtype == 0 ) { | ||
418 | if ( hasEndDate ) r->setDaily( freq, endDate ); | ||
419 | else r->setDaily( freq, -1 ); | ||
420 | } else if ( rtype == 1 ) { | ||
421 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | ||
422 | else r->setWeekly( freq, weekDays, -1 ); | ||
423 | } else if ( rtype == 3 ) { | ||
424 | if ( hasEndDate ) | ||
425 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | ||
426 | else | ||
427 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | ||
428 | r->addMonthlyDay( startDate.day() ); | ||
429 | } else if ( rtype == 2 ) { | ||
430 | if ( hasEndDate ) | ||
431 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | ||
432 | else | ||
433 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | ||
434 | QBitArray days( 7 ); | ||
435 | days.fill( false ); | ||
436 | days.setBit( dayOfWeek - 1 ); | ||
437 | r->addMonthlyPos( pos, days ); | ||
438 | } else if ( rtype == 4 ) { | ||
439 | if ( hasEndDate ) | ||
440 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | ||
441 | else | ||
442 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | ||
443 | r->addYearlyNum( startDate.month() ); | ||
444 | } | ||
445 | } else { | ||
446 | event->recurrence()->unsetRecurs(); | ||
447 | } | ||
448 | |||
449 | QStringList cat = event->categories(); | ||
450 | QString nCat = getCategory( Note ); | ||
451 | |||
452 | if ( !nCat.isEmpty() ) | ||
453 | if ( !cat.contains( nCat )) { | ||
454 | cat << nCat; | ||
455 | event->setCategories( cat ); | ||
456 | } | ||
457 | |||
458 | if ( alarm ) { | ||
459 | Alarm *alarm; | ||
460 | if ( event->alarms().count() > 0 ) | ||
461 | alarm = event->alarms().first(); | ||
462 | else { | ||
463 | alarm = new Alarm( event ); | ||
464 | event->addAlarm( alarm ); | ||
465 | } | ||
466 | alarm->setType( Alarm::Audio ); | ||
467 | alarm->setEnabled( true ); | ||
468 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); | ||
469 | alarm->setStartOffset( -alarmOffset ); | ||
470 | } else { | ||
471 | Alarm *alarm; | ||
472 | if ( event->alarms().count() > 0 ) { | ||
473 | alarm = event->alarms().first(); | ||
474 | alarm->setType( Alarm::Audio ); | ||
475 | alarm->setStartOffset( -60*15 ); | ||
476 | alarm->setEnabled( false ); | ||
477 | } | ||
478 | } | ||
479 | // csum ***************************************** | ||
480 | |||
481 | uint cSum; | ||
482 | cSum = PhoneFormat::getCsumEvent( event ); | ||
483 | event->setCsum( mProfileName, QString::number( cSum )); | ||
484 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
485 | mCalendar->addEvent( event); | ||
486 | |||
487 | return true; | ||
488 | } | ||
489 | |||
490 | |||
491 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = false ) { | ||
492 | QDateTime dt; | ||
493 | int y,m,t,h,min,sec; | ||
494 | y = dtp->Year; | ||
495 | m = dtp->Month; | ||
496 | t = dtp->Day; | ||
497 | h = dtp->Hour; | ||
498 | min = dtp->Minute; | ||
499 | sec = dtp->Second; | ||
500 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | ||
501 | // dtp->Timezone: offset in hours | ||
502 | int offset = KGlobal::locale()->localTimeOffset( dt ); | ||
503 | if ( useTz ) | ||
504 | dt = dt.addSecs ( offset*60); | ||
505 | return dt; | ||
506 | |||
507 | } | ||
508 | |||
509 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) | 55 | static QString dtToString( const QDateTime& dti, bool useTZ = false ) |
510 | { | 56 | { |
511 | QString datestr; | 57 | QString datestr; |
512 | QString timestr; | 58 | QString timestr; |
513 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 59 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
514 | QDateTime dt; | 60 | QDateTime dt; |
515 | if (useTZ) | 61 | if (useTZ) |
516 | dt = dti.addSecs ( -(offset*60)); | 62 | dt = dti.addSecs ( -(offset*60)); |
517 | else | 63 | else |
518 | dt = dti; | 64 | dt = dti; |
519 | if(dt.date().isValid()){ | 65 | if(dt.date().isValid()){ |
520 | const QDate& date = dt.date(); | 66 | const QDate& date = dt.date(); |
521 | datestr.sprintf("%04d%02d%02d", | 67 | datestr.sprintf("%04d%02d%02d", |
522 | date.year(), date.month(), date.day()); | 68 | date.year(), date.month(), date.day()); |
523 | } | 69 | } |
524 | if(dt.time().isValid()){ | 70 | if(dt.time().isValid()){ |
525 | const QTime& time = dt.time(); | 71 | const QTime& time = dt.time(); |
526 | timestr.sprintf("T%02d%02d%02d", | 72 | timestr.sprintf("T%02d%02d%02d", |
527 | time.hour(), time.minute(), time.second()); | 73 | time.hour(), time.minute(), time.second()); |
528 | } | 74 | } |
529 | return datestr + timestr; | 75 | return datestr + timestr; |
530 | } | 76 | } |
531 | QDate datefromGSM ( GSM_DateTime*dtp ) { | ||
532 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); | ||
533 | } | ||
534 | QString getCategory( GSM_CalendarEntry*Note) | ||
535 | { | ||
536 | QString CATEGORY; | ||
537 | switch (Note->Type) { | ||
538 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; | ||
539 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; | ||
540 | //case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; | ||
541 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; | ||
542 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; | ||
543 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; | ||
544 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; | ||
545 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; | ||
546 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; | ||
547 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; | ||
548 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; | ||
549 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; | ||
550 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; | ||
551 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; | ||
552 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; | ||
553 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; | ||
554 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; | ||
555 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; | ||
556 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; | ||
557 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; | ||
558 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; | ||
559 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; | ||
560 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; | ||
561 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; | ||
562 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; | ||
563 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; | ||
564 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; | ||
565 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; | ||
566 | default : CATEGORY = QString(""); | ||
567 | } | ||
568 | 77 | ||
569 | return CATEGORY; | ||
570 | } | ||
571 | 78 | ||
572 | protected: | ||
573 | private: | ||
574 | Calendar *mCalendar; | ||
575 | QString mProfileName ; | ||
576 | }; | 79 | }; |
577 | 80 | ||
81 | |||
578 | 82 | ||
579 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) | 83 | PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) |
580 | { | 84 | { |
581 | mProfileName = profileName; | 85 | mProfileName = profileName; |
582 | mDevice = device; | 86 | mDevice = device; |
583 | mConnection = connection; | 87 | mConnection = connection; |
584 | mModel = model; | 88 | mModel = model; |
585 | } | 89 | } |
586 | 90 | ||
587 | PhoneFormat::~PhoneFormat() | 91 | PhoneFormat::~PhoneFormat() |
588 | { | 92 | { |
589 | } | 93 | } |
94 | #if 0 | ||
590 | int PhoneFormat::initDevice(GSM_StateMachine *s) | 95 | int PhoneFormat::initDevice(GSM_StateMachine *s) |
591 | { | 96 | { |
592 | GSM_ReadConfig(NULL, &s->Config[0], 0); | 97 | GSM_ReadConfig(NULL, &s->Config[0], 0); |
593 | s->ConfigNum = 1; | 98 | s->ConfigNum = 1; |
594 | GSM_Config *cfg = &s->Config[0]; | 99 | GSM_Config *cfg = &s->Config[0]; |
595 | if ( ! mConnection.isEmpty() ) { | 100 | if ( ! mConnection.isEmpty() ) { |
596 | cfg->Connection = strdup(mConnection.latin1()); | 101 | cfg->Connection = strdup(mConnection.latin1()); |
597 | cfg->DefaultConnection = false; | 102 | cfg->DefaultConnection = false; |
598 | qDebug("Connection set %s ", cfg->Connection ); | 103 | qDebug("Connection set %s ", cfg->Connection ); |
599 | 104 | ||
600 | } | 105 | } |
601 | if ( ! mDevice.isEmpty() ) { | 106 | if ( ! mDevice.isEmpty() ) { |
602 | cfg->Device = strdup(mDevice.latin1()); | 107 | cfg->Device = strdup(mDevice.latin1()); |
603 | cfg->DefaultDevice = false; | 108 | cfg->DefaultDevice = false; |
604 | qDebug("Device set %s ", cfg->Device); | 109 | qDebug("Device set %s ", cfg->Device); |
605 | 110 | ||
606 | } | 111 | } |
607 | if ( ! mModel.isEmpty() ) { | 112 | if ( ! mModel.isEmpty() ) { |
608 | strcpy(cfg->Model,mModel.latin1() ); | 113 | strcpy(cfg->Model,mModel.latin1() ); |
609 | cfg->DefaultModel = false; | 114 | cfg->DefaultModel = false; |
610 | qDebug("Model set %s ",cfg->Model ); | 115 | qDebug("Model set %s ",cfg->Model ); |
611 | } | 116 | } |
612 | int error=GSM_InitConnection(s,3); | 117 | int error=GSM_InitConnection(s,3); |
613 | return error; | 118 | return error; |
614 | } | 119 | } |
120 | #endif | ||
615 | ulong PhoneFormat::getCsumTodo( Todo* todo ) | 121 | ulong PhoneFormat::getCsumTodo( Todo* todo ) |
616 | { | 122 | { |
617 | QStringList attList; | 123 | QStringList attList; |
618 | if ( todo->hasDueDate() ) | 124 | if ( todo->hasDueDate() ) |
619 | attList << PhoneParser::dtToString ( todo->dtDue() ); | 125 | attList << PhoneParser::dtToString ( todo->dtDue() ); |
620 | attList << todo->summary(); | 126 | attList << todo->summary(); |
621 | QString completedString = "no"; | 127 | QString completedString = "no"; |
622 | if ( todo->isCompleted() ) | 128 | if ( todo->isCompleted() ) |
623 | completedString = "yes"; | 129 | completedString = "yes"; |
624 | attList << completedString; | 130 | attList << completedString; |
625 | attList << QString::number( todo->priority() ); | 131 | attList << QString::number( todo->priority() ); |
626 | QString alarmString = "na"; | 132 | QString alarmString = "na"; |
627 | Alarm *alarm; | 133 | Alarm *alarm; |
628 | if ( todo->alarms().count() > 0 ) { | 134 | if ( todo->alarms().count() > 0 ) { |
629 | alarm = todo->alarms().first(); | 135 | alarm = todo->alarms().first(); |
630 | if ( alarm->enabled() ) { | 136 | if ( alarm->enabled() ) { |
631 | alarmString = QString::number(alarm->startOffset().asSeconds() ); | 137 | alarmString = QString::number(alarm->startOffset().asSeconds() ); |
632 | } | 138 | } |
633 | } | 139 | } |
634 | attList << alarmString; | 140 | attList << alarmString; |
635 | attList << todo->categoriesStr(); | 141 | attList << todo->categoriesStr(); |
636 | attList << todo->secrecyStr(); | 142 | attList << todo->secrecyStr(); |
637 | return PhoneFormat::getCsum(attList ); | 143 | return PhoneFormat::getCsum(attList ); |
638 | 144 | ||
639 | } | 145 | } |
640 | ulong PhoneFormat::getCsumEvent( Event* event ) | 146 | ulong PhoneFormat::getCsumEvent( Event* event ) |
641 | { | 147 | { |
642 | QStringList attList; | 148 | QStringList attList; |
643 | attList << PhoneParser::dtToString ( event->dtStart() ); | 149 | attList << PhoneParser::dtToString ( event->dtStart() ); |
644 | attList << PhoneParser::dtToString ( event->dtEnd() ); | 150 | attList << PhoneParser::dtToString ( event->dtEnd() ); |
645 | attList << event->summary(); | 151 | attList << event->summary(); |
646 | attList << event->location(); | 152 | attList << event->location(); |
647 | QString alarmString = "na"; | 153 | QString alarmString = "na"; |
648 | Alarm *alarm; | 154 | Alarm *alarm; |
649 | if ( event->alarms().count() > 0 ) { | 155 | if ( event->alarms().count() > 0 ) { |
650 | alarm = event->alarms().first(); | 156 | alarm = event->alarms().first(); |
651 | if ( alarm->enabled() ) { | 157 | if ( alarm->enabled() ) { |
652 | alarmString = QString::number( alarm->startOffset().asSeconds() ); | 158 | alarmString = QString::number( alarm->startOffset().asSeconds() ); |
653 | } | 159 | } |
654 | } | 160 | } |
655 | attList << alarmString; | 161 | attList << alarmString; |
656 | Recurrence* rec = event->recurrence(); | 162 | Recurrence* rec = event->recurrence(); |
657 | QStringList list; | 163 | QStringList list; |
658 | bool writeEndDate = false; | 164 | bool writeEndDate = false; |
659 | switch ( rec->doesRecur() ) | 165 | switch ( rec->doesRecur() ) |
660 | { | 166 | { |
661 | case Recurrence::rDaily: // 0 | 167 | case Recurrence::rDaily: // 0 |
662 | list.append( "0" ); | 168 | list.append( "0" ); |
@@ -726,966 +232,350 @@ ulong PhoneFormat::getCsumEvent( Event* event ) | |||
726 | list.append( "0" ); | 232 | list.append( "0" ); |
727 | list.append( "20991231T000000" ); | 233 | list.append( "20991231T000000" ); |
728 | break; | 234 | break; |
729 | } | 235 | } |
730 | if ( writeEndDate ) { | 236 | if ( writeEndDate ) { |
731 | 237 | ||
732 | if ( rec->endDate().isValid() ) { // 15 + 16 | 238 | if ( rec->endDate().isValid() ) { // 15 + 16 |
733 | list.append( "1" ); | 239 | list.append( "1" ); |
734 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 240 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
735 | } else { | 241 | } else { |
736 | list.append( "0" ); | 242 | list.append( "0" ); |
737 | list.append( "20991231T000000" ); | 243 | list.append( "20991231T000000" ); |
738 | } | 244 | } |
739 | 245 | ||
740 | } | 246 | } |
741 | attList << list.join(""); | 247 | attList << list.join(""); |
742 | attList << event->categoriesStr(); | 248 | attList << event->categoriesStr(); |
743 | attList << event->secrecyStr(); | 249 | attList << event->secrecyStr(); |
744 | return PhoneFormat::getCsum(attList ); | 250 | return PhoneFormat::getCsum(attList ); |
745 | } | 251 | } |
746 | ulong PhoneFormat::getCsum( const QStringList & attList) | 252 | ulong PhoneFormat::getCsum( const QStringList & attList) |
747 | { | 253 | { |
748 | int max = attList.count() -1; | 254 | int max = attList.count() -1; |
749 | ulong cSum = 0; | 255 | ulong cSum = 0; |
750 | int j,k,i; | 256 | int j,k,i; |
751 | int add; | 257 | int add; |
752 | for ( i = 1; i < max ; ++i ) { | 258 | for ( i = 1; i < max ; ++i ) { |
753 | QString s = attList[i]; | 259 | QString s = attList[i]; |
754 | if ( ! s.isEmpty() ){ | 260 | if ( ! s.isEmpty() ){ |
755 | j = s.length(); | 261 | j = s.length(); |
756 | for ( k = 0; k < j; ++k ) { | 262 | for ( k = 0; k < j; ++k ) { |
757 | int mul = k +1; | 263 | int mul = k +1; |
758 | add = s[k].unicode (); | 264 | add = s[k].unicode (); |
759 | if ( k < 16 ) | 265 | if ( k < 16 ) |
760 | mul = mul * mul; | 266 | mul = mul * mul; |
761 | add = add * mul *i*i*i; | 267 | add = add * mul *i*i*i; |
762 | cSum += add; | 268 | cSum += add; |
763 | } | 269 | } |
764 | } | 270 | } |
765 | } | 271 | } |
766 | return cSum; | 272 | return cSum; |
767 | 273 | ||
768 | } | 274 | } |
769 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 275 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
770 | #include <stdlib.h> | 276 | #include <stdlib.h> |
771 | #define DEBUGMODE false | 277 | #define DEBUGMODE false |
772 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 278 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
773 | { | 279 | { |
774 | GSM_StateMachines; | ||
775 | qDebug(" load "); | ||
776 | s.opened = false; | ||
777 | s.msg = NULL; | ||
778 | s.ConfigNum = 0; | ||
779 | QLabel status ( i18n("Opening device ..."), 0 ); | ||
780 | int w = status.sizeHint().width()+20 ; | ||
781 | if ( w < 200 ) w = 230; | ||
782 | int h = status.sizeHint().height()+20 ; | ||
783 | int dw = QApplication::desktop()->width(); | ||
784 | int dh = QApplication::desktop()->height(); | ||
785 | status.setCaption(i18n("Reading phone...") ); | ||
786 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | ||
787 | status.show(); | ||
788 | status.raise(); | ||
789 | qApp->processEvents(); | ||
790 | 280 | ||
791 | int error=initDevice(&s); | 281 | QString fileName; |
792 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 282 | #ifdef _WIN32_ |
793 | if ( error != ERR_NONE ) | 283 | fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
284 | #else | ||
285 | fileName = "/tmp/kdepimtemp.vcs"; | ||
286 | #endif | ||
287 | QString command ="./kammu --backup " + fileName + " -yes"; | ||
288 | int ret = system ( command.latin1() ); | ||
289 | if ( ret != 0 ) | ||
794 | return false; | 290 | return false; |
795 | GSM_Phone_Functions*Phone; | 291 | VCalFormat vfload; |
796 | GSM_CalendarEntrynote; | 292 | vfload.setLocalTime ( true ); |
797 | bool start = true; | 293 | if ( ! vfload.load( calendar, fileName ) ) |
798 | Phone=s.Phone.Functions; | 294 | return false; |
799 | bool gshutdown = false; | 295 | QPtrList<Event> er = calendar->rawEvents(); |
800 | PhoneParser handler( calendar, mProfileName ); | 296 | Event* ev = er.first(); |
801 | int ccc = 0; | 297 | while ( ev ) { |
802 | QString message = i18n(" Reading event # "); | 298 | int id = ev->pilotId(); |
803 | int procCount = 0; | 299 | Event *event; |
804 | qDebug("Debug: only 10 calender items are downloaded "); | 300 | event = existingCal->event( mProfileName ,QString::number( id ) ); |
805 | while (!gshutdown && ccc++ < 10) { | 301 | if ( event ) { |
806 | status.setText ( message + QString::number ( ++procCount ) ); | 302 | event = (Event*)event->clone(); |
807 | qApp->processEvents(); | 303 | copyEvent( event, ev ); |
808 | qDebug("readEvent %d ", ccc); | 304 | calendar->deleteEvent( ev ); |
809 | error=Phone->GetNextCalendar(&s,¬e,start); | 305 | calendar->addEvent( event); |
810 | if (error == ERR_EMPTY) break; | 306 | } |
811 | start = false; | 307 | else |
812 | handler.readEvent( existingCal, ¬e ); | 308 | event = ev; |
813 | qDebug("Org loc %d ",note.Location); | 309 | uint cSum; |
814 | //note.Location = 0; | 310 | cSum = PhoneFormat::getCsumEvent( event ); |
815 | error=Phone->SetCalendar(&s,¬e); | 311 | event->setCsum( mProfileName, QString::number( cSum )); |
816 | qDebug("new loc %d ",note.Location); | 312 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
313 | event->setID( mProfileName,QString::number( id ) ); | ||
314 | ev = er.next(); | ||
315 | } | ||
316 | { | ||
317 | QPtrList<Todo> tr = calendar->rawTodos(); | ||
318 | Todo* ev = tr.first(); | ||
319 | while ( ev ) { | ||
320 | |||
321 | QStringList cat = ev->categories(); | ||
322 | if ( cat.contains( "MeetingDEF" )) { | ||
323 | ev->setCategories( QStringList() ); | ||
324 | } | ||
325 | int id = ev->pilotId(); | ||
326 | Todo *event; | ||
327 | event = existingCal->todo( mProfileName ,QString::number( id ) ); | ||
328 | if ( event ) { | ||
329 | event = (Todo*)event->clone(); | ||
330 | copyTodo( event, ev ); | ||
331 | calendar->deleteTodo( ev ); | ||
332 | calendar->addTodo( event); | ||
333 | } | ||
334 | else | ||
335 | event = ev; | ||
336 | uint cSum; | ||
337 | cSum = PhoneFormat::getCsumTodo( event ); | ||
338 | event->setCsum( mProfileName, QString::number( cSum )); | ||
339 | event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | ||
340 | event->setID( mProfileName,QString::number( id ) ); | ||
341 | ev = tr.next(); | ||
342 | } | ||
817 | } | 343 | } |
818 | |||
819 | start = true; | ||
820 | GSM_ToDoEntry ToDo; | ||
821 | ccc = 0; | ||
822 | message = i18n(" Reading todo # "); | ||
823 | procCount = 0; | ||
824 | while (!gshutdown && ccc++ < 10) { | ||
825 | status.setText ( message + QString::number ( ++procCount ) ); | ||
826 | qApp->processEvents(); | ||
827 | error = Phone->GetNextToDo(&s, &ToDo, start); | ||
828 | if (error == ERR_EMPTY) break; | ||
829 | start = false; | ||
830 | qDebug("ReadTodo %d ", ccc); | ||
831 | handler.readTodo( existingCal, &ToDo, &s); | ||
832 | |||
833 | } | ||
834 | |||
835 | error=GSM_TerminateConnection(&s); | ||
836 | |||
837 | return true; | 344 | return true; |
838 | } | 345 | } |
839 | #include <qcstring.h> | 346 | void PhoneFormat::copyEvent( Event* to, Event* from ) |
840 | void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) | ||
841 | { | 347 | { |
842 | QString eText = vfconverter.eventToString( ev, cal ); | 348 | if ( from->dtStart().isValid() ) |
843 | int pos = 0; | 349 | to->setDtStart( from->dtStart() ); |
844 | GSM_ToDoEntry dummy; | 350 | if ( from->dtEnd().isValid() ) |
845 | qDebug( "Convert event"); | 351 | to->setDtEnd( from->dtEnd() ); |
846 | QByteArray ba; | 352 | if ( !from->location().isEmpty() ) |
847 | QDataStream s ( ba, IO_WriteOnly ); | 353 | to->setLocation( from->location() ); |
848 | s << eText.utf8(); | 354 | if ( !from->description().isEmpty() ) |
849 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | 355 | to->setDescription( from->description() ); |
850 | qDebug( "Convert event done"); | 356 | if ( !from->summary().isEmpty() ) |
851 | Note->Location = 0; | 357 | to->setSummary( from->summary() ); |
852 | QString loc = ev->getID(mProfileName); | 358 | |
853 | if ( !loc.isEmpty() ){ | 359 | QPtrListIterator<Alarm> it( from->alarms() ); |
854 | Note->Location = loc.toInt(); | 360 | to->clearAlarms(); |
361 | const Alarm *a; | ||
362 | while( (a = it.current()) ) { | ||
363 | Alarm *b = new Alarm( *a ); | ||
364 | b->setParent( to ); | ||
365 | to->addAlarm( b ); | ||
366 | ++it; | ||
367 | } | ||
368 | QStringList cat = to->categories(); | ||
369 | QStringList catFrom = from->categories(); | ||
370 | QString nCat; | ||
371 | int iii; | ||
372 | for ( iii = 0; iii < catFrom.count();++iii ) { | ||
373 | nCat = catFrom[iii]; | ||
374 | if ( !nCat.isEmpty() ) | ||
375 | if ( !cat.contains( nCat )) { | ||
376 | cat << nCat; | ||
377 | } | ||
855 | } | 378 | } |
379 | to->setCategories( cat ); | ||
380 | Recurrence * r = new Recurrence( *from->recurrence(),to); | ||
381 | to->setRecurrence( r ) ; | ||
382 | |||
856 | 383 | ||
857 | } | 384 | } |
858 | void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) | 385 | void PhoneFormat::copyTodo( Todo* to, Todo* from ) |
859 | { | 386 | { |
860 | qDebug( "Convert todo1"); | 387 | if ( from->dtStart().isValid() ) |
861 | QString tText = vfconverter.todoToString( todo, cal ); | 388 | to->setDtStart( from->dtStart() ); |
862 | int pos = 0; | 389 | if ( from->dtDue().isValid() ) |
863 | GSM_CalendarEntry dummy; | 390 | to->setDtDue( from->dtDue() ); |
864 | QByteArray ba; | 391 | if ( !from->location().isEmpty() ) |
865 | QDataStream s ( ba, IO_WriteOnly ); | 392 | to->setLocation( from->location() ); |
866 | s << tText.utf8(); | 393 | if ( !from->description().isEmpty() ) |
867 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | 394 | to->setDescription( from->description() ); |
868 | qDebug( "Convert todo done "); | 395 | if ( !from->summary().isEmpty() ) |
869 | gsmTodo->Location = 0; | 396 | to->setSummary( from->summary() ); |
870 | QString loc = todo->getID(mProfileName); | 397 | |
871 | if ( !loc.isEmpty() ){ | 398 | QPtrListIterator<Alarm> it( from->alarms() ); |
872 | gsmTodo->Location = loc.toInt(); | 399 | to->clearAlarms(); |
400 | const Alarm *a; | ||
401 | while( (a = it.current()) ) { | ||
402 | Alarm *b = new Alarm( *a ); | ||
403 | b->setParent( to ); | ||
404 | to->addAlarm( b ); | ||
405 | ++it; | ||
406 | } | ||
407 | QStringList cat = to->categories(); | ||
408 | QStringList catFrom = from->categories(); | ||
409 | QString nCat; | ||
410 | int iii; | ||
411 | for ( iii = 0; iii < catFrom.count();++iii ) { | ||
412 | nCat = catFrom[iii]; | ||
413 | if ( !nCat.isEmpty() ) | ||
414 | if ( !cat.contains( nCat )) { | ||
415 | cat << nCat; | ||
416 | } | ||
873 | } | 417 | } |
874 | 418 | to->setCategories( cat ); | |
419 | if ( from->isCompleted() ) { | ||
420 | to->setCompleted( true ); | ||
421 | if( from->completed().isValid() ) | ||
422 | to->setCompleted( from->completed() ); | ||
423 | } else { | ||
424 | // set percentcomplete only, if to->isCompleted() | ||
425 | if ( to->isCompleted() ) | ||
426 | to->setPercentComplete(from->percentComplete()); | ||
427 | } | ||
428 | to->setPriority(from->priority()); | ||
429 | |||
875 | } | 430 | } |
431 | #include <qcstring.h> | ||
432 | |||
876 | void PhoneFormat::afterSave( Incidence* inc) | 433 | void PhoneFormat::afterSave( Incidence* inc) |
877 | { | 434 | { |
878 | uint csum; | 435 | uint csum; |
879 | inc->removeID( mProfileName ); | 436 | inc->removeID( mProfileName ); |
880 | if ( inc->type() == "Event") | 437 | if ( inc->type() == "Event") |
881 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 438 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
882 | else | 439 | else |
883 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 440 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
884 | inc->setCsum( mProfileName, QString::number( csum )); | 441 | inc->setCsum( mProfileName, QString::number( csum )); |
885 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 442 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
886 | 443 | ||
887 | } | 444 | } |
888 | bool PhoneFormat::save( Calendar *calendar) | 445 | bool PhoneFormat::save( Calendar *calendar) |
889 | { | 446 | { |
890 | |||
891 | GSM_StateMachines; | ||
892 | qDebug(" save "); | ||
893 | s.opened = false; | ||
894 | s.msg = NULL; | ||
895 | s.ConfigNum = 0; | ||
896 | QLabel status ( i18n(" Opening device ..."), 0 ); | 447 | QLabel status ( i18n(" Opening device ..."), 0 ); |
897 | int w = status.sizeHint().width()+20 ; | 448 | int w = status.sizeHint().width()+20 ; |
898 | if ( w < 200 ) w = 230; | 449 | if ( w < 200 ) w = 230; |
899 | int h = status.sizeHint().height()+20 ; | 450 | int h = status.sizeHint().height()+20 ; |
900 | int dw = QApplication::desktop()->width(); | 451 | int dw = QApplication::desktop()->width(); |
901 | int dh = QApplication::desktop()->height(); | 452 | int dh = QApplication::desktop()->height(); |
902 | status.setCaption(i18n("Writing to phone...") ); | 453 | status.setCaption(i18n("Writing to phone...") ); |
903 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 454 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
904 | status.show(); | 455 | status.show(); |
905 | status.raise(); | 456 | status.raise(); |
906 | qApp->processEvents(); | 457 | qApp->processEvents(); |
907 | 458 | QString message; | |
908 | int error=initDevice(&s); | ||
909 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | ||
910 | if ( error != ERR_NONE ) | ||
911 | return false; | ||
912 | GSM_Phone_Functions*Phone; | ||
913 | GSM_CalendarEntryNote; | ||
914 | bool start = true; | ||
915 | Phone=s.Phone.Functions; | ||
916 | bool gshutdown = false; | ||
917 | QPtrList<Event> er = calendar->rawEvents(); | ||
918 | Event* ev = er.first(); | ||
919 | QString message = i18n(" Deleting event # "); | ||
920 | int procCount = 0; | ||
921 | int diffProc = 0; | ||
922 | bool setPossible = true; | ||
923 | #ifdef _WIN32_ | 459 | #ifdef _WIN32_ |
924 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; | 460 | QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; |
925 | #else | 461 | #else |
926 | QString fileName = "/tmp/kdepimtemp.vcs"; | 462 | QString fileName = "/tmp/kdepimtemp.vcs"; |
927 | #endif | 463 | #endif |
928 | //algo 1 delete event | ||
929 | while ( ev ) { | ||
930 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | ||
931 | |||
932 | status.setText ( message + QString::number ( ++procCount ) ); | ||
933 | qApp->processEvents(); | ||
934 | qDebug("del event1 %d ", procCount); | ||
935 | //event2GSM( calendar, ev, &Note ); | ||
936 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
937 | 464 | ||
938 | QString loc = ev->getID(mProfileName); | 465 | // 1 remove events which should be deleted |
939 | if ( !loc.isEmpty() ){ | 466 | QPtrList<Event> er = calendar->rawEvents(); |
940 | Note.Location = loc.toInt(); | 467 | Event* ev = er.first(); |
941 | } else { | 468 | while ( ev ) { |
942 | qDebug("error: loc is empty "); | 469 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
943 | } | 470 | calendar->deleteEvent( ev ); |
944 | error = Phone->DeleteCalendar(&s, &Note); | 471 | } else { |
945 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
946 | qDebug(" e error delete1 planB %d ", error); | ||
947 | break; | ||
948 | } | ||
949 | } | ||
950 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | ||
951 | // we have to do this later after deleting | ||
952 | |||
953 | } | ||
954 | else { // change existing | ||
955 | 472 | ||
956 | QString loc = ev->getID(mProfileName); | 473 | } |
957 | if ( !loc.isEmpty() ){ | ||
958 | Note.Location = loc.toInt(); | ||
959 | } else { | ||
960 | qDebug("error3: loc is empty "); | ||
961 | } | ||
962 | error = Phone->DeleteCalendar(&s, &Note); | ||
963 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
964 | qDebug(" e error delete2 planB %d ", error); | ||
965 | break; | ||
966 | } | ||
967 | ev->removeID( mProfileName ); | ||
968 | } | ||
969 | } | ||
970 | ev = er.next(); | 474 | ev = er.next(); |
971 | } | 475 | } |
972 | //algo 1 delete todo | 476 | // 2 remove todos which should be deleted |
973 | GSM_ToDoEntry ToDoEntry; | ||
974 | QPtrList<Todo> tl = calendar->rawTodos(); | 477 | QPtrList<Todo> tl = calendar->rawTodos(); |
975 | Todo* to = tl.first(); | 478 | Todo* to = tl.first(); |
976 | message = i18n(" Deleting todo # "); | ||
977 | procCount = 0; | ||
978 | while ( to ) { | 479 | while ( to ) { |
979 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 480 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
980 | qDebug("todo3 %d ", procCount); | 481 | calendar->deleteTodo( to ); |
981 | status.setText ( message + QString::number ( ++procCount ) ); | ||
982 | qApp->processEvents(); | ||
983 | qDebug("todo5 %d ", procCount); | ||
984 | // todo2GSM( calendar, to, &ToDoEntry ); | ||
985 | QString loc = to->getID(mProfileName); | ||
986 | if ( !loc.isEmpty() ){ | ||
987 | ToDoEntry.Location = loc.toInt(); | ||
988 | } else { | ||
989 | qDebug("error2: loc is empty "); | ||
990 | } | ||
991 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
992 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
993 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
994 | qDebug("delete planB %d ", error); | ||
995 | } | ||
996 | } | ||
997 | else if ( to->getID(mProfileName).isEmpty() ) { // add new | ||
998 | ; | ||
999 | } | ||
1000 | else { // change existing | ||
1001 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
1002 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1003 | qDebug("set planB %d ", error); | ||
1004 | } | ||
1005 | to->removeID( mProfileName ); | ||
1006 | } | ||
1007 | } | 482 | } |
1008 | to = tl.next(); | 483 | to = tl.next(); |
1009 | } | 484 | } |
1010 | //algo 2 add event | 485 | // 3 save file |
1011 | ev = er.first(); | 486 | VCalFormat vfsave; |
1012 | QString filec; | 487 | vfsave.setLocalTime ( true ); |
1013 | message = i18n(" Preparing event # "); | 488 | if ( ! vfsave.save( calendar, fileName ) ) |
1014 | procCount = 0; | ||
1015 | while ( ev ) { | ||
1016 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1017 | if ( ev->getID(mProfileName).isEmpty() ) { | ||
1018 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1019 | qApp->processEvents(); | ||
1020 | filec += vfconverter.eventToString( ev, calendar )+ "\n"; | ||
1021 | afterSave ( ev ); | ||
1022 | |||
1023 | } | ||
1024 | } | ||
1025 | ev = er.next(); | ||
1026 | } | ||
1027 | //algo 2 add todo | ||
1028 | to = tl.first(); | ||
1029 | procCount = 0; | ||
1030 | message = i18n(" Preparing todo # "); | ||
1031 | while ( to ) { | ||
1032 | qDebug("todo2 %d ", procCount); | ||
1033 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1034 | qDebug("todo4 %d ", procCount); | ||
1035 | if ( to->getID(mProfileName).isEmpty() ) { | ||
1036 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1037 | qApp->processEvents(); | ||
1038 | filec += vfconverter.todoToString( to, calendar )+ "\n"; | ||
1039 | afterSave ( to ); | ||
1040 | } | ||
1041 | } | ||
1042 | to = tl.next(); | ||
1043 | } | ||
1044 | if ( filec.isEmpty() ) { | ||
1045 | qDebug("Nothing to write back.Finished. "); | ||
1046 | error=GSM_TerminateConnection(&s); | ||
1047 | return true; | ||
1048 | } | ||
1049 | //algo 3 saving file | ||
1050 | message = i18n(" Saving temp file ... "); | ||
1051 | status.setText ( message ); | ||
1052 | qApp->processEvents(); | ||
1053 | QFile file( fileName ); | ||
1054 | if (!file.open( IO_WriteOnly ) ) { | ||
1055 | qDebug("error open file "); | ||
1056 | error=GSM_TerminateConnection(&s); | ||
1057 | return false; | 489 | return false; |
1058 | } | 490 | // 4 call kammu |
1059 | QTextStream ts( &file ); | 491 | QString command ="./kammu --restore " + fileName ; |
1060 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 492 | int ret = system ( command.latin1() ); |
1061 | ts << filec ; | 493 | if ( ret != 0 ) |
1062 | file.close(); | 494 | return false; |
1063 | 495 | // 5 reread data | |
1064 | |||
1065 | message = i18n(" Parsing temp file ... "); | ||
1066 | status.setText ( message ); | ||
1067 | qApp->processEvents(); | ||
1068 | GSM_Backup Backup; | ||
1069 | error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup); | ||
1070 | qDebug("Read file result %d ",error ); | ||
1071 | //algo 4 writing event | ||
1072 | int max, i; | ||
1073 | procCount = 0; | ||
1074 | message = i18n(" Writing event # "); | ||
1075 | if (Backup.Calendar[0] != NULL) { | ||
1076 | max = 0; | ||
1077 | while (Backup.Calendar[max]!=NULL) max++; | ||
1078 | |||
1079 | GSM_DateTime*dtp; | ||
1080 | |||
1081 | for (i=0;i<max;i++) { | ||
1082 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1083 | qApp->processEvents(); | ||
1084 | Note = *Backup.Calendar[i]; | ||
1085 | |||
1086 | #if 0 | ||
1087 | int j; | ||
1088 | for (j=0;j<Note.EntriesNum;j++) { | ||
1089 | //qDebug(" for ev"); | ||
1090 | switch (Note.Entries[j].EntryType) { | ||
1091 | case CAL_START_DATETIME: | ||
1092 | //Note->Entries[i].Date.Hour = 5; | ||
1093 | dtp = &Note.Entries[j].Date; | ||
1094 | qDebug("start event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); | ||
1095 | break; | ||
1096 | case CAL_END_DATETIME: | ||
1097 | dtp = &Note.Entries[j].Date; | ||
1098 | qDebug("end event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); | ||
1099 | break; | ||
1100 | } | ||
1101 | } | ||
1102 | int type = Note.Type; | ||
1103 | qDebug(" event type %d - %d %d - %d %d %d",type, GSM_CAL_CALL , GSM_CAL_MEETING ,GSM_CAL_BIRTHDAY, GSM_CAL_MEMO ,GSM_CAL_ALARM ); | ||
1104 | #endif | ||
1105 | |||
1106 | Note.Type = GSM_CAL_MEETING; | ||
1107 | // pending: fix in gammu GSM_ReadBackupFile the type settings | ||
1108 | int loc = Note.Location; | ||
1109 | Note.Location = 0; | ||
1110 | error=Phone->AddCalendar(&s,&Note); | ||
1111 | qDebug("add event %d %d %d", error, Note.Location, loc ); | ||
1112 | } | ||
1113 | } | ||
1114 | //algo 4 writing todo | ||
1115 | procCount = 0; | ||
1116 | message = i18n(" Writing todo # "); | ||
1117 | if (Backup.ToDo[0] != NULL) { | ||
1118 | max = 0; | ||
1119 | while (Backup.ToDo[max]!=NULL) max++; | ||
1120 | for (i=0;i<max;i++) { | ||
1121 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1122 | qApp->processEvents(); | ||
1123 | ToDoEntry = *Backup.ToDo[i]; | ||
1124 | error = Phone->AddToDo(&s,&ToDoEntry); | ||
1125 | qDebug("add todo %d ", error); | ||
1126 | } | ||
1127 | } | ||
1128 | //algo 5 reread | ||
1129 | message = i18n(" Rereading all data ... "); | 496 | message = i18n(" Rereading all data ... "); |
1130 | status.setText ( message ); | 497 | status.setText ( message ); |
1131 | qApp->processEvents(); | 498 | qApp->processEvents(); |
1132 | error=GSM_TerminateConnection(&s); | ||
1133 | CalendarLocal* calendarTemp = new CalendarLocal(); | 499 | CalendarLocal* calendarTemp = new CalendarLocal(); |
1134 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); | 500 | calendarTemp->setTimeZoneId( calendar->timeZoneId()); |
1135 | if ( ! load( calendarTemp,calendar) ){ | 501 | if ( ! load( calendarTemp,calendar) ){ |
1136 | qDebug("error reloading calendar "); | 502 | qDebug("error reloading calendar "); |
1137 | delete calendarTemp; | 503 | delete calendarTemp; |
1138 | return false; | 504 | return false; |
1139 | } | 505 | } |
506 | // 6 compare data | ||
1140 | 507 | ||
1141 | 508 | //algo 6 compare event | |
1142 | //algo 6 compare event | 509 | er = calendar->rawEvents(); |
1143 | ev = er.first(); | 510 | ev = er.first(); |
1144 | message = i18n(" Comparing event # "); | 511 | message = i18n(" Comparing event # "); |
1145 | QPtrList<Event> er1 = calendarTemp->rawEvents(); | 512 | QPtrList<Event> er1 = calendarTemp->rawEvents(); |
1146 | Event* ev1; | 513 | Event* ev1; |
1147 | procCount = 0; | 514 | int procCount = 0; |
1148 | while ( ev ) { | 515 | while ( ev ) { |
1149 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { | ||
1150 | qDebug("event new ID "); | 516 | qDebug("event new ID "); |
1151 | status.setText ( message + QString::number ( ++procCount ) ); | 517 | status.setText ( message + QString::number ( ++procCount ) ); |
1152 | qApp->processEvents(); | 518 | qApp->processEvents(); |
1153 | QString cSum = ev->getCsum(mProfileName); | 519 | QString cSum = ev->getCsum(mProfileName); |
1154 | ev1 = er1.first(); | 520 | ev1 = er1.first(); |
1155 | while ( ev1 ) { | 521 | while ( ev1 ) { |
1156 | if ( ev1->getCsum( mProfileName ) == cSum ) { | 522 | if ( ev1->getCsum( mProfileName ) == cSum ) { |
1157 | er1.remove( ev1 ); | 523 | er1.remove( ev1 ); |
524 | afterSave( ev ); | ||
1158 | ev->setID(mProfileName, ev1->getID(mProfileName) ); | 525 | ev->setID(mProfileName, ev1->getID(mProfileName) ); |
1159 | break; | 526 | break; |
1160 | } | 527 | } |
1161 | ev1 = er1.next(); | 528 | ev1 = er1.next(); |
1162 | } | 529 | } |
1163 | if ( ! ev1 ) { | 530 | if ( ! ev1 ) { |
1164 | ev->removeID(mProfileName); | 531 | ev->removeID(mProfileName); |
1165 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); | 532 | qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); |
1166 | qDebug("Probably writing back of events not supported "); | ||
1167 | } | 533 | } |
1168 | 534 | ||
1169 | } | 535 | |
1170 | ev = er.next(); | 536 | ev = er.next(); |
1171 | } | 537 | } |
1172 | //algo 6 compare todo | 538 | //algo 6 compare todo |
1173 | to = tl.first(); | 539 | to = tl.first(); |
1174 | procCount = 0; | 540 | procCount = 0; |
1175 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); | 541 | QPtrList<Todo> tl1 = calendarTemp->rawTodos(); |
1176 | Todo* to1 ; | 542 | Todo* to1 ; |
1177 | message = i18n(" Comparing todo # "); | 543 | message = i18n(" Comparing todo # "); |
1178 | while ( to ) { | 544 | while ( to ) { |
1179 | qDebug("todo2 %d ", procCount); | 545 | qDebug("todo2 %d ", procCount); |
1180 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { | ||
1181 | status.setText ( message + QString::number ( ++procCount ) ); | 546 | status.setText ( message + QString::number ( ++procCount ) ); |
1182 | qApp->processEvents(); | 547 | qApp->processEvents(); |
1183 | QString cSum = to->getCsum(mProfileName); | 548 | QString cSum = to->getCsum(mProfileName); |
1184 | Todo* to1 = tl1.first(); | 549 | Todo* to1 = tl1.first(); |
1185 | while ( to1 ) { | 550 | while ( to1 ) { |
1186 | if ( to1->getCsum( mProfileName ) == cSum ) { | 551 | if ( to1->getCsum( mProfileName ) == cSum ) { |
1187 | tl1.remove( to1 ); | 552 | tl1.remove( to1 ); |
553 | afterSave( to ); | ||
1188 | to->setID(mProfileName, to1->getID(mProfileName) ); | 554 | to->setID(mProfileName, to1->getID(mProfileName) ); |
1189 | break; | 555 | break; |
1190 | } | 556 | } |
1191 | to1 = tl1.next(); | 557 | to1 = tl1.next(); |
1192 | } | 558 | } |
1193 | if ( ! to1 ) { | 559 | if ( ! to1 ) { |
1194 | to->removeID(mProfileName); | 560 | to->removeID(mProfileName); |
1195 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); | 561 | qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); |
1196 | qDebug("Probably writing back of todos not supported "); | ||
1197 | } | 562 | } |
1198 | } | 563 | |
1199 | to = tl.next(); | 564 | to = tl.next(); |
1200 | } | 565 | } |
1201 | delete calendarTemp; | 566 | delete calendarTemp; |
1202 | return true; | 567 | return true; |
1203 | // ******************************************************************* | ||
1204 | // ******************************************************************* | ||
1205 | // ******************************************************************* | ||
1206 | #if 0 | ||
1207 | while ( ev && ! planB) { | ||
1208 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | ||
1209 | |||
1210 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1211 | qApp->processEvents(); | ||
1212 | qDebug("event1 %d ", procCount); | ||
1213 | event2GSM( calendar, ev, &Note ); | ||
1214 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
1215 | error = Phone->DeleteCalendar(&s, &Note); | ||
1216 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1217 | planB = true; | ||
1218 | qDebug(" e delete1 planB %d ", error); | ||
1219 | break; | ||
1220 | } | ||
1221 | } | ||
1222 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | ||
1223 | // we have to do this later after deleting | ||
1224 | |||
1225 | } | ||
1226 | else { // change existing | ||
1227 | if ( setPossible ) { | ||
1228 | error = Phone->SetCalendar(&s, &Note); | ||
1229 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1230 | setPossible = false; | ||
1231 | ++diffProc; | ||
1232 | qDebug("Set cal not supported %d ", error); | ||
1233 | break; | ||
1234 | } | ||
1235 | } | ||
1236 | if ( ! setPossible) { | ||
1237 | ++diffProc; | ||
1238 | error = Phone->DeleteCalendar(&s, &Note); | ||
1239 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1240 | planB = true; | ||
1241 | qDebug(" e delete2 planB %d ", error); | ||
1242 | break; | ||
1243 | } | ||
1244 | ev->removeID( mProfileName ); | ||
1245 | } | ||
1246 | qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); | ||
1247 | } | ||
1248 | } | ||
1249 | ev = er.next(); | ||
1250 | } | ||
1251 | ev = er.first(); | ||
1252 | // pending get empty slots | ||
1253 | int loc = 0; | ||
1254 | procCount -= diffProc; | ||
1255 | while ( ev && ! planB) { | ||
1256 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1257 | qDebug("event2 %d ", procCount); | ||
1258 | if ( ev->getID(mProfileName).isEmpty() ) { | ||
1259 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1260 | qApp->processEvents(); | ||
1261 | //int newID ;//= pending | ||
1262 | //ev->setID(mProfileName, QString::number( newID )); | ||
1263 | event2GSM( calendar, ev, &Note ); | ||
1264 | ++loc; | ||
1265 | Note.Location = loc; | ||
1266 | error = Phone->AddCalendar(&s, &Note); | ||
1267 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1268 | planB = true; | ||
1269 | qDebug(" e add planB %d ", error); | ||
1270 | break; | ||
1271 | } | ||
1272 | ev->setID( mProfileName, QString::number( Note.Location ) ); | ||
1273 | qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); | ||
1274 | afterSave( ev ); | ||
1275 | } else { | ||
1276 | afterSave( ev ); // setting temp sync stat for changed items | ||
1277 | } | ||
1278 | } | ||
1279 | ev = er.next(); | ||
1280 | } | ||
1281 | 568 | ||
1282 | 569 | ||
1283 | if ( planB ) { | ||
1284 | qDebug("delete all calendar..."); | ||
1285 | status.setText ( i18n("Deleting all calendar...")); | ||
1286 | qApp->processEvents(); | ||
1287 | error=Phone->DeleteAllCalendar(&s); | ||
1288 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1289 | message = i18n(" Deleting event # "); | ||
1290 | procCount = 0; | ||
1291 | while (1) { | ||
1292 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1293 | qApp->processEvents(); | ||
1294 | qDebug("deleting event ... %d", procCount); | ||
1295 | error = Phone->GetNextCalendar(&s,&Note,true); | ||
1296 | if (error != ERR_NONE) break; | ||
1297 | error = Phone->DeleteCalendar(&s,&Note); | ||
1298 | } | ||
1299 | qDebug("deleting calendar ... finished"); | ||
1300 | } else { | ||
1301 | status.setText ( i18n("All calendar deleted!")); | ||
1302 | qDebug("all cal deleted"); | ||
1303 | } | ||
1304 | bool planC = false; | ||
1305 | ev = er.first(); | ||
1306 | procCount = 0; | ||
1307 | message = i18n(" Writing event # "); | ||
1308 | while ( ev && ! planC) { | ||
1309 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1310 | qApp->processEvents(); | ||
1311 | event2GSM( calendar, ev, &Note ); | ||
1312 | Note.Location = procCount; | ||
1313 | error=Phone->AddCalendar(&s,&Note); | ||
1314 | if (error != ERR_NONE ) { | ||
1315 | // we have currently no planC :-( | ||
1316 | // planC = true; | ||
1317 | //qDebug("add planC %d ", error); | ||
1318 | //break; | ||
1319 | // we remove the ID such that this todo is not deleted after next sync | ||
1320 | ev->removeID(mProfileName); | ||
1321 | ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1322 | qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1323 | } else { | ||
1324 | qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1325 | ev->setID(mProfileName, QString::number( Note.Location )); | ||
1326 | afterSave( ev ); | ||
1327 | } | ||
1328 | ev = er.next(); | ||
1329 | } | ||
1330 | if ( planC ) { | ||
1331 | qDebug("writing cal went wrong..."); | ||
1332 | 570 | ||
1333 | // we have currently no planC :-( | ||
1334 | } | ||
1335 | } | ||
1336 | GSM_ToDoEntry ToDoEntry; | ||
1337 | QPtrList<Todo> tl = calendar->rawTodos(); | ||
1338 | Todo* to = tl.first(); | ||
1339 | |||
1340 | message = i18n(" Processing todo # "); | ||
1341 | procCount = 0; | ||
1342 | planB = false; | ||
1343 | while ( to && ! planB ) { | ||
1344 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | ||
1345 | qDebug("todo3 %d ", procCount); | ||
1346 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1347 | qApp->processEvents(); | ||
1348 | qDebug("todo5 %d ", procCount); | ||
1349 | todo2GSM( calendar, to, &ToDoEntry ); | ||
1350 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | ||
1351 | error=Phone->DeleteToDo(&s,&ToDoEntry); | ||
1352 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1353 | planB = true; | ||
1354 | qDebug("delete planB %d ", error); | ||
1355 | } | ||
1356 | } | ||
1357 | else if ( to->getID(mProfileName).isEmpty() ) { // add new | ||
1358 | ; | ||
1359 | } | ||
1360 | else { // change existing | ||
1361 | error=Phone->SetToDo(&s,&ToDoEntry); | ||
1362 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1363 | planB = true; | ||
1364 | qDebug("set planB %d ", error); | ||
1365 | } | ||
1366 | qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); | ||
1367 | } | ||
1368 | } | ||
1369 | to = tl.next(); | ||
1370 | } | ||
1371 | |||
1372 | // pending get empty slots | ||
1373 | to = tl.first(); | ||
1374 | while ( to && ! planB ) { | ||
1375 | qDebug("todo2 %d ", procCount); | ||
1376 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | ||
1377 | qDebug("todo4 %d ", procCount); | ||
1378 | if ( to->getID(mProfileName).isEmpty() ) { | ||
1379 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1380 | qApp->processEvents(); | ||
1381 | //int newID ;//= pending | ||
1382 | //to->setID(mProfileName, QString::number( newID )); | ||
1383 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1384 | ToDoEntry.Location = 0; | ||
1385 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1386 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1387 | planB = true; | ||
1388 | qDebug("new planB %d ", error); | ||
1389 | } | ||
1390 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1391 | afterSave( to ); | ||
1392 | qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); | ||
1393 | } else { | ||
1394 | afterSave( to ); | ||
1395 | } | ||
1396 | } | ||
1397 | to = tl.next(); | ||
1398 | } | ||
1399 | if ( planB ) { | ||
1400 | qDebug("delete all ..."); | ||
1401 | error=Phone->DeleteAllToDo(&s); | ||
1402 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1403 | while (1) { | ||
1404 | qDebug("deleting todo ..."); | ||
1405 | error = Phone->GetNextToDo(&s,&ToDoEntry,true); | ||
1406 | if (error != ERR_NONE) break; | ||
1407 | error = Phone->DeleteToDo(&s,&ToDoEntry); | ||
1408 | } | ||
1409 | qDebug("deleting todo ... finished"); | ||
1410 | } else { | ||
1411 | qDebug("all todo deleted"); | ||
1412 | } | ||
1413 | bool planC = false; | ||
1414 | to = tl.first(); | ||
1415 | while ( to && ! planC ) { | ||
1416 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1417 | ToDoEntry.Location = 0; | ||
1418 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1419 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1420 | // we have currently no planC :-( | ||
1421 | // planC = true; | ||
1422 | //qDebug("add planC %d ", error); | ||
1423 | //break; | ||
1424 | // we remove the ID such that this todo is not deleted after next sync | ||
1425 | to->removeID(mProfileName); | ||
1426 | to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1427 | } else { | ||
1428 | qDebug("adding %d planB %d ", ToDoEntry.Location ,error); | ||
1429 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1430 | afterSave( to ); | ||
1431 | } | ||
1432 | to = tl.next(); | ||
1433 | } | ||
1434 | if ( planC ) { | ||
1435 | // we have currently no planC :-( | ||
1436 | } | ||
1437 | } | ||
1438 | return true; | ||
1439 | #endif | ||
1440 | } | ||
1441 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) | ||
1442 | { | ||
1443 | QString datestr; | ||
1444 | QString timestr; | ||
1445 | int offset = KGlobal::locale()->localTimeOffset( dti ); | ||
1446 | QDateTime dt; | ||
1447 | if (useTZ) | ||
1448 | dt = dti.addSecs ( -(offset*60)); | ||
1449 | else | ||
1450 | dt = dti; | ||
1451 | if(dt.date().isValid()){ | ||
1452 | const QDate& date = dt.date(); | ||
1453 | datestr.sprintf("%04d%02d%02d", | ||
1454 | date.year(), date.month(), date.day()); | ||
1455 | } | ||
1456 | if(dt.time().isValid()){ | ||
1457 | const QTime& time = dt.time(); | ||
1458 | timestr.sprintf("T%02d%02d%02d", | ||
1459 | time.hour(), time.minute(), time.second()); | ||
1460 | } | ||
1461 | return datestr + timestr; | ||
1462 | } | ||
1463 | QString PhoneFormat::getEventString( Event* event ) | ||
1464 | { | ||
1465 | #if 0 | ||
1466 | QStringList list; | ||
1467 | list.append( QString::number(event->zaurusId() ) ); | ||
1468 | list.append( event->categories().join(",") ); | ||
1469 | if ( !event->summary().isEmpty() ) | ||
1470 | list.append( event->summary() ); | ||
1471 | else | ||
1472 | list.append("" ); | ||
1473 | if ( !event->location().isEmpty() ) | ||
1474 | list.append( event->location() ); | ||
1475 | else | ||
1476 | list.append("" ); | ||
1477 | if ( !event->description().isEmpty() ) | ||
1478 | list.append( event->description() ); | ||
1479 | else | ||
1480 | list.append( "" ); | ||
1481 | if ( event->doesFloat () ) { | ||
1482 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | ||
1483 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | ||
1484 | list.append( "1" ); | ||
1485 | |||
1486 | } | ||
1487 | else { | ||
1488 | list.append( dtToString( event->dtStart()) ); | ||
1489 | list.append( dtToString( event->dtEnd()) ); //6 | ||
1490 | list.append( "0" ); | ||
1491 | } | ||
1492 | bool noAlarm = true; | ||
1493 | if ( event->alarms().count() > 0 ) { | ||
1494 | Alarm * al = event->alarms().first(); | ||
1495 | if ( al->enabled() ) { | ||
1496 | noAlarm = false; | ||
1497 | list.append( "0" ); // yes, 0 == alarm | ||
1498 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | ||
1499 | if ( al->type() == Alarm::Audio ) | ||
1500 | list.append( "1" ); // type audio | ||
1501 | else | ||
1502 | list.append( "0" ); // type silent | ||
1503 | } | ||
1504 | } | ||
1505 | if ( noAlarm ) { | ||
1506 | list.append( "1" ); // yes, 1 == no alarm | ||
1507 | list.append( "0" ); // no alarm offset | ||
1508 | list.append( "1" ); // type | ||
1509 | } | ||
1510 | // next is: 11 | ||
1511 | // next is: 11-16 are recurrence | ||
1512 | Recurrence* rec = event->recurrence(); | ||
1513 | |||
1514 | bool writeEndDate = false; | ||
1515 | switch ( rec->doesRecur() ) | ||
1516 | { | ||
1517 | case Recurrence::rDaily: // 0 | ||
1518 | list.append( "0" ); | ||
1519 | list.append( QString::number( rec->frequency() ));//12 | ||
1520 | list.append( "0" ); | ||
1521 | list.append( "0" ); | ||
1522 | writeEndDate = true; | ||
1523 | break; | ||
1524 | case Recurrence::rWeekly:// 1 | ||
1525 | list.append( "1" ); | ||
1526 | list.append( QString::number( rec->frequency()) );//12 | ||
1527 | list.append( "0" ); | ||
1528 | { | ||
1529 | int days = 0; | ||
1530 | QBitArray weekDays = rec->days(); | ||
1531 | int i; | ||
1532 | for( i = 1; i <= 7; ++i ) { | ||
1533 | if ( weekDays[i-1] ) { | ||
1534 | days += 1 << (i-1); | ||
1535 | } | ||
1536 | } | ||
1537 | list.append( QString::number( days ) ); | ||
1538 | } | ||
1539 | //pending weekdays | ||
1540 | writeEndDate = true; | ||
1541 | |||
1542 | break; | ||
1543 | case Recurrence::rMonthlyPos:// 2 | ||
1544 | list.append( "2" ); | ||
1545 | list.append( QString::number( rec->frequency()) );//12 | ||
1546 | |||
1547 | writeEndDate = true; | ||
1548 | { | ||
1549 | int count = 1; | ||
1550 | QPtrList<Recurrence::rMonthPos> rmp; | ||
1551 | rmp = rec->monthPositions(); | ||
1552 | if ( rmp.first()->negative ) | ||
1553 | count = 5 - rmp.first()->rPos - 1; | ||
1554 | else | ||
1555 | count = rmp.first()->rPos - 1; | ||
1556 | list.append( QString::number( count ) ); | ||
1557 | |||
1558 | } | ||
1559 | |||
1560 | list.append( "0" ); | ||
1561 | break; | ||
1562 | case Recurrence::rMonthlyDay:// 3 | ||
1563 | list.append( "3" ); | ||
1564 | list.append( QString::number( rec->frequency()) );//12 | ||
1565 | list.append( "0" ); | ||
1566 | list.append( "0" ); | ||
1567 | writeEndDate = true; | ||
1568 | break; | ||
1569 | case Recurrence::rYearlyMonth://4 | ||
1570 | list.append( "4" ); | ||
1571 | list.append( QString::number( rec->frequency()) );//12 | ||
1572 | list.append( "0" ); | ||
1573 | list.append( "0" ); | ||
1574 | writeEndDate = true; | ||
1575 | break; | ||
1576 | |||
1577 | default: | ||
1578 | list.append( "255" ); | ||
1579 | list.append( QString() ); | ||
1580 | list.append( "0" ); | ||
1581 | list.append( QString() ); | ||
1582 | list.append( "0" ); | ||
1583 | list.append( "20991231T000000" ); | ||
1584 | break; | ||
1585 | } | ||
1586 | if ( writeEndDate ) { | ||
1587 | |||
1588 | if ( rec->endDate().isValid() ) { // 15 + 16 | ||
1589 | list.append( "1" ); | ||
1590 | list.append( dtToString( rec->endDate()) ); | ||
1591 | } else { | ||
1592 | list.append( "0" ); | ||
1593 | list.append( "20991231T000000" ); | ||
1594 | } | ||
1595 | |||
1596 | } | ||
1597 | if ( event->doesFloat () ) { | ||
1598 | list.append( dtToString( event->dtStart(), false ).left( 8 )); | ||
1599 | list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 | ||
1600 | |||
1601 | } | ||
1602 | else { | ||
1603 | list.append( QString() ); | ||
1604 | list.append( QString() ); | ||
1605 | |||
1606 | } | ||
1607 | if (event->dtStart().date() == event->dtEnd().date() ) | ||
1608 | list.append( "0" ); | ||
1609 | else | ||
1610 | list.append( "1" ); | ||
1611 | |||
1612 | |||
1613 | for(QStringList::Iterator it=list.begin(); | ||
1614 | it!=list.end(); ++it){ | ||
1615 | QString& s = (*it); | ||
1616 | s.replace(QRegExp("\""), "\"\""); | ||
1617 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | ||
1618 | s.prepend('\"'); | ||
1619 | s.append('\"'); | ||
1620 | } else if(s.isEmpty() && !s.isNull()){ | ||
1621 | s = "\"\""; | ||
1622 | } | ||
1623 | } | ||
1624 | return list.join(","); | ||
1625 | #endif | ||
1626 | return QString(); | ||
1627 | |||
1628 | } | ||
1629 | QString PhoneFormat::getTodoString( Todo* todo ) | ||
1630 | { | ||
1631 | #if 0 | ||
1632 | QStringList list; | ||
1633 | list.append( QString::number( todo->zaurusId() ) ); | ||
1634 | list.append( todo->categories().join(",") ); | ||
1635 | |||
1636 | if ( todo->hasStartDate() ) { | ||
1637 | list.append( dtToString( todo->dtStart()) ); | ||
1638 | } else | ||
1639 | list.append( QString() ); | ||
1640 | |||
1641 | if ( todo->hasDueDate() ) { | ||
1642 | QTime tim; | ||
1643 | if ( todo->doesFloat()) { | ||
1644 | list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; | ||
1645 | } else { | ||
1646 | list.append( dtToString(todo->dtDue() ) ); | ||
1647 | } | ||
1648 | } else | ||
1649 | list.append( QString() ); | ||
1650 | |||
1651 | if ( todo->isCompleted() ) { | ||
1652 | list.append( dtToString( todo->completed()) ); | ||
1653 | list.append( "0" ); // yes 0 == completed | ||
1654 | } else { | ||
1655 | list.append( dtToString( todo->completed()) ); | ||
1656 | list.append( "1" ); | ||
1657 | } | ||
1658 | list.append( QString::number( todo->priority() )); | ||
1659 | if( ! todo->summary().isEmpty() ) | ||
1660 | list.append( todo->summary() ); | ||
1661 | else | ||
1662 | list.append( "" ); | ||
1663 | if (! todo->description().isEmpty() ) | ||
1664 | list.append( todo->description() ); | ||
1665 | else | ||
1666 | list.append( "" ); | ||
1667 | for(QStringList::Iterator it=list.begin(); | ||
1668 | it!=list.end(); ++it){ | ||
1669 | QString& s = (*it); | ||
1670 | s.replace(QRegExp("\""), "\"\""); | ||
1671 | if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ | ||
1672 | s.prepend('\"'); | ||
1673 | s.append('\"'); | ||
1674 | } else if(s.isEmpty() && !s.isNull()){ | ||
1675 | s = "\"\""; | ||
1676 | } | ||
1677 | } | ||
1678 | return list.join(","); | ||
1679 | #endif | ||
1680 | return QString(); | ||
1681 | } | 571 | } |
1682 | 572 | ||
1683 | 573 | ||
1684 | QString PhoneFormat::toString( Calendar * ) | 574 | QString PhoneFormat::toString( Calendar * ) |
1685 | { | 575 | { |
1686 | return QString::null; | 576 | return QString::null; |
1687 | } | 577 | } |
1688 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) | 578 | bool PhoneFormat::fromString( Calendar *calendar, const QString & text) |
1689 | { | 579 | { |
1690 | return false; | 580 | return false; |
1691 | } | 581 | } |
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 2c2e51c..8286098 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h | |||
@@ -1,67 +1,61 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 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 | #ifndef PHONEFORMAT_H | 21 | #ifndef PHONEFORMAT_H |
22 | #define PHONEFORMAT_H | 22 | #define PHONEFORMAT_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | 25 | ||
26 | #include "scheduler.h" | 26 | #include "scheduler.h" |
27 | 27 | ||
28 | #include "vcalformat.h" | 28 | #include "vcalformat.h" |
29 | #include "calformat.h" | 29 | #include "calformat.h" |
30 | extern "C" { | 30 | |
31 | #include "../gammu/emb/common/gammu.h" | ||
32 | } | ||
33 | namespace KCal { | 31 | namespace KCal { |
34 | 32 | ||
35 | /** | 33 | /** |
36 | This class implements the calendar format used by Phone. | 34 | This class implements the calendar format used by Phone. |
37 | */ | 35 | */ |
38 | class Event; | 36 | class Event; |
39 | class Todo; | 37 | class Todo; |
40 | class PhoneFormat : public QObject { | 38 | class PhoneFormat : public QObject { |
41 | public: | 39 | public: |
42 | /** Create new iCalendar format. */ | 40 | /** Create new iCalendar format. */ |
43 | PhoneFormat(QString profileName, QString device,QString connection, QString model); | 41 | PhoneFormat(QString profileName, QString device,QString connection, QString model); |
44 | virtual ~PhoneFormat(); | 42 | virtual ~PhoneFormat(); |
45 | 43 | ||
46 | bool load( Calendar * ,Calendar * ); | 44 | bool load( Calendar * ,Calendar * ); |
47 | bool save( Calendar * ); | 45 | bool save( Calendar * ); |
48 | bool fromString( Calendar *, const QString & ); | 46 | bool fromString( Calendar *, const QString & ); |
49 | QString toString( Calendar * ); | 47 | QString toString( Calendar * ); |
50 | static ulong getCsum( const QStringList & ); | 48 | static ulong getCsum( const QStringList & ); |
51 | static ulong getCsumTodo( Todo* to ); | 49 | static ulong getCsumTodo( Todo* to ); |
52 | static ulong getCsumEvent( Event* ev ); | 50 | static ulong getCsumEvent( Event* ev ); |
53 | private: | 51 | private: |
54 | VCalFormat vfconverter; | 52 | void copyEvent( Event* to, Event* from ); |
55 | void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note ); | 53 | void copyTodo( Todo* to, Todo* from ); |
56 | void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo ); | 54 | //int initDevice(GSM_StateMachine *s); |
57 | int initDevice(GSM_StateMachine *s); | ||
58 | QString getEventString( Event* ); | ||
59 | QString getTodoString( Todo* ); | ||
60 | QString dtToGSM( const QDateTime& dt, bool useTZ = true ); | ||
61 | QString mProfileName, mDevice, mConnection, mModel; | 55 | QString mProfileName, mDevice, mConnection, mModel; |
62 | void afterSave( Incidence* ); | 56 | void afterSave( Incidence* ); |
63 | }; | 57 | }; |
64 | 58 | ||
65 | } | 59 | } |
66 | 60 | ||
67 | #endif | 61 | #endif |
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp index 0ebd7d1..4727a7a 100644 --- a/libkcal/vcalformat.cpp +++ b/libkcal/vcalformat.cpp | |||
@@ -9,100 +9,103 @@ | |||
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 <qapplication.h> | 22 | #include <qapplication.h> |
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qclipboard.h> | 27 | #include <qclipboard.h> |
28 | #include <qdialog.h> | 28 | #include <qdialog.h> |
29 | #include <qfile.h> | 29 | #include <qfile.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | #include <kmessagebox.h> | 33 | #include <kmessagebox.h> |
34 | #include <kiconloader.h> | 34 | #include <kiconloader.h> |
35 | #include <klocale.h> | 35 | #include <klocale.h> |
36 | 36 | ||
37 | #include "vcc.h" | 37 | #include "vcc.h" |
38 | #include "vobject.h" | 38 | #include "vobject.h" |
39 | 39 | ||
40 | #include "vcaldrag.h" | 40 | #include "vcaldrag.h" |
41 | #include "calendar.h" | 41 | #include "calendar.h" |
42 | 42 | ||
43 | #include "vcalformat.h" | 43 | #include "vcalformat.h" |
44 | 44 | ||
45 | using namespace KCal; | 45 | using namespace KCal; |
46 | 46 | ||
47 | VCalFormat::VCalFormat() | 47 | VCalFormat::VCalFormat() |
48 | { | 48 | { |
49 | mCalendar = 0; | 49 | mCalendar = 0; |
50 | useLocalTime = false; | 50 | useLocalTime = false; |
51 | } | 51 | } |
52 | 52 | ||
53 | VCalFormat::~VCalFormat() | 53 | VCalFormat::~VCalFormat() |
54 | { | 54 | { |
55 | } | 55 | } |
56 | 56 | ||
57 | void VCalFormat::setLocalTime ( bool b ) | ||
58 | { | ||
59 | useLocalTime = b; | ||
60 | } | ||
57 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) | 61 | bool VCalFormat::load(Calendar *calendar, const QString &fileName) |
58 | { | 62 | { |
59 | mCalendar = calendar; | 63 | mCalendar = calendar; |
60 | |||
61 | clearException(); | 64 | clearException(); |
62 | 65 | ||
63 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; | 66 | kdDebug(5800) << "VCalFormat::load() " << fileName << endl; |
64 | 67 | ||
65 | VObject *vcal = 0; | 68 | VObject *vcal = 0; |
66 | 69 | ||
67 | // this is not necessarily only 1 vcal. Could be many vcals, or include | 70 | // this is not necessarily only 1 vcal. Could be many vcals, or include |
68 | // a vcard... | 71 | // a vcard... |
69 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); | 72 | vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data())); |
70 | 73 | ||
71 | if (!vcal) { | 74 | if (!vcal) { |
72 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 75 | setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
73 | return FALSE; | 76 | return FALSE; |
74 | } | 77 | } |
75 | 78 | ||
76 | // any other top-level calendar stuff should be added/initialized here | 79 | // any other top-level calendar stuff should be added/initialized here |
77 | 80 | ||
78 | // put all vobjects into their proper places | 81 | // put all vobjects into their proper places |
79 | populate(vcal); | 82 | populate(vcal); |
80 | 83 | ||
81 | // clean up from vcal API stuff | 84 | // clean up from vcal API stuff |
82 | cleanVObjects(vcal); | 85 | cleanVObjects(vcal); |
83 | cleanStrTbl(); | 86 | cleanStrTbl(); |
84 | 87 | ||
85 | return true; | 88 | return true; |
86 | } | 89 | } |
87 | 90 | ||
88 | 91 | ||
89 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) | 92 | bool VCalFormat::save(Calendar *calendar, const QString &fileName) |
90 | { | 93 | { |
91 | mCalendar = calendar; | 94 | mCalendar = calendar; |
92 | 95 | ||
93 | QString tmpStr; | 96 | QString tmpStr; |
94 | VObject *vcal, *vo; | 97 | VObject *vcal, *vo; |
95 | 98 | ||
96 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; | 99 | kdDebug(5800) << "VCalFormat::save(): " << fileName << endl; |
97 | 100 | ||
98 | vcal = newVObject(VCCalProp); | 101 | vcal = newVObject(VCCalProp); |
99 | 102 | ||
100 | // addPropValue(vcal,VCLocationProp, "0.0"); | 103 | // addPropValue(vcal,VCLocationProp, "0.0"); |
101 | addPropValue(vcal,VCProdIdProp, productId()); | 104 | addPropValue(vcal,VCProdIdProp, productId()); |
102 | tmpStr = mCalendar->getTimeZoneStr(); | 105 | tmpStr = mCalendar->getTimeZoneStr(); |
103 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); | 106 | //qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() ); |
104 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); | 107 | addPropValue(vcal,VCTimeZoneProp, tmpStr.local8Bit()); |
105 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); | 108 | addPropValue(vcal,VCVersionProp, _VCAL_VERSION); |
106 | 109 | ||
107 | // TODO STUFF | 110 | // TODO STUFF |
108 | QPtrList<Todo> todoList = mCalendar->rawTodos(); | 111 | QPtrList<Todo> todoList = mCalendar->rawTodos(); |
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h index 848be78..5bef7ed 100644 --- a/libkcal/vcalformat.h +++ b/libkcal/vcalformat.h | |||
@@ -2,110 +2,111 @@ | |||
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) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 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 | #ifndef _VCALFORMAT_H | 22 | #ifndef _VCALFORMAT_H |
23 | #define _VCALFORMAT_H | 23 | #define _VCALFORMAT_H |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #define _VCAL_VERSION "1.0" | 27 | #define _VCAL_VERSION "1.0" |
28 | 28 | ||
29 | class VObject; | 29 | class VObject; |
30 | 30 | ||
31 | namespace KCal { | 31 | namespace KCal { |
32 | 32 | ||
33 | /** | 33 | /** |
34 | This class implements the vCalendar format. It provides methods for | 34 | This class implements the vCalendar format. It provides methods for |
35 | loading/saving/converting vCalendar format data into the internal KOrganizer | 35 | loading/saving/converting vCalendar format data into the internal KOrganizer |
36 | representation as Calendar and Events. | 36 | representation as Calendar and Events. |
37 | 37 | ||
38 | @short vCalendar format implementation | 38 | @short vCalendar format implementation |
39 | */ | 39 | */ |
40 | class VCalFormat : public CalFormat { | 40 | class VCalFormat : public CalFormat { |
41 | public: | 41 | public: |
42 | VCalFormat(); | 42 | VCalFormat(); |
43 | virtual ~VCalFormat(); | 43 | virtual ~VCalFormat(); |
44 | 44 | ||
45 | /** loads a calendar on disk in vCalendar format into the current calendar. | 45 | /** loads a calendar on disk in vCalendar format into the current calendar. |
46 | * any information already present is lost. Returns TRUE if successful, | 46 | * any information already present is lost. Returns TRUE if successful, |
47 | * else returns FALSE. | 47 | * else returns FALSE. |
48 | * @param fileName the name of the calendar on disk. | 48 | * @param fileName the name of the calendar on disk. |
49 | */ | 49 | */ |
50 | bool load(Calendar *,const QString &fileName); | 50 | bool load(Calendar *,const QString &fileName ); |
51 | /** writes out the calendar to disk in vCalendar format. Returns true if | 51 | /** writes out the calendar to disk in vCalendar format. Returns true if |
52 | * successful and false on error. | 52 | * successful and false on error. |
53 | * @param fileName the name of the file | 53 | * @param fileName the name of the file |
54 | */ | 54 | */ |
55 | bool save(Calendar *,const QString &fileName); | 55 | bool save(Calendar *,const QString &fileName ); |
56 | 56 | ||
57 | /** | 57 | /** |
58 | Parse string and populate calendar with that information. | 58 | Parse string and populate calendar with that information. |
59 | */ | 59 | */ |
60 | bool fromString( Calendar *, const QString & ); | 60 | bool fromString( Calendar *, const QString & ); |
61 | /** | 61 | /** |
62 | Return calendar information as string. | 62 | Return calendar information as string. |
63 | */ | 63 | */ |
64 | void setLocalTime ( bool ); | ||
64 | QString toString( Calendar * ); | 65 | QString toString( Calendar * ); |
65 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); | 66 | QString eventToString( Event *, Calendar *calendar, bool useLocalTime = true ); |
66 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); | 67 | QString todoToString( Todo * ,Calendar *calendar, bool useLocalTime = true ); |
67 | 68 | ||
68 | protected: | 69 | protected: |
69 | /** translates a VObject of the TODO type into a Event */ | 70 | /** translates a VObject of the TODO type into a Event */ |
70 | Todo *VTodoToEvent(VObject *vtodo); | 71 | Todo *VTodoToEvent(VObject *vtodo); |
71 | /** translates a VObject into a Event and returns a pointer to it. */ | 72 | /** translates a VObject into a Event and returns a pointer to it. */ |
72 | Event *VEventToEvent(VObject *vevent); | 73 | Event *VEventToEvent(VObject *vevent); |
73 | /** translate a Event into a VTodo-type VObject and return pointer */ | 74 | /** translate a Event into a VTodo-type VObject and return pointer */ |
74 | VObject *eventToVTodo(const Todo *anEvent); | 75 | VObject *eventToVTodo(const Todo *anEvent); |
75 | /** translate a Event into a VObject and returns a pointer to it. */ | 76 | /** translate a Event into a VObject and returns a pointer to it. */ |
76 | VObject* eventToVEvent(const Event *anEvent); | 77 | VObject* eventToVEvent(const Event *anEvent); |
77 | 78 | ||
78 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ | 79 | /** takes a QDate and returns a string in the format YYYYMMDDTHHMMSS */ |
79 | QString qDateToISO(const QDate &); | 80 | QString qDateToISO(const QDate &); |
80 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ | 81 | /** takes a QDateTime and returns a string in format YYYYMMDDTHHMMSS */ |
81 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); | 82 | QString qDateTimeToISO(const QDateTime &, bool zulu=TRUE); |
82 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a | 83 | /** takes a string in the format YYYYMMDDTHHMMSS and returns a |
83 | * valid QDateTime. */ | 84 | * valid QDateTime. */ |
84 | QDateTime ISOToQDateTime(const QString & dtStr); | 85 | QDateTime ISOToQDateTime(const QString & dtStr); |
85 | /** takes a string in the format YYYYMMDD and returns a | 86 | /** takes a string in the format YYYYMMDD and returns a |
86 | * valid QDate. */ | 87 | * valid QDate. */ |
87 | QDate ISOToQDate(const QString & dtStr); | 88 | QDate ISOToQDate(const QString & dtStr); |
88 | /** takes a vCalendar tree of VObjects, and puts all of them that have | 89 | /** takes a vCalendar tree of VObjects, and puts all of them that have |
89 | * the "event" property into the dictionary, todos in the todo-list, etc. */ | 90 | * the "event" property into the dictionary, todos in the todo-list, etc. */ |
90 | void populate(VObject *vcal); | 91 | void populate(VObject *vcal); |
91 | 92 | ||
92 | /** takes a number 0 - 6 and returns the two letter string of that day, | 93 | /** takes a number 0 - 6 and returns the two letter string of that day, |
93 | * i.e. MO, TU, WE, etc. */ | 94 | * i.e. MO, TU, WE, etc. */ |
94 | const char *dayFromNum(int day); | 95 | const char *dayFromNum(int day); |
95 | /** the reverse of the above function. */ | 96 | /** the reverse of the above function. */ |
96 | int numFromDay(const QString &day); | 97 | int numFromDay(const QString &day); |
97 | 98 | ||
98 | Attendee::PartStat readStatus(const char *s) const; | 99 | Attendee::PartStat readStatus(const char *s) const; |
99 | QCString writeStatus(Attendee::PartStat status) const; | 100 | QCString writeStatus(Attendee::PartStat status) const; |
100 | 101 | ||
101 | private: | 102 | private: |
102 | Calendar *mCalendar; | 103 | Calendar *mCalendar; |
103 | bool useLocalTime; | 104 | bool useLocalTime; |
104 | 105 | ||
105 | QPtrList<Event> mEventsRelate; // events with relations | 106 | QPtrList<Event> mEventsRelate; // events with relations |
106 | QPtrList<Todo> mTodosRelate; // todos with relations | 107 | QPtrList<Todo> mTodosRelate; // todos with relations |
107 | }; | 108 | }; |
108 | 109 | ||
109 | } | 110 | } |
110 | 111 | ||
111 | #endif | 112 | #endif |