summaryrefslogtreecommitdiffabout
path: root/kde2file/caldump
Unidiff
Diffstat (limited to 'kde2file/caldump') (more/less context) (ignore whitespace changes)
-rw-r--r--kde2file/caldump/main.cpp4
1 files changed, 4 insertions, 0 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
index 95ae29e..76bfad3 100644
--- a/kde2file/caldump/main.cpp
+++ b/kde2file/caldump/main.cpp
@@ -1,204 +1,208 @@
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 57
58#include <stdlib.h> 58#include <stdlib.h>
59#include <iostream> 59#include <iostream>
60 60
61using namespace KCal; 61using namespace KCal;
62using namespace std; 62using namespace std;
63 63
64static const char progName[] = "kdecalendar"; 64static const char progName[] = "kdecalendar";
65static const char progDisplay[] = "KDE_Calendar"; 65static const char progDisplay[] = "KDE_Calendar";
66static const char progVersion[] = "33.1/3"; 66static const char progVersion[] = "33.1/3";
67static const char progDesc[] = "A command line interface to KDE calendars"; 67static const char progDesc[] = "A command line interface to KDE calendars";
68 68
69 69
70static KCmdLineOptions options[] = 70static KCmdLineOptions options[] =
71 { 71 {
72 { "dump", 72 { "dump",
73 I18N_NOOP( "Dumps calendar" ), 0 }, 73 I18N_NOOP( "Dumps calendar" ), 0 },
74 { "read", 74 { "read",
75 I18N_NOOP( "Reads calendar" ), 0 }, 75 I18N_NOOP( "Reads calendar" ), 0 },
76 KCmdLineLastOption 76 KCmdLineLastOption
77 }; 77 };
78 78
79int main( int argc, char *argv[] ) 79int main( int argc, char *argv[] )
80{ 80{
81 KAboutData aboutData( 81 KAboutData aboutData(
82 progName, // internal program name 82 progName, // internal program name
83 I18N_NOOP( progDisplay ), // displayable program name. 83 I18N_NOOP( progDisplay ), // displayable program name.
84 progVersion, // version string 84 progVersion, // version string
85 I18N_NOOP( progDesc ), // short porgram description 85 I18N_NOOP( progDesc ), // short porgram description
86 KAboutData::License_GPL, // license type 86 KAboutData::License_GPL, // license type
87 "(c) 2004, Lutz Rogowski", // copyright statement 87 "(c) 2004, Lutz Rogowski", // copyright statement
88 0, // any free form text 88 0, // any free form text
89 "", // program home page address 89 "", // program home page address
90 "bugs.kde.org" // bug report email address 90 "bugs.kde.org" // bug report email address
91 ); 91 );
92 92
93 93
94 // KCmdLineArgs::init() final 'true' argument indicates no commandline options 94 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
95 // for QApplication/KApplication (no KDE or Qt options) 95 // for QApplication/KApplication (no KDE or Qt options)
96 KCmdLineArgs::init( argc, argv, &aboutData, true ); 96 KCmdLineArgs::init( argc, argv, &aboutData, true );
97 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. 97 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
98 98
99 KInstance ins ( progName ); 99 KInstance ins ( progName );
100 100
101 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); 101 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
102 102
103 bool read = false; 103 bool read = false;
104 if ( args->isSet( "read" ) ) { 104 if ( args->isSet( "read" ) ) {
105 read = true; 105 read = true;
106 qDebug("read "); 106 qDebug("read ");
107 } 107 }
108 CalendarResources *calendarResource = 0; 108 CalendarResources *calendarResource = 0;
109 CalendarLocal *localCalendar = 0; 109 CalendarLocal *localCalendar = 0;
110 110
111 calendarResource = new CalendarResources( "" ); 111 calendarResource = new CalendarResources( "" );
112 calendarResource->readConfig(); 112 calendarResource->readConfig();
113 calendarResource->load(); 113 calendarResource->load();
114 qDebug("************************************* "); 114 qDebug("************************************* ");
115 qDebug("************************************* "); 115 qDebug("************************************* ");
116 qDebug("************************************* "); 116 qDebug("************************************* ");
117 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1()); 117 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1());
118 118
119 if ( !read ) { 119 if ( !read ) {
120 localCalendar = new CalendarLocal(); 120 localCalendar = new CalendarLocal();
121 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 121 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
122 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 122 KCal::Incidence::List allInc = calendarResource->rawIncidences();
123 Incidence::List::ConstIterator it; 123 Incidence::List::ConstIterator it;
124 int num = 0; 124 int num = 0;
125 for( it = allInc.begin(); it != allInc.end(); ++it ) { 125 for( it = allInc.begin(); it != allInc.end(); ++it ) {
126 ResourceCalendar * re = calendarResource->resource( (*it) ); 126 ResourceCalendar * re = calendarResource->resource( (*it) );
127 if ( re && !re->readOnly() ) { 127 if ( re && !re->readOnly() ) {
128 ++num; 128 ++num;
129 Incidence* cl = (*it)->clone(); 129 Incidence* cl = (*it)->clone();
130 cl->setLastModified( (*it)->lastModified() );
130 if ( cl->type() == "Journal" ) 131 if ( cl->type() == "Journal" )
131 localCalendar->addJournal( (Journal *) cl ); 132 localCalendar->addJournal( (Journal *) cl );
132 else if ( cl->type() == "Todo" ) 133 else if ( cl->type() == "Todo" )
133 localCalendar->addTodo( (Todo *) cl ); 134 localCalendar->addTodo( (Todo *) cl );
134 else if ( cl->type() == "Event" ) 135 else if ( cl->type() == "Event" )
135 localCalendar->addEvent( (Event *) cl ); 136 localCalendar->addEvent( (Event *) cl );
136 } 137 }
137 } 138 }
138 139
139 FileStorage* storage = new FileStorage( calendarResource ); 140 FileStorage* storage = new FileStorage( calendarResource );
140 storage->setFileName( "/tmp/kdedumpall.ics" ); 141 storage->setFileName( "/tmp/kdedumpall.ics" );
141 storage->setSaveFormat( new ICalFormat() ); 142 storage->setSaveFormat( new ICalFormat() );
142 storage->save(); 143 storage->save();
143 delete storage; 144 delete storage;
144 qDebug("************************************* "); 145 qDebug("************************************* ");
145 qDebug("************************************* "); 146 qDebug("************************************* ");
146 qDebug("************************************* "); 147 qDebug("************************************* ");
147 qDebug("%d calendar entries dumped to file /tmp/kdedumpall.ics", num); 148 qDebug("%d calendar entries dumped to file /tmp/kdedumpall.ics", num);
148 149
149 } else { 150 } else {
150 localCalendar = new CalendarLocal(); 151 localCalendar = new CalendarLocal();
151 localCalendar->setTimeZoneId( calendarResource->timeZoneId()); 152 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
152 FileStorage* storage = new FileStorage( localCalendar ); 153 FileStorage* storage = new FileStorage( localCalendar );
153 storage->setFileName( "/tmp/kdedumpall.ics" ); 154 storage->setFileName( "/tmp/kdedumpall.ics" );
154 int num = 0; 155 int num = 0;
155 int del = 0; 156 int del = 0;
156 if ( storage->load() ) { 157 if ( storage->load() ) {
157 KCal::Incidence::List allInc = calendarResource->rawIncidences(); 158 KCal::Incidence::List allInc = calendarResource->rawIncidences();
158 KCal::Incidence::List newInc = localCalendar->rawIncidences(); 159 KCal::Incidence::List newInc = localCalendar->rawIncidences();
159 Incidence::List::ConstIterator it; 160 Incidence::List::ConstIterator it;
160 for( it = allInc.begin(); it != allInc.end(); ++it ) { 161 for( it = allInc.begin(); it != allInc.end(); ++it ) {
161 ResourceCalendar * re = calendarResource->resource( (*it) ); 162 ResourceCalendar * re = calendarResource->resource( (*it) );
162 if ( re && !re->readOnly() ) { 163 if ( re && !re->readOnly() ) {
163 Incidence* cl = localCalendar->incidence( (*it)->uid() ); 164 Incidence* cl = localCalendar->incidence( (*it)->uid() );
164 if ( cl ) { 165 if ( cl ) {
166 QDateTime lm = cl->lastModified();
165 cl->setResources( (*it)->resources() ); 167 cl->setResources( (*it)->resources() );
168 cl->setLastModified(lm);
166 } 169 }
167 ++del; 170 ++del;
168 cl = (*it); 171 cl = (*it);
169 if ( cl->type() == "Journal" ) 172 if ( cl->type() == "Journal" )
170 calendarResource->deleteJournal( (Journal *) cl ); 173 calendarResource->deleteJournal( (Journal *) cl );
171 else if ( cl->type() == "Todo" ) 174 else if ( cl->type() == "Todo" )
172 calendarResource->deleteTodo( (Todo *) cl ); 175 calendarResource->deleteTodo( (Todo *) cl );
173 else if ( cl->type() == "Event" ) 176 else if ( cl->type() == "Event" )
174 calendarResource->deleteEvent( (Event *) cl ); 177 calendarResource->deleteEvent( (Event *) cl );
175 } 178 }
176 } 179 }
177 for( it = newInc.begin(); it != newInc.end(); ++it ) { 180 for( it = newInc.begin(); it != newInc.end(); ++it ) {
178 Incidence* cl = (*it)->clone(); 181 Incidence* cl = (*it)->clone();
179 ++num; 182 ++num;
180 calendarResource->addIncidence( cl ); 183 calendarResource->addIncidence( cl );
184 //cl->setLastModified( (*it)->lastModified() );
181 } 185 }
182 calendarResource->save(); 186 calendarResource->save();
183 qDebug("************************************* "); 187 qDebug("************************************* ");
184 qDebug("************************************* "); 188 qDebug("************************************* ");
185 qDebug("************************************* "); 189 qDebug("************************************* ");
186 qDebug("%d calendar entries deleted/ %d added from file /tmp/kdedumpall.ics", del, num); 190 qDebug("%d calendar entries deleted/ %d added from file /tmp/kdedumpall.ics", del, num);
187 191
188 } else 192 } else
189 qDebug("error loading file /tmp/kdedumpall.ics"); 193 qDebug("error loading file /tmp/kdedumpall.ics");
190 194
191 } 195 }
192 196
193 if ( localCalendar ) { 197 if ( localCalendar ) {
194 localCalendar->close(); 198 localCalendar->close();
195 delete localCalendar; 199 delete localCalendar;
196 } 200 }
197 if ( calendarResource ) { 201 if ( calendarResource ) {
198 calendarResource->close(); 202 calendarResource->close();
199 delete calendarResource; 203 delete calendarResource;
200 } 204 }
201 205
202 qDebug("ente "); 206 qDebug("ente ");
203 return 0; 207 return 0;
204} 208}