From kde-commits Tue Jun 30 21:45:50 2009 From: Jan Hambrecht Date: Tue, 30 Jun 2009 21:45:50 +0000 To: kde-commits Subject: koffice/libs/resources Message-Id: <1246398350.250047.23127.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=124653891819651 SVN commit 989770 by jaham: use the full filename as the key for identifying a resource add a blacklist used for omitting resources that could not be removed from the hard disk M +21 -11 KoResourceServer.h --- trunk/koffice/libs/resources/KoResourceServer.h #989769:989770 @@ -120,7 +120,7 @@ T* resource = createResource(front); if (resource->load() && resource->valid()) { - m_resourcesByFilename[fname] = resource; + m_resourcesByFilename[front] = resource; if ( resource->name().isNull() ) { resource->setName( fname ); @@ -147,8 +147,10 @@ kWarning(30009) << "Tried to add an invalid resource!"; return false; } - if( ! resource->save() ) + if( ! resource->save() ) { + kWarning(30009) << "Could not save resource!"; return false; + } Q_ASSERT( !resource->filename().isEmpty() || !resource->name().isEmpty() ); if ( resource->filename().isEmpty() ) { @@ -168,12 +170,12 @@ /// Remove a resource from resourceserver and hard disk bool removeResource(T* resource) { - - QString fname = QFileInfo(resource->filename()).fileName(); - if ( !m_resourcesByFilename.contains( fname ) ) { + if ( !m_resourcesByFilename.contains( resource->filename() ) ) { return false; } + bool removedFromDisk = true; + QFile file( resource->filename() ); if( ! file.remove() ) { @@ -183,22 +185,30 @@ // app-start. But if we cannot remove a resource from the // disk, remove it from the chooser at least. - //return false; + removedFromDisk = false; + kWarning(30009) << "Could not remove resource!"; } notifyRemovingResource(resource); - //m_resourcesByName.remove[resource->name()]; - //m_resourcesByFilename.remove[resource->filename()]; + if (removedFromDisk) { + m_resourcesByName.remove(resource->name()); + m_resourcesByFilename.remove(resource->filename()); + delete resource; + } else { + // TODO: save blacklist to config file and load it again on next start + m_resourceBlackList << resource; + } - delete resource; - return true; } QList resources() { loadLock.lock(); QList resourceList = m_resourcesByFilename.values(); + foreach(T* r, m_resourceBlackList) { + resourceList.removeOne(r); + } loadLock.unlock(); return resourceList; } @@ -313,7 +323,7 @@ QHash m_resourcesByName; QHash m_resourcesByFilename; - + QList m_resourceBlackList; QList*> m_observers; };