00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "calendarlocal.h"
00023
#include "icalformat.h"
00024
#include "qtopiaformat.h"
00025
00026
#include <kaboutdata.h>
00027
#include <kapplication.h>
00028
#include <kdebug.h>
00029
#include <klocale.h>
00030
#include <kcmdlineargs.h>
00031
#include <kglobal.h>
00032
#include <kconfig.h>
00033
#include <kstandarddirs.h>
00034
00035
#include <iostream>
00036
00037
using namespace KCal;
00038
00039
static const KCmdLineOptions options[] =
00040 {
00041 {
"q", 0, 0 },
00042 {
"qtopia2icalendar", I18N_NOOP(
"Convert Qtopia calendar file to iCalendar"), 0 },
00043 {
"i", 0, 0 },
00044 {
"icalendar2qtopia", I18N_NOOP(
"Convert iCalendar to iCalendar"), 0 },
00045 {
"o", 0, 0},
00046 {
"output <file>", I18N_NOOP(
"Output file"), 0 },
00047 {
"+input", I18N_NOOP(
"Input file"), 0 },
00048 KCmdLineLastOption
00049 };
00050
00051
int main(
int argc,
char **argv)
00052 {
00053 KAboutData aboutData(
"convertqtopia",I18N_NOOP(
"Qtopia calendar file converter"),
"0.1");
00054 aboutData.addAuthor(
"Cornelius Schumacher", 0,
"schumacher@kde.org");
00055
00056 KCmdLineArgs::init(argc,argv,&aboutData);
00057 KCmdLineArgs::addCmdLineOptions( options );
00058
00059 KApplication app;
00060
00061 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00062
00063
bool sourceQtopia =
false;
00064
bool sourceIcalendar =
false;
00065
00066
if ( args->isSet(
"qtopia2icalendar" ) ) {
00067 sourceQtopia =
true;
00068 }
00069
00070
if ( args->isSet(
"icalendar2qtopia" ) ) {
00071 sourceIcalendar =
true;
00072 }
00073
00074
if ( sourceQtopia && sourceIcalendar ) {
00075 KCmdLineArgs::usage(
00076 i18n(
"Please specify only one of the conversion options.") );
00077 }
00078
if ( !sourceQtopia && !sourceIcalendar ) {
00079 KCmdLineArgs::usage(
00080 i18n(
"You have to specify one conversion option.") );
00081 }
00082
00083
if ( args->count() != 1 ) {
00084 KCmdLineArgs::usage( i18n(
"Error: No input file.") );
00085 }
00086
00087
QString inputFile = args->arg( 0 );
00088
00089
QString outputFile;
00090
if ( args->isSet(
"output") ) outputFile = args->getOption(
"output" );
00091
00092 kdDebug(5800) <<
"Input File: '" << inputFile <<
"'" << endl;
00093 kdDebug(5800) <<
"Output File: '" << outputFile <<
"'" << endl;
00094
00095
if ( sourceQtopia ) {
00096
CalendarLocal cal;
00097
00098
QtopiaFormat qtopiaFormat;
00099 qtopiaFormat.
load( &cal, inputFile );
00100
00101
ICalFormat icalendarFormat;
00102
if ( outputFile.isEmpty() ) {
00103
QString out = icalendarFormat.
toString( &cal );
00104 std::cout << out.local8Bit() << std::endl;
00105 }
else {
00106
bool success = icalendarFormat.
save( &cal, outputFile );
00107
if ( !success ) {
00108 std::cerr << i18n(
"Error saving to '%1'." ).arg( outputFile ).local8Bit()
00109 << std::endl;
00110
return 1;
00111 }
00112 }
00113 }
00114
00115
if ( sourceIcalendar ) {
00116 std::cerr <<
"Not implemented yet." << std::endl;
00117
return 1;
00118 }
00119 }