diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 13:45:34 +0200 |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 15:23:57 +0200 |
commit | 9b4b9d048968dcc670344f5c24fa212c5428aec3 (patch) | |
tree | 3cbcaefe67dae5ef3c2d559ad69916e7a05aa673 /src | |
parent | Fix the file scheme of NewTabPage::browsingMenu() (diff) | |
download | rekonq-9b4b9d048968dcc670344f5c24fa212c5428aec3.tar.xz |
Refactor NewTabPage::browsingMenu() to clean the creation of item
Almost identical code was copied 5 times. It has been replaced by
a private function.
Diffstat (limited to 'src')
-rw-r--r-- | src/newtabpage.cpp | 73 | ||||
-rw-r--r-- | src/newtabpage.h | 4 |
2 files changed, 24 insertions, 53 deletions
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 7711d2e7..2b80b7f0 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -338,75 +338,31 @@ void NewTabPage::removePreview(int index) ReKonfig::self()->writeConfig(); } - void NewTabPage::browsingMenu(const KUrl ¤tUrl) { QList<QWebElement> navItems; - KIconLoader *loader = KIconLoader::global(); - - // String used for content creation - const QString aTagString('a'); - const QString linkClassString(QLatin1String(".link")); - const QString imgTagString(QLatin1String("img")); - const QString spanTagString(QLatin1String("span")); - const QString hrefAttributeString(QLatin1String("href")); - const QString srcAttributeString(QLatin1String("src")); - const QString fileSchemeString(QLatin1String("file://")); - - // Favorites - QWebElement nav = markup(linkClassString); - nav.findFirst(aTagString).setAttribute(hrefAttributeString, - QLatin1String("about:favorites")); - nav.findFirst(imgTagString).setAttribute(srcAttributeString, - fileSchemeString + loader->iconPath(QLatin1String("emblem-favorite"), - KIconLoader::Desktop || KIconLoader::SizeSmall)); - nav.findFirst(spanTagString).appendInside(i18n("Favorites")); - navItems.append(nav); + navItems.append(createNavItem(i18n("Favorites"), QLatin1String("about:favorites"), QLatin1String("emblem-favorite"))); // Closed Tabs - nav = markup(linkClassString); - nav.findFirst(aTagString).setAttribute(hrefAttributeString, QLatin1String("about:closedTabs")); - nav.findFirst(imgTagString).setAttribute(srcAttributeString, - fileSchemeString + loader->iconPath(QLatin1String("tab-close"), - KIconLoader::Desktop || KIconLoader::SizeSmall)); - nav.findFirst(spanTagString).appendInside(i18n("Closed Tabs")); - navItems.append(nav); - + navItems.append(createNavItem(i18n("Closed Tabs"), QLatin1String("about:closedTabs"), QLatin1String("tab-close"))); // Bookmarks - nav = markup(linkClassString); - nav.findFirst(aTagString).setAttribute(hrefAttributeString, QLatin1String("about:bookmarks")); - nav.findFirst(imgTagString).setAttribute(srcAttributeString, - fileSchemeString + loader->iconPath(QLatin1String("bookmarks"), - KIconLoader::Desktop || KIconLoader::SizeSmall)); - nav.findFirst(spanTagString).appendInside(i18n("Bookmarks")); - navItems.append(nav); - + navItems.append(createNavItem(i18n("Bookmarks"), QLatin1String("about:bookmarks"), QLatin1String("bookmarks"))); // History - nav = markup(linkClassString); - nav.findFirst(aTagString).setAttribute(hrefAttributeString, QLatin1String("about:history")); - nav.findFirst(imgTagString).setAttribute(srcAttributeString, - fileSchemeString + loader->iconPath(QLatin1String("view-history"), - KIconLoader::Desktop || KIconLoader::SizeSmall)); - nav.findFirst(spanTagString).appendInside(i18n("History")); - navItems.append(nav); - + navItems.append(createNavItem(i18n("History"), QLatin1String("about:history"), QLatin1String("view-history"))); // Downloads - nav = markup(linkClassString); - nav.findFirst(aTagString).setAttribute(hrefAttributeString, QLatin1String("about:downloads")); - nav.findFirst(imgTagString).setAttribute(srcAttributeString, - fileSchemeString + loader->iconPath(QLatin1String("download"), - KIconLoader::Desktop || KIconLoader::SizeSmall)); - nav.findFirst(spanTagString).appendInside(i18n("Downloads")); - navItems.append(nav); + navItems.append(createNavItem(i18n("Downloads"), QLatin1String("about:downloads"), QLatin1String("download"))); foreach(QWebElement it, navItems) { + const QString aTagString('a'); + const QString hrefAttributeString(QLatin1String("href")); + if (it.findFirst(aTagString).attribute(hrefAttributeString) == currentUrl.toMimeDataString()) it.addClass(QLatin1String("current")); else if (currentUrl == QLatin1String("about:home") && it.findFirst(aTagString).attribute(hrefAttributeString) == QLatin1String("about:favorites")) @@ -620,3 +576,16 @@ void NewTabPage::downloadsPage() div.lastChild().setPlainText(i18n("Open file")); } } + +QWebElement NewTabPage::createNavItem(const QString &title, const QString &urlString, const QString &iconPath) const +{ + const KIconLoader * const loader = KIconLoader::global(); + + QWebElement nav = markup(QLatin1String(".link")); + nav.findFirst(QString('a')).setAttribute(QLatin1String("href"), urlString); + nav.findFirst(QLatin1String("img")).setAttribute(QLatin1String("src"), + QString::fromLatin1("file://") + loader->iconPath(iconPath, + KIconLoader::Desktop || KIconLoader::SizeSmall)); + nav.findFirst(QLatin1String("span")).appendInside(title); + return nav; +} diff --git a/src/newtabpage.h b/src/newtabpage.h index ad4941d3..c4e48f5c 100644 --- a/src/newtabpage.h +++ b/src/newtabpage.h @@ -107,7 +107,7 @@ private: * It works for all elements defined here. * */ - inline QWebElement markup(const QString &selector) + inline QWebElement markup(const QString &selector) const { return m_root.document().findFirst("#models > " + selector).clone(); } @@ -115,6 +115,8 @@ private: QString checkTitle(const QString &title); private: + QWebElement createNavItem(const QString &title, const QString &urlString, const QString &iconPath) const; + QString m_html; QWebElement m_root; }; |