From e093d5d571fbd8439907fd85c5ef9e434dcfb8c9 Mon Sep 17 00:00:00 2001 From: tpearson Date: Thu, 6 May 2010 01:16:07 +0000 Subject: Fixed bug 180 and bug 146 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeaddons@1123404 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- konq-plugins/dirfilter/dirfilterplugin.cpp | 77 ++++++++++++++++++++---------- konq-plugins/dirfilter/dirfilterplugin.h | 3 ++ 2 files changed, 54 insertions(+), 26 deletions(-) (limited to 'konq-plugins') diff --git a/konq-plugins/dirfilter/dirfilterplugin.cpp b/konq-plugins/dirfilter/dirfilterplugin.cpp index eee1284..3e16bf4 100644 --- a/konq-plugins/dirfilter/dirfilterplugin.cpp +++ b/konq-plugins/dirfilter/dirfilterplugin.cpp @@ -199,11 +199,18 @@ DirFilterPlugin::DirFilterPlugin (QObject* parent, const char* name, KWidgetAction *filterAction = new KWidgetAction(hbox, i18n("Filter Field"), 0, 0, 0, actionCollection(), "toolbar_filter_field"); filterAction->setShortcutConfigurable(false); + + m_refreshTimer = new QTimer( this ); + connect( m_refreshTimer, SIGNAL(timeout()), this, SLOT(activateSearch()) ); + m_refreshTimer->start( 200, FALSE ); // 200 millisecond continuous timer + } DirFilterPlugin::~DirFilterPlugin() { + m_refreshTimer->stop(); delete m_pFilterMenu; + delete m_refreshTimer; } void DirFilterPlugin::slotOpenURL () @@ -396,7 +403,6 @@ void DirFilterPlugin::slotItemsAdded (const KFileItemList& list) { static_cast(m_searchWidget)->updateSearch(); } - //m_searchWidget->updateSearch(); // Make sure the filter menu is enabled once a named // filter is removed. @@ -415,8 +421,7 @@ void DirFilterPlugin::slotItemsAdded (const KFileItemList& list) { MimeInfo& mimeInfo = m_pMimeInfo[mimeType]; QStringList filters = m_part->mimeFilter (); - mimeInfo.useAsFilter = (!filters.isEmpty () && - filters.contains (mimeType)); + mimeInfo.useAsFilter = (!filters.isEmpty () && filters.contains (mimeType)); mimeInfo.mimeComment = mime->comment(); mimeInfo.iconName = mime->icon(KURL(), false); mimeInfo.filenames.insert(name, false); @@ -430,30 +435,50 @@ void DirFilterPlugin::slotItemsAdded (const KFileItemList& list) void DirFilterPlugin::slotItemRemoved (const KFileItem* item) { - if (!item || !m_part) - return; - - QString mimeType = item->mimetype().stripWhiteSpace(); - - if (m_pMimeInfo.contains (mimeType)) - { - MimeInfo info = m_pMimeInfo [mimeType]; + if (!item || !m_part) + return; + + // Due to the poor implementation of qiconviewitem, there is no way for it to know if an item on the hidden list was deleted + // This *will* eventually cause the kiconviewsearchline to attempt to reference a deleted object, resulting in a crash + // This is illustrated well with two Konqueror windows. Open one, set the filter bar to filter out a file, then delete the filtered file from another window. + // Now clear the search bar (forcing injection of the deleted iconview object pointer from the hidden list). Konqueror will crash! + // If iconDeleted is called, it allows kiconviewsearchline to temporarily add the affected qiconviewitem(s) (by filename) to the iconview so that as far as + // qiconview is concerned the qiconviewitem objects never left. + // NOTE: This bug is NOT present in qlistviewitem + + // HACK around it here... + if ( ::qt_cast(m_part->scrollWidget()) ) { + static_cast(m_searchWidget)->iconDeleted(item->name()); + } + + QString mimeType = item->mimetype().stripWhiteSpace(); + + if (m_pMimeInfo.contains (mimeType)) { + MimeInfo info = m_pMimeInfo [mimeType]; + + if (info.filenames.size () > 1) + m_pMimeInfo [mimeType].filenames.remove (item->name ()); + else { + if (info.useAsFilter) { + QStringList filters = m_part->mimeFilter (); + filters.remove (mimeType); + m_part->setMimeFilter (filters); + SessionManager::self()->save (m_part->url(), filters); + QTimer::singleShot( 0, this, SLOT(slotTimeout()) ); + } + m_pMimeInfo.remove (mimeType); + } + } +} - if (info.filenames.size () > 1) - m_pMimeInfo [mimeType].filenames.remove (item->name ()); - else - { - if (info.useAsFilter) - { - QStringList filters = m_part->mimeFilter (); - filters.remove (mimeType); - m_part->setMimeFilter (filters); - SessionManager::self()->save (m_part->url(), filters); - QTimer::singleShot( 0, this, SLOT(slotTimeout()) ); - } - m_pMimeInfo.remove (mimeType); - } - } +void DirFilterPlugin::activateSearch() +{ + if ( ::qt_cast(m_part->scrollWidget()) ) { + static_cast(m_searchWidget)->updateSearch(); + } + else if ( ::qt_cast(m_part->scrollWidget()) ) { + static_cast(m_searchWidget)->updateSearch(); + } } void DirFilterPlugin::slotReset() diff --git a/konq-plugins/dirfilter/dirfilterplugin.h b/konq-plugins/dirfilter/dirfilterplugin.h index f1c5b44..74ad8e2 100644 --- a/konq-plugins/dirfilter/dirfilterplugin.h +++ b/konq-plugins/dirfilter/dirfilterplugin.h @@ -20,6 +20,7 @@ #define __DIR_FILTER_PLUGIN_H #include +#include #include @@ -119,10 +120,12 @@ private slots: void slotItemSelected(int); void slotItemRemoved(const KFileItem *); void slotItemsAdded(const KFileItemList &); + void activateSearch(); private: KURL m_pURL; KonqDirPart* m_part; + QTimer *m_refreshTimer; KActionMenu* m_pFilterMenu; KLineEdit *m_searchWidget; -- cgit v1.2.1