author | zautrix <zautrix> | 2004-08-09 11:07:44 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-09 11:07:44 (UTC) |
commit | 2d3e20244a156485f6001aa82c4494dfce177b8f (patch) (unidiff) | |
tree | c5cc2cc6eaa79b6d6dd1c7dd27f29d3871d6a528 /libkcal | |
parent | b51c65d86224ee7d77e672fcfba5ea92d55eed0e (diff) | |
download | kdepimpi-2d3e20244a156485f6001aa82c4494dfce177b8f.zip kdepimpi-2d3e20244a156485f6001aa82c4494dfce177b8f.tar.gz kdepimpi-2d3e20244a156485f6001aa82c4494dfce177b8f.tar.bz2 |
minor fixes
-rw-r--r-- | libkcal/phoneformat.cpp | 16 | ||||
-rw-r--r-- | libkcal/sharpformat.cpp | 8 |
2 files changed, 22 insertions, 2 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 7e1c9cd..94744fb 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp | |||
@@ -45,258 +45,264 @@ | |||
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 = 1; 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 = 5; 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 | QString completedString = "no"; | 83 | QString completedString = "no"; |
84 | for (j=0;j<ToDo->EntriesNum;j++) { | 84 | for (j=0;j<ToDo->EntriesNum;j++) { |
85 | 85 | ||
86 | //qDebug(" for todo %d",ToDo->Location ); | 86 | //qDebug(" for todo %d",ToDo->Location ); |
87 | switch (ToDo->Entries[j].EntryType) { | 87 | switch (ToDo->Entries[j].EntryType) { |
88 | case TODO_END_DATETIME: | 88 | case TODO_END_DATETIME: |
89 | dtp = &ToDo->Entries[j].Date ; | 89 | dtp = &ToDo->Entries[j].Date ; |
90 | todo->setDtDue (fromGSM ( dtp )); | 90 | todo->setDtDue (fromGSM ( dtp )); |
91 | break; | 91 | break; |
92 | case TODO_COMPLETED: | 92 | case TODO_COMPLETED: |
93 | if ( ToDo->Entries[j].Number == 1 ) { | 93 | if ( ToDo->Entries[j].Number == 1 ) { |
94 | todo->setCompleted( true ); | 94 | todo->setCompleted( true ); |
95 | completedString = "yes"; | 95 | completedString = "yes"; |
96 | } | 96 | } |
97 | else { | 97 | else { |
98 | todo->setCompleted( false ); | 98 | todo->setCompleted( false ); |
99 | } | 99 | } |
100 | break; | 100 | break; |
101 | case TODO_ALARM_DATETIME: | 101 | case TODO_ALARM_DATETIME: |
102 | dtp = &ToDo->Entries[j].Date ; | 102 | dtp = &ToDo->Entries[j].Date ; |
103 | alarm = true; | 103 | alarm = true; |
104 | alarmDt = fromGSM ( dtp ); | 104 | alarmDt = fromGSM ( dtp ); |
105 | break; | 105 | break; |
106 | case TODO_SILENT_ALARM_DATETIME: | 106 | case TODO_SILENT_ALARM_DATETIME: |
107 | dtp = &ToDo->Entries[j].Date ; | 107 | dtp = &ToDo->Entries[j].Date ; |
108 | alarm = true; | 108 | alarm = true; |
109 | alarmDt = fromGSM ( dtp ); | 109 | alarmDt = fromGSM ( dtp ); |
110 | break; | 110 | break; |
111 | case TODO_TEXT: | 111 | case TODO_TEXT: |
112 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); | 112 | //qDebug(" text *%s* ", (const char*) DecodeUnicodeConsole(ToDo->Entries[j].Text )); |
113 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); | 113 | todo->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole(ToDo->Entries[j].Text ))); |
114 | break; | 114 | break; |
115 | case TODO_PRIVATE: | 115 | case TODO_PRIVATE: |
116 | if ( ToDo->Entries[j].Number == 1 ) | 116 | if ( ToDo->Entries[j].Number == 1 ) |
117 | todo->setSecrecy( Incidence::SecrecyPrivate ); | 117 | todo->setSecrecy( Incidence::SecrecyPrivate ); |
118 | else | 118 | else |
119 | todo->setSecrecy( Incidence::SecrecyPublic ); | 119 | todo->setSecrecy( Incidence::SecrecyPublic ); |
120 | break; | 120 | break; |
121 | case TODO_CATEGORY: | 121 | case TODO_CATEGORY: |
122 | Category.Location = ToDo->Entries[j].Number; | 122 | Category.Location = ToDo->Entries[j].Number; |
123 | Category.Type = Category_ToDo; | 123 | Category.Type = Category_ToDo; |
124 | error=Phone->GetCategory(s, &Category); | 124 | error=Phone->GetCategory(s, &Category); |
125 | if (error == ERR_NONE) { | 125 | if (error == ERR_NONE) { |
126 | QStringList cat = todo->categories(); | 126 | QStringList cat = todo->categories(); |
127 | QString nCat = QString ( (const char*)Category.Name ); | 127 | QString nCat = QString ( (const char*)Category.Name ); |
128 | if ( !nCat.isEmpty() ) | 128 | if ( !nCat.isEmpty() ) |
129 | if ( !cat.contains( nCat )) { | 129 | if ( !cat.contains( nCat )) { |
130 | cat << nCat; | 130 | cat << nCat; |
131 | todo->setCategories( cat ); | 131 | todo->setCategories( cat ); |
132 | } | 132 | } |
133 | } | 133 | } |
134 | break; | 134 | break; |
135 | case TODO_CONTACTID: | 135 | case TODO_CONTACTID: |
136 | #if 0 | 136 | #if 0 |
137 | // not supported | 137 | // not supported |
138 | entry.Location = ToDo->Entries[j].Number; | 138 | entry.Location = ToDo->Entries[j].Number; |
139 | entry.MemoryType = MEM_ME; | 139 | entry.MemoryType = MEM_ME; |
140 | error=Phone->GetMemory(s, &entry); | 140 | error=Phone->GetMemory(s, &entry); |
141 | if (error == ERR_NONE) { | 141 | if (error == ERR_NONE) { |
142 | name = GSM_PhonebookGetEntryName(&entry); | 142 | name = GSM_PhonebookGetEntryName(&entry); |
143 | if (name != NULL) { | 143 | if (name != NULL) { |
144 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); | 144 | printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); |
145 | } else { | 145 | } else { |
146 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); | 146 | printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); |
147 | } | 147 | } |
148 | } else { | 148 | } else { |
149 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); | 149 | printmsg("Contact : %d\n",ToDo->Entries[j].Number); |
150 | } | 150 | } |
151 | #endif | 151 | #endif |
152 | break; | 152 | break; |
153 | case TODO_PHONE: | 153 | case TODO_PHONE: |
154 | #if 0 | 154 | #if 0 |
155 | // not supported | 155 | // not supported |
156 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); | 156 | printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); |
157 | #endif | 157 | #endif |
158 | break; | 158 | break; |
159 | } | 159 | } |
160 | } | 160 | } |
161 | QString alarmString = ""; | 161 | QString alarmString = ""; |
162 | if ( alarm ) { | 162 | if ( alarm ) { |
163 | Alarm *alarm; | 163 | Alarm *alarm; |
164 | if ( todo->alarms().count() > 0 ) | 164 | if ( todo->alarms().count() > 0 ) |
165 | alarm = todo->alarms().first(); | 165 | alarm = todo->alarms().first(); |
166 | else { | 166 | else { |
167 | alarm = new Alarm( todo ); | 167 | alarm = new Alarm( todo ); |
168 | todo->addAlarm( alarm ); | 168 | todo->addAlarm( alarm ); |
169 | } | 169 | } |
170 | alarm->setType( Alarm::Audio ); | 170 | alarm->setType( Alarm::Audio ); |
171 | alarm->setEnabled( true ); | 171 | alarm->setEnabled( true ); |
172 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); | 172 | int alarmOffset = alarmDt.secsTo( todo->dtStart() ); |
173 | alarm->setStartOffset( alarmOffset ); | 173 | alarm->setStartOffset( -alarmOffset ); |
174 | alarmString = QString::number( alarmOffset ); | 174 | alarmString = QString::number( alarmOffset ); |
175 | } else { | ||
176 | Alarm *alarm; | ||
177 | if ( todo->alarms().count() > 0 ) { | ||
178 | alarm = todo->alarms().first(); | ||
179 | alarm->setEnabled( false ); | ||
180 | } | ||
175 | } | 181 | } |
176 | // csum ***************************************** | 182 | // csum ***************************************** |
177 | QStringList attList; | 183 | QStringList attList; |
178 | uint cSum; | 184 | uint cSum; |
179 | if ( todo->hasDueDate() ) | 185 | if ( todo->hasDueDate() ) |
180 | attList << dtToString ( todo->dtDue() ); | 186 | attList << dtToString ( todo->dtDue() ); |
181 | attList << QString::number( id ); | 187 | attList << QString::number( id ); |
182 | attList << todo->summary(); | 188 | attList << todo->summary(); |
183 | attList << completedString; | 189 | attList << completedString; |
184 | attList << QString::number( todo->priority() ); | 190 | attList << QString::number( todo->priority() ); |
185 | attList << alarmString; | 191 | attList << alarmString; |
186 | attList << todo->categoriesStr(); | 192 | attList << todo->categoriesStr(); |
187 | attList << todo->secrecyStr(); | 193 | attList << todo->secrecyStr(); |
188 | cSum = PhoneFormat::getCsum(attList ); | 194 | cSum = PhoneFormat::getCsum(attList ); |
189 | todo->setCsum( mProfileName, QString::number( cSum )); | 195 | todo->setCsum( mProfileName, QString::number( cSum )); |
190 | mCalendar->addTodo( todo); | 196 | mCalendar->addTodo( todo); |
191 | 197 | ||
192 | return true; | 198 | return true; |
193 | } | 199 | } |
194 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) | 200 | bool readEvent( Calendar *existingCalendar, GSM_CalendarEntry*Note) |
195 | { | 201 | { |
196 | 202 | ||
197 | int id = Note->Location; | 203 | int id = Note->Location; |
198 | Event *event; | 204 | Event *event; |
199 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); | 205 | event = existingCalendar->event( mProfileName ,QString::number( id ) ); |
200 | if ( event ) | 206 | if ( event ) |
201 | event = (Event*)event->clone(); | 207 | event = (Event*)event->clone(); |
202 | else | 208 | else |
203 | event = new Event; | 209 | event = new Event; |
204 | event->setID( mProfileName,QString::number( id ) ); | 210 | event->setID( mProfileName,QString::number( id ) ); |
205 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 211 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
206 | 212 | ||
207 | 213 | ||
208 | int i = 0; | 214 | int i = 0; |
209 | bool repeating = false; | 215 | bool repeating = false; |
210 | int repeat_dayofweek = -1; | 216 | int repeat_dayofweek = -1; |
211 | int repeat_day = -1; | 217 | int repeat_day = -1; |
212 | int repeat_weekofmonth = -1; | 218 | int repeat_weekofmonth = -1; |
213 | int repeat_month = -1; | 219 | int repeat_month = -1; |
214 | int repeat_frequency = -1; | 220 | int repeat_frequency = -1; |
215 | int rec_type = -1; | 221 | int rec_type = -1; |
216 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | 222 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; |
217 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | 223 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; |
218 | GSM_DateTime* dtp; | 224 | GSM_DateTime* dtp; |
219 | bool alarm = false; | 225 | bool alarm = false; |
220 | QDateTime alarmDt; | 226 | QDateTime alarmDt; |
221 | repeat_startdate.Day= 0; | 227 | repeat_startdate.Day= 0; |
222 | repeat_stopdate.Day = 0; | 228 | repeat_stopdate.Day = 0; |
223 | for (i=0;i<Note->EntriesNum;i++) { | 229 | for (i=0;i<Note->EntriesNum;i++) { |
224 | 230 | ||
225 | //qDebug(" for ev"); | 231 | //qDebug(" for ev"); |
226 | switch (Note->Entries[i].EntryType) { | 232 | switch (Note->Entries[i].EntryType) { |
227 | case CAL_START_DATETIME: | 233 | case CAL_START_DATETIME: |
228 | dtp = &Note->Entries[i].Date ; | 234 | dtp = &Note->Entries[i].Date ; |
229 | if ( dtp->Hour > 24 ) { | 235 | if ( dtp->Hour > 24 ) { |
230 | event->setFloats( true ); | 236 | event->setFloats( true ); |
231 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 237 | event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
232 | } else { | 238 | } else { |
233 | event->setDtStart (fromGSM ( dtp )); | 239 | event->setDtStart (fromGSM ( dtp )); |
234 | 240 | ||
235 | } | 241 | } |
236 | break; | 242 | break; |
237 | case CAL_END_DATETIME: | 243 | case CAL_END_DATETIME: |
238 | dtp = &Note->Entries[i].Date ; | 244 | dtp = &Note->Entries[i].Date ; |
239 | if ( dtp->Hour > 24 ) { | 245 | if ( dtp->Hour > 24 ) { |
240 | event->setFloats( true ); | 246 | event->setFloats( true ); |
241 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); | 247 | event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); |
242 | } else { | 248 | } else { |
243 | event->setDtEnd (fromGSM ( dtp )); | 249 | event->setDtEnd (fromGSM ( dtp )); |
244 | } | 250 | } |
245 | break; | 251 | break; |
246 | case CAL_ALARM_DATETIME: | 252 | case CAL_ALARM_DATETIME: |
247 | dtp = &Note->Entries[i].Date ; | 253 | dtp = &Note->Entries[i].Date ; |
248 | alarm = true; | 254 | alarm = true; |
249 | alarmDt = fromGSM ( dtp ); | 255 | alarmDt = fromGSM ( dtp ); |
250 | break; | 256 | break; |
251 | case CAL_SILENT_ALARM_DATETIME: | 257 | case CAL_SILENT_ALARM_DATETIME: |
252 | dtp = &Note->Entries[i].Date ; | 258 | dtp = &Note->Entries[i].Date ; |
253 | alarm = true; | 259 | alarm = true; |
254 | alarmDt = fromGSM ( dtp ); | 260 | alarmDt = fromGSM ( dtp ); |
255 | break; | 261 | break; |
256 | case CAL_RECURRANCE: | 262 | case CAL_RECURRANCE: |
257 | rec_type = Note->Entries[i].Number; | 263 | rec_type = Note->Entries[i].Number; |
258 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); | 264 | //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); |
259 | break; | 265 | break; |
260 | case CAL_TEXT: | 266 | case CAL_TEXT: |
261 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); | 267 | //qDebug(" ev text %s", DecodeUnicodeConsole(Note->Entries[i].Text) ); |
262 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); | 268 | event->setSummary( QString::fromUtf8 ( (const char*)DecodeUnicodeConsole( Note->Entries[i].Text ))); |
263 | break; | 269 | break; |
264 | case CAL_LOCATION: | 270 | case CAL_LOCATION: |
265 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); | 271 | event->setLocation(QString::fromUtf8 ((const char*) DecodeUnicodeConsole(Note->Entries[i].Text) )); |
266 | break; | 272 | break; |
267 | case CAL_PHONE: | 273 | case CAL_PHONE: |
268 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); | 274 | //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); |
269 | break; | 275 | break; |
270 | case CAL_PRIVATE: | 276 | case CAL_PRIVATE: |
271 | if ( Note->Entries[i].Number == 1 ) | 277 | if ( Note->Entries[i].Number == 1 ) |
272 | event->setSecrecy( Incidence::SecrecyPrivate ); | 278 | event->setSecrecy( Incidence::SecrecyPrivate ); |
273 | else | 279 | else |
274 | event->setSecrecy( Incidence::SecrecyPublic ); | 280 | event->setSecrecy( Incidence::SecrecyPublic ); |
275 | 281 | ||
276 | break; | 282 | break; |
277 | case CAL_CONTACTID: | 283 | case CAL_CONTACTID: |
278 | #if 0 | 284 | #if 0 |
279 | entry.Location = Note->Entries[i].Number; | 285 | entry.Location = Note->Entries[i].Number; |
280 | entry.MemoryType = MEM_ME; | 286 | entry.MemoryType = MEM_ME; |
281 | error=Phone->GetMemory(&s, &entry); | 287 | error=Phone->GetMemory(&s, &entry); |
282 | if (error == ERR_NONE) { | 288 | if (error == ERR_NONE) { |
283 | name = GSM_PhonebookGetEntryName(&entry); | 289 | name = GSM_PhonebookGetEntryName(&entry); |
284 | if (name != NULL) { | 290 | if (name != NULL) { |
285 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); | 291 | //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); |
286 | } else { | 292 | } else { |
287 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | 293 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); |
288 | } | 294 | } |
289 | } else { | 295 | } else { |
290 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); | 296 | //printmsg("Contact ID : %d\n",Note->Entries[i].Number); |
291 | } | 297 | } |
292 | #endif | 298 | #endif |
293 | break; | 299 | break; |
294 | case CAL_REPEAT_DAYOFWEEK: | 300 | case CAL_REPEAT_DAYOFWEEK: |
295 | repeat_dayofweek = Note->Entries[i].Number; | 301 | repeat_dayofweek = Note->Entries[i].Number; |
296 | repeating = true; | 302 | repeating = true; |
297 | break; | 303 | break; |
298 | case CAL_REPEAT_DAY: | 304 | case CAL_REPEAT_DAY: |
299 | repeat_day = Note->Entries[i].Number; | 305 | repeat_day = Note->Entries[i].Number; |
300 | repeating = true; | 306 | repeating = true; |
301 | break; | 307 | break; |
302 | case CAL_REPEAT_WEEKOFMONTH: | 308 | case CAL_REPEAT_WEEKOFMONTH: |
@@ -323,258 +329,264 @@ public: | |||
323 | } | 329 | } |
324 | #if 0 | 330 | #if 0 |
325 | event->setDescription( attList[4] ); | 331 | event->setDescription( attList[4] ); |
326 | bool repeating = false; | 332 | bool repeating = false; |
327 | int repeat_dayofweek = -1; | 333 | int repeat_dayofweek = -1; |
328 | int repeat_day = -1; | 334 | int repeat_day = -1; |
329 | int repeat_weekofmonth = -1; | 335 | int repeat_weekofmonth = -1; |
330 | int repeat_month = -1; | 336 | int repeat_month = -1; |
331 | int repeat_frequency = -1; | 337 | int repeat_frequency = -1; |
332 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; | 338 | GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; |
333 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; | 339 | GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; |
334 | 340 | ||
335 | #endif | 341 | #endif |
336 | 342 | ||
337 | QString recurString = "no"; | 343 | QString recurString = "no"; |
338 | if ( repeating ) { | 344 | if ( repeating ) { |
339 | recurString = "y"; | 345 | recurString = "y"; |
340 | if ( repeat_dayofweek >= 0 ) | 346 | if ( repeat_dayofweek >= 0 ) |
341 | recurString += "dow" + QString::number (repeat_dayofweek); | 347 | recurString += "dow" + QString::number (repeat_dayofweek); |
342 | if ( repeat_day >= 0 ) | 348 | if ( repeat_day >= 0 ) |
343 | recurString += "d" + QString::number (repeat_day); | 349 | recurString += "d" + QString::number (repeat_day); |
344 | if ( repeat_weekofmonth >= 0 ) | 350 | if ( repeat_weekofmonth >= 0 ) |
345 | recurString += "w" + QString::number (repeat_weekofmonth); | 351 | recurString += "w" + QString::number (repeat_weekofmonth); |
346 | if ( repeat_month >= 0 ) | 352 | if ( repeat_month >= 0 ) |
347 | recurString += "m" + QString::number ( repeat_month ); | 353 | recurString += "m" + QString::number ( repeat_month ); |
348 | if ( repeat_frequency >= 0 ) | 354 | if ( repeat_frequency >= 0 ) |
349 | recurString += "f" + QString::number (repeat_frequency ); | 355 | recurString += "f" + QString::number (repeat_frequency ); |
350 | 356 | ||
351 | int rtype = 0; | 357 | int rtype = 0; |
352 | // qDebug("recurs "); | 358 | // qDebug("recurs "); |
353 | QDate startDate, endDate; | 359 | QDate startDate, endDate; |
354 | if ( repeat_startdate.Day > 0 ) | 360 | if ( repeat_startdate.Day > 0 ) |
355 | startDate = datefromGSM ( &repeat_startdate ); | 361 | startDate = datefromGSM ( &repeat_startdate ); |
356 | else | 362 | else |
357 | startDate = event->dtStart().date(); | 363 | startDate = event->dtStart().date(); |
358 | int freq = repeat_frequency; | 364 | int freq = repeat_frequency; |
359 | bool hasEndDate = false; | 365 | bool hasEndDate = false; |
360 | if ( repeat_stopdate.Day > 0 ) { | 366 | if ( repeat_stopdate.Day > 0 ) { |
361 | endDate = datefromGSM ( &repeat_stopdate ); | 367 | endDate = datefromGSM ( &repeat_stopdate ); |
362 | hasEndDate = true; | 368 | hasEndDate = true; |
363 | } | 369 | } |
364 | 370 | ||
365 | uint weekDaysNum = repeat_dayofweek ; | 371 | uint weekDaysNum = repeat_dayofweek ; |
366 | 372 | ||
367 | QBitArray weekDays( 7 ); | 373 | QBitArray weekDays( 7 ); |
368 | int i; | 374 | int i; |
369 | int bb = 1; | 375 | int bb = 1; |
370 | for( i = 1; i <= 7; ++i ) { | 376 | for( i = 1; i <= 7; ++i ) { |
371 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 377 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
372 | bb = 2 << (i-1); | 378 | bb = 2 << (i-1); |
373 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 379 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
374 | } | 380 | } |
375 | // qDebug("next "); | 381 | // qDebug("next "); |
376 | int pos = 0; | 382 | int pos = 0; |
377 | Recurrence *r = event->recurrence(); | 383 | Recurrence *r = event->recurrence(); |
378 | /* | 384 | /* |
379 | 0 daily; | 385 | 0 daily; |
380 | 1 weekly;x | 386 | 1 weekly;x |
381 | 2 monthpos;x | 387 | 2 monthpos;x |
382 | 3 monthlyday; | 388 | 3 monthlyday; |
383 | 4 rYearlyMont | 389 | 4 rYearlyMont |
384 | bool repeating = false; | 390 | bool repeating = false; |
385 | int repeat_dayofweek = -1; | 391 | int repeat_dayofweek = -1; |
386 | int repeat_day = -1; | 392 | int repeat_day = -1; |
387 | int repeat_weekofmonth = -1; | 393 | int repeat_weekofmonth = -1; |
388 | int repeat_month = -1; | 394 | int repeat_month = -1; |
389 | int repeat_frequency = -1; | 395 | int repeat_frequency = -1; |
390 | */ | 396 | */ |
391 | int dayOfWeek = startDate.dayOfWeek(); | 397 | int dayOfWeek = startDate.dayOfWeek(); |
392 | if ( repeat_weekofmonth >= 0 ) { | 398 | if ( repeat_weekofmonth >= 0 ) { |
393 | rtype = 2; | 399 | rtype = 2; |
394 | pos = repeat_weekofmonth; | 400 | pos = repeat_weekofmonth; |
395 | if ( repeat_dayofweek >= 0 ) | 401 | if ( repeat_dayofweek >= 0 ) |
396 | dayOfWeek = repeat_dayofweek; | 402 | dayOfWeek = repeat_dayofweek; |
397 | } else if ( repeat_dayofweek >= 0 ) { | 403 | } else if ( repeat_dayofweek >= 0 ) { |
398 | rtype = 1; | 404 | rtype = 1; |
399 | } if ( repeat_dayofweek >= 0 ) { | 405 | } if ( repeat_dayofweek >= 0 ) { |
400 | rtype = 1; | 406 | rtype = 1; |
401 | } | 407 | } |
402 | 408 | ||
403 | if ( rtype == 0 ) { | 409 | if ( rtype == 0 ) { |
404 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 410 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
405 | else r->setDaily( freq, -1 ); | 411 | else r->setDaily( freq, -1 ); |
406 | } else if ( rtype == 1 ) { | 412 | } else if ( rtype == 1 ) { |
407 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 413 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
408 | else r->setWeekly( freq, weekDays, -1 ); | 414 | else r->setWeekly( freq, weekDays, -1 ); |
409 | } else if ( rtype == 3 ) { | 415 | } else if ( rtype == 3 ) { |
410 | if ( hasEndDate ) | 416 | if ( hasEndDate ) |
411 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 417 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
412 | else | 418 | else |
413 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 419 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
414 | r->addMonthlyDay( startDate.day() ); | 420 | r->addMonthlyDay( startDate.day() ); |
415 | } else if ( rtype == 2 ) { | 421 | } else if ( rtype == 2 ) { |
416 | if ( hasEndDate ) | 422 | if ( hasEndDate ) |
417 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 423 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
418 | else | 424 | else |
419 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 425 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
420 | QBitArray days( 7 ); | 426 | QBitArray days( 7 ); |
421 | days.fill( false ); | 427 | days.fill( false ); |
422 | days.setBit( dayOfWeek - 1 ); | 428 | days.setBit( dayOfWeek - 1 ); |
423 | r->addMonthlyPos( pos, days ); | 429 | r->addMonthlyPos( pos, days ); |
424 | } else if ( rtype == 4 ) { | 430 | } else if ( rtype == 4 ) { |
425 | if ( hasEndDate ) | 431 | if ( hasEndDate ) |
426 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 432 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
427 | else | 433 | else |
428 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 434 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
429 | r->addYearlyNum( startDate.month() ); | 435 | r->addYearlyNum( startDate.month() ); |
430 | } | 436 | } |
431 | } else { | 437 | } else { |
432 | event->recurrence()->unsetRecurs(); | 438 | event->recurrence()->unsetRecurs(); |
433 | } | 439 | } |
434 | 440 | ||
435 | QStringList categoryList; | 441 | QStringList categoryList; |
436 | categoryList << getCategory( Note ); | 442 | categoryList << getCategory( Note ); |
437 | event->setCategories( categoryList ); | 443 | event->setCategories( categoryList ); |
438 | QString alarmString = ""; | 444 | QString alarmString = ""; |
439 | // strange 0 semms to mean: alarm enabled | 445 | // strange 0 semms to mean: alarm enabled |
440 | if ( alarm ) { | 446 | if ( alarm ) { |
441 | Alarm *alarm; | 447 | Alarm *alarm; |
442 | if ( event->alarms().count() > 0 ) | 448 | if ( event->alarms().count() > 0 ) |
443 | alarm = event->alarms().first(); | 449 | alarm = event->alarms().first(); |
444 | else { | 450 | else { |
445 | alarm = new Alarm( event ); | 451 | alarm = new Alarm( event ); |
446 | event->addAlarm( alarm ); | 452 | event->addAlarm( alarm ); |
447 | } | 453 | } |
448 | alarm->setType( Alarm::Audio ); | 454 | alarm->setType( Alarm::Audio ); |
449 | alarm->setEnabled( true ); | 455 | alarm->setEnabled( true ); |
450 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); | 456 | int alarmOffset = alarmDt.secsTo( event->dtStart() ); |
451 | alarm->setStartOffset( alarmOffset ); | 457 | alarm->setStartOffset( -alarmOffset ); |
452 | alarmString = QString::number( alarmOffset ); | 458 | alarmString = QString::number( alarmOffset ); |
459 | } else { | ||
460 | Alarm *alarm; | ||
461 | if ( event->alarms().count() > 0 ) { | ||
462 | alarm = event->alarms().first(); | ||
463 | alarm->setEnabled( false ); | ||
464 | } | ||
453 | } | 465 | } |
454 | // csum ***************************************** | 466 | // csum ***************************************** |
455 | QStringList attList; | 467 | QStringList attList; |
456 | uint cSum; | 468 | uint cSum; |
457 | attList << dtToString ( event->dtStart() ); | 469 | attList << dtToString ( event->dtStart() ); |
458 | attList << dtToString ( event->dtEnd() ); | 470 | attList << dtToString ( event->dtEnd() ); |
459 | attList << QString::number( id ); | 471 | attList << QString::number( id ); |
460 | attList << event->summary(); | 472 | attList << event->summary(); |
461 | attList << event->location(); | 473 | attList << event->location(); |
462 | attList << alarmString; | 474 | attList << alarmString; |
463 | attList << recurString; | 475 | attList << recurString; |
464 | attList << event->categoriesStr(); | 476 | attList << event->categoriesStr(); |
465 | attList << event->secrecyStr(); | 477 | attList << event->secrecyStr(); |
466 | cSum = PhoneFormat::getCsum(attList ); | 478 | cSum = PhoneFormat::getCsum(attList ); |
467 | event->setCsum( mProfileName, QString::number( cSum )); | 479 | event->setCsum( mProfileName, QString::number( cSum )); |
468 | mCalendar->addEvent( event); | 480 | mCalendar->addEvent( event); |
469 | 481 | ||
470 | return true; | 482 | return true; |
471 | } | 483 | } |
472 | 484 | ||
473 | 485 | ||
474 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { | 486 | QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) { |
475 | QDateTime dt; | 487 | QDateTime dt; |
476 | int y,m,t,h,min,sec; | 488 | int y,m,t,h,min,sec; |
477 | y = dtp->Year; | 489 | y = dtp->Year; |
478 | m = dtp->Month; | 490 | m = dtp->Month; |
479 | t = dtp->Day; | 491 | t = dtp->Day; |
480 | h = dtp->Hour; | 492 | h = dtp->Hour; |
481 | min = dtp->Minute; | 493 | min = dtp->Minute; |
482 | sec = dtp->Second; | 494 | sec = dtp->Second; |
483 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 495 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
484 | // dtp->Timezone: offset in hours | 496 | // dtp->Timezone: offset in hours |
485 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 497 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
486 | if ( useTz ) | 498 | if ( useTz ) |
487 | dt = dt.addSecs ( offset*60); | 499 | dt = dt.addSecs ( offset*60); |
488 | return dt; | 500 | return dt; |
489 | 501 | ||
490 | } | 502 | } |
491 | 503 | ||
492 | QString dtToString( const QDateTime& dti, bool useTZ = false ) | 504 | QString dtToString( const QDateTime& dti, bool useTZ = false ) |
493 | { | 505 | { |
494 | QString datestr; | 506 | QString datestr; |
495 | QString timestr; | 507 | QString timestr; |
496 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 508 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
497 | QDateTime dt; | 509 | QDateTime dt; |
498 | if (useTZ) | 510 | if (useTZ) |
499 | dt = dti.addSecs ( -(offset*60)); | 511 | dt = dti.addSecs ( -(offset*60)); |
500 | else | 512 | else |
501 | dt = dti; | 513 | dt = dti; |
502 | if(dt.date().isValid()){ | 514 | if(dt.date().isValid()){ |
503 | const QDate& date = dt.date(); | 515 | const QDate& date = dt.date(); |
504 | datestr.sprintf("%04d%02d%02d", | 516 | datestr.sprintf("%04d%02d%02d", |
505 | date.year(), date.month(), date.day()); | 517 | date.year(), date.month(), date.day()); |
506 | } | 518 | } |
507 | if(dt.time().isValid()){ | 519 | if(dt.time().isValid()){ |
508 | const QTime& time = dt.time(); | 520 | const QTime& time = dt.time(); |
509 | timestr.sprintf("T%02d%02d%02d", | 521 | timestr.sprintf("T%02d%02d%02d", |
510 | time.hour(), time.minute(), time.second()); | 522 | time.hour(), time.minute(), time.second()); |
511 | } | 523 | } |
512 | return datestr + timestr; | 524 | return datestr + timestr; |
513 | } | 525 | } |
514 | QDate datefromGSM ( GSM_DateTime*dtp ) { | 526 | QDate datefromGSM ( GSM_DateTime*dtp ) { |
515 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); | 527 | return QDate ( dtp->Year, dtp->Month, dtp->Day ); |
516 | } | 528 | } |
517 | QString getCategory( GSM_CalendarEntry*Note) | 529 | QString getCategory( GSM_CalendarEntry*Note) |
518 | { | 530 | { |
519 | QString CATEGORY; | 531 | QString CATEGORY; |
520 | switch (Note->Type) { | 532 | switch (Note->Type) { |
521 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; | 533 | case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; |
522 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; | 534 | case GSM_CAL_CALL : CATEGORY = QString("Call"); break; |
523 | case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; | 535 | case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; |
524 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; | 536 | case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; |
525 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; | 537 | case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; |
526 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; | 538 | case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; |
527 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; | 539 | case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; |
528 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; | 540 | case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; |
529 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; | 541 | case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; |
530 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; | 542 | case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; |
531 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; | 543 | case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; |
532 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; | 544 | case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; |
533 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; | 545 | case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; |
534 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; | 546 | case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; |
535 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; | 547 | case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; |
536 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; | 548 | case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; |
537 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; | 549 | case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; |
538 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; | 550 | case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; |
539 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; | 551 | case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; |
540 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; | 552 | case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; |
541 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; | 553 | case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; |
542 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; | 554 | case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; |
543 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; | 555 | case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; |
544 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; | 556 | case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; |
545 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; | 557 | case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; |
546 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; | 558 | case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; |
547 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; | 559 | case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; |
548 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; | 560 | case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; |
549 | default : CATEGORY = QString(""); | 561 | default : CATEGORY = QString(""); |
550 | } | 562 | } |
551 | 563 | ||
552 | return CATEGORY; | 564 | return CATEGORY; |
553 | } | 565 | } |
554 | 566 | ||
555 | protected: | 567 | protected: |
556 | private: | 568 | private: |
557 | Calendar *mCalendar; | 569 | Calendar *mCalendar; |
558 | QString mProfileName ; | 570 | QString mProfileName ; |
559 | }; | 571 | }; |
560 | 572 | ||
561 | 573 | ||
562 | PhoneFormat::PhoneFormat() | 574 | PhoneFormat::PhoneFormat() |
563 | { | 575 | { |
564 | ; | 576 | ; |
565 | } | 577 | } |
566 | 578 | ||
567 | PhoneFormat::~PhoneFormat() | 579 | PhoneFormat::~PhoneFormat() |
568 | { | 580 | { |
569 | } | 581 | } |
570 | ulong PhoneFormat::getCsum( const QStringList & attList) | 582 | ulong PhoneFormat::getCsum( const QStringList & attList) |
571 | { | 583 | { |
572 | int max = attList.count() -1; | 584 | int max = attList.count() -1; |
573 | ulong cSum = 0; | 585 | ulong cSum = 0; |
574 | int j,k,i; | 586 | int j,k,i; |
575 | int add; | 587 | int add; |
576 | for ( i = 1; i < max ; ++i ) { | 588 | for ( i = 1; i < max ; ++i ) { |
577 | QString s = attList[i]; | 589 | QString s = attList[i]; |
578 | if ( ! s.isEmpty() ){ | 590 | if ( ! s.isEmpty() ){ |
579 | j = s.length(); | 591 | j = s.length(); |
580 | for ( k = 0; k < j; ++k ) { | 592 | for ( k = 0; k < j; ++k ) { |
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index 4e54fdf..f8b066d 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -40,274 +40,282 @@ | |||
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 "sharpformat.h" | 44 | #include "sharpformat.h" |
45 | #include "syncdefines.h" | 45 | #include "syncdefines.h" |
46 | 46 | ||
47 | using namespace KCal; | 47 | using namespace KCal; |
48 | 48 | ||
49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY | 49 | //CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY |
50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 50 | // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
51 | 51 | ||
52 | //ARSD silentalarm = 0 | 52 | //ARSD silentalarm = 0 |
53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly | 53 | // 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly |
54 | // 12 RFRQ | 54 | // 12 RFRQ |
55 | // 13 RPOS pos = 4. monday in month | 55 | // 13 RPOS pos = 4. monday in month |
56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun | 56 | // 14 RDYS days: 1 mon/ 2 tue .. 64 sun |
57 | // 15 REND 0 = no end/ 1 = end | 57 | // 15 REND 0 = no end/ 1 = end |
58 | // 16 REDT rec end dt | 58 | // 16 REDT rec end dt |
59 | //ALSD | 59 | //ALSD |
60 | //ALED | 60 | //ALED |
61 | //MDAY | 61 | //MDAY |
62 | 62 | ||
63 | class SharpParser : public QObject | 63 | class SharpParser : public QObject |
64 | { | 64 | { |
65 | public: | 65 | public: |
66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { | 66 | SharpParser( Calendar *calendar ) : mCalendar( calendar ) { |
67 | oldCategories = 0; | 67 | oldCategories = 0; |
68 | } | 68 | } |
69 | 69 | ||
70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) | 70 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) |
71 | { | 71 | { |
72 | int i = 1; | 72 | int i = 1; |
73 | bool skip = true; | 73 | bool skip = true; |
74 | int max = attList.count() -2; | 74 | int max = attList.count() -2; |
75 | while ( i < max ) { | 75 | while ( i < max ) { |
76 | if ( !attList[i].isEmpty() ) { | 76 | if ( !attList[i].isEmpty() ) { |
77 | skip = false; | 77 | skip = false; |
78 | break; | 78 | break; |
79 | } | 79 | } |
80 | ++i ; | 80 | ++i ; |
81 | } | 81 | } |
82 | if ( skip ) | 82 | if ( skip ) |
83 | return false; | 83 | return false; |
84 | ulong cSum = SharpFormat::getCsum(attList ); | 84 | ulong cSum = SharpFormat::getCsum(attList ); |
85 | 85 | ||
86 | if ( qName == "Event" ) { | 86 | if ( qName == "Event" ) { |
87 | Event *event; | 87 | Event *event; |
88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); | 88 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); |
89 | if ( event ) | 89 | if ( event ) |
90 | event = (Event*)event->clone(); | 90 | event = (Event*)event->clone(); |
91 | else | 91 | else |
92 | event = new Event; | 92 | event = new Event; |
93 | event->setID("Sharp_DTM", attList[0] ); | 93 | event->setID("Sharp_DTM", attList[0] ); |
94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); | 94 | event->setCsum( "Sharp_DTM", QString::number( cSum )); |
95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 95 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
96 | 96 | ||
97 | event->setSummary( attList[2] ); | 97 | event->setSummary( attList[2] ); |
98 | event->setLocation( attList[3] ); | 98 | event->setLocation( attList[3] ); |
99 | event->setDescription( attList[4] ); | 99 | event->setDescription( attList[4] ); |
100 | if ( attList[7] == "1" ) { | 100 | if ( attList[7] == "1" ) { |
101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); | 101 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); |
102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); | 102 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); |
103 | event->setFloats( true ); | 103 | event->setFloats( true ); |
104 | } else { | 104 | } else { |
105 | event->setFloats( false ); | 105 | event->setFloats( false ); |
106 | event->setDtStart( fromString( attList[5] ) ); | 106 | event->setDtStart( fromString( attList[5] ) ); |
107 | event->setDtEnd( fromString( attList[6] )); | 107 | event->setDtEnd( fromString( attList[6] )); |
108 | } | 108 | } |
109 | 109 | ||
110 | QString rtype = attList[11]; | 110 | QString rtype = attList[11]; |
111 | if ( rtype != "255" ) { | 111 | if ( rtype != "255" ) { |
112 | // qDebug("recurs "); | 112 | // qDebug("recurs "); |
113 | QDate startDate = event->dtStart().date(); | 113 | QDate startDate = event->dtStart().date(); |
114 | 114 | ||
115 | QString freqStr = attList[12]; | 115 | QString freqStr = attList[12]; |
116 | int freq = freqStr.toInt(); | 116 | int freq = freqStr.toInt(); |
117 | 117 | ||
118 | QString hasEndDateStr = attList[15] ; | 118 | QString hasEndDateStr = attList[15] ; |
119 | bool hasEndDate = hasEndDateStr == "1"; | 119 | bool hasEndDate = hasEndDateStr == "1"; |
120 | 120 | ||
121 | QString endDateStr = attList[16]; | 121 | QString endDateStr = attList[16]; |
122 | QDate endDate = fromString( endDateStr ).date(); | 122 | QDate endDate = fromString( endDateStr ).date(); |
123 | 123 | ||
124 | QString weekDaysStr = attList[14]; | 124 | QString weekDaysStr = attList[14]; |
125 | uint weekDaysNum = weekDaysStr.toInt(); | 125 | uint weekDaysNum = weekDaysStr.toInt(); |
126 | 126 | ||
127 | QBitArray weekDays( 7 ); | 127 | QBitArray weekDays( 7 ); |
128 | int i; | 128 | int i; |
129 | int bb = 1; | 129 | int bb = 1; |
130 | for( i = 1; i <= 7; ++i ) { | 130 | for( i = 1; i <= 7; ++i ) { |
131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 131 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
132 | bb = 2 << (i-1); | 132 | bb = 2 << (i-1); |
133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 133 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
134 | } | 134 | } |
135 | // qDebug("next "); | 135 | // qDebug("next "); |
136 | QString posStr = attList[13]; | 136 | QString posStr = attList[13]; |
137 | int pos = posStr.toInt(); | 137 | int pos = posStr.toInt(); |
138 | Recurrence *r = event->recurrence(); | 138 | Recurrence *r = event->recurrence(); |
139 | 139 | ||
140 | if ( rtype == "0" ) { | 140 | if ( rtype == "0" ) { |
141 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 141 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
142 | else r->setDaily( freq, -1 ); | 142 | else r->setDaily( freq, -1 ); |
143 | } else if ( rtype == "1" ) { | 143 | } else if ( rtype == "1" ) { |
144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 144 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
145 | else r->setWeekly( freq, weekDays, -1 ); | 145 | else r->setWeekly( freq, weekDays, -1 ); |
146 | } else if ( rtype == "3" ) { | 146 | } else if ( rtype == "3" ) { |
147 | if ( hasEndDate ) | 147 | if ( hasEndDate ) |
148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 148 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
149 | else | 149 | else |
150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 150 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
151 | r->addMonthlyDay( startDate.day() ); | 151 | r->addMonthlyDay( startDate.day() ); |
152 | } else if ( rtype == "2" ) { | 152 | } else if ( rtype == "2" ) { |
153 | if ( hasEndDate ) | 153 | if ( hasEndDate ) |
154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 154 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
155 | else | 155 | else |
156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 156 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
157 | QBitArray days( 7 ); | 157 | QBitArray days( 7 ); |
158 | days.fill( false ); | 158 | days.fill( false ); |
159 | days.setBit( startDate.dayOfWeek() - 1 ); | 159 | days.setBit( startDate.dayOfWeek() - 1 ); |
160 | r->addMonthlyPos( pos, days ); | 160 | r->addMonthlyPos( pos, days ); |
161 | } else if ( rtype == "4" ) { | 161 | } else if ( rtype == "4" ) { |
162 | if ( hasEndDate ) | 162 | if ( hasEndDate ) |
163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 163 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
164 | else | 164 | else |
165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 165 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
166 | r->addYearlyNum( startDate.month() ); | 166 | r->addYearlyNum( startDate.month() ); |
167 | } | 167 | } |
168 | } else { | ||
169 | event->recurrence()->unsetRecurs(); | ||
168 | } | 170 | } |
169 | 171 | ||
170 | QString categoryList = attList[1] ; | 172 | QString categoryList = attList[1] ; |
171 | event->setCategories( lookupCategories( categoryList ) ); | 173 | event->setCategories( lookupCategories( categoryList ) ); |
172 | 174 | ||
173 | // strange 0 semms to mean: alarm enabled | 175 | // strange 0 semms to mean: alarm enabled |
174 | if ( attList[8] == "0" ) { | 176 | if ( attList[8] == "0" ) { |
175 | Alarm *alarm; | 177 | Alarm *alarm; |
176 | if ( event->alarms().count() > 0 ) | 178 | if ( event->alarms().count() > 0 ) |
177 | alarm = event->alarms().first(); | 179 | alarm = event->alarms().first(); |
178 | else { | 180 | else { |
179 | alarm = new Alarm( event ); | 181 | alarm = new Alarm( event ); |
180 | event->addAlarm( alarm ); | 182 | event->addAlarm( alarm ); |
181 | } | 183 | } |
182 | alarm->setType( Alarm::Audio ); | 184 | alarm->setType( Alarm::Audio ); |
183 | alarm->setEnabled( true ); | 185 | alarm->setEnabled( true ); |
184 | int alarmOffset = attList[9].toInt(); | 186 | int alarmOffset = attList[9].toInt(); |
185 | alarm->setStartOffset( alarmOffset * -60 ); | 187 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | ||
189 | Alarm *alarm; | ||
190 | if ( event->alarms().count() > 0 ) { | ||
191 | alarm = event->alarms().first(); | ||
192 | alarm->setEnabled( false ); | ||
193 | } | ||
186 | } | 194 | } |
187 | 195 | ||
188 | mCalendar->addEvent( event); | 196 | mCalendar->addEvent( event); |
189 | } else if ( qName == "Todo" ) { | 197 | } else if ( qName == "Todo" ) { |
190 | Todo *todo; | 198 | Todo *todo; |
191 | 199 | ||
192 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 200 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
193 | if (todo ) | 201 | if (todo ) |
194 | todo = (Todo*)todo->clone(); | 202 | todo = (Todo*)todo->clone(); |
195 | else | 203 | else |
196 | todo = new Todo; | 204 | todo = new Todo; |
197 | 205 | ||
198 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 206 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
199 | // 0 1 2 3 4 5 6 7 8 | 207 | // 0 1 2 3 4 5 6 7 8 |
200 | //1,,,,,1,4,Loch zumachen,"" | 208 | //1,,,,,1,4,Loch zumachen,"" |
201 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 209 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " |
202 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes | 210 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
203 | 211 | ||
204 | todo->setID( "Sharp_DTM", attList[0]); | 212 | todo->setID( "Sharp_DTM", attList[0]); |
205 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 213 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
206 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 214 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
207 | 215 | ||
208 | todo->setSummary( attList[7] ); | 216 | todo->setSummary( attList[7] ); |
209 | todo->setDescription( attList[8]); | 217 | todo->setDescription( attList[8]); |
210 | 218 | ||
211 | int priority = attList[6].toInt(); | 219 | int priority = attList[6].toInt(); |
212 | if ( priority == 0 ) priority = 3; | 220 | if ( priority == 0 ) priority = 3; |
213 | todo->setPriority( priority ); | 221 | todo->setPriority( priority ); |
214 | 222 | ||
215 | QString categoryList = attList[1]; | 223 | QString categoryList = attList[1]; |
216 | todo->setCategories( lookupCategories( categoryList ) ); | 224 | todo->setCategories( lookupCategories( categoryList ) ); |
217 | 225 | ||
218 | 226 | ||
219 | 227 | ||
220 | QString hasDateStr = attList[3]; // due | 228 | QString hasDateStr = attList[3]; // due |
221 | if ( !hasDateStr.isEmpty() ) { | 229 | if ( !hasDateStr.isEmpty() ) { |
222 | if ( hasDateStr.right(6) == "000000" ) { | 230 | if ( hasDateStr.right(6) == "000000" ) { |
223 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 231 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
224 | todo->setFloats( true ); | 232 | todo->setFloats( true ); |
225 | } | 233 | } |
226 | else { | 234 | else { |
227 | todo->setDtDue( fromString( hasDateStr ) ); | 235 | todo->setDtDue( fromString( hasDateStr ) ); |
228 | todo->setFloats( false ); | 236 | todo->setFloats( false ); |
229 | } | 237 | } |
230 | 238 | ||
231 | todo->setHasDueDate( true ); | 239 | todo->setHasDueDate( true ); |
232 | } | 240 | } |
233 | hasDateStr = attList[2];//start | 241 | hasDateStr = attList[2];//start |
234 | if ( !hasDateStr.isEmpty() ) { | 242 | if ( !hasDateStr.isEmpty() ) { |
235 | 243 | ||
236 | todo->setDtStart( fromString( hasDateStr ) ); | 244 | todo->setDtStart( fromString( hasDateStr ) ); |
237 | todo->setHasStartDate( true); | 245 | todo->setHasStartDate( true); |
238 | } else | 246 | } else |
239 | todo->setHasStartDate( false ); | 247 | todo->setHasStartDate( false ); |
240 | hasDateStr = attList[4];//completed | 248 | hasDateStr = attList[4];//completed |
241 | if ( !hasDateStr.isEmpty() ) { | 249 | if ( !hasDateStr.isEmpty() ) { |
242 | todo->setCompleted(fromString( hasDateStr ) ); | 250 | todo->setCompleted(fromString( hasDateStr ) ); |
243 | } | 251 | } |
244 | QString completedStr = attList[5]; | 252 | QString completedStr = attList[5]; |
245 | if ( completedStr == "0" ) | 253 | if ( completedStr == "0" ) |
246 | todo->setCompleted( true ); | 254 | todo->setCompleted( true ); |
247 | else | 255 | else |
248 | todo->setCompleted( false ); | 256 | todo->setCompleted( false ); |
249 | mCalendar->addTodo( todo ); | 257 | mCalendar->addTodo( todo ); |
250 | 258 | ||
251 | } else if ( qName == "Category" ) { | 259 | } else if ( qName == "Category" ) { |
252 | /* | 260 | /* |
253 | QString id = attributes.value( "id" ); | 261 | QString id = attributes.value( "id" ); |
254 | QString name = attributes.value( "name" ); | 262 | QString name = attributes.value( "name" ); |
255 | setCategory( id, name ); | 263 | setCategory( id, name ); |
256 | */ | 264 | */ |
257 | } | 265 | } |
258 | //qDebug("end "); | 266 | //qDebug("end "); |
259 | return true; | 267 | return true; |
260 | } | 268 | } |
261 | 269 | ||
262 | 270 | ||
263 | void setCategoriesList ( QStringList * c ) | 271 | void setCategoriesList ( QStringList * c ) |
264 | { | 272 | { |
265 | oldCategories = c; | 273 | oldCategories = c; |
266 | } | 274 | } |
267 | 275 | ||
268 | QDateTime fromString ( QString s, bool useTz = true ) { | 276 | QDateTime fromString ( QString s, bool useTz = true ) { |
269 | QDateTime dt; | 277 | QDateTime dt; |
270 | int y,m,t,h,min,sec; | 278 | int y,m,t,h,min,sec; |
271 | y = s.mid(0,4).toInt(); | 279 | y = s.mid(0,4).toInt(); |
272 | m = s.mid(4,2).toInt(); | 280 | m = s.mid(4,2).toInt(); |
273 | t = s.mid(6,2).toInt(); | 281 | t = s.mid(6,2).toInt(); |
274 | h = s.mid(9,2).toInt(); | 282 | h = s.mid(9,2).toInt(); |
275 | min = s.mid(11,2).toInt(); | 283 | min = s.mid(11,2).toInt(); |
276 | sec = s.mid(13,2).toInt(); | 284 | sec = s.mid(13,2).toInt(); |
277 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 285 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
278 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 286 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
279 | if ( useTz ) | 287 | if ( useTz ) |
280 | dt = dt.addSecs ( offset*60); | 288 | dt = dt.addSecs ( offset*60); |
281 | return dt; | 289 | return dt; |
282 | 290 | ||
283 | } | 291 | } |
284 | protected: | 292 | protected: |
285 | QDateTime toDateTime( const QString &value ) | 293 | QDateTime toDateTime( const QString &value ) |
286 | { | 294 | { |
287 | QDateTime dt; | 295 | QDateTime dt; |
288 | dt.setTime_t( value.toUInt() ); | 296 | dt.setTime_t( value.toUInt() ); |
289 | 297 | ||
290 | return dt; | 298 | return dt; |
291 | } | 299 | } |
292 | 300 | ||
293 | QStringList lookupCategories( const QString &categoryList ) | 301 | QStringList lookupCategories( const QString &categoryList ) |
294 | { | 302 | { |
295 | QStringList categoryIds = QStringList::split( ";", categoryList ); | 303 | QStringList categoryIds = QStringList::split( ";", categoryList ); |
296 | QStringList categories; | 304 | QStringList categories; |
297 | QStringList::ConstIterator it; | 305 | QStringList::ConstIterator it; |
298 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { | 306 | for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { |
299 | QString cate = category( *it ); | 307 | QString cate = category( *it ); |
300 | if ( oldCategories ) { | 308 | if ( oldCategories ) { |
301 | if ( ! oldCategories->contains( cate ) ) | 309 | if ( ! oldCategories->contains( cate ) ) |
302 | oldCategories->append( cate ); | 310 | oldCategories->append( cate ); |
303 | } | 311 | } |
304 | categories.append(cate ); | 312 | categories.append(cate ); |
305 | } | 313 | } |
306 | return categories; | 314 | return categories; |
307 | } | 315 | } |
308 | 316 | ||
309 | private: | 317 | private: |
310 | Calendar *mCalendar; | 318 | Calendar *mCalendar; |
311 | QStringList * oldCategories; | 319 | QStringList * oldCategories; |
312 | static QString category( const QString &id ) | 320 | static QString category( const QString &id ) |
313 | { | 321 | { |