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

knotes

resourcemanager.cpp

Go to the documentation of this file.
00001 /*******************************************************************
00002  This file is part of KNotes.
00003 
00004  Copyright (c) 2004, Bo Thorsen <bo@sonofthor.dk>
00005                2004, Michael Brade <brade@kde.org>
00006 
00007  This program is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  This program is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with this program; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00020  MA  02110-1301, USA.
00021 
00022  In addition, as a special exception, the copyright holders give
00023  permission to link the code of this program with any edition of
00024  the Qt library by Trolltech AS, Norway (or with modified versions
00025  of Qt that use the same license as Qt), and distribute linked
00026  combinations including the two.  You must obey the GNU General
00027  Public License in all respects for all of the code used other than
00028  Qt.  If you modify this file, you may extend this exception to
00029  your version of the file, but you are not obligated to do so.  If
00030  you do not wish to do so, delete this exception statement from
00031  your version.
00032 *******************************************************************/
00033 
00034 #include "knotes/resourcelocal.h"
00035 #include "knotes/resourcemanager.h"
00036 
00037 #include <kcal/journal.h>
00038 
00039 
00040 KNotesResourceManager::KNotesResourceManager()
00041   : QObject( 0 )
00042 {
00043   setObjectName( "KNotes Resource Manager" );
00044   m_manager = new KRES::Manager<ResourceNotes>( "notes" );
00045   m_manager->addObserver( this );
00046   m_manager->readConfig();
00047 }
00048 
00049 KNotesResourceManager::~KNotesResourceManager()
00050 {
00051   delete m_manager;
00052 }
00053 
00054 void KNotesResourceManager::load()
00055 {
00056   if ( !m_manager->standardResource() ) {
00057     kWarning( 5500 ) << "No standard resource yet.";
00058     ResourceNotes *resource = new ResourceLocal();
00059     m_manager->add( resource );
00060     m_manager->setStandardResource( resource );
00061   }
00062   
00063   // Open all active resources
00064   KRES::Manager<ResourceNotes>::ActiveIterator it;
00065   for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) {
00066     kDebug( 5500 ) << "Opening resource " + ( *it )->resourceName();
00067     ( *it )->setManager( this );
00068     if ( ( *it )->open() ) {
00069       ( *it )->load();
00070     }
00071   }
00072 }
00073 
00074 void KNotesResourceManager::save()
00075 {
00076   KRES::Manager<ResourceNotes>::ActiveIterator it;
00077   for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) {
00078     ( *it )->save();
00079   }
00080 }
00081 
00082 // when adding a new note, make sure a config file exists!!
00083 
00084 void KNotesResourceManager::addNewNote( KCal::Journal *journal )
00085 {
00086   // TODO: Make this configurable
00087   ResourceNotes *resource = m_manager->standardResource();
00088   if ( resource ) {
00089     resource->addNote( journal );
00090     registerNote( resource, journal );
00091   } else {
00092     kWarning( 5500 ) << "no resource!";
00093   }
00094 }
00095 
00096 void KNotesResourceManager::registerNote( ResourceNotes *resource,
00097                                           KCal::Journal *journal )
00098 {
00099   // TODO: only emit the signal if the journal is new?
00100   m_resourceMap.insert( journal->uid(), resource );
00101   emit sigRegisteredNote( journal );
00102 }
00103 
00104 void KNotesResourceManager::deleteNote( KCal::Journal *journal )
00105 {
00106   QString uid = journal->uid();
00107   
00108   // Remove the journal from the resource it came from
00109   m_resourceMap[ uid ]->deleteNote( journal );
00110   m_resourceMap.remove( uid );
00111   
00112   // libkcal does not delete the journal immediately, therefore it is ok to
00113   // emit the journal here
00114   emit sigDeregisteredNote( journal );
00115 }
00116 
00117 KCal::Alarm::List KNotesResourceManager::alarms( const KDateTime &from,
00118                                                  const KDateTime &to )
00119 {
00120   KCal::Alarm::List result;
00121   
00122   KRES::Manager<ResourceNotes>::ActiveIterator it;
00123   for ( it = m_manager->activeBegin(); it != m_manager->activeEnd(); ++it ) {
00124     KCal::Alarm::List list = ( *it )->alarms( from, to );
00125     KCal::Alarm::List::Iterator it;
00126     for ( it = list.begin(); it != list.end(); ++it ) {
00127       result.append( *it );
00128     }
00129   }
00130   
00131   return result;
00132 }
00133 
00134 void KNotesResourceManager::resourceAdded( ResourceNotes *resource )
00135 {
00136   kDebug( 5500 ) << "Resource added:" << resource->resourceName();
00137   
00138   if ( !resource->isActive() ) {
00139     return;
00140   }
00141   
00142   resource->setManager( this );
00143   if ( resource->open() ) {
00144     resource->load();
00145   }
00146 }
00147 
00148 void KNotesResourceManager::resourceModified( ResourceNotes *resource )
00149 {
00150   kDebug( 5500 ) << "Resource modified:" << resource->resourceName();
00151 }
00152 
00153 void KNotesResourceManager::resourceDeleted( ResourceNotes *resource )
00154 {
00155   kDebug( 5500 ) << "Resource deleted:" << resource->resourceName();
00156 }
00157 
00158 
00159 #include "resourcemanager.moc"

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal