summaryrefslogtreecommitdiffabout
path: root/kde2file
Unidiff
Diffstat (limited to 'kde2file') (more/less context) (show whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp77
1 files changed, 57 insertions, 20 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 76bfad3..8d81307 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -54,6 +54,7 @@
54 54
55#include <qdatetime.h> 55#include <qdatetime.h>
56#include <qfile.h> 56#include <qfile.h>
57#include <qdir.h>
57 58
58#include <stdlib.h> 59#include <stdlib.h>
59#include <iostream> 60#include <iostream>
@@ -105,14 +106,17 @@ int main( int argc, char *argv[] )
105 read = true; 106 read = true;
106 qDebug("read "); 107 qDebug("read ");
107 } 108 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
108 CalendarResources *calendarResource = 0; 110 CalendarResources *calendarResource = 0;
109 CalendarLocal *localCalendar = 0; 111 CalendarLocal *localCalendar = 0;
110 112 KConfig c( locate( "config", "korganizerrc" ) );
111 calendarResource = new CalendarResources( "" ); 113 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz );
112 calendarResource->readConfig(); 116 calendarResource->readConfig();
113 calendarResource->load(); 117 calendarResource->load();
114 qDebug("************************************* "); 118 qDebug("************************************* ");
115 qDebug("************************************* "); 119 qDebug("**************kdecaldump************* ");
116 qDebug("************************************* "); 120 qDebug("************************************* ");
117 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1()); 121 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1());
118 122
@@ -138,35 +142,69 @@ int main( int argc, char *argv[] )
138 } 142 }
139 143
140 FileStorage* storage = new FileStorage( calendarResource ); 144 FileStorage* storage = new FileStorage( calendarResource );
141 storage->setFileName( "/tmp/kdedumpall.ics" ); 145 storage->setFileName( fileName );
142 storage->setSaveFormat( new ICalFormat() ); 146 storage->setSaveFormat( new ICalFormat() );
143 storage->save(); 147 storage->save();
144 delete storage; 148 delete storage;
145 qDebug("************************************* "); 149 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** ");
146 qDebug("************************************* "); 151 qDebug("************************************* ");
147 qDebug("************************************* "); 152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
148 qDebug("%d calendar entries dumped to file /tmp/kdedumpall.ics", num);
149 153
150 } else { 154 } else {
151 localCalendar = new CalendarLocal(); 155 localCalendar = new CalendarLocal();
152 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 156 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
153 FileStorage* storage = new FileStorage( localCalendar ); 157 FileStorage* storage = new FileStorage( localCalendar );
154 storage->setFileName( "/tmp/kdedumpall.ics" ); 158 storage->setFileName( fileName );
155 int num = 0; 159 int num = 0;
156 int del = 0; 160 int del = 0;
161 int add = 0;
157 if ( storage->load() ) { 162 if ( storage->load() ) {
158 KCal::Incidence::List allInc = calendarResource->rawIncidences();
159 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 163 KCal::Incidence::List newInc = localCalendar->rawIncidences();
160 Incidence::List::ConstIterator it; 164 Incidence::List::ConstIterator it;
165 for( it = newInc.begin(); it != newInc.end(); ++it ) {
166 Incidence* cl = (*it)->clone();
167 Incidence *incOld = calendarResource->incidence( cl->uid() );
168 ResourceCalendar * res = 0;
169 if ( incOld )
170 res = calendarResource->resource( incOld );
171 if ( res ) {
172 ++num;
173 if ( incOld->type() == "Journal" )
174 calendarResource->deleteJournal( (Journal *) incOld );
175 else if ( incOld->type() == "Todo" )
176 calendarResource->deleteTodo( (Todo *) incOld );
177 else if ( incOld->type() == "Event" )
178 calendarResource->deleteEvent( (Event *) incOld );
179
180 if ( cl->type() == "Journal" )
181 calendarResource->addJournal( (Journal *) cl, res );
182 else if ( cl->type() == "Todo" )
183 calendarResource->addTodo( (Todo *) cl, res );
184 else if ( cl->type() == "Event" )
185 calendarResource->addEvent( (Event *) cl, res );
186
187 } else {
188 if ( incOld ) {
189 qDebug("ERROR: no resource found for old incidence ");
190 if ( incOld->type() == "Journal" )
191 calendarResource->deleteJournal( (Journal *) incOld );
192 else if ( incOld->type() == "Todo" )
193 calendarResource->deleteTodo( (Todo *) incOld );
194 else if ( incOld->type() == "Event" )
195 calendarResource->deleteEvent( (Event *) incOld );
196
197 }
198 calendarResource->addIncidence( cl );
199 ++add;
200 }
201 KCal::Incidence::List allInc = calendarResource->rawIncidences();
202
161 for( it = allInc.begin(); it != allInc.end(); ++it ) { 203 for( it = allInc.begin(); it != allInc.end(); ++it ) {
162 ResourceCalendar * re = calendarResource->resource( (*it) ); 204 ResourceCalendar * re = calendarResource->resource( (*it) );
163 if ( re && !re->readOnly() ) { 205 if ( re && !re->readOnly() ) {
164 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 206 Incidence* cl = localCalendar->incidence( (*it)->uid() );
165 if ( cl ) { 207 if ( !cl ) {
166 QDateTime lm = cl->lastModified();
167 cl->setResources( (*it)->resources() );
168 cl->setLastModified(lm);
169 }
170 ++del; 208 ++del;
171 cl = (*it); 209 cl = (*it);
172 if ( cl->type() == "Journal" ) 210 if ( cl->type() == "Journal" )
@@ -175,19 +213,18 @@ int main( int argc, char *argv[] )
175 calendarResource->deleteTodo( (Todo *) cl ); 213 calendarResource->deleteTodo( (Todo *) cl );
176 else if ( cl->type() == "Event" ) 214 else if ( cl->type() == "Event" )
177 calendarResource->deleteEvent( (Event *) cl ); 215 calendarResource->deleteEvent( (Event *) cl );
216 //QDateTime lm = cl->lastModified();
217 //cl->setResources( (*it)->resources() );
218 //cl->setLastModified(lm);
219 }
178 } 220 }
179 } 221 }
180 for( it = newInc.begin(); it != newInc.end(); ++it ) {
181 Incidence* cl = (*it)->clone();
182 ++num;
183 calendarResource->addIncidence( cl );
184 //cl->setLastModified( (*it)->lastModified() );
185 } 222 }
186 calendarResource->save(); 223 calendarResource->save();
187 qDebug("************************************* "); 224 qDebug("************************************* ");
225 qDebug("************kdecaldump*************** ");
188 qDebug("************************************* "); 226 qDebug("************************************* ");
189 qDebug("************************************* "); 227 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
190 qDebug("%d calendar entries deleted/ %d added from file /tmp/kdedumpall.ics", del, num);
191 228
192 } else 229 } else
193 qDebug("error loading file /tmp/kdedumpall.ics"); 230 qDebug("error loading file /tmp/kdedumpall.ics");