Partial rewrite of kiconviewsearchline to prevent directory filter from crashing Konqueror (bug 180)

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1123390 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 15 years ago
parent c1b28a61b6
commit 1f9bff1381

@ -1,4 +1,5 @@
/* This file is part of the KDE libraries /* This file is part of the KDE libraries
Copyright (c) 2010 Timothy Pearson <kb9vqf@pearsoncomputing.net>
Copyright (c) 2004 Gustavo Sverzut Barbieri <gsbarbieri@users.sourceforge.net> Copyright (c) 2004 Gustavo Sverzut Barbieri <gsbarbieri@users.sourceforge.net>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@ -41,7 +42,7 @@ public:
iconView( 0 ), iconView( 0 ),
caseSensitive( DEFAULT_CASESENSITIVE ), caseSensitive( DEFAULT_CASESENSITIVE ),
activeSearch( false ), activeSearch( false ),
hiddenItemsLockout( false ), hiddenListChanged( 0 ),
queuedSearches( 0 ) {} queuedSearches( 0 ) {}
QIconView *iconView; QIconView *iconView;
@ -49,7 +50,7 @@ public:
bool activeSearch; bool activeSearch;
QString search; QString search;
int queuedSearches; int queuedSearches;
bool hiddenItemsLockout; int hiddenListChanged;
QIconViewItemList hiddenItems; QIconViewItemList hiddenItems;
}; };
@ -93,24 +94,23 @@ QIconView *KIconViewSearchLine::iconView() const
*****************************************************************************/ *****************************************************************************/
void KIconViewSearchLine::updateSearch( const QString &s ) void KIconViewSearchLine::updateSearch( const QString &s )
{ {
QIconView *iv = d->iconView; long original_count;
if( ! iv ) int original_hiddenListChanged;
if( ! d->iconView )
return; // disabled return; // disabled
QString search = d->search = s.isNull() ? text() : s; QString search = d->search = s.isNull() ? text() : s;
QIconViewItem *currentItem = d->iconView->currentItem();
QIconViewItem *currentItem = iv->currentItem();
QIconViewItem *item = NULL; QIconViewItem *item = NULL;
// Remove Non-Matching items, add them them to hidden list // Remove Non-Matching items, add them them to hidden list
QIconViewItem *i = iv->firstItem(); QIconViewItem *i = d->iconView->firstItem();
while ( i != NULL ) while ( i != NULL ) {
{
item = i; item = i;
i = i->nextItem(); // Point to next, otherwise will loose it. i = i->nextItem(); // Point to next, otherwise will loose it.
if ( ! itemMatches( item, search ) ) if ( ! itemMatches( item, search ) ) {
{
hideItem( item ); hideItem( item );
if ( item == currentItem ) if ( item == currentItem )
@ -119,28 +119,32 @@ void KIconViewSearchLine::updateSearch( const QString &s )
} }
// Add Matching items, remove from hidden list // Add Matching items, remove from hidden list
d->hiddenItemsLockout = true; original_count = d->hiddenItems.count();
QIconViewItemList::iterator it = d->hiddenItems.begin(); original_hiddenListChanged = d->hiddenListChanged;
while ( it != d->hiddenItems.end() ) for (QIconViewItemList::iterator it=d->hiddenItems.begin();it!=d->hiddenItems.end();++it) {
{
item = *it; item = *it;
++it; if ((original_count != d->hiddenItems.count()) || (original_hiddenListChanged != d->hiddenListChanged)) {
// The list has changed; pointers are now most likely invalid
// ABORT, but restart the search at the beginning
original_count = d->hiddenItems.count();
original_hiddenListChanged = d->hiddenListChanged;
it=d->hiddenItems.begin();
}
else {
if ( itemMatches( item, search ) ) if ( itemMatches( item, search ) )
showItem( item ); showItem( item );
} }
d->hiddenItemsLockout = false; }
d->iconView->sort();
iv->sort();
if ( currentItem != NULL ) if ( currentItem != NULL )
iv->ensureItemVisible( currentItem ); d->iconView->ensureItemVisible( currentItem );
} }
void KIconViewSearchLine::clear() void KIconViewSearchLine::clear()
{ {
// Clear hidden list, give items back to QIconView, if it still exists // Clear hidden list, give items back to QIconView, if it still exists
QIconViewItem *item = NULL; QIconViewItem *item = NULL;
d->hiddenItemsLockout = true;
QIconViewItemList::iterator it = d->hiddenItems.begin(); QIconViewItemList::iterator it = d->hiddenItems.begin();
while ( it != d->hiddenItems.end() ) while ( it != d->hiddenItems.end() )
{ {
@ -159,13 +163,31 @@ void KIconViewSearchLine::clear()
"hiddenItems is not empty as it should be. " << "hiddenItems is not empty as it should be. " <<
d->hiddenItems.count() << " items are still there.\n" << endl; d->hiddenItems.count() << " items are still there.\n" << endl;
d->hiddenItemsLockout= false;
d->search = ""; d->search = "";
d->queuedSearches = 0; d->queuedSearches = 0;
KLineEdit::clear(); KLineEdit::clear();
} }
void KIconViewSearchLine::iconDeleted(const QString &filename) {
// Clear hidden list, give items back to QIconView, if it still exists
QIconViewItem *item = NULL;
QIconViewItemList::iterator it = d->hiddenItems.begin();
while ( it != d->hiddenItems.end() )
{
item = *it;
++it;
if ( item != NULL )
{
if (item->text() == filename) {
if (d->iconView != NULL)
showItem( item );
else
delete item;
}
}
}
}
void KIconViewSearchLine::setCaseSensitive( bool cs ) void KIconViewSearchLine::setCaseSensitive( bool cs )
{ {
d->caseSensitive = cs; d->caseSensitive = cs;
@ -230,6 +252,7 @@ void KIconViewSearchLine::hideItem( QIconViewItem *item )
if ( ( item == NULL ) || ( d->iconView == NULL ) ) if ( ( item == NULL ) || ( d->iconView == NULL ) )
return; return;
d->hiddenListChanged++;
d->hiddenItems.append( item ); d->hiddenItems.append( item );
d->iconView->takeItem( item ); d->iconView->takeItem( item );
} }
@ -243,11 +266,10 @@ void KIconViewSearchLine::showItem( QIconViewItem *item )
endl; endl;
return; return;
} }
d->hiddenListChanged++;
d->iconView->insertItem( item ); d->iconView->insertItem( item );
if (d->hiddenItemsLockout == false) {
d->hiddenItems.remove( item ); d->hiddenItems.remove( item );
} }
}
/****************************************************************************** /******************************************************************************
* Protected Slots * * Protected Slots *
@ -268,6 +290,9 @@ void KIconViewSearchLine::activateSearch()
updateSearch( d->search ); updateSearch( d->search );
d->queuedSearches = 0; d->queuedSearches = 0;
} }
else {
QTimer::singleShot( 200, this, SLOT( activateSearch() ) );
}
} }
/****************************************************************************** /******************************************************************************

@ -106,6 +106,11 @@ public slots:
*/ */
void clear(); void clear();
/**
* Must be called before updateSearch() whenever an icon is deleted.
*/
void iconDeleted(const QString &filename);
protected: protected:
/** /**

Loading…
Cancel
Save