-rw-r--r-- | kde2file/caldump/main.cpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp index 03571b9..755e792 100644 --- a/kde2file/caldump/main.cpp +++ b/kde2file/caldump/main.cpp | |||
@@ -1,248 +1,255 @@ | |||
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 | 58 | ||
59 | #include <stdlib.h> | 59 | #include <stdlib.h> |
60 | #include <iostream> | 60 | #include <iostream> |
61 | 61 | ||
62 | using namespace KCal; | 62 | using namespace KCal; |
63 | using namespace std; | 63 | using namespace std; |
64 | 64 | ||
65 | static const char progName[] = "kdecalendar"; | 65 | static const char progName[] = "kdecalendar"; |
66 | static const char progDisplay[] = "KDE_Calendar"; | 66 | static const char progDisplay[] = "KDE_Calendar"; |
67 | static const char progVersion[] = "33.1/3"; | 67 | static const char progVersion[] = "33.1/3"; |
68 | static const char progDesc[] = "A command line interface to KDE calendars"; | 68 | static const char progDesc[] = "A command line interface to KDE calendars"; |
69 | 69 | ||
70 | 70 | ||
71 | static KCmdLineOptions options[] = | 71 | static KCmdLineOptions options[] = |
72 | { | 72 | { |
73 | { "dump", | 73 | { "dump", |
74 | I18N_NOOP( "Dumps calendar" ), 0 }, | 74 | I18N_NOOP( "Dumps calendar" ), 0 }, |
75 | { "read", | 75 | { "read", |
76 | I18N_NOOP( "Reads calendar" ), 0 }, | 76 | I18N_NOOP( "Reads calendar" ), 0 }, |
77 | KCmdLineLastOption | 77 | KCmdLineLastOption |
78 | }; | 78 | }; |
79 | 79 | ||
80 | int main( int argc, char *argv[] ) | 80 | int main( int argc, char *argv[] ) |
81 | { | 81 | { |
82 | KAboutData aboutData( | 82 | KAboutData aboutData( |
83 | progName, // internal program name | 83 | progName, // internal program name |
84 | I18N_NOOP( progDisplay ), // displayable program name. | 84 | I18N_NOOP( progDisplay ), // displayable program name. |
85 | progVersion, // version string | 85 | progVersion, // version string |
86 | I18N_NOOP( progDesc ), // short porgram description | 86 | I18N_NOOP( progDesc ), // short porgram description |
87 | KAboutData::License_GPL, // license type | 87 | KAboutData::License_GPL, // license type |
88 | "(c) 2004, Lutz Rogowski", // copyright statement | 88 | "(c) 2004, Lutz Rogowski", // copyright statement |
89 | 0, // any free form text | 89 | 0, // any free form text |
90 | "", // program home page address | 90 | "", // program home page address |
91 | "bugs.kde.org" // bug report email address | 91 | "bugs.kde.org" // bug report email address |
92 | ); | 92 | ); |
93 | 93 | ||
94 | 94 | ||
95 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options | 95 | // KCmdLineArgs::init() final 'true' argument indicates no commandline options |
96 | // for QApplication/KApplication (no KDE or Qt options) | 96 | // for QApplication/KApplication (no KDE or Qt options) |
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 | qDebug("*************************load"); |
156 | localCalendar = new CalendarLocal(); | 156 | localCalendar = new CalendarLocal(); |
157 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); | 157 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); |
158 | FileStorage* storage = new FileStorage( localCalendar ); | 158 | FileStorage* storage = new FileStorage( localCalendar ); |
159 | storage->setFileName( fileName ); | 159 | storage->setFileName( fileName ); |
160 | int num = 0; | 160 | int num = 0; |
161 | int del = 0; | 161 | int del = 0; |
162 | int add = 0; | 162 | int add = 0; |
163 | if ( storage->load() ) { | 163 | if ( storage->load() ) { |
164 | qDebug("*************************loaded!"); | 164 | qDebug("*************************loaded!"); |
165 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); | 165 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); |
166 | Incidence::List::ConstIterator it; | 166 | Incidence::List::ConstIterator it; |
167 | for( it = newInc.begin(); it != newInc.end(); ++it ) { | 167 | for( it = newInc.begin(); it != newInc.end(); ++it ) { |
168 | Incidence* cl = (*it)->clone(); | 168 | if ( (*it)->pilotId() > 0 ) { //changed |
169 | Incidence *incOld = calendarResource->incidence( cl->uid() ); | 169 | Incidence* cl = (*it)->clone(); |
170 | ResourceCalendar * res = 0; | 170 | Incidence *incOld = calendarResource->incidence( cl->uid() ); |
171 | if ( incOld ) | 171 | ResourceCalendar * res = 0; |
172 | res = calendarResource->resource( incOld ); | 172 | if ( incOld ) |
173 | if ( res ) { | 173 | res = calendarResource->resource( incOld ); |
174 | ++num; | 174 | if ( res ) { |
175 | if ( incOld->type() == "Journal" ) | 175 | cl->setPilotId( incOld->pilotId() ); |
176 | calendarResource->deleteJournal( (Journal *) incOld ); | 176 | ++num; |
177 | else if ( incOld->type() == "Todo" ) | ||
178 | calendarResource->deleteTodo( (Todo *) incOld ); | ||
179 | else if ( incOld->type() == "Event" ) | ||
180 | calendarResource->deleteEvent( (Event *) incOld ); | ||
181 | |||
182 | if ( cl->type() == "Journal" ) | ||
183 | calendarResource->addJournal( (Journal *) cl, res ); | ||
184 | else if ( cl->type() == "Todo" ) | ||
185 | calendarResource->addTodo( (Todo *) cl, res ); | ||
186 | else if ( cl->type() == "Event" ) | ||
187 | calendarResource->addEvent( (Event *) cl, res ); | ||
188 | |||
189 | } else { | ||
190 | if ( incOld ) { | ||
191 | qDebug("ERROR: no resource found for old incidence "); | ||
192 | if ( incOld->type() == "Journal" ) | 177 | if ( incOld->type() == "Journal" ) |
193 | calendarResource->deleteJournal( (Journal *) incOld ); | 178 | calendarResource->deleteJournal( (Journal *) incOld ); |
194 | else if ( incOld->type() == "Todo" ) | 179 | else if ( incOld->type() == "Todo" ) |
195 | calendarResource->deleteTodo( (Todo *) incOld ); | 180 | calendarResource->deleteTodo( (Todo *) incOld ); |
196 | else if ( incOld->type() == "Event" ) | 181 | else if ( incOld->type() == "Event" ) |
197 | calendarResource->deleteEvent( (Event *) incOld ); | 182 | calendarResource->deleteEvent( (Event *) incOld ); |
183 | |||
184 | if ( cl->type() == "Journal" ) | ||
185 | calendarResource->addJournal( (Journal *) cl, res ); | ||
186 | else if ( cl->type() == "Todo" ) | ||
187 | calendarResource->addTodo( (Todo *) cl, res ); | ||
188 | else if ( cl->type() == "Event" ) | ||
189 | calendarResource->addEvent( (Event *) cl, res ); | ||
190 | |||
191 | } else { | ||
192 | if ( incOld ) { | ||
193 | qDebug("ERROR: no resource found for old incidence "); | ||
194 | if ( incOld->type() == "Journal" ) | ||
195 | calendarResource->deleteJournal( (Journal *) incOld ); | ||
196 | else if ( incOld->type() == "Todo" ) | ||
197 | calendarResource->deleteTodo( (Todo *) incOld ); | ||
198 | else if ( incOld->type() == "Event" ) | ||
199 | calendarResource->deleteEvent( (Event *) incOld ); | ||
198 | 200 | ||
201 | } | ||
202 | calendarResource->addIncidence( cl ); | ||
203 | ++add; | ||
199 | } | 204 | } |
205 | } else { // added | ||
206 | Incidence* cl = (*it)->clone(); | ||
200 | calendarResource->addIncidence( cl ); | 207 | calendarResource->addIncidence( cl ); |
201 | ++add; | 208 | ++add; |
202 | } | 209 | } |
203 | } | 210 | } |
204 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); | 211 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); |
205 | 212 | ||
206 | for( it = allInc.begin(); it != allInc.end(); ++it ) { | 213 | for( it = allInc.begin(); it != allInc.end(); ++it ) { |
207 | ResourceCalendar * re = calendarResource->resource( (*it) ); | 214 | ResourceCalendar * re = calendarResource->resource( (*it) ); |
208 | if ( re && !re->readOnly() ) { | 215 | if ( re && !re->readOnly() ) { |
209 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); | 216 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); |
210 | if ( !cl ) { | 217 | if ( !cl ) { |
211 | ++del; | 218 | ++del; |
212 | cl = (*it); | 219 | cl = (*it); |
213 | if ( cl->type() == "Journal" ) | 220 | if ( cl->type() == "Journal" ) |
214 | calendarResource->deleteJournal( (Journal *) cl ); | 221 | calendarResource->deleteJournal( (Journal *) cl ); |
215 | else if ( cl->type() == "Todo" ) | 222 | else if ( cl->type() == "Todo" ) |
216 | calendarResource->deleteTodo( (Todo *) cl ); | 223 | calendarResource->deleteTodo( (Todo *) cl ); |
217 | else if ( cl->type() == "Event" ) | 224 | else if ( cl->type() == "Event" ) |
218 | calendarResource->deleteEvent( (Event *) cl ); | 225 | calendarResource->deleteEvent( (Event *) cl ); |
219 | //QDateTime lm = cl->lastModified(); | 226 | //QDateTime lm = cl->lastModified(); |
220 | //cl->setResources( (*it)->resources() ); | 227 | //cl->setResources( (*it)->resources() ); |
221 | //cl->setLastModified(lm); | 228 | //cl->setLastModified(lm); |
222 | } | 229 | } |
223 | } | 230 | } |
224 | } | 231 | } |
225 | 232 | ||
226 | calendarResource->save(); | 233 | calendarResource->save(); |
227 | qDebug("************************************* "); | 234 | qDebug("************************************* "); |
228 | qDebug("************kdecaldump*************** "); | 235 | qDebug("************kdecaldump*************** "); |
229 | qDebug("************************************* "); | 236 | qDebug("************************************* "); |
230 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); | 237 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); |
231 | 238 | ||
232 | } else | 239 | } else |
233 | qDebug("ERROR loading file %s",fileName.latin1() ); | 240 | qDebug("ERROR loading file %s",fileName.latin1() ); |
234 | 241 | ||
235 | } | 242 | } |
236 | 243 | ||
237 | if ( localCalendar ) { | 244 | if ( localCalendar ) { |
238 | localCalendar->close(); | 245 | localCalendar->close(); |
239 | delete localCalendar; | 246 | delete localCalendar; |
240 | } | 247 | } |
241 | if ( calendarResource ) { | 248 | if ( calendarResource ) { |
242 | calendarResource->close(); | 249 | calendarResource->close(); |
243 | delete calendarResource; | 250 | delete calendarResource; |
244 | } | 251 | } |
245 | 252 | ||
246 | qDebug("ente "); | 253 | qDebug("ente "); |
247 | return 0; | 254 | return 0; |
248 | } | 255 | } |