diff --git a/src/lib/cookies/cookiemanager.cpp b/src/lib/cookies/cookiemanager.cpp index abeee4a82..5837309ff 100644 --- a/src/lib/cookies/cookiemanager.cpp +++ b/src/lib/cookies/cookiemanager.cpp @@ -46,7 +46,7 @@ CookieManager::CookieManager(QWidget* parent) connect(ui->close, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); connect(ui->close2, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); connect(ui->close3, SIGNAL(clicked(QAbstractButton*)), this, SLOT(close())); - connect(ui->search, SIGNAL(textChanged(QString)), ui->cookieTree, SLOT(filterString(QString))); + connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString))); // Cookie Filtering connect(ui->whiteAdd, SIGNAL(clicked()), this, SLOT(addWhitelist())); @@ -158,9 +158,9 @@ void CookieManager::currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem void CookieManager::refreshTable() { - disconnect(ui->search, SIGNAL(textChanged(QString)), ui->cookieTree, SLOT(filterString(QString))); + disconnect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString))); ui->search->clear(); - connect(ui->search, SIGNAL(textChanged(QString)), ui->cookieTree, SLOT(filterString(QString))); + connect(ui->search, SIGNAL(textChanged(QString)), this, SLOT(filterString(QString))); QTimer::singleShot(0, this, SLOT(slotRefreshTable())); QTimer::singleShot(0, this, SLOT(slotRefreshFilters())); @@ -282,6 +282,23 @@ void CookieManager::saveCookiesChanged(bool state) ui->deleteCookiesOnClose->setEnabled(state); } +void CookieManager::filterString(const QString &string) +{ + if (string.isEmpty()) { + for (int i = 0; i < ui->cookieTree->topLevelItemCount(); ++i) { + ui->cookieTree->topLevelItem(i)->setHidden(false); + ui->cookieTree->topLevelItem(i)->setExpanded(ui->cookieTree->defaultItemShowMode() == TreeWidget::ItemsExpanded); + } + } + else { + for (int i = 0; i < ui->cookieTree->topLevelItemCount(); ++i) { + QString text = "." + ui->cookieTree->topLevelItem(i)->text(0); + ui->cookieTree->topLevelItem(i)->setHidden(!text.contains(string, Qt::CaseInsensitive)); + ui->cookieTree->topLevelItem(i)->setExpanded(true); + } + } +} + void CookieManager::closeEvent(QCloseEvent* e) { QStringList whitelist; diff --git a/src/lib/cookies/cookiemanager.h b/src/lib/cookies/cookiemanager.h index 68a1623b5..30cfdf4c6 100644 --- a/src/lib/cookies/cookiemanager.h +++ b/src/lib/cookies/cookiemanager.h @@ -57,6 +57,8 @@ private slots: void deletePressed(); void saveCookiesChanged(bool state); + void filterString(const QString &string); + private: void closeEvent(QCloseEvent* e); void keyPressEvent(QKeyEvent* e); diff --git a/src/lib/tools/treewidget.h b/src/lib/tools/treewidget.h index d21bbc93e..4b864ca69 100644 --- a/src/lib/tools/treewidget.h +++ b/src/lib/tools/treewidget.h @@ -28,6 +28,7 @@ class QT_QUPZILLA_EXPORT TreeWidget : public QTreeWidget public: explicit TreeWidget(QWidget* parent = 0); enum ItemShowMode { ItemsCollapsed = 0, ItemsExpanded = 1 }; + ItemShowMode defaultItemShowMode() { return m_showMode; } void setDefaultItemShowMode(ItemShowMode mode) { m_showMode = mode; } QList allItems(); bool appendToParentItem(const QString &parentText, QTreeWidgetItem* item);