summaryrefslogtreecommitdiffabout
path: root/kde2file/caldump
authorzautrix <zautrix>2004-10-17 18:08:43 (UTC)
committer zautrix <zautrix>2004-10-17 18:08:43 (UTC)
commit6f6d1d58938539215bb4fcb5b97cf9fb089a11ef (patch) (unidiff)
tree9937fe24c3fa3f29421b39a58b393e893a11636a /kde2file/caldump
parentd92f58ffa1937af8a4240b9d235da15f5f352769 (diff)
downloadkdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.zip
kdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.tar.gz
kdepimpi-6f6d1d58938539215bb4fcb5b97cf9fb089a11ef.tar.bz2
more KDE sync fixes
Diffstat (limited to 'kde2file/caldump') (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp38
1 files changed, 18 insertions, 20 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 755e792..be1735b 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -10,96 +10,97 @@
10 * * 10 * *
11 * This program is distributed in the hope that it will be useful, * 11 * This program 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 * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. * 14 * GNU General Public License for more details. *
15 * * 15 * *
16 * You should have received a copy of the GNU General Public License * 16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software * 17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * * 19 * *
20 * As a special exception, permission is given to link this program * 20 * As a special exception, permission is given to link this program *
21 * with any edition of Qt, and distribute the resulting executable, * 21 * with any edition of Qt, and distribute the resulting executable, *
22 * without including the source code for Qt in the source distribution. * 22 * without including the source code for Qt in the source distribution. *
23 * * 23 * *
24 ******************************************************************************/ 24 ******************************************************************************/
25 25
26#ifdef HAVE_CONFIG_H 26#ifdef HAVE_CONFIG_H
27#include "config.h" 27#include "config.h"
28#endif 28#endif
29 29
30#if TIME_WITH_SYS_TIME 30#if TIME_WITH_SYS_TIME
31# include <sys/time.h> 31# include <sys/time.h>
32# include <time.h> 32# include <time.h>
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#include <qdir.h>
58#include <qapplication.h>
58 59
59#include <stdlib.h> 60#include <stdlib.h>
60#include <iostream> 61#include <iostream>
61 62
62using namespace KCal; 63using namespace KCal;
63using namespace std; 64using namespace std;
64 65
65static const char progName[] = "kdecalendar"; 66static const char progName[] = "kdecalendar";
66static const char progDisplay[] = "KDE_Calendar"; 67static const char progDisplay[] = "KDE_Calendar";
67static const char progVersion[] = "33.1/3"; 68static const char progVersion[] = "33.1/3";
68static const char progDesc[] = "A command line interface to KDE calendars"; 69static const char progDesc[] = "A command line interface to KDE calendars";
69 70
70 71
71static KCmdLineOptions options[] = 72static KCmdLineOptions options[] =
72 { 73 {
73 { "dump", 74 { "dump",
74 I18N_NOOP( "Dumps calendar" ), 0 }, 75 I18N_NOOP( "Dumps calendar" ), 0 },
75 { "read", 76 { "read",
76 I18N_NOOP( "Reads calendar" ), 0 }, 77 I18N_NOOP( "Reads calendar" ), 0 },
77 KCmdLineLastOption 78 KCmdLineLastOption
78 }; 79 };
79 80
80int main( int argc, char *argv[] ) 81int main( int argc, char *argv[] )
81{ 82{
82 KAboutData aboutData( 83 KAboutData aboutData(
83 progName, // internal program name 84 progName, // internal program name
84 I18N_NOOP( progDisplay ), // displayable program name. 85 I18N_NOOP( progDisplay ), // displayable program name.
85 progVersion, // version string 86 progVersion, // version string
86 I18N_NOOP( progDesc ), // short porgram description 87 I18N_NOOP( progDesc ), // short porgram description
87 KAboutData::License_GPL, // license type 88 KAboutData::License_GPL, // license type
88 "(c) 2004, Lutz Rogowski", // copyright statement 89 "(c) 2004, Lutz Rogowski", // copyright statement
89 0, // any free form text 90 0, // any free form text
90 "", // program home page address 91 "", // program home page address
91 "bugs.kde.org" // bug report email address 92 "bugs.kde.org" // bug report email address
92 ); 93 );
93 94
94 95
95 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 96 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
96 // for QApplication/KApplication (no KDE or Qt options) 97 // for QApplication/KApplication (no KDE or Qt options)
97 KCmdLineArgs::init( argc, argv, &aboutData, true ); 98 KCmdLineArgs::init( argc, argv, &aboutData, true );
98 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 99 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
99 100
100 KInstance ins ( progName ); 101 KInstance ins ( progName );
101 102
102 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
103 104
104 bool read = false; 105 bool read = false;
105 if ( args->isSet( "read" ) ) { 106 if ( args->isSet( "read" ) ) {
@@ -107,149 +108,146 @@ int main( int argc, char *argv[] )
107 qDebug("read "); 108 qDebug("read ");
108 } 109 }
109 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 110 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
110 CalendarResources *calendarResource = 0; 111 CalendarResources *calendarResource = 0;
111 CalendarLocal *localCalendar = 0; 112 CalendarLocal *localCalendar = 0;
112 KConfig c( locate( "config", "korganizerrc" ) ); 113 KConfig c( locate( "config", "korganizerrc" ) );
113 c.setGroup( "Time & Date" ); 114 c.setGroup( "Time & Date" );
114 QString tz = c.readEntry( "TimeZoneId" ); 115 QString tz = c.readEntry( "TimeZoneId" );
115 calendarResource = new CalendarResources( tz ); 116 calendarResource = new CalendarResources( tz );
116 calendarResource->readConfig(); 117 calendarResource->readConfig();
117 calendarResource->load(); 118 calendarResource->load();
118 qDebug("************************************* "); 119 qDebug("************************************* ");
119 qDebug("**************kdecaldump************* "); 120 qDebug("**************kdecaldump************* ");
120 qDebug("************************************* "); 121 qDebug("************************************* ");
121 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); 122 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
122 123
123 if ( !read ) { 124 if ( !read ) {
124 localCalendar = new CalendarLocal(); 125 localCalendar = new CalendarLocal();
125 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 126 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
126 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 127 KCal::Incidence::List allInc = calendarResource->rawIncidences();
127 Incidence::List::ConstIterator it; 128 Incidence::List::ConstIterator it;
128 int num = 0; 129 int num = 0;
129 for( it = allInc.begin(); it != allInc.end(); ++it ) { 130 for( it = allInc.begin(); it != allInc.end(); ++it ) {
130 ResourceCalendar * re = calendarResource->resource( (*it) ); 131 ResourceCalendar * re = calendarResource->resource( (*it) );
131 if ( re && !re->readOnly() ) { 132 if ( re && !re->readOnly() ) {
132 ++num; 133 ++num;
133 Incidence* cl = (*it)->clone(); 134 Incidence* cl = (*it)->clone();
134 cl->setLastModified( (*it)->lastModified() ); 135 cl->setLastModified( (*it)->lastModified() );
135 if ( cl->type() == "Journal" ) 136 if ( cl->type() == "Journal" )
136 localCalendar->addJournal( (Journal *) cl ); 137 localCalendar->addJournal( (Journal *) cl );
137 else if ( cl->type() == "Todo" ) 138 else if ( cl->type() == "Todo" )
138 localCalendar->addTodo( (Todo *) cl ); 139 localCalendar->addTodo( (Todo *) cl );
139 else if ( cl->type() == "Event" ) 140 else if ( cl->type() == "Event" )
140 localCalendar->addEvent( (Event *) cl ); 141 localCalendar->addEvent( (Event *) cl );
141 } 142 }
142 } 143 }
143 144
144 FileStorage* storage = new FileStorage( calendarResource ); 145 FileStorage* storage = new FileStorage( calendarResource );
145 storage->setFileName( fileName ); 146 storage->setFileName( fileName );
146 storage->setSaveFormat( new ICalFormat() ); 147 storage->setSaveFormat( new ICalFormat() );
147 storage->save(); 148 storage->save();
148 delete storage; 149 delete storage;
149 qDebug("************************************* "); 150 qDebug("************************************* ");
150 qDebug("************kdecaldump*************** "); 151 qDebug("************kdecaldump*************** ");
151 qDebug("************************************* "); 152 qDebug("************************************* ");
152 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 153 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
153 154
154 } else { 155 } else {
155 qDebug("*************************load"); 156 qDebug("************load");
156 localCalendar = new CalendarLocal(); 157 localCalendar = new CalendarLocal();
157 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 158 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
158 FileStorage* storage = new FileStorage( localCalendar ); 159 FileStorage* storage = new FileStorage( localCalendar );
159 storage->setFileName( fileName ); 160 storage->setFileName( fileName );
160 int num = 0; 161 int num = 0;
161 int del = 0; 162 int del = 0;
162 int add = 0; 163 int add = 0;
163 if ( storage->load() ) { 164 if ( storage->load() ) {
164 qDebug("*************************loaded!"); 165 qDebug("***********loaded!");
165 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 166 KCal::Incidence::List newInc = localCalendar->rawIncidences();
166 Incidence::List::ConstIterator it; 167 Incidence::List::ConstIterator it;
167 for( it = newInc.begin(); it != newInc.end(); ++it ) { 168 for( it = newInc.begin(); it != newInc.end(); ++it ) {
168 if ( (*it)->pilotId() > 0 ) { //changed 169 if ( (*it)->pilotId() > 1 ) { //changed
169 Incidence* cl = (*it)->clone(); 170 qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1());
170 Incidence *incOld = calendarResource->incidence( cl->uid() ); 171 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
171 ResourceCalendar * res = 0; 172 ResourceCalendar * res = 0;
172 if ( incOld ) 173 if ( incOld )
173 res = calendarResource->resource( incOld ); 174 res = calendarResource->resource( incOld );
174 if ( res ) { 175 if ( res ) {
176 Incidence* cl = (*it)->clone();
175 cl->setPilotId( incOld->pilotId() ); 177 cl->setPilotId( incOld->pilotId() );
176 ++num; 178 ++num;
177 if ( incOld->type() == "Journal" ) 179 if ( incOld->type() == "Journal" )
178 calendarResource->deleteJournal( (Journal *) incOld ); 180 calendarResource->deleteJournal( (Journal *) incOld );
179 else if ( incOld->type() == "Todo" ) 181 else if ( incOld->type() == "Todo" )
180 calendarResource->deleteTodo( (Todo *) incOld ); 182 calendarResource->deleteTodo( (Todo *) incOld );
181 else if ( incOld->type() == "Event" ) 183 else if ( incOld->type() == "Event" )
182 calendarResource->deleteEvent( (Event *) incOld ); 184 calendarResource->deleteEvent( (Event *) incOld );
183 185 qDebug("*********change incidence %s ",cl->summary().latin1());
184 if ( cl->type() == "Journal" ) 186 if ( cl->type() == "Journal" )
185 calendarResource->addJournal( (Journal *) cl, res ); 187 calendarResource->addJournal( (Journal *) cl, res );
186 else if ( cl->type() == "Todo" ) 188 else if ( cl->type() == "Todo" )
187 calendarResource->addTodo( (Todo *) cl, res ); 189 calendarResource->addTodo( (Todo *) cl, res );
188 else if ( cl->type() == "Event" ) 190 else if ( cl->type() == "Event" )
189 calendarResource->addEvent( (Event *) cl, res ); 191 calendarResource->addEvent( (Event *) cl, res );
190 192
191 } else { 193 } else {
192 if ( incOld ) { 194 Incidence* cl = (*it)->clone();
193 qDebug("ERROR: no resource found for old incidence "); 195 qDebug("*********add incidence %s ",cl->summary().latin1());
194 if ( incOld->type() == "Journal" ) 196 calendarResource->addIncidence( cl );
195 calendarResource->deleteJournal( (Journal *) incOld ); 197 ++add;
196 else if ( incOld->type() == "Todo" ) 198 }
197 calendarResource->deleteTodo( (Todo *) incOld ); 199 } else { // maybe added
198 else if ( incOld->type() == "Event" ) 200 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
199 calendarResource->deleteEvent( (Event *) incOld ); 201 if ( !incOld ) { //added
200 202 Incidence* cl = (*it)->clone();
201 } 203 qDebug("*********add incidence %s ",cl->summary().latin1());
202 calendarResource->addIncidence( cl ); 204 calendarResource->addIncidence( cl );
203 ++add; 205 ++add;
204 } 206 }
205 } else { // added
206 Incidence* cl = (*it)->clone();
207 calendarResource->addIncidence( cl );
208 ++add;
209 } 207 }
210 } 208 }
211 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 209 KCal::Incidence::List allInc = calendarResource->rawIncidences();
212 210
213 for( it = allInc.begin(); it != allInc.end(); ++it ) { 211 for( it = allInc.begin(); it != allInc.end(); ++it ) {
214 ResourceCalendar * re = calendarResource->resource( (*it) ); 212 ResourceCalendar * re = calendarResource->resource( (*it) );
215 if ( re && !re->readOnly() ) { 213 if ( re && !re->readOnly() ) {
216 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 214 Incidence* cl = localCalendar->incidence( (*it)->uid() );
217 if ( !cl ) { 215 if ( !cl ) {
218 ++del; 216 ++del;
219 cl = (*it); 217 cl = (*it);
220 if ( cl->type() == "Journal" ) 218 if ( cl->type() == "Journal" )
221 calendarResource->deleteJournal( (Journal *) cl ); 219 calendarResource->deleteJournal( (Journal *) cl );
222 else if ( cl->type() == "Todo" ) 220 else if ( cl->type() == "Todo" )
223 calendarResource->deleteTodo( (Todo *) cl ); 221 calendarResource->deleteTodo( (Todo *) cl );
224 else if ( cl->type() == "Event" ) 222 else if ( cl->type() == "Event" )
225 calendarResource->deleteEvent( (Event *) cl ); 223 calendarResource->deleteEvent( (Event *) cl );
226 //QDateTime lm = cl->lastModified(); 224 //QDateTime lm = cl->lastModified();
227 //cl->setResources( (*it)->resources() ); 225 //cl->setResources( (*it)->resources() );
228 //cl->setLastModified(lm); 226 //cl->setLastModified(lm);
229 } 227 }
230 } 228 }
231 } 229 }
232 230
233 calendarResource->save(); 231 calendarResource->save();
234 qDebug("************************************* "); 232 qDebug("************************************* ");
235 qDebug("************kdecaldump*************** "); 233 qDebug("************kdecaldump*************** ");
236 qDebug("************************************* "); 234 qDebug("************************************* ");
237 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 235 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
238 236
239 } else 237 } else
240 qDebug("ERROR loading file %s",fileName.latin1() ); 238 qDebug("ERROR loading file %s",fileName.latin1() );
241 239
242 } 240 }
243 241
244 if ( localCalendar ) { 242 if ( localCalendar ) {
245 localCalendar->close(); 243 localCalendar->close();
246 delete localCalendar; 244 delete localCalendar;
247 } 245 }
248 if ( calendarResource ) { 246 if ( calendarResource ) {
249 calendarResource->close(); 247 calendarResource->close();
250 delete calendarResource; 248 delete calendarResource;
251 } 249 }
252 250
253 qDebug("ente "); 251 qDebug("ente ");
254 return 0; 252 return 0;
255} 253}