Initial commit.
[PrivacyBrowserPC.git] / src / privacybrowserpcwindow.cpp
1 /*
2     SPDX-FileCopyrightText: %{CURRENT_YEAR} %{AUTHOR} <%{EMAIL}>
3
4     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 */
6
7 // application headers
8 #include "privacybrowserpcwindow.h"
9
10 #include "privacybrowserpcview.h"
11 #include "privacybrowserpcdebug.h"
12
13 // KF headers
14 #include <KActionCollection>
15 #include <KConfigDialog>
16
17
18 PrivacyBrowserPCWindow::PrivacyBrowserPCWindow()
19     : KXmlGuiWindow()
20 {
21     m_privacybrowserpcView = new PrivacyBrowserPCView(this);
22     setCentralWidget(m_privacybrowserpcView);
23
24     KActionCollection* actionCollection = this->actionCollection();
25     m_switchAction = actionCollection->addAction(QStringLiteral("switch_action"));
26     m_switchAction->setText(i18nc("@action", "Switch Colors"));
27     m_switchAction->setIcon(QIcon::fromTheme(QStringLiteral("fill-color")));
28     connect(m_switchAction, &QAction::triggered, m_privacybrowserpcView, &PrivacyBrowserPCView::switchColors);
29
30     KStandardAction::openNew(this, SLOT(fileNew()), actionCollection);
31     KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection);
32     KStandardAction::preferences(this, SLOT(settingsConfigure()), actionCollection);
33
34     setupGUI();
35 }
36
37 PrivacyBrowserPCWindow::~PrivacyBrowserPCWindow()
38 {
39 }
40
41 void PrivacyBrowserPCWindow::fileNew()
42 {
43     qCDebug(PRIVACYBROWSERPC) << "PrivacyBrowserPCWindow::fileNew()";
44     (new PrivacyBrowserPCWindow)->show();
45 }
46
47 void PrivacyBrowserPCWindow::settingsConfigure()
48 {
49     qCDebug(PRIVACYBROWSERPC) << "PrivacyBrowserPCWindow::settingsConfigure()";
50     // The preference dialog is derived from prefs_base.ui
51     //
52     // compare the names of the widgets in the .ui file
53     // to the names of the variables in the .kcfg file
54     //avoid to have 2 dialogs shown
55     if (KConfigDialog::showDialog(QStringLiteral("settings"))) {
56         return;
57     }
58
59     KConfigDialog *dialog = new KConfigDialog(this, QStringLiteral("settings"), PrivacyBrowserPCSettings::self());
60     QWidget *generalSettingsPage = new QWidget;
61     m_settings.setupUi(generalSettingsPage);
62     dialog->addPage(generalSettingsPage, i18nc("@title:tab", "General"), QStringLiteral("package_setting"));
63     connect(dialog, &KConfigDialog::settingsChanged, m_privacybrowserpcView, &PrivacyBrowserPCView::handleSettingsChanged);
64     dialog->setAttribute(Qt::WA_DeleteOnClose);
65     dialog->show();
66 }