1 /*
2 SPDX-FileCopyrightText: 2001-2009 Otto Bruggeman <bruggie@gmail.com>
3 SPDX-FileCopyrightText: 2001-2003 John Firebaugh <jfirebaugh@kde.org>
4 SPDX-FileCopyrightText: 2007 Kevin Kofler <kevin.kofler@chello.at>
5
6 SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "kompareprefdlg.h"
10
11 #include <QTabWidget>
12 #include <QPushButton>
13
14 #include <KLocalizedString>
15 #include <KHelpClient>
16 #include <KStandardGuiItem>
17
18 #include "diffpage.h"
19 #include "viewpage.h"
20
21 // implementation
22
KomparePrefDlg(ViewSettings * viewSets,DiffSettings * diffSets)23 KomparePrefDlg::KomparePrefDlg(ViewSettings* viewSets, DiffSettings* diffSets) : KPageDialog(nullptr)
24 {
25 setFaceType(KPageDialog::List);
26 setWindowTitle(i18nc("@title:window", "Preferences"));
27 setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Reset | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
28 setModal(true);
29
30 KGuiItem::assign(button(QDialogButtonBox::Reset), KStandardGuiItem::defaults());
31
32 // ok i need some stuff in that pref dlg...
33 //setIconListAllVisible(true);
34
35 m_viewPage = new ViewPage();
36 KPageWidgetItem* item = addPage(m_viewPage, i18nc("@title:tab", "View"));
37 item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-theme")));
38 item->setHeader(i18nc("@title", "View Settings"));
39 m_viewPage->setSettings(viewSets);
40
41 m_diffPage = new DiffPage();
42 item = addPage(m_diffPage, i18nc("@title:tab", "Diff"));
43 item->setIcon(QIcon::fromTheme(QStringLiteral("text-x-patch")));
44 item->setHeader(i18nc("@title", "Diff Settings"));
45 m_diffPage->setSettings(diffSets);
46
47 // frame = addVBoxPage(i18n(""), i18n(""), UserIcon(""));
48
49 connect(button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &KomparePrefDlg::slotDefault);
50 connect(button(QDialogButtonBox::Help), &QPushButton::clicked, this, &KomparePrefDlg::slotHelp);
51 connect(button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KomparePrefDlg::slotApply);
52 connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &KomparePrefDlg::slotOk);
53 connect(button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &KomparePrefDlg::slotCancel);
54
55 adjustSize();
56 }
57
~KomparePrefDlg()58 KomparePrefDlg::~KomparePrefDlg()
59 {
60
61 }
62
63 /** No descriptions */
slotDefault()64 void KomparePrefDlg::slotDefault()
65 {
66 // restore all defaults in the options...
67 m_viewPage->setDefaults();
68 m_diffPage->setDefaults();
69 }
70
71 /** No descriptions */
slotHelp()72 void KomparePrefDlg::slotHelp()
73 {
74 // figure out the current active page
75 QWidget* currentpage = currentPage()->widget();
76 if (dynamic_cast<ViewPage*>(currentpage))
77 {
78 // figure out the active tab
79 int currentTab = static_cast<ViewPage*>(currentpage)->m_tabWidget->currentIndex();
80 switch (currentTab)
81 {
82 case 0:
83 KHelpClient::invokeHelp(QStringLiteral("appearance"));
84 break;
85 case 1:
86 KHelpClient::invokeHelp(QStringLiteral("fonts"));
87 break;
88 default:
89 KHelpClient::invokeHelp(QStringLiteral("view-settings"));
90 }
91 }
92 else if (dynamic_cast<DiffPage*>(currentpage))
93 {
94 // figure out the active tab
95 int currentTab = static_cast<DiffPage*>(currentpage)->m_tabWidget->currentIndex();
96 switch (currentTab)
97 {
98 case 0:
99 KHelpClient::invokeHelp(QStringLiteral("diff"));
100 break;
101 case 1:
102 KHelpClient::invokeHelp(QStringLiteral("diff-format"));
103 break;
104 case 2:
105 KHelpClient::invokeHelp(QStringLiteral("options"));
106 break;
107 case 3:
108 KHelpClient::invokeHelp(QStringLiteral("exclude"));
109 break;
110 default:
111 KHelpClient::invokeHelp(QStringLiteral("diff-settings"));
112 }
113 }
114 else // Fallback since we had not added the code for the page/tab or forgotten about it
115 KHelpClient::invokeHelp(QStringLiteral("configure-preferences"));
116 }
117
118 /** No descriptions */
slotApply()119 void KomparePrefDlg::slotApply()
120 {
121 // well apply the settings that are currently selected
122 m_viewPage->apply();
123 m_diffPage->apply();
124
125 Q_EMIT configChanged();
126 }
127
128 /** No descriptions */
slotOk()129 void KomparePrefDlg::slotOk()
130 {
131 // Apply the settings that are currently selected
132 m_viewPage->apply();
133 m_diffPage->apply();
134
135 //accept();
136 }
137
138 /** No descriptions */
slotCancel()139 void KomparePrefDlg::slotCancel()
140 {
141 // discard the current settings and use the present ones
142 m_viewPage->restore();
143 m_diffPage->restore();
144
145 //reject();
146 }
147