From 12fd6b5fe4593faaec5da7ec77438c81b2d5fb5d Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Mon, 21 Feb 2022 15:33:37 -0700 Subject: [PATCH] Improve initialization order. --- src/BrowserWindow.cpp | 15 +++++++-------- src/BrowserWindow.h | 2 +- src/MainView.cpp | 39 +++++++++++++++++++++------------------ src/MainView.h | 1 + 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/BrowserWindow.cpp b/src/BrowserWindow.cpp index a2eda98..7e908a3 100644 --- a/src/BrowserWindow.cpp +++ b/src/BrowserWindow.cpp @@ -132,18 +132,14 @@ BrowserWindow::BrowserWindow() : KXmlGuiWindow() // Display dialogs. connect(zoomFactorActionPointer, SIGNAL(triggered()), this, SLOT(getZoomFactorFromUser())); - // Set the current zoom factor. - currentZoomFactor = Settings::zoomFactor(); - - // Initialize the on-the-fly menus, as the slot connections had not been created when MainView was constructed. - updateOnTheFlyZoomFactor(currentZoomFactor); - updateOnTheFlySearchEngine(Settings::searchEngine()); - // Update the status bar with the URL when a link is hovered. connect(mainViewPointer, SIGNAL(linkHovered(QString)), this, SLOT(updateStatusBar(QString))); // Setup the GUI based on the privacybrowserui.rc file. setupGUI(); + + // Load the initial webstie. + mainViewPointer->loadInitialWebsite(); } void BrowserWindow::fileNew() const @@ -349,8 +345,11 @@ void BrowserWindow::updateOnTheFlyUserAgent(const QString &userAgent) const } } -void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor) const +void BrowserWindow::updateOnTheFlyZoomFactor(const double &zoomFactor) { + // Set the current zoom factor. + currentZoomFactor = Settings::zoomFactor(); + // Update the zoom factor action text, formatting the double with 2 decimal places. zoomFactorActionPointer->setText(ki18nc("@action", "Zoom Factor - %1").subs(zoomFactor, 0, '0', 2).toString()); } diff --git a/src/BrowserWindow.h b/src/BrowserWindow.h index 357909e..14ef8cc 100644 --- a/src/BrowserWindow.h +++ b/src/BrowserWindow.h @@ -45,7 +45,7 @@ private Q_SLOTS: void settingsConfigure(); void updateOnTheFlySearchEngine(const QString &searchEngine) const; void updateOnTheFlyUserAgent(const QString &userAgent) const; - void updateOnTheFlyZoomFactor(const double &zoomFactor) const; + void updateOnTheFlyZoomFactor(const double &zoomFactor); void updateSearchEngineLabel(const QString &searchEngineString) const; void updateStatusBar(const QString &statusBarMessage) const; void updateUserAgentLabel(const QString &userAgentName) const; diff --git a/src/MainView.cpp b/src/MainView.cpp index 04cc1ee..3893f2b 100644 --- a/src/MainView.cpp +++ b/src/MainView.cpp @@ -93,26 +93,8 @@ MainView::MainView(QWidget *parent) : QWidget(parent) // Don't allow JavaScript to open windows. webEngineSettingsPointer->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, false); - // Apply the application settings. - applyApplicationSettings(); - // Set the focus on the WebEngine view. webEngineViewPointer->setFocus(); - - // Get the arguments. - QStringList argumentsStringList = qApp->arguments(); - - // Check to see if the arguments lists contains a URL. - if (argumentsStringList.size() > 1) - { - // Load the URL from the arguments list. - webEngineViewPointer->setUrl(QUrl::fromUserInput(argumentsStringList.at(1))); - } - else - { - // Load the homepage. - goHome(); - } } void MainView::applyApplicationSettings() @@ -209,6 +191,27 @@ void MainView::goHome() const webEngineViewPointer->setUrl(QUrl::fromUserInput(Settings::homepage())); } +void MainView::loadInitialWebsite() +{ + // Apply the application settings. + applyApplicationSettings(); + + // Get the arguments. + QStringList argumentsStringList = qApp->arguments(); + + // Check to see if the arguments lists contains a URL. + if (argumentsStringList.size() > 1) + { + // Load the URL from the arguments list. + webEngineViewPointer->setUrl(QUrl::fromUserInput(argumentsStringList.at(1))); + } + else + { + // Load the homepage. + goHome(); + } +} + void MainView::loadUrlFromTextBox(QString urlFromUser) const { // Remove the focus from the URL line edit. diff --git a/src/MainView.h b/src/MainView.h index 38b5928..dba6914 100644 --- a/src/MainView.h +++ b/src/MainView.h @@ -40,6 +40,7 @@ public: // The public functions. void applyOnTheFlyZoomFactor(const double &zoomFactor) const; + void loadInitialWebsite(); signals: // The signals. -- 2.43.0