summaryrefslogtreecommitdiff
path: root/src/newtabpage.cpp
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-11 13:45:34 +0200
committerBenjamin Poulain <benjamin.poulain@nokia.com>2010-08-11 15:23:57 +0200
commit9b4b9d048968dcc670344f5c24fa212c5428aec3 (patch)
tree3cbcaefe67dae5ef3c2d559ad69916e7a05aa673 /src/newtabpage.cpp
parentFix the file scheme of NewTabPage::browsingMenu() (diff)
downloadrekonq-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/newtabpage.cpp')
-rw-r--r--src/newtabpage.cpp73
1 files changed, 21 insertions, 52 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 &currentUrl)
{
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;
+}