]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blobdiff - src/mainwindow.cpp
Add the icon.
[PrivacyBrowserPC.git] / src / mainwindow.cpp
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
new file mode 100644 (file)
index 0000000..739fca9
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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 "mainwindow.h"
+#include "privacybrowserpcview.h"
+#include "privacybrowserpcdebug.h"
+
+// KDE Frameworks headers.
+#include <KActionCollection>
+#include <KConfigDialog>
+
+
+MainWindow::MainWindow() : KXmlGuiWindow()
+{
+    m_privacybrowserpcView = new PrivacyBrowserPCView(this);
+    setCentralWidget(m_privacybrowserpcView);
+
+    KActionCollection* actionCollection = this->actionCollection();
+    m_switchAction = actionCollection->addAction(QStringLiteral("switch_action"));
+    m_switchAction->setText(i18nc("@action", "Switch Colors"));
+    m_switchAction->setIcon(QIcon::fromTheme(QStringLiteral("fill-color")));
+    connect(m_switchAction, &QAction::triggered, m_privacybrowserpcView, &PrivacyBrowserPCView::switchColors);
+
+    KStandardAction::openNew(this, SLOT(fileNew()), actionCollection);
+    KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection);
+    KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollection);
+
+    setupGUI();
+}
+
+MainWindow::~MainWindow()
+{
+}
+
+void MainWindow::fileNew()
+{
+    qCDebug(PRIVACYBROWSER) << "PrivacyBrowserPCWindow::fileNew()";
+    (new MainWindow)->show();
+}
+
+void MainWindow::settingsConfigure()
+{
+    qCDebug(PRIVACYBROWSER) << "MainWindow::settingsConfigure()";
+    // The preference dialog is derived from prefs_base.ui
+    //
+    // compare the names of the widgets in the .ui file
+    // to the names of the variables in the .kcfg file
+    //avoid to have 2 dialogs shown
+    if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
+        return;
+    }
+
+    KConfigDialog *dialog = new KConfigDialog(this, QStringLiteral("settings"), PrivacyBrowserPCSettings::self());
+    QWidget *generalSettingsPage = new QWidget;
+    m_settings.setupUi(generalSettingsPage);
+    dialog->addPage(generalSettingsPage, i18nc("@title:tab", "General"), QStringLiteral("package_setting"));
+    connect(dialog, &KConfigDialog::settingsChanged, m_privacybrowserpcView, &PrivacyBrowserPCView::handleSettingsChanged);
+    dialog->setAttribute(Qt::WA_DeleteOnClose);
+    dialog->show();
+}