summaryrefslogtreecommitdiffabout
path: root/kde2file/caldump/main.cpp
authorzautrix <zautrix>2005-04-17 14:27:55 (UTC)
committer zautrix <zautrix>2005-04-17 14:27:55 (UTC)
commitb411ec2d8961d07c3e2e9aefc9e04322b7851859 (patch) (unidiff)
tree79e2a70f1ad32562456b0bfa03aa2b916095fbb0 /kde2file/caldump/main.cpp
parent2d81c75c4ffb8f144ae58e90e68496500d07a19e (diff)
downloadkdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.zip
kdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.tar.gz
kdepimpi-b411ec2d8961d07c3e2e9aefc9e04322b7851859.tar.bz2
qdebugcleanup
Diffstat (limited to 'kde2file/caldump/main.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 9cc1a73..c8755cd 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -1,253 +1,254 @@
1/******************************************************************************* 1/*******************************************************************************
2 * main.cpp * 2 * main.cpp *
3 * * 3 * *
4 * 4 *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by * 7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or * 8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. * 9 * (at your option) any later version. *
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#include <qapplication.h>
59 59
60#include <stdlib.h> 60#include <stdlib.h>
61#include <iostream> 61#include <iostream>
62 62
63using namespace KCal; 63using namespace KCal;
64using namespace std; 64using namespace std;
65 65
66static const char progName[] = "kdecalendar"; 66static const char progName[] = "kdecalendar";
67static const char progDisplay[] = "KDE_Calendar"; 67static const char progDisplay[] = "KDE_Calendar";
68static const char progVersion[] = "33.1/3"; 68static const char progVersion[] = "33.1/3";
69static const char progDesc[] = "A command line interface to KDE calendars"; 69static const char progDesc[] = "A command line interface to KDE calendars";
70 70
71 71
72static KCmdLineOptions options[] = 72static KCmdLineOptions options[] =
73 { 73 {
74 { "dump", 74 { "dump",
75 I18N_NOOP( "Dumps calendar" ), 0 }, 75 I18N_NOOP( "Dumps calendar" ), 0 },
76 { "read", 76 { "read",
77 I18N_NOOP( "Reads calendar" ), 0 }, 77 I18N_NOOP( "Reads calendar" ), 0 },
78 KCmdLineLastOption 78 KCmdLineLastOption
79 }; 79 };
80 80
81int main( int argc, char *argv[] ) 81int main( int argc, char *argv[] )
82{ 82{
83 KAboutData aboutData( 83 KAboutData aboutData(
84 progName, // internal program name 84 progName, // internal program name
85 I18N_NOOP( progDisplay ), // displayable program name. 85 I18N_NOOP( progDisplay ), // displayable program name.
86 progVersion, // version string 86 progVersion, // version string
87 I18N_NOOP( progDesc ), // short porgram description 87 I18N_NOOP( progDesc ), // short porgram description
88 KAboutData::License_GPL, // license type 88 KAboutData::License_GPL, // license type
89 "(c) 2004, Lutz Rogowski", // copyright statement 89 "(c) 2004, Lutz Rogowski", // copyright statement
90 0, // any free form text 90 0, // any free form text
91 "", // program home page address 91 "", // program home page address
92 "bugs.kde.org" // bug report email address 92 "bugs.kde.org" // bug report email address
93 ); 93 );
94 94
95 95
96 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 96 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
97 // for QApplication/KApplication (no KDE or Qt options) 97 // for QApplication/KApplication (no KDE or Qt options)
98 KCmdLineArgs::init( argc, argv, &aboutData, true ); 98 KCmdLineArgs::init( argc, argv, &aboutData, true );
99 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 99 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
100 100
101 KInstance ins ( progName ); 101 KInstance ins ( progName );
102 102
103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 103 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
104 104
105 bool read = false; 105 bool read = false;
106 if ( args->isSet( "read" ) ) { 106 if ( args->isSet( "read" ) ) {
107 read = true; 107 read = true;
108 qDebug("read "); 108 qDebug("read ");
109 } 109 }
110 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics"; 110 QString fileName = QDir::homeDirPath ()+"/.kdecalendardump.ics";
111 CalendarResources *calendarResource = 0; 111 CalendarResources *calendarResource = 0;
112 CalendarLocal *localCalendar = 0; 112 CalendarLocal *localCalendar = 0;
113 KConfig c( locate( "config", "korganizerrc" ) ); 113 KConfig c( locate( "config", "korganizerrc" ) );
114 c.setGroup( "Time & Date" ); 114 c.setGroup( "Time & Date" );
115 QString tz = c.readEntry( "TimeZoneId" ); 115 QString tz = c.readEntry( "TimeZoneId" );
116 calendarResource = new CalendarResources( tz ); 116 calendarResource = new CalendarResources( tz );
117 calendarResource->readConfig(); 117 calendarResource->readConfig();
118 calendarResource->load(); 118 calendarResource->load();
119 qDebug("************************************* "); 119 qDebug("************************************* ");
120 qDebug("**************kdecaldump************* "); 120 qDebug("**************kdecaldump************* ");
121 qDebug("************************************* "); 121 qDebug("************************************* ");
122 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1()); 122 qDebug("Using timezone ID: %s", calendarResource->timeZoneId().latin1());
123 123
124 if ( !read ) { 124 if ( !read ) {
125 localCalendar = new CalendarLocal(); 125 localCalendar = new CalendarLocal();
126 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 126 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
127 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 127 KCal::Incidence::List allInc = calendarResource->rawIncidences();
128 Incidence::List::ConstIterator it; 128 Incidence::List::ConstIterator it;
129 int num = 0; 129 int num = 0;
130 for( it = allInc.begin(); it != allInc.end(); ++it ) { 130 for( it = allInc.begin(); it != allInc.end(); ++it ) {
131 ResourceCalendar * re = calendarResource->resource( (*it) ); 131 ResourceCalendar * re = calendarResource->resource( (*it) );
132 if ( re ) { 132 //if ( re )
133 {
133 ++num; 134 ++num;
134 Incidence* cl = (*it)->clone(); 135 Incidence* cl = (*it)->clone();
135 cl->setLastModified( (*it)->lastModified() ); 136 cl->setLastModified( (*it)->lastModified() );
136 if ( cl->type() == "Journal" ) 137 if ( cl->type() == "Journal" )
137 localCalendar->addJournal( (Journal *) cl ); 138 localCalendar->addJournal( (Journal *) cl );
138 else if ( cl->type() == "Todo" ) 139 else if ( cl->type() == "Todo" )
139 localCalendar->addTodo( (Todo *) cl ); 140 localCalendar->addTodo( (Todo *) cl );
140 else if ( cl->type() == "Event" ) 141 else if ( cl->type() == "Event" )
141 localCalendar->addEvent( (Event *) cl ); 142 localCalendar->addEvent( (Event *) cl );
142 } 143 }
143 } 144 }
144 145
145 FileStorage* storage = new FileStorage( calendarResource ); 146 FileStorage* storage = new FileStorage( calendarResource );
146 storage->setFileName( fileName ); 147 storage->setFileName( fileName );
147 storage->setSaveFormat( new ICalFormat() ); 148 storage->setSaveFormat( new ICalFormat() );
148 storage->save(); 149 storage->save();
149 delete storage; 150 delete storage;
150 qDebug("************************************* "); 151 qDebug("************************************* ");
151 qDebug("************kdecaldump*************** "); 152 qDebug("************kdecaldump*************** ");
152 qDebug("************************************* "); 153 qDebug("************************************* ");
153 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); 154 qDebug("%d calendar entries dumped to file %s", num, fileName.latin1());
154 155
155 } else { 156 } else {
156 qDebug("************load"); 157 qDebug("************load");
157 localCalendar = new CalendarLocal(); 158 localCalendar = new CalendarLocal();
158 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 159 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
159 FileStorage* storage = new FileStorage( localCalendar ); 160 FileStorage* storage = new FileStorage( localCalendar );
160 storage->setFileName( fileName ); 161 storage->setFileName( fileName );
161 int num = 0; 162 int num = 0;
162 int del = 0; 163 int del = 0;
163 int add = 0; 164 int add = 0;
164 if ( storage->load() ) { 165 if ( storage->load() ) {
165 qDebug("***********loaded!"); 166 qDebug("***********loaded!");
166 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 167 KCal::Incidence::List newInc = localCalendar->rawIncidences();
167 Incidence::List::ConstIterator it; 168 Incidence::List::ConstIterator it;
168 for( it = newInc.begin(); it != newInc.end(); ++it ) { 169 for( it = newInc.begin(); it != newInc.end(); ++it ) {
169 if ( (*it)->pilotId() > 1 ) { //changed 170 if ( (*it)->pilotId() > 1 ) { //changed
170 qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1()); 171 qDebug("*********pilot id %d %s ",(*it)->pilotId() ,(*it)->summary().latin1());
171 Incidence *incOld = calendarResource->incidence( (*it)->uid() ); 172 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
172 ResourceCalendar * res = 0; 173 ResourceCalendar * res = 0;
173 if ( incOld ) 174 if ( incOld )
174 res = calendarResource->resource( incOld ); 175 res = calendarResource->resource( incOld );
175 if ( res ) { 176 if ( res ) {
176 Incidence* cl = (*it)->clone(); 177 Incidence* cl = (*it)->clone();
177 cl->setPilotId( incOld->pilotId() ); 178 cl->setPilotId( incOld->pilotId() );
178 ++num; 179 ++num;
179 if ( incOld->type() == "Journal" ) 180 if ( incOld->type() == "Journal" )
180 calendarResource->deleteJournal( (Journal *) incOld ); 181 calendarResource->deleteJournal( (Journal *) incOld );
181 else if ( incOld->type() == "Todo" ) 182 else if ( incOld->type() == "Todo" )
182 calendarResource->deleteTodo( (Todo *) incOld ); 183 calendarResource->deleteTodo( (Todo *) incOld );
183 else if ( incOld->type() == "Event" ) 184 else if ( incOld->type() == "Event" )
184 calendarResource->deleteEvent( (Event *) incOld ); 185 calendarResource->deleteEvent( (Event *) incOld );
185 qDebug("*********change incidence %s ",cl->summary().latin1()); 186 qDebug("*********change incidence %s ",cl->summary().latin1());
186 if ( cl->type() == "Journal" ) 187 if ( cl->type() == "Journal" )
187 calendarResource->addJournal( (Journal *) cl, res ); 188 calendarResource->addJournal( (Journal *) cl, res );
188 else if ( cl->type() == "Todo" ) 189 else if ( cl->type() == "Todo" )
189 calendarResource->addTodo( (Todo *) cl, res ); 190 calendarResource->addTodo( (Todo *) cl, res );
190 else if ( cl->type() == "Event" ) 191 else if ( cl->type() == "Event" )
191 calendarResource->addEvent( (Event *) cl, res ); 192 calendarResource->addEvent( (Event *) cl, res );
192 193
193 } else { 194 } else {
194 Incidence* cl = (*it)->clone(); 195 Incidence* cl = (*it)->clone();
195 qDebug("*********add incidence %s ",cl->summary().latin1()); 196 qDebug("*********add incidence %s ",cl->summary().latin1());
196 calendarResource->addIncidence( cl ); 197 calendarResource->addIncidence( cl );
197 ++add; 198 ++add;
198 } 199 }
199 } else { // maybe added 200 } else { // maybe added
200 Incidence *incOld = calendarResource->incidence( (*it)->uid() ); 201 Incidence *incOld = calendarResource->incidence( (*it)->uid() );
201 if ( !incOld ) { //added 202 if ( !incOld ) { //added
202 Incidence* cl = (*it)->clone(); 203 Incidence* cl = (*it)->clone();
203 qDebug("*********add incidence %s ",cl->summary().latin1()); 204 qDebug("*********add incidence %s ",cl->summary().latin1());
204 calendarResource->addIncidence( cl ); 205 calendarResource->addIncidence( cl );
205 ++add; 206 ++add;
206 } 207 }
207 } 208 }
208 } 209 }
209 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 210 KCal::Incidence::List allInc = calendarResource->rawIncidences();
210 211
211 for( it = allInc.begin(); it != allInc.end(); ++it ) { 212 for( it = allInc.begin(); it != allInc.end(); ++it ) {
212 ResourceCalendar * re = calendarResource->resource( (*it) ); 213 ResourceCalendar * re = calendarResource->resource( (*it) );
213 if ( re && !re->readOnly() ) { 214 if ( re && !re->readOnly() ) {
214 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 215 Incidence* cl = localCalendar->incidence( (*it)->uid() );
215 if ( !cl ) { 216 if ( !cl ) {
216 ++del; 217 ++del;
217 cl = (*it); 218 cl = (*it);
218 if ( cl->type() == "Journal" ) 219 if ( cl->type() == "Journal" )
219 calendarResource->deleteJournal( (Journal *) cl ); 220 calendarResource->deleteJournal( (Journal *) cl );
220 else if ( cl->type() == "Todo" ) 221 else if ( cl->type() == "Todo" )
221 calendarResource->deleteTodo( (Todo *) cl ); 222 calendarResource->deleteTodo( (Todo *) cl );
222 else if ( cl->type() == "Event" ) 223 else if ( cl->type() == "Event" )
223 calendarResource->deleteEvent( (Event *) cl ); 224 calendarResource->deleteEvent( (Event *) cl );
224 //QDateTime lm = cl->lastModified(); 225 //QDateTime lm = cl->lastModified();
225 //cl->setResources( (*it)->resources() ); 226 //cl->setResources( (*it)->resources() );
226 //cl->setLastModified(lm); 227 //cl->setLastModified(lm);
227 } 228 }
228 } 229 }
229 } 230 }
230 231
231 calendarResource->save(); 232 calendarResource->save();
232 qDebug("************************************* "); 233 qDebug("************************************* ");
233 qDebug("************kdecaldump*************** "); 234 qDebug("************kdecaldump*************** ");
234 qDebug("************************************* "); 235 qDebug("************************************* ");
235 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); 236 qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1());
236 237
237 } else 238 } else
238 qDebug("ERROR loading file %s",fileName.latin1() ); 239 qDebug("ERROR loading file %s",fileName.latin1() );
239 240
240 } 241 }
241 242
242 if ( localCalendar ) { 243 if ( localCalendar ) {
243 localCalendar->close(); 244 localCalendar->close();
244 delete localCalendar; 245 delete localCalendar;
245 } 246 }
246 if ( calendarResource ) { 247 if ( calendarResource ) {
247 calendarResource->close(); 248 calendarResource->close();
248 delete calendarResource; 249 delete calendarResource;
249 } 250 }
250 251
251 qDebug("ente "); 252 qDebug("ente ");
252 return 0; 253 return 0;
253} 254}