konsolekalendar Library API Documentation

main.cpp

00001 /***************************************************************************
00002                           main.cpp  -  description
00003                              -------------------
00004     begin                : Sun Jan  6 11:50:14 EET 2002
00005     copyright            : (C) 2002 by Tuukka Pasanen
00006     email                : illuusio@mailcity.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <kcmdlineargs.h>
00019 #include <kaboutdata.h>
00020 #include <klocale.h>
00021 #include <kglobal.h>
00022 #include <kconfig.h>
00023 #include <kstandarddirs.h>
00024 #include <kdebug.h>
00025 
00026 #include <qdatetime.h>
00027 
00028 #include <stdlib.h>
00029 #include <iostream>
00030 
00031 #include "konsolekalendar.h"
00032 
00033 using namespace KCal;
00034 using namespace std;
00035 
00036 static const char *description = I18N_NOOP("KonsoleKalendar");
00037         
00038 static KCmdLineOptions options[] =
00039 {
00040   { "help", I18N_NOOP("Prints this help"), 0 },
00041   { "verbose", I18N_NOOP("Output helpful (?) debug info"), 0 },
00042   { "file <calendarfile>", I18N_NOOP("Specify which calendar you want to use."), 0 },
00043   { "next", I18N_NOOP("Next activity in calendar"), 0 },
00044   { "date <date>", I18N_NOOP("Show day info"), 0 },
00045   { "startdate <startdate>", I18N_NOOP("From this day"), 0 },
00046   { "enddate <enddate>", I18N_NOOP("To this day"), 0 },
00047   { "all", I18N_NOOP("Show all entries"), 0 },
00048   { "date", I18N_NOOP("Date for which the calendar is shown."), 0},
00049   { "startdate", I18N_NOOP("Starting date."), 0},
00050   { "enddate", I18N_NOOP("Ending date."), 0},
00051   { "file", I18N_NOOP("Location of your calendar file."), 0}
00052 };
00053 
00054 int main(int argc, char *argv[])
00055 {
00056   KAboutData aboutData( "konsolekalendar", I18N_NOOP( "KonsoleKalendar" ),
00057                         "0.1", description, KAboutData::License_GPL,
00058                         "(c) 2002, Tuukka Pasanen", 0, 0,
00059                         "illuusio@mailcity.com");
00060   aboutData.addAuthor("Tuukka Pasanen",0, "illuusio@mailcity.com");
00061 
00062   KCmdLineArgs::init( argc, argv, &aboutData );
00063   KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
00064 
00065   KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00066 
00067   QString KalendarFile;
00068   QDate date;
00069   QString option;
00070 
00071   KApplication app( false, false );
00072         
00073   KalendarVariables variables;
00074 
00075   if ( args->isSet("verbose") ){
00076      variables.setVerbose(true);
00077   }
00078 
00079   /*
00080    *  Show next happening and exit
00081    *
00082    */
00083   if ( args->isSet("next") ) {
00084     if(variables.isVerbose()) {
00085       kdDebug() << "main.cpp::int main(int argc, char *argv[]) | Show next happening in calendar and exit" << endl;
00086     }
00087     variables.setNext(true);
00088   }
00089 
00090   /*
00091    *  If we like to see some date
00092    *
00093    */
00094   if ( args->isSet("date") ) {
00095     option = args->getOption("date");
00096     if(variables.isVerbose()) {
00097       kdDebug() << "main.cpp::int main(int argc, char *argv[]) | Show date info and exit: (" << option << ")" << endl;             
00098     }
00099 
00100     date = variables.parseDate(option);
00101 
00102     variables.setDate(date);
00103   } else {
00104     variables.setDate(QDate::currentDate());
00105   }
00106 
00107   /*
00108    *  Set starting date for calendar
00109    *
00110    */
00111   if ( args->isSet("startdate") ) {
00112     option = args->getOption("startdate");
00113     if(variables.isVerbose()){
00114       kdDebug() << "main.cpp::int main(int argc, char *argv[]) | Shows all entries from this date 30 days or to enddate: (" << option << ")" << endl;              
00115     }
00116 
00117     date = variables.parseDate(option);
00118         
00119     variables.setStartDate(date);
00120   }
00121 
00122   /*
00123    *  Set starting end date for calendar
00124    *
00125    */
00126   if ( args->isSet("enddate") ) {
00127     QString option = args->getOption("enddate");
00128     if(variables.isVerbose()) {
00129       kdDebug() << "main.cpp::int main(int argc, char *argv[]) | Shows all entries to this date: (" << option << ")" << endl;              
00130     }
00131 
00132     date = variables.parseDate(option);
00133 
00134     variables.setEndDate(date);
00135   }
00136 
00137   if( args->isSet("all") ) {
00138     variables.setAll( true );
00139   } else {
00140     variables.setAll( false );
00141   }
00142 
00143   if ( args->isSet("file") ) {
00144     option = args->getOption("file");
00145     variables.setCalendarFile(option);
00146 
00147     if(variables.isVerbose()){
00148       kdDebug() << "main.cpp::int main(int argc, char *argv[]) | using calendar at: (" << variables.getCalendarFile() << ")" << endl;              
00149     }    
00150   } else {
00151     KConfig cfg( locate( "config", "korganizerrc" ) );
00152 
00153     cfg.setGroup("General");
00154     KURL url( cfg.readEntry("Active Calendar") );
00155     if ( url.isLocalFile() ) {
00156       KalendarFile = url.path();
00157     
00158       variables.setCalendarFile(KalendarFile);
00159         
00160       if(variables.isVerbose()){
00161         cout << "main.cpp::int main(int argc, char *argv[]) | Calendar file currently is " << variables.getCalendarFile() << endl;
00162       }
00163     } else {
00164       cout << i18n("Remote files are not supported yet.") << endl;
00165     }
00166   }
00167 
00168   args->clear(); // Free up some memory.
00169 
00170   //variables->setCalendarFile(KalendarFile);
00171         
00172   KonsoleKalendar *konsolekalendar = new KonsoleKalendar(variables);
00173   konsolekalendar->showInstance();
00174 
00175   delete konsolekalendar;
00176 
00177   if(variables.isVerbose()){
00178     kdDebug() << "main.cpp::int main(int argc, char *argv[]) | exiting" << endl;
00179   }
00180 
00181   return 0;
00182 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:19 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001