From 0862253c111d11a86c348a93b910b3073171ccb0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Sat, 12 May 2012 01:26:48 +0200 Subject: Downloads search --- src/newtabpage.cpp | 48 ++++++++++++++++++++++++++++++++++-------------- src/newtabpage.h | 2 +- 2 files changed, 35 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 7cf9a8a4..153755fc 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -200,13 +200,25 @@ void NewTabPage::generate(const KUrl &url) } - if (url == KUrl("about:downloads/clear")) + // about:downloads links + if (KUrl("about:downloads").isParentOf(url)) { - rApp->downloadManager()->clearDownloadsHistory(); - loadPageForUrl(KUrl("about:downloads")); - return; - } + if (url.fileName() == QL1S("clear")) + { + rApp->downloadManager()->clearDownloadsHistory(); + loadPageForUrl(KUrl("about:downloads")); + return; + } + if (url.fileName() == QL1S("search")) + { + QString value = url.queryItemValue( QL1S("q") ); + loadPageForUrl(KUrl("about:downloads"), value); + return; + } + + } + if (url == KUrl("about:bookmarks/edit")) { rApp->bookmarkManager()->slotEditBookmarks(); @@ -261,7 +273,7 @@ void NewTabPage::loadPageForUrl(const KUrl &url, const QString & filter) } else if (encodedUrl == QByteArray("about:downloads")) { - downloadsPage(); + downloadsPage(filter); updateWindowIcon(); title = i18n("Downloads"); } @@ -463,9 +475,6 @@ void NewTabPage::bookmarksPage() { m_root.addClass(QL1S("bookmarks")); - const QWebElement searchForm = createFormItem(i18n("Search Bookmarks"), QL1S("about:bookmarks/search")); - m_root.document().findFirst(QL1S("#actions")).appendInside(searchForm); - const QWebElement editBookmarks = createLinkItem(i18n("Edit Bookmarks"), QL1S("about:bookmarks/edit"), QL1S("bookmarks-organize"), @@ -519,11 +528,11 @@ void NewTabPage::closedTabsPage() } -void NewTabPage::downloadsPage() +void NewTabPage::downloadsPage(const QString & filter) { m_root.addClass(QL1S("downloads")); - const QWebElement searchForm = createFormItem(i18n("Search Downloads"), QL1S("about:download/search")); + const QWebElement searchForm = createFormItem(i18n("Search Downloads"), QL1S("about:downloads/search")); m_root.document().findFirst(QL1S("#actions")).appendInside(searchForm); const QWebElement clearDownloads = createLinkItem(i18n("Clear Downloads"), @@ -534,6 +543,8 @@ void NewTabPage::downloadsPage() DownloadList list = rApp->downloadManager()->downloads(); + bool filterIsEmpty = filter.isEmpty(); + if (list.isEmpty()) { m_root.addClass(QL1S("empty")); @@ -543,13 +554,22 @@ void NewTabPage::downloadsPage() Q_FOREACH(DownloadItem * item, list) { + KUrl u = KUrl(item->destinationUrl()); + QString fName = u.fileName(); + + QString srcUrl = item->originUrl(); + + if (!filterIsEmpty) + { + if (!fName.contains(filter, Qt::CaseInsensitive) && !srcUrl.contains(filter, Qt::CaseInsensitive)) + continue; + } + m_root.prependInside(markup(QL1S("div"))); QWebElement div = m_root.firstChild(); div.addClass(QL1S("download")); - KUrl u = KUrl(item->destinationUrl()); - QString fName = u.fileName(); QString dir = u.directory(); QString file = dir + QL1C('/') + fName; @@ -565,7 +585,7 @@ void NewTabPage::downloadsPage() div.appendInside(QL1S("") + date + QL1S("")); div.appendInside(QL1S("
")); - div.appendInside(QL1S("")); + div.appendInside(QL1S("")); div.appendInside(QL1S("
")); if (QFile::exists(file)) diff --git a/src/newtabpage.h b/src/newtabpage.h index 8d446908..a9e618db 100644 --- a/src/newtabpage.h +++ b/src/newtabpage.h @@ -68,7 +68,7 @@ private: void historyPage(const QString & filter = QString()); void bookmarksPage(); void closedTabsPage(); - void downloadsPage(); + void downloadsPage(const QString & filter = QString()); void tabsPage(); void loadPageForUrl(const KUrl &url, const QString & filter = QString()); -- cgit v1.2.1