00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 );
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
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
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
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
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();
00169
00170
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 }