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.
 
 
 
 
 
 

175 lines
5.3 KiB

  1. /*******************************************************************
  2. This file is part of KNotes.
  3. Copyright (c) 2004, Bo Thorsen <bo@sonofthor.dk>
  4. 2004, 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 "knotes/resourcemanager.h"
  29. #include "knotes/resourcelocal.h"
  30. #include <libkcal/journal.h>
  31. KNotesResourceManager::KNotesResourceManager()
  32. : TQObject( 0, "KNotes Resource Manager" )
  33. {
  34. m_manager = new KRES::Manager<ResourceNotes>( "notes" );
  35. m_manager->addObserver( this );
  36. m_manager->readConfig();
  37. }
  38. KNotesResourceManager::~KNotesResourceManager()
  39. {
  40. delete m_manager;
  41. }
  42. void KNotesResourceManager::load()
  43. {
  44. if ( !m_manager->standardResource() )
  45. {
  46. kdWarning(5500) << "No standard resource yet." << endl;
  47. ResourceNotes *resource = new ResourceLocal( 0 );
  48. m_manager->add( resource );
  49. m_manager->setStandardResource( resource );
  50. }
  51. // Open all active resources
  52. KRES::Manager<ResourceNotes>::ActiveIterator it;
  53. for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it )
  54. {
  55. if ( (*it)->isOpen() ) {
  56. kdDebug(5500) << (*it)->resourceName() << " is already open" << endl;
  57. continue;
  58. }
  59. kdDebug(5500) << "Opening resource " + (*it)->resourceName() << endl;
  60. (*it)->setManager( this );
  61. if ( (*it)->open() )
  62. (*it)->load();
  63. }
  64. }
  65. void KNotesResourceManager::save()
  66. {
  67. KRES::Manager<ResourceNotes>::ActiveIterator it;
  68. for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it )
  69. (*it)->save();
  70. }
  71. // when adding a new note, make sure a config file exists!!
  72. bool KNotesResourceManager::addNewNote( KCal::Journal *journal )
  73. {
  74. // TODO: Make this configurable
  75. ResourceNotes *resource = m_manager->standardResource();
  76. if ( resource ) {
  77. if ( resource->addNote( journal ) ) {
  78. registerNote( resource, journal );
  79. return true;
  80. }
  81. } else {
  82. kdWarning(5500) << k_funcinfo << "no resource!" << endl;
  83. }
  84. return false;
  85. }
  86. void KNotesResourceManager::registerNote( ResourceNotes *resource,
  87. KCal::Journal *journal )
  88. {
  89. // TODO: only emit the signal if the journal is new?
  90. m_resourceMap.insert( journal->uid(), resource );
  91. emit sigRegisteredNote( journal );
  92. }
  93. void KNotesResourceManager::deleteNote( KCal::Journal *journal )
  94. {
  95. if ( !journal )
  96. return;
  97. TQString uid = journal->uid();
  98. // Remove the journal from the resource it came from
  99. ResourceNotes *res = m_resourceMap[ uid ];
  100. if ( res ) {
  101. res->deleteNote( journal );
  102. m_resourceMap.remove( uid );
  103. // libkcal does not delete the journal immediately, therefore it is ok to
  104. // emit the journal here
  105. emit sigDeregisteredNote( journal );
  106. }
  107. }
  108. KCal::Alarm::List KNotesResourceManager::alarms( const TQDateTime& from, const TQDateTime& to )
  109. {
  110. KCal::Alarm::List result;
  111. KRES::Manager<ResourceNotes>::ActiveIterator it;
  112. for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it )
  113. {
  114. KCal::Alarm::List list = (*it)->alarms( from, to );
  115. KCal::Alarm::List::ConstIterator it;
  116. for ( it = list.constBegin(); it != list.constEnd(); ++it )
  117. result.append( *it );
  118. }
  119. return result;
  120. }
  121. void KNotesResourceManager::resourceAdded( ResourceNotes *resource )
  122. {
  123. kdDebug(5500) << "Resource added: " << resource->resourceName() << endl;
  124. if ( !resource->isActive() )
  125. return;
  126. if ( resource->isOpen() ) {
  127. kdDebug(5500) << resource->resourceName() << " is already open" << endl;
  128. return;
  129. }
  130. resource->setManager( this );
  131. if ( resource->open() )
  132. resource->load();
  133. }
  134. void KNotesResourceManager::resourceModified( ResourceNotes *resource )
  135. {
  136. kdDebug(5500) << "Resource modified: " << resource->resourceName() << endl;
  137. }
  138. void KNotesResourceManager::resourceDeleted( ResourceNotes *resource )
  139. {
  140. kdDebug(5500) << "Resource deleted: " << resource->resourceName() << endl;
  141. }
  142. #include "resourcemanager.moc"