diff options
27 files changed, 216 insertions, 189 deletions
diff --git a/lib/bookmarks/bookmarkmodel.cpp b/lib/bookmarks/bookmarkmodel.cpp index 8599f1d..0775ff2 100644 --- a/lib/bookmarks/bookmarkmodel.cpp +++ b/lib/bookmarks/bookmarkmodel.cpp @@ -241,10 +241,11 @@ inline QStringList searchThrough(const QString &term, const QStringList &tags, B if(has(tags, child->data(BookmarkItem::Tags).toStringList())) { // append all bookmarks - for(int i = 0; i < child->childCount(); ++i) { - auto *subChild = child->child(i); - if(subChild->type() == BookmarkItem::Bookmark) + for(int j = 0; j < child->childCount(); ++j) { + auto *subChild = child->child(j); + if(subChild->type() == BookmarkItem::Bookmark) { results.append(subChild->data(BookmarkItem::Href).toString()); + } } } results.append(searchThrough(term, tags, child)); diff --git a/lib/bookmarks/formats/ffjson.cpp b/lib/bookmarks/formats/ffjson.cpp index 1fe6a96..f9e0866 100644 --- a/lib/bookmarks/formats/ffjson.cpp +++ b/lib/bookmarks/formats/ffjson.cpp @@ -32,7 +32,8 @@ inline void readElementData(const QJsonObject &object, BookmarkItem *item) item->setData(BookmarkItem::Tags, tags); // descriptions - for(const auto &a : object["annos"].toArray()) { + const auto annos_array = object["annos"].toArray(); + for(const auto &a : annos_array) { const auto anno = a.toObject(); if(anno["name"] == "bookmarkProperties/description") { item->setData(BookmarkItem::Description, anno["value"].toString()); @@ -40,9 +41,10 @@ inline void readElementData(const QJsonObject &object, BookmarkItem *item) } } -void readChildElements(const QJsonObject &object, BookmarkItem *item) +inline void readChildElements(const QJsonObject &object, BookmarkItem *item) { - for(const auto c : object["children"].toArray()) { + const auto children_array = object["children"].toArray(); + for(const auto &c : children_array) { const auto child = c.toObject(); const auto type = child["type"].toString(); diff --git a/lib/downloads/widgets/downloaditemwidget.cpp b/lib/downloads/widgets/downloaditemwidget.cpp index 241b90b..e0c8a60 100644 --- a/lib/downloads/widgets/downloaditemwidget.cpp +++ b/lib/downloads/widgets/downloaditemwidget.cpp @@ -13,7 +13,7 @@ #include <QDesktopServices> #include <QBuffer> -inline QString sizeString(int size) +inline QString sizeString(qint64 size) { if(size < 1024) { return QString("%1 bytes").arg(size); @@ -30,12 +30,12 @@ inline QString sizeString(int size) return QString("%1 GB").arg(size / (1024 * 1024 * 1024)); } -DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent) +DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *parent) : QWidget(parent) , ui(new Ui::DownloadItemForm) { Q_CHECK_PTR(item); - this->item = item; + m_item = item; ui->setupUi(this); { // pause/resume icons @@ -56,15 +56,11 @@ DownloadItemWidget::DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *pa connect(item, &QWebEngineDownloadItem::finished, this, &DownloadItemWidget::updateFinished); connect(ui->abort_toolButton, &QToolButton::clicked, item, &QWebEngineDownloadItem::cancel); - connect(ui->pause_toolButton, &QToolButton::clicked, item, [item](bool clicked) { - if(clicked) { - item->pause(); - } else { - item->resume(); - } + connect(ui->pause_toolButton, &QToolButton::clicked, item, [m_item](bool clicked) { + clicked ? m_item->pause() : m_item->resume(); }); - connect(ui->open_toolButton, &QToolButton::clicked, item, [item]() { - QDesktopServices::openUrl(QUrl::fromLocalFile(item->downloadDirectory()+'/'+item->downloadFileName())); + connect(ui->open_toolButton, &QToolButton::clicked, item, [m_item]() { + QDesktopServices::openUrl(QUrl::fromLocalFile(m_item->downloadDirectory() + '/' + m_item->downloadFileName())); }); } @@ -113,8 +109,7 @@ void DownloadItemWidget::updateState(QWebEngineDownloadItem::DownloadState state void DownloadItemWidget::updateProgress(qint64 value, qint64 total) { - ui->progressBar->setMaximum(total); - ui->progressBar->setValue(value); + ui->progressBar->setValue(static_cast<int>((static_cast<long double>(value) / static_cast<long double>(total)) * 100)); ui->progressBar->setFormat(QString("%1 / %2").arg(sizeString(value), sizeString(total))); } diff --git a/lib/downloads/widgets/downloaditemwidget.h b/lib/downloads/widgets/downloaditemwidget.h index c2809d2..a1de175 100644 --- a/lib/downloads/widgets/downloaditemwidget.h +++ b/lib/downloads/widgets/downloaditemwidget.h @@ -22,7 +22,7 @@ class DownloadItemWidget : public QWidget Q_OBJECT public: - explicit DownloadItemWidget(QWebEngineDownloadItem *item, QWidget *parent = 0); + explicit DownloadItemWidget(QWebEngineDownloadItem *m_item, QWidget *parent = 0); ~DownloadItemWidget() override; private slots: diff --git a/lib/pluginloader/pluginloader.cpp b/lib/pluginloader/pluginloader.cpp index 082a449..ce84c7a 100644 --- a/lib/pluginloader/pluginloader.cpp +++ b/lib/pluginloader/pluginloader.cpp @@ -65,7 +65,11 @@ bool PluginLoader::verify(const char *hashName) const std::size_t buffer_size = 1024; std::vector<char> buffer(buffer_size); - while(const auto sz = plugin.readsome(&buffer.front(), buffer_size)) { + std::size_t sz = 0; + while(true) { + sz = static_cast<std::size_t>(plugin.readsome(&buffer.front(), buffer_size)); + if(sz <= 0) + break; rc = EVP_DigestVerifyUpdate(ctx, reinterpret_cast<unsigned char *>(buffer.data()), sz); if(rc != 1) { m_sigError = tr("Failed to compute signature (stage=update)"); diff --git a/lib/pluginloader/pluginloader.h b/lib/pluginloader/pluginloader.h index 703c285..cc67901 100644 --- a/lib/pluginloader/pluginloader.h +++ b/lib/pluginloader/pluginloader.h @@ -45,6 +45,6 @@ public: bool verify(const char *hashName = "SHA256"); private: - const int m_state; + const signature_state_t m_state; QString m_sigError; }; diff --git a/lib/session_formats/session_json.cpp b/lib/session_formats/session_json.cpp index eca96f2..96319ac 100644 --- a/lib/session_formats/session_json.cpp +++ b/lib/session_formats/session_json.cpp @@ -10,7 +10,7 @@ #include <QJsonArray> #include <QJsonDocument> -[[nodiscard]] QVector<Session::MainWindow> toWindowList(const QString &profile, const QStringList &urls) +[[nodiscard]] inline QVector<Session::MainWindow> toWindowList(const QString &profile, const QStringList &urls) { Session::SubWindow main_; main_.profile = profile; @@ -22,7 +22,7 @@ return { main }; } -[[nodiscard]] QJsonObject toJson(const QVector<Session::MainWindow> &windows) +[[nodiscard]] inline QJsonObject toJson(const QVector<Session::MainWindow> &windows) { QJsonObject root; QJsonArray windows_; @@ -76,12 +76,18 @@ QByteArray JsonSession::serialize() const QVector<Session::MainWindow> JsonSession::get() const { QVector<Session::MainWindow> windows; - for(const auto &windowData : root["windows"].toArray()) { + const auto root_array = root["windows"].toArray(); + for(const auto &windowData : root_array) { Session::MainWindow window; - for(const auto &subwindowData : windowData.toObject()["subwindows"].toArray()) { + + const auto subwindows_array = windowData.toObject()["subwindows"].toArray(); + for(const auto &subwindowData : subwindows_array) { Session::SubWindow subwindow; + subwindow.profile = subwindowData.toObject()["profile"].toString(); - for(const auto &tabData : subwindowData.toObject()["tabs"].toArray()) { + + const auto tabs_array = subwindowData.toObject()["tabs"].toArray(); + for(const auto &tabData : tabs_array) { Session::WebView tab{ tabData.toObject()["profile"].toString(), tabData.toObject()["url"].toString(), diff --git a/meson.build b/meson.build index c180449..bc72ff3 100644 --- a/meson.build +++ b/meson.build @@ -37,12 +37,41 @@ add_project_arguments(cxx.get_supported_arguments([ # clang specific '-mspeculative-load-hardening', # Spectre v1 mitigation - '-Wconsumed', # use-after-move warnings '-Xclang -plugin-arg-clazy -Xclang level0,level1', # clazy default warning level + ## warnings + # variables + '-Wunused', # warn on anything being unused + '-Wshadow', # if variable declaration shadows one from a parent context + # functions + '-Wnon-virtual-dtor', # if class with virtual functions has non-virtual dtor + '-Werror=missing-declarations', # missing function declarations in header files + '-Werror=redundant-decls', + '-Woverloaded-virtual', # warn if you overload (not override) a virtual function + '-Werror=return-type', + # style + '-Wformat=2', # security issues around printf '-Wdate-time', # __TIME__ and __DATE__ macros - '-Wimplicit-fallthrough', # switch implicit fallthrough - '-Wold-style-cast' # c-style casts + '-Werror=missing-field-initializers', + # objects + '-Wnull-dereference', + '-Wconsumed', # use-after-move warnings + '-Wlifetime', # object lifetime issues + # logic + '-Wlogical-op', # logical operations being used where bitwise were probably wanted + '-Wimplicit-fallthrough', + '-Wduplicated-cond', # if/else chain has duplicated conditions + '-Wduplicated-brances', # if/else branches have duplicated code + # casts + '-Wold-style-cast', + '-Wcast-align', # potential performance problem casts + '-Wuseless-cast', # cast to same type + '-Wconversion', # type conversions that may lose data + '-Wsign-conversion', # sign conversions + '-Wdouble-promotion', # float is promoted to double + # others + '-Werror=pedantic', # if non-standard c++ is used + #'-Weffc++', ]), language: 'cpp') if get_option('buildtype') == 'release' diff --git a/plugins/ProfileEditor/forms/profileview.cpp b/plugins/ProfileEditor/forms/profileview.cpp index 992364c..23713cb 100644 --- a/plugins/ProfileEditor/forms/profileview.cpp +++ b/plugins/ProfileEditor/forms/profileview.cpp @@ -111,8 +111,8 @@ ProfileView::ProfileView(const QString &name, QWebEngineProfile *profile, QSetti connectSetting(ui->printElementBackgrounds, m_profile, QWebEngineSettings::PrintElementBackgrounds); // cookies tab - for(const auto &data : profile->property("cookies").toList()) { - for(const auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) { + for(auto &raw_cookies : profile->property("cookies").toList()) { + for(auto &cookie : QNetworkCookie::parseCookies(raw_cookies.toByteArray())) { cookieAdded(cookie); } } diff --git a/plugins/ProfileEditor/forms/settingstable.cpp b/plugins/ProfileEditor/forms/settingstable.cpp index 6cfe144..88781a7 100644 --- a/plugins/ProfileEditor/forms/settingstable.cpp +++ b/plugins/ProfileEditor/forms/settingstable.cpp @@ -47,7 +47,7 @@ void SettingsTable::connect(QSettings *settings, const QString §ion) setItem(row, 1, new QTableWidgetItem("value")); }); - QObject::connect(removeBtn, &QToolButton::clicked, [this, settings, section]() { + QObject::connect(removeBtn, &QToolButton::clicked, settings, [this, settings, section]() { settings->beginGroup(section); const int row = currentRow(); @@ -60,7 +60,7 @@ void SettingsTable::connect(QSettings *settings, const QString §ion) settings->endGroup(); }); - QObject::connect(this, &QTableWidget::cellChanged, [this, settings, section](int row, int column) { + QObject::connect(this, &QTableWidget::cellChanged, settings, [this, settings, section](int row, int column) { // no value has been created yet if(item(row, 1) == nullptr) { return; diff --git a/src/bookmarks/bookmarkswidget.cpp b/src/bookmarks/bookmarkswidget.cpp index e05f291..c7bc5f0 100644 --- a/src/bookmarks/bookmarkswidget.cpp +++ b/src/bookmarks/bookmarkswidget.cpp @@ -163,9 +163,9 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) // import button connect(ui->import_toolButton, &QToolButton::clicked, this, [this]() { - const auto path = QFileDialog::getOpenFileName(this, tr("Open bookmarks file"), QDir::homePath(), tr("Firefox bookmarks backup (*.json)")); - if(!path.isEmpty()) { - loadModel(path, m_model, ui->treeView); + const auto import_path = QFileDialog::getOpenFileName(this, tr("Open bookmarks file"), QDir::homePath(), tr("Firefox bookmarks backup (*.json)")); + if(!import_path.isEmpty()) { + loadModel(import_path, m_model, ui->treeView); } }); } diff --git a/src/browser.cpp b/src/browser.cpp index 4f1e02e..f748e2f 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -63,6 +63,49 @@ Browser::Browser(int &argc, char *argv[], bool allowSecondary) if(auto iconTheme = conf.value<QString>("browser.iconTheme")) { QIcon::setThemeName(iconTheme.value()); } + + if(auto stylesheet = conf.value<QString>("browser.stylesheet")) { + QFile f(stylesheet.value()); + if(f.open(QIODevice::ReadOnly)) { + setStyleSheet(f.readAll()); + f.close(); + } + } + + // load profiles + { + const auto profiles = Util::files(conf.value<QString>("profile.path").value(), { "*.profile" }); + const auto search = conf.value<QString>("profile.search").value(); + const auto homepage = QUrl::fromUserInput(conf.value<QString>("profile.homepage").value()); + const auto newtab = QUrl::fromUserInput(conf.value<QString>("profile.newtab").value()); + const auto default_id = conf.value<QString>("profile.default").value(); + m_profileManager = std::make_unique<WebProfileManager<false>>(profiles, default_id, search, homepage, newtab); + m_profileManager->make_global(); + + for(auto &id : m_profileManager->idList()) { + spdlog::info("Added profile\t{}", qUtf8Printable(id)); + } + + // set default profile + auto *profile = m_profileManager->profile(default_id); + spdlog::info("Default profile\t{}{}\t{}", qUtf8Printable(default_id), profile->isOffTheRecord() ? "*" : "", qUtf8Printable(profile->name())); + } + + // downloads + m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads.path").value()); + m_profileManager->walk([this](const QString &, WebProfile *profile, QSettings *) { + connect(profile, &QWebEngineProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); + }); + + // bookmarks + m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value())); + connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { + m_windows.last()->createTab(url); + }); + + auto *timer = new QTimer(this); + connect(timer, &QTimer::timeout, m_bookmarks.get(), &BookmarksWidget::save); + timer->start(5 * 60 * 1000); // 5min * 60sec * 1000ms } Browser::~Browser() @@ -86,7 +129,7 @@ void Browser::about() void Browser::aboutPlugins() { auto *dlg = new AboutPluginDialog; - for(auto *info : m_plugins) { + for(auto *info : qAsConst(m_plugins)) { dlg->add(info->loader); } dlg->exec(); @@ -118,53 +161,6 @@ bool Browser::loadPlugin(const QString &path) return true; } -void Browser::setup() -{ - Configuration conf; - - if(auto stylesheet = conf.value<QString>("browser.stylesheet")) { - QFile f(stylesheet.value()); - if(f.open(QIODevice::ReadOnly)) { - setStyleSheet(f.readAll()); - f.close(); - } - } - - // downloads - m_downloads = std::make_unique<DownloadsWidget>(conf.value<QString>("downloads.path").value()); - - // load profiles - { - const auto profiles = Util::files(conf.value<QString>("profile.path").value(), { "*.profile" }); - const auto search = conf.value<QString>("profile.search").value(); - const auto homepage = QUrl::fromUserInput(conf.value<QString>("profile.homepage").value()); - const auto newtab = QUrl::fromUserInput(conf.value<QString>("profile.newtab").value()); - const auto default_id = conf.value<QString>("profile.default").value(); - m_profileManager = std::make_unique<WebProfileManager<false>>(profiles, default_id, search, homepage, newtab); - m_profileManager->make_global(); - - for(const auto &id : m_profileManager->idList()) { - spdlog::info("Added profile\t{}", qUtf8Printable(id)); - } - - // set default profile - auto *profile = m_profileManager->profile(default_id); - spdlog::info("Default profile\t{}{}\t{}", qUtf8Printable(default_id), profile->isOffTheRecord() ? "*" : "", qUtf8Printable(profile->name())); - } - - // bookmarks - m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(conf.value<std::string>("bookmarks.path").value())); - - connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { - m_windows.last()->createTab(url); - }); - - auto *timer = new QTimer(this); - connect(timer, &QTimer::timeout, m_bookmarks.get(), &BookmarksWidget::save); - // 5min * 60sec * 1000ms - timer->start(5 * 60 * 1000); -} - void Browser::showWidget(QWidget *widget, MainWindow *where) const { bool wasVisible = widget->isVisible(); @@ -191,8 +187,8 @@ void Browser::open(const QVector<Session::MainWindow> &data, bool merge) window->createTab(tab); } } else { - for(const auto &data : windowData.subwindows) { - window->createSubWindow(data); + for(const auto &window_data : windowData.subwindows) { + window->createSubWindow(window_data); } } diff --git a/src/browser.h b/src/browser.h index 1964267..5b4785b 100644 --- a/src/browser.h +++ b/src/browser.h @@ -31,8 +31,6 @@ public: explicit Browser(int &argc, char *argv[], bool allowSecondary = true); ~Browser() final; - void setup(); - const QVector<MainWindow *> windows() const { return qAsConst(m_windows); diff --git a/src/main.cpp b/src/main.cpp index f0c1591..dad1f73 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,15 +132,13 @@ int main(int argc, char **argv) return c.value<QString>("profile.default").value(); }(); - app.setup(); - QStringList urls; - for(const auto &u : args::get(cmd_args)) { urls.append(QString::fromStdString(u)); } - if(urls.isEmpty()) + if(urls.isEmpty()) { urls.append(QString()); + } // if app is primary, create new sessions from received messages if(app.isPrimary() && !cmd_noRemote) { diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 4ec79b1..64c149c 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -24,7 +24,7 @@ #include <QMessageBox> #include <QStatusBar> -MainWindow::MainWindow(const Session::MainWindow &data, QMenu *appMenu, QWidget *parent) +MainWindow::MainWindow(const Session::MainWindow &mainwindow_data, QMenu *appMenu, QWidget *parent) : QMainWindow(parent) { Configuration config; @@ -66,7 +66,7 @@ MainWindow::MainWindow(const Session::MainWindow &data, QMenu *appMenu, QWidget }); QMainWindow::addAction(searchAction); - for(const auto &s : data.subwindows) { + for(const auto &s : mainwindow_data.subwindows) { createSubWindow(s); } if(m_subwindows.isEmpty()) { @@ -115,19 +115,19 @@ void MainWindow::createTab(const QUrl &url) } } -void MainWindow::createTab(const Session::WebView &data) +void MainWindow::createTab(const Session::WebView &tab_data) { auto *w = qobject_cast<SubWindow *>(centralWidget()); if(w != nullptr) { - w->addTab(data); + w->addTab(tab_data); } } -SubWindow *MainWindow::createSubWindow(const Session::SubWindow &data) +SubWindow *MainWindow::createSubWindow(const Session::SubWindow &subwindow_data) { WebProfileManager profileManager; - auto *profile = profileManager.profile(data.profile); + auto *profile = profileManager.profile(subwindow_data.profile); if(profile == nullptr) { profile = WebProfile::defaultProfile(); } @@ -153,11 +153,11 @@ SubWindow *MainWindow::createSubWindow(const Session::SubWindow &data) } }); - if(data.tabs.count() == 0) { + if(subwindow_data.tabs.count() == 0) { w->addTab(profile->newtab()); return w; } - for(const auto &tab : data.tabs) { + for(const auto &tab : subwindow_data.tabs) { w->addTab(tab); } return w; diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 31f5658..c5d573e 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -34,7 +34,7 @@ public: ToolsMenu }; - explicit MainWindow(const Session::MainWindow &data, QMenu *appMenu, QWidget *parent = nullptr); + explicit MainWindow(const Session::MainWindow &mainwindow_data, QMenu *appMenu, QWidget *parent = nullptr); MainWindow(const MainWindow &) = delete; ~MainWindow() = default; @@ -66,8 +66,8 @@ public: public slots: void createTab(const QUrl &url); - void createTab(const Session::WebView &data); - SubWindow *createSubWindow(const Session::SubWindow &data); + void createTab(const Session::WebView &tab_data); + SubWindow *createSubWindow(const Session::SubWindow &subwindow_data); void setCurrentSubWindow(SubWindow *subwindow); private slots: diff --git a/src/mainwindow/menubar.cpp b/src/mainwindow/menubar.cpp index f8979de..5fc039a 100644 --- a/src/mainwindow/menubar.cpp +++ b/src/mainwindow/menubar.cpp @@ -87,37 +87,37 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) conf.shortcut<QAction>(*actionDownloads, "shortcuts.window.downloads.show"); window->addSeparator(); - auto *actionNewWindow = window->addAction(tr("New Window"), browser, [browser]() { - const Session::MainWindow window; - browser->open({ window }, false); - }); - conf.shortcut<QAction>(*actionNewWindow, "shortcuts.window.newwindow"); + auto *actionNewWindow = window->addAction(tr("New Window"), browser, [browser]() { + const Session::MainWindow window_data; + browser->open({ window_data }, false); + }); + conf.shortcut<QAction>(*actionNewWindow, "shortcuts.window.newwindow"); - auto *actionNewSubwindow = window->addAction(tr("New Subwindow"), parent, [parent]() { - const Session::SubWindow session; - parent->createSubWindow(session); - }); - conf.shortcut<QAction>(*actionNewSubwindow, "shortcuts.window.newgroup"); + auto *actionNewSubwindow = window->addAction(tr("New Subwindow"), parent, [parent]() { + const Session::SubWindow session; + parent->createSubWindow(session); + }); + conf.shortcut<QAction>(*actionNewSubwindow, "shortcuts.window.newgroup"); - auto *actionCloseSubwindow = window->addAction(tr("Close Subwindow"), parent, [parent]() { - parent->currentSubWindow()->close(); - }); - conf.shortcut<QAction>(*actionCloseSubwindow, "shortcuts.subwindow.close"); + auto *actionCloseSubwindow = window->addAction(tr("Close Subwindow"), parent, [parent]() { + parent->currentSubWindow()->close(); + }); + conf.shortcut<QAction>(*actionCloseSubwindow, "shortcuts.subwindow.close"); - window->addSeparator()->setText(tr("Toolbars")); + window->addSeparator()->setText(tr("Toolbars")); - bool hasMovableToolbar = false; + bool hasMovableToolbar = false; - for(auto *toolbar : parent->findChildren<QToolBar *>()) { - auto *action = window->addAction(toolbar->windowTitle()); - action->setCheckable(true); - action->setChecked(toolbar->isVisible()); - connect(toolbar, &QToolBar::visibilityChanged, action, &QAction::setChecked); - connect(action, &QAction::triggered, toolbar, &QToolBar::setVisible); - conf.shortcut<QAction>(*action, qUtf8Printable(toolbar->objectName() + ".show")); + for(auto *toolbar : parent->findChildren<QToolBar *>()) { + auto *action = window->addAction(toolbar->windowTitle()); + action->setCheckable(true); + action->setChecked(toolbar->isVisible()); + connect(toolbar, &QToolBar::visibilityChanged, action, &QAction::setChecked); + connect(action, &QAction::triggered, toolbar, &QToolBar::setVisible); + conf.shortcut<QAction>(*action, qUtf8Printable(toolbar->objectName() + ".show")); - if(toolbar->isMovable()) - hasMovableToolbar = true; + if(toolbar->isMovable()) + hasMovableToolbar = true; } auto *lockAction = window->addAction(tr("Unlock toolbars")); @@ -169,27 +169,27 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) auto *actionLockClose = subwindow->addAction(tr("Prevent tab from closing"), parent, [parent](bool checked) { run_if(parent->currentSubWindow(), [checked](SubWindow *_subwindow, int currentIdx) { - auto data = _subwindow->tabData(currentIdx); - data.closeLocked = checked; - _subwindow->setTabData(data, currentIdx); + auto tab_data = _subwindow->tabData(currentIdx); + tab_data.closeLocked = checked; + _subwindow->setTabData(tab_data, currentIdx); }); }); actionLockClose->setCheckable(true); auto *actionLockRefresh = subwindow->addAction(tr("Prevent tab from refreshing"), parent, [parent](bool checked) { run_if(parent->currentSubWindow(), [checked](SubWindow *_subwindow, int currentIdx) { - auto data = _subwindow->tabData(currentIdx); - data.refreshLocked = checked; - _subwindow->setTabData(data, currentIdx); + auto tab_data = _subwindow->tabData(currentIdx); + tab_data.refreshLocked = checked; + _subwindow->setTabData(tab_data, currentIdx); }); }); actionLockRefresh->setCheckable(true); connect(subwindow, &QMenu::aboutToShow, subwindow, [=]() { run_if(parent->currentSubWindow(), [=](SubWindow *_subwindow, int currentIdx) { - auto data = _subwindow->tabData(currentIdx); - actionLockClose->setChecked(data.closeLocked); - actionLockRefresh->setChecked(data.refreshLocked); + auto tab_data = _subwindow->tabData(currentIdx); + actionLockClose->setChecked(tab_data.closeLocked); + actionLockRefresh->setChecked(tab_data.refreshLocked); }); }); @@ -235,8 +235,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) subwindow->addAction(tr("Close tabs to the left"), parent, [parent]() { run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = currentIdx - 1; i >= 0; i--) { - const auto data = _subwindow->tabData(i); - if(!data.closeLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.closeLocked) _subwindow->closeTab(i); } }); @@ -244,8 +244,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) subwindow->addAction(tr("Close tabs to the right"), parent, [parent]() { run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = _subwindow->tabCount() - 1; i > currentIdx; i--) { - const auto data = _subwindow->tabData(i); - if(!data.closeLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.closeLocked) _subwindow->closeTab(i); } }); @@ -254,8 +254,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = _subwindow->tabCount() - 1; i >= 0; i--) { if(i != currentIdx) { - const auto data = _subwindow->tabData(i); - if(!data.closeLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.closeLocked) _subwindow->closeTab(i); } } @@ -267,8 +267,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) subwindow->addAction(tr("Refresh tabs to the left"), parent, [parent]() { run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = 0; i < currentIdx; i++) { - const auto data = _subwindow->tabData(i); - if(!data.refreshLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.refreshLocked) _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); } }); @@ -276,8 +276,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) subwindow->addAction(tr("Refresh tabs to the right"), parent, [parent]() { run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = currentIdx + 1; i < _subwindow->tabCount(); i++) { - const auto data = _subwindow->tabData(i); - if(!data.refreshLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.refreshLocked) _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); } }); @@ -286,8 +286,8 @@ MenuBar::MenuBar(QMenu *appMenu, MainWindow *parent) run_if(parent->currentSubWindow(), [](SubWindow *_subwindow, int currentIdx) { for(int i = 0; i < _subwindow->tabCount(); i++) { if(i != currentIdx) { - const auto data = _subwindow->tabData(i); - if(!data.refreshLocked) + const auto tab_data = _subwindow->tabData(i); + if(!tab_data.refreshLocked) _subwindow->view(i)->triggerPageAction(QWebEnginePage::Reload); } } diff --git a/src/mainwindow/widgets/searchform.cpp b/src/mainwindow/widgets/searchform.cpp index 1519df2..e10933b 100644 --- a/src/mainwindow/widgets/searchform.cpp +++ b/src/mainwindow/widgets/searchform.cpp @@ -22,11 +22,11 @@ SearchForm::SearchForm(QWidget *parent) ui->result_label->setVisible(false); connect(ui->lineEdit, &QLineEdit::returnPressed, this, [this]() { - if(view) { + if(m_view) { QWebEnginePage::FindFlags searchFlags; searchFlags.setFlag(QWebEnginePage::FindCaseSensitively, ui->caseSensitivity_checkBox->isChecked()); searchFlags.setFlag(QWebEnginePage::FindBackward, ui->reverseSearch_checkBox->isChecked()); - view->findText(ui->lineEdit->text(), searchFlags, [this](bool found) { + m_view->findText(ui->lineEdit->text(), searchFlags, [this](bool found) { ui->result_label->setVisible(!found); }); } @@ -40,7 +40,7 @@ SearchForm::~SearchForm() void SearchForm::setView(QWebEngineView *view) { - this->view = view; + m_view = view; } void SearchForm::showEvent(QShowEvent *event) @@ -53,8 +53,8 @@ void SearchForm::showEvent(QShowEvent *event) void SearchForm::hideEvent(QHideEvent *event) { // clear highlighted text when hiding - if(view) { - view->findText(""); + if(m_view) { + m_view->findText(""); } event->accept(); } diff --git a/src/mainwindow/widgets/searchform.h b/src/mainwindow/widgets/searchform.h index 16effe9..285ed16 100644 --- a/src/mainwindow/widgets/searchform.h +++ b/src/mainwindow/widgets/searchform.h @@ -34,7 +34,7 @@ protected: private: Ui::SearchForm *ui; - QWebEngineView *view = nullptr; + QWebEngineView *m_view = nullptr; }; #endif // SMOLBOTE_SEARCHFORM_H diff --git a/src/subwindow/subwindow.cpp b/src/subwindow/subwindow.cpp index 588a070..6e9a713 100644 --- a/src/subwindow/subwindow.cpp +++ b/src/subwindow/subwindow.cpp @@ -78,18 +78,18 @@ SubWindow::SubWindow(QWidget *parent, Qt::WindowFlags flags) }); } -SubWindow::SubWindow(const Session::SubWindow &data, QWidget *parent, Qt::WindowFlags flags) +SubWindow::SubWindow(const Session::SubWindow &tab_data, QWidget *parent, Qt::WindowFlags flags) : SubWindow(parent, flags) { WebProfileManager profileManager; - auto *profile = profileManager.profile(data.profile); + auto *profile = profileManager.profile(tab_data.profile); if(profile != nullptr) { setProfile(profile); } - for(const auto &data : data.tabs) { - addTab(data); + for(const auto &tab : tab_data.tabs) { + addTab(tab); } } @@ -117,9 +117,9 @@ void SubWindow::setProfile(WebProfile *profile) } } -void SubWindow::setTabData(TabData &data, int index) +void SubWindow::setTabData(TabData &tab_data, int index) { - tabWidget->tabBar()->setTabData(index, QVariant::fromValue<TabData>(data)); + tabWidget->tabBar()->setTabData(index, QVariant::fromValue<TabData>(tab_data)); } SubWindow::TabData SubWindow::tabData(int index) const @@ -149,9 +149,9 @@ int SubWindow::addTab(const QUrl &url, WebProfile *profile) return tabWidget->addTab(view); } -int SubWindow::addTab(const Session::WebView &data) +int SubWindow::addTab(const Session::WebView &tab_data) { - auto *view = new WebView(data, std::bind(&SubWindow::createView, this, std::placeholders::_1), this); + auto *view = new WebView(tab_data, std::bind(&SubWindow::createView, this, std::placeholders::_1), this); return tabWidget->addTab(view); } diff --git a/src/subwindow/subwindow.h b/src/subwindow/subwindow.h index 88f3985..68f7cf9 100644 --- a/src/subwindow/subwindow.h +++ b/src/subwindow/subwindow.h @@ -28,7 +28,7 @@ public: }; explicit SubWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); - explicit SubWindow(const Session::SubWindow &data, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); + explicit SubWindow(const Session::SubWindow &tab_data, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); ~SubWindow() = default; [[nodiscard]] Session::SubWindow serialize() const; @@ -58,7 +58,7 @@ public: return m_profile; } - void setTabData(TabData &data, int index); + void setTabData(TabData &tab_data, int index); [[nodiscard]] TabData tabData(int index) const; signals: @@ -71,7 +71,7 @@ public slots: WebView *createView(QWebEnginePage::WebWindowType type); int addTab(const QUrl &url = QUrl(), WebProfile *profile = nullptr); - int addTab(const Session::WebView &data); + int addTab(const Session::WebView &tab_data); void closeTab(int index) { tabWidget->removeTab(index); diff --git a/src/subwindow/tabwidget.cpp b/src/subwindow/tabwidget.cpp index efa2b6a..6f1e348 100644 --- a/src/subwindow/tabwidget.cpp +++ b/src/subwindow/tabwidget.cpp @@ -87,23 +87,21 @@ int TabWidget::addTab(WebView *view) { Q_ASSERT_X(view != nullptr, "TabWidget::addTab", "Tried to add null view"); - int idx = QTabWidget::addTab(view, view->title()); + const int idx = QTabWidget::addTab(view, view->title()); connect(view, &WebView::titleChanged, [this, view](const QString &title) { - int idx = this->indexOf(view); - Q_ASSERT(idx != -1); - - this->setTabText(idx, title); + const int current_idx = indexOf(view); + if(current_idx != -1) { + setTabText(current_idx, title); + } }); connect(view, &WebView::iconChanged, [this, view](const QIcon &icon) { - int idx = this->indexOf(view); - Q_ASSERT(idx != -1); - - this->setTabIcon(idx, icon); + const int current_idx = indexOf(view); + if(current_idx != -1) { + setTabIcon(current_idx, icon); + } }); - SubWindow::TabData data; - tabBar()->setTabData(idx, QVariant::fromValue<SubWindow::TabData>(data)); - + tabBar()->setTabData(idx, QVariant::fromValue<SubWindow::TabData>(SubWindow::TabData{})); return idx; } diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp index 8c6b8db..b2b19b5 100644 --- a/src/webengine/webpage.cpp +++ b/src/webengine/webpage.cpp @@ -13,7 +13,7 @@ #include <QWebEngineFullScreenRequest> #include <QWebEngineCertificateError> -QString tr_terminationStatus(QWebEnginePage::RenderProcessTerminationStatus status) +[[nodiscard]] inline QString tr_terminationStatus(QWebEnginePage::RenderProcessTerminationStatus status) { switch(status) { case QWebEnginePage::NormalTerminationStatus: @@ -29,7 +29,7 @@ QString tr_terminationStatus(QWebEnginePage::RenderProcessTerminationStatus stat return QObject::tr("The render process was terminated with an unknown status."); } -QString feature_toString(QWebEnginePage::Feature feature) +[[nodiscard]] inline QString feature_toString(QWebEnginePage::Feature feature) { switch(feature) { case QWebEnginePage::Notifications: diff --git a/src/webengine/webprofile.h b/src/webengine/webprofile.h index 0747638..894463f 100644 --- a/src/webengine/webprofile.h +++ b/src/webengine/webprofile.h @@ -205,7 +205,7 @@ public slots: auto *store = cookieStore(); store->deleteAllCookies(); for(const auto &data : cookies) { - for(const auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) { + for(auto &cookie : QNetworkCookie::parseCookies(data.toByteArray())) { store->setCookie(cookie); } } diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 135f25c..38e564a 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -42,21 +42,21 @@ WebView::WebView(WebProfile *profile, cb_createWindow_t cb, QWidget *parent) setPage(new WebPage(profile, this)); } -WebView::WebView(const Session::WebView &data, cb_createWindow_t cb, QWidget *parent) +WebView::WebView(const Session::WebView &webview_data, cb_createWindow_t cb, QWidget *parent) : WebView(parent) { cb_createWindow = cb; WebProfileManager profileManager; - auto *profile = profileManager.profile(data.profile); + auto *profile = profileManager.profile(webview_data.profile); if(profile != nullptr) { setProfile(profile); } - if(!data.url.isEmpty()) - load(QUrl::fromUserInput(data.url)); + if(!webview_data.url.isEmpty()) + load(QUrl::fromUserInput(webview_data.url)); else { - QByteArray copy(data.history); + QByteArray copy(webview_data.history); QDataStream historyStream(©, QIODevice::ReadOnly); historyStream >> *history(); } diff --git a/src/webengine/webview.h b/src/webengine/webview.h index a9c6866..34c77bf 100644 --- a/src/webengine/webview.h +++ b/src/webengine/webview.h @@ -28,7 +28,7 @@ public: typedef std::function<WebView *(QWebEnginePage::WebWindowType)> cb_createWindow_t; WebView(WebProfile *profile, cb_createWindow_t cb, QWidget *parent = nullptr); - WebView(const Session::WebView &data, cb_createWindow_t cb, QWidget *parent = nullptr); + WebView(const Session::WebView &webview_data, cb_createWindow_t cb, QWidget *parent = nullptr); ~WebView() = default; [[nodiscard]] WebProfile *profile() const diff --git a/src/webengine/webviewcontextmenu.cpp b/src/webengine/webviewcontextmenu.cpp index 1f6b337..ea5e8c6 100644 --- a/src/webengine/webviewcontextmenu.cpp +++ b/src/webengine/webviewcontextmenu.cpp @@ -196,7 +196,7 @@ WebViewContextMenu::WebViewContextMenu(WebView *view) auto *zoomSlider = new QSlider(Qt::Horizontal); zoomSlider->setMinimum(5); zoomSlider->setMaximum(50); - zoomSlider->setValue(view->zoomFactor() * 10); + zoomSlider->setValue(static_cast<int>(view->zoomFactor() * 10)); auto *zoomAction = this->addAction(tr("Zoom: %1x").arg(view->zoomFactor())); connect(zoomAction, &QAction::triggered, view, [zoomSlider]() { |