1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Small cleanup in code (classes holding settings as static variables)

- merged LocationBarSettings and WebSettings into one class
- new class QzSettings no longer uses static variables
This commit is contained in:
nowrep 2012-08-10 21:16:43 +02:00
parent 1f225de11c
commit e709e17d5c
20 changed files with 103 additions and 158 deletions

View File

@ -44,8 +44,7 @@
#include "speeddial.h"
#include "webpage.h"
#include "settings.h"
#include "locationbarsettings.h"
#include "websettings.h"
#include "qzsettings.h"
#include "clearprivatedata.h"
#include "commandlineoptions.h"
@ -373,8 +372,7 @@ void MainApplication::loadSettings()
m_downloadManager->loadSettings();
}
LocationBarSettings::loadSettings();
WebSettings::loadSettings();
qzSettings->loadSettings();
}
void MainApplication::reloadSettings()

View File

@ -16,10 +16,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "settings.h"
#include "qzsettings.h"
#include <QSettings>
QSettings* Settings::s_settings = 0;
QzSettings* Settings::s_qzSettings = 0;
Settings::Settings()
{
@ -32,6 +34,7 @@ Settings::Settings()
void Settings::createSettings(const QString &fileName)
{
s_settings = new QSettings(fileName, QSettings::IniFormat);
s_qzSettings = new QzSettings();
}
void Settings::syncSettings()
@ -64,6 +67,11 @@ QSettings* Settings::globalSettings()
return s_settings;
}
QzSettings *Settings::staticSettings()
{
return s_qzSettings;
}
Settings::~Settings()
{
if (!s_settings->group().isEmpty()) {

View File

@ -25,7 +25,9 @@
class QSettings;
class Settings
class QzSettings;
class QT_QUPZILLA_EXPORT Settings
{
public:
explicit Settings();
@ -35,6 +37,7 @@ public:
static void syncSettings();
static QSettings* globalSettings();
static QzSettings* staticSettings();
void setValue(const QString &key, const QVariant &defaultValue = QVariant());
QVariant value(const QString &key, const QVariant &defaultValue = QVariant());
@ -48,6 +51,7 @@ public slots:
private:
static QSettings* s_settings;
static QzSettings* s_qzSettings;
};

View File

@ -29,7 +29,7 @@
#include "bookmarksimportdialog.h"
#include "iconchooser.h"
#include "webtab.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QInputDialog>
#include <QComboBox>
@ -194,7 +194,7 @@ void BookmarksManager::itemControlClicked(QTreeWidgetItem* item)
void BookmarksManager::loadInNewTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
getQupZilla()->tabWidget()->addView(action->data().toUrl(), WebSettings::newTabPosition);
getQupZilla()->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
}
}

View File

@ -25,7 +25,7 @@
#include "tabbedwebview.h"
#include "historymodel.h"
#include "headerview.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QMessageBox>
@ -90,7 +90,7 @@ void HistoryManager::search(const QString &searchText)
void HistoryManager::openLink(const QUrl &url, HistoryView::OpenBehavior openIn)
{
if (openIn == HistoryView::OpenInNewTab) {
getQupZilla()->tabWidget()->addView(url, WebSettings::newTabPosition);
getQupZilla()->tabWidget()->addView(url, qzSettings->newTabPosition);
}
else {
getQupZilla()->weView()->load(url);

View File

@ -110,7 +110,6 @@ SOURCES += \
3rdparty/squeezelabelv2.cpp \
3rdparty/squeezelabelv1.cpp \
tools/buttonwithmenu.cpp \
navigation/locationbarsettings.cpp \
other/browsinglibrary.cpp \
3rdparty/stylehelper.cpp \
3rdparty/fancytabwidget.cpp \
@ -164,7 +163,6 @@ SOURCES += \
bookmarksimport/bookmarksimporticonfetcher.cpp \
other/checkboxdialog.cpp \
tools/plaineditwithlines.cpp \
webview/websettings.cpp \
tools/focusselectlineedit.cpp \
navigation/completer/locationcompleterdelegate.cpp \
navigation/completer/locationcompleter.cpp \
@ -181,7 +179,8 @@ SOURCES += \
adblock/adblockschemehandler.cpp \
tools/emptynetworkreply.cpp \
3rdparty/processinfo.cpp \
preferences/pluginsmanager.cpp
preferences/pluginsmanager.cpp \
other/qzsettings.cpp
HEADERS += \
webview/tabpreview.h \
@ -259,7 +258,6 @@ HEADERS += \
3rdparty/squeezelabelv2.h \
3rdparty/squeezelabelv1.h \
tools/buttonwithmenu.h \
navigation/locationbarsettings.h \
other/browsinglibrary.h \
3rdparty/stylehelper.h \
3rdparty/fancytabwidget.h \
@ -317,7 +315,6 @@ HEADERS += \
network/schemehandler.h \
tools/plaineditwithlines.h \
sidebar/sidebarinterface.h \
webview/websettings.h \
tools/focusselectlineedit.h \
navigation/completer/locationcompleterdelegate.h \
navigation/completer/locationcompleter.h \
@ -334,7 +331,8 @@ HEADERS += \
adblock/adblockschemehandler.h \
tools/emptynetworkreply.h \
3rdparty/processinfo.h \
preferences/pluginsmanager.h
preferences/pluginsmanager.h \
other/qzsettings.h
FORMS += \
preferences/autofillmanager.ui \

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "locationcompletermodel.h"
#include "locationbarsettings.h"
#include "iconprovider.h"
#include "qzsettings.h"
#include "mainapplication.h"
#include <QSqlQuery>
@ -43,7 +43,7 @@ void LocationCompleterModel::refreshCompletions(const QString &string)
clear();
Type showType = (Type) LocationBarSettings::showLocationSuggestions;
Type showType = (Type) qzSettings->showLocationSuggestions;
int limit = string.size() < 3 ? 25 : 15;
QString searchString = QString("%%1%").arg(string);

View File

@ -28,7 +28,6 @@
#include "bookmarkicon.h"
#include "progressbar.h"
#include "statusbarmessage.h"
#include "locationbarsettings.h"
#include "toolbutton.h"
#include "searchenginesmanager.h"
#include "siteicon.h"
@ -37,7 +36,7 @@
#include "downicon.h"
#include "globalfunctions.h"
#include "iconprovider.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QClipboard>
@ -376,7 +375,7 @@ void LocationBar::focusOutEvent(QFocusEvent* e)
void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton && LocationBarSettings::selectAllOnDoubleClick) {
if (event->button() == Qt::LeftButton && qzSettings->selectAllOnDoubleClick) {
selectAll();
}
else {
@ -386,7 +385,7 @@ void LocationBar::mouseDoubleClickEvent(QMouseEvent* event)
void LocationBar::mousePressEvent(QMouseEvent* event)
{
if (cursorPosition() == 0 && LocationBarSettings::selectAllOnClick) {
if (cursorPosition() == 0 && qzSettings->selectAllOnClick) {
selectAll();
return;
}
@ -429,7 +428,7 @@ void LocationBar::keyPressEvent(QKeyEvent* event)
break;
case Qt::AltModifier:
p_QupZilla->tabWidget()->addView(createUrl(), WebSettings::newTabPosition);
p_QupZilla->tabWidget()->addView(createUrl(), qzSettings->newTabPosition);
m_holdingAlt = false;
break;
@ -468,7 +467,7 @@ void LocationBar::keyReleaseEvent(QKeyEvent* event)
{
QString localDomain = tr(".co.uk", "Append domain name on ALT + Enter = Should be different for every country");
if (event->key() == Qt::Key_Alt && m_holdingAlt && LocationBarSettings::addCountryWithAlt &&
if (event->key() == Qt::Key_Alt && m_holdingAlt && qzSettings->addCountryWithAlt &&
!text().endsWith(localDomain) && !text().endsWith("/")) {
LineEdit::setText(text().append(localDomain));
}

View File

@ -1,47 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "locationbarsettings.h"
#include "mainapplication.h"
#include "settings.h"
bool LocationBarSettings::selectAllOnDoubleClick = false;
bool LocationBarSettings::selectAllOnClick = false;
bool LocationBarSettings::addCountryWithAlt = false;
int LocationBarSettings::showLocationSuggestions = 0;
bool LocationBarSettings::showSearchSuggestions = false;
LocationBarSettings::LocationBarSettings()
{
loadSettings();
}
void LocationBarSettings::loadSettings()
{
Settings settings;
settings.beginGroup("AddressBar");
selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool();
selectAllOnClick = settings.value("SelectAllTextOnClick", false).toBool();
addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool();
showLocationSuggestions = settings.value("showSuggestions", 0).toInt();
settings.endGroup();
settings.beginGroup("SearchEngines");
showSearchSuggestions = settings.value("showSuggestions", true).toBool();
settings.endGroup();
}

View File

@ -1,37 +0,0 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef LOCATIONBARSETTINGS_H
#define LOCATIONBARSETTINGS_H
#include "qz_namespace.h"
class QT_QUPZILLA_EXPORT LocationBarSettings
{
public:
LocationBarSettings();
static void loadSettings();
static bool selectAllOnDoubleClick;
static bool selectAllOnClick;
static bool addCountryWithAlt;
static int showLocationSuggestions;
static bool showSearchSuggestions;
};
#endif // LOCATIONBARSETTINGS_H

View File

@ -27,7 +27,7 @@
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "webpage.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QSplitter>
#include <QHBoxLayout>
@ -297,7 +297,7 @@ void NavigationBar::goAtHistoryIndexInNewTab(int index)
QWebHistory* history = p_QupZilla->weView(tabIndex)->page()->history();
history->goToItem(history->itemAt(index));
if (WebSettings::newTabPosition == Qz::NT_SelectedTab) {
if (qzSettings->newTabPosition == Qz::NT_SelectedTab) {
tabWidget->setCurrentIndex(tabIndex);
}
}

View File

@ -21,13 +21,12 @@
#include "tabbedwebview.h"
#include "webpage.h"
#include "settings.h"
#include "websettings.h"
#include "qzsettings.h"
#include "tabwidget.h"
#include "clickablelabel.h"
#include "buttonwithmenu.h"
#include "searchenginesmanager.h"
#include "searchenginesdialog.h"
#include "locationbarsettings.h"
#include "networkmanager.h"
#include <QCompleter>
@ -104,7 +103,7 @@ void WebSearchBar::aboutToShowMenu()
void WebSearchBar::addSuggestions(const QStringList &list)
{
if (LocationBarSettings::showSearchSuggestions) {
if (qzSettings->showSearchSuggestions) {
QStringList list_ = list.mid(0, 6);
m_completerModel->setStringList(list_);
}
@ -129,7 +128,7 @@ void WebSearchBar::enableSearchSuggestions(bool enable)
settings.setValue("showSuggestions", enable);
settings.endGroup();
LocationBarSettings::showSearchSuggestions = enable;
qzSettings->showSearchSuggestions = enable;
m_completerModel->setStringList(QStringList());
}
@ -193,7 +192,7 @@ void WebSearchBar::search()
void WebSearchBar::searchInNewTab()
{
p_QupZilla->weView()->setFocus();
p_QupZilla->tabWidget()->addView(m_searchManager->searchUrl(m_activeEngine, text()), WebSettings::newTabPosition);
p_QupZilla->tabWidget()->addView(m_searchManager->searchUrl(m_activeEngine, text()), qzSettings->newTabPosition);
}
void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu)
@ -293,7 +292,7 @@ void WebSearchBar::contextMenuEvent(QContextMenuEvent* event)
m_menu->addSeparator();
QAction* act = m_menu->addAction(tr("Show suggestions"));
act->setCheckable(true);
act->setChecked(LocationBarSettings::showSearchSuggestions);
act->setChecked(qzSettings->showSearchSuggestions);
connect(act, SIGNAL(triggered(bool)), this, SLOT(enableSearchSuggestions(bool)));
m_pasteAndGoAction->setEnabled(!QApplication::clipboard()->text().isEmpty());

View File

@ -15,27 +15,33 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#include "websettings.h"
#include "qzsettings.h"
#include "settings.h"
int WebSettings::defaultZoom = 100;
bool WebSettings::loadTabsOnActivation = false;
QzSettings::QzSettings()
{
loadSettings();
}
Qz::NewTabPositionFlag WebSettings::newTabPosition;
QStringList WebSettings::autoOpenProtocols;
QStringList WebSettings::blockedProtocols;
void WebSettings::loadSettings()
void QzSettings::loadSettings()
{
Settings settings;
settings.beginGroup("Web-Browser-Settings");
settings.beginGroup("AddressBar");
selectAllOnDoubleClick = settings.value("SelectAllTextOnDoubleClick", true).toBool();
selectAllOnClick = settings.value("SelectAllTextOnClick", false).toBool();
addCountryWithAlt = settings.value("AddCountryDomainWithAltKey", true).toBool();
showLocationSuggestions = settings.value("showSuggestions", 0).toInt();
settings.endGroup();
settings.beginGroup("SearchEngines");
showSearchSuggestions = settings.value("showSuggestions", true).toBool();
settings.endGroup();
settings.beginGroup("Web-Browser-Settings");
defaultZoom = settings.value("DefaultZoom", 100).toInt();
loadTabsOnActivation = settings.value("LoadTabsOnActivation", false).toBool();
autoOpenProtocols = settings.value("AutomaticallyOpenProtocols", QStringList()).toStringList();
blockedProtocols = settings.value("BlockOpeningProtocols", QStringList()).toStringList();
settings.endGroup();
settings.beginGroup("Browser-Tabs-Settings");
@ -43,7 +49,7 @@ void WebSettings::loadSettings()
settings.endGroup();
}
void WebSettings::saveSettings()
void QzSettings::saveSettings()
{
Settings settings;
settings.beginGroup("Web-Browser-Settings");
@ -53,3 +59,5 @@ void WebSettings::saveSettings()
settings.endGroup();
}

View File

@ -15,27 +15,42 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ============================================================ */
#ifndef WEBVIEWSETTINGS_H
#define WEBVIEWSETTINGS_H
#ifndef QZSETTINGS_H
#define QZSETTINGS_H
#include "qz_namespace.h"
#include "settings.h"
#include <QStringList>
class WebSettings
class QT_QUPZILLA_EXPORT QzSettings
{
public:
WebSettings();
QzSettings();
static void loadSettings();
static void saveSettings();
void loadSettings();
void saveSettings();
static int defaultZoom;
static bool loadTabsOnActivation;
// AddressBar
bool selectAllOnDoubleClick;
bool selectAllOnClick;
bool addCountryWithAlt;
int showLocationSuggestions;
static Qz::NewTabPositionFlag newTabPosition;
static QStringList autoOpenProtocols;
static QStringList blockedProtocols;
// SearchEngines
bool showSearchSuggestions;
// Web-Browser-Settings
int defaultZoom;
bool loadTabsOnActivation;
QStringList autoOpenProtocols;
QStringList blockedProtocols;
// Browser-Tabs-Settings
Qz::NewTabPositionFlag newTabPosition;
};
#endif // WEBVIEWSETTINGS_H
#define qzSettings Settings::staticSettings()
#endif // QZSETTINGS_H

View File

@ -26,7 +26,7 @@
#include "globalfunctions.h"
#include "followredirectreply.h"
#include "networkmanager.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QMenu>
#include <QXmlStreamReader>
@ -266,13 +266,13 @@ void RSSManager::controlLoadFeed(QTreeWidgetItem* item)
return;
}
getQupZilla()->tabWidget()->addView(QUrl(item->toolTip(0)), WebSettings::newTabPosition);
getQupZilla()->tabWidget()->addView(QUrl(item->toolTip(0)), qzSettings->newTabPosition);
}
void RSSManager::loadFeedInNewTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
getQupZilla()->tabWidget()->addView(action->data().toUrl(), WebSettings::newTabPosition);
getQupZilla()->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
}
}

View File

@ -24,7 +24,7 @@
#include "bookmarkstoolbar.h"
#include "tabwidget.h"
#include "bookmarksmodel.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QMenu>
#include <QTimer>
@ -80,7 +80,7 @@ void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem* item)
void BookmarksSideBar::loadInNewTab()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
p_QupZilla->tabWidget()->addView(action->data().toUrl(), WebSettings::newTabPosition);
p_QupZilla->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
}
}

View File

@ -22,7 +22,7 @@
#include "tabbedwebview.h"
#include "mainapplication.h"
#include "historymodel.h"
#include "websettings.h"
#include "qzsettings.h"
HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent)
: QWidget(parent)
@ -43,7 +43,7 @@ HistorySideBar::HistorySideBar(QupZilla* mainClass, QWidget* parent)
void HistorySideBar::openLink(const QUrl &url, HistoryView::OpenBehavior openIn)
{
if (openIn == HistoryView::OpenInNewTab) {
p_QupZilla->tabWidget()->addView(url, WebSettings::newTabPosition);
p_QupZilla->tabWidget()->addView(url, qzSettings->newTabPosition);
}
else {
p_QupZilla->weView()->load(url);

View File

@ -33,7 +33,7 @@
#include "adblockicon.h"
#include "adblockmanager.h"
#include "iconprovider.h"
#include "websettings.h"
#include "qzsettings.h"
#ifdef NONBLOCK_JS_DIALOGS
#include "ui_jsconfirm.h"
@ -310,12 +310,12 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
{
const QString &protocol = url.scheme();
if (WebSettings::blockedProtocols.contains(protocol)) {
if (qzSettings->blockedProtocols.contains(protocol)) {
qDebug() << "WebPage::handleUnknownProtocol Protocol" << protocol << "is blocked!";
return;
}
if (WebSettings::autoOpenProtocols.contains(protocol)) {
if (qzSettings->autoOpenProtocols.contains(protocol)) {
desktopServicesOpen(url);
return;
}
@ -335,8 +335,8 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
switch (dialog.exec()) {
case QDialog::Accepted:
if (dialog.isChecked()) {
WebSettings::autoOpenProtocols.append(protocol);
WebSettings::saveSettings();
qzSettings->autoOpenProtocols.append(protocol);
qzSettings->saveSettings();
}
QDesktopServices::openUrl(url);
@ -344,8 +344,8 @@ void WebPage::handleUnknownProtocol(const QUrl &url)
case QDialog::Rejected:
if (dialog.isChecked()) {
WebSettings::blockedProtocols.append(protocol);
WebSettings::saveSettings();
qzSettings->blockedProtocols.append(protocol);
qzSettings->saveSettings();
}
break;

View File

@ -23,7 +23,7 @@
#include "tabwidget.h"
#include "locationbar.h"
#include "globalfunctions.h"
#include "websettings.h"
#include "qzsettings.h"
#include <QVBoxLayout>
#include <QWebHistory>
@ -222,7 +222,7 @@ bool WebTab::isRestored() const
void WebTab::restoreTab(const WebTab::SavedTab &tab)
{
if (WebSettings::loadTabsOnActivation) {
if (qzSettings->loadTabsOnActivation) {
m_savedTab = tab;
int index = tabIndex();

View File

@ -29,7 +29,7 @@
#include "browsinglibrary.h"
#include "bookmarksmanager.h"
#include "settings.h"
#include "websettings.h"
#include "qzsettings.h"
#include "enhancedmenu.h"
#include "pluginproxy.h"
@ -125,7 +125,7 @@ void WebView::setPage(QWebPage* page)
QWebView::setPage(page);
m_page = qobject_cast<WebPage*>(page);
setZoom(WebSettings::defaultZoom);
setZoom(qzSettings->defaultZoom);
connect(m_page, SIGNAL(saveFrameStateRequested(QWebFrame*, QWebHistoryItem*)), this, SLOT(frameStateChanged()));
connect(m_page, SIGNAL(privacyChanged(bool)), this, SIGNAL(privacyChanged(bool)));
@ -509,7 +509,7 @@ void WebView::openUrlInBackgroundTab()
void WebView::userDefinedOpenUrlInNewTab(const QUrl &url, bool invert)
{
Qz::NewTabPositionFlag position = WebSettings::newTabPosition;
Qz::NewTabPositionFlag position = qzSettings->newTabPosition;
if (invert) {
position = (position == Qz::NT_SelectedTab) ? Qz::NT_NotSelectedTab : Qz::NT_SelectedTab;
}