-rw-r--r-- | libkcal/phoneformat.cpp | 227 |
1 files changed, 194 insertions, 33 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index e6d4879..6bbc0a3 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -21,99 +21,99 @@ | |||
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 | 48 | ||
49 | class PhoneParser : public QObject | 49 | class PhoneParser : public QObject |
50 | { | 50 | { |
51 | public: | 51 | public: |
52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { | 52 | PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { |
53 | ; | 53 | ; |
54 | } | 54 | } |
55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) | 55 | bool readTodo( Calendar *existingCalendar,GSM_ToDoEntry *ToDo, GSM_StateMachine* s) |
56 | { | 56 | { |
57 | 57 | ||
58 | int id = ToDo->Location; | 58 | int id = ToDo->Location; |
59 | Todo *todo; | 59 | Todo *todo; |
60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); | 60 | todo = existingCalendar->todo( mProfileName ,QString::number( id ) ); |
61 | if (todo ) | 61 | if (todo ) |
62 | todo = (Todo *)todo->clone(); | 62 | todo = (Todo *)todo->clone(); |
63 | else | 63 | else |
64 | todo = new Todo; | 64 | todo = new Todo; |
65 | todo->setID( mProfileName,QString::number( id ) ); | 65 | todo->setID( mProfileName,QString::number( id ) ); |
66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 66 | todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
67 | int priority; | 67 | int priority; |
68 | switch (ToDo->Priority) { | 68 | switch (ToDo->Priority) { |
69 | case GSM_Priority_Low : priority = 1; break; | 69 | case GSM_Priority_Low : priority = 5; break; |
70 | case GSM_Priority_Medium : priority = 3; break; | 70 | case GSM_Priority_Medium : priority = 3; break; |
71 | case GSM_Priority_High : priority = 5; break; | 71 | case GSM_Priority_High : priority = 1; break; |
72 | default :priority = 3 ;break; | 72 | default :priority = 3 ;break; |
73 | } | 73 | } |
74 | todo->setPriority( priority ); | 74 | todo->setPriority( priority ); |
75 | GSM_Phone_Functions*Phone; | 75 | GSM_Phone_Functions*Phone; |
76 | Phone=s->Phone.Functions; | 76 | Phone=s->Phone.Functions; |
77 | int j; | 77 | int j; |
78 | GSM_DateTime* dtp; | 78 | GSM_DateTime* dtp; |
79 | bool alarm = false; | 79 | bool alarm = false; |
80 | QDateTime alarmDt; | 80 | QDateTime alarmDt; |
81 | GSM_Category Category; | 81 | GSM_Category Category; |
82 | int error; | 82 | int error; |
83 | for (j=0;j<ToDo->EntriesNum;j++) { | 83 | for (j=0;j<ToDo->EntriesNum;j++) { |
84 | 84 | ||
85 | //qDebug(" for todo %d",ToDo->Location ); | 85 | //qDebug(" for todo %d",ToDo->Location ); |
86 | switch (ToDo->Entries[j].EntryType) { | 86 | switch (ToDo->Entries[j].EntryType) { |
87 | case TODO_END_DATETIME: | 87 | case TODO_END_DATETIME: |
88 | dtp = &ToDo->Entries[j].Date ; | 88 | dtp = &ToDo->Entries[j].Date ; |
89 | todo->setDtDue (fromGSM ( dtp )); | 89 | todo->setDtDue (fromGSM ( dtp )); |
90 | break; | 90 | break; |
91 | case TODO_COMPLETED: | 91 | case TODO_COMPLETED: |
92 | if ( ToDo->Entries[j].Number == 1 ) { | 92 | if ( ToDo->Entries[j].Number == 1 ) { |
93 | todo->setCompleted( true ); | 93 | todo->setCompleted( true ); |
94 | } | 94 | } |
95 | else { | 95 | else { |
96 | todo->setCompleted( false ); | 96 | todo->setCompleted( false ); |
97 | } | 97 | } |
98 | break; | 98 | break; |
99 | case TODO_ALARM_DATETIME: | 99 | case TODO_ALARM_DATETIME: |
100 | dtp = &ToDo->Entries[j].Date ; | 100 | dtp = &ToDo->Entries[j].Date ; |
101 | alarm = true; | 101 | alarm = true; |
102 | alarmDt = fromGSM ( dtp ); | 102 | alarmDt = fromGSM ( dtp ); |
103 | break; | 103 | break; |
104 | case TODO_SILENT_ALARM_DATETIME: | 104 | case TODO_SILENT_ALARM_DATETIME: |
105 | dtp = &ToDo->Entries[j].Date ; | 105 | dtp = &ToDo->Entries[j].Date ; |
106 | alarm = true; | 106 | alarm = true; |
107 | alarmDt = fromGSM ( dtp ); | 107 | alarmDt = fromGSM ( dtp ); |
108 | break; | 108 | break; |
109 | case TODO_TEXT: | 109 | case TODO_TEXT: |
110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); | 110 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); |
111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); | 111 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); |
112 | break; | 112 | break; |
113 | case TODO_PRIVATE: | 113 | case TODO_PRIVATE: |
114 | if ( ToDo->Entries[j].Number == 1 ) | 114 | if ( ToDo->Entries[j].Number == 1 ) |
115 | todo->setSecrecy( Incidence::SecrecyPrivate ); | 115 | todo->setSecrecy( Incidence::SecrecyPrivate ); |
116 | else | 116 | else |
117 | todo->setSecrecy( Incidence::SecrecyPublic ); | 117 | todo->setSecrecy( Incidence::SecrecyPublic ); |
118 | break; | 118 | break; |
119 | case TODO_CATEGORY: | 119 | case TODO_CATEGORY: |
@@ -185,96 +185,97 @@ public: | |||
185 | todo->setCsum( mProfileName, QString::number( cSum )); | 185 | todo->setCsum( mProfileName, QString::number( cSum )); |
186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 186 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
187 | mCalendar->addTodo( todo); | 187 | mCalendar->addTodo( todo); |
188 | 188 | ||
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) | 191 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) |
192 | { | 192 | { |
193 | 193 | ||
194 | int id = Note->Location; | 194 | int id = Note->Location; |
195 | Event *event; | 195 | Event *event; |
196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); | 196 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); |
197 | if ( event ) | 197 | if ( event ) |
198 | event = (Event*)event->clone(); | 198 | event = (Event*)event->clone(); |
199 | else | 199 | else |
200 | event = new Event; | 200 | event = new Event; |
201 | event->setID( mProfileName,QString::number( id ) ); | 201 | event->setID( mProfileName,QString::number( id ) ); |
202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 202 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
203 | 203 | ||
204 | 204 | ||
205 | int i = 0; | 205 | int i = 0; |
206 | bool repeating = false; | 206 | bool repeating = false; |
207 | int repeat_dayofweek = -1; | 207 | int repeat_dayofweek = -1; |
208 | int repeat_day = -1; | 208 | int repeat_day = -1; |
209 | int repeat_weekofmonth = -1; | 209 | int repeat_weekofmonth = -1; |
210 | int repeat_month = -1; | 210 | int repeat_month = -1; |
211 | int repeat_frequency = -1; | 211 | int repeat_frequency = -1; |
212 | int rec_type = -1; | 212 | int rec_type = -1; |
213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | 213 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; |
214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | 214 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; |
215 | GSM_DateTime* dtp; | 215 | GSM_DateTime* dtp; |
216 | bool alarm = false; | 216 | bool alarm = false; |
217 | QDateTime alarmDt; | 217 | QDateTime alarmDt; |
218 | repeat_startdate.Day= 0; | 218 | repeat_startdate.Day= 0; |
219 | repeat_stopdate.Day = 0; | 219 | repeat_stopdate.Day = 0; |
220 | for (i=0;i<Note->EntriesNum;i++) { | 220 | for (i=0;i<Note->EntriesNum;i++) { |
221 | 221 | ||
222 | //qDebug(" for ev"); | 222 | //qDebug(" for ev"); |
223 | switch (Note->Entries[i].EntryType) { | 223 | switch (Note->Entries[i].EntryType) { |
224 | case CAL_START_DATETIME: | 224 | case CAL_START_DATETIME: |
225 | dtp = &Note->Entries[i].Date ; | 225 | dtp = &Note->Entries[i].Date ; |
226 | if ( dtp->Hour > 24 ) { | 226 | if ( dtp->Hour > 24 ) { |
227 | event->setFloats( true ); | 227 | event->setFloats( true ); |
228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 228 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
229 | } else { | 229 | } else { |
230 | event->setDtStart (fromGSM ( dtp )); | 230 | event->setDtStart (fromGSM ( dtp )); |
231 | 231 | ||
232 | } | 232 | } |
233 | //Note->Entries[i].Date.Hour = 5; | ||
233 | break; | 234 | break; |
234 | case CAL_END_DATETIME: | 235 | case CAL_END_DATETIME: |
235 | dtp = &Note->Entries[i].Date ; | 236 | dtp = &Note->Entries[i].Date ; |
236 | if ( dtp->Hour > 24 ) { | 237 | if ( dtp->Hour > 24 ) { |
237 | event->setFloats( true ); | 238 | event->setFloats( true ); |
238 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 239 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
239 | } else { | 240 | } else { |
240 | event->setDtEnd (fromGSM ( dtp )); | 241 | event->setDtEnd (fromGSM ( dtp )); |
241 | } | 242 | } |
242 | break; | 243 | break; |
243 | case CAL_ALARM_DATETIME: | 244 | case CAL_ALARM_DATETIME: |
244 | dtp = &Note->Entries[i].Date ; | 245 | dtp = &Note->Entries[i].Date ; |
245 | alarm = true; | 246 | alarm = true; |
246 | alarmDt = fromGSM ( dtp ); | 247 | alarmDt = fromGSM ( dtp ); |
247 | break; | 248 | break; |
248 | case CAL_SILENT_ALARM_DATETIME: | 249 | case CAL_SILENT_ALARM_DATETIME: |
249 | dtp = &Note->Entries[i].Date ; | 250 | dtp = &Note->Entries[i].Date ; |
250 | alarm = true; | 251 | alarm = true; |
251 | alarmDt = fromGSM ( dtp ); | 252 | alarmDt = fromGSM ( dtp ); |
252 | break; | 253 | break; |
253 | case CAL_RECURRANCE: | 254 | case CAL_RECURRANCE: |
254 | rec_type = Note->Entries[i].Number; | 255 | rec_type = Note->Entries[i].Number; |
255 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); | 256 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); |
256 | break; | 257 | break; |
257 | case CAL_TEXT: | 258 | case CAL_TEXT: |
258 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); | 259 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); |
259 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); | 260 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); |
260 | break; | 261 | break; |
261 | case CAL_LOCATION: | 262 | case CAL_LOCATION: |
262 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); | 263 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); |
263 | break; | 264 | break; |
264 | case CAL_PHONE: | 265 | case CAL_PHONE: |
265 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); | 266 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); |
266 | break; | 267 | break; |
267 | case CAL_PRIVATE: | 268 | case CAL_PRIVATE: |
268 | if ( Note->Entries[i].Number == 1 ) | 269 | if ( Note->Entries[i].Number == 1 ) |
269 | event->setSecrecy( Incidence::SecrecyPrivate ); | 270 | event->setSecrecy( Incidence::SecrecyPrivate ); |
270 | else | 271 | else |
271 | event->setSecrecy( Incidence::SecrecyPublic ); | 272 | event->setSecrecy( Incidence::SecrecyPublic ); |
272 | 273 | ||
273 | break; | 274 | break; |
274 | case CAL_CONTACTID: | 275 | case CAL_CONTACTID: |
275 | #if 0 | 276 | #if 0 |
276 | entry.Location = Note->Entries[i].Number; | 277 | entry.Location = Note->Entries[i].Number; |
277 | entry.MemoryType = MEM_ME; | 278 | entry.MemoryType = MEM_ME; |
278 | error=Phone->GetMemory(&s, &entry); | 279 | error=Phone->GetMemory(&s, &entry); |
279 | if (error == ERR_NONE) { | 280 | if (error == ERR_NONE) { |
280 | name = GSM_PhonebookGetEntryName(&entry); | 281 | name = GSM_PhonebookGetEntryName(&entry); |
@@ -725,337 +726,497 @@ ulong PhoneFormat::getCsumEvent( Event* event ) | |||
725 | 726 | ||
726 | if ( rec->endDate().isValid() ) { // 15 + 16 | 727 | if ( rec->endDate().isValid() ) { // 15 + 16 |
727 | list.append( "1" ); | 728 | list.append( "1" ); |
728 | list.append( PhoneParser::dtToString( rec->endDate()) ); | 729 | list.append( PhoneParser::dtToString( rec->endDate()) ); |
729 | } else { | 730 | } else { |
730 | list.append( "0" ); | 731 | list.append( "0" ); |
731 | list.append( "20991231T000000" ); | 732 | list.append( "20991231T000000" ); |
732 | } | 733 | } |
733 | 734 | ||
734 | } | 735 | } |
735 | attList << list.join(""); | 736 | attList << list.join(""); |
736 | attList << event->categoriesStr(); | 737 | attList << event->categoriesStr(); |
737 | attList << event->secrecyStr(); | 738 | attList << event->secrecyStr(); |
738 | return PhoneFormat::getCsum(attList ); | 739 | return PhoneFormat::getCsum(attList ); |
739 | } | 740 | } |
740 | ulong PhoneFormat::getCsum( const QStringList & attList) | 741 | ulong PhoneFormat::getCsum( const QStringList & attList) |
741 | { | 742 | { |
742 | int max = attList.count() -1; | 743 | int max = attList.count() -1; |
743 | ulong cSum = 0; | 744 | ulong cSum = 0; |
744 | int j,k,i; | 745 | int j,k,i; |
745 | int add; | 746 | int add; |
746 | for ( i = 1; i < max ; ++i ) { | 747 | for ( i = 1; i < max ; ++i ) { |
747 | QString s = attList[i]; | 748 | QString s = attList[i]; |
748 | if ( ! s.isEmpty() ){ | 749 | if ( ! s.isEmpty() ){ |
749 | j = s.length(); | 750 | j = s.length(); |
750 | for ( k = 0; k < j; ++k ) { | 751 | for ( k = 0; k < j; ++k ) { |
751 | int mul = k +1; | 752 | int mul = k +1; |
752 | add = s[k].unicode (); | 753 | add = s[k].unicode (); |
753 | if ( k < 16 ) | 754 | if ( k < 16 ) |
754 | mul = mul * mul; | 755 | mul = mul * mul; |
755 | add = add * mul *i*i*i; | 756 | add = add * mul *i*i*i; |
756 | cSum += add; | 757 | cSum += add; |
757 | } | 758 | } |
758 | } | 759 | } |
759 | } | 760 | } |
760 | return cSum; | 761 | return cSum; |
761 | 762 | ||
762 | } | 763 | } |
763 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); | 764 | //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); |
764 | #include <stdlib.h> | 765 | #include <stdlib.h> |
765 | #define DEBUGMODE false | 766 | #define DEBUGMODE false |
766 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) | 767 | bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) |
767 | { | 768 | { |
768 | GSM_StateMachines; | 769 | GSM_StateMachines; |
769 | qDebug(" load "); | 770 | qDebug(" load "); |
770 | s.opened = false; | 771 | s.opened = false; |
771 | s.msg = NULL; | 772 | s.msg = NULL; |
772 | s.ConfigNum = 0; | 773 | s.ConfigNum = 0; |
773 | QLabel status ( i18n("Reading data. Opening device ..."), 0 ); | 774 | QLabel status ( i18n("Opening device ..."), 0 ); |
774 | int w = status.sizeHint().width()+20 ; | 775 | int w = status.sizeHint().width()+20 ; |
775 | if ( w < 200 ) w = 200; | 776 | if ( w < 200 ) w = 230; |
776 | int h = status.sizeHint().height()+20 ; | 777 | int h = status.sizeHint().height()+20 ; |
777 | int dw = QApplication::desktop()->width(); | 778 | int dw = QApplication::desktop()->width(); |
778 | int dh = QApplication::desktop()->height(); | 779 | int dh = QApplication::desktop()->height(); |
779 | status.setCaption(i18n("Reading Phone Data") ); | 780 | status.setCaption(i18n("Reading phone...") ); |
780 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 781 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
781 | status.show(); | 782 | status.show(); |
782 | status.raise(); | 783 | status.raise(); |
783 | qApp->processEvents(); | 784 | qApp->processEvents(); |
784 | #if 0 | 785 | #if 0 |
785 | static char*cp; | 786 | static char*cp; |
786 | static INI_Section *cfg = NULL; | 787 | static INI_Section *cfg = NULL; |
787 | cfg=GSM_FindGammuRC(); | 788 | cfg=GSM_FindGammuRC(); |
788 | int i; | 789 | int i; |
789 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { | 790 | for (i = 0; i <= MAX_CONFIG_NUM; i++) { |
790 | if (cfg!=NULL) { | 791 | if (cfg!=NULL) { |
791 | cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); | 792 | cp = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*)"gammucoding", false); |
792 | if (cp) di.coding = cp; | 793 | if (cp) di.coding = cp; |
793 | 794 | ||
794 | s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); | 795 | s.Config[i].Localize = (char *)INI_GetValue(cfg, (unsigned char*) "gammu", (unsigned char*) "gammuloc", false); |
795 | if (s.Config[i].Localize) { | 796 | if (s.Config[i].Localize) { |
796 | s.msg=INI_ReadFile(s.Config[i].Localize, true); | 797 | s.msg=INI_ReadFile(s.Config[i].Localize, true); |
797 | } else { | 798 | } else { |
798 | #if !defined(WIN32) && defined(LOCALE_PATH) | 799 | #if !defined(WIN32) && defined(LOCALE_PATH) |
799 | locale = setlocale(LC_MESSAGES, NULL); | 800 | locale = setlocale(LC_MESSAGES, NULL); |
800 | if (locale != NULL) { | 801 | if (locale != NULL) { |
801 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", | 802 | snprintf(locale_file, 200, "%s/gammu_%c%c.txt", |
802 | LOCALE_PATH, | 803 | LOCALE_PATH, |
803 | tolower(locale[0]), | 804 | tolower(locale[0]), |
804 | tolower(locale[1])); | 805 | tolower(locale[1])); |
805 | s.msg = INI_ReadFile(locale_file, true); | 806 | s.msg = INI_ReadFile(locale_file, true); |
806 | } | 807 | } |
807 | #endif | 808 | #endif |
808 | } | 809 | } |
809 | } | 810 | } |
810 | 811 | ||
811 | /* Wanted user specific configuration? */ | 812 | /* Wanted user specific configuration? */ |
812 | 813 | ||
813 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; | 814 | if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; |
814 | 815 | ||
815 | s.ConfigNum++; | 816 | s.ConfigNum++; |
816 | 817 | ||
817 | /* We want to use only one file descriptor for global and state machine debug output */ | 818 | /* We want to use only one file descriptor for global and state machine debug output */ |
818 | s.Config[i].UseGlobalDebugFile = true; | 819 | s.Config[i].UseGlobalDebugFile = true; |
819 | 820 | ||
820 | 821 | ||
821 | 822 | ||
822 | /* We wanted to read just user specified configuration. */ | 823 | /* We wanted to read just user specified configuration. */ |
823 | {break;} | 824 | {break;} |
824 | } | 825 | } |
825 | 826 | ||
826 | #endif | 827 | #endif |
827 | int error=initDevice(&s); | 828 | int error=initDevice(&s); |
828 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 829 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); |
829 | if ( error != ERR_NONE ) | 830 | if ( error != ERR_NONE ) |
830 | return false; | 831 | return false; |
831 | GSM_Phone_Functions*Phone; | 832 | GSM_Phone_Functions*Phone; |
832 | GSM_CalendarEntrynote; | 833 | GSM_CalendarEntrynote; |
833 | bool start = true; | 834 | bool start = true; |
834 | Phone=s.Phone.Functions; | 835 | Phone=s.Phone.Functions; |
835 | bool gshutdown = false; | 836 | bool gshutdown = false; |
836 | PhoneParser handler( calendar, mProfileName ); | 837 | PhoneParser handler( calendar, mProfileName ); |
837 | int ccc = 0; | 838 | int ccc = 0; |
838 | QString message = i18n("Processing event # "); | 839 | QString message = i18n(" Reading event # "); |
839 | int procCount = 0; | 840 | int procCount = 0; |
840 | qDebug("Debug: only 10 calender items are downloaded "); | 841 | qDebug("Debug: only 10 calender items are downloaded "); |
841 | while (!gshutdown && ccc++ < 10) { | 842 | while (!gshutdown && ccc++ < 10) { |
842 | status.setText ( message + QString::number ( ++procCount ) ); | 843 | status.setText ( message + QString::number ( ++procCount ) ); |
843 | qApp->processEvents(); | 844 | qApp->processEvents(); |
844 | qDebug("readEvent %d ", ccc); | 845 | qDebug("readEvent %d ", ccc); |
845 | error=Phone->GetNextCalendar(&s,¬e,start); | 846 | error=Phone->GetNextCalendar(&s,¬e,start); |
846 | if (error == ERR_EMPTY) break; | 847 | if (error == ERR_EMPTY) break; |
847 | start = false; | 848 | start = false; |
848 | handler.readEvent( existingCal, ¬e ); | 849 | handler.readEvent( existingCal, ¬e ); |
850 | qDebug("Org loc %d ",note.Location); | ||
851 | //note.Location = 0; | ||
852 | error=Phone->SetCalendar(&s,¬e); | ||
853 | qDebug("new loc %d ",note.Location); | ||
849 | } | 854 | } |
850 | 855 | ||
851 | start = true; | 856 | start = true; |
852 | GSM_ToDoEntry ToDo; | 857 | GSM_ToDoEntry ToDo; |
853 | ccc = 0; | 858 | ccc = 0; |
854 | message = i18n("Processing todo # "); | 859 | message = i18n(" Reading todo # "); |
855 | procCount = 0; | 860 | procCount = 0; |
856 | while (!gshutdown) { | 861 | while (!gshutdown && ccc++ < 10) { |
857 | status.setText ( message + QString::number ( ++procCount ) ); | 862 | status.setText ( message + QString::number ( ++procCount ) ); |
858 | qApp->processEvents(); | 863 | qApp->processEvents(); |
859 | error = Phone->GetNextToDo(&s, &ToDo, start); | 864 | error = Phone->GetNextToDo(&s, &ToDo, start); |
860 | if (error == ERR_EMPTY) break; | 865 | if (error == ERR_EMPTY) break; |
861 | start = false; | 866 | start = false; |
862 | qDebug("ReadTodo %d ", ++ccc); | 867 | qDebug("ReadTodo %d ", ccc); |
863 | handler.readTodo( existingCal, &ToDo, &s); | 868 | handler.readTodo( existingCal, &ToDo, &s); |
864 | 869 | ||
865 | } | 870 | } |
866 | 871 | ||
867 | error=GSM_TerminateConnection(&s); | 872 | error=GSM_TerminateConnection(&s); |
868 | 873 | ||
869 | return true; | 874 | return true; |
870 | } | 875 | } |
871 | void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note ) | 876 | #include <qcstring.h> |
877 | void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note ) | ||
872 | { | 878 | { |
873 | QString eText = vfconverter.eventToString( ev ); | 879 | QString eText = vfconverter.eventToString( ev, cal ); |
874 | int pos = 0; | 880 | int pos = 0; |
875 | GSM_ToDoEntry dummy; | 881 | GSM_ToDoEntry dummy; |
876 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | 882 | qDebug( "Convert event"); |
883 | QByteArray ba; | ||
884 | QDataStream s ( ba, IO_WriteOnly ); | ||
885 | s << eText.utf8(); | ||
886 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo ); | ||
887 | qDebug( "Convert event done"); | ||
888 | Note->Location = 0; | ||
889 | QString loc = ev->getID(mProfileName); | ||
890 | if ( !loc.isEmpty() ){ | ||
891 | Note->Location = loc.toInt(); | ||
892 | } | ||
893 | |||
877 | } | 894 | } |
878 | void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo ) | 895 | void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo ) |
879 | { | 896 | { |
880 | QString tText = vfconverter.todoToString( todo ); | 897 | qDebug( "Convert todo1"); |
898 | QString tText = vfconverter.todoToString( todo, cal ); | ||
881 | int pos = 0; | 899 | int pos = 0; |
882 | GSM_CalendarEntry dummy; | 900 | GSM_CalendarEntry dummy; |
883 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | 901 | QByteArray ba; |
902 | QDataStream s ( ba, IO_WriteOnly ); | ||
903 | s << tText.utf8(); | ||
904 | GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo ); | ||
905 | qDebug( "Convert todo done "); | ||
906 | gsmTodo->Location = 0; | ||
907 | QString loc = todo->getID(mProfileName); | ||
908 | if ( !loc.isEmpty() ){ | ||
909 | gsmTodo->Location = loc.toInt(); | ||
910 | } | ||
911 | |||
884 | } | 912 | } |
885 | void PhoneFormat::afterSave( Incidence* inc) | 913 | void PhoneFormat::afterSave( Incidence* inc) |
886 | { | 914 | { |
887 | uint csum; | 915 | uint csum; |
888 | if ( inc->type() == "Event") | 916 | if ( inc->type() == "Event") |
889 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); | 917 | csum = PhoneFormat::getCsumEvent( (Event*) inc ); |
890 | else | 918 | else |
891 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); | 919 | csum = PhoneFormat::getCsumTodo( (Todo*) inc ); |
892 | inc->setCsum( mProfileName, QString::number( csum )); | 920 | inc->setCsum( mProfileName, QString::number( csum )); |
893 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 921 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
894 | 922 | ||
895 | } | 923 | } |
896 | bool PhoneFormat::save( Calendar *calendar) | 924 | bool PhoneFormat::save( Calendar *calendar) |
897 | { | 925 | { |
926 | return true; | ||
898 | GSM_StateMachines; | 927 | GSM_StateMachines; |
899 | qDebug(" save "); | 928 | qDebug(" save "); |
900 | s.opened = false; | 929 | s.opened = false; |
901 | s.msg = NULL; | 930 | s.msg = NULL; |
902 | s.ConfigNum = 0; | 931 | s.ConfigNum = 0; |
903 | QLabel status ( i18n("Writing data. Opening device ..."), 0 ); | 932 | QLabel status ( i18n(" Opening device ..."), 0 ); |
904 | int w = status.sizeHint().width()+20 ; | 933 | int w = status.sizeHint().width()+20 ; |
905 | if ( w < 200 ) w = 200; | 934 | if ( w < 200 ) w = 230; |
906 | int h = status.sizeHint().height()+20 ; | 935 | int h = status.sizeHint().height()+20 ; |
907 | int dw = QApplication::desktop()->width(); | 936 | int dw = QApplication::desktop()->width(); |
908 | int dh = QApplication::desktop()->height(); | 937 | int dh = QApplication::desktop()->height(); |
909 | status.setCaption(i18n("Writing Phone Data") ); | 938 | status.setCaption(i18n("Writing to phone...") ); |
910 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 939 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
911 | status.show(); | 940 | status.show(); |
912 | status.raise(); | 941 | status.raise(); |
913 | qApp->processEvents(); | 942 | qApp->processEvents(); |
914 | 943 | ||
915 | int error=initDevice(&s); | 944 | int error=initDevice(&s); |
916 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); | 945 | qDebug("GSM Init %d (no error is %d)", error, ERR_NONE); |
917 | if ( error != ERR_NONE ) | 946 | if ( error != ERR_NONE ) |
918 | return false; | 947 | return false; |
919 | GSM_Phone_Functions*Phone; | 948 | GSM_Phone_Functions*Phone; |
920 | GSM_CalendarEntryNote; | 949 | GSM_CalendarEntryNote; |
921 | bool start = true; | 950 | bool start = true; |
922 | Phone=s.Phone.Functions; | 951 | Phone=s.Phone.Functions; |
923 | bool gshutdown = false; | 952 | bool gshutdown = false; |
924 | QPtrList<Event> er = calendar->rawEvents(); | 953 | QPtrList<Event> er = calendar->rawEvents(); |
925 | Event* ev = er.first(); | 954 | Event* ev = er.first(); |
926 | QString message = i18n("Processing event # "); | 955 | QString message = i18n(" Processing event # "); |
927 | int procCount = 0; | 956 | int procCount = 0; |
928 | while ( ev ) { | 957 | bool planB = true;// false; |
929 | //qDebug("i %d ", ++i); | 958 | while ( ev && ! planB) { |
930 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one | 959 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one |
931 | 960 | ||
932 | status.setText ( message + QString::number ( ++procCount ) ); | 961 | status.setText ( message + QString::number ( ++procCount ) ); |
933 | qApp->processEvents(); | 962 | qApp->processEvents(); |
934 | event2GSM( ev, &Note ); | 963 | qDebug("event1 %d ", procCount); |
964 | event2GSM( calendar, ev, &Note ); | ||
935 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 965 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
936 | error = Phone->DeleteCalendar(&s, &Note); | 966 | error = Phone->DeleteCalendar(&s, &Note); |
967 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
968 | planB = true; | ||
969 | qDebug(" e delete planB %d ", error); | ||
970 | break; | ||
971 | } | ||
937 | } | 972 | } |
938 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new | 973 | else if ( ev->getID(mProfileName).isEmpty() ) { // add new |
939 | // we have to do this later after deleting | 974 | // we have to do this later after deleting |
940 | 975 | ||
941 | } | 976 | } |
942 | else { // change existing | 977 | else { // change existing |
943 | error = Phone->SetCalendar(&s, &Note); | 978 | error = Phone->SetCalendar(&s, &Note); |
979 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
980 | planB = true; | ||
981 | qDebug(" e change planB %d ", error); | ||
982 | break; | ||
983 | } | ||
984 | qDebug("Change Calendar. Location %d status: %d",Note.Location, error ); | ||
944 | } | 985 | } |
945 | } | 986 | } |
946 | ev = er.next(); | 987 | ev = er.next(); |
947 | } | 988 | } |
948 | ev = er.first(); | 989 | ev = er.first(); |
949 | // pending get empty slots | 990 | // pending get empty slots |
950 | while ( ev ) { | 991 | int loc = 0; |
992 | while ( ev && ! planB) { | ||
951 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | 993 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { |
994 | qDebug("event2 %d ", procCount); | ||
952 | if ( ev->getID(mProfileName).isEmpty() ) { | 995 | if ( ev->getID(mProfileName).isEmpty() ) { |
953 | status.setText ( message + QString::number ( ++procCount ) ); | 996 | status.setText ( message + QString::number ( ++procCount ) ); |
954 | qApp->processEvents(); | 997 | qApp->processEvents(); |
955 | //int newID ;//= pending | 998 | //int newID ;//= pending |
956 | //ev->setID(mProfileName, QString::number( newID )); | 999 | //ev->setID(mProfileName, QString::number( newID )); |
957 | event2GSM( ev, &Note ); | 1000 | event2GSM( calendar, ev, &Note ); |
958 | Note.Location = 0; | 1001 | ++loc; |
1002 | Note.Location = loc; | ||
959 | error = Phone->AddCalendar(&s, &Note); | 1003 | error = Phone->AddCalendar(&s, &Note); |
1004 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1005 | planB = true; | ||
1006 | qDebug(" e add planB %d ", error); | ||
1007 | break; | ||
1008 | } | ||
960 | ev->setID( mProfileName, QString::number( Note.Location ) ); | 1009 | ev->setID( mProfileName, QString::number( Note.Location ) ); |
961 | qDebug("New Calendar. Location %d ",Note.Location ); | 1010 | qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN); |
962 | afterSave( ev ); | 1011 | afterSave( ev ); |
963 | } else { | 1012 | } else { |
964 | afterSave( ev ); // setting temp sync stat for changed items | 1013 | afterSave( ev ); // setting temp sync stat for changed items |
965 | } | 1014 | } |
966 | } | 1015 | } |
967 | ev = er.next(); | 1016 | ev = er.next(); |
968 | } | 1017 | } |
1018 | |||
1019 | |||
1020 | if ( planB ) { | ||
1021 | qDebug("delete all calendar..."); | ||
1022 | status.setText ( i18n("Deleting all calendar...")); | ||
1023 | qApp->processEvents(); | ||
1024 | error=Phone->DeleteAllCalendar(&s); | ||
1025 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1026 | message = i18n(" Deleting event # "); | ||
1027 | procCount = 0; | ||
1028 | while (1) { | ||
1029 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1030 | qApp->processEvents(); | ||
1031 | qDebug("deleting event ... %d", procCount); | ||
1032 | error = Phone->GetNextCalendar(&s,&Note,true); | ||
1033 | if (error != ERR_NONE) break; | ||
1034 | error = Phone->DeleteCalendar(&s,&Note); | ||
1035 | } | ||
1036 | qDebug("deleting calendar ... finished"); | ||
1037 | } else { | ||
1038 | status.setText ( i18n("All calendar deleted!")); | ||
1039 | qDebug("all cal deleted"); | ||
1040 | } | ||
1041 | bool planC = false; | ||
1042 | ev = er.first(); | ||
1043 | procCount = 0; | ||
1044 | message = i18n(" Writing event # "); | ||
1045 | while ( ev && ! planC) { | ||
1046 | status.setText ( message + QString::number ( ++procCount ) ); | ||
1047 | qApp->processEvents(); | ||
1048 | event2GSM( calendar, ev, &Note ); | ||
1049 | Note.Location = procCount; | ||
1050 | error=Phone->AddCalendar(&s,&Note); | ||
1051 | if (error != ERR_NONE ) { | ||
1052 | // we have currently no planC :-( | ||
1053 | // planC = true; | ||
1054 | //qDebug("add planC %d ", error); | ||
1055 | //break; | ||
1056 | // we remove the ID such that this todo is not deleted after next sync | ||
1057 | ev->removeID(mProfileName); | ||
1058 | ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1059 | qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1060 | } else { | ||
1061 | qDebug("cal adding loc %d planB stat %d ", Note.Location ,error); | ||
1062 | ev->setID(mProfileName, QString::number( Note.Location )); | ||
1063 | afterSave( ev ); | ||
1064 | } | ||
1065 | ev = er.next(); | ||
1066 | } | ||
1067 | if ( planC ) { | ||
1068 | qDebug("writing cal went wrong..."); | ||
1069 | |||
1070 | // we have currently no planC :-( | ||
1071 | } | ||
1072 | } | ||
969 | GSM_ToDoEntry ToDoEntry; | 1073 | GSM_ToDoEntry ToDoEntry; |
970 | QPtrList<Todo> tl = calendar->rawTodos(); | 1074 | QPtrList<Todo> tl = calendar->rawTodos(); |
971 | Todo* to = tl.first(); | 1075 | Todo* to = tl.first(); |
972 | 1076 | ||
973 | message = i18n("Processing todo # "); | 1077 | message = i18n(" Processing todo # "); |
974 | procCount = 0; | 1078 | procCount = 0; |
975 | while ( to ) { | 1079 | planB = false; |
1080 | while ( to && ! planB ) { | ||
976 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 1081 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
1082 | qDebug("todo3 %d ", procCount); | ||
977 | status.setText ( message + QString::number ( ++procCount ) ); | 1083 | status.setText ( message + QString::number ( ++procCount ) ); |
978 | qApp->processEvents(); | 1084 | qApp->processEvents(); |
979 | todo2GSM( to, &ToDoEntry ); | 1085 | qDebug("todo5 %d ", procCount); |
1086 | todo2GSM( calendar, to, &ToDoEntry ); | ||
980 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 1087 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
981 | error=Phone->DeleteToDo(&s,&ToDoEntry); | 1088 | error=Phone->DeleteToDo(&s,&ToDoEntry); |
1089 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1090 | planB = true; | ||
1091 | qDebug("delete planB %d ", error); | ||
1092 | } | ||
982 | } | 1093 | } |
983 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 1094 | else if ( to->getID(mProfileName).isEmpty() ) { // add new |
984 | ; | 1095 | ; |
985 | } | 1096 | } |
986 | else { // change existing | 1097 | else { // change existing |
987 | error=Phone->SetToDo(&s,&ToDoEntry); | 1098 | error=Phone->SetToDo(&s,&ToDoEntry); |
1099 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1100 | planB = true; | ||
1101 | qDebug("set planB %d ", error); | ||
1102 | } | ||
1103 | qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error ); | ||
988 | } | 1104 | } |
989 | } | 1105 | } |
990 | to = tl.next(); | 1106 | to = tl.next(); |
991 | } | 1107 | } |
992 | 1108 | ||
993 | // pending get empty slots | 1109 | // pending get empty slots |
994 | to = tl.first(); | 1110 | to = tl.first(); |
995 | while ( to ) { | 1111 | while ( to && ! planB ) { |
1112 | qDebug("todo2 %d ", procCount); | ||
996 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { | 1113 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { |
1114 | qDebug("todo4 %d ", procCount); | ||
997 | if ( to->getID(mProfileName).isEmpty() ) { | 1115 | if ( to->getID(mProfileName).isEmpty() ) { |
998 | status.setText ( message + QString::number ( ++procCount ) ); | 1116 | status.setText ( message + QString::number ( ++procCount ) ); |
999 | qApp->processEvents(); | 1117 | qApp->processEvents(); |
1000 | //int newID ;//= pending | 1118 | //int newID ;//= pending |
1001 | //to->setID(mProfileName, QString::number( newID )); | 1119 | //to->setID(mProfileName, QString::number( newID )); |
1002 | todo2GSM( to, &ToDoEntry ); | 1120 | todo2GSM( calendar,to, &ToDoEntry ); |
1003 | ToDoEntry.Location = 0; | 1121 | ToDoEntry.Location = 0; |
1004 | error=Phone->AddToDo(&s,&ToDoEntry); | 1122 | error=Phone->AddToDo(&s,&ToDoEntry); |
1123 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1124 | planB = true; | ||
1125 | qDebug("new planB %d ", error); | ||
1126 | } | ||
1005 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | 1127 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); |
1006 | afterSave( to ); | 1128 | afterSave( to ); |
1007 | qDebug("New Todo. Location %d ",ToDoEntry.Location ); | 1129 | qDebug("New Todo. Location %d %d",ToDoEntry.Location, error ); |
1008 | } else { | 1130 | } else { |
1009 | afterSave( to ); | 1131 | afterSave( to ); |
1010 | } | 1132 | } |
1011 | } | 1133 | } |
1012 | to = tl.next(); | 1134 | to = tl.next(); |
1013 | } | 1135 | } |
1136 | if ( planB ) { | ||
1137 | qDebug("delete all ..."); | ||
1138 | error=Phone->DeleteAllToDo(&s); | ||
1139 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1140 | while (1) { | ||
1141 | qDebug("deleting todo ..."); | ||
1142 | error = Phone->GetNextToDo(&s,&ToDoEntry,true); | ||
1143 | if (error != ERR_NONE) break; | ||
1144 | error = Phone->DeleteToDo(&s,&ToDoEntry); | ||
1145 | } | ||
1146 | qDebug("deleting todo ... finished"); | ||
1147 | } else { | ||
1148 | qDebug("all todo deleted"); | ||
1149 | } | ||
1150 | bool planC = false; | ||
1151 | to = tl.first(); | ||
1152 | while ( to && ! planC ) { | ||
1153 | todo2GSM( calendar,to, &ToDoEntry ); | ||
1154 | ToDoEntry.Location = 0; | ||
1155 | error=Phone->AddToDo(&s,&ToDoEntry); | ||
1156 | if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { | ||
1157 | // we have currently no planC :-( | ||
1158 | // planC = true; | ||
1159 | //qDebug("add planC %d ", error); | ||
1160 | //break; | ||
1161 | // we remove the ID such that this todo is not deleted after next sync | ||
1162 | to->removeID(mProfileName); | ||
1163 | to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
1164 | } else { | ||
1165 | qDebug("adding %d planB %d ", ToDoEntry.Location ,error); | ||
1166 | to->setID(mProfileName, QString::number( ToDoEntry.Location )); | ||
1167 | afterSave( to ); | ||
1168 | } | ||
1169 | to = tl.next(); | ||
1170 | } | ||
1171 | if ( planC ) { | ||
1172 | // we have currently no planC :-( | ||
1173 | } | ||
1174 | } | ||
1014 | return true; | 1175 | return true; |
1015 | } | 1176 | } |
1016 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) | 1177 | QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ ) |
1017 | { | 1178 | { |
1018 | QString datestr; | 1179 | QString datestr; |
1019 | QString timestr; | 1180 | QString timestr; |
1020 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 1181 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
1021 | QDateTime dt; | 1182 | QDateTime dt; |
1022 | if (useTZ) | 1183 | if (useTZ) |
1023 | dt = dti.addSecs ( -(offset*60)); | 1184 | dt = dti.addSecs ( -(offset*60)); |
1024 | else | 1185 | else |
1025 | dt = dti; | 1186 | dt = dti; |
1026 | if(dt.date().isValid()){ | 1187 | if(dt.date().isValid()){ |
1027 | const QDate& date = dt.date(); | 1188 | const QDate& date = dt.date(); |
1028 | datestr.sprintf("%04d%02d%02d", | 1189 | datestr.sprintf("%04d%02d%02d", |
1029 | date.year(), date.month(), date.day()); | 1190 | date.year(), date.month(), date.day()); |
1030 | } | 1191 | } |
1031 | if(dt.time().isValid()){ | 1192 | if(dt.time().isValid()){ |
1032 | const QTime& time = dt.time(); | 1193 | const QTime& time = dt.time(); |
1033 | timestr.sprintf("T%02d%02d%02d", | 1194 | timestr.sprintf("T%02d%02d%02d", |
1034 | time.hour(), time.minute(), time.second()); | 1195 | time.hour(), time.minute(), time.second()); |
1035 | } | 1196 | } |
1036 | return datestr + timestr; | 1197 | return datestr + timestr; |
1037 | } | 1198 | } |
1038 | QString PhoneFormat::getEventString( Event* event ) | 1199 | QString PhoneFormat::getEventString( Event* event ) |
1039 | { | 1200 | { |
1040 | #if 0 | 1201 | #if 0 |
1041 | QStringList list; | 1202 | QStringList list; |
1042 | list.append( QString::number(event->zaurusId() ) ); | 1203 | list.append( QString::number(event->zaurusId() ) ); |
1043 | list.append( event->categories().join(",") ); | 1204 | list.append( event->categories().join(",") ); |
1044 | if ( !event->summary().isEmpty() ) | 1205 | if ( !event->summary().isEmpty() ) |
1045 | list.append( event->summary() ); | 1206 | list.append( event->summary() ); |
1046 | else | 1207 | else |
1047 | list.append("" ); | 1208 | list.append("" ); |
1048 | if ( !event->location().isEmpty() ) | 1209 | if ( !event->location().isEmpty() ) |
1049 | list.append( event->location() ); | 1210 | list.append( event->location() ); |
1050 | else | 1211 | else |
1051 | list.append("" ); | 1212 | list.append("" ); |
1052 | if ( !event->description().isEmpty() ) | 1213 | if ( !event->description().isEmpty() ) |
1053 | list.append( event->description() ); | 1214 | list.append( event->description() ); |
1054 | else | 1215 | else |
1055 | list.append( "" ); | 1216 | list.append( "" ); |
1056 | if ( event->doesFloat () ) { | 1217 | if ( event->doesFloat () ) { |
1057 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 1218 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
1058 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 1219 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
1059 | list.append( "1" ); | 1220 | list.append( "1" ); |
1060 | 1221 | ||
1061 | } | 1222 | } |