Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/plugins/views/reports/kcm_reportsview.cpp
- This file was moved from kmymoney/dialogs/settings/ksettingsreports.cpp.
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | ksettingsreports.cpp | 2 | * Copyright 2018 Łukasz Wojniłowicz lukasz.wojnilowicz@gmail.com * | ||
3 | -------------------- | 3 | * * | ||
4 | copyright : (C) 2010 by Bernd Gonsior | 4 | * This program is free software; you can redistribute it and/or * | ||
5 | email : bernd.gonsior@googlemail.com | 5 | * modify it under the terms of the GNU General Public License as * | ||
6 | (C) 2017 by Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> | 6 | * published by the Free Software Foundation; either version 2 of * | ||
7 | ***************************************************************************/ | 7 | * the License or (at your option) version 3 or any later version * | ||
8 | 8 | * accepted by the membership of KDE e.V. (or its successor approved * | |||
9 | /*************************************************************************** | 9 | * by the membership of KDE e.V.), which shall act as a proxy * | ||
10 | * defined in Section 14 of version 3 of the license. * | ||||
10 | * * | 11 | * * | ||
11 | * This program is free software; you can redistribute it and/or modify * | 12 | * This program is distributed in the hope that it will be useful, * | ||
12 | * it under the terms of the GNU General Public License as published by * | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
13 | * the Free Software Foundation; either version 2 of the License, or * | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
14 | * (at your option) any later version. * | 15 | * GNU General Public License for more details. * | ||
15 | * * | 16 | * * | ||
17 | * You should have received a copy of the GNU General Public License * | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/> * | ||||
16 | ***************************************************************************/ | 19 | ***************************************************************************/ | ||
17 | 20 | | |||
18 | #include "ksettingsreports.h" | 21 | #include "kcm_reportsview.h" | ||
22 | #include <config-kmymoney-version.h> | ||||
19 | 23 | | |||
20 | // ---------------------------------------------------------------------------- | 24 | // ---------------------------------------------------------------------------- | ||
21 | // QT Includes | 25 | // QT Includes | ||
22 | 26 | | |||
23 | #include <QUrl> | 27 | #include <QUrl> | ||
24 | #include <QFileInfo> | 28 | #include <QFileInfo> | ||
25 | 29 | | |||
26 | // ---------------------------------------------------------------------------- | 30 | // ---------------------------------------------------------------------------- | ||
27 | // KDE Includes | 31 | // KDE Includes | ||
28 | 32 | | |||
33 | #include <KPluginFactory> | ||||
34 | #include <KAboutData> | ||||
29 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
30 | #include <KMessageBox> | 36 | #include <KMessageBox> | ||
31 | #include <KLineEdit> | 37 | #include <KLineEdit> | ||
32 | 38 | | |||
33 | // ---------------------------------------------------------------------------- | 39 | // ---------------------------------------------------------------------------- | ||
34 | // Project Includes | 40 | // Project Includes | ||
35 | 41 | | |||
36 | #include "ui_ksettingsreports.h" | 42 | #include "ui_reportsviewsettings.h" | ||
37 | | ||||
38 | #include "kmymoneysettings.h" | 43 | #include "kmymoneysettings.h" | ||
39 | 44 | | |||
40 | class KSettingsReportsPrivate | 45 | class ReportsViewSettingsWidgetPrivate | ||
41 | { | 46 | { | ||
42 | Q_DISABLE_COPY(KSettingsReportsPrivate) | 47 | Q_DISABLE_COPY(ReportsViewSettingsWidgetPrivate) | ||
43 | 48 | | |||
44 | public: | 49 | public: | ||
45 | KSettingsReportsPrivate() : | 50 | ReportsViewSettingsWidgetPrivate() : | ||
46 | ui(new Ui::KSettingsReports), | 51 | ui(new Ui::ReportsViewSettings), | ||
47 | m_fileKLineEdit(nullptr) | 52 | m_fileKLineEdit(nullptr) | ||
48 | { | 53 | { | ||
49 | } | 54 | } | ||
50 | 55 | | |||
51 | ~KSettingsReportsPrivate() | 56 | ~ReportsViewSettingsWidgetPrivate() | ||
52 | { | 57 | { | ||
53 | delete ui; | 58 | delete ui; | ||
54 | } | 59 | } | ||
55 | 60 | | |||
56 | 61 | | |||
57 | /** | 62 | /** | ||
58 | * Collector for both signals | 63 | * Collector for both signals | ||
59 | * urlSelected and editingFinished. | 64 | * urlSelected and editingFinished. | ||
60 | * | 65 | * | ||
61 | * Only shows a warning | 66 | * Only shows a warning | ||
62 | * if the selected file | 67 | * if the selected file | ||
63 | * is not a readable plain file - | 68 | * is not a readable plain file - | ||
64 | * and only one time. | 69 | * and only one time. | ||
65 | * | 70 | * | ||
66 | * @param[in] css css file name | 71 | * @param[in] css css file name | ||
67 | * | 72 | * | ||
68 | * @see KSettingsReports#slotCssUrlSelected | 73 | * @see ReportsViewSettingsWidget#slotCssUrlSelected | ||
69 | * @see KSettingsReports#slotEditingFinished | 74 | * @see ReportsViewSettingsWidget#slotEditingFinished | ||
70 | */ | 75 | */ | ||
71 | void checkCssFile(QString& css) { | 76 | void checkCssFile(QString& css) { | ||
72 | 77 | | |||
73 | if (css == m_cssFileOld) { | 78 | if (css == m_cssFileOld) { | ||
74 | // do not check again to avoid emitting a warning more than 1 time | 79 | // do not check again to avoid emitting a warning more than 1 time | ||
75 | return; | 80 | return; | ||
76 | } | 81 | } | ||
77 | 82 | | |||
Show All 30 Lines | |||||
108 | QList<QString>::const_iterator i; | 113 | QList<QString>::const_iterator i; | ||
109 | for (i = warnings.constBegin(); i != warnings.constEnd(); ++i) { | 114 | for (i = warnings.constBegin(); i != warnings.constEnd(); ++i) { | ||
110 | out += '\n' + *i; | 115 | out += '\n' + *i; | ||
111 | } | 116 | } | ||
112 | 117 | | |||
113 | KMessageBox::sorry(0, out); | 118 | KMessageBox::sorry(0, out); | ||
114 | } | 119 | } | ||
115 | 120 | | |||
116 | Ui::KSettingsReports *ui; | 121 | Ui::ReportsViewSettings *ui; | ||
117 | /** | 122 | /** | ||
118 | * Old value of css file to avoid warnings | 123 | * Old value of css file to avoid warnings | ||
119 | * when a signal is emitted | 124 | * when a signal is emitted | ||
120 | * but the value itself did not change. | 125 | * but the value itself did not change. | ||
121 | */ | 126 | */ | ||
122 | QString m_cssFileOld; | 127 | QString m_cssFileOld; | ||
123 | 128 | | |||
124 | /** | 129 | /** | ||
125 | * Pointer to the KLineEdit of the KFileDialog which we need | 130 | * Pointer to the KLineEdit of the KFileDialog which we need | ||
126 | * to receive signal editingFinished. | 131 | * to receive signal editingFinished. | ||
127 | */ | 132 | */ | ||
128 | KLineEdit* m_fileKLineEdit; | 133 | KLineEdit* m_fileKLineEdit; | ||
129 | }; | 134 | }; | ||
130 | 135 | | |||
131 | KSettingsReports::KSettingsReports(QWidget* parent) : | 136 | ReportsViewSettingsWidget::ReportsViewSettingsWidget(QWidget* parent) : | ||
132 | QWidget(parent), | 137 | QWidget(parent), | ||
133 | d_ptr(new KSettingsReportsPrivate) | 138 | d_ptr(new ReportsViewSettingsWidgetPrivate) | ||
134 | { | 139 | { | ||
135 | Q_D(KSettingsReports); | 140 | Q_D(ReportsViewSettingsWidget); | ||
136 | d->ui->setupUi(this); | 141 | d->ui->setupUi(this); | ||
137 | 142 | | |||
138 | // keep initial (default) css file in mind | 143 | // keep initial (default) css file in mind | ||
139 | d->m_cssFileOld = KMyMoneySettings::cssFileDefault(); | 144 | d->m_cssFileOld = KMyMoneySettings::cssFileDefault(); | ||
140 | 145 | | |||
141 | // set default css file in ksettingsreports dialog | 146 | // set default css file in ReportsViewSettingsWidget dialog | ||
142 | d->ui->kcfg_CssFileDefault->setUrl(QUrl::fromLocalFile(KMyMoneySettings::cssFileDefault())); | 147 | d->ui->kcfg_CssFileDefault->setUrl(QUrl::fromLocalFile(KMyMoneySettings::cssFileDefault())); | ||
143 | 148 | | |||
144 | d->m_fileKLineEdit = d->ui->kcfg_CssFileDefault->lineEdit(); | 149 | d->m_fileKLineEdit = d->ui->kcfg_CssFileDefault->lineEdit(); | ||
145 | 150 | | |||
146 | connect(d->ui->kcfg_CssFileDefault, &KUrlRequester::urlSelected, | 151 | connect(d->ui->kcfg_CssFileDefault, &KUrlRequester::urlSelected, | ||
147 | this, &KSettingsReports::slotCssUrlSelected); | 152 | this, &ReportsViewSettingsWidget::slotCssUrlSelected); | ||
148 | 153 | | |||
149 | connect(d->m_fileKLineEdit, &QLineEdit::editingFinished, | 154 | connect(d->m_fileKLineEdit, &QLineEdit::editingFinished, | ||
150 | this, &KSettingsReports::slotEditingFinished); | 155 | this, &ReportsViewSettingsWidget::slotEditingFinished); | ||
151 | } | 156 | } | ||
152 | 157 | | |||
153 | KSettingsReports::~KSettingsReports() | 158 | ReportsViewSettingsWidget::~ReportsViewSettingsWidget() | ||
154 | { | 159 | { | ||
155 | Q_D(KSettingsReports); | 160 | Q_D(ReportsViewSettingsWidget); | ||
156 | delete d; | 161 | delete d; | ||
157 | } | 162 | } | ||
158 | 163 | | |||
159 | /** | 164 | /** | ||
160 | * Receiver for signal urlSelected. | 165 | * Receiver for signal urlSelected. | ||
161 | * | 166 | * | ||
162 | * Signal urlSelected only is emitted | 167 | * Signal urlSelected only is emitted | ||
163 | * when a file is selected with the file chooser. | 168 | * when a file is selected with the file chooser. | ||
164 | * | 169 | * | ||
165 | * @param[in] cssUrl url of css file | 170 | * @param[in] cssUrl url of css file | ||
166 | * | 171 | * | ||
167 | * @see KSettingsReports#Private#checkCssFile | 172 | * @see ReportsViewSettingsWidget#Private#checkCssFile | ||
168 | */ | 173 | */ | ||
169 | void KSettingsReports::slotCssUrlSelected(const QUrl &cssUrl) | 174 | void ReportsViewSettingsWidget::slotCssUrlSelected(const QUrl &cssUrl) | ||
170 | { | 175 | { | ||
171 | Q_D(KSettingsReports); | 176 | Q_D(ReportsViewSettingsWidget); | ||
172 | auto css = cssUrl.toLocalFile(); | 177 | auto css = cssUrl.toLocalFile(); | ||
173 | d->checkCssFile(css); | 178 | d->checkCssFile(css); | ||
174 | } | 179 | } | ||
175 | 180 | | |||
176 | /** | 181 | /** | ||
177 | * Receiver for signal editingFinished. | 182 | * Receiver for signal editingFinished. | ||
178 | * | 183 | * | ||
179 | * Signal editingFinished is emitted | 184 | * Signal editingFinished is emitted | ||
180 | * on focus out only, | 185 | * on focus out only, | ||
181 | * not when a file is selected with the file chooser. | 186 | * not when a file is selected with the file chooser. | ||
182 | * | 187 | * | ||
183 | * @see KSettingsReports#Private#checkCssFile | 188 | * @see ReportsViewSettingsWidget#Private#checkCssFile | ||
184 | */ | 189 | */ | ||
185 | void KSettingsReports::slotEditingFinished() | 190 | void ReportsViewSettingsWidget::slotEditingFinished() | ||
186 | { | 191 | { | ||
187 | Q_D(KSettingsReports); | 192 | Q_D(ReportsViewSettingsWidget); | ||
188 | auto txt = d->m_fileKLineEdit->text(); | 193 | auto txt = d->m_fileKLineEdit->text(); | ||
189 | d->checkCssFile(txt); | 194 | d->checkCssFile(txt); | ||
190 | } | 195 | } | ||
196 | | ||||
197 | KCMReportsView::KCMReportsView(QWidget *parent, const QVariantList& args) | ||||
198 | : KCModule(parent, args) | ||||
199 | { | ||||
200 | ReportsViewSettingsWidget* w = new ReportsViewSettingsWidget(this); | ||||
201 | // addConfig(ReportsViewSettings::self(), w); | ||||
202 | addConfig(KMyMoneySettings::self(), w); | ||||
203 | QVBoxLayout *layout = new QVBoxLayout; | ||||
204 | setLayout(layout); | ||||
205 | layout->addWidget(w); | ||||
206 | setButtons(NoAdditionalButton); | ||||
207 | load(); | ||||
208 | } | ||||
209 | | ||||
210 | KCMReportsView::~KCMReportsView() | ||||
211 | { | ||||
212 | } | ||||
213 | | ||||
214 | K_PLUGIN_FACTORY_WITH_JSON(KCMReportsViewFactory, "kcm_reportsview.json", registerPlugin<KCMReportsView>();) | ||||
215 | | ||||
216 | #include "kcm_reportsview.moc" |