• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

KonsoleKalendar

  • sources
  • kde-4.12
  • kdepim
  • console
  • konsolekalendar
main.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * main.cpp *
3  * *
4  * KonsoleKalendar is a command line interface to KDE calendars *
5  * Copyright (C) 2002-2004 Tuukka Pasanen <illuusio@mailcity.com> *
6  * Copyright (C) 2003-2009 Allen Winter <winter@kde.org> *
7  * Copyright (C) 2013 Sérgio Martins <iamsergio@gmail.com> *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License along *
20  * with this program; if not, write to the Free Software Foundation, Inc., *
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
22  * *
23  * As a special exception, permission is given to link this program *
24  * with any edition of Qt, and distribute the resulting executable, *
25  * without including the source code for Qt in the source distribution. *
26  * *
27  *****************************************************************************/
36 #include "konsolekalendar.h"
37 #include "konsolekalendarepoch.h"
38 
39 #include "konsolekalendarvariables.h"
40 
41 #include <kcmdlineargs.h>
42 #include <kaboutdata.h>
43 #include <klocale.h>
44 #include <kglobal.h>
45 #include <kconfig.h>
46 #include <kstandarddirs.h>
47 #include <kurl.h>
48 #include <kdebug.h>
49 #include <KApplication>
50 
51 #include <KCalCore/CalFormat>
52 
53 #include <QtCore/QDateTime>
54 #include <QtCore/QFile>
55 #include <QtCore/QFileInfo>
56 #include <QtCore/QEventLoop>
57 
58 #include <stdlib.h>
59 #include <iostream>
60 #include <time.h>
61 
62 using namespace KCalCore;
63 using namespace std;
64 
65 //@cond IGNORE
66 static const char progName[] = "konsolekalendar";
67 static const char progDisplay[] = "KonsoleKalendar";
68 #include "kdepim-version.h"
69 static const char progVersion[] = KDEPIM_VERSION;
70 static const char progDesc[] = "A command line interface to KDE calendars";
71 static const char progURL[] = "pim.kde.org/components/konsolekalendar.php";
72 
73 int main( int argc, char *argv[] )
74 {
75  KAboutData aboutData(
76  progName, 0, // internal program name
77  ki18n( progDisplay ), // displayable program name.
78  progVersion, // version string
79  ki18n( progDesc ), // short program description
80  KAboutData::License_GPL, // license type
81  ki18n( "(c) 2002-2009, Tuukka Pasanen and Allen Winter" ),
82  ki18n( 0 ), // any free form text
83  progURL, // program home page address
84  "bugs.kde.org" // bug report email address
85  );
86 
87  aboutData.addAuthor(
88  ki18n( "Allen Winter" ), // developer's name
89  ki18n( "Maintainer" ), // task or role
90  "winter@kde.org", // email address
91  0 // home page or relevant link
92  );
93  aboutData.addAuthor(
94  ki18n( "Tuukka Pasanen" ), // developer's name
95  ki18n( "Author" ), // task or role
96  "illuusio@mailcity.com", // email address
97  0 // home page or relevant link
98  );
99 
100  KCmdLineArgs::init( argc, argv, &aboutData, KCmdLineArgs::CmdLineArgNone );
101 
102  KCmdLineOptions options;
103  options.add( "verbose",
104  ki18n( "Print helpful runtime messages" ) );
105  options.add( "dry-run",
106  ki18n( "Print what would have been done, but do not execute" ) );
107  options.add( "allow-gui",
108  ki18n( "Allow calendars which might need an interactive user interface" ) );
109  options.add( ":",
110  ki18n( "Incidence types (these options can be combined):" ) );
111  options.add( "event",
112  ki18n( " Operate for Events only (Default)" ) );
113  options.add( "todo",
114  ki18n( " Operate for To-dos only [NOT WORKING YET]" ) );
115  options.add( "journal",
116  ki18n( " Operate for Journals only [NOT WORKING YET]" ) );
117  options.add( ":",
118  ki18n( "Major operation modes:" ) );
119  options.add( "view",
120  ki18n( " Print incidences in specified export format" ) );
121  options.add( "add",
122  ki18n( " Insert an incidence into the calendar" ) );
123  options.add( "change",
124  ki18n( " Modify an existing incidence" ) );
125  options.add( "delete",
126  ki18n( " Remove an existing incidence" ) );
127  options.add( "create",
128  ki18n( " Create new calendar file if one does not exist" ) );
129  options.add( "import <import-file>",
130  ki18n( " Import this calendar to main calendar" ) );
131  options.add( "list-calendars",
132  ki18n( " List available calendars" ) );
133  options.add( ":",
134  ki18n( "Operation modifiers:" ) );
135  options.add( "all",
136  ki18n( " View all calendar entries, ignoring date/time options" ) );
137  options.add( "next",
138  ki18n( " View next activity in calendar" ) );
139  options.add( "show-next <days>",
140  ki18n( " From start date show next # days' activities" ) );
141  options.add( "uid <uid>",
142  ki18n( " Incidence Unique-string identifier" ) );
143  options.add( "date <start-date>",
144  ki18n( " Start from this day [YYYY-MM-DD]" ) );
145  options.add( "time <start-time>",
146  ki18n( " Start from this time [HH:MM:SS]" ) );
147  options.add( "end-date <end-date>",
148  ki18n( " End at this day [YYYY-MM-DD]" ) );
149  options.add( "end-time <end-time>",
150  ki18n( " End at this time [HH:MM:SS]" ) );
151  options.add( "epoch-start <epoch-time>",
152  ki18n( " Start from this time [secs since epoch]" ) );
153  options.add( "epoch-end <epoch-time>",
154  ki18n( " End at this time [secs since epoch]" ) );
155  options.add( "summary <summary>",
156  ki18n( " Add summary to incidence (for add/change modes)" ) );
157  options.add( "description <description>",
158  ki18n( "Add description to incidence (for add/change modes)" ) );
159  options.add( "location <location>",
160  ki18n( " Add location to incidence (for add/change modes)" ) );
161  options.add( "calendar <calendar id>",
162  ki18n( " Calendar to use when creating a new incidence" ) );
163  options.add( ":",
164  ki18n( "Export options:" ) );
165  options.add( "export-type <export-type>",
166  ki18n( "Export file type (Default: text)" ) );
167  options.add( "export-file <export-file>",
168  ki18n( "Export to file (Default: stdout)" ) );
169  options.add( "export-list",
170  ki18n( " Print list of export types supported and exit" ) );
171  options.add( "",
172  ki18n( "Examples:\n"
173  " konsolekalendar --view\n"
174  " konsolekalendar --list-collections\n"
175  " konsolekalendar --add --collection 42 --date 2003-06-04 "
176  "--time 10:00 --end-time 12:00 \\\n"
177  " --summary \"Doctor Visit\" "
178  "--description \"Get My Head Examined\"\n"
179  " konsolekalendar --delete --uid KOrganizer-1740326.803" ) );
180  options.add( "",
181  ki18n( "For more information visit the program home page at:\n"
182  " http://pim.kde.org/components/konsolekalendar.php" ) );
183  KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
184 
185  KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
186 
187  KApplication app(
188  // when not set (default) GUI is not enabled - disable all GUI stuff
189  args->isSet( "allow-gui" )
190  );
191 
192  // Default values for start date/time (today at 07:00)
193  QDate startdate = QDate::currentDate();
194  QTime starttime( 7, 0 );
195 
196  // Default values for end date/time (today at 17:00)
197  QDate enddate = QDate::currentDate();
198  QTime endtime( 17, 0 );
199 
200  // Default values for switches
201  bool view = true;
202  bool add = false;
203  bool change = false;
204  bool del = false;
205  bool create = false;
206  //bool calendarFile = false;
207  bool importFile = false;
208 
209  QString option;
210 
211  KonsoleKalendarVariables variables;
212  KonsoleKalendarEpoch epochs;
213 
214  variables.setFloating( false ); // by default, new events do NOT float
215 
216  if ( args->isSet( "verbose" ) ) {
217  variables.setVerbose( true );
218  }
219 
220  if ( args->isSet( "dry-run" ) ) {
221  variables.setDryRun( true );
222  }
223 
224  if ( args->isSet( "allow-gui" ) ) {
225  variables.setAllowGui( true );
226  }
227 
228  /*
229  * Switch on export list
230  */
231  if ( args->isSet( "export-list" ) ) {
232  cout << endl;
233  cout << i18n( "%1 supports these export formats:",
234  QString::fromLatin1(progDisplay) ).toLocal8Bit().data()
235  << endl;
236  cout << i18nc( "the default export format", " %1 [Default]",
237  QString::fromLatin1( "Text" ) ).toLocal8Bit().data()
238  << endl;
239  cout << i18nc( "short text export", " %1 (like %2, but more compact)",
240  QString::fromLatin1( "Short" ), QString::fromLatin1( "Text" ) ).toLocal8Bit().data()
241  << endl;
242  cout << i18nc( "HTML export", " %1",
243  QString::fromLatin1( "HTML" ) ).toLocal8Bit().data()
244  << endl;
245  cout << i18nc( "HTMLmonth export", " %1 (like %2, but in a month view)",
246  QString::fromLatin1( "HTMLmonth" ), QString::fromLatin1( "HTML" ) ).toLocal8Bit().data()
247  << endl;
248  cout << i18nc( "comma-separated values export", " %1 (Comma-Separated Values)",
249  QString::fromLatin1( "CSV" ) ).toLocal8Bit().data()
250  << endl;
251  cout << endl;
252  return 0;
253  }
254 
255  /*
256  * Set incidence type(s)
257  */
258  if ( args->isSet( "event" ) ) {
259  variables.setUseEvents( true );
260  kDebug() << "main | parse options | use Events";
261  }
262  if ( args->isSet( "todo" ) ) {
263  variables.setUseTodos( true );
264  kDebug() << "main | parse options | use To-dos";
265  cout << i18n( "Sorry, To-dos are not working yet." ).toLocal8Bit().data()
266  << endl;
267  return 1;
268  }
269  if ( args->isSet( "journal" ) ) {
270  variables.setUseJournals( true );
271  kDebug() << "main | parse options | use Journals";
272  cout << i18n( "Sorry, Journals are not working yet." ).toLocal8Bit().data()
273  << endl;
274  return 1;
275  }
276  // Use Events if no incidence type is specified on the command line
277  if ( !args->isSet( "event" ) &&
278  !args->isSet( "todo" ) &&
279  !args->isSet( "journal" ) ) {
280  variables.setUseEvents( true );
281  kDebug() << "main | parse options | use Events (Default)";
282  }
283 
284  /*
285  * Switch on exporting
286  */
287  variables.setExportType( ExportTypeText );
288  if ( args->isSet( "export-type" ) ) {
289  option = args->getOption( "export-type" );
290 
291  if ( option.toUpper() == QLatin1String("HTML") ) {
292  kDebug() << "main | export-type | Export to HTML";
293  variables.setExportType( ExportTypeHTML );
294  } else if ( option.toUpper() == QLatin1String("HTMLMONTH") ) {
295  kDebug() << "main | export-type | Export to HTML by Month";
296  variables.setExportType( ExportTypeMonthHTML );
297  } else if ( option.toUpper() == QLatin1String("CSV") ) {
298  kDebug() << "main | export-type | Export to CSV";
299  variables.setExportType( ExportTypeCSV );
300  } else if ( option.toUpper() == QLatin1String("TEXT") ) {
301  kDebug() << "main | export-type | Export to TEXT (default)";
302  variables.setExportType( ExportTypeText );
303  } else if ( option.toUpper() == QLatin1String("SHORT") ) {
304  kDebug() << "main | export-type | Export to TEXT-SHORT";
305  variables.setExportType( ExportTypeTextShort );
306  } else {
307  cout << i18n( "Invalid Export Type Specified: %1", option ).toLocal8Bit().data()
308  << endl;
309  return 1;
310  }
311  }
312 
313  /*
314  * Switch on export file name
315  */
316  if ( args->isSet( "export-file" ) ) {
317  option = args->getOption( "export-file" );
318 
319  kDebug() << "main | parse options |"
320  << "Export File:"
321  << "(" << option << ")";
322 
323  variables.setExportFile( option );
324  }
325 
326  /*
327  * Switch on View (Print Entries). This is the default mode of operation.
328  */
329  if ( args->isSet( "view" ) ) {
330  view = true;
331 
332  kDebug() << "main | parse options |"
333  << "Mode: (Print incidences)";
334  }
335 
336  /*
337  * Switch on Add (Insert Entry)
338  */
339  if ( args->isSet( "add" ) ) {
340  view = false;
341  add = true;
342 
343  kDebug() << "main | parse options |"
344  << "Mode: (Add incidence)";
345  }
346 
347  /*
348  * Switch on Change (Modify Entry)
349  */
350  if ( args->isSet( "change" ) ) {
351  view = false;
352  change = true;
353 
354  kDebug() << "main | parse options |"
355  << "Mode: (Change incidence)";
356  }
357 
358  /*
359  * Switch on Delete (Remove Entry)
360  */
361  if ( args->isSet( "delete" ) ) {
362  view = false;
363  del = true;
364 
365  kDebug() << "main | parse options |"
366  << "Mode: (Delete incidence)";
367  }
368 
369  /*
370  * Switch on Create
371  */
372  if ( args->isSet( "create" ) ) {
373  view = false;
374  create = true;
375 
376  kDebug() << "main | parse options |"
377  << "Calendar File: (Create)";
378  }
379 
380  /*
381  * If there is summary attached.
382  */
383  if ( args->isSet( "summary" ) ) {
384  option = args->getOption( "summary" );
385 
386  kDebug() << "main | parse options |"
387  << "Summary:"
388  << "(" << option << ")";
389 
390  variables.setSummary( option );
391  }
392 
393  /*
394  * If there is description attached.
395  */
396  if ( args->isSet( "description" ) ) {
397  option = args->getOption( "description" );
398 
399  kDebug() << "main | parse options |"
400  << "Description:"
401  << "(" << option << ")";
402 
403  variables.setDescription( option );
404  }
405 
406  if ( args->isSet( "calendar" ) ) {
407  option = args->getOption( "calendar" );
408  bool ok = false;
409  int colId = option.toInt(&ok);
410  if (ok)
411  variables.setCollectionId(colId);
412  }
413 
414  /*
415  * If there is location information
416  */
417  if ( args->isSet( "location" ) ) {
418  option = args->getOption( "location" );
419 
420  kDebug() << "main | parse options |"
421  << "Location:"
422  << "(" << option << ")";
423 
424  variables.setLocation( option );
425  }
426 
427  /*
428  * Show next happening and exit
429  */
430  if ( args->isSet( "next" ) ) {
431  kDebug() << "main | parse options |"
432  << "Show next incidence only";
433 
434  variables.setNext( true );
435  }
436 
437  /*
438  * Set incidence unique string identifier
439  */
440  if ( args->isSet( "uid" ) ) {
441  option = args->getOption( "uid" );
442 
443  kDebug() << "main | parse options |"
444  << "incidence UID:"
445  << "(" << option << ")";
446 
447  variables.setUID( option );
448  }
449 
450  /*
451  * Set starting date for calendar
452  */
453  if ( args->isSet( "date" ) ) {
454  option = args->getOption( "date" );
455 
456  kDebug() << "main | parse options |"
457  << "Start date before conversion:"
458  << "(" << option << ")";
459 
460  startdate = QDate::fromString( option, Qt::ISODate );
461  if ( !startdate.isValid() ) {
462  cout << i18n( "Invalid Start Date Specified: %1",
463  option ).toLocal8Bit().data()
464  << endl;
465  return 1;
466  }
467  kDebug() << "main | parse options |"
468  << "Start date after conversion:"
469  << "(" << startdate.toString() << ")";
470  }
471 
472  /*
473  * Set starting time
474  */
475  if ( args->isSet( "time" ) ) {
476  option = args->getOption( "time" );
477 
478  kDebug() << "main | parse options |"
479  << "Start time before conversion :"
480  << "(" << option << ")";
481 
482  if ( option.toUpper() != QLatin1String("FLOAT") ) {
483  if ( option.count( QLatin1Char(':') ) < 2 ) {
484  // need to append seconds
485  option.append( QLatin1String(":00") );
486  }
487  starttime = QTime::fromString( option, Qt::ISODate );
488  if ( !starttime.isValid() ) {
489  cout << i18n( "Invalid Start Time Specified: %1", option ).toLocal8Bit().data()
490  << endl;
491  return 1;
492  }
493  kDebug() << "main | parse options |"
494  << "Start time after conversion:"
495  << "(" << starttime.toString() << ")";
496  } else {
497  variables.setFloating( true );
498  kDebug() << "main | parse options |"
499  << "Floating event time specified";
500  }
501  }
502 
503  /*
504  * Set end date for calendar
505  */
506  if ( args->isSet( "end-date" ) ) {
507  option = args->getOption( "end-date" );
508 
509  kDebug() << "main | parse options |"
510  << "End date before conversion:"
511  << "(" << option << ")";
512 
513  enddate = QDate::fromString( option, Qt::ISODate );
514  if ( !enddate.isValid() ) {
515  cout << i18n( "Invalid End Date Specified: %1",
516  option ).toLocal8Bit().data()
517  << endl;
518  return 1;
519  }
520  kDebug() << "main | parse options |"
521  << "End date after conversion:"
522  << "(" << enddate.toString() << ")";
523  }
524 
525  /*
526  * Show next # days and exit
527  */
528  if ( args->isSet( "show-next" ) ) {
529  bool ok;
530 
531  option = args->getOption( "show-next" );
532  kDebug() << "main | parse options |"
533  << "Show" << option << "days ahead";
534  variables.setDaysCount( option.toInt( &ok, 10 ) );
535 
536  if ( !ok ) {
537  cout << i18n( "Invalid Date Count Specified: %1", option ).toLocal8Bit().data()
538  << endl;
539  return 1;
540  }
541 
542  enddate = startdate;
543  enddate = enddate.addDays( variables.getDaysCount() );
544  kDebug() << "main | parse options |"
545  << "End date after conversion:"
546  << "(" << enddate.toString() << ")";
547  }
548 
549  /*
550  * Set ending time
551  */
552  if ( args->isSet( "end-time" ) ) {
553  option = args->getOption( "end-time" );
554 
555  kDebug() << "main | parse options |"
556  << "End time before conversion:"
557  << "(" << option << ")";
558 
559  if ( option.toUpper() != QLatin1String("FLOAT") ) {
560  if ( option.count( QLatin1Char(':') ) < 2 ) {
561  // need to append seconds
562  option.append( QLatin1String(":00") );
563  }
564  endtime = QTime::fromString( option, Qt::ISODate );
565  if ( !endtime.isValid() ) {
566  cout << i18n( "Invalid End Time Specified: %1", option ).toLocal8Bit().data()
567  << endl;
568  return 1;
569  }
570 
571  kDebug() << "main | parse options |"
572  << "End time after conversion:"
573  << "(" << endtime.toString() << ")";
574  } else {
575  variables.setFloating( true );
576  kDebug() << "main | parse options |"
577  << "Floating event time specified";
578  }
579  }
580 
581  /*
582  * Set start date/time from epoch
583  */
584  time_t epochstart = 0;
585  if ( args->isSet( "epoch-start" ) ) {
586  option = args->getOption( "epoch-start" );
587 
588  kDebug() << "main | parse options |"
589  << "Epoch start:"
590  << "(" << option << ")";
591 
592  epochstart = ( time_t ) option.toULong( 0, 10 );
593  }
594 
595  /*
596  * Set end date/time from epoch
597  */
598  time_t epochend = 0;
599  if ( args->isSet( "epoch-end" ) ) {
600  option = args->getOption( "epoch-end" );
601 
602  kDebug() << "main | parse options |"
603  << "Epoch end:"
604  << "(" << option << ")";
605 
606  epochend = ( time_t ) option.toULong( 0, 10 );
607  }
608 
609  if ( args->isSet( "all" ) ) {
610  variables.setAll( true );
611  } else {
612  variables.setAll( false );
613  }
614 
615  if ( args->isSet( "import" ) ) {
616  view = false;
617  importFile = true;
618  option = args->getOption( "import" );
619  variables.setImportFile( option );
620 
621  kDebug() << "main | parse options |"
622  << "importing file from:"
623  << "(" << option << ")";
624  }
625 
626  KonsoleKalendar *konsolekalendar = new KonsoleKalendar( &variables );
627 
628  if (args->isSet("list-calendars")) {
629  konsolekalendar->printCalendarList();
630  return 0;
631  }
632 
633  QEventLoop loop;
634  Akonadi::FetchJobCalendar::Ptr calendar = Akonadi::FetchJobCalendar::Ptr( new Akonadi::FetchJobCalendar() );
635  QObject::connect(calendar.data(), SIGNAL(loadFinished(bool,QString)), &loop, SLOT(quit()));
636  kDebug() << "Starting to load calendar";
637  QElapsedTimer t;
638  t.start();
639  loop.exec();
640  kDebug() << "Calendar loaded in" << t.elapsed() << "ms; success=" << calendar->isLoaded() << "; num incidences=" << calendar->incidences().count();
641 
642  if ( !args->isSet( "import" ) ) {
643  variables.setCalendar( calendar );
644  }
645 
646  /***************************************************************************
647  * Glorious date/time checking and setting code *
648  ***************************************************************************/
649  QDateTime startdatetime, enddatetime;
650 
651  // Handle case with either date or end-date unspecified
652  if ( !args->isSet( "end-date" ) && !args->isSet( "show-next" ) &&
653  args->isSet( "date" ) ) {
654  enddate = startdate;
655  kDebug() << "main | datetimestamp |"
656  << "setting enddate to startdate";
657  } else if ( args->isSet( "end-date" ) && !args->isSet( "date" ) ) {
658  startdate = enddate;
659  kDebug() << "main | datetimestamp |"
660  << "setting startdate to enddate";
661  }
662 
663  // NOTE: If neither date nor end-date specified, then event will be today.
664 
665  // Case:
666  // End time (or epoch) unspecified, and start time (or epoch) IS specified.
667  // In this case, set the ending to 1 hour after starting.
668  if ( !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) {
669  if ( args->isSet( "time" ) ) {
670  endtime = starttime.addSecs( 60 * 60 ); // end is 1 hour after start
671  kDebug() << "main | datetimestamp |"
672  << "setting endtime 1 hour after starttime";
673  } else if ( args->isSet( "epoch-start" ) ) {
674  startdatetime = epochs.epoch2QDateTime( epochstart );
675  enddatetime = startdatetime.addSecs( 60 * 60 );
676  kDebug() << "main | datetimestamp |"
677  << "setting endtime 1 hour after epochstart";
678  }
679  }
680 
681  // Case:
682  // Time (or epoch) unspecified, and end-time (or epoch) IS specified.
683  // In this case, set the starting to 1 hour before ending.
684  if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) ) {
685  if ( args->isSet( "end-time" ) ) {
686  starttime = endtime.addSecs( -60 * 60 ); // start is 1 hour before end
687  kDebug() << "main | datetimestamp |"
688  << "setting starttime 1 hour before endtime";
689  } else if ( args->isSet( "epoch-end" ) ) {
690  enddatetime = epochs.epoch2QDateTime( epochend );
691  startdatetime = enddatetime.addSecs( -60 * 60 );
692  kDebug() << "main | datetimestamp |"
693  << "setting starttime 1 before after epochend";
694  }
695  }
696 
697  // Case:
698  // Time (or epoch) unspecified, and end-time (or epoch) unspecified.
699  if ( !args->isSet( "time" ) && !args->isSet( "epoch-start" ) &&
700  !args->isSet( "end-time" ) && !args->isSet( "epoch-end" ) ) {
701  // set default start date/time
702  startdatetime = QDateTime( startdate, starttime );
703  kDebug() << "main | datetimestamp |"
704  << "setting startdatetime from"
705  << "default startdate (today) and starttime";
706  // set default end date/time
707  enddatetime = QDateTime( enddate, endtime );
708  kDebug() << "main | datetimestamp |"
709  << "setting enddatetime from"
710  << "default enddate (today) and endtime";
711  }
712 
713  // Set startdatetime, enddatetime if still necessary
714  if ( startdatetime.isNull() ) {
715  startdatetime = QDateTime( startdate, starttime );
716  kDebug() << "main | datetimestamp |"
717  << "setting startdatetime from startdate and starttime";
718  }
719  if ( enddatetime.isNull() ) {
720  enddatetime = QDateTime( enddate, endtime );
721  kDebug() << "main | datetimestamp |"
722  << "setting enddatetime from enddate and endtime";
723  }
724 
725  // Float check for add mode:
726  // Events float if time AND end-time AND epoch times are UNspecified
727  if ( add ) {
728  if ( !args->isSet( "time" ) && !args->isSet( "end-time" ) &&
729  !args->isSet( "epoch-start" ) && !args->isSet( "epoch-end" ) ) {
730  variables.setFloating( true );
731  kDebug() << "main | floatingcheck |"
732  << "turn-on floating event";
733  }
734  }
735 
736  // Finally! Set the start/end date times
737  if ( !change ) {
738  variables.setStartDateTime( startdatetime );
739  variables.setEndDateTime( enddatetime );
740  } else {
741  // Do NOT set start/end datetimes in change mode,
742  // unless they were specified on commandline
743  if ( args->isSet( "time" ) || args->isSet( "epoch-start" ) ||
744  args->isSet( "end-time" ) || args->isSet( "epoch-end" ) ) {
745  variables.setStartDateTime( startdatetime );
746  variables.setEndDateTime( enddatetime );
747  }
748  }
749 
750  // Some more debug prints
751  kDebug() << "main | datetimestamp | StartDate="
752  << startdatetime.toString( Qt::TextDate );
753  kDebug() << "main | datetimestamp | EndDate="
754  << enddatetime.toString( Qt::TextDate );
755 
756  /***************************************************************************
757  * Sanity checks *
758  ***************************************************************************/
759 
760  // Cannot combine modes
761  if ( create + view + add + change + del > 1 ) {
762  cout << i18n( "Only 1 operation mode "
763  "(view, add, change, delete, create) "
764  "permitted at any one time" ).toLocal8Bit().data() << endl;
765  return 1;
766  }
767 
768  // Cannot have a ending before starting
769  if ( startdatetime > enddatetime ) {
770  cout << i18n( "Ending Date/Time occurs before the Starting Date/Time" ).toLocal8Bit().data()
771  << endl;
772  return 1;
773  }
774 
775  /***************************************************************************
776  * And away we go with the real work... *
777  ***************************************************************************/
778 
779  args->clear(); // Free up some memory.
780 
781  /*
782  * Set our application name for use in unique IDs and error messages,
783  * and product ID for incidence PRODID property
784  */
785  QString prodId = QLatin1String("-//K Desktop Environment//NONSGML %1 %2//EN");
786  CalFormat::setApplication( QLatin1String(progDisplay),
787  prodId.arg( QLatin1String(progDisplay) ).arg( QLatin1String(progVersion) ) );
788 
789  if ( importFile ) {
790  if ( konsolekalendar->importCalendar() ) {
791  cout << i18n( "Calendar %1 successfully imported",
792  variables.getImportFile() ).toLocal8Bit().data()
793  << endl;
794  return 0;
795  } else {
796  cout << i18n( "Unable to import calendar: %1",
797  variables.getImportFile() ).toLocal8Bit().data()
798  << endl;
799  return 1;
800  }
801  }
802 
803  if ( add ) {
804  if ( !konsolekalendar->isEvent( startdatetime, enddatetime,
805  variables.getSummary() ) ) {
806  kDebug() << "main | modework |"
807  << "calling addEvent()";
808  konsolekalendar->addEvent();
809  } else {
810  cout << i18n( "Attempting to insert an event that already exists" ).toLocal8Bit().data()
811  << endl;
812  return 1;
813  }
814  }
815 
816  if ( change ) {
817  kDebug() << "main | modework |"
818  << "calling changeEvent()";
819  if ( !variables.isUID() ) {
820  cout << i18n( "Missing event UID: "
821  "use --uid command line option" ).toLocal8Bit().data()
822  << endl;
823  return 1;
824  }
825  if ( !konsolekalendar->changeEvent() ) {
826  cout << i18n( "No such event UID: change event failed" ).toLocal8Bit().data()
827  << endl;
828  return 1;
829  }
830  kDebug() << "main | modework |"
831  << "successful changeEvent()";
832  }
833 
834  if ( del ) {
835  kDebug() << "main | modework |"
836  << "calling deleteEvent()";
837  if ( !variables.isUID() ) {
838  cout << i18n( "Missing event UID: "
839  "use --uid command line option" ).toLocal8Bit().data()
840  << endl;
841  return 1;
842  }
843  if ( !konsolekalendar->deleteEvent() ) {
844  cout << i18n( "No such event UID: delete event failed" ).toLocal8Bit().data()
845  << endl;
846  return 1;
847  }
848  kDebug() << "main | modework |"
849  << "successful deleteEvent()";
850  }
851 
852  if ( view ) {
853  kDebug() << "main | modework |"
854  << "calling showInstance() to view events";
855  if ( !konsolekalendar->showInstance() ) {
856  cout << i18n( "Cannot open specified export file: %1",
857  variables.getExportFile() ).toLocal8Bit().data()
858  << endl;
859  return 1;
860  }
861  }
862 
863  delete konsolekalendar;
864 
865 
866  kDebug() << "main | exiting";
867 
868  return 0;
869 }
870 //@endcond
ExportTypeMonthHTML
Export HTML for the time span on month boundaries.
Definition: konsolekalendarvariables.h:56
KonsoleKalendarVariables::setAll
void setAll(bool all)
View all option.
Definition: konsolekalendarvariables.cpp:251
KonsoleKalendar::changeEvent
bool changeEvent()
Change event.
Definition: konsolekalendar.cpp:414
KonsoleKalendar::printCalendarList
bool printCalendarList()
Prints the available calendars.
Definition: konsolekalendar.cpp:81
KonsoleKalendarVariables::setDescription
void setDescription(const QString &description)
Add description.
Definition: konsolekalendarvariables.cpp:261
KonsoleKalendarVariables::setUseJournals
void setUseJournals(bool useJournals)
Set switch to use Journals.
Definition: konsolekalendarvariables.cpp:180
KonsoleKalendarVariables::setDaysCount
void setDaysCount(int count)
Sets how many day should be seen.
Definition: konsolekalendarvariables.cpp:319
KonsoleKalendarVariables::setAllowGui
void setAllowGui(bool allow)
Sets whether to allow using resources with potential GUI dependencies.
Definition: konsolekalendarvariables.cpp:335
KonsoleKalendarVariables::setStartDateTime
void setStartDateTime(const QDateTime &start)
Sets start date.
Definition: konsolekalendarvariables.cpp:98
KonsoleKalendarVariables::getExportFile
QString getExportFile() const
To what file we'll output.
Definition: konsolekalendarvariables.cpp:241
KonsoleKalendarVariables::getSummary
QString getSummary() const
Get summary.
Definition: konsolekalendarvariables.cpp:299
ExportTypeTextShort
Export as compact text.
Definition: konsolekalendarvariables.h:52
KonsoleKalendarVariables::setVerbose
void setVerbose(bool verbose)
Should program be more verbose?
Definition: konsolekalendarvariables.cpp:140
KonsoleKalendarVariables
This class provides all the variables for the program.
Definition: konsolekalendarvariables.h:73
KonsoleKalendarVariables::isUID
bool isUID() const
Is there UID set?
Definition: konsolekalendarvariables.cpp:93
KonsoleKalendarVariables::setLocation
void setLocation(const QString &location)
Add location information.
Definition: konsolekalendarvariables.cpp:277
konsolekalendar.h
Provides the KonsoleKalendar class definition.
KonsoleKalendarVariables::setNext
void setNext(bool next)
Show only next activity and exit.
Definition: konsolekalendarvariables.cpp:130
KonsoleKalendarVariables::setCollectionId
void setCollectionId(Akonadi::Collection::Id)
Definition: konsolekalendarvariables.cpp:340
KonsoleKalendarVariables::setExportFile
void setExportFile(const QString &export_file)
Sets the output file name to export_file.
Definition: konsolekalendarvariables.cpp:230
KonsoleKalendarVariables::setSummary
void setSummary(const QString &summary)
Add summary.
Definition: konsolekalendarvariables.cpp:293
KonsoleKalendar::addEvent
bool addEvent()
Add event to calendar.
Definition: konsolekalendar.cpp:404
KonsoleKalendarVariables::getImportFile
QString getImportFile() const
Return import filename.
Definition: konsolekalendarvariables.cpp:205
KonsoleKalendarVariables::setUID
void setUID(const QString &uid)
Sets the UID, the unique tag for VCard entry.
Definition: konsolekalendarvariables.cpp:82
KonsoleKalendarVariables::setUseEvents
void setUseEvents(bool useEvents)
Set switch to use Events.
Definition: konsolekalendarvariables.cpp:160
konsolekalendarepoch.h
Provides the KonsoleKalendarEpoch class definition.
KonsoleKalendarVariables::setDryRun
void setDryRun(bool dryrun)
Should we only try to run it and do nothing?
Definition: konsolekalendarvariables.cpp:150
KonsoleKalendar::showInstance
bool showInstance()
Visualize what we need.
Definition: konsolekalendar.cpp:161
ExportTypeHTML
Export HTML for the specified time span.
Definition: konsolekalendarvariables.h:54
KonsoleKalendarVariables::setImportFile
void setImportFile(const QString &calendar)
Set file to import active calendar.
Definition: konsolekalendarvariables.cpp:200
KonsoleKalendar::importCalendar
bool importCalendar()
Imports calendar file.
Definition: konsolekalendar.cpp:73
KonsoleKalendarVariables::setFloating
void setFloating(bool floating)
Set if Event is floating.
Definition: konsolekalendarvariables.cpp:309
KonsoleKalendarVariables::setEndDateTime
void setEndDateTime(const QDateTime &end)
Sets end date.
Definition: konsolekalendarvariables.cpp:114
KonsoleKalendarVariables::getDaysCount
int getDaysCount() const
Get how many day should be seen.
Definition: konsolekalendarvariables.cpp:325
KonsoleKalendarVariables::setExportType
void setExportType(ExportType exportType)
Sets the ExportType to use.
Definition: konsolekalendarvariables.cpp:220
KonsoleKalendar::isEvent
bool isEvent(const QDateTime &startdate, const QDateTime &enddate, const QString &summary)
Detect if event already exists.
Definition: konsolekalendar.cpp:435
KonsoleKalendarVariables::setCalendar
void setCalendar(const Akonadi::FetchJobCalendar::Ptr &)
Sets the calendar resources for global use.
Definition: konsolekalendarvariables.cpp:210
KonsoleKalendar::deleteEvent
bool deleteEvent()
Delete event.
Definition: konsolekalendar.cpp:425
KonsoleKalendarEpoch::epoch2QDateTime
static QDateTime epoch2QDateTime(uint epoch)
Converts epoch time to QDateTime format.
Definition: konsolekalendarepoch.cpp:52
ExportTypeCSV
Export Comma-Separated Values.
Definition: konsolekalendarvariables.h:62
KonsoleKalendarVariables::setUseTodos
void setUseTodos(bool useTodos)
Set switch to use Todos.
Definition: konsolekalendarvariables.cpp:170
KonsoleKalendar
The base class of the project.
Definition: konsolekalendar.h:50
ExportTypeText
Export as text (default)
Definition: konsolekalendarvariables.h:50
KonsoleKalendarEpoch
Class for timestamps expressed as epochs.
Definition: konsolekalendarepoch.h:43
konsolekalendarvariables.h
Provides the KonsoleKalendarVariables class definition.
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:04 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KonsoleKalendar

Skip menu "KonsoleKalendar"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal