summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kde2file/caldump/caldump.pro13
-rw-r--r--kde2file/caldump/main.cpp204
2 files changed, 217 insertions, 0 deletions
diff --git a/kde2file/caldump/caldump.pro b/kde2file/caldump/caldump.pro
new file mode 100644
index 0000000..ecc20c5
--- a/dev/null
+++ b/kde2file/caldump/caldump.pro
@@ -0,0 +1,13 @@
1
2TEMPLATE = app
3CONFIG += qt
4include( ../../variables.pri )
5DESTDIR= ../../bin
6 TARGET = kdecaldump
7INCLUDEPATH += . $(KDEDIR)/include $(KDEDIR)/include/libkcal /kde_dev/kde32/build/kdepim33_proko2_new/libkdepim
8
9LIBS += $(KDEDIR)/lib/libkcal.so
10LIBS += $(KDEDIR)/lib/libkdepim.so
11HEADERS +=
12
13SOURCES += main.cpp
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp
new file mode 100644
index 0000000..95ae29e
--- a/dev/null
+++ b/kde2file/caldump/main.cpp
@@ -0,0 +1,204 @@
1/*******************************************************************************
2 * main.cpp *
3 * *
4 *
5 * *
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 *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
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 *
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * *
20 * As a special exception, permission is given to link this program *
21 * with any edition of Qt, and distribute the resulting executable, *
22 * without including the source code for Qt in the source distribution. *
23 * *
24 ******************************************************************************/
25
26#ifdef HAVE_CONFIG_H
27#include "config.h"
28#endif
29
30#if TIME_WITH_SYS_TIME
31# include <sys/time.h>
32# include <time.h>
33#else
34# if HAVE_SYS_TIME_H
35# include <sys/time.h>
36# else
37# include <time.h>
38# endif
39#endif
40
41#include <kcmdlineargs.h>
42#include <kaboutdata.h>
43#include <klocale.h>
44#include <kglobal.h>
45#include <kconfig.h>
46#include <kstandarddirs.h>
47#include <kdebug.h>
48
49#include <libkcal/calformat.h>
50#include <libkcal/calendarresources.h>
51#include <libkcal/resourcelocal.h>
52#include <libkcal/filestorage.h>
53#include <libkcal/icalformat.h>
54
55#include <qdatetime.h>
56#include <qfile.h>
57
58#include <stdlib.h>
59#include <iostream>
60
61using namespace KCal;
62using namespace std;
63
64static const char progName[] = "kdecalendar";
65static const char progDisplay[] = "KDE_Calendar";
66static const char progVersion[] = "33.1/3";
67static const char progDesc[] = "A command line interface to KDE calendars";
68
69
70static KCmdLineOptions options[] =
71 {
72 { "dump",
73 I18N_NOOP( "Dumps calendar" ), 0 },
74 { "read",
75 I18N_NOOP( "Reads calendar" ), 0 },
76 KCmdLineLastOption
77 };
78
79int main( int argc, char *argv[] )
80{
81 KAboutData aboutData(
82 progName, // internal program name
83 I18N_NOOP( progDisplay ), // displayable program name.
84 progVersion, // version string
85 I18N_NOOP( progDesc ), // short porgram description
86 KAboutData::License_GPL, // license type
87 "(c) 2004, Lutz Rogowski", // copyright statement
88 0, // any free form text
89 "", // program home page address
90 "bugs.kde.org" // bug report email address
91 );
92
93
94 // KCmdLineArgs::init() final 'true' argument indicates no commandline options
95 // for QApplication/KApplication (no KDE or Qt options)
96 KCmdLineArgs::init( argc, argv, &aboutData, true );
97 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
98
99 KInstance ins ( progName );
100
101 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
102
103 bool read = false;
104 if ( args->isSet( "read" ) ) {
105 read = true;
106 qDebug("read ");
107 }
108 CalendarResources *calendarResource = 0;
109 CalendarLocal *localCalendar = 0;
110
111 calendarResource = new CalendarResources( "" );
112 calendarResource->readConfig();
113 calendarResource->load();
114 qDebug("************************************* ");
115 qDebug("************************************* ");
116 qDebug("************************************* ");
117 qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1());
118
119 if ( !read ) {
120 localCalendar = new CalendarLocal();
121 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
122 KCal::Incidence::List allInc = calendarResource->rawIncidences();
123 Incidence::List::ConstIterator it;
124 int num = 0;
125 for( it = allInc.begin(); it != allInc.end(); ++it ) {
126 ResourceCalendar * re = calendarResource->resource( (*it) );
127 if ( re && !re->readOnly() ) {
128 ++num;
129 Incidence* cl = (*it)->clone();
130 if ( cl->type() == "Journal" )
131 localCalendar->addJournal( (Journal *) cl );
132 else if ( cl->type() == "Todo" )
133 localCalendar->addTodo( (Todo *) cl );
134 else if ( cl->type() == "Event" )
135 localCalendar->addEvent( (Event *) cl );
136 }
137 }
138
139 FileStorage* storage = new FileStorage( calendarResource );
140 storage->setFileName( "/tmp/kdedumpall.ics" );
141 storage->setSaveFormat( new ICalFormat() );
142 storage->save();
143 delete storage;
144 qDebug("************************************* ");
145 qDebug("************************************* ");
146 qDebug("************************************* ");
147 qDebug("%d calendar entries dumped to file /tmp/kdedumpall.ics", num);
148
149 } else {
150 localCalendar = new CalendarLocal();
151 localCalendar->setTimeZoneId( calendarResource->timeZoneId());
152 FileStorage* storage = new FileStorage( localCalendar );
153 storage->setFileName( "/tmp/kdedumpall.ics" );
154 int num = 0;
155 int del = 0;
156 if ( storage->load() ) {
157 KCal::Incidence::List allInc = calendarResource->rawIncidences();
158 KCal::Incidence::List newInc = localCalendar->rawIncidences();
159 Incidence::List::ConstIterator it;
160 for( it = allInc.begin(); it != allInc.end(); ++it ) {
161 ResourceCalendar * re = calendarResource->resource( (*it) );
162 if ( re && !re->readOnly() ) {
163 Incidence* cl = localCalendar->incidence( (*it)->uid() );
164 if ( cl ) {
165 cl->setResources( (*it)->resources() );
166 }
167 ++del;
168 cl = (*it);
169 if ( cl->type() == "Journal" )
170 calendarResource->deleteJournal( (Journal *) cl );
171 else if ( cl->type() == "Todo" )
172 calendarResource->deleteTodo( (Todo *) cl );
173 else if ( cl->type() == "Event" )
174 calendarResource->deleteEvent( (Event *) cl );
175 }
176 }
177 for( it = newInc.begin(); it != newInc.end(); ++it ) {
178 Incidence* cl = (*it)->clone();
179 ++num;
180 calendarResource->addIncidence( cl );
181 }
182 calendarResource->save();
183 qDebug("************************************* ");
184 qDebug("************************************* ");
185 qDebug("************************************* ");
186 qDebug("%d calendar entries deleted/ %d added from file /tmp/kdedumpall.ics", del, num);
187
188 } else
189 qDebug("error loading file /tmp/kdedumpall.ics");
190
191 }
192
193 if ( localCalendar ) {
194 localCalendar->close();
195 delete localCalendar;
196 }
197 if ( calendarResource ) {
198 calendarResource->close();
199 delete calendarResource;
200 }
201
202 qDebug("ente ");
203 return 0;
204}