libkcal

convertqtopia.cpp
1 /*
2  This file is part of libkcal.
3 
4  Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library 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 GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "calendarlocal.h"
23 #include "icalformat.h"
24 #include "qtopiaformat.h"
25 
26 #include <tdeaboutdata.h>
27 #include <tdeapplication.h>
28 #include <kdebug.h>
29 #include <tdelocale.h>
30 #include <tdecmdlineargs.h>
31 #include <tdeglobal.h>
32 #include <tdeconfig.h>
33 #include <kstandarddirs.h>
34 
35 #include <iostream>
36 
37 using namespace KCal;
38 
39 static const TDECmdLineOptions options[] =
40 {
41  {"q", 0, 0 },
42  {"qtopia2icalendar", I18N_NOOP("Convert TQtopia calendar file to iCalendar"), 0 },
43  {"i", 0, 0 },
44  {"icalendar2qtopia", I18N_NOOP("Convert iCalendar to iCalendar"), 0 },
45  {"o", 0, 0},
46  {"output <file>", I18N_NOOP("Output file"), 0 },
47  {"+input", I18N_NOOP("Input file"), 0 },
48  TDECmdLineLastOption
49 };
50 
51 int main(int argc,char **argv)
52 {
53  TDEAboutData aboutData("convertqtopia",I18N_NOOP("TQtopia calendar file converter"),"0.1");
54  aboutData.addAuthor("Cornelius Schumacher", 0, "schumacher@kde.org");
55 
56  TDECmdLineArgs::init(argc,argv,&aboutData);
57  TDECmdLineArgs::addCmdLineOptions( options );
58 
59  TDEApplication app;
60 
61  TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
62 
63  bool sourceTQtopia = false;
64  bool sourceIcalendar = false;
65 
66  if ( args->isSet( "qtopia2icalendar" ) ) {
67  sourceTQtopia = true;
68  }
69 
70  if ( args->isSet( "icalendar2qtopia" ) ) {
71  sourceIcalendar = true;
72  }
73 
74  if ( sourceTQtopia && sourceIcalendar ) {
75  TDECmdLineArgs::usage(
76  i18n("Please specify only one of the conversion options.") );
77  }
78  if ( !sourceTQtopia && !sourceIcalendar ) {
79  TDECmdLineArgs::usage(
80  i18n("You have to specify one conversion option.") );
81  }
82 
83  if ( args->count() != 1 ) {
84  TDECmdLineArgs::usage( i18n("Error: No input file.") );
85  }
86 
87  TQString inputFile = args->arg( 0 );
88 
89  TQString outputFile;
90  if ( args->isSet("output") ) outputFile = args->getOption( "output" );
91 
92  kdDebug(5800) << "Input File: '" << inputFile << "'" << endl;
93  kdDebug(5800) << "Output File: '" << outputFile << "'" << endl;
94 
95  if ( sourceTQtopia ) {
96  CalendarLocal cal;
97 
98  TQtopiaFormat qtopiaFormat;
99  qtopiaFormat.load( &cal, inputFile );
100 
101  ICalFormat icalendarFormat;
102  if ( outputFile.isEmpty() ) {
103  TQString out = icalendarFormat.toString( &cal );
104  std::cout << out.local8Bit() << std::endl;
105  } else {
106  bool success = icalendarFormat.save( &cal, outputFile );
107  if ( !success ) {
108  std::cerr << i18n( "Error saving to '%1'." ).arg( outputFile ).local8Bit()
109  << std::endl;
110  return 1;
111  }
112  }
113  }
114 
115  if ( sourceIcalendar ) {
116  std::cerr << "Not implemented yet." << std::endl;
117  return 1;
118  }
119 }
This class provides a calendar stored as a local file.
Definition: calendarlocal.h:37
This class implements the iCalendar format.
Definition: icalformat.h:44
bool save(Calendar *calendar, const TQString &fileName)
Writes out the calendar to disk in iCalendar format.
Definition: icalformat.cpp:102
TQString toString(Calendar *)
Return calendar information as string.
Definition: icalformat.cpp:225
This class implements the calendar format used by TQtopia.
Definition: qtopiaformat.h:37
bool load(Calendar *, const TQString &fileName)
loads a calendar on disk into the calendar associated with this format.
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition: alarm.h:38