]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/mainwindow.cpp
c48e4955853c03f469af71149129dfa565127d36
[PrivacyBrowserPC.git] / src / mainwindow.cpp
1 /*
2  * Copyright © 2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser PC <https://www.stoutner.com/privacy-browser-pc>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 // Application headers.
21 #include "mainview.h"
22 #include "mainwindow.h"
23 #include "settings.h"
24 #include "ui_settings.h"
25
26 // KDE Frameworks headers.
27 #include <KActionCollection>
28 #include <KConfigDialog>
29
30 MainWindow::MainWindow() : KXmlGuiWindow()
31 {
32     // Instantiate the main view pointer.
33     MainView *mainViewPointer = new MainView(this);
34
35     // Set the main view as the central widget.
36     setCentralWidget(mainViewPointer);
37
38     // Get a handle for the action collectoin.
39     KActionCollection *actionCollectionPointer = this->actionCollection();
40
41     // Add the standard actions.
42     KStandardAction::openNew(this, SLOT(fileNew()), actionCollectionPointer);
43     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollectionPointer);
44     KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollectionPointer);
45
46     // Setup the GUI based on the privacybrowserui.rc file.
47     setupGUI();
48 }
49
50 void MainWindow::fileNew()
51 {
52     // Display a new instance of Privacy Browser.
53     (new MainWindow)->show();
54 }
55
56 void MainWindow::settingsConfigure()
57 {
58     // Check to make sure the dialog box isn't already displayed.
59     if (!KConfigDialog::exists(QStringLiteral("settings")))
60     {
61         // Create a general settings page.
62         QWidget *generalSettingsWidgetPointer = new QWidget;
63
64         // Instantiate the settings UI.
65         Ui::Settings settingsUi;
66
67         // Setup the UI to display the general settings widget.
68         settingsUi.setupUi(generalSettingsWidgetPointer);
69
70         // Instantiate a settings config dialog from the settings.kcfg file.
71         KConfigDialog *configDialogPointer = new KConfigDialog(this, QStringLiteral("settings"), Settings::self());
72
73         // Add the general settings widget page.
74         configDialogPointer->addPage(generalSettingsWidgetPointer, i18nc("@title:tab", "General"), QStringLiteral("breeze-settings"));
75
76         // Delete the config dialog when it is closed.
77         configDialogPointer->setAttribute(Qt::WA_DeleteOnClose);
78
79         // Make it so.
80         configDialogPointer->show();
81     }
82 }