00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include "config.h"
00030 #endif
00031
00032 #if TIME_WITH_SYS_TIME
00033 # include <sys/time.h>
00034 # include <time.h>
00035 #else
00036 # if HAVE_SYS_TIME_H
00037 # include <sys/time.h>
00038 # else
00039 # include <time.h>
00040 # endif
00041 #endif
00042
00043 #include <kcmdlineargs.h>
00044 #include <kaboutdata.h>
00045 #include <klocale.h>
00046 #include <kglobal.h>
00047 #include <kconfig.h>
00048 #include <kstandarddirs.h>
00049 #include <kdebug.h>
00050
00051 #include <libkcal/calformat.h>
00052 #include <libkcal/calendarresources.h>
00053 #include <libkcal/resourcelocal.h>
00054
00055 #include <qdatetime.h>
00056 #include <qfile.h>
00057
00058 #include <stdlib.h>
00059 #include <iostream>
00060
00061 #include "konsolekalendar.h"
00062 #include "konsolekalendarepoch.h"
00063
00064 #include "konsolekalendarvariables.h"
00065
00066 using namespace KCal;
00067 using namespace std;
00068
00069 static const char progName[] = "konsolekalendar";
00070 static const char progDisplay[] = "KonsoleKalendar";
00071 static const char progVersion[] = "1.2.0";
00072 static const char progDesc[] = "A command line interface to KDE calendars";
00073 static const char progURL[] = "pim.kde.org/components/konsolekalendar.php";
00074
00075
00076 static KCmdLineOptions options[] =
00077 {
00078 { "help",
00079 I18N_NOOP( "Print this help and exit" ), 0 },
00080 { "verbose",
00081 I18N_NOOP( "Print helpful runtime messages" ), 0 },
00082 { "dry-run",
00083 I18N_NOOP( "Print what would have been done, but do not execute" ), 0 },
00084 { "file <calendar-file>",
00085 I18N_NOOP( "Specify which calendar you want to use" ), 0 },
00086
00087 { ":",
00088 I18N_NOOP( "Major operation modes:" ), 0 },
00089 { "view",
00090 I18N_NOOP( " Print calendar events in specified export format" ), 0 },
00091 { "add",
00092 I18N_NOOP( " Insert an event into the calendar" ), 0 },
00093 { "change",
00094 I18N_NOOP( " Modify an existing calendar event" ), 0 },
00095 { "delete",
00096 I18N_NOOP( " Remove an existing calendar event" ), 0 },
00097 { "create",
00098 I18N_NOOP( " Create new calendar file if one does not exist" ), 0 },
00099 { "import <import-file>",
00100 I18N_NOOP( " Import this calendar to main calendar" ), 0 },
00101
00102 { ":",
00103 I18N_NOOP( "Operation modifiers:" ), 0 },
00104 { "all",
00105 I18N_NOOP( " View all calendar entries" ), 0 },
00106 { "next",
00107 I18N_NOOP( " View next activity in calendar" ), 0 },
00108 { "show-next <days>",
00109 I18N_NOOP( " From start date show next # days' activities" ), 0 },
00110 { "uid <uid>",
00111 I18N_NOOP( " Event Unique-string identifier" ), 0 },
00112 { "date <start-date>",
00113 I18N_NOOP( " Start from this day [YYYY-MM-DD]" ), 0 },
00114 { "time <start-time>",
00115 I18N_NOOP( " Start from this time [HH:MM:SS]" ), 0 },
00116 { "end-date <end-date>",
00117 I18N_NOOP( " End at this day [YYYY-MM-DD]" ), 0 },
00118 { "end-time <end-time>",
00119 I18N_NOOP( " End at this time [HH:MM:SS]" ), 0 },
00120 { "epoch-start <epoch-time>",
00121 I18N_NOOP( " Start from this time [secs since epoch]" ), 0 },
00122 { "epoch-end <epoch-time>",
00123 I18N_NOOP( " End at this time [secs since epoch]" ), 0 },
00124 { "summary <summary>",
00125 I18N_NOOP( " Add summary to event (for add/change modes)" ), 0 },
00126 { "description <description>",
00127 I18N_NOOP( "Add description to event (for add/change modes)" ), 0 },
00128 { "location <location>",
00129 I18N_NOOP( " Add location to event (for add/change modes)" ), 0 },
00130
00131 { ":", I18N_NOOP( "Export options:" ), 0 },
00132 { "export-type <export-type>",
00133 I18N_NOOP( "Export file type (Default: text)" ), 0 },
00134 { "export-file <export-file>",
00135 I18N_NOOP( "Export to file (Default: stdout)" ), 0 },
00136 { "export-list",
00137 I18N_NOOP( " Print list of export types supported and exit" ), 0 },
00138
00139 { "",
00140 I18N_NOOP( "Examples:\n"
00141 " konsolekalendar --view\n"
00142 " konsolekalendar --add --date 2003-06-04 "
00143 "--time 10:00 --end-time 12:00 \\\n"
00144 " --summary \"Doctor Visit\" "
00145 "--description \"Get My Head Examined\"\n"
00146 " konsolekalendar --delete --uid KOrganizer-1740326.803" ), 0 },
00147
00148 { "",
00149 I18N_NOOP( "For more information visit the program home page at:\n"
00150 " http://pim.kde.org/components/konsolekalendar.php" ), 0 },
00151
00152 KCmdLineLastOption
00153 };
00154
00155 int main( int argc, char *argv[] )
00156 {
00157 KAboutData aboutData(
00158 progName,
00159 I18N_NOOP( progDisplay ),
00160 progVersion,
00161 I18N_NOOP( progDesc ),
00162 KAboutData::License_GPL,
00163 "(c) 2002-2004, Tuukka Pasanen and Allen Winter",
00164 0,
00165 progURL,
00166 "bugs.kde.org"
00167 );
00168
00169 aboutData.addAuthor(
00170 "Tuukka Pasanen",
00171 I18N_NOOP( "Primary Author" ),
00172 "illuusio@mailcity.com",
00173 0
00174 );
00175 aboutData.addAuthor(
00176 "Allen Winter",
00177 I18N_NOOP( "Author" ),
00178 "awinterz@users.sourceforge.net",
00179 0
00180 );
00181
00182
00183
00184
00185
00186 KCmdLineArgs::init( argc, argv, &aboutData, true );
00187 KCmdLineArgs::addCmdLineOptions( options );
00188
00189 KInstance ins( progName );
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00201
00202
00203 QDate startdate = QDate::currentDate();
00204 QTime starttime( 7 ,0 );
00205
00206
00207 QDate enddate = QDate::currentDate();
00208 QTime endtime( 17, 0 );
00209
00210
00211 bool view = true;
00212 bool add = false;
00213 bool change = false;
00214 bool del = false;
00215 bool create = false;
00216 bool calendarFile = false;
00217 bool importFile = false;
00218
00219 QString option;
00220
00221 KonsoleKalendarVariables variables;
00222 KonsoleKalendarEpoch epochs;
00223
00224 variables.setExportType( NONE );
00225 variables.setFloating( false );
00226
00227 if ( args->isSet( "verbose" ) ) {
00228 variables.setVerbose( true );
00229 }
00230
00231 if ( args->isSet( "dry-run" ) ) {
00232 variables.setDryRun( true );
00233 }
00234
00235
00236
00237
00238
00239 if ( args->isSet( "export-list" ) ) {
00240 cout << i18n(
00241 "\nKonsoleKalendar supports these export formats:\n"
00242 " Text [Default]\n"
00243 " Short (like Text, but more compact)\n"
00244 " HTML\n"
00245 " CSV (Comma-Separated Values)\n"
00246 ).local8Bit()
00247 << endl;
00248 return 0;
00249 }
00250
00251
00252
00253
00254
00255 if ( args->isSet( "export-type" ) ) {
00256 option = args->getOption( "export-type" );
00257
00258 if ( option.upper() == "HTML" ) {
00259 kdDebug() << "main | export-type | Export to HTML" << endl;
00260 variables.setExportType( HTML );
00261 } else if ( option.upper() == "CSV" ) {
00262 kdDebug() << "main | export-type | Export to CSV" << endl;
00263 variables.setExportType( CSV );
00264 } else if ( option.upper() == "TEXT" ) {
00265 kdDebug() << "main | export-type | Export to TEXT (default)" << endl;
00266 variables.setExportType( TEXT_KONSOLEKALENDAR );
00267 } else if ( option.upper() == "SHORT" ) {
00268 kdDebug() << "main | export-type | Export to TEXT-SHORT" << endl;
00269 variables.setExportType( TEXT_SHORT );
00270 } else {
00271 cout << i18n( "Invalid Export Type Specified: %1" ).
00272 arg( option ).local8Bit()
00273 << endl;
00274 return 1;
00275 }
00276 }
00277
00278
00279
00280
00281
00282 if ( args->isSet( "export-file" ) ) {
00283 option = args->getOption( "export-file" );
00284
00285 kdDebug() << "main | parse options | "
00286 << "Export File: "
00287 << "(" << option << ")"
00288 << endl;
00289
00290 variables.setExportFile( option );
00291 }
00292
00293
00294
00295
00296
00297 if ( args->isSet( "view" ) ) {
00298 view=true;
00299
00300 kdDebug() << "main | parse options | "
00301 << "Mode: (Print events)"
00302 << endl;
00303 }
00304
00305
00306
00307
00308
00309 if ( args->isSet( "add" ) ) {
00310 view=false;
00311 add=true;
00312
00313 kdDebug() << "main | parse options | "
00314 << "Mode: (Add event)"
00315 << endl;
00316 }
00317
00318
00319
00320
00321
00322 if ( args->isSet( "change" ) ) {
00323 view=false;
00324 change=true;
00325
00326 kdDebug() << "main | parse options | "
00327 << "Mode: (Change event)"
00328 << endl;
00329 }
00330
00331
00332
00333
00334
00335 if ( args->isSet( "delete" ) ) {
00336 view=false;
00337 del=true;
00338
00339 kdDebug() << "main | parse options | "
00340 << "Mode: (Delete event)"
00341 << endl;
00342 }
00343
00344
00345
00346
00347
00348 if ( args->isSet( "create" ) ) {
00349 view=false;
00350 create=true;
00351
00352 kdDebug() << "main | parse options | "
00353 << "Calendar File: (Create)"
00354 << endl;
00355 }
00356
00357
00358
00359
00360
00361
00362 if ( args->isSet( "summary" ) ) {
00363 option = args->getOption( "summary" );
00364
00365 kdDebug() << "main | parse options | "
00366 << "Summary: "
00367 << "(" << option << ")"
00368 << endl;
00369
00370 variables.setSummary( option );
00371 }
00372
00373
00374
00375
00376
00377 if ( args->isSet( "description" ) ) {
00378 option = args->getOption( "description" );
00379
00380 kdDebug() << "main | parse options | "
00381 << "Description: "
00382 << "(" << option << ")"
00383 << endl;
00384
00385 variables.setDescription( option );
00386 }
00387
00388
00389
00390
00391
00392 if ( args->isSet( "location" ) ) {
00393 option = args->getOption( "location" );
00394
00395 kdDebug() << "main | parse options | "
00396 << "Location: "
00397 << "(" << option << ")"
00398 << endl;
00399
00400 variables.setLocation( option );
00401 }
00402
00403
00404
00405
00406
00407 if ( args->isSet( "next" ) )
00408 {
00409 kdDebug() << "main | parse options | "
00410 << "Show next event only"
00411 << endl;
00412
00413 variables.setNext( true );
00414 }
00415
00416
00417
00418
00419
00420
00421 if (args->isSet( "uid" ) ) {
00422 option = args->getOption( "uid" );
00423
00424 kdDebug() << "main | parse options | "
00425 << "Event UID: "
00426 << "(" << option << ")"
00427 << endl;
00428
00429 variables.setUID( option );
00430 }
00431
00432
00433
00434
00435
00436 if ( args->isSet( "date" ) ) {
00437 option = args->getOption( "date" );
00438
00439 kdDebug() << "main | parse options | "
00440 << "Start date before conversion: "
00441 << "(" << option << ")"
00442 << endl;
00443
00444 startdate = QDate::fromString( option, Qt::ISODate );
00445 if ( ! startdate.isValid() ) {
00446 cout << i18n( "Invalid Start Date Specified: %1" ).
00447 arg( option ).local8Bit()
00448 << endl;
00449 return 1;
00450 }
00451 kdDebug() << "main | parse options | "
00452 << "Start date after conversion: "
00453 << "(" << startdate.toString() << ")"
00454 << endl;
00455 }
00456
00457
00458
00459
00460
00461 if ( args->isSet( "time" ) ) {
00462 option = args->getOption( "time" );
00463
00464 kdDebug() << "main | parse options | "
00465 << "Start time before conversion : "
00466 << "(" << option << ")"
00467 << endl;
00468
00469 if ( option.upper() != "FLOAT" ) {
00470 starttime = QTime::fromString( option, Qt::ISODate );
00471 if ( ! starttime.isValid() ) {
00472 cout << i18n( "Invalid Start Time Specified: %1" ).
00473 arg( option ).local8Bit()
00474 << endl;
00475 return 1;
00476 }
00477 kdDebug() << "main | parse options | "
00478 << "Start time after conversion: "
00479 << "(" << starttime.toString() << ")"
00480 << endl;
00481 } else {
00482 variables.setFloating( true );
00483 kdDebug() << "main | parse options | "
00484 << "Floating event time specified"
00485 << endl;
00486 }
00487 }
00488
00489
00490
00491
00492
00493 if ( args->isSet( "end-date" ) ) {
00494 QString option = args->getOption( "end-date" );
00495
00496 kdDebug() << "main | parse options | "
00497 << "End date before conversion: "
00498 << "(" << option << ")"
00499 << endl;
00500
00501 enddate = QDate::fromString( option, Qt::ISODate );
00502 if ( ! enddate.isValid() ) {
00503 cout << i18n( "Invalid End Date Specified: %1" ).
00504 arg( option ).local8Bit()
00505 << endl;
00506 return 1;
00507 }
00508 kdDebug() << "main | parse options | "
00509 << "End date after conversion: "
00510 << "(" << enddate.toString() << ")"
00511 << endl;
00512 }
00513
00514
00515
00516
00517
00518 if ( args->isSet( "show-next" ) )
00519 {
00520 bool ok;
00521
00522 option = args->getOption( "show-next" );
00523 kdDebug() << "main | parse options | "
00524 << "Show " << option << " days ahead"
00525 << endl;
00526 variables.setDaysCount( option.toInt( &ok, 10 ) );
00527
00528 if ( ! ok ) {
00529 cout << i18n( "Invalid Date Count Specified: %1" ).
00530 arg( option ).local8Bit()
00531 << endl;
00532 return 1;
00533 }
00534
00535 enddate = startdate;
00536 enddate = enddate.addDays( variables.getDaysCount() );
00537 kdDebug() << "main | parse options | "
00538 << "End date after conversion: "
00539 << "(" << enddate.toString() << ")"
00540 << endl;
00541 }
00542
00543
00544
00545
00546
00547 if ( args->isSet( "end-time" ) ) {
00548 option = args->getOption( "end-time" );
00549
00550 kdDebug() << "main | parse options | "
00551 << "End time before conversion: "
00552 << "(" << option << ")"
00553 << endl;
00554
00555 if ( option.upper() != "FLOAT" ) {
00556 endtime = QTime::fromString( option, Qt::ISODate );
00557 if ( ! endtime.isValid() ) {
00558 cout << i18n( "Invalid End Time Specified: %1" ).
00559 arg( option ).local8Bit()
00560 << endl;
00561 return 1;
00562 }
00563
00564 kdDebug() << "main | parse options | "
00565 << "End time after conversion: "
00566 << "(" << endtime.toString() << ")"
00567 << endl;
00568 } else {
00569 variables.setFloating( true );
00570 kdDebug() << "main | parse options | "
00571 << "Floating event time specified"
00572 << endl;
00573 }
00574 }
00575
00576
00577
00578
00579
00580 time_t epochstart=0;
00581 if ( args->isSet( "epoch-start" ) ) {
00582 option = args->getOption( "epoch-start" );
00583
00584 kdDebug() << "main | parse options | "
00585 << "Epoch start: "
00586 << "(" << option << ")"
00587 << endl;
00588
00589 epochstart = (time_t) option.toULong( 0, 10 );
00590 }
00591
00592
00593
00594
00595
00596 time_t epochend=0;
00597 if ( args->isSet( "epoch-end" ) ) {
00598 option = args->getOption( "epoch-end" );
00599
00600 kdDebug() << "main | parse options | "
00601 << "Epoch end: "
00602 << "(" << option << ")"
00603 << endl;
00604
00605 epochend = (time_t) option.toULong( 0, 10 );
00606 }
00607
00608 if ( args->isSet( "all" ) ) {
00609 variables.setAll( true );
00610 } else {
00611 variables.setAll( false );
00612 }
00613
00614 if ( args->isSet( "import" ) ) {
00615 view = false;
00616 importFile = true;
00617 option = args->getOption( "import" );
00618 variables.setImportFile( option );
00619
00620 kdDebug() << "main | parse options | "
00621 << "importing file from: "
00622 << "(" << option << ")"
00623 << endl;
00624 }
00625
00626 KonsoleKalendar *konsolekalendar = new KonsoleKalendar( &variables );
00627
00628 if ( args->isSet( "file" ) ) {
00629 calendarFile = true;
00630 option = args->getOption( "file" );
00631 variables.setCalendarFile( option );
00632
00633
00634
00635
00636
00637 bool exists = QFile::exists( variables.getCalendarFile() );
00638
00639 if ( create ) {
00640
00641 kdDebug() << "main | createcalendar | "
00642 << "check if calendar file already exists"
00643 << endl;
00644
00645 if ( exists ) {
00646 cout << i18n( "Calendar %1 already exists" ).
00647 arg( variables.getCalendarFile() ).local8Bit()
00648 << endl;
00649 return 1;
00650 }
00651 if ( konsolekalendar->createCalendar() ) {
00652 cout << i18n( "Calendar %1 successfully created" ).
00653 arg( variables.getCalendarFile() ).local8Bit()
00654 << endl;
00655 return 0;
00656 } else {
00657 cout << i18n( "Unable to create calendar: %1" ).
00658 arg( variables.getCalendarFile() ).local8Bit()
00659 << endl;
00660 return 1;
00661 }
00662 }
00663
00664 if ( ! exists ) {
00665 cout << i18n( "Calendar file not found %1" ).
00666 arg( option ).local8Bit()
00667 << endl;
00668 cout << i18n( "Try --create to create new calendar file" ).local8Bit()
00669 << endl;
00670 return 1;
00671 }
00672 }
00673
00674 CalendarResources *calendarResource = NULL;
00675 CalendarLocal *localCalendar = NULL;
00676
00677
00678
00679
00680 variables.setTimeZoneId();
00681 if ( args->isSet( "file" ) ) {
00682 localCalendar = new CalendarLocal( variables.getTimeZoneId() );
00683 localCalendar->load( variables.getCalendarFile() );
00684 variables.setCalendar( localCalendar );
00685 } else {
00686 calendarResource = new CalendarResources( variables.getTimeZoneId() );
00687 calendarResource->readConfig();
00688 calendarResource->load();
00689 variables.setCalendarResources( calendarResource );
00690 }
00691
00692
00693
00694
00695 QDateTime startdatetime, enddatetime;
00696
00697
00698 if ( ! args->isSet( "end-date" ) && ! args->isSet( "show-next" ) &&
00699 args->isSet( "date" ) ) {
00700 enddate = startdate;
00701 kdDebug() << "main | datetimestamp | "
00702 << "setting enddate to startdate"
00703 << endl;
00704 } else if ( args->isSet( "end-date" ) && ! args->isSet( "date" ) ) {
00705 startdate = enddate;
00706 kdDebug() << "main | datetimestamp | "
00707 << "setting startdate to enddate"
00708 << endl;
00709 }
00710
00711
00712
00713
00714
00715
00716 if ( ! args->isSet( "end-time" ) && ! args->isSet( "epoch-end" ) ) {
00717 if ( args->isSet( "time" ) ) {
00718 endtime = starttime.addSecs( 60*60 );
00719 kdDebug() << "main | datetimestamp | "
00720 << "setting endtime 1 hour after starttime"
00721 << endl;
00722 } else if ( args->isSet( "epoch-start" ) ) {
00723 startdatetime = epochs.epoch2QDateTime( epochstart );
00724 enddatetime = startdatetime.addSecs( 60*60 );
00725 kdDebug() << "main | datetimestamp | "
00726 << "setting endtime 1 hour after epochstart"
00727 << endl;
00728 }
00729 }
00730
00731
00732
00733
00734 if ( ! args->isSet( "time" ) && ! args->isSet( "epoch-start" ) ) {
00735 if ( args->isSet( "end-time" ) ) {
00736 starttime = endtime.addSecs( -60*60 );
00737 kdDebug() << "main | datetimestamp | "
00738 << "setting starttime 1 hour before endtime"
00739 << endl;
00740 } else if ( args->isSet( "epoch-end" ) ) {
00741 enddatetime = epochs.epoch2QDateTime( epochend );
00742 startdatetime = enddatetime.addSecs( -60*60 );
00743 kdDebug() << "main | datetimestamp | "
00744 << "setting starttime 1 before after epochend"
00745 << endl;
00746 }
00747 }
00748
00749
00750
00751 if ( ! args->isSet( "time" ) && ! args->isSet( "epoch-start" ) &&
00752 ! args->isSet( "end-time" ) && ! args->isSet( "epoch-end" ) ) {
00753
00754 startdatetime = QDateTime::QDateTime( startdate, starttime );
00755 kdDebug() << "main | datetimestamp | "
00756 << "setting startdatetime from "
00757 << "default startdate (today) and starttime"
00758 << endl;
00759
00760 enddatetime = QDateTime::QDateTime( enddate, endtime );
00761 kdDebug() << "main | datetimestamp | "
00762 << "setting enddatetime from "
00763 << "default enddate (today) and endtime"
00764 << endl;
00765 }
00766
00767
00768 if ( startdatetime.isNull() ) {
00769 startdatetime = QDateTime::QDateTime( startdate, starttime );
00770 kdDebug() << "main | datetimestamp | "
00771 << "setting startdatetime from startdate and starttime"
00772 << endl;
00773 }
00774 if ( enddatetime.isNull() ) {
00775 enddatetime = QDateTime::QDateTime( enddate, endtime );
00776 kdDebug() << "main | datetimestamp | "
00777 << "setting enddatetime from enddate and endtime"
00778 << endl;
00779 }
00780
00781
00782
00783 if ( add ) {
00784 if ( ! args->isSet( "time" ) && ! args->isSet( "end-time" ) &&
00785 ! args->isSet( "epoch-start" ) && ! args->isSet( "epoch-end" ) ) {
00786 variables.setFloating( true );
00787 kdDebug() << "main | floatingcheck | "
00788 << "turn-on floating event"
00789 << endl;
00790 }
00791 }
00792
00793
00794 if ( ! change ) {
00795 variables.setStartDateTime( startdatetime );
00796 variables.setEndDateTime( enddatetime );
00797 } else {
00798
00799
00800 if ( args->isSet( "time" ) || args->isSet( "epoch-start" ) ||
00801 args->isSet( "end-time" ) || args->isSet( "epoch-end" ) ) {
00802 variables.setStartDateTime( startdatetime );
00803 variables.setEndDateTime( enddatetime );
00804 }
00805 }
00806
00807
00808 kdDebug() << "main | datetimestamp | StartDate="
00809 << startdatetime.toString( Qt::TextDate )
00810 << endl;
00811 kdDebug() << "main | datetimestamp | EndDate="
00812 << enddatetime.toString( Qt::TextDate )
00813 << endl;
00814
00815
00816
00817
00818
00819
00820 if ( create + view + add + change + del > 1 ) {
00821 cout << i18n(
00822 "Only 1 operation mode "
00823 "(view, add, change, delete, create) "
00824 "permitted at any one time"
00825 ).local8Bit() << endl;
00826 return 1;
00827 }
00828
00829
00830 if ( startdatetime > enddatetime ) {
00831 cout << i18n(
00832 "Ending Date/Time occurs before the Starting Date/Time"
00833 ).local8Bit() << endl;
00834 return 1;
00835 }
00836
00837
00838
00839
00840
00841 args->clear();
00842
00843
00844
00845
00846
00847 QString prodId = "-//K Desktop Environment//NONSGML %1 %2//EN";
00848 CalFormat::setApplication( progDisplay,
00849 prodId.arg( progDisplay).arg( progVersion ) );
00850
00851 if ( importFile ) {
00852 if ( konsolekalendar->importCalendar() ) {
00853 cout << i18n( "Calendar %1 successfully imported" ).
00854 arg( variables.getImportFile() ).local8Bit()
00855 << endl;
00856 return 0;
00857 } else {
00858 cout << i18n( "Unable to import calendar: %1" ).
00859 arg( variables.getImportFile() ).local8Bit()
00860 << endl;
00861 return 1;
00862 }
00863 }
00864
00865 if ( add ) {
00866 if ( ! konsolekalendar->isEvent( startdatetime, enddatetime,
00867 variables.getSummary() ) ) {
00868 kdDebug() << "main | modework | "
00869 << "calling addEvent()"
00870 << endl;
00871 konsolekalendar->addEvent();
00872 } else {
00873 cout << i18n(
00874 "Attempting to insert an event that already exists"
00875 ).local8Bit() << endl;
00876 return 1;
00877 }
00878 }
00879
00880 if ( change ) {
00881 kdDebug() << "main | modework | "
00882 << "calling changeEvent()"
00883 << endl;
00884 if ( ! variables.isUID() ) {
00885 cout << i18n( "Missing event UID: "
00886 "use --uid command line option" ).local8Bit()
00887 << endl;
00888 return 1;
00889 }
00890 if ( konsolekalendar->changeEvent() != true ) {
00891 cout << i18n( "No such event UID: change event failed" ).local8Bit()
00892 << endl;
00893 return 1;
00894 }
00895 kdDebug() << "main | modework | "
00896 << "successful changeEvent()"
00897 << endl;
00898 }
00899
00900 if ( del ) {
00901 kdDebug() << "main | modework | "
00902 << "calling deleteEvent()"
00903 << endl;
00904 if ( ! variables.isUID() ) {
00905 cout << i18n( "Missing event UID: "
00906 "use --uid command line option" ).local8Bit()
00907 << endl;
00908 return 1;
00909 }
00910 if ( konsolekalendar->deleteEvent() != true ) {
00911 cout << i18n( "No such event UID: delete event failed").local8Bit()
00912 << endl;
00913 return 1;
00914 }
00915 kdDebug() << "main | modework | "
00916 << "successful deleteEvent()"
00917 << endl;
00918 }
00919
00920 if ( view ) {
00921 kdDebug() << "main | modework | "
00922 << "calling showInstance() to view events"
00923 << endl;
00924 if ( ! konsolekalendar->showInstance() ) {
00925 cout << i18n( "Cannot open specified export file: %1" ).
00926 arg( variables.getExportFile() ).local8Bit()
00927 << endl;
00928 return 1;
00929 }
00930 }
00931
00932 delete konsolekalendar;
00933
00934 if ( calendarFile ) {
00935 localCalendar->close();
00936 delete localCalendar;
00937 } else {
00938 calendarResource->close();
00939 delete calendarResource;
00940 }
00941
00942 kdDebug() << "main | exiting"
00943 << endl;
00944
00945 return 0;
00946 }