summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 8d81307..03571b9 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -97,149 +97,152 @@ int main( int argc, char *argv[] )
97 KCmdLineArgs::init( argc, argv, &aboutData, true ); 97 KCmdLineArgs::init( argc, argv, &aboutData, true );
98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
99 99
100 KInstance ins ( progName ); 100 KInstance ins ( progName );
101 101
102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
103 103
104 bool read = false; 104 bool read = false;
105 if ( args->isSet( "read" ) ) { 105 if ( args->isSet( "read" ) ) {
106 read = true; 106 read = true;
107 qDebug("read "); 107 qDebug("read ");
108 } 108 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
110 CalendarResources *calendarResource = 0; 110 CalendarResources *calendarResource = 0;
111 CalendarLocal *localCalendar = 0; 111 CalendarLocal *localCalendar = 0;
112 KConfig c( locate( "config", "korganizerrc" ) ); 112 KConfig c( locate( "config", "korganizerrc" ) );
113 c.setGroup( "Time & Date" ); 113 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" ); 114 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz ); 115 calendarResource = new CalendarResources( tz );
116 calendarResource->readConfig(); 116 calendarResource->readConfig();
117 calendarResource->load(); 117 calendarResource->load();
118 qDebug("************************************* "); 118 qDebug("************************************* ");
119 qDebug("**************kdecaldump************* "); 119 qDebug("**************kdecaldump************* ");
120 qDebug("************************************* "); 120 qDebug("************************************* ");
121 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1()); 121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
122 122
123 if ( !read ) { 123 if ( !read ) {
124 localCalendar = new CalendarLocal(); 124 localCalendar = new CalendarLocal();
125 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 125 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
126 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 126 KCal::Incidence::List allInc = calendarResource->rawIncidences();
127 Incidence::List::ConstIterator it; 127 Incidence::List::ConstIterator it;
128 int num = 0; 128 int num = 0;
129 for( it = allInc.begin(); it != allInc.end(); ++it ) { 129 for( it = allInc.begin(); it != allInc.end(); ++it ) {
130 ResourceCalendar * re = calendarResource->resource( (*it) ); 130 ResourceCalendar * re = calendarResource->resource( (*it) );
131 if ( re && !re->readOnly() ) { 131 if ( re && !re->readOnly() ) {
132 ++num; 132 ++num;
133 Incidence* cl = (*it)->clone(); 133 Incidence* cl = (*it)->clone();
134 cl->setLastModified( (*it)->lastModified() ); 134 cl->setLastModified( (*it)->lastModified() );
135 if ( cl->type() == "Journal" ) 135 if ( cl->type() == "Journal" )
136 localCalendar->addJournal( (Journal *) cl ); 136 localCalendar->addJournal( (Journal *) cl );
137 else if ( cl->type() == "Todo" ) 137 else if ( cl->type() == "Todo" )
138 localCalendar->addTodo( (Todo *) cl ); 138 localCalendar->addTodo( (Todo *) cl );
139 else if ( cl->type() == "Event" ) 139 else if ( cl->type() == "Event" )
140 localCalendar->addEvent( (Event *) cl ); 140 localCalendar->addEvent( (Event *) cl );
141 } 141 }
142 } 142 }
143 143
144 FileStorage* storage = new FileStorage( calendarResource ); 144 FileStorage* storage = new FileStorage( calendarResource );
145 storage->setFileName( fileName ); 145 storage->setFileName( fileName );
146 storage->setSaveFormat( new ICalFormat() ); 146 storage->setSaveFormat( new ICalFormat() );
147 storage->save(); 147 storage->save();
148 delete storage; 148 delete storage;
149 qDebug("************************************* "); 149 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** "); 150 qDebug("************kdecaldump*************** ");
151 qDebug("************************************* "); 151 qDebug("************************************* ");
152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
153 153
154 } else { 154 } else {
155 qDebug("*************************load");
155 localCalendar = new CalendarLocal(); 156 localCalendar = new CalendarLocal();
156 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 157 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
157 FileStorage* storage = new FileStorage( localCalendar ); 158 FileStorage* storage = new FileStorage( localCalendar );
158 storage->setFileName( fileName ); 159 storage->setFileName( fileName );
159 int num = 0; 160 int num = 0;
160 int del = 0; 161 int del = 0;
161 int add = 0; 162 int add = 0;
162 if ( storage->load() ) { 163 if ( storage->load() ) {
164 qDebug("*************************loaded!");
163 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 165 KCal::Incidence::List newInc = localCalendar->rawIncidences();
164 Incidence::List::ConstIterator it; 166 Incidence::List::ConstIterator it;
165 for( it = newInc.begin(); it != newInc.end(); ++it ) { 167 for( it = newInc.begin(); it != newInc.end(); ++it ) {
166 Incidence* cl = (*it)->clone(); 168 Incidence* cl = (*it)->clone();
167 Incidence *incOld = calendarResource->incidence( cl->uid() ); 169 Incidence *incOld = calendarResource->incidence( cl->uid() );
168 ResourceCalendar * res = 0; 170 ResourceCalendar * res = 0;
169 if ( incOld ) 171 if ( incOld )
170 res = calendarResource->resource( incOld ); 172 res = calendarResource->resource( incOld );
171 if ( res ) { 173 if ( res ) {
172 ++num; 174 ++num;
173 if ( incOld->type() == "Journal" ) 175 if ( incOld->type() == "Journal" )
174 calendarResource->deleteJournal( (Journal *) incOld ); 176 calendarResource->deleteJournal( (Journal *) incOld );
175 else if ( incOld->type() == "Todo" ) 177 else if ( incOld->type() == "Todo" )
176 calendarResource->deleteTodo( (Todo *) incOld ); 178 calendarResource->deleteTodo( (Todo *) incOld );
177 else if ( incOld->type() == "Event" ) 179 else if ( incOld->type() == "Event" )
178 calendarResource->deleteEvent( (Event *) incOld ); 180 calendarResource->deleteEvent( (Event *) incOld );
179 181
180 if ( cl->type() == "Journal" ) 182 if ( cl->type() == "Journal" )
181 calendarResource->addJournal( (Journal *) cl, res ); 183 calendarResource->addJournal( (Journal *) cl, res );
182 else if ( cl->type() == "Todo" ) 184 else if ( cl->type() == "Todo" )
183 calendarResource->addTodo( (Todo *) cl, res ); 185 calendarResource->addTodo( (Todo *) cl, res );
184 else if ( cl->type() == "Event" ) 186 else if ( cl->type() == "Event" )
185 calendarResource->addEvent( (Event *) cl, res ); 187 calendarResource->addEvent( (Event *) cl, res );
186 188
187 } else { 189 } else {
188 if ( incOld ) { 190 if ( incOld ) {
189 qDebug("ERROR: no resource found for old incidence "); 191 qDebug("ERROR: no resource found for old incidence ");
190 if ( incOld->type() == "Journal" ) 192 if ( incOld->type() == "Journal" )
191 calendarResource->deleteJournal( (Journal *) incOld ); 193 calendarResource->deleteJournal( (Journal *) incOld );
192 else if ( incOld->type() == "Todo" ) 194 else if ( incOld->type() == "Todo" )
193 calendarResource->deleteTodo( (Todo *) incOld ); 195 calendarResource->deleteTodo( (Todo *) incOld );
194 else if ( incOld->type() == "Event" ) 196 else if ( incOld->type() == "Event" )
195 calendarResource->deleteEvent( (Event *) incOld ); 197 calendarResource->deleteEvent( (Event *) incOld );
196 198
197 } 199 }
198 calendarResource->addIncidence( cl ); 200 calendarResource->addIncidence( cl );
199 ++add; 201 ++add;
200 } 202 }
201 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 203 }
204 KCal::Incidence::List allInc = calendarResource->rawIncidences();
202 205
203 for( it = allInc.begin(); it != allInc.end(); ++it ) { 206 for( it = allInc.begin(); it != allInc.end(); ++it ) {
204 ResourceCalendar * re = calendarResource->resource( (*it) ); 207 ResourceCalendar * re = calendarResource->resource( (*it) );
205 if ( re && !re->readOnly() ) { 208 if ( re && !re->readOnly() ) {
206 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 209 Incidence* cl = localCalendar->incidence( (*it)->uid() );
207 if ( !cl ) { 210 if ( !cl ) {
208 ++del; 211 ++del;
209 cl = (*it); 212 cl = (*it);
210 if ( cl->type() == "Journal" ) 213 if ( cl->type() == "Journal" )
211 calendarResource->deleteJournal( (Journal *) cl ); 214 calendarResource->deleteJournal( (Journal *) cl );
212 else if ( cl->type() == "Todo" ) 215 else if ( cl->type() == "Todo" )
213 calendarResource->deleteTodo( (Todo *) cl ); 216 calendarResource->deleteTodo( (Todo *) cl );
214 else if ( cl->type() == "Event" ) 217 else if ( cl->type() == "Event" )
215 calendarResource->deleteEvent( (Event *) cl ); 218 calendarResource->deleteEvent( (Event *) cl );
216 //QDateTime lm = cl->lastModified(); 219 //QDateTime lm = cl->lastModified();
217 //cl->setResources( (*it)->resources() ); 220 //cl->setResources( (*it)->resources() );
218 //cl->setLastModified(lm); 221 //cl->setLastModified(lm);
219 } 222 }
220 }
221 } 223 }
222 } 224 }
225
223 calendarResource->save(); 226 calendarResource->save();
224 qDebug("************************************* "); 227 qDebug("************************************* ");
225 qDebug("************kdecaldump*************** "); 228 qDebug("************kdecaldump*************** ");
226 qDebug("************************************* "); 229 qDebug("************************************* ");
227 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 230 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
228 231
229 } else 232 } else
230 qDebug("error loading file /tmp/kdedumpall.ics"); 233 qDebug("ERROR loading file %s",fileName.latin1() );
231 234
232 } 235 }
233 236
234 if ( localCalendar ) { 237 if ( localCalendar ) {
235 localCalendar->close(); 238 localCalendar->close();
236 delete localCalendar; 239 delete localCalendar;
237 } 240 }
238 if ( calendarResource ) { 241 if ( calendarResource ) {
239 calendarResource->close(); 242 calendarResource->close();
240 delete calendarResource; 243 delete calendarResource;
241 } 244 }
242 245
243 qDebug("ente "); 246 qDebug("ente ");
244 return 0; 247 return 0;
245} 248}