Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…membered
  • Loading branch information...
commit db832c01f132be6cdcf83dc57f2fdd81ce3b31d9 1 parent 530ff55
John Wimer authored October 03, 2009
18  src/tabbar.cpp
@@ -63,6 +63,7 @@
63 63
 #include "tabbar.h"
64 64
 
65 65
 #include "tabwidget.h"
  66
+#include "webview.h"
66 67
 
67 68
 #include <qaction.h>
68 69
 #include <qapplication.h>
@@ -178,6 +179,15 @@ void TabBar::contextMenuRequested(const QPoint &position)
178 179
         action = menu.addAction(tr("Close &Other Tabs"),
179 180
                                 this, SLOT(closeOtherTabs()));
180 181
         action->setData(index);
  182
+	menu.addSeparator();
  183
+
  184
+        QAction *showIconAction = new QAction(tr("Show Favicon Only"), &menu);
  185
+        showIconAction->setCheckable(true);
  186
+        showIconAction->setData(index);
  187
+        showIconAction->setChecked(tabWidget->webView(index)->showIconOnly());
  188
+        menu.addAction(showIconAction);
  189
+        connect(showIconAction, SIGNAL(toggled(bool)),
  190
+                this, SLOT(showIconOnly(bool)));
181 191
 
182 192
         menu.addSeparator();
183 193
 
@@ -307,6 +317,14 @@ void TabBar::dropEvent(QDropEvent *event)
307 317
     QTabBar::dropEvent(event);
308 318
 }
309 319
 
  320
+void TabBar::showIconOnly(bool show)
  321
+{
  322
+    if (QAction *action = qobject_cast<QAction*>(sender())) {
  323
+        int index = action->data().toInt();
  324
+        emit showIconOnly(index, show);
  325
+    }
  326
+}
  327
+
310 328
 QSize TabBar::tabSizeHint(int index) const
311 329
 {
312 330
     QSize sizeHint = QTabBar::tabSizeHint(index);
2  src/tabbar.h
@@ -82,6 +82,7 @@ class TabBar : public QTabBar
82 82
     void reloadTab(int index);
83 83
     void reloadAllTabs();
84 84
     void loadUrl(const QUrl &url, TabWidget::OpenUrlIn tab);
  85
+    void showIconOnly(int index, bool show);
85 86
 
86 87
 public:
87 88
     TabBar(QWidget *parent = 0);
@@ -111,6 +112,7 @@ private slots:
111 112
     void contextMenuRequested(const QPoint &position);
112 113
     void updateViewToolBarAction();
113 114
     void viewTabBar();
  115
+    void showIconOnly(bool show);
114 116
 
115 117
 private:
116 118
     void updateVisibility();
84  src/tabwidget.cpp
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2  
- * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
  2
+ * Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net>
3 3
  *
4 4
  * This program is free software; you can redistribute it and/or modify
5 5
  * it under the terms of the GNU General Public License as published by
@@ -125,6 +125,8 @@ TabWidget::TabWidget(QWidget *parent)
125 125
     connect(m_tabBar, SIGNAL(closeOtherTabs(int)), this, SLOT(closeOtherTabs(int)));
126 126
     connect(m_tabBar, SIGNAL(reloadTab(int)), this, SLOT(reloadTab(int)));
127 127
     connect(m_tabBar, SIGNAL(reloadAllTabs()), this, SLOT(reloadAllTabs()));
  128
+    connect(m_tabBar, SIGNAL(showIconOnly(int, bool)),
  129
+            this, SLOT(showIconOnly(int, bool)));
128 130
     setTabBar(m_tabBar);
129 131
     setDocumentMode(true);
130 132
     connect(m_tabBar, SIGNAL(tabMoved(int, int)),
@@ -208,6 +210,16 @@ TabWidget::TabWidget(QWidget *parent)
208 210
     connect(BrowserApplication::historyManager(), SIGNAL(historyCleared()),
209 211
         this, SLOT(historyCleared()));
210 212
 
  213
+    settings.endGroup();
  214
+
  215
+    // Read the urls that should only have an icon displayed in the tab.
  216
+    int size = settings.beginReadArray(QLatin1String("iconOnlyUrls"));
  217
+    for (int i = 0; i < size; ++i) {
  218
+        settings.setArrayIndex(i);
  219
+        m_iconOnlyUrls.append(settings.value(QLatin1String("url")).toString());
  220
+    }
  221
+    settings.endArray();
  222
+
211 223
     // Initialize Actions' labels
212 224
     retranslate();
213 225
 }
@@ -556,6 +568,35 @@ void TabWidget::bookmarkTabs()
556 568
     }
557 569
 }
558 570
 
  571
+void TabWidget::showIconOnly(int index, bool show)
  572
+{
  573
+    WebView *tab = webView(index);
  574
+    tab->setShowIconOnly(show);
  575
+
  576
+    if (show) {
  577
+        setTitle(tab, QString());
  578
+        m_iconOnlyUrls.append(tab->url());
  579
+    } else {
  580
+        setTitle(tab, tab->title());
  581
+        m_iconOnlyUrls.removeAll(tab->url());
  582
+    }
  583
+
  584
+    saveIconOnlyUrls();
  585
+}
  586
+
  587
+void TabWidget::saveIconOnlyUrls()
  588
+{
  589
+    // Save the "faviconized" urls.
  590
+    QSettings settings;
  591
+    settings.beginWriteArray(QLatin1String("iconOnlyUrls"));
  592
+    for (int i = 0; i < m_iconOnlyUrls.size(); ++i) {
  593
+        settings.setArrayIndex(i);
  594
+        settings.setValue(QLatin1String("url"),
  595
+                          m_iconOnlyUrls.at(i).toString());
  596
+    }
  597
+    settings.endArray();
  598
+}
  599
+
559 600
 void TabWidget::lineEditReturnPressed()
560 601
 {
561 602
     if (QLineEdit *lineEdit = qobject_cast<QLineEdit*>(sender())) {
@@ -752,21 +793,36 @@ void TabWidget::webViewIconChanged()
752 793
     }
753 794
 }
754 795
 
755  
-void TabWidget::webViewTitleChanged(const QString &title)
  796
+void TabWidget::setTitle(WebView *webView, const QString& title)
756 797
 {
757  
-    WebView *webView = qobject_cast<WebView*>(sender());
  798
+    QString tabTitle;
  799
+
  800
+    if (! webView->showIconOnly()) {
  801
+        tabTitle = title;
  802
+        if (title.isEmpty())
  803
+            tabTitle = QString::fromUtf8(webView->url().toEncoded());
  804
+        tabTitle.replace(QLatin1Char('&'), QLatin1String("&&"));
  805
+    }
  806
+
758 807
     int index = webViewIndex(webView);
759  
-    if (-1 == index)
760  
-        return;
761  
-    QString tabTitle = title;
762  
-    if (title.isEmpty())
763  
-        tabTitle = QString::fromUtf8(webView->url().toEncoded());
764  
-    tabTitle.replace(QLatin1Char('&'), QLatin1String("&&"));
  808
+
765 809
     setTabText(index, tabTitle);
766 810
     setTabToolTip(index, tabTitle);
  811
+
767 812
     if (currentIndex() == index)
768 813
         emit setCurrentTitle(title);
769  
-    BrowserApplication::historyManager()->updateHistoryEntry(webView->url(), title);
  814
+    BrowserApplication::historyManager()->updateHistoryEntry(webView->url(),
  815
+                                                             title);
  816
+}
  817
+
  818
+void TabWidget::webViewTitleChanged(const QString &title)
  819
+{
  820
+    WebView *webView = qobject_cast<WebView*>(sender());
  821
+    int index = webViewIndex(webView);
  822
+    if (-1 == index)
  823
+        return;
  824
+
  825
+   setTitle(webView, title);
770 826
 }
771 827
 
772 828
 void TabWidget::webViewUrlChanged(const QUrl &url)
@@ -775,6 +831,14 @@ void TabWidget::webViewUrlChanged(const QUrl &url)
775 831
     int index = webViewIndex(webView);
776 832
     if (-1 == index)
777 833
         return;
  834
+
  835
+    QUrl element;
  836
+    foreach (element, m_iconOnlyUrls) {
  837
+        if (element == url)
  838
+            webView->setShowIconOnly(true);
  839
+    }
  840
+
  841
+
778 842
     m_tabBar->setTabData(index, url);
779 843
     emit tabsChanged();
780 844
 }
6  src/tabwidget.h
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2  
- * Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
  2
+ * Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net>
3 3
  *
4 4
  * This program is free software; you can redistribute it and/or modify
5 5
  * it under the terms of the GNU General Public License as published by
@@ -164,6 +164,7 @@ public slots:
164 164
     void nextTab();
165 165
     void previousTab();
166 166
     void bookmarkTabs();
  167
+    void showIconOnly(int index, bool show);
167 168
 
168 169
 private slots:
169 170
     void currentChanged(int index);
@@ -189,6 +190,8 @@ private slots:
189 190
     static QUrl guessUrlFromString(const QString &url);
190 191
     QLabel *animationLabel(int index, bool addMovie);
191 192
     void retranslate();
  193
+    void setTitle(WebView *webView, const QString& title);
  194
+    void saveIconOnlyUrls();
192 195
 
193 196
     QAction *m_recentlyClosedTabsAction;
194 197
     QAction *m_newTabAction;
@@ -200,6 +203,7 @@ private slots:
200 203
     QMenu *m_recentlyClosedTabsMenu;
201 204
     static const int m_recentlyClosedTabsSize = 10;
202 205
     QList<QUrl> m_recentlyClosedTabs;
  206
+    QList<QUrl> m_iconOnlyUrls;
203 207
     QList<QByteArray> m_recentlyClosedTabsHistory;
204 208
     QList<WebActionMapper*> m_actions;
205 209
     bool m_swappedDelayedWidget;
1  src/webview.cpp
@@ -103,6 +103,7 @@ WebView::WebView(QWidget *parent)
103 103
     , m_progress(0)
104 104
     , m_currentZoom(100)
105 105
     , m_page(new WebPage(this))
  106
+    , m_showIconOnly(false)
106 107
 #if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
107 108
     , m_enableAccessKeys(true)
108 109
     , m_accessKeysPressed(false)
3  src/webview.h
@@ -100,6 +100,8 @@ class WebView : public QWebView
100 100
     QString lastStatusBarText() const;
101 101
     inline int progress() const { return m_progress; }
102 102
     TabWidget *tabWidget() const;
  103
+    inline void setShowIconOnly(bool show) { m_showIconOnly = show; }
  104
+    inline bool showIconOnly() { return m_showIconOnly; }
103 105
 
104 106
 signals:
105 107
     void search(const QUrl &searchUrl, TabWidget::OpenUrlIn openIn);
@@ -153,6 +155,7 @@ private slots:
153 155
     int m_currentZoom;
154 156
     QList<int> m_zoomLevels;
155 157
     WebPage *m_page;
  158
+    bool m_showIconOnly;
156 159
 
157 160
 #if QT_VERSION >= 0x040600 || defined(WEBKIT_TRUNK)
158 161
     bool m_enableAccessKeys;

0 notes on commit db832c0

Please sign in to comment.
Something went wrong with that request. Please try again.