Go to the documentation of this file.
37 #if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
42 # include <sys/time.h>
48 #include <kcmdlineargs.h>
49 #include <kaboutdata.h>
53 #include <kstandarddirs.h>
56 #include <libkcal/calformat.h>
57 #include <libkcal/calendarresources.h>
58 #include <libkcal/resourcelocal.h>
60 #include <tqdatetime.h>
62 #include <tqfileinfo.h>
67 #include "stdcalendar.h"
76 static const char progName[] = "konsolekalendar";
77 static const char progDisplay[] = "KonsoleKalendar";
78 static const char progVersion[] = "1.3.5";
79 static const char progDesc[] = "A command line interface to KDE calendars";
80 static const char progURL[] = "pim.kde.org/components/konsolekalendar.php";
83 static KCmdLineOptions options[] =
86 I18N_NOOP( "Print helpful runtime messages" ), 0 },
88 I18N_NOOP( "Print what would have been done, but do not execute" ), 0 },
89 { "file <calendar-file>",
90 I18N_NOOP( "Specify which calendar you want to use" ), 0 },
93 I18N_NOOP( "Incidence types (these options can be combined):" ), 0 },
95 I18N_NOOP( " Operate for Events only (Default)" ), 0 },
97 I18N_NOOP( " Operate for To-dos only [NOT WORKING YET]" ), 0 },
99 I18N_NOOP( " Operate for Journals only [NOT WORKING YET]" ), 0 },
102 I18N_NOOP( "Major operation modes:" ), 0 },
104 I18N_NOOP( " Print incidences in specified export format" ), 0 },
106 I18N_NOOP( " Insert an incidence into the calendar" ), 0 },
108 I18N_NOOP( " Modify an existing incidence" ), 0 },
110 I18N_NOOP( " Remove an existing incidence" ), 0 },
112 I18N_NOOP( " Create new calendar file if one does not exist" ), 0 },
113 { "import <import-file>",
114 I18N_NOOP( " Import this calendar to main calendar" ), 0 },
116 I18N_NOOP( "Operation modifiers:" ), 0 },
118 I18N_NOOP( " View all calendar entries" ), 0 },
120 I18N_NOOP( " View next activity in calendar" ), 0 },
121 { "show-next <days>",
122 I18N_NOOP( " From start date show next # days' activities" ), 0 },
124 I18N_NOOP( " Incidence Unique-string identifier" ), 0 },
125 { "date <start-date>",
126 I18N_NOOP( " Start from this day [YYYY-MM-DD]" ), 0 },
127 { "time <start-time>",
128 I18N_NOOP( " Start from this time [HH:MM:SS]" ), 0 },
129 { "end-date <end-date>",
130 I18N_NOOP( " End at this day [YYYY-MM-DD]" ), 0 },
131 { "end-time <end-time>",
132 I18N_NOOP( " End at this time [HH:MM:SS]" ), 0 },
133 { "epoch-start <epoch-time>",
134 I18N_NOOP( " Start from this time [secs since epoch]" ), 0 },
135 { "epoch-end <epoch-time>",
136 I18N_NOOP( " End at this time [secs since epoch]" ), 0 },
137 { "summary <summary>",
138 I18N_NOOP( " Add summary to incidence (for add/change modes)" ), 0 },
139 { "description <description>",
140 I18N_NOOP( "Add description to incidence (for add/change modes)" ), 0 },
141 { "location <location>",
142 I18N_NOOP( " Add location to incidence (for add/change modes)" ), 0 },
144 { ":", I18N_NOOP( "Export options:" ), 0 },
145 { "export-type <export-type>",
146 I18N_NOOP( "Export file type (Default: text)" ), 0 },
147 { "export-file <export-file>",
148 I18N_NOOP( "Export to file (Default: stdout)" ), 0 },
150 I18N_NOOP( " Print list of export types supported and exit" ), 0 },
153 I18N_NOOP( "Examples:\n"
154 " konsolekalendar --view\n"
155 " konsolekalendar --add --date 2003-06-04 "
156 "--time 10:00 --end-time 12:00 \\\n"
157 " --summary \"Doctor Visit\" "
158 "--description \"Get My Head Examined\"\n"
159 " konsolekalendar --delete --uid KOrganizer-1740326.803" ), 0 },
162 I18N_NOOP( "For more information visit the program home page at:\n"
163 " http://pim.kde.org/components/konsolekalendar.php" ), 0 },
168 int main( int argc, char *argv[] )
170 KAboutData aboutData(
172 I18N_NOOP( progDisplay ),
174 I18N_NOOP( progDesc ),
175 KAboutData::License_GPL,
176 "(c) 2002-2005, Tuukka Pasanen and Allen Winter",
184 I18N_NOOP( "Primary Author" ),
185 "illuusio@mailcity.com",
190 I18N_NOOP( "Author" ),
196 KCmdLineArgs::init( argc, argv, &aboutData );
197 KCmdLineArgs::addCmdLineOptions( options );
204 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
207 TQDate startdate = TQDate::currentDate();
208 TQTime starttime( 7, 0 );
211 TQDate enddate = TQDate::currentDate();
212 TQTime endtime( 17, 0 );
220 bool calendarFile = false;
221 bool importFile = false;
230 if ( args->isSet( "verbose" ) ) {
234 if ( args->isSet( "dry-run" ) ) {
241 if ( args->isSet( "export-list" ) ) {
243 cout << i18n( "%1 supports these export formats:" ).
244 arg( progDisplay ).local8Bit().data()
246 cout << i18n( " %1 [Default]" ).
247 arg( "Text" ).local8Bit().data()
249 cout << i18n( " %1 (like %2, but more compact)" ).
250 arg( "Short", "Text" ).local8Bit().data()
252 cout << i18n( " %1" ).
253 arg( "HTML" ).local8Bit().data()
255 cout << i18n( " %1 (like %2, but in a month view)" ).
256 arg( "HTMLmonth", "HTML" ).local8Bit().data()
258 cout << i18n( " %1 (Comma-Separated Values)" ).
259 arg( "CSV" ).local8Bit().data()
268 if ( args->isSet( "event" ) ) {
270 kdDebug() << "main | parse options | use Events" << endl;
272 if ( args->isSet( "todo" ) ) {
274 kdDebug() << "main | parse options | use To-dos" << endl;
275 cout << i18n( "Sorry, To-dos are not working yet." ).local8Bit().data()
279 if ( args->isSet( "journal" ) ) {
281 kdDebug() << "main | parse options | use Journals" << endl;
282 cout << i18n( "Sorry, Journals are not working yet." ).local8Bit().data()
287 if ( !args->isSet( "event" ) &&
288 !args->isSet( "todo" ) &&
289 !args->isSet( "journal" ) ) {
291 kdDebug() << "main | parse options | use Events (Default)" << endl;
298 if ( args->isSet( "export-type" ) ) {
299 option = args->getOption( "export-type" );
301 if ( option.upper() == "HTML" ) {
302 kdDebug() << "main | export-type | Export to HTML" << endl;
304 } else if ( option.upper() == "HTMLMONTH" ) {
305 kdDebug() << "main | export-type | Export to HTML by Month" << endl;
307 } else if ( option.upper() == "CSV" ) {
308 kdDebug() << "main | export-type | Export to CSV" << endl;
310 } else if ( option.upper() == "TEXT" ) {
311 kdDebug() << "main | export-type | Export to TEXT (default)" << endl;
313 } else if ( option.upper() == "SHORT" ) {
314 kdDebug() << "main | export-type | Export to TEXT-SHORT" << endl;
317 cout << i18n( "Invalid Export Type Specified: %1" ).
318 arg( option ).local8Bit().data()
327 if ( args->isSet( "export-file" ) ) {
328 option = args->getOption( "export-file" );
330 kdDebug() << "main | parse options | "
332 << "(" << option << ")"
341 if ( args->isSet( "view" ) ) {
344 kdDebug() << "main | parse options | "
345 << "Mode: (Print incidences)"
352 if ( args->isSet( "add" ) ) {
356 kdDebug() << "main | parse options | "
357 << "Mode: (Add incidence)"
364 if ( args->isSet( "change" ) ) {
368 kdDebug() << "main | parse options | "
369 << "Mode: (Change incidence)"
376 if ( args->isSet( "delete" ) ) {
380 kdDebug() << "main | parse options | "
381 << "Mode: (Delete incidence)"
388 if ( args->isSet( "create" ) ) {
392 kdDebug() << "main | parse options | "
393 << "Calendar File: (Create)"
400 if ( args->isSet( "summary" ) ) {
401 option = args->getOption( "summary" );
403 kdDebug() << "main | parse options | "
405 << "(" << option << ")"
414 if ( args->isSet( "description" ) ) {
415 option = args->getOption( "description" );
417 kdDebug() << "main | parse options | "
419 << "(" << option << ")"
428 if ( args->isSet( "location" ) ) {
429 option = args->getOption( "location" );
431 kdDebug() << "main | parse options | "
433 << "(" << option << ")"
442 if ( args->isSet( "next" ) ) {
443 kdDebug() << "main | parse options | "
444 << "Show next incidence only"
453 if ( args->isSet( "uid" ) ) {
454 option = args->getOption( "uid" );
456 kdDebug() << "main | parse options | "
458 << "(" << option << ")"
461 variables. setUID( option );
467 if ( args->isSet( "date" ) ) {
468 option = args->getOption( "date" );
470 kdDebug() << "main | parse options | "
471 << "Start date before conversion: "
472 << "(" << option << ")"
475 startdate = TQDate::fromString( option, Qt::ISODate );
476 if ( !startdate.isValid() ) {
477 cout << i18n( "Invalid Start Date Specified: %1" ).
478 arg( option ).local8Bit().data()
482 kdDebug() << "main | parse options | "
483 << "Start date after conversion: "
484 << "(" << TQString(startdate.toString()) << ")"
491 if ( args->isSet( "time" ) ) {
492 option = args->getOption( "time" );
494 kdDebug() << "main | parse options | "
495 << "Start time before conversion : "
496 << "(" << option << ")"
499 if ( option.upper() != "FLOAT" ) {
500 starttime = TQTime::fromString( option, Qt::ISODate );
501 if ( !starttime.isValid() ) {
502 cout << i18n( "Invalid Start Time Specified: %1" ).
503 arg( option ).local8Bit().data()
507 kdDebug() << "main | parse options | "
508 << "Start time after conversion: "
509 << "(" << TQString(starttime.toString()) << ")"
513 kdDebug() << "main | parse options | "
514 << "Floating event time specified"
522 if ( args->isSet( "end-date" ) ) {
523 option = args->getOption( "end-date" );
525 kdDebug() << "main | parse options | "
526 << "End date before conversion: "
527 << "(" << option << ")"
530 enddate = TQDate::fromString( option, Qt::ISODate );
531 if ( !enddate.isValid() ) {
532 cout << i18n( "Invalid End Date Specified: %1" ).
533 arg( option ).local8Bit().data()
537 kdDebug() << "main | parse options | "
538 << "End date after conversion: "
539 << "(" << TQString(enddate.toString()) << ")"
546 if ( args->isSet( "show-next" ) ) {
549 option = args->getOption( "show-next" );
550 kdDebug() << "main | parse options | "
551 << "Show " << option << " days ahead"
556 cout << i18n( "Invalid Date Count Specified: %1" ).
557 arg( option ).local8Bit().data()
564 kdDebug() << "main | parse options | "
565 << "End date after conversion: "
566 << "(" << TQString(enddate.toString()) << ")"
573 if ( args->isSet( "end-time" ) ) {
574 option = args->getOption( "end-time" );
576 kdDebug() << "main | parse options | "
577 << "End time before conversion: "
578 << "(" << option << ")"
581 if ( option.upper() != "FLOAT" ) {
582 endtime = TQTime::fromString( option, Qt::ISODate );
583 if ( !endtime.isValid() ) {
584 cout << i18n( "Invalid End Time Specified: %1" ).
585 arg( option ).local8Bit().data()
590 kdDebug() << "main | parse options | "
591 << "End time after conversion: "
592 << "(" << TQString(endtime.toString()) << ")"
596 kdDebug() << "main | parse options | "
597 << "Floating event time specified"
605 time_t epochstart = 0;
606 if ( args->isSet( "epoch-start" ) ) {
607 option = args->getOption( "epoch-start" );
609 kdDebug() << "main | parse options | "
611 << "(" << option << ")"
614 epochstart = ( time_t ) option.toULong( 0, 10 );
621 if ( args->isSet( "epoch-end" ) ) {
622 option = args->getOption( "epoch-end" );
624 kdDebug() << "main | parse options | "
626 << "(" << option << ")"
629 epochend = ( time_t ) option.toULong( 0, 10 );
632 if ( args->isSet( "all" ) ) {
635 variables. setAll( false );
638 if ( args->isSet( "import" ) ) {
641 option = args->getOption( "import" );
644 kdDebug() << "main | parse options | "
645 << "importing file from: "
646 << "(" << option << ")"
652 if ( args->isSet( "file" ) ) {
654 option = args->getOption( "file" );
663 if ( url.isLocalFile() ) {
667 } else if ( url.protocol().isEmpty() ) {
679 kdDebug() << "main | createcalendar | "
680 << "check if calendar file already exists"
684 cout << i18n( "Attempting to create a remote file %1" ).
689 cout << i18n( "Calendar %1 already exists" ).
697 cout << i18n( "Calendar %1 successfully created" ).
702 cout << i18n( "Unable to create calendar: %1" ).
710 cout << i18n( "Calendar file not found %1" ).
713 cout << i18n( "Try --create to create new calendar file" ).local8Bit().data()
719 CalendarResources *calendarResource = NULL;
723 if ( args->isSet( "file" ) ) {
725 i18n( "Active Calendar" ) );
731 calendarResource = new StdCalendar( locateLocal( "data",
732 "korganizer/std.ics" ),
733 i18n( "Default Calendar" ) );
735 if ( !args->isSet( "import" ) ) {
737 calendarResource->load();
743 TQDateTime startdatetime, enddatetime;
746 if ( !args->isSet( "end-date" ) && !args->isSet( "show-next" ) &&
747 args->isSet( "date" ) ) {
749 kdDebug() << "main | datetimestamp | "
750 << "setting enddate to startdate"
752 } else if ( args->isSet( "end-date" ) && !args->isSet( "date" ) ) {
754 kdDebug() << "main | datetimestamp | "
755 << "setting startdate to enddate"
764 if ( !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) {
765 if ( args->isSet( "time" ) ) {
766 endtime = starttime.addSecs( 60 * 60 );
767 kdDebug() << "main | datetimestamp | "
768 << "setting endtime 1 hour after starttime"
770 } else if ( args->isSet( "epoch-start" ) ) {
772 enddatetime = startdatetime.addSecs( 60 * 60 );
773 kdDebug() << "main | datetimestamp | "
774 << "setting endtime 1 hour after epochstart"
782 if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) ) {
783 if ( args->isSet( "end-time" ) ) {
784 starttime = endtime.addSecs( -60 * 60 );
785 kdDebug() << "main | datetimestamp | "
786 << "setting starttime 1 hour before endtime"
788 } else if ( args->isSet( "epoch-end" ) ) {
790 startdatetime = enddatetime.addSecs( -60 * 60 );
791 kdDebug() << "main | datetimestamp | "
792 << "setting starttime 1 before after epochend"
799 if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) &&
800 !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) {
802 startdatetime = TQDateTime( startdate, starttime );
803 kdDebug() << "main | datetimestamp | "
804 << "setting startdatetime from "
805 << "default startdate (today) and starttime"
808 enddatetime = TQDateTime( enddate, endtime );
809 kdDebug() << "main | datetimestamp | "
810 << "setting enddatetime from "
811 << "default enddate (today) and endtime"
816 if ( startdatetime.isNull() ) {
817 startdatetime = TQDateTime( startdate, starttime );
818 kdDebug() << "main | datetimestamp | "
819 << "setting startdatetime from startdate and starttime"
822 if ( enddatetime.isNull() ) {
823 enddatetime = TQDateTime( enddate, endtime );
824 kdDebug() << "main | datetimestamp | "
825 << "setting enddatetime from enddate and endtime"
832 if ( !args->isSet( "time" ) && !args->isSet( "end-time" ) &&
833 !args->isSet( "epoch-start" ) && !args->isSet( "epoch-end" ) ) {
835 kdDebug() << "main | floatingcheck | "
836 << "turn-on floating event"
848 if ( args->isSet( "time" ) || args->isSet( "epoch-start" ) ||
849 args->isSet( "end-time" ) || args->isSet( "epoch-end" ) ) {
856 kdDebug() << "main | datetimestamp | StartDate="
857 << startdatetime.toString( Qt::TextDate )
859 kdDebug() << "main | datetimestamp | EndDate="
860 << enddatetime.toString( Qt::TextDate )
868 if ( create + view + add + change + del > 1 ) {
870 "Only 1 operation mode "
871 "(view, add, change, delete, create) "
872 "permitted at any one time"
873 ).local8Bit().data() << endl;
878 if ( startdatetime > enddatetime ) {
880 "Ending Date/Time occurs before the Starting Date/Time"
881 ).local8Bit().data() << endl;
895 TQString prodId = "-//K Desktop Environment//NONSGML %1 %2//EN";
896 CalFormat::setApplication( progDisplay,
897 prodId.arg( progDisplay ).arg( progVersion ) );
901 cout << i18n( "Calendar %1 successfully imported" ).
906 cout << i18n( "Unable to import calendar: %1" ).
914 if ( !konsolekalendar-> isEvent( startdatetime, enddatetime,
916 kdDebug() << "main | modework | "
917 << "calling addEvent()"
922 "Attempting to insert an event that already exists"
923 ).local8Bit().data() << endl;
929 kdDebug() << "main | modework | "
930 << "calling changeEvent()"
932 if ( !variables. isUID() ) {
933 cout << i18n( "Missing event UID: "
934 "use --uid command line option" ).local8Bit().data()
939 cout << i18n( "No such event UID: change event failed" ).local8Bit().data()
943 kdDebug() << "main | modework | "
944 << "successful changeEvent()"
949 kdDebug() << "main | modework | "
950 << "calling deleteEvent()"
952 if ( !variables. isUID() ) {
953 cout << i18n( "Missing event UID: "
954 "use --uid command line option" ).local8Bit().data()
959 cout << i18n( "No such event UID: delete event failed").local8Bit().data()
963 kdDebug() << "main | modework | "
964 << "successful deleteEvent()"
969 kdDebug() << "main | modework | "
970 << "calling showInstance() to view events"
973 cout << i18n( "Cannot open specified export file: %1" ).
980 delete konsolekalendar;
982 calendarResource->close();
983 delete calendarResource;
985 kdDebug() << "main | exiting"
|