knotes Library API Documentation

resourcemanager.cpp

00001 /******************************************************************* 00002 This file is part of KNotes. 00003 00004 Copyright (c) 2004, Bo Thorsen <bo@klaralvdalens-datakonsult.se> 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., 59 Temple Place - Suite 330, Boston, 00020 MA 02111-1307, 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/resourcemanager.h" 00035 #include "knotes/resourcelocal.h" 00036 00037 #include <libkcal/journal.h> 00038 00039 00040 KNotesResourceManager::KNotesResourceManager() 00041 : QObject( 0, "KNotes Resource Manager" ) 00042 { 00043 m_manager = new KRES::Manager<ResourceNotes>( "notes" ); 00044 m_manager->addObserver( this ); 00045 m_manager->readConfig(); 00046 } 00047 00048 KNotesResourceManager::~KNotesResourceManager() 00049 { 00050 delete m_manager; 00051 } 00052 00053 void KNotesResourceManager::load() 00054 { 00055 if ( !m_manager->standardResource() ) 00056 { 00057 kdWarning(5500) << "No standard resource yet." << endl; 00058 ResourceNotes *resource = new ResourceLocal( 0 ); 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 { 00067 kdDebug(5500) << "Opening resource " + (*it)->resourceName() << endl; 00068 (*it)->setManager( this ); 00069 if ( (*it)->open() ) 00070 (*it)->load(); 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 // when adding a new note, make sure a config file exists!! 00082 00083 void KNotesResourceManager::addNewNote( KCal::Journal *journal ) 00084 { 00085 // TODO: Make this configurable 00086 ResourceNotes *resource = m_manager->standardResource(); 00087 if ( resource ) 00088 { 00089 resource->addNote( journal ); 00090 registerNote( resource, journal ); 00091 } 00092 else 00093 kdWarning(5500) << k_funcinfo << "no resource!" << endl; 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 emit sigDeregisteredNote( journal ); 00112 } 00113 00114 void KNotesResourceManager::resourceAdded( ResourceNotes *resource ) 00115 { 00116 kdDebug(5500) << "Resource added: " << resource->resourceName() << endl; 00117 00118 if ( !resource->isActive() ) 00119 return; 00120 00121 resource->setManager( this ); 00122 if ( resource->open() ) 00123 resource->load(); 00124 } 00125 00126 void KNotesResourceManager::resourceModified( ResourceNotes *resource ) 00127 { 00128 kdDebug(5500) << "Resource modified: " << resource->resourceName() << endl; 00129 } 00130 00131 void KNotesResourceManager::resourceDeleted( ResourceNotes *resource ) 00132 { 00133 kdDebug(5500) << "Resource deleted: " << resource->resourceName() << endl; 00134 } 00135 00136 00137 #include "resourcemanager.moc"
KDE Logo
This file is part of the documentation for knotes Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:15 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003