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 <tdecmdlineargs.h>
49 #include <tdeaboutdata.h>
50 #include <tdelocale.h>
51 #include <tdeglobal.h>
52 #include <tdeconfig.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 TDECmdLineOptions 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 TDEAboutData aboutData(
172 I18N_NOOP( progDisplay ),
174 I18N_NOOP( progDesc ),
175 TDEAboutData::License_GPL,
176 "(c) 2002-2005, Tuukka Pasanen and Allen Winter",
179 "bugs.trinitydesktop.org"
184 I18N_NOOP( "Primary Author" ),
185 "illuusio@mailcity.com",
190 I18N_NOOP( "Author" ),
196 TDECmdLineArgs::init( argc, argv, &aboutData );
197 TDECmdLineArgs::addCmdLineOptions( options );
204 TDECmdLineArgs *args = TDECmdLineArgs::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, TQt::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, TQt::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, TQt::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, TQt::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( TQt::TextDate )
859 kdDebug() << "main | datetimestamp | EndDate="
860 << enddatetime.toString( TQt::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"
Class for timestamps expressed as epochs.
static TQDateTime epoch2TQDateTime(uint epoch) Converts epoch time to TQDateTime format.
This class provides all the variables for the program.
void setDescription(TQString description) Add description.
void setCalendar(CalendarResources *resources) Set calendar resources for global use.
void setEndDateTime(TQDateTime end) Sets end date.
TQString getImportFile() Return import filename.
void setStartDateTime(TQDateTime start) Sets start date.
void setUID(TQString uid) Sets the UID, the unique tag for VCard entry.
void setUseEvents(bool useEvents) Set switch to use Events.
void setAll(bool all) View all option.
void setNext(bool next) Show only next activity and exit.
TQString getCalendarFile() Returns fullpath to calendar file.
void setFloating(bool floating) Set if Event is floating.
int getDaysCount() Get how many day should be seen.
TQString getExportFile() To what file we'll output.
void setExportType(ExportType exportType) Set export type that'll we use.
void setCalendarFile(TQString calendar) Set calendar file.
void setUseTodos(bool useTodos) Set switch to use Todos.
void setVerbose(bool verbose) Should program be more verbose?
void setDaysCount(int count) Set how many day should be seen.
bool isUID() Is there UID set?
void setDryRun(bool dryrun) Should we only try to run it and do nothing?
void setUseJournals(bool useJournals) Set switch to use Journals.
void setSummary(TQString summary) Add summary.
void setImportFile(TQString calendar) Set file to import active calendar.
TQString getSummary() Get summary.
void setLocation(TQString location) Add location information.
void setExportFile(TQString export_file) Set output file.
The base class of the project.
bool changeEvent() Change event.
bool addEvent() Add event to calendar.
bool createCalendar() Creates calendar file (If it doesn't exists)
bool isEvent(TQDateTime startdate, TQDateTime enddate, TQString summary) Detect if event already exists.
bool deleteEvent() Delete event.
bool importCalendar() Imports calendar file.
bool showInstance() Visualize what we need.
Provides the KonsoleKalendar class definition.
Provides the KonsoleKalendarEpoch class definition.
Provides the KonsoleKalendarVariables class definition.
|