From 9c4dd932c6d692178bb8d5265c634126cb415767 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 26 May 2020 22:23:25 +0300 Subject: Turn on more warnings by default - fix clazy warnings - fix various other compiler warnings - bugfix: connect profiles' downloadRequested signal --- src/browser.cpp | 96 +++++++++++++++++++++++++++------------------------------ 1 file changed, 46 insertions(+), 50 deletions(-) (limited to 'src/browser.cpp') 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("browser.iconTheme")) { QIcon::setThemeName(iconTheme.value()); } + + if(auto stylesheet = conf.value("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("profile.path").value(), { "*.profile" }); + const auto search = conf.value("profile.search").value(); + const auto homepage = QUrl::fromUserInput(conf.value("profile.homepage").value()); + const auto newtab = QUrl::fromUserInput(conf.value("profile.newtab").value()); + const auto default_id = conf.value("profile.default").value(); + m_profileManager = std::make_unique>(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(conf.value("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(QString::fromStdString(conf.value("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("browser.stylesheet")) { - QFile f(stylesheet.value()); - if(f.open(QIODevice::ReadOnly)) { - setStyleSheet(f.readAll()); - f.close(); - } - } - - // downloads - m_downloads = std::make_unique(conf.value("downloads.path").value()); - - // load profiles - { - const auto profiles = Util::files(conf.value("profile.path").value(), { "*.profile" }); - const auto search = conf.value("profile.search").value(); - const auto homepage = QUrl::fromUserInput(conf.value("profile.homepage").value()); - const auto newtab = QUrl::fromUserInput(conf.value("profile.newtab").value()); - const auto default_id = conf.value("profile.default").value(); - m_profileManager = std::make_unique>(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(QString::fromStdString(conf.value("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 &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); } } -- cgit v1.2.1