Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support showing only the favicon for a tab. "faviconized" urls are re…

…membered
  • Loading branch information...
commit db832c01f132be6cdcf83dc57f2fdd81ce3b31d9 1 parent 530ff55
John Wimer authored
18 src/tabbar.cpp
View
@@ -63,6 +63,7 @@
#include "tabbar.h"
#include "tabwidget.h"
+#include "webview.h"
#include <qaction.h>
#include <qapplication.h>
@@ -178,6 +179,15 @@ void TabBar::contextMenuRequested(const QPoint &position)
action = menu.addAction(tr("Close &Other Tabs"),
this, SLOT(closeOtherTabs()));
action->setData(index);
+ menu.addSeparator();
+
+ QAction *showIconAction = new QAction(tr("Show Favicon Only"), &menu);
+ showIconAction->setCheckable(true);
+ showIconAction->setData(index);
+ showIconAction->setChecked(tabWidget->webView(index)->showIconOnly());
+ menu.addAction(showIconAction);
+ connect(showIconAction, SIGNAL(toggled(bool)),
+ this, SLOT(showIconOnly(bool)));
menu.addSeparator();
@@ -307,6 +317,14 @@ void TabBar::dropEvent(QDropEvent *event)
QTabBar::dropEvent(event);
}
+void TabBar::showIconOnly(bool show)
+{
+ if (QAction *action = qobject_cast<QAction*>(sender())) {
+ int index = action->data().toInt();
+ emit showIconOnly(index, show);
+ }
+}
+
QSize TabBar::tabSizeHint(int index) const
{
QSize sizeHint = QTabBar::tabSizeHint(index);
2  src/tabbar.h
View
@@ -82,6 +82,7 @@ class TabBar : public QTabBar
void reloadTab(int index);
void reloadAllTabs();
void loadUrl(const QUrl &url, TabWidget::OpenUrlIn tab);
+ void showIconOnly(int index, bool show);
public:
TabBar(QWidget *parent = 0);
@@ -111,6 +112,7 @@ private slots:
void contextMenuRequested(const QPoint &position);
void updateViewToolBarAction();
void viewTabBar();
+ void showIconOnly(bool show);
private:
void updateVisibility();
84 src/tabwidget.cpp
View
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
+ * Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -125,6 +125,8 @@ TabWidget::TabWidget(QWidget *parent)
connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
+ connect(m_tabBar, SIGNAL(showIconOnly(int, bool)),
+ this, SLOT(showIconOnly(int, bool)));
setTabBar(m_tabBar);
setDocumentMode(true);
connect(m_tabBar, SIGNAL(tabMoved(int, int)),
@@ -208,6 +210,16 @@ TabWidget::TabWidget(QWidget *parent)
connect(BrowserApplication::historyManager(), SIGNAL(historyCleared()),
this, SLOT(historyCleared()));
+ settings.endGroup();
+
+ // Read the urls that should only have an icon displayed in the tab.
+ int size = settings.beginReadArray(QLatin1String("iconOnlyUrls"));
+ for (int i = 0; i < size; ++i) {
+ settings.setArrayIndex(i);
+ m_iconOnlyUrls.append(settings.value(QLatin1String("url")).toString());
+ }
+ settings.endArray();
+
// Initialize Actions' labels
retranslate();
}
@@ -556,6 +568,35 @@ void TabWidget::bookmarkTabs()
}
}
+void TabWidget::showIconOnly(int index, bool show)
+{
+ WebView *tab = webView(index);
+ tab->setShowIconOnly(show);
+
+ if (show) {
+ setTitle(tab, QString());
+ m_iconOnlyUrls.append(tab->url());
+ } else {
+ setTitle(tab, tab->title());
+ m_iconOnlyUrls.removeAll(tab->url());
+ }
+
+ saveIconOnlyUrls();
+}
+
+void TabWidget::saveIconOnlyUrls()
+{
+ // Save the "faviconized" urls.
+ QSettings settings;
+ settings.beginWriteArray(QLatin1String("iconOnlyUrls"));
+ for (int i = 0; i < m_iconOnlyUrls.size(); ++i) {
+ settings.setArrayIndex(i);
+ settings.setValue(QLatin1String("url"),
+ m_iconOnlyUrls.at(i).toString());
+ }
+ settings.endArray();
+}
+
void TabWidget::lineEditReturnPressed()
{
if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender())) {
@@ -752,21 +793,36 @@ void TabWidget::webViewIconChanged()
}
}
-void TabWidget::webViewTitleChanged(const QString &title)
+void TabWidget::setTitle(WebView *webView, const QString& title)
{
- WebView *webView = qobject_cast<WebView*>(sender());
+ QString tabTitle;
+
+ if (! webView->showIconOnly()) {
+ tabTitle = title;
+ if (title.isEmpty())
+ tabTitle = QString::fromUtf8(webView->url().toEncoded());
+ tabTitle.replace(QLatin1Char('&'), QLatin1String("&&"));
+ }
+
int index = webViewIndex(webView);
- if (-1 == index)
- return;
- QString tabTitle = title;
- if (title.isEmpty())
- tabTitle = QString::fromUtf8(webView->url().toEncoded());
- tabTitle.replace(QLatin1Char('&'), QLatin1String("&&"));
+
setTabText(index, tabTitle);
setTabToolTip(index, tabTitle);
+
if (currentIndex() == index)
emit setCurrentTitle(title);
- BrowserApplication::historyManager()->updateHistoryEntry(webView->url(), title);
+ BrowserApplication::historyManager()->updateHistoryEntry(webView->url(),
+ title);
+}
+
+void TabWidget::webViewTitleChanged(const QString &title)
+{
+ WebView *webView = qobject_cast<WebView*>(sender());
+ int index = webViewIndex(webView);
+ if (-1 == index)
+ return;
+
+ setTitle(webView, title);
}
void TabWidget::webViewUrlChanged(const QUrl &url)
@@ -775,6 +831,14 @@ void TabWidget::webViewUrlChanged(const QUrl &url)
int index = webViewIndex(webView);
if (-1 == index)
return;
+
+ QUrl element;
+ foreach (element, m_iconOnlyUrls) {
+ if (element == url)
+ webView->setShowIconOnly(true);
+ }
+
+
m_tabBar->setTabData(index, url);
emit tabsChanged();
}
6 src/tabwidget.h
View
@@ -1,5 +1,5 @@
/*
- * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
+ * Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -164,6 +164,7 @@ public slots:
void nextTab();
void previousTab();
void bookmarkTabs();
+ void showIconOnly(int index, bool show);
private slots:
void currentChanged(int index);
@@ -189,6 +190,8 @@ private slots:
static QUrl guessUrlFromString(const QString &url);
QLabel *animationLabel(int index, bool addMovie);
void retranslate();
+ void setTitle(WebView *webView, const QString& title);
+ void saveIconOnlyUrls();
QAction *m_recentlyClosedTabsAction;
QAction *m_newTabAction;
@@ -200,6 +203,7 @@ private slots:
QMenu *m_recentlyClosedTabsMenu;
static const int m_recentlyClosedTabsSize = 10;
QList<QUrl> m_recentlyClosedTabs;
+ QList<QUrl> m_iconOnlyUrls;
QList<QByteArray> m_recentlyClosedTabsHistory;
QList<WebActionMapper*> m_actions;
bool m_swappedDelayedWidget;
1  src/webview.cpp
View
@@ -103,6 +103,7 @@ WebView::WebView(QWidget *parent)
, m_progress(0)
, m_currentZoom(100)
, m_page(new WebPage(this))
+ , m_showIconOnly(false)
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
, m_enableAccessKeys(true)
, m_accessKeysPressed(false)
3  src/webview.h
View
@@ -100,6 +100,8 @@ class WebView : public QWebView
QString lastStatusBarText() const;
inline int progress() const { return m_progress; }
TabWidget *tabWidget() const;
+ inline void setShowIconOnly(bool show) { m_showIconOnly = show; }
+ inline bool showIconOnly() { return m_showIconOnly; }
signals:
void search(const QUrl &searchUrl, TabWidget::OpenUrlIn openIn);
@@ -153,6 +155,7 @@ private slots:
int m_currentZoom;
QList<int> m_zoomLevels;
WebPage *m_page;
+ bool m_showIconOnly;
#if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
bool m_enableAccessKeys;
Please sign in to comment.
Something went wrong with that request. Please try again.