Falkon Develop
Cross-platform Qt-based web browser
sbi_iconsmanager.cpp
Go to the documentation of this file.
1/* ============================================================
2* StatusBarIcons - Extra icons in statusbar for Falkon
3* Copyright (C) 2013-2018 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#include "sbi_iconsmanager.h"
19#include "sbi_imagesicon.h"
20#include "sbi_javascripticon.h"
21#include "sbi_zoomwidget.h"
22#include "sbi_networkicon.h"
23#include "sbi_networkmanager.h"
24#include "browserwindow.h"
25#include "statusbar.h"
26
27#include <QSettings>
28
29SBI_IconsManager::SBI_IconsManager(const QString &settingsPath, QObject* parent)
30 : QObject(parent)
31 , m_settingsPath(settingsPath)
32 , m_showImagesIcon(false)
33 , m_showJavaScriptIcon(false)
34 , m_showNetworkIcon(false)
35 , m_showZoomWidget(false)
36 , m_networkManager(nullptr)
37{
39}
40
42{
43 QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
44 settings.beginGroup("StatusBarIcons");
45 m_showImagesIcon = settings.value("showImagesIcon", true).toBool();
46 m_showJavaScriptIcon = settings.value("showJavaScriptIcon", true).toBool();
47 m_showNetworkIcon = settings.value("showNetworkIcon", true).toBool();
48 m_showZoomWidget = settings.value("showZoomWidget", true).toBool();
49 settings.endGroup();
50}
51
53{
54 return m_showImagesIcon;
55}
56
58{
59 QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
60 settings.setValue("StatusBarIcons/showImagesIcon", show);
61
62 m_showImagesIcon = show;
63}
64
66{
67 return m_showJavaScriptIcon;
68}
69
71{
72 QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
73 settings.setValue("StatusBarIcons/showJavaScriptIcon", show);
74
75 m_showJavaScriptIcon = show;
76}
77
79{
80 return m_showNetworkIcon;
81}
82
84{
85 QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
86 settings.setValue("StatusBarIcons/showNetworkIcon", show);
87
88 m_showNetworkIcon = show;
89}
90
92{
93 return m_showZoomWidget;
94}
95
97{
98 QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
99 settings.setValue("StatusBarIcons/showZoomWidget", show);
100
101 m_showZoomWidget = show;
102}
103
105{
106 QHashIterator<BrowserWindow*, QWidgetList> it(m_windows);
107
108 while (it.hasNext()) {
109 it.next();
110 mainWindowDeleted(it.key());
111 mainWindowCreated(it.key());
112 }
113}
114
116{
117 QHashIterator<BrowserWindow*, QWidgetList> it(m_windows);
118
119 while (it.hasNext()) {
120 it.next();
121 mainWindowDeleted(it.key());
122 }
123}
124
126{
127 if (m_showImagesIcon) {
128 auto* w = new SBI_ImagesIcon(window, m_settingsPath);
129 window->statusBar()->addPermanentWidget(w);
130 m_windows[window].append(w);
131 }
132
133 if (m_showJavaScriptIcon) {
134 auto* w = new SBI_JavaScriptIcon(window);
135 window->statusBar()->addPermanentWidget(w);
136 m_windows[window].append(w);
137 }
138
139 if (m_showNetworkIcon) {
140 if (!m_networkManager) {
141 m_networkManager = new SBI_NetworkManager(m_settingsPath, this);
142 }
143
144 auto* w = new SBI_NetworkIcon(window);
145 window->statusBar()->addPermanentWidget(w);
146 m_windows[window].append(w);
147 }
148
149 if (m_showZoomWidget) {
150 auto* w = new SBI_ZoomWidget(window);
151 window->statusBar()->addPermanentWidget(w);
152 m_windows[window].append(w);
153 }
154}
155
157{
158 const auto windows = m_windows[window];
159 for (QWidget* w : windows) {
160 window->statusBar()->removeWidget(w);
161 delete w;
162 }
163
164 m_windows[window].clear();
165}
166
168{
169 delete m_networkManager;
170}
StatusBar * statusBar() const
void mainWindowDeleted(BrowserWindow *window)
void mainWindowCreated(BrowserWindow *window)
bool showNetworkIcon() const
bool showImagesIcon() const
bool showZoomWidget() const
void setShowImagesIcon(bool show)
void setShowNetworkIcon(bool show)
bool showJavaScriptIcon() const
SBI_IconsManager(const QString &settingsPath, QObject *parent=nullptr)
void setShowJavaScriptIcon(bool show)
void setShowZoomWidget(bool show)
#define QL1S(x)
Definition: qzcommon.h:44