summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-16 20:24:23 (UTC)
committer zautrix <zautrix>2004-10-16 20:24:23 (UTC)
commit4bab2cac8beb6103b982bd2b42eeb7061a18a0d1 (patch) (side-by-side diff)
tree75c465dc882dbf8c90f6d3ac75b1c50c14793a45
parentc3325ebbb92a2814fcb622caaf71316cfa0c2908 (diff)
downloadkdepimpi-4bab2cac8beb6103b982bd2b42eeb7061a18a0d1.zip
kdepimpi-4bab2cac8beb6103b982bd2b42eeb7061a18a0d1.tar.gz
kdepimpi-4bab2cac8beb6103b982bd2b42eeb7061a18a0d1.tar.bz2
added a kdecal2file app
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 @@
+
+TEMPLATE = app
+CONFIG += qt
+include( ../../variables.pri )
+DESTDIR= ../../bin
+TARGET = kdecaldump
+INCLUDEPATH += . $(KDEDIR)/include $(KDEDIR)/include/libkcal /kde_dev/kde32/build/kdepim33_proko2_new/libkdepim
+
+LIBS += $(KDEDIR)/lib/libkcal.so
+LIBS += $(KDEDIR)/lib/libkdepim.so
+HEADERS +=
+
+SOURCES += 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 @@
+/*******************************************************************************
+ * main.cpp *
+ * *
+ *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software *
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ * *
+ * As a special exception, permission is given to link this program *
+ * with any edition of Qt, and distribute the resulting executable, *
+ * without including the source code for Qt in the source distribution. *
+ * *
+ ******************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <klocale.h>
+#include <kglobal.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+#include <libkcal/calformat.h>
+#include <libkcal/calendarresources.h>
+#include <libkcal/resourcelocal.h>
+#include <libkcal/filestorage.h>
+#include <libkcal/icalformat.h>
+
+#include <qdatetime.h>
+#include <qfile.h>
+
+#include <stdlib.h>
+#include <iostream>
+
+using namespace KCal;
+using namespace std;
+
+static const char progName[] = "kdecalendar";
+static const char progDisplay[] = "KDE_Calendar";
+static const char progVersion[] = "33.1/3";
+static const char progDesc[] = "A command line interface to KDE calendars";
+
+
+static KCmdLineOptions options[] =
+ {
+ { "dump",
+ I18N_NOOP( "Dumps calendar" ), 0 },
+ { "read",
+ I18N_NOOP( "Reads calendar" ), 0 },
+ KCmdLineLastOption
+ };
+
+int main( int argc, char *argv[] )
+{
+ KAboutData aboutData(
+ progName, // internal program name
+ I18N_NOOP( progDisplay ), // displayable program name.
+ progVersion, // version string
+ I18N_NOOP( progDesc ), // short porgram description
+ KAboutData::License_GPL, // license type
+ "(c) 2004, Lutz Rogowski", // copyright statement
+ 0, // any free form text
+ "", // program home page address
+ "bugs.kde.org" // bug report email address
+ );
+
+
+ // KCmdLineArgs::init() final 'true' argument indicates no commandline options
+ // for QApplication/KApplication (no KDE or Qt options)
+ KCmdLineArgs::init( argc, argv, &aboutData, true );
+ KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
+
+ KInstance ins ( progName );
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ bool read = false;
+ if ( args->isSet( "read" ) ) {
+ read = true;
+ qDebug("read ");
+ }
+ CalendarResources *calendarResource = 0;
+ CalendarLocal *localCalendar = 0;
+
+ calendarResource = new CalendarResources( "" );
+ calendarResource->readConfig();
+ calendarResource->load();
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("Using timezone id: %s", calendarResource->timeZoneId().latin1());
+
+ if ( !read ) {
+ localCalendar = new CalendarLocal();
+ localCalendar->setTimeZoneId( calendarResource->timeZoneId());
+ KCal::Incidence::List allInc = calendarResource->rawIncidences();
+ Incidence::List::ConstIterator it;
+ int num = 0;
+ for( it = allInc.begin(); it != allInc.end(); ++it ) {
+ ResourceCalendar * re = calendarResource->resource( (*it) );
+ if ( re && !re->readOnly() ) {
+ ++num;
+ Incidence* cl = (*it)->clone();
+ if ( cl->type() == "Journal" )
+ localCalendar->addJournal( (Journal *) cl );
+ else if ( cl->type() == "Todo" )
+ localCalendar->addTodo( (Todo *) cl );
+ else if ( cl->type() == "Event" )
+ localCalendar->addEvent( (Event *) cl );
+ }
+ }
+
+ FileStorage* storage = new FileStorage( calendarResource );
+ storage->setFileName( "/tmp/kdedumpall.ics" );
+ storage->setSaveFormat( new ICalFormat() );
+ storage->save();
+ delete storage;
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("%d calendar entries dumped to file /tmp/kdedumpall.ics", num);
+
+ } else {
+ localCalendar = new CalendarLocal();
+ localCalendar->setTimeZoneId( calendarResource->timeZoneId());
+ FileStorage* storage = new FileStorage( localCalendar );
+ storage->setFileName( "/tmp/kdedumpall.ics" );
+ int num = 0;
+ int del = 0;
+ if ( storage->load() ) {
+ KCal::Incidence::List allInc = calendarResource->rawIncidences();
+ KCal::Incidence::List newInc = localCalendar->rawIncidences();
+ Incidence::List::ConstIterator it;
+ for( it = allInc.begin(); it != allInc.end(); ++it ) {
+ ResourceCalendar * re = calendarResource->resource( (*it) );
+ if ( re && !re->readOnly() ) {
+ Incidence* cl = localCalendar->incidence( (*it)->uid() );
+ if ( cl ) {
+ cl->setResources( (*it)->resources() );
+ }
+ ++del;
+ cl = (*it);
+ if ( cl->type() == "Journal" )
+ calendarResource->deleteJournal( (Journal *) cl );
+ else if ( cl->type() == "Todo" )
+ calendarResource->deleteTodo( (Todo *) cl );
+ else if ( cl->type() == "Event" )
+ calendarResource->deleteEvent( (Event *) cl );
+ }
+ }
+ for( it = newInc.begin(); it != newInc.end(); ++it ) {
+ Incidence* cl = (*it)->clone();
+ ++num;
+ calendarResource->addIncidence( cl );
+ }
+ calendarResource->save();
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("************************************* ");
+ qDebug("%d calendar entries deleted/ %d added from file /tmp/kdedumpall.ics", del, num);
+
+ } else
+ qDebug("error loading file /tmp/kdedumpall.ics");
+
+ }
+
+ if ( localCalendar ) {
+ localCalendar->close();
+ delete localCalendar;
+ }
+ if ( calendarResource ) {
+ calendarResource->close();
+ delete calendarResource;
+ }
+
+ qDebug("ente ");
+ return 0;
+}