diff options
author | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 14:34:22 +0200 |
---|---|---|
committer | Benjamin Poulain <benjamin.poulain@nokia.com> | 2010-08-11 21:29:37 +0200 |
commit | 89ac1b7f00b1632f655ade8daf34cc3d49df93f3 (patch) | |
tree | 452ae1d9724ea5cac9da29eada94babf8619353e /src/newtabpage.cpp | |
parent | Refactor NewTabPage::browsingMenu() to clean the creation of item (diff) | |
download | rekonq-89ac1b7f00b1632f655ade8daf34cc3d49df93f3.tar.xz |
Refactor createNavItem to use it everywhere .link items are used
Change createNavItem() to a more generic createLinkItem() capable of
generating icon of any type.
Use the new createLinkItem() in every position where .link items are
created.
Fix the flags used for icons. The flags were specified with a boolean
or operator:
KIconLoader::SizeSmall || KIconLoader::Small -> one |
All the icon flags have been changed to KIconLoader::Toolbar in order
to keep the same behavior as before (Toolbar value equals 1).
Diffstat (limited to 'src/newtabpage.cpp')
-rw-r--r-- | src/newtabpage.cpp | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp index 2b80b7f0..78496bc2 100644 --- a/src/newtabpage.cpp +++ b/src/newtabpage.cpp @@ -44,7 +44,6 @@ // KDE Includes #include <KStandardDirs> -#include <KIconLoader> #include <KConfig> #include <KDialog> #include <KCalendarSystem> @@ -167,11 +166,10 @@ void NewTabPage::favoritesPage() { m_root.addClass("favorites"); - QWebElement add = markup(".link"); - add.findFirst("a").setAttribute("href", "about:preview/add"); - add.findFirst("img").setAttribute("src" , QString("file:///" + - KIconLoader::global()->iconPath("list-add", KIconLoader::Small || KIconLoader::SizeSmall))); - add.findFirst("span").appendInside(i18n("Add Favorite")); + const QWebElement add = createLinkItem(i18n("Add Favorite"), + QLatin1String("about:preview/add"), + QLatin1String("list-add"), + KIconLoader::Toolbar); m_root.document().findFirst("#actions").appendInside(add); QStringList names = ReKonfig::previewNames(); @@ -343,20 +341,34 @@ void NewTabPage::browsingMenu(const KUrl ¤tUrl) QList<QWebElement> navItems; // Favorites - navItems.append(createNavItem(i18n("Favorites"), QLatin1String("about:favorites"), QLatin1String("emblem-favorite"))); - + navItems.append(createLinkItem(i18n("Favorites"), + QLatin1String("about:favorites"), + QLatin1String("emblem-favorite"), + KIconLoader::Toolbar)); // Closed Tabs - navItems.append(createNavItem(i18n("Closed Tabs"), QLatin1String("about:closedTabs"), QLatin1String("tab-close"))); + navItems.append(createLinkItem(i18n("Closed Tabs"), + QLatin1String("about:closedTabs"), + QLatin1String("tab-close"), + KIconLoader::Toolbar)); // Bookmarks - navItems.append(createNavItem(i18n("Bookmarks"), QLatin1String("about:bookmarks"), QLatin1String("bookmarks"))); + navItems.append(createLinkItem(i18n("Bookmarks"), + QLatin1String("about:bookmarks"), + QLatin1String("bookmarks"), + KIconLoader::Toolbar)); // History - navItems.append(createNavItem(i18n("History"), QLatin1String("about:history"), QLatin1String("view-history"))); + navItems.append(createLinkItem(i18n("History"), + QLatin1String("about:history"), + QLatin1String("view-history"), + KIconLoader::Toolbar)); // Downloads - navItems.append(createNavItem(i18n("Downloads"), QLatin1String("about:downloads"), QLatin1String("download"))); + navItems.append(createLinkItem(i18n("Downloads"), + QLatin1String("about:downloads"), + QLatin1String("download"), + KIconLoader::Toolbar)); foreach(QWebElement it, navItems) { @@ -376,11 +388,10 @@ void NewTabPage::historyPage() { m_root.addClass("history"); - QWebElement clearData = markup(".link"); - clearData.findFirst("a").setAttribute("href", "about:history/clear"); - QString iconPath = QString("file:///" + KIconLoader::global()->iconPath("edit-clear", KIconLoader::SizeSmall || KIconLoader::Small)); - clearData.findFirst("img").setAttribute("src" , iconPath); - clearData.findFirst("span").appendInside(i18n("Clear Private Data")); + const QWebElement clearData = createLinkItem(i18n("Clear Private Data"), + QLatin1String("about:history/clear"), + QLatin1String("edit-clear"), + KIconLoader::Toolbar); m_root.document().findFirst("#actions").appendInside(clearData); HistoryTreeModel *model = Application::historyManager()->historyTreeModel(); @@ -422,11 +433,10 @@ void NewTabPage::bookmarksPage() { m_root.addClass("bookmarks"); - QWebElement editBookmarks = markup(".link"); - editBookmarks.findFirst("a").setAttribute("href", "about:bookmarks/edit"); - QString iconPath = QString("file:///" + KIconLoader::global()->iconPath("bookmarks-organize", KIconLoader::SizeSmall || KIconLoader::Small)); - editBookmarks.findFirst("img").setAttribute("src" , iconPath); - editBookmarks.findFirst("span").appendInside(i18n("Edit Bookmarks")); + const QWebElement editBookmarks = createLinkItem(i18n("Edit Bookmarks"), + QLatin1String("about:bookmarks/edit"), + QLatin1String("bookmarks-organize"), + KIconLoader::Toolbar); m_root.document().findFirst("#actions").appendInside(editBookmarks); KBookmarkGroup bookGroup = Application::bookmarkProvider()->rootGroup(); @@ -523,11 +533,10 @@ void NewTabPage::downloadsPage() { m_root.addClass("downloads"); - QWebElement clearData = markup(".link"); - clearData.findFirst("a").setAttribute("href", "about:downloads/clear"); - QString iconPath = QString("file:///" + KIconLoader::global()->iconPath("edit-clear", KIconLoader::SizeSmall || KIconLoader::Small)); - clearData.findFirst("img").setAttribute("src" , iconPath); - clearData.findFirst("span").appendInside(i18n("Clear Private Data")); + const QWebElement clearData = createLinkItem(i18n("Clear Private Data"), + QLatin1String("about:downloads/clear"), + QLatin1String("edit-clear"), + KIconLoader::Toolbar); m_root.document().findFirst("#actions").appendInside(clearData); DownloadList list = Application::instance()->downloads(); @@ -577,15 +586,14 @@ void NewTabPage::downloadsPage() } } -QWebElement NewTabPage::createNavItem(const QString &title, const QString &urlString, const QString &iconPath) const +QWebElement NewTabPage::createLinkItem(const QString &title, const QString &urlString, const QString &iconPath, int groupOrSize) 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)); + QString::fromLatin1("file://") + loader->iconPath(iconPath, groupOrSize)); nav.findFirst(QLatin1String("span")).appendInside(title); return nav; } |