]> gitweb.stoutner.com Git - PrivacyBrowserPC.git/blob - src/mainwindow.cpp
Remove .kdev4/.
[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 "mainwindow.h"
22 #include "privacybrowserpcview.h"
23 #include "privacybrowserpcdebug.h"
24
25 // KDE Frameworks headers.
26 #include <KActionCollection>
27 #include <KConfigDialog>
28
29
30 MainWindow::MainWindow() : KXmlGuiWindow()
31 {
32     m_privacybrowserpcView = new PrivacyBrowserPCView(this);
33     setCentralWidget(m_privacybrowserpcView);
34
35     KActionCollection* actionCollection = this->actionCollection();
36     m_switchAction = actionCollection->addAction(QStringLiteral("switch_action"));
37     m_switchAction->setText(i18nc("@action", "Switch Colors"));
38     m_switchAction->setIcon(QIcon::fromTheme(QStringLiteral("fill-color")));
39     connect(m_switchAction, &QAction::triggered, m_privacybrowserpcView, &PrivacyBrowserPCView::switchColors);
40
41     KStandardAction::openNew(this, SLOT(fileNew()), actionCollection);
42     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection);
43     KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollection);
44
45     setupGUI();
46 }
47
48 MainWindow::~MainWindow()
49 {
50 }
51
52 void MainWindow::fileNew()
53 {
54     qCDebug(PRIVACYBROWSER) << "PrivacyBrowserPCWindow::fileNew()";
55     (new MainWindow)->show();
56 }
57
58 void MainWindow::settingsConfigure()
59 {
60     qCDebug(PRIVACYBROWSER) << "MainWindow::settingsConfigure()";
61     // The preference dialog is derived from prefs_base.ui
62     //
63     // compare the names of the widgets in the .ui file
64     // to the names of the variables in the .kcfg file
65     //avoid to have 2 dialogs shown
66     if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
67         return;
68     }
69
70     KConfigDialog *dialog = new KConfigDialog(this, QStringLiteral("settings"), PrivacyBrowserPCSettings::self());
71     QWidget *generalSettingsPage = new QWidget;
72     m_settings.setupUi(generalSettingsPage);
73     dialog->addPage(generalSettingsPage, i18nc("@title:tab", "General"), QStringLiteral("package_setting"));
74     connect(dialog, &KConfigDialog::settingsChanged, m_privacybrowserpcView, &PrivacyBrowserPCView::handleSettingsChanged);
75     dialog->setAttribute(Qt::WA_DeleteOnClose);
76     dialog->show();
77 }