summaryrefslogtreecommitdiffabout
path: root/kde2file
authorzautrix <zautrix>2004-10-17 14:32:16 (UTC)
committer zautrix <zautrix>2004-10-17 14:32:16 (UTC)
commit780a12295cbbcf4eff4f9570322c1cac517414ad (patch) (unidiff)
tree4c68b7e6ee854f9d4f0e7e3032f7c70cc45668be /kde2file
parentf909868a098a22c17906f3d2ab05d5fac0332e85 (diff)
downloadkdepimpi-780a12295cbbcf4eff4f9570322c1cac517414ad.zip
kdepimpi-780a12295cbbcf4eff4f9570322c1cac517414ad.tar.gz
kdepimpi-780a12295cbbcf4eff4f9570322c1cac517414ad.tar.bz2
many kde sync fixes
Diffstat (limited to 'kde2file') (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp97
1 files changed, 67 insertions, 30 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
@@ -33,48 +33,49 @@
33#else 33#else
34# if HAVE_SYS_TIME_H 34# if HAVE_SYS_TIME_H
35# include <sys/time.h> 35# include <sys/time.h>
36# else 36# else
37# include <time.h> 37# include <time.h>
38# endif 38# endif
39#endif 39#endif
40 40
41#include <kcmdlineargs.h> 41#include <kcmdlineargs.h>
42#include <kaboutdata.h> 42#include <kaboutdata.h>
43#include <klocale.h> 43#include <klocale.h>
44#include <kglobal.h> 44#include <kglobal.h>
45#include <kconfig.h> 45#include <kconfig.h>
46#include <kstandarddirs.h> 46#include <kstandarddirs.h>
47#include <kdebug.h> 47#include <kdebug.h>
48 48
49#include <libkcal/calformat.h> 49#include <libkcal/calformat.h>
50#include <libkcal/calendarresources.h> 50#include <libkcal/calendarresources.h>
51#include <libkcal/resourcelocal.h> 51#include <libkcal/resourcelocal.h>
52#include <libkcal/filestorage.h> 52#include <libkcal/filestorage.h>
53#include <libkcal/icalformat.h> 53#include <libkcal/icalformat.h>
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>
60 61
61using namespace KCal; 62using namespace KCal;
62using namespace std; 63using namespace std;
63 64
64static const char progName[] = "kdecalendar"; 65static const char progName[] = "kdecalendar";
65static const char progDisplay[] = "KDE_Calendar"; 66static const char progDisplay[] = "KDE_Calendar";
66static const char progVersion[] = "33.1/3"; 67static const char progVersion[] = "33.1/3";
67static const char progDesc[] = "A command line interface to KDE calendars"; 68static const char progDesc[] = "A command line interface to KDE calendars";
68 69
69 70
70static KCmdLineOptions options[] = 71static KCmdLineOptions options[] =
71 { 72 {
72 { "dump", 73 { "dump",
73 I18N_NOOP( "Dumps calendar" ), 0 }, 74 I18N_NOOP( "Dumps calendar" ), 0 },
74 { "read", 75 { "read",
75 I18N_NOOP( "Reads calendar" ), 0 }, 76 I18N_NOOP( "Reads calendar" ), 0 },
76 KCmdLineLastOption 77 KCmdLineLastOption
77 }; 78 };
78 79
79int main( int argc, char *argv[] ) 80int main( int argc, char *argv[] )
80{ 81{
@@ -84,125 +85,161 @@ int main( int argc, char *argv[] )
84 progVersion, // version string 85 progVersion, // version string
85 I18N_NOOP( progDesc ), // short porgram description 86 I18N_NOOP( progDesc ), // short porgram description
86 KAboutData::License_GPL, // license type 87 KAboutData::License_GPL, // license type
87 "(c) 2004, Lutz Rogowski", // copyright statement 88 "(c) 2004, Lutz Rogowski", // copyright statement
88 0, // any free form text 89 0, // any free form text
89 "", // program home page address 90 "", // program home page address
90 "bugs.kde.org" // bug report email address 91 "bugs.kde.org" // bug report email address
91 ); 92 );
92 93
93 94
94 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
95 // for QApplication/KApplication (no KDE or Qt options) 96 // for QApplication/KApplication (no KDE or Qt options)
96 KCmdLineArgs::init( argc, argv, &aboutData, true ); 97 KCmdLineArgs::init( argc, argv, &aboutData, true );
97 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
98 99
99 KInstance ins ( progName ); 100 KInstance ins ( progName );
100 101
101 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
102 103
103 bool read = false; 104 bool read = false;
104 if ( args->isSet( "read" ) ) { 105 if ( args->isSet( "read" ) ) {
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
119 if ( !read ) { 123 if ( !read ) {
120 localCalendar = new CalendarLocal(); 124 localCalendar = new CalendarLocal();
121 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 125 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
122 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 126 KCal::Incidence::List allInc = calendarResource->rawIncidences();
123 Incidence::List::ConstIterator it; 127 Incidence::List::ConstIterator it;
124 int num = 0; 128 int num = 0;
125 for( it = allInc.begin(); it != allInc.end(); ++it ) { 129 for( it = allInc.begin(); it != allInc.end(); ++it ) {
126 ResourceCalendar * re = calendarResource->resource( (*it) ); 130 ResourceCalendar * re = calendarResource->resource( (*it) );
127 if ( re && !re->readOnly() ) { 131 if ( re && !re->readOnly() ) {
128 ++num; 132 ++num;
129 Incidence* cl = (*it)->clone(); 133 Incidence* cl = (*it)->clone();
130 cl->setLastModified( (*it)->lastModified() ); 134 cl->setLastModified( (*it)->lastModified() );
131 if ( cl->type() == "Journal" ) 135 if ( cl->type() == "Journal" )
132 localCalendar->addJournal( (Journal *) cl ); 136 localCalendar->addJournal( (Journal *) cl );
133 else if ( cl->type() == "Todo" ) 137 else if ( cl->type() == "Todo" )
134 localCalendar->addTodo( (Todo *) cl ); 138 localCalendar->addTodo( (Todo *) cl );
135 else if ( cl->type() == "Event" ) 139 else if ( cl->type() == "Event" )
136 localCalendar->addEvent( (Event *) cl ); 140 localCalendar->addEvent( (Event *) cl );
137 } 141 }
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;
161 for( it = allInc.begin(); it != allInc.end(); ++it ) { 165 for( it = newInc.begin(); it != newInc.end(); ++it ) {
162 ResourceCalendar * re = calendarResource->resource( (*it) ); 166 Incidence* cl = (*it)->clone();
163 if ( re && !re->readOnly() ) { 167 Incidence *incOld = calendarResource->incidence( cl->uid() );
164 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 168 ResourceCalendar * res = 0;
165 if ( cl ) { 169 if ( incOld )
166 QDateTime lm = cl->lastModified(); 170 res = calendarResource->resource( incOld );
167 cl->setResources( (*it)->resources() ); 171 if ( res ) {
168 cl->setLastModified(lm); 172 ++num;
169 } 173 if ( incOld->type() == "Journal" )
170 ++del; 174 calendarResource->deleteJournal( (Journal *) incOld );
171 cl = (*it); 175 else if ( incOld->type() == "Todo" )
176 calendarResource->deleteTodo( (Todo *) incOld );
177 else if ( incOld->type() == "Event" )
178 calendarResource->deleteEvent( (Event *) incOld );
179
172 if ( cl->type() == "Journal" ) 180 if ( cl->type() == "Journal" )
173 calendarResource->deleteJournal( (Journal *) cl ); 181 calendarResource->addJournal( (Journal *) cl, res );
174 else if ( cl->type() == "Todo" ) 182 else if ( cl->type() == "Todo" )
175 calendarResource->deleteTodo( (Todo *) cl ); 183 calendarResource->addTodo( (Todo *) cl, res );
176 else if ( cl->type() == "Event" ) 184 else if ( cl->type() == "Event" )
177 calendarResource->deleteEvent( (Event *) cl ); 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
203 for( it = allInc.begin(); it != allInc.end(); ++it ) {
204 ResourceCalendar * re = calendarResource->resource( (*it) );
205 if ( re && !re->readOnly() ) {
206 Incidence* cl = localCalendar->incidence( (*it)->uid() );
207 if ( !cl ) {
208 ++del;
209 cl = (*it);
210 if ( cl->type() == "Journal" )
211 calendarResource->deleteJournal( (Journal *) cl );
212 else if ( cl->type() == "Todo" )
213 calendarResource->deleteTodo( (Todo *) cl );
214 else if ( cl->type() == "Event" )
215 calendarResource->deleteEvent( (Event *) cl );
216 //QDateTime lm = cl->lastModified();
217 //cl->setResources( (*it)->resources() );
218 //cl->setLastModified(lm);
219 }
220 }
178 } 221 }
179 }
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");
194 231
195 } 232 }
196 233
197 if ( localCalendar ) { 234 if ( localCalendar ) {
198 localCalendar->close(); 235 localCalendar->close();
199 delete localCalendar; 236 delete localCalendar;
200 } 237 }
201 if ( calendarResource ) { 238 if ( calendarResource ) {
202 calendarResource->close(); 239 calendarResource->close();
203 delete calendarResource; 240 delete calendarResource;
204 } 241 }
205 242
206 qDebug("ente "); 243 qDebug("ente ");
207 return 0; 244 return 0;
208} 245}