--- /dev/null
+/*
+ * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
+ *
+ * Privacy Browser PC is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser PC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Application headers.
+#include "BrowserWindow.h"
+#include "Settings.h"
+#include "ui_SettingsPrivacy.h"
+#include "ui_SettingsGeneral.h"
+
+// KDE Frameworks headers.
+#include <KActionCollection>
+#include <KConfigDialog>
+
+// Qt framework headers.
+#include <QStatusBar>
+
+BrowserWindow::BrowserWindow() : KXmlGuiWindow()
+{
+ // Instantiate the main view pointer.
+ mainViewPointer = new MainView(this);
+
+ // Set the main view as the central widget.
+ setCentralWidget(mainViewPointer);
+
+ // Get a handle for the action collectoin.
+ KActionCollection *actionCollectionPointer = this->actionCollection();
+
+ // Add the standard actions.
+ KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
+ KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
+ KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
+
+ // 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();
+}
+
+void BrowserWindow::fileNew()
+{
+ // Display a new instance of Privacy Browser.
+ (new BrowserWindow)->show();
+}
+
+void BrowserWindow::settingsConfigure()
+{
+ // Check to make sure the dialog box isn't already displayed.
+ if (!KConfigDialog::exists(QStringLiteral("settings")))
+ {
+ // Create the settings widgets.
+ QWidget *privacySettingsWidgetPointer = new QWidget;
+ QWidget *generalSettingsWidgetPointer = new QWidget;
+
+ // Instantiate the settings UI.
+ Ui::PrivacySettings privacySettingsUi;
+ Ui::GeneralSettings generalSettingsUi;
+
+ // Setup the UI to display the settings widgets.
+ privacySettingsUi.setupUi(privacySettingsWidgetPointer);
+ generalSettingsUi.setupUi(generalSettingsWidgetPointer);
+
+ // Get handles for the user agent widgets.
+ QComboBox *userAgentComboBoxPointer = privacySettingsUi.kcfg_userAgent;
+ userAgentLabelPointer = privacySettingsUi.userAgentLabel;
+
+ // Instantiate the user agent helper.
+ userAgentHelperPointer = new UserAgentHelper();
+
+ // Display the initial user agent.
+ updateUserAgentLabel(userAgentComboBoxPointer->currentText());
+
+ // Update the user agent when the combo box changes.
+ connect(userAgentComboBoxPointer, SIGNAL(currentTextChanged(QString)), this, SLOT(updateUserAgentLabel(QString)));
+
+ // Instantiate a settings config dialog from the settings.kcfg file.
+ KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
+
+ // Add the settings widgets as config dialog pages.
+ configDialogPointer->addPage(privacySettingsWidgetPointer, i18nc("@title:tab", "Privacy"), QStringLiteral("privacy-browser"));
+ configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
+
+ // Delete the config dialog when it is closed.
+ configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
+
+ // Make it so.
+ configDialogPointer->show();
+
+ // Expand the config dialog.
+ configDialogPointer->resize(1000, 500);
+
+ // Apply the settings when they are updated.
+ connect(configDialogPointer, SIGNAL(settingsChanged(QString)), mainViewPointer, SLOT(applyApplicationSettings()));
+ connect(configDialogPointer, SIGNAL(settingsChanged(QString)), mainViewPointer, SLOT(applyDomainSettingsAndReload()));
+ }
+}
+
+void BrowserWindow::updateStatusBar(const QString &statusBarMessage)
+{
+ // Display the status bar message.
+ statusBar()->showMessage(statusBarMessage);
+}
+
+void BrowserWindow::updateUserAgentLabel(const QString &userAgentName)
+{
+ // Update the user agent label.
+ userAgentLabelPointer->setText(userAgentHelperPointer->getUserAgent(userAgentName));
+}