Falkon Develop
Cross-platform Qt-based web browser
iconprovider.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#ifndef ICONPROVIDER_H
19#define ICONPROVIDER_H
20
21#include <QWidget>
22#include <QStyle>
23#include <QImage>
24#include <QUrl>
25#include <QCache>
26#include <QMutex>
27
28#include <functional>
29
30#include "qzcommon.h"
31
32class QIcon;
33
34class WebView;
35class AutoSaver;
36
37// Needs to be QWidget subclass, otherwise qproperty- setting won't work
38class FALKON_EXPORT IconProvider : public QWidget
39{
40 Q_OBJECT
41 Q_PROPERTY(QIcon bookmarkIcon READ bookmarkIcon WRITE setBookmarkIcon)
42
43public:
44 explicit IconProvider();
45
46 void saveIcon(WebView* view);
47
48 QIcon bookmarkIcon() const;
49 void setBookmarkIcon(const QIcon &icon);
50
51 // QStyle equivalent
52 static QIcon standardIcon(QStyle::StandardPixmap icon);
53
54 static QIcon newTabIcon();
55 static QIcon newWindowIcon();
56 static QIcon privateBrowsingIcon();
57 static QIcon settingsIcon();
58
59 // Icon for empty page
60 static QIcon emptyWebIcon();
61 static QImage emptyWebImage();
62
63 // Icon for url (only available for urls in history)
64 static QIcon iconForUrl(const QUrl &url, bool allowNull = false);
65 static QImage imageForUrl(const QUrl &url, bool allowNull = false);
66
67 // Icon for domain (only available for urls in history)
68 static QIcon iconForDomain(const QUrl &url, bool allowNull = false);
69 static QImage imageForDomain(const QUrl &url, bool allowNull = false);
70
71 static IconProvider* instance();
72
73public Q_SLOTS:
74 void saveIconsToDatabase();
75 void clearOldIconsInDatabase();
76
77private:
78 using BufferedIcon = QPair<QUrl, QImage>;
79
80 QIcon iconFromImage(const QImage &image);
81
82 QImage m_emptyWebImage;
83 QIcon m_bookmarkIcon;
84 QVector<BufferedIcon> m_iconBuffer;
85 QCache<QByteArray, QImage> m_urlImageCache;
86 QMutex m_iconCacheMutex;
87
88 AutoSaver* m_autoSaver;
89};
90
91#endif // ICONPROVIDER_H
#define FALKON_EXPORT
Definition: qzcommon.h:28