aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-02 11:02:42 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-02 11:02:42 +0200
commit3533e0d4cce3e7af2df8e6c42f462315da8c9df8 (patch)
treeff19b54818708f122f4dc501fcaf80594b8b99a2 /src
parentFix hg bookmark not showing up in arch build version (diff)
downloadsmolbote-3533e0d4cce3e7af2df8e6c42f462315da8c9df8.tar.xz
Clazy fixes
Diffstat (limited to 'src')
-rw-r--r--src/browser.cpp14
-rw-r--r--src/browser.h4
-rw-r--r--src/mainwindow/mainwindow.cpp10
-rw-r--r--src/mainwindow/subwindow.cpp2
-rw-r--r--src/webengine/urlinterceptor.cpp31
-rw-r--r--src/webengine/webprofile.cpp24
6 files changed, 49 insertions, 36 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 3442d66..4f3f3d7 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -117,14 +117,14 @@ void Browser::setup(const QString &defaultProfile)
m_plugins.append(loadPlugins(QString::fromStdString(m_config->value<std::string>("plugins.path").value())));
// register commands
- for(Plugin p : m_plugins) {
+ for(const Plugin &p : qAsConst(m_plugins)) {
if(p.instance->inherits("ProfileInterface")) {
auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
Q_ASSERT_X(profileEditor != nullptr, "Browser::setup", "profile interface cast failed");
- for(const QString &name : m_profiles.keys()) {
- profileEditor->addProfile(name, qobject_cast<QWebEngineProfile*>(m_profiles.value(name)));
+ for(auto i = m_profiles.constBegin(); i != m_profiles.constEnd(); ++i) {
+ profileEditor->addProfile(i.key(), qobject_cast<QWebEngineProfile*>(i.value()));
}
}
@@ -228,11 +228,11 @@ MainWindow *Browser::createWindow()
});
window->addAction(MainWindow::ToolsMenu, downloadsAction);
- for(Plugin p : m_plugins) {
- auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
- if(profileEditor) {
+ for(const Plugin &p : qAsConst(m_plugins)) {
+ if(p.instance->inherits("ProfileInterface")) {
+ auto *profileEditor = qobject_cast<ProfileInterface *>(p.instance.get());
auto *profileAction = new QAction(tr("Profile"), window);
- connect(profileAction, &QAction::triggered, window, [this, profileEditor]() {
+ connect(profileAction, &QAction::triggered, window, [profileEditor]() {
profileEditor->createWidget(nullptr)->show();
});
window->addAction(MainWindow::ToolsMenu, profileAction);
diff --git a/src/browser.h b/src/browser.h
index 03126d3..a06993d 100644
--- a/src/browser.h
+++ b/src/browser.h
@@ -37,13 +37,13 @@ public:
void setup(const QString &defaultProfile);
WebProfile *profile(const QString &name) const;
- QStringList profiles() const
+ const QStringList profiles() const
{
return m_profiles.keys();
}
int command(const QString &command);
- QStringList commands() const
+ const QStringList commands() const
{
return m_commands.keys();
}
diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp
index 7e49ab8..0234f13 100644
--- a/src/mainwindow/mainwindow.cpp
+++ b/src/mainwindow/mainwindow.cpp
@@ -116,7 +116,7 @@ void MainWindow::createMenuBar()
createSubWindow();
}, QKeySequence(m_config->value<std::string>("mainwindow.shortcuts.newGroup").value().c_str()));
- smolboteMenu->addAction(tr("New window"), this, [this]() {
+ smolboteMenu->addAction(tr("New window"), this, []() {
auto *browser = qobject_cast<Browser *>(qApp);
if(browser)
browser->createWindow();
@@ -158,20 +158,20 @@ void MainWindow::addAction(ActionLocation where, QAction *action)
void MainWindow::addDockWidget(Qt::DockWidgetArea area, QWidget *widget)
{
- QList<QDockWidget *> docks;
+ QDockWidget *lastDock = nullptr;
for(QDockWidget *dock : findChildren<QDockWidget *>()) {
if(dockWidgetArea(dock) == area)
- docks.append(dock);
+ lastDock = dock;
}
DockWidget *dock = new DockWidget(widget->windowTitle(), this);
dock->setMinimumWidth(460);
dock->setWidget(widget);
- if(docks.empty())
+ if(lastDock == nullptr)
QMainWindow::addDockWidget(area, dock);
else
- tabifyDockWidget(docks.last(), dock);
+ tabifyDockWidget(lastDock, dock);
}
void MainWindow::removeDockWidget(QWidget *widget)
diff --git a/src/mainwindow/subwindow.cpp b/src/mainwindow/subwindow.cpp
index 497e6d0..17a2268 100644
--- a/src/mainwindow/subwindow.cpp
+++ b/src/mainwindow/subwindow.cpp
@@ -196,7 +196,7 @@ void SubWindow::restoreSession(const QJsonObject &sessionData)
return;
}
- for(const auto tab : tabs) {
+ for(const auto &tab : tabs) {
auto *view = new WebView(profile, this);
view->load(QUrl::fromUserInput(tab.toString()));
tabWidget->addTab(view);
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index e88e5b7..5e17e78 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -25,13 +25,7 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren
#endif
rulesLock.lock();
- for(const auto &k : r.keys()) {
- if(rules.contains(k)) {
- //
- } else {
- rules.insert(k, r.value(k));
- }
- }
+ rules.unite(r);
rulesLock.unlock();
});
}
@@ -57,28 +51,41 @@ QHash<QString, UrlRequestInterceptor::HostRule> parse(const QString &filename)
// with a QTextStream we can read lines without getting linebreaks at the end
QTextStream hostfile_stream(&hostfile);
+
while(!hostfile_stream.atEnd()) {
+
// read line and remove any whitespace at the end
const QString &line = hostfile_stream.readLine().trimmed();
// skip comments and empty lines
+ if(line.isEmpty() || line.startsWith('#'))
+ continue;
+
// everything else should be a rule
// format is <redirect> <host>
// 0.0.0.0 hostname
const QStringList &parts = line.split(' ');
const QString &redirect = parts.at(0);
- for(const QString &host : parts.mid(1)) {
- if(!rules.contains(host)) {
+ for(auto i = parts.constBegin() + 1; i != parts.constEnd(); ++i) {
+ if(!rules.contains(*i)) {
UrlRequestInterceptor::HostRule rule{};
- rule.isBlocking = redirect == "0.0.0.0";
- rules.insert(host, rule);
+ rule.isBlocking = (redirect == "0.0.0.0");
+ rules.insert(*i, rule);
}
}
+
+// for(const QString &host : parts.mid(1)) {
+// if(!rules.contains(host)) {
+// UrlRequestInterceptor::HostRule rule{};
+// rule.isBlocking = redirect == "0.0.0.0";
+// rules.insert(host, rule);
+// }
+// }
}
hostfile.close();
}
return rules;
-}; \ No newline at end of file
+};
diff --git a/src/webengine/webprofile.cpp b/src/webengine/webprofile.cpp
index 081e091..5b07645 100644
--- a/src/webengine/webprofile.cpp
+++ b/src/webengine/webprofile.cpp
@@ -21,27 +21,33 @@ void loadProfile(WebProfile *profile, const QString &path)
return;
#ifdef QT_DEBUG
- qDebug("Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path));
+ qDebug("+ Reading config for profile '%s': %s", qUtf8Printable(profile->name()), qUtf8Printable(path));
#endif
QSettings config(path, QSettings::IniFormat);
config.beginGroup("properties");
- for(const QString &key : config.childKeys()) {
+ {
+ const auto keys = config.childKeys();
+ for(const QString &key : keys) {
#ifdef QT_DEBUG
- qDebug("set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
+ qDebug("- set property %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
- profile->setProperty(qUtf8Printable(key), config.value(key));
+ profile->setProperty(qUtf8Printable(key), config.value(key));
+ }
}
config.endGroup(); // properties
config.beginGroup("attributes");
- auto *settings = profile->settings();
- for(const QString &key : config.childKeys()) {
+ {
+ const auto keys = config.childKeys();
+ auto *settings = profile->settings();
+ for(const QString &key : keys) {
#ifdef QT_DEBUG
- qDebug("set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
+ qDebug("- set attribute %s to %s", qUtf8Printable(key), qUtf8Printable(config.value(key).toString()));
#endif
- auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
- settings->setAttribute(attribute, config.value(key).toBool());
+ auto attribute = static_cast<QWebEngineSettings::WebAttribute>(key.toInt());
+ settings->setAttribute(attribute, config.value(key).toBool());
+ }
}
config.endGroup();