2 * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
6 * Privacy Browser PC is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser PC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser PC. If not, see <http://www.gnu.org/licenses/>.
20 // Application headers.
22 #include "mainwindow.h"
23 #include "privacybrowserdebug.h"
26 // KDE Frameworks headers.
27 #include <KActionCollection>
28 #include <KConfigDialog>
30 MainWindow::MainWindow() : KXmlGuiWindow()
32 // Instantiate the main view pointer.
33 mainViewPointer = new MainView(this);
35 // Set the main view as the central widget.
36 setCentralWidget(mainViewPointer);
38 // Get a handle for the action collectoin.
39 KActionCollection *actionCollectionPointer = this->actionCollection();
41 // Create a switch colorsaction pointer.
42 QAction *switchColorsActionPointer;
44 // Populate the switch colors action pointer.
45 switchColorsActionPointer = actionCollectionPointer->addAction(QStringLiteral("switch_action"));
46 switchColorsActionPointer->setText(i18nc("@action", "Switch Colors"));
47 switchColorsActionPointer->setIcon(QIcon::fromTheme(QStringLiteral("fill-color")));
49 // Connect the signals to the slots.
50 connect(switchColorsActionPointer, &QAction::triggered, mainViewPointer, &MainView::switchColors);
52 KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
53 KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
54 KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
59 void MainWindow::fileNew()
61 qCDebug(PRIVACYBROWSER) << "MainWindow::fileNew()";
62 (new MainWindow)->show();
65 void MainWindow::settingsConfigure()
67 qCDebug(PRIVACYBROWSER) << "MainWindow::settingsConfigure()";
68 // The preference dialog is derived from prefs_base.ui
70 // compare the names of the widgets in the .ui file
71 // to the names of the variables in the .kcfg file
72 //avoid to have 2 dialogs shown
73 if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
77 KConfigDialog *dialog = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
78 QWidget *generalSettingsPage = new QWidget;
79 settingsWidget.setupUi(generalSettingsPage);
80 dialog->addPage(generalSettingsPage, i18nc("@title:tab", "General"), QStringLiteral("package_setting"));
81 connect(dialog, &KConfigDialog::settingsChanged, mainViewPointer, &MainView::handleSettingsChanged);
82 dialog->setAttribute(Qt::WA_DeleteOnClose);