File indexing completed on 2024-05-12 04:58:27
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #ifndef ICONPROVIDER_H 0019 #define ICONPROVIDER_H 0020 0021 #include <QWidget> 0022 #include <QStyle> 0023 #include <QImage> 0024 #include <QUrl> 0025 #include <QCache> 0026 #include <QMutex> 0027 0028 #include <functional> 0029 0030 #include "qzcommon.h" 0031 0032 class QIcon; 0033 0034 class WebView; 0035 class AutoSaver; 0036 0037 // Needs to be QWidget subclass, otherwise qproperty- setting won't work 0038 class FALKON_EXPORT IconProvider : public QWidget 0039 { 0040 Q_OBJECT 0041 Q_PROPERTY(QIcon bookmarkIcon READ bookmarkIcon WRITE setBookmarkIcon) 0042 0043 public: 0044 explicit IconProvider(); 0045 0046 void saveIcon(WebView* view); 0047 0048 QIcon bookmarkIcon() const; 0049 void setBookmarkIcon(const QIcon &icon); 0050 0051 // QStyle equivalent 0052 static QIcon standardIcon(QStyle::StandardPixmap icon); 0053 0054 static QIcon newTabIcon(); 0055 static QIcon newWindowIcon(); 0056 static QIcon privateBrowsingIcon(); 0057 static QIcon settingsIcon(); 0058 0059 // Icon for empty page 0060 static QIcon emptyWebIcon(); 0061 static QImage emptyWebImage(); 0062 0063 // Icon for url (only available for urls in history) 0064 static QIcon iconForUrl(const QUrl &url, bool allowNull = false); 0065 static QImage imageForUrl(const QUrl &url, bool allowNull = false); 0066 0067 // Icon for domain (only available for urls in history) 0068 static QIcon iconForDomain(const QUrl &url, bool allowNull = false); 0069 static QImage imageForDomain(const QUrl &url, bool allowNull = false); 0070 0071 static IconProvider* instance(); 0072 0073 public Q_SLOTS: 0074 void saveIconsToDatabase(); 0075 void clearOldIconsInDatabase(); 0076 0077 private: 0078 using BufferedIcon = QPair<QUrl, QImage>; 0079 0080 QIcon iconFromImage(const QImage &image); 0081 0082 QImage m_emptyWebImage; 0083 QIcon m_bookmarkIcon; 0084 QVector<BufferedIcon> m_iconBuffer; 0085 QCache<QByteArray, QImage> m_urlImageCache; 0086 QMutex m_iconCacheMutex; 0087 0088 AutoSaver* m_autoSaver; 0089 }; 0090 0091 #endif // ICONPROVIDER_H