author | zautrix <zautrix> | 2004-12-04 04:53:22 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-12-04 04:53:22 (UTC) |
commit | 7828f46413766ee5db72dc9bd457eac0868f0646 (patch) (unidiff) | |
tree | d3da09120bdef2b498f836c5b1b97a5b2aa2da99 /libkcal | |
parent | 967f7c879d06961dd7a25d019380c521f7a84792 (diff) | |
download | kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.zip kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.gz kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.bz2 |
fixed some bugs
-rw-r--r-- | libkcal/sharpformat.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index 24b8349..c2ee2c9 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -1,770 +1,773 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 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 "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 | } | 67 | } |
68 | 68 | ||
69 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) | 69 | bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) |
70 | { | 70 | { |
71 | int i = 1; | 71 | int i = 1; |
72 | bool skip = true; | 72 | bool skip = true; |
73 | int max = attList.count() -2; | 73 | int max = attList.count() -2; |
74 | while ( i < max ) { | 74 | while ( i < max ) { |
75 | if ( !attList[i].isEmpty() ) { | 75 | if ( !attList[i].isEmpty() ) { |
76 | skip = false; | 76 | skip = false; |
77 | break; | 77 | break; |
78 | } | 78 | } |
79 | ++i ; | 79 | ++i ; |
80 | } | 80 | } |
81 | if ( skip ) | 81 | if ( skip ) |
82 | return false; | 82 | return false; |
83 | ulong cSum = SharpFormat::getCsum(attList ); | 83 | ulong cSum = SharpFormat::getCsum(attList ); |
84 | 84 | ||
85 | if ( qName == "Event" ) { | 85 | if ( qName == "Event" ) { |
86 | Event *event; | 86 | Event *event; |
87 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); | 87 | event = existingCalendar->event( "Sharp_DTM",attList[0] ); |
88 | if ( event ) | 88 | if ( event ) |
89 | event = (Event*)event->clone(); | 89 | event = (Event*)event->clone(); |
90 | else | 90 | else |
91 | event = new Event; | 91 | event = new Event; |
92 | event->setID("Sharp_DTM", attList[0] ); | 92 | event->setID("Sharp_DTM", attList[0] ); |
93 | event->setCsum( "Sharp_DTM", QString::number( cSum )); | 93 | event->setCsum( "Sharp_DTM", QString::number( cSum )); |
94 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); | 94 | event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); |
95 | 95 | ||
96 | event->setSummary( attList[2] ); | 96 | event->setSummary( attList[2] ); |
97 | event->setLocation( attList[3] ); | 97 | event->setLocation( attList[3] ); |
98 | event->setDescription( attList[4] ); | 98 | event->setDescription( attList[4] ); |
99 | if ( attList[7] == "1" ) { | 99 | if ( attList[7] == "1" ) { |
100 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); | 100 | event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); |
101 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); | 101 | event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); |
102 | event->setFloats( true ); | 102 | event->setFloats( true ); |
103 | } else { | 103 | } else { |
104 | event->setFloats( false ); | 104 | event->setFloats( false ); |
105 | event->setDtStart( fromString( attList[5] ) ); | 105 | event->setDtStart( fromString( attList[5] ) ); |
106 | event->setDtEnd( fromString( attList[6] )); | 106 | event->setDtEnd( fromString( attList[6] )); |
107 | } | 107 | } |
108 | 108 | ||
109 | QString rtype = attList[11]; | 109 | QString rtype = attList[11]; |
110 | if ( rtype != "255" ) { | 110 | if ( rtype != "255" ) { |
111 | // qDebug("recurs "); | 111 | // qDebug("recurs "); |
112 | QDate startDate = event->dtStart().date(); | 112 | QDate startDate = event->dtStart().date(); |
113 | 113 | ||
114 | QString freqStr = attList[12]; | 114 | QString freqStr = attList[12]; |
115 | int freq = freqStr.toInt(); | 115 | int freq = freqStr.toInt(); |
116 | 116 | ||
117 | QString hasEndDateStr = attList[15] ; | 117 | QString hasEndDateStr = attList[15] ; |
118 | bool hasEndDate = hasEndDateStr == "1"; | 118 | bool hasEndDate = hasEndDateStr == "1"; |
119 | 119 | ||
120 | QString endDateStr = attList[16]; | 120 | QString endDateStr = attList[16]; |
121 | QDate endDate = fromString( endDateStr ).date(); | 121 | QDate endDate = fromString( endDateStr ).date(); |
122 | 122 | ||
123 | QString weekDaysStr = attList[14]; | 123 | QString weekDaysStr = attList[14]; |
124 | uint weekDaysNum = weekDaysStr.toInt(); | 124 | uint weekDaysNum = weekDaysStr.toInt(); |
125 | 125 | ||
126 | QBitArray weekDays( 7 ); | 126 | QBitArray weekDays( 7 ); |
127 | int i; | 127 | int i; |
128 | int bb = 1; | 128 | int bb = 1; |
129 | for( i = 1; i <= 7; ++i ) { | 129 | for( i = 1; i <= 7; ++i ) { |
130 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); | 130 | weekDays.setBit( i - 1, ( bb & weekDaysNum )); |
131 | bb = 2 << (i-1); | 131 | bb = 2 << (i-1); |
132 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); | 132 | //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); |
133 | } | 133 | } |
134 | // qDebug("next "); | 134 | // qDebug("next "); |
135 | QString posStr = attList[13]; | 135 | QString posStr = attList[13]; |
136 | int pos = posStr.toInt(); | 136 | int pos = posStr.toInt(); |
137 | Recurrence *r = event->recurrence(); | 137 | Recurrence *r = event->recurrence(); |
138 | 138 | ||
139 | if ( rtype == "0" ) { | 139 | if ( rtype == "0" ) { |
140 | if ( hasEndDate ) r->setDaily( freq, endDate ); | 140 | if ( hasEndDate ) r->setDaily( freq, endDate ); |
141 | else r->setDaily( freq, -1 ); | 141 | else r->setDaily( freq, -1 ); |
142 | } else if ( rtype == "1" ) { | 142 | } else if ( rtype == "1" ) { |
143 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); | 143 | if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); |
144 | else r->setWeekly( freq, weekDays, -1 ); | 144 | else r->setWeekly( freq, weekDays, -1 ); |
145 | } else if ( rtype == "3" ) { | 145 | } else if ( rtype == "3" ) { |
146 | if ( hasEndDate ) | 146 | if ( hasEndDate ) |
147 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); | 147 | r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); |
148 | else | 148 | else |
149 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); | 149 | r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); |
150 | r->addMonthlyDay( startDate.day() ); | 150 | r->addMonthlyDay( startDate.day() ); |
151 | } else if ( rtype == "2" ) { | 151 | } else if ( rtype == "2" ) { |
152 | if ( hasEndDate ) | 152 | if ( hasEndDate ) |
153 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); | 153 | r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); |
154 | else | 154 | else |
155 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); | 155 | r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); |
156 | QBitArray days( 7 ); | 156 | QBitArray days( 7 ); |
157 | days.fill( false ); | 157 | days.fill( false ); |
158 | days.setBit( startDate.dayOfWeek() - 1 ); | 158 | days.setBit( startDate.dayOfWeek() - 1 ); |
159 | r->addMonthlyPos( pos, days ); | 159 | r->addMonthlyPos( pos, days ); |
160 | } else if ( rtype == "4" ) { | 160 | } else if ( rtype == "4" ) { |
161 | if ( hasEndDate ) | 161 | if ( hasEndDate ) |
162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
163 | else | 163 | else |
164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
165 | r->addYearlyNum( startDate.month() ); | 165 | r->addYearlyNum( startDate.month() ); |
166 | } | 166 | } |
167 | } else { | 167 | } else { |
168 | event->recurrence()->unsetRecurs(); | 168 | event->recurrence()->unsetRecurs(); |
169 | } | 169 | } |
170 | 170 | ||
171 | QString categoryList = attList[1] ; | 171 | QString categoryList = attList[1] ; |
172 | event->setCategories( categoryList ); | 172 | event->setCategories( categoryList ); |
173 | 173 | ||
174 | // strange 0 semms to mean: alarm enabled | 174 | // strange 0 semms to mean: alarm enabled |
175 | if ( attList[8] == "0" ) { | 175 | if ( attList[8] == "0" ) { |
176 | Alarm *alarm; | 176 | Alarm *alarm; |
177 | if ( event->alarms().count() > 0 ) | 177 | if ( event->alarms().count() > 0 ) |
178 | alarm = event->alarms().first(); | 178 | alarm = event->alarms().first(); |
179 | else { | 179 | else { |
180 | alarm = new Alarm( event ); | 180 | alarm = new Alarm( event ); |
181 | event->addAlarm( alarm ); | 181 | event->addAlarm( alarm ); |
182 | alarm->setType( Alarm::Audio ); | 182 | alarm->setType( Alarm::Audio ); |
183 | } | 183 | } |
184 | //alarm->setType( Alarm::Audio ); | 184 | //alarm->setType( Alarm::Audio ); |
185 | alarm->setEnabled( true ); | 185 | alarm->setEnabled( true ); |
186 | int alarmOffset = attList[9].toInt(); | 186 | int alarmOffset = attList[9].toInt(); |
187 | alarm->setStartOffset( alarmOffset * -60 ); | 187 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | 188 | } else { |
189 | Alarm *alarm; | 189 | Alarm *alarm; |
190 | if ( event->alarms().count() > 0 ) { | 190 | if ( event->alarms().count() > 0 ) { |
191 | alarm = event->alarms().first(); | 191 | alarm = event->alarms().first(); |
192 | alarm->setType( Alarm::Audio ); | 192 | alarm->setType( Alarm::Audio ); |
193 | alarm->setStartOffset( -60*15 ); | 193 | alarm->setStartOffset( -60*15 ); |
194 | alarm->setEnabled( false ); | 194 | alarm->setEnabled( false ); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | mCalendar->addEvent( event); | 198 | mCalendar->addEvent( event); |
199 | } else if ( qName == "Todo" ) { | 199 | } else if ( qName == "Todo" ) { |
200 | Todo *todo; | 200 | Todo *todo; |
201 | 201 | ||
202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
203 | if (todo ) | 203 | if (todo ) |
204 | todo = (Todo*)todo->clone(); | 204 | todo = (Todo*)todo->clone(); |
205 | else | 205 | else |
206 | todo = new Todo; | 206 | todo = new Todo; |
207 | 207 | ||
208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
209 | // 0 1 2 3 4 5 6 7 8 | 209 | // 0 1 2 3 4 5 6 7 8 |
210 | //1,,,,,1,4,Loch zumachen,"" | 210 | //1,,,,,1,4,Loch zumachen,"" |
211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " |
212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes | 212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
213 | 213 | ||
214 | todo->setID( "Sharp_DTM", attList[0]); | 214 | todo->setID( "Sharp_DTM", attList[0]); |
215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
217 | 217 | ||
218 | todo->setSummary( attList[7] ); | 218 | todo->setSummary( attList[7] ); |
219 | todo->setDescription( attList[8]); | 219 | todo->setDescription( attList[8]); |
220 | 220 | ||
221 | int priority = attList[6].toInt(); | 221 | int priority = attList[6].toInt(); |
222 | if ( priority == 0 ) priority = 3; | 222 | if ( priority == 0 ) priority = 3; |
223 | todo->setPriority( priority ); | 223 | todo->setPriority( priority ); |
224 | 224 | ||
225 | QString categoryList = attList[1]; | 225 | QString categoryList = attList[1]; |
226 | todo->setCategories( categoryList ); | 226 | todo->setCategories( categoryList ); |
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | QString hasDateStr = attList[3]; // due | 230 | QString hasDateStr = attList[3]; // due |
231 | if ( !hasDateStr.isEmpty() ) { | 231 | if ( !hasDateStr.isEmpty() ) { |
232 | if ( hasDateStr.right(6) == "000000" ) { | 232 | if ( hasDateStr.right(6) == "000000" ) { |
233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
234 | todo->setFloats( true ); | 234 | todo->setFloats( true ); |
235 | } | 235 | } |
236 | else { | 236 | else { |
237 | todo->setDtDue( fromString( hasDateStr ) ); | 237 | todo->setDtDue( fromString( hasDateStr ) ); |
238 | todo->setFloats( false ); | 238 | todo->setFloats( false ); |
239 | } | 239 | } |
240 | 240 | ||
241 | todo->setHasDueDate( true ); | 241 | todo->setHasDueDate( true ); |
242 | } | 242 | } |
243 | hasDateStr = attList[2];//start | 243 | hasDateStr = attList[2];//start |
244 | if ( !hasDateStr.isEmpty() ) { | 244 | if ( !hasDateStr.isEmpty() ) { |
245 | 245 | ||
246 | todo->setDtStart( fromString( hasDateStr ) ); | 246 | todo->setDtStart( fromString( hasDateStr ) ); |
247 | todo->setHasStartDate( true); | 247 | todo->setHasStartDate( true); |
248 | } else | 248 | } else |
249 | todo->setHasStartDate( false ); | 249 | todo->setHasStartDate( false ); |
250 | hasDateStr = attList[4];//completed | 250 | hasDateStr = attList[4];//completed |
251 | if ( !hasDateStr.isEmpty() ) { | 251 | if ( !hasDateStr.isEmpty() ) { |
252 | todo->setCompleted(fromString( hasDateStr ) ); | 252 | todo->setCompleted(fromString( hasDateStr ) ); |
253 | } | 253 | } |
254 | QString completedStr = attList[5]; | 254 | QString completedStr = attList[5]; |
255 | if ( completedStr == "0" ) | 255 | if ( completedStr == "0" ) |
256 | todo->setCompleted( true ); | 256 | todo->setCompleted( true ); |
257 | else | 257 | else { |
258 | todo->setCompleted( false ); | 258 | // do not change percent complete |
259 | if ( todo->isCompleted() ) | ||
260 | todo->setCompleted( false ); | ||
261 | } | ||
259 | mCalendar->addTodo( todo ); | 262 | mCalendar->addTodo( todo ); |
260 | 263 | ||
261 | } else if ( qName == "Category" ) { | 264 | } else if ( qName == "Category" ) { |
262 | /* | 265 | /* |
263 | QString id = attributes.value( "id" ); | 266 | QString id = attributes.value( "id" ); |
264 | QString name = attributes.value( "name" ); | 267 | QString name = attributes.value( "name" ); |
265 | setCategory( id, name ); | 268 | setCategory( id, name ); |
266 | */ | 269 | */ |
267 | } | 270 | } |
268 | //qDebug("end "); | 271 | //qDebug("end "); |
269 | return true; | 272 | return true; |
270 | } | 273 | } |
271 | 274 | ||
272 | 275 | ||
273 | QDateTime fromString ( QString s, bool useTz = true ) { | 276 | QDateTime fromString ( QString s, bool useTz = true ) { |
274 | QDateTime dt; | 277 | QDateTime dt; |
275 | int y,m,t,h,min,sec; | 278 | int y,m,t,h,min,sec; |
276 | y = s.mid(0,4).toInt(); | 279 | y = s.mid(0,4).toInt(); |
277 | m = s.mid(4,2).toInt(); | 280 | m = s.mid(4,2).toInt(); |
278 | t = s.mid(6,2).toInt(); | 281 | t = s.mid(6,2).toInt(); |
279 | h = s.mid(9,2).toInt(); | 282 | h = s.mid(9,2).toInt(); |
280 | min = s.mid(11,2).toInt(); | 283 | min = s.mid(11,2).toInt(); |
281 | sec = s.mid(13,2).toInt(); | 284 | sec = s.mid(13,2).toInt(); |
282 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 285 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
283 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 286 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
284 | if ( useTz ) | 287 | if ( useTz ) |
285 | dt = dt.addSecs ( offset*60); | 288 | dt = dt.addSecs ( offset*60); |
286 | return dt; | 289 | return dt; |
287 | 290 | ||
288 | } | 291 | } |
289 | protected: | 292 | protected: |
290 | QDateTime toDateTime( const QString &value ) | 293 | QDateTime toDateTime( const QString &value ) |
291 | { | 294 | { |
292 | QDateTime dt; | 295 | QDateTime dt; |
293 | dt.setTime_t( value.toUInt() ); | 296 | dt.setTime_t( value.toUInt() ); |
294 | 297 | ||
295 | return dt; | 298 | return dt; |
296 | } | 299 | } |
297 | 300 | ||
298 | private: | 301 | private: |
299 | Calendar *mCalendar; | 302 | Calendar *mCalendar; |
300 | }; | 303 | }; |
301 | 304 | ||
302 | 305 | ||
303 | SharpFormat::SharpFormat() | 306 | SharpFormat::SharpFormat() |
304 | { | 307 | { |
305 | 308 | ||
306 | } | 309 | } |
307 | 310 | ||
308 | SharpFormat::~SharpFormat() | 311 | SharpFormat::~SharpFormat() |
309 | { | 312 | { |
310 | } | 313 | } |
311 | ulong SharpFormat::getCsum( const QStringList & attList) | 314 | ulong SharpFormat::getCsum( const QStringList & attList) |
312 | { | 315 | { |
313 | int max = attList.count() -1; | 316 | int max = attList.count() -1; |
314 | ulong cSum = 0; | 317 | ulong cSum = 0; |
315 | int j,k,i; | 318 | int j,k,i; |
316 | int add; | 319 | int add; |
317 | for ( i = 1; i < max ; ++i ) { | 320 | for ( i = 1; i < max ; ++i ) { |
318 | QString s = attList[i]; | 321 | QString s = attList[i]; |
319 | if ( ! s.isEmpty() ){ | 322 | if ( ! s.isEmpty() ){ |
320 | j = s.length(); | 323 | j = s.length(); |
321 | for ( k = 0; k < j; ++k ) { | 324 | for ( k = 0; k < j; ++k ) { |
322 | int mul = k +1; | 325 | int mul = k +1; |
323 | add = s[k].unicode (); | 326 | add = s[k].unicode (); |
324 | if ( k < 16 ) | 327 | if ( k < 16 ) |
325 | mul = mul * mul; | 328 | mul = mul * mul; |
326 | add = add * mul *i*i*i; | 329 | add = add * mul *i*i*i; |
327 | cSum += add; | 330 | cSum += add; |
328 | } | 331 | } |
329 | } | 332 | } |
330 | } | 333 | } |
331 | return cSum; | 334 | return cSum; |
332 | 335 | ||
333 | } | 336 | } |
334 | #include <stdlib.h> | 337 | #include <stdlib.h> |
335 | #define DEBUGMODE false | 338 | #define DEBUGMODE false |
336 | //#define DEBUGMODE true | 339 | //#define DEBUGMODE true |
337 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 340 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
338 | { | 341 | { |
339 | 342 | ||
340 | 343 | ||
341 | bool debug = DEBUGMODE; | 344 | bool debug = DEBUGMODE; |
342 | QString text; | 345 | QString text; |
343 | QString codec = "utf8"; | 346 | QString codec = "utf8"; |
344 | QLabel status ( i18n("Reading events ..."), 0 ); | 347 | QLabel status ( i18n("Reading events ..."), 0 ); |
345 | 348 | ||
346 | int w = status.sizeHint().width()+20 ; | 349 | int w = status.sizeHint().width()+20 ; |
347 | if ( w < 200 ) w = 200; | 350 | if ( w < 200 ) w = 200; |
348 | int h = status.sizeHint().height()+20 ; | 351 | int h = status.sizeHint().height()+20 ; |
349 | int dw = QApplication::desktop()->width(); | 352 | int dw = QApplication::desktop()->width(); |
350 | int dh = QApplication::desktop()->height(); | 353 | int dh = QApplication::desktop()->height(); |
351 | status.setCaption(i18n("Reading DTM Data") ); | 354 | status.setCaption(i18n("Reading DTM Data") ); |
352 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 355 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
353 | status.show(); | 356 | status.show(); |
354 | status.raise(); | 357 | status.raise(); |
355 | qApp->processEvents(); | 358 | qApp->processEvents(); |
356 | QString fileName; | 359 | QString fileName; |
357 | if ( ! debug ) { | 360 | if ( ! debug ) { |
358 | fileName = "/tmp/kopitempout"; | 361 | fileName = "/tmp/kopitempout"; |
359 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; | 362 | QString command ="db2file datebook -r -c "+ codec + " > " + fileName; |
360 | system ( command.latin1() ); | 363 | system ( command.latin1() ); |
361 | } else { | 364 | } else { |
362 | fileName = "/tmp/events.txt"; | 365 | fileName = "/tmp/events.txt"; |
363 | 366 | ||
364 | } | 367 | } |
365 | QFile file( fileName ); | 368 | QFile file( fileName ); |
366 | if (!file.open( IO_ReadOnly ) ) { | 369 | if (!file.open( IO_ReadOnly ) ) { |
367 | return false; | 370 | return false; |
368 | 371 | ||
369 | } | 372 | } |
370 | QTextStream ts( &file ); | 373 | QTextStream ts( &file ); |
371 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 374 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
372 | text = ts.read(); | 375 | text = ts.read(); |
373 | file.close(); | 376 | file.close(); |
374 | status.setText( i18n("Processing events ...") ); | 377 | status.setText( i18n("Processing events ...") ); |
375 | status.raise(); | 378 | status.raise(); |
376 | qApp->processEvents(); | 379 | qApp->processEvents(); |
377 | fromString2Cal( calendar, existngCal, text, "Event" ); | 380 | fromString2Cal( calendar, existngCal, text, "Event" ); |
378 | status.setText( i18n("Reading todos ...") ); | 381 | status.setText( i18n("Reading todos ...") ); |
379 | qApp->processEvents(); | 382 | qApp->processEvents(); |
380 | if ( ! debug ) { | 383 | if ( ! debug ) { |
381 | fileName = "/tmp/kopitempout"; | 384 | fileName = "/tmp/kopitempout"; |
382 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; | 385 | QString command = "db2file todo -r -c " + codec+ " > " + fileName; |
383 | system ( command.latin1() ); | 386 | system ( command.latin1() ); |
384 | } else { | 387 | } else { |
385 | fileName = "/tmp/todo.txt"; | 388 | fileName = "/tmp/todo.txt"; |
386 | } | 389 | } |
387 | file.setName( fileName ); | 390 | file.setName( fileName ); |
388 | if (!file.open( IO_ReadOnly ) ) { | 391 | if (!file.open( IO_ReadOnly ) ) { |
389 | return false; | 392 | return false; |
390 | 393 | ||
391 | } | 394 | } |
392 | ts.setDevice( &file ); | 395 | ts.setDevice( &file ); |
393 | text = ts.read(); | 396 | text = ts.read(); |
394 | file.close(); | 397 | file.close(); |
395 | 398 | ||
396 | status.setText( i18n("Processing todos ...") ); | 399 | status.setText( i18n("Processing todos ...") ); |
397 | status.raise(); | 400 | status.raise(); |
398 | qApp->processEvents(); | 401 | qApp->processEvents(); |
399 | fromString2Cal( calendar, existngCal, text, "Todo" ); | 402 | fromString2Cal( calendar, existngCal, text, "Todo" ); |
400 | return true; | 403 | return true; |
401 | } | 404 | } |
402 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) | 405 | int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) |
403 | { | 406 | { |
404 | int retval = -1; | 407 | int retval = -1; |
405 | QStringList templist; | 408 | QStringList templist; |
406 | QString tempString; | 409 | QString tempString; |
407 | int start = 0; | 410 | int start = 0; |
408 | int len = answer.length(); | 411 | int len = answer.length(); |
409 | int end = answer.find ("\n",start)+1; | 412 | int end = answer.find ("\n",start)+1; |
410 | bool ok = true; | 413 | bool ok = true; |
411 | start = end; | 414 | start = end; |
412 | int ccc = 0; | 415 | int ccc = 0; |
413 | while ( start > 0 ) { | 416 | while ( start > 0 ) { |
414 | templist.clear(); | 417 | templist.clear(); |
415 | ok = true; | 418 | ok = true; |
416 | int loopCount = 0; | 419 | int loopCount = 0; |
417 | while ( ok ) { | 420 | while ( ok ) { |
418 | ++loopCount; | 421 | ++loopCount; |
419 | if ( loopCount > 25 ) { | 422 | if ( loopCount > 25 ) { |
420 | qDebug("KO: Error in while loop"); | 423 | qDebug("KO: Error in while loop"); |
421 | ok = false; | 424 | ok = false; |
422 | start = 0; | 425 | start = 0; |
423 | break; | 426 | break; |
424 | } | 427 | } |
425 | if ( ok ) | 428 | if ( ok ) |
426 | tempString = getPart( answer, ok, start ); | 429 | tempString = getPart( answer, ok, start ); |
427 | if ( start >= len || start == 0 ) { | 430 | if ( start >= len || start == 0 ) { |
428 | start = 0; | 431 | start = 0; |
429 | ok = false; | 432 | ok = false; |
430 | } | 433 | } |
431 | if ( tempString.right(1) =="\n" ) | 434 | if ( tempString.right(1) =="\n" ) |
432 | tempString = tempString.left( tempString.length()-1); | 435 | tempString = tempString.left( tempString.length()-1); |
433 | 436 | ||
434 | templist.append( tempString ); | 437 | templist.append( tempString ); |
435 | } | 438 | } |
436 | ++ccc; | 439 | ++ccc; |
437 | if ( ccc == 2 && loopCount < 25 ) { | 440 | if ( ccc == 2 && loopCount < 25 ) { |
438 | start = 0; | 441 | start = 0; |
439 | bool ok; | 442 | bool ok; |
440 | int newnum = templist[0].toInt( &ok ); | 443 | int newnum = templist[0].toInt( &ok ); |
441 | if ( ok && newnum > 0) { | 444 | if ( ok && newnum > 0) { |
442 | retval = newnum; | 445 | retval = newnum; |
443 | inc->setID( "Sharp_DTM",templist[0] ); | 446 | inc->setID( "Sharp_DTM",templist[0] ); |
444 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); | 447 | inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); |
445 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 448 | inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
446 | } | 449 | } |
447 | if ( ok && newnum == -1 ) { | 450 | if ( ok && newnum == -1 ) { |
448 | qDebug("Error writing back %s ", inc->summary().latin1()); | 451 | qDebug("Error writing back %s ", inc->summary().latin1()); |
449 | } | 452 | } |
450 | } | 453 | } |
451 | } | 454 | } |
452 | //qDebug("getNumFromRecord returning : %d ", retval); | 455 | //qDebug("getNumFromRecord returning : %d ", retval); |
453 | return retval; | 456 | return retval; |
454 | } | 457 | } |
455 | bool SharpFormat::save( Calendar *calendar) | 458 | bool SharpFormat::save( Calendar *calendar) |
456 | { | 459 | { |
457 | 460 | ||
458 | QLabel status ( i18n("Processing/adding events ..."), 0 ); | 461 | QLabel status ( i18n("Processing/adding events ..."), 0 ); |
459 | int w = status.sizeHint().width()+20 ; | 462 | int w = status.sizeHint().width()+20 ; |
460 | if ( w < 200 ) w = 200; | 463 | if ( w < 200 ) w = 200; |
461 | int h = status.sizeHint().height()+20 ; | 464 | int h = status.sizeHint().height()+20 ; |
462 | int dw = QApplication::desktop()->width(); | 465 | int dw = QApplication::desktop()->width(); |
463 | int dh = QApplication::desktop()->height(); | 466 | int dh = QApplication::desktop()->height(); |
464 | status.setCaption(i18n("Writing DTM Data") ); | 467 | status.setCaption(i18n("Writing DTM Data") ); |
465 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 468 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
466 | status.show(); | 469 | status.show(); |
467 | status.raise(); | 470 | status.raise(); |
468 | qApp->processEvents(); | 471 | qApp->processEvents(); |
469 | bool debug = DEBUGMODE; | 472 | bool debug = DEBUGMODE; |
470 | QString codec = "utf8"; | 473 | QString codec = "utf8"; |
471 | QString answer; | 474 | QString answer; |
472 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; | 475 | QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; |
473 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; | 476 | QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; |
474 | QString command; | 477 | QString command; |
475 | QPtrList<Event> er = calendar->rawEvents(); | 478 | QPtrList<Event> er = calendar->rawEvents(); |
476 | Event* ev = er.first(); | 479 | Event* ev = er.first(); |
477 | QString fileName = "/tmp/kopitempout"; | 480 | QString fileName = "/tmp/kopitempout"; |
478 | int i = 0; | 481 | int i = 0; |
479 | QString changeString = ePrefix; | 482 | QString changeString = ePrefix; |
480 | QString deleteString = ePrefix; | 483 | QString deleteString = ePrefix; |
481 | bool deleteEnt = false; | 484 | bool deleteEnt = false; |
482 | bool changeEnt = false; | 485 | bool changeEnt = false; |
483 | QString message = i18n("Processing event # "); | 486 | QString message = i18n("Processing event # "); |
484 | int procCount = 0; | 487 | int procCount = 0; |
485 | while ( ev ) { | 488 | while ( ev ) { |
486 | //qDebug("i %d ", ++i); | 489 | //qDebug("i %d ", ++i); |
487 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 490 | if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
488 | status.setText ( message + QString::number ( ++procCount ) ); | 491 | status.setText ( message + QString::number ( ++procCount ) ); |
489 | qApp->processEvents(); | 492 | qApp->processEvents(); |
490 | QString eString = getEventString( ev ); | 493 | QString eString = getEventString( ev ); |
491 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 494 | if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
492 | // deleting empty strings does not work. | 495 | // deleting empty strings does not work. |
493 | // we write first and x and then delete the record with the x | 496 | // we write first and x and then delete the record with the x |
494 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 497 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
495 | changeString += eString + "\n"; | 498 | changeString += eString + "\n"; |
496 | deleteString += eString + "\n"; | 499 | deleteString += eString + "\n"; |
497 | deleteEnt = true; | 500 | deleteEnt = true; |
498 | changeEnt = true; | 501 | changeEnt = true; |
499 | } | 502 | } |
500 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new | 503 | else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new |
501 | QString fileNameIn = "/tmp/kopitempin"; | 504 | QString fileNameIn = "/tmp/kopitempin"; |
502 | QFile fileIn( fileNameIn ); | 505 | QFile fileIn( fileNameIn ); |
503 | if (!fileIn.open( IO_WriteOnly ) ) { | 506 | if (!fileIn.open( IO_WriteOnly ) ) { |
504 | return false; | 507 | return false; |
505 | } | 508 | } |
506 | QTextStream tsIn( &fileIn ); | 509 | QTextStream tsIn( &fileIn ); |
507 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 510 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
508 | tsIn << ePrefix << eString ; | 511 | tsIn << ePrefix << eString ; |
509 | fileIn.close(); | 512 | fileIn.close(); |
510 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 513 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
511 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; | 514 | command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; |
512 | //qDebug("command ++++++++ "); | 515 | //qDebug("command ++++++++ "); |
513 | //qDebug("%s ",command.latin1()); | 516 | //qDebug("%s ",command.latin1()); |
514 | //qDebug("command -------- "); | 517 | //qDebug("command -------- "); |
515 | system ( command.utf8() ); | 518 | system ( command.utf8() ); |
516 | QFile file( fileName ); | 519 | QFile file( fileName ); |
517 | if (!file.open( IO_ReadOnly ) ) { | 520 | if (!file.open( IO_ReadOnly ) ) { |
518 | return false; | 521 | return false; |
519 | 522 | ||
520 | } | 523 | } |
521 | QTextStream ts( &file ); | 524 | QTextStream ts( &file ); |
522 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 525 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
523 | answer = ts.read(); | 526 | answer = ts.read(); |
524 | file.close(); | 527 | file.close(); |
525 | //qDebug("answer \n%s ", answer.latin1()); | 528 | //qDebug("answer \n%s ", answer.latin1()); |
526 | getNumFromRecord( answer, ev ) ; | 529 | getNumFromRecord( answer, ev ) ; |
527 | 530 | ||
528 | } | 531 | } |
529 | else { // change existing | 532 | else { // change existing |
530 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); | 533 | //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); |
531 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 534 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
532 | changeString += eString + "\n"; | 535 | changeString += eString + "\n"; |
533 | changeEnt = true; | 536 | changeEnt = true; |
534 | 537 | ||
535 | } | 538 | } |
536 | } | 539 | } |
537 | ev = er.next(); | 540 | ev = er.next(); |
538 | } | 541 | } |
539 | status.setText ( i18n("Changing events ...") ); | 542 | status.setText ( i18n("Changing events ...") ); |
540 | qApp->processEvents(); | 543 | qApp->processEvents(); |
541 | //qDebug("changing... "); | 544 | //qDebug("changing... "); |
542 | if ( changeEnt ) { | 545 | if ( changeEnt ) { |
543 | QFile file( fileName ); | 546 | QFile file( fileName ); |
544 | if (!file.open( IO_WriteOnly ) ) { | 547 | if (!file.open( IO_WriteOnly ) ) { |
545 | return false; | 548 | return false; |
546 | 549 | ||
547 | } | 550 | } |
548 | QTextStream ts( &file ); | 551 | QTextStream ts( &file ); |
549 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 552 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
550 | ts << changeString ; | 553 | ts << changeString ; |
551 | file.close(); | 554 | file.close(); |
552 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; | 555 | command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; |
553 | system ( command.latin1() ); | 556 | system ( command.latin1() ); |
554 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 557 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
555 | 558 | ||
556 | } | 559 | } |
557 | status.setText ( i18n("Deleting events ...") ); | 560 | status.setText ( i18n("Deleting events ...") ); |
558 | qApp->processEvents(); | 561 | qApp->processEvents(); |
559 | //qDebug("deleting... "); | 562 | //qDebug("deleting... "); |
560 | if ( deleteEnt ) { | 563 | if ( deleteEnt ) { |
561 | QFile file( fileName ); | 564 | QFile file( fileName ); |
562 | if (!file.open( IO_WriteOnly ) ) { | 565 | if (!file.open( IO_WriteOnly ) ) { |
563 | return false; | 566 | return false; |
564 | 567 | ||
565 | } | 568 | } |
566 | QTextStream ts( &file ); | 569 | QTextStream ts( &file ); |
567 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 570 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
568 | ts << deleteString; | 571 | ts << deleteString; |
569 | file.close(); | 572 | file.close(); |
570 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; | 573 | command = "db2file datebook -d -c " + codec+ " < "+ fileName; |
571 | system ( command.latin1() ); | 574 | system ( command.latin1() ); |
572 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 575 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
573 | } | 576 | } |
574 | 577 | ||
575 | 578 | ||
576 | changeString = tPrefix; | 579 | changeString = tPrefix; |
577 | deleteString = tPrefix; | 580 | deleteString = tPrefix; |
578 | status.setText ( i18n("Processing todos ...") ); | 581 | status.setText ( i18n("Processing todos ...") ); |
579 | qApp->processEvents(); | 582 | qApp->processEvents(); |
580 | QPtrList<Todo> tl = calendar->rawTodos(); | 583 | QPtrList<Todo> tl = calendar->rawTodos(); |
581 | Todo* to = tl.first(); | 584 | Todo* to = tl.first(); |
582 | i = 0; | 585 | i = 0; |
583 | message = i18n("Processing todo # "); | 586 | message = i18n("Processing todo # "); |
584 | procCount = 0; | 587 | procCount = 0; |
585 | while ( to ) { | 588 | while ( to ) { |
586 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 589 | if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
587 | status.setText ( message + QString::number ( ++procCount ) ); | 590 | status.setText ( message + QString::number ( ++procCount ) ); |
588 | qApp->processEvents(); | 591 | qApp->processEvents(); |
589 | QString eString = getTodoString( to ); | 592 | QString eString = getTodoString( to ); |
590 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete | 593 | if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete |
591 | // deleting empty strings does not work. | 594 | // deleting empty strings does not work. |
592 | // we write first and x and then delete the record with the x | 595 | // we write first and x and then delete the record with the x |
593 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); | 596 | eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); |
594 | changeString += eString + "\n"; | 597 | changeString += eString + "\n"; |
595 | deleteString += eString + "\n"; | 598 | deleteString += eString + "\n"; |
596 | deleteEnt = true; | 599 | deleteEnt = true; |
597 | changeEnt = true; | 600 | changeEnt = true; |
598 | } | 601 | } |
599 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new | 602 | else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new |
600 | 603 | ||
601 | 604 | ||
602 | 605 | ||
603 | QString fileNameIn = "/tmp/kopitempin"; | 606 | QString fileNameIn = "/tmp/kopitempin"; |
604 | QFile fileIn( fileNameIn ); | 607 | QFile fileIn( fileNameIn ); |
605 | if (!fileIn.open( IO_WriteOnly ) ) { | 608 | if (!fileIn.open( IO_WriteOnly ) ) { |
606 | return false; | 609 | return false; |
607 | } | 610 | } |
608 | QTextStream tsIn( &fileIn ); | 611 | QTextStream tsIn( &fileIn ); |
609 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); | 612 | tsIn.setCodec( QTextCodec::codecForName("utf8") ); |
610 | tsIn << tPrefix << eString ; | 613 | tsIn << tPrefix << eString ; |
611 | fileIn.close(); | 614 | fileIn.close(); |
612 | command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; | 615 | command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; |
613 | system ( command.utf8() ); | 616 | system ( command.utf8() ); |
614 | QFile file( fileName ); | 617 | QFile file( fileName ); |
615 | if (!file.open( IO_ReadOnly ) ) { | 618 | if (!file.open( IO_ReadOnly ) ) { |
616 | return false; | 619 | return false; |
617 | } | 620 | } |
618 | QTextStream ts( &file ); | 621 | QTextStream ts( &file ); |
619 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 622 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
620 | answer = ts.read(); | 623 | answer = ts.read(); |
621 | file.close(); | 624 | file.close(); |
622 | //qDebug("answer \n%s ", answer.latin1()); | 625 | //qDebug("answer \n%s ", answer.latin1()); |
623 | getNumFromRecord( answer, to ) ; | 626 | getNumFromRecord( answer, to ) ; |
624 | 627 | ||
625 | } | 628 | } |
626 | else { // change existing | 629 | else { // change existing |
627 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); | 630 | //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); |
628 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; | 631 | //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; |
629 | changeString += eString + "\n"; | 632 | changeString += eString + "\n"; |
630 | changeEnt = true; | 633 | changeEnt = true; |
631 | 634 | ||
632 | } | 635 | } |
633 | } | 636 | } |
634 | 637 | ||
635 | to = tl.next(); | 638 | to = tl.next(); |
636 | } | 639 | } |
637 | status.setText ( i18n("Changing todos ...") ); | 640 | status.setText ( i18n("Changing todos ...") ); |
638 | qApp->processEvents(); | 641 | qApp->processEvents(); |
639 | //qDebug("changing... "); | 642 | //qDebug("changing... "); |
640 | if ( changeEnt ) { | 643 | if ( changeEnt ) { |
641 | QFile file( fileName ); | 644 | QFile file( fileName ); |
642 | if (!file.open( IO_WriteOnly ) ) { | 645 | if (!file.open( IO_WriteOnly ) ) { |
643 | return false; | 646 | return false; |
644 | 647 | ||
645 | } | 648 | } |
646 | QTextStream ts( &file ); | 649 | QTextStream ts( &file ); |
647 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 650 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
648 | ts << changeString ; | 651 | ts << changeString ; |
649 | file.close(); | 652 | file.close(); |
650 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; | 653 | command = "db2file todo -w -g -c " + codec+ " < "+ fileName; |
651 | system ( command.latin1() ); | 654 | system ( command.latin1() ); |
652 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); | 655 | //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); |
653 | 656 | ||
654 | } | 657 | } |
655 | status.setText ( i18n("Deleting todos ...") ); | 658 | status.setText ( i18n("Deleting todos ...") ); |
656 | qApp->processEvents(); | 659 | qApp->processEvents(); |
657 | //qDebug("deleting... "); | 660 | //qDebug("deleting... "); |
658 | if ( deleteEnt ) { | 661 | if ( deleteEnt ) { |
659 | QFile file( fileName ); | 662 | QFile file( fileName ); |
660 | if (!file.open( IO_WriteOnly ) ) { | 663 | if (!file.open( IO_WriteOnly ) ) { |
661 | return false; | 664 | return false; |
662 | 665 | ||
663 | } | 666 | } |
664 | QTextStream ts( &file ); | 667 | QTextStream ts( &file ); |
665 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 668 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
666 | ts << deleteString; | 669 | ts << deleteString; |
667 | file.close(); | 670 | file.close(); |
668 | command = "db2file todo -d -c " + codec+ " < "+ fileName; | 671 | command = "db2file todo -d -c " + codec+ " < "+ fileName; |
669 | system ( command.latin1() ); | 672 | system ( command.latin1() ); |
670 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); | 673 | // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); |
671 | } | 674 | } |
672 | 675 | ||
673 | return true; | 676 | return true; |
674 | } | 677 | } |
675 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) | 678 | QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) |
676 | { | 679 | { |
677 | QString datestr; | 680 | QString datestr; |
678 | QString timestr; | 681 | QString timestr; |
679 | int offset = KGlobal::locale()->localTimeOffset( dti ); | 682 | int offset = KGlobal::locale()->localTimeOffset( dti ); |
680 | QDateTime dt; | 683 | QDateTime dt; |
681 | if (useTZ) | 684 | if (useTZ) |
682 | dt = dti.addSecs ( -(offset*60)); | 685 | dt = dti.addSecs ( -(offset*60)); |
683 | else | 686 | else |
684 | dt = dti; | 687 | dt = dti; |
685 | if(dt.date().isValid()){ | 688 | if(dt.date().isValid()){ |
686 | const QDate& date = dt.date(); | 689 | const QDate& date = dt.date(); |
687 | datestr.sprintf("%04d%02d%02d", | 690 | datestr.sprintf("%04d%02d%02d", |
688 | date.year(), date.month(), date.day()); | 691 | date.year(), date.month(), date.day()); |
689 | } | 692 | } |
690 | if(dt.time().isValid()){ | 693 | if(dt.time().isValid()){ |
691 | const QTime& time = dt.time(); | 694 | const QTime& time = dt.time(); |
692 | timestr.sprintf("T%02d%02d%02d", | 695 | timestr.sprintf("T%02d%02d%02d", |
693 | time.hour(), time.minute(), time.second()); | 696 | time.hour(), time.minute(), time.second()); |
694 | } | 697 | } |
695 | return datestr + timestr; | 698 | return datestr + timestr; |
696 | } | 699 | } |
697 | QString SharpFormat::getEventString( Event* event ) | 700 | QString SharpFormat::getEventString( Event* event ) |
698 | { | 701 | { |
699 | QStringList list; | 702 | QStringList list; |
700 | list.append( event->getID("Sharp_DTM") ); | 703 | list.append( event->getID("Sharp_DTM") ); |
701 | list.append( event->categories().join(",") ); | 704 | list.append( event->categories().join(",") ); |
702 | if ( !event->summary().isEmpty() ) | 705 | if ( !event->summary().isEmpty() ) |
703 | list.append( event->summary() ); | 706 | list.append( event->summary() ); |
704 | else | 707 | else |
705 | list.append("" ); | 708 | list.append("" ); |
706 | if ( !event->location().isEmpty() ) | 709 | if ( !event->location().isEmpty() ) |
707 | list.append( event->location() ); | 710 | list.append( event->location() ); |
708 | else | 711 | else |
709 | list.append("" ); | 712 | list.append("" ); |
710 | if ( !event->description().isEmpty() ) | 713 | if ( !event->description().isEmpty() ) |
711 | list.append( event->description() ); | 714 | list.append( event->description() ); |
712 | else | 715 | else |
713 | list.append( "" ); | 716 | list.append( "" ); |
714 | if ( event->doesFloat () ) { | 717 | if ( event->doesFloat () ) { |
715 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); | 718 | list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); |
716 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 | 719 | list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 |
717 | list.append( "1" ); | 720 | list.append( "1" ); |
718 | 721 | ||
719 | } | 722 | } |
720 | else { | 723 | else { |
721 | list.append( dtToString( event->dtStart()) ); | 724 | list.append( dtToString( event->dtStart()) ); |
722 | list.append( dtToString( event->dtEnd()) ); //6 | 725 | list.append( dtToString( event->dtEnd()) ); //6 |
723 | list.append( "0" ); | 726 | list.append( "0" ); |
724 | } | 727 | } |
725 | bool noAlarm = true; | 728 | bool noAlarm = true; |
726 | if ( event->alarms().count() > 0 ) { | 729 | if ( event->alarms().count() > 0 ) { |
727 | Alarm * al = event->alarms().first(); | 730 | Alarm * al = event->alarms().first(); |
728 | if ( al->enabled() ) { | 731 | if ( al->enabled() ) { |
729 | noAlarm = false; | 732 | noAlarm = false; |
730 | list.append( "0" ); // yes, 0 == alarm | 733 | list.append( "0" ); // yes, 0 == alarm |
731 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); | 734 | list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); |
732 | if ( al->type() == Alarm::Audio ) | 735 | if ( al->type() == Alarm::Audio ) |
733 | list.append( "1" ); // type audio | 736 | list.append( "1" ); // type audio |
734 | else | 737 | else |
735 | list.append( "0" ); // type silent | 738 | list.append( "0" ); // type silent |
736 | } | 739 | } |
737 | } | 740 | } |
738 | if ( noAlarm ) { | 741 | if ( noAlarm ) { |
739 | list.append( "1" ); // yes, 1 == no alarm | 742 | list.append( "1" ); // yes, 1 == no alarm |
740 | list.append( "0" ); // no alarm offset | 743 | list.append( "0" ); // no alarm offset |
741 | list.append( "1" ); // type | 744 | list.append( "1" ); // type |
742 | } | 745 | } |
743 | // next is: 11 | 746 | // next is: 11 |
744 | // next is: 11-16 are recurrence | 747 | // next is: 11-16 are recurrence |
745 | Recurrence* rec = event->recurrence(); | 748 | Recurrence* rec = event->recurrence(); |
746 | 749 | ||
747 | bool writeEndDate = false; | 750 | bool writeEndDate = false; |
748 | switch ( rec->doesRecur() ) | 751 | switch ( rec->doesRecur() ) |
749 | { | 752 | { |
750 | case Recurrence::rDaily: // 0 | 753 | case Recurrence::rDaily: // 0 |
751 | list.append( "0" ); | 754 | list.append( "0" ); |
752 | list.append( QString::number( rec->frequency() ));//12 | 755 | list.append( QString::number( rec->frequency() ));//12 |
753 | list.append( "0" ); | 756 | list.append( "0" ); |
754 | list.append( "0" ); | 757 | list.append( "0" ); |
755 | writeEndDate = true; | 758 | writeEndDate = true; |
756 | break; | 759 | break; |
757 | case Recurrence::rWeekly:// 1 | 760 | case Recurrence::rWeekly:// 1 |
758 | list.append( "1" ); | 761 | list.append( "1" ); |
759 | list.append( QString::number( rec->frequency()) );//12 | 762 | list.append( QString::number( rec->frequency()) );//12 |
760 | list.append( "0" ); | 763 | list.append( "0" ); |
761 | { | 764 | { |
762 | int days = 0; | 765 | int days = 0; |
763 | QBitArray weekDays = rec->days(); | 766 | QBitArray weekDays = rec->days(); |
764 | int i; | 767 | int i; |
765 | for( i = 1; i <= 7; ++i ) { | 768 | for( i = 1; i <= 7; ++i ) { |
766 | if ( weekDays[i-1] ) { | 769 | if ( weekDays[i-1] ) { |
767 | days += 1 << (i-1); | 770 | days += 1 << (i-1); |
768 | } | 771 | } |
769 | } | 772 | } |
770 | list.append( QString::number( days ) ); | 773 | list.append( QString::number( days ) ); |