diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 12:59:17 +0200 |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 15:23:57 +0200 |
commit | ea16e02a0243aee24f1805ffce106b924ce2fc02 (patch) | |
tree | bc9dd5c379ce2596c948fc576fc60861403248e7 /src/newtabpage.cpp | |
parent | remove superfluous space (diff) | |
download | rekonq-ea16e02a0243aee24f1805ffce106b924ce2fc02.tar.xz |
Modify NewTabPage::browsingMenu() to use explicit text encoding.
Use explicit text encoding in NewTabPage::browsingMenu() with
QLatin1String().
Using explicit text encoding has a some advantages:
-it is safe if the default codec is changed
-the application compile even with QT_NO_CAST_FROM_ASCII
Reviewed-by: Andreas Kling
Diffstat (limited to 'src/newtabpage.cpp')
-rw-r--r-- | src/newtabpage.cpp | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 1c14f3dc..4217bf89 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -345,48 +345,73 @@ void NewTabPage::browsingMenu(const KUrl ¤tUrl) KIconLoader *loader = KIconLoader::global(); - QWebElement nav = markup(".link"); // Favorites - nav.findFirst("a").setAttribute("href", "about:favorites"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("emblem-favorite", KIconLoader::Desktop || KIconLoader::SizeSmall))); - nav.findFirst("span").appendInside(i18n("Favorites")); + // 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); - nav = markup(".link"); // Closed Tabs - nav.findFirst("a").setAttribute("href", "about:closedTabs"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("tab-close", KIconLoader::Desktop || KIconLoader::SizeSmall))); - nav.findFirst("span").appendInside(i18n("Closed Tabs")); + + // 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); - nav = markup(".link"); // Bookmarks - nav.findFirst("a").setAttribute("href", "about:bookmarks"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("bookmarks", KIconLoader::Desktop || KIconLoader::SizeSmall))); - nav.findFirst("span").appendInside(i18n("Bookmarks")); + + // 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); - nav = markup(".link"); // History - nav.findFirst("a").setAttribute("href", "about:history"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("view-history", KIconLoader::Desktop || KIconLoader::SizeSmall))); - nav.findFirst("span").appendInside(i18n("History")); + + // 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); - nav = markup(".link"); // Downloads - nav.findFirst("a").setAttribute("href", "about:downloads"); - nav.findFirst("img").setAttribute("src" , QString("file:///" + - loader->iconPath("download", KIconLoader::Desktop || KIconLoader::SizeSmall))); - nav.findFirst("span").appendInside(i18n("Downloads")); + + // 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); foreach(QWebElement it, navItems) { - if (it.findFirst("a").attribute("href") == currentUrl.toMimeDataString()) - it.addClass("current"); - else if (currentUrl == "about:home" && it.findFirst("a").attribute("href") == "about:favorites") - it.addClass("current"); - m_root.document().findFirst("#navigation").appendInside(it); + 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")) + it.addClass(QLatin1String("current")); + m_root.document().findFirst(QLatin1String("#navigation")).appendInside(it); } } |