TDE personal information management applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.1 KiB

  1. /*
  2. This file is part of libkcal.
  3. Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
  4. Copyright (C) 2005 Reinhold Kainhofer <reinhold@kainhofe.com>
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. Boston, MA 02110-1301, USA.
  17. */
  18. #include "calendarlocal.h"
  19. extern "C" {
  20. #include "libical/icaltimezone.h"
  21. }
  22. #include <tdeaboutdata.h>
  23. #include <tdeapplication.h>
  24. #include <kdebug.h>
  25. #include <tdecmdlineargs.h>
  26. #include <tqfile.h>
  27. using namespace KCal;
  28. static const TDECmdLineOptions options[] =
  29. {
  30. { "verbose", "Verbose output", 0 },
  31. { "+input", "Name of input file", 0 },
  32. { "[+output]", "optional name of output file for the recurrence dates", 0 },
  33. TDECmdLineLastOption
  34. };
  35. int main( int argc, char **argv )
  36. {
  37. TDEAboutData aboutData( "testrecurrencenew", "Load recurrence rules with the new class and print out debug messages", "0.1" );
  38. TDECmdLineArgs::init( argc, argv, &aboutData );
  39. TDECmdLineArgs::addCmdLineOptions( options );
  40. TDEApplication app( false, false );
  41. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  42. if ( args->count() < 1 ) {
  43. args->usage( "Wrong number of arguments." );
  44. }
  45. TQString input = TQFile::decodeName( args->arg( 0 ) );
  46. kdDebug(5800) << "Input file: " << input << endl;
  47. TQTextStream *outstream;
  48. outstream = 0;
  49. TQString fn("");
  50. if ( args->count() > 1 ) {
  51. fn = args->arg( 1 );
  52. kdDebug() << "We have a file name given: " << fn << endl;
  53. }
  54. TQFile outfile( fn );
  55. if ( !fn.isEmpty() && outfile.open( IO_WriteOnly ) ) {
  56. kdDebug() << "Opened output file!!!" << endl;
  57. outstream = new TQTextStream( &outfile );
  58. }
  59. CalendarLocal cal( TQString::fromLatin1("UTC") );
  60. if ( !cal.load( input ) ) return 1;
  61. TQString tz = cal.nonKDECustomProperty( "X-LibKCal-Testsuite-OutTZ" );
  62. if ( !tz.isEmpty() ) {
  63. cal.setTimeZoneIdViewOnly( tz );
  64. }
  65. Incidence::List inc = cal.incidences();
  66. for ( Incidence::List::Iterator it = inc.begin(); it != inc.end(); ++it ) {
  67. Incidence *incidence = *it;
  68. kdDebug(5800) << "*+*+*+*+*+*+*+*+*+*" << endl;
  69. kdDebug(5800) << " -> " << incidence->summary() << " <- " << endl;
  70. incidence->recurrence()->dump();
  71. TQDateTime dt( incidence->recurrence()->endDateTime() );
  72. int i=0;
  73. if ( outstream ) {
  74. if ( !dt.isValid() ) dt = TQDateTime( TQDate( 2011, 1, 1 ), TQTime( 0, 0, 1 ) );
  75. else dt = dt.addYears( 2 );
  76. kdDebug(5800) << "-------------------------------------------" << endl;
  77. kdDebug(5800) << " *~*~*~*~ Starting with date: " << dt << endl;
  78. // Output to file for testing purposes
  79. while (dt.isValid() && i<500 ) {
  80. dt = dt.addSecs( -1 );
  81. ++i;
  82. dt = incidence->recurrence()->getPreviousDateTime( dt );
  83. (*outstream) << dt.toString( TQt::ISODate ) << endl;
  84. }
  85. } else {
  86. if ( !dt.isValid() ) dt = TQDateTime( TQDate( 2005, 7, 31 ), TQTime( 23, 59, 59 ) );
  87. else dt = dt.addYears( 2 );
  88. incidence->recurrence()->dump();
  89. kdDebug(5800) << "-------------------------------------------" << endl;
  90. kdDebug(5800) << " *~*~*~*~ Starting with date: " << dt << endl;
  91. // Output to konsole
  92. while ( dt.isValid() && i<50 ) {
  93. dt = dt.addSecs( -1 );
  94. ++i;
  95. kdDebug(5800) << "-------------------------------------------" << endl;
  96. dt = incidence->recurrence()->getPreviousDateTime( dt );
  97. kdDebug(5800) << " *~*~*~*~ Previous date is: " << dt << endl;
  98. }
  99. }
  100. }
  101. delete outstream;
  102. outfile.close();
  103. return 0;
  104. }