libkcal Library API Documentation

convertqtopia.cpp

00001 /* 00002 This file is part of libkcal. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 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 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:42 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003