diff options
-rw-r--r-- | src/browser.cpp | 56 | ||||
-rw-r--r-- | src/browser.h | 19 | ||||
-rw-r--r-- | src/filter/blockermanager.cpp | 2 | ||||
-rw-r--r-- | src/forms/aboutdialog.cpp | 4 | ||||
-rw-r--r-- | src/forms/downloadswidget.cpp | 4 | ||||
-rw-r--r-- | src/forms/profilesdialog.cpp | 10 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/mainwindow.cpp | 61 | ||||
-rw-r--r-- | src/mainwindow.h | 5 | ||||
-rw-r--r-- | src/webengine/webengineprofile.cpp | 14 | ||||
-rw-r--r-- | src/widgets/mainwindowmenubar.cpp | 12 | ||||
-rw-r--r-- | src/widgets/webviewtabbar.cpp | 6 |
12 files changed, 89 insertions, 110 deletions
diff --git a/src/browser.cpp b/src/browser.cpp index 15a7029..c0289a6 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -43,10 +43,6 @@ Browser::~Browser() qDeleteAll(m_windows); m_windows.clear(); - if(m_networkAccessManager) { - delete m_networkAccessManager; - } - if(m_bookmarksManager) { delete m_bookmarksManager; } @@ -112,10 +108,7 @@ void Browser::loadProfiles() //qDebug("Creating new window for [%s]", qUtf8Printable(params["urls"].toString())); - MainWindow *w = addWindow(params["urls"].toStringList()); - if(params.contains("profile")) { - w->setProfile(profile(params["profile"].toString())); - } + createWindow(params); }); } @@ -126,15 +119,8 @@ Browser *Browser::instance() Settings *Browser::settings() { - return m_settings; -} - -QNetworkAccessManager *Browser::network() -{ - if(!m_networkAccessManager) { - m_networkAccessManager = new QNetworkAccessManager(); - } - return m_networkAccessManager; + Q_ASSERT(m_settings); + return m_settings.get(); } BookmarksWidget *Browser::bookmarks() @@ -194,7 +180,7 @@ void Browser::loadSettings(const QString &path) defaultsLocation = ":/poi.toml"; } - m_settings = new Settings(configLocation, defaultsLocation); + m_settings = std::unique_ptr<Settings>(new Settings(configLocation, defaultsLocation)); #ifdef QT_DEBUG if(m_settings->isEmpty()) { @@ -210,7 +196,7 @@ void Browser::loadSettings(const QString &path) MainWindow *Browser::activeWindow() { if(m_windows.empty()) { - addWindow(new MainWindow()); + return nullptr; } for(auto it = m_windows.cbegin(); it != m_windows.cend(); it++) { @@ -221,22 +207,32 @@ MainWindow *Browser::activeWindow() return m_windows.first().data(); } -void Browser::addWindow(MainWindow *window) +MainWindow *Browser::createWindow(const QHash<QString, QVariant> options) { - Q_ASSERT(window != nullptr); + Q_ASSERT(options.contains("urls")); + + MainWindow *w = new MainWindow(); - m_windows.append(QPointer<MainWindow>(window)); - connect(window, &QObject::destroyed, this, [&]() { - this->clean(); + m_windows.append(QPointer<MainWindow>(w)); + connect(w, &MainWindow::destroyed, this, [&]() { + clean(); }); - window->show(); -} + QString profileName; + if(options.contains("profile")) { + profileName = options.value("profile").toString(); + } + const QStringList urls = options.value("urls").toStringList(); + if(urls.isEmpty()) { + w->newTab(profile(profileName)->homepage()); + } else { + for(const QString url : urls) { + w->newTab(QUrl::fromUserInput(url)); + } + } + + w->show(); -MainWindow *Browser::addWindow(const QStringList params) -{ - MainWindow *w = new MainWindow(params); - addWindow(w); return w; } diff --git a/src/browser.h b/src/browser.h index 43ff1f4..9fd0bdf 100644 --- a/src/browser.h +++ b/src/browser.h @@ -25,19 +25,17 @@ #include <bookmarks/bookmarkswidget.h> #include "forms/downloadswidget.h" #include "settings.h" -#include <QNetworkAccessManager> #include "webengine/webengineprofile.h" #include "filter/blockermanager.h" #include "webengine/urlinterceptor.h" -#ifdef qApp -#undef qApp -#endif -#define qApp Browser::instance() +#include <memory> -#define sSettings Browser::instance()->settings() -#define sNetwork Browser::instance()->network() +#ifdef browser +#undef browser +#endif +#define browser Browser::instance() class MainWindow; class Browser : public SingleApplication @@ -57,7 +55,6 @@ public: static Browser *instance(); Settings *settings(); - QNetworkAccessManager *network(); BookmarksWidget *bookmarks(); DownloadsWidget *downloads(); BlockerManager *blocklists(); @@ -71,19 +68,17 @@ public: QStringList plugins(); public slots: - void addWindow(MainWindow* window); - MainWindow *addWindow(const QStringList params); + MainWindow* createWindow(const QHash<QString, QVariant> options); void clean(); private: Q_DISABLE_COPY(Browser) - Settings *m_settings = nullptr; + std::unique_ptr<Settings> m_settings; QVector<QPointer<MainWindow>> m_windows; QHash<QString, WebEngineProfile *> m_profiles; - QNetworkAccessManager *m_networkAccessManager = nullptr; UrlRequestInterceptor *m_urlRequestInterceptor = nullptr; BookmarksWidget *m_bookmarksManager = nullptr; DownloadsWidget *m_downloadManager = nullptr; diff --git a/src/filter/blockermanager.cpp b/src/filter/blockermanager.cpp index 90d99a9..cef7f36 100644 --- a/src/filter/blockermanager.cpp +++ b/src/filter/blockermanager.cpp @@ -33,7 +33,7 @@ BlockerManager::BlockerManager(QWidget *parent) : { ui->setupUi(this); - const QStringList subscriptions = sSettings->value("blocker.subscriptions").toStringList(); + const QStringList subscriptions = browser->settings()->value("blocker.subscriptions").toStringList(); QStringList::const_iterator i; for(i = subscriptions.constBegin(); i != subscriptions.constEnd(); ++i) { FilterCollection *sub = new FilterCollection(QString(*i), this); diff --git a/src/forms/aboutdialog.cpp b/src/forms/aboutdialog.cpp index 2fe312b..e9c2a93 100644 --- a/src/forms/aboutdialog.cpp +++ b/src/forms/aboutdialog.cpp @@ -54,7 +54,9 @@ AboutDialog::AboutDialog(QWidget *parent) : "Configuration lives in %2<br>" "Default configuration lives in %3" "</p>") - .arg(qApp->applicationLongVersion(), sSettings->configurationPath(), sSettings->defaultsPath())); + .arg(browser->applicationLongVersion(), + browser->settings()->configurationPath(), + browser->settings()->defaultsPath())); ui->toolBox->addItem(detailsLabel, tr("Details")); QLabel *libsLabel = new QLabel(this); diff --git a/src/forms/downloadswidget.cpp b/src/forms/downloadswidget.cpp index ab1d6c0..008e371 100644 --- a/src/forms/downloadswidget.cpp +++ b/src/forms/downloadswidget.cpp @@ -46,7 +46,9 @@ DownloadsWidget::~DownloadsWidget() void DownloadsWidget::addDownload(QWebEngineDownloadItem *item) { - QString filepath = QFileDialog::getSaveFileName(this, tr("Save"), sSettings->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); + QString filepath = QFileDialog::getSaveFileName(this, + tr("Save"), + browser->settings()->value("downloads.path").toString() + "/" + QFileInfo(item->path()).fileName()); if(filepath.isEmpty()) { // user cancelled the save dialog diff --git a/src/forms/profilesdialog.cpp b/src/forms/profilesdialog.cpp index 00e4920..7723683 100644 --- a/src/forms/profilesdialog.cpp +++ b/src/forms/profilesdialog.cpp @@ -69,8 +69,8 @@ void ProfilesDialog::loadProfiles() { ui->listWidget->clear(); - for(QString name : qApp->profiles()) { - QListWidgetItem *item = new QListWidgetItem(qApp->profile(name)->name(), ui->listWidget); + for(QString name : browser->profiles()) { + QListWidgetItem *item = new QListWidgetItem(browser->profile(name)->name(), ui->listWidget); item->setData(Qt::UserRole, name); } } @@ -81,18 +81,18 @@ void ProfilesDialog::newProfile() QString name = QInputDialog::getText(this, tr("Profile Name"), tr("Profile Name:"), QLineEdit::Normal, tr("Default"), &ok); if(ok) { - qApp->profile(name); + browser->profile(name); loadProfiles(); } } void ProfilesDialog::loadSelectedProfile() { - m_window->setProfile(qApp->profile(ui->listWidget->currentItem()->data(Qt::UserRole).toString())); + m_window->setProfile(browser->profile(ui->listWidget->currentItem()->data(Qt::UserRole).toString())); } void ProfilesDialog::viewProfile(int index) { - m_view->setProfile(qApp->profile(ui->listWidget->item(index)->data(Qt::UserRole).toString())); + m_view->setProfile(browser->profile(ui->listWidget->item(index)->data(Qt::UserRole).toString())); m_view->show(); } diff --git a/src/main.cpp b/src/main.cpp index 87def7a..9df24b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -133,11 +133,7 @@ int main(int argc, char *argv[]) // app.loadPlugins(); // } - MainWindow *w = new MainWindow(options.value("urls").toStringList()); - if(options.contains("profile")) { - w->setProfile(app.profile(options.value("profile").toString())); - } - app.addWindow(w); + app.createWindow(options); } return app.exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 29a5c8f..4146e8a 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -34,7 +34,7 @@ #include <QWebEngineHistory> -MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : +MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), navigationToolBar(new QToolBar(tr("Navigation"), this)), @@ -49,7 +49,7 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : // set up UI ui->setupUi(this); QAction *fullscreenAction = new QAction(this); - fullscreenAction->setShortcut(QKeySequence::fromString(sSettings->value("window.shortcuts.fullscreen").toString())); + fullscreenAction->setShortcut(QKeySequence::fromString(browser->settings()->value("window.shortcuts.fullscreen").toString())); connect(fullscreenAction, SIGNAL(triggered(bool)), this, SLOT(toggleFullscreen())); addAction(fullscreenAction); @@ -69,29 +69,30 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : // Add the toolbars // tabToolBar: main menu and tab list - tabToolBar->setMovable(sSettings->value("window.ui.tabtoolbarMovable").toBool()); + tabToolBar->setMovable(browser->settings()->value("window.ui.tabtoolbarMovable").toBool()); tabToolBar->addWidget(menuBar); tabToolBar->addWidget(tabBar); this->addToolBar(Qt::TopToolBarArea, tabToolBar); this->addToolBarBreak(Qt::TopToolBarArea); // navigationToolBar: address bar - navigationToolBar->setMovable(sSettings->value("window.ui.navtoolbarMovable").toBool()); + navigationToolBar->setMovable(browser->settings()->value("window.ui.navtoolbarMovable").toBool()); // page actions - backButton = new NavigationButton(NavigationButton::BackButton, this); +m: + m_backButton = new NavigationButton(NavigationButton::BackButton, this); - forwardButton = new NavigationButton(NavigationButton::ForwardButton, this); + m_forwardButton = new NavigationButton(NavigationButton::ForwardButton, this); - reloadButton = new NavigationButton(NavigationButton::ReloadButton, this); + m_reloadButton = new NavigationButton(NavigationButton::ReloadButton, this); QToolButton *homepageButton = new QToolButton(this); homepageButton->setIcon(style()->standardIcon(QStyle::SP_DirHomeIcon)); connect(homepageButton, SIGNAL(clicked()), tabBar->signalMapper(), SLOT(map())); tabBar->signalMapper()->setMapping(homepageButton, WebViewTabBar::Homepage); - navigationToolBar->addWidget(backButton); - navigationToolBar->addWidget(forwardButton); - navigationToolBar->addWidget(reloadButton); + navigationToolBar->addWidget(m_backButton); + navigationToolBar->addWidget(m_forwardButton); + navigationToolBar->addWidget(m_reloadButton); navigationToolBar->addWidget(homepageButton); navigationToolBar->addWidget(m_addressBar); this->addToolBar(Qt::TopToolBarArea, navigationToolBar); @@ -103,49 +104,34 @@ MainWindow::MainWindow(QUrl defaultUrl, QWidget *parent) : connect(m_addressBar, &AddressBar::searchTermEntered, this, [&](const QString &string) { QString term = string.mid(1); term.replace(' ', '+'); - tabBar->currentView()->load(QUrl::fromUserInput(qApp->settings()->value("general.search").toString().replace("$term", term))); + tabBar->currentView()->load(QUrl::fromUserInput(browser->settings()->value("general.search").toString().replace("$term", term))); }); connect(tabBar, SIGNAL(currentTabChanged(WebView*)), this, SLOT(handleTabChanged(WebView*))); - connect(qApp->bookmarks(), &BookmarksWidget::openUrl, this, [&](const QUrl &url) { + connect(browser->bookmarks(), &BookmarksWidget::openUrl, this, [&](const QUrl &url) { if(this->isActiveWindow()) { this->newTab(url); } }); // Load profile - tabBar->setProfile(qApp->profile(sSettings->value("browser.profile.default").toString())); + tabBar->setProfile(browser->profile(browser->settings()->value("browser.profile.default").toString())); // loading bar ui->statusBar->addPermanentWidget(m_progressBar); // shortcuts QAction *focusAddressAction = new QAction(this); - focusAddressAction->setShortcut(QKeySequence::fromString(sSettings->value("window.shortcuts.focusAddress").toString())); + focusAddressAction->setShortcut(QKeySequence::fromString(browser->settings()->value("window.shortcuts.focusAddress").toString())); connect(focusAddressAction, SIGNAL(triggered(bool)), this, SLOT(focusAddress())); addAction(focusAddressAction); - if(!defaultUrl.isEmpty()) { - newTab(defaultUrl); - } else { - newTab(tabBar->profile()->homepage()); - } - - resize(sSettings->value("window.width").toInt(), sSettings->value("window.height").toInt()); - if(sSettings->value("window.maximized").toBool()) { + resize(browser->settings()->value("window.width").toInt(), browser->settings()->value("window.height").toInt()); + if(browser->settings()->value("window.maximized").toBool()) { showMaximized(); } } -MainWindow::MainWindow(const QStringList urlList, QWidget *parent) : - MainWindow(QUrl(""), parent) -{ - QStringList::const_iterator i; - for(i = urlList.constBegin(); i != urlList.constEnd(); ++i) { - newTab(QUrl::fromUserInput(*i)); - } -} - MainWindow::~MainWindow() { delete ui; @@ -218,7 +204,9 @@ void MainWindow::toggleFullscreen() void MainWindow::newWindow(const QUrl &url) { - Browser::instance()->addWindow(new MainWindow(url)); + QHash<QString, QVariant> options; + options.insert("urls", url); + browser->createWindow(options); } void MainWindow::handleTabChanged(WebView *view) @@ -240,9 +228,10 @@ void MainWindow::handleTabChanged(WebView *view) setCentralWidget(view); // connect signals - backButton->setView(view); - forwardButton->setView(view); - reloadButton->setView(view); +m: + m_backButton->setView(view); + m_forwardButton->setView(view); + m_reloadButton->setView(view); m_addressBar->setWebView(view); connect(view, SIGNAL(titleChanged(QString)), this, SLOT(handleTitleUpdated(QString))); connect(view, SIGNAL(linkHovered(QString)), ui->statusBar, SLOT(showMessage(QString))); @@ -256,5 +245,5 @@ void MainWindow::handleTabChanged(WebView *view) void MainWindow::handleTitleUpdated(const QString &title) { - setWindowTitle(sSettings->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name())); + setWindowTitle(browser->settings()->value("window.title").toString().replace("title", title).replace("profile", tabBar->profile()->name())); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 398e460..5d330d5 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -43,8 +43,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - MainWindow(QUrl defaultUrl = QUrl(""), QWidget *parent = 0); - MainWindow(const QStringList urlList, QWidget *parent = 0); + MainWindow(QWidget *parent = nullptr); ~MainWindow(); void addTabbedDock(Qt::DockWidgetArea area, QDockWidget *widget); @@ -76,7 +75,7 @@ private: WebView *m_currentView; // navigation - NavigationButton *backButton, *forwardButton, *reloadButton; + NavigationButton *m_backButton, *m_forwardButton, *m_reloadButton; AddressBar *m_addressBar; LoadingBar *m_progressBar; }; diff --git a/src/webengine/webengineprofile.cpp b/src/webengine/webengineprofile.cpp index 9745949..62f744e 100644 --- a/src/webengine/webengineprofile.cpp +++ b/src/webengine/webengineprofile.cpp @@ -31,25 +31,25 @@ WebEngineProfile::WebEngineProfile(QObject *parent) : // Off-the-record profiles have no persistent path - m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); - m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); + m_homepage = browser->settings()->value("browser.profile.new.homepage").toUrl(); + m_newtab = browser->settings()->value("browser.profile.new.newtab").toUrl(); } WebEngineProfile::WebEngineProfile(const QString &name, QObject *parent) : QWebEngineProfile(name, parent) { m_name = name; - setPersistentStoragePath(sSettings->value("browser.profile.storagePath").toString() + name); - setCachePath(sSettings->value("browser.profile.cachePath").toString() + name); + setPersistentStoragePath(browser->settings()->value("browser.profile.storagePath").toString() + name); + setCachePath(browser->settings()->value("browser.profile.cachePath").toString() + name); // Read profile settings - QString profileIniPath = sSettings->value("browser.profile.path").toString() + name + "/profile.ini"; + QString profileIniPath = browser->settings()->value("browser.profile.path").toString() + name + "/profile.ini"; // If none exist, use the defaults if(!QFile::exists(profileIniPath)) { qDebug("Creating new profile..."); - m_homepage = sSettings->value("browser.profile.new.homepage").toUrl(); - m_newtab = sSettings->value("browser.profile.new.newtab").toUrl(); + m_homepage = browser->settings()->value("browser.profile.new.homepage").toUrl(); + m_newtab = browser->settings()->value("browser.profile.new.newtab").toUrl(); // Else read them } else { diff --git a/src/widgets/mainwindowmenubar.cpp b/src/widgets/mainwindowmenubar.cpp index e69a207..95cb280 100644 --- a/src/widgets/mainwindowmenubar.cpp +++ b/src/widgets/mainwindowmenubar.cpp @@ -36,25 +36,25 @@ MainWindowMenuBar::MainWindowMenuBar(MainWindow *parent) : // Browser menu QMenu *browserMenu = new QMenu(qApp->applicationName(), this); addMenu(browserMenu); - browserMenu->addAction(tr("New Window"), parent, SLOT(newWindow()), QKeySequence::fromString(sSettings->value("window.shortcuts.windowNew").toString())); - browserMenu->addAction(tr("New Tab"), parent, SLOT(newTab()), QKeySequence::fromString(sSettings->value("window.shortcuts.tabNew").toString())); + browserMenu->addAction(tr("New Window"), parent, SLOT(newWindow()), QKeySequence::fromString(browser->settings()->value("window.shortcuts.windowNew").toString())); + browserMenu->addAction(tr("New Tab"), parent, SLOT(newTab()), QKeySequence::fromString(browser->settings()->value("window.shortcuts.tabNew").toString())); browserMenu->addSeparator(); browserMenu->addAction(tr("About"), parent, SLOT(about()), QKeySequence(tr("F1"))); browserMenu->addAction(tr("About Qt"), qApp, SLOT(aboutQt())); browserMenu->addSeparator(); - browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence::fromString(sSettings->value("window.shortcuts.windowClose").toString())); + browserMenu->addAction(tr("Quit"), qApp, SLOT(quit()), QKeySequence::fromString(browser->settings()->value("window.shortcuts.windowClose").toString())); // Tools menu QMenu *toolsMenu = new QMenu(tr("Tools"), this); addMenu(toolsMenu); QAction *downloadsAction = toolsMenu->addAction(tr("Downloads"), Browser::instance()->downloads(), SLOT(show())); downloadsAction->setParent(parent); - downloadsAction->setShortcut(QKeySequence::fromString(sSettings->value("downloads.dialogShortcut").toString())); + downloadsAction->setShortcut(QKeySequence::fromString(browser->settings()->value("downloads.dialogShortcut").toString())); QAction *bookmarksAction = toolsMenu->addAction(tr("Bookmarks"), Browser::instance()->bookmarks(), SLOT(show())); bookmarksAction->setParent(parent); - bookmarksAction->setShortcut(QKeySequence(sSettings->value("bookmarks.dialogShortcut").toString())); + bookmarksAction->setShortcut(QKeySequence(browser->settings()->value("bookmarks.dialogShortcut").toString())); toolsMenu->addSeparator(); - toolsMenu->addAction(tr("Filter"), qApp->blocklists(), SLOT(show()), QKeySequence::fromString(sSettings->value("blocker.shortcut").toString())); + toolsMenu->addAction(tr("Filter"), browser->blocklists(), SLOT(show()), QKeySequence::fromString(browser->settings()->value("blocker.shortcut").toString())); // Plugins // if(qApp->plugin("")) { diff --git a/src/widgets/webviewtabbar.cpp b/src/widgets/webviewtabbar.cpp index 9264a2a..c52e323 100644 --- a/src/widgets/webviewtabbar.cpp +++ b/src/widgets/webviewtabbar.cpp @@ -40,19 +40,19 @@ WebViewTabBar::WebViewTabBar(WebEngineProfile *profile, QWidget *parent) : connect(this, SIGNAL(tabMoved(int,int)), this, SLOT(updateVectorArrangement(int,int))); QShortcut *tabCloseShortcut = new QShortcut(this); - tabCloseShortcut->setKey(QKeySequence::fromString(qApp->settings()->value("window.shortcuts.tabClose").toString())); + tabCloseShortcut->setKey(QKeySequence::fromString(browser->settings()->value("window.shortcuts.tabClose").toString())); connect(tabCloseShortcut, &QShortcut::activated, [this]() { this->removeTab(currentIndex()); }); QShortcut *tabLeftShortcut = new QShortcut(this); - tabLeftShortcut->setKey(QKeySequence::fromString(qApp->settings()->value("window.shortcuts.tabLeft").toString())); + tabLeftShortcut->setKey(QKeySequence::fromString(browser->settings()->value("window.shortcuts.tabLeft").toString())); connect(tabLeftShortcut, &QShortcut::activated, [this]() { this->setCurrentIndex(currentIndex()-1); }); QShortcut *tabRightShortcut = new QShortcut(this); - tabRightShortcut->setKey(QKeySequence::fromString(qApp->settings()->value("window.shortcuts.tabRight").toString())); + tabRightShortcut->setKey(QKeySequence::fromString(browser->settings()->value("window.shortcuts.tabRight").toString())); connect(tabRightShortcut, &QShortcut::activated, [this]() { this->setCurrentIndex(currentIndex()+1); }); |