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 KNotes.
  3. Copyright (c) 2004, Bo Thorsen <bo@sonofthor.dk>
  4. 2004-2006, Michael Brade <brade@kde.org>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program 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
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. MA 02110-1301, USA.
  17. In addition, as a special exception, the copyright holders give
  18. permission to link the code of this program with any edition of
  19. the TQt library by Trolltech AS, Norway (or with modified versions
  20. of TQt that use the same license as TQt), and distribute linked
  21. combinations including the two. You must obey the GNU General
  22. Public License in all respects for all of the code used other than
  23. TQt. If you modify this file, you may extend this exception to
  24. your version of the file, but you are not obligated to do so. If
  25. you do not wish to do so, delete this exception statement from
  26. your version.
  27. *******************************************************************/
  28. #include <tdelocale.h>
  29. #include <tdemessagebox.h>
  30. #include <kstandarddirs.h>
  31. #include <libkcal/icalformat.h>
  32. #include "knotes/resourcelocal.h"
  33. #include "knotes/resourcelocalconfig.h"
  34. #include "knotes/resourcemanager.h"
  35. #include "knotes/resourcenotes.h"
  36. ResourceLocal::ResourceLocal( const TDEConfig *config )
  37. : ResourceNotes( config ), mCalendar( TQString::fromLatin1( "UTC" ) )
  38. {
  39. kdDebug(5500) << "ResourceLocal::ResourceLocal()" << endl;
  40. setType( "file" );
  41. mURL = TDEGlobal::dirs()->saveLocation( "data", "knotes/" ) + "notes.ics";
  42. if ( config )
  43. {
  44. KURL u = config->readPathEntry( "NotesURL" );
  45. if ( !u.isEmpty() )
  46. mURL = u;
  47. }
  48. }
  49. ResourceLocal::~ResourceLocal()
  50. {
  51. }
  52. void ResourceLocal::writeConfig( TDEConfig *config )
  53. {
  54. KRES::Resource::writeConfig( config );
  55. config->writePathEntry( "NotesURL", mURL.prettyURL() );
  56. }
  57. bool ResourceLocal::load()
  58. {
  59. mCalendar.load( mURL.path() );
  60. KCal::Journal::List notes = mCalendar.journals();
  61. KCal::Journal::List::ConstIterator it;
  62. for ( it = notes.constBegin(); it != notes.constEnd(); ++it )
  63. manager()->registerNote( this, *it );
  64. return true;
  65. }
  66. bool ResourceLocal::save()
  67. {
  68. if ( !mCalendar.save( mURL.path(), new KCal::ICalFormat() ) )
  69. {
  70. KMessageBox::error( 0,
  71. i18n("<qt>Unable to save the notes to <b>%1</b>. "
  72. "Check that there is sufficient disk space."
  73. "<br>There should be a backup in the same directory "
  74. "though.</qt>").arg( mURL.path() ) );
  75. return false;
  76. }
  77. return true;
  78. }
  79. bool ResourceLocal::addNote( KCal::Journal *journal )
  80. {
  81. return mCalendar.addJournal( journal );
  82. }
  83. bool ResourceLocal::deleteNote( KCal::Journal *journal )
  84. {
  85. return mCalendar.deleteJournal( journal );
  86. }
  87. KCal::Alarm::List ResourceLocal::alarms( const TQDateTime& from, const TQDateTime& to )
  88. {
  89. KCal::Alarm::List alarms;
  90. KCal::Journal::List notes = mCalendar.journals();
  91. KCal::Journal::List::ConstIterator note;
  92. for ( note = notes.constBegin(); note != notes.constEnd(); ++note )
  93. {
  94. TQDateTime preTime = from.addSecs( -1 );
  95. KCal::Alarm::List::ConstIterator it;
  96. for( it = (*note)->alarms().constBegin(); it != (*note)->alarms().constEnd(); ++it )
  97. {
  98. if ( (*it)->enabled() )
  99. {
  100. TQDateTime dt = (*it)->nextRepetition( preTime );
  101. if ( dt.isValid() && dt <= to )
  102. alarms.append( *it );
  103. }
  104. }
  105. }
  106. return alarms;
  107. }