docindexwatcher.cpp
Go to the documentation of this file.00001 /*************************************************************************** 00002 * Copyright (C) 2004 by Hamish Rodda * 00003 * rodda@kde.org * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 00012 #include "docindexwatcher.h" 00013 00014 #include <kdirwatch.h> 00015 00016 #include "doctreeitem.h" 00017 00018 DocIndexWatcher::DocIndexWatcher(QObject* parent, const char* name) 00019 : QObject(parent, name) 00020 { 00021 connect(KDirWatch::self(), SIGNAL(dirty(const QString&)), SLOT(slotDirty(const QString&))); 00022 connect(KDirWatch::self(), SIGNAL(deleted(const QString&)), SLOT(slotDirty(const QString&))); 00023 } 00024 00025 void DocIndexWatcher::addItem(DocTreeItem* item) 00026 { 00027 if (!item->indexFileName().isEmpty() && !m_docs.find(item->indexFileName())) { 00028 m_docs.insert(item->indexFileName(), item); 00029 KDirWatch::self()->addFile(item->indexFileName()); 00030 } 00031 } 00032 00033 void DocIndexWatcher::removeItem(const DocTreeItem* item) 00034 { 00035 if (!item->indexFileName().isEmpty()) { 00036 KDirWatch::self()->removeFile(item->indexFileName()); 00037 m_docs.remove(item->indexFileName()); 00038 } 00039 } 00040 00041 void DocIndexWatcher::slotDirty( const QString & fileName ) 00042 { 00043 for (QDictIterator<DocTreeItem> it = m_docs; it.current(); ++it) 00044 if (it.currentKey() == fileName) { 00045 it.current()->setDirty(); 00046 break; 00047 } 00048 } 00049 00050 #include "docindexwatcher.moc"