Changeset View
Changeset View
Standalone View
Standalone View
src/knotificationjobuidelegate.cpp
- This file was added.
1 | /* This file is part of the KDE Frameworks | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2020 Kai Uwe Broulik <kde@broulik.de> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Library General Public | ||||
6 | License version 2 as published by the Free Software Foundation. | ||||
7 | | ||||
8 | This library is distributed in the hope that it will be useful, | ||||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
11 | Library General Public License for more details. | ||||
12 | | ||||
13 | You should have received a copy of the GNU Library General Public License | ||||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||||
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
16 | Boston, MA 02110-1301, USA. | ||||
17 | */ | ||||
18 | | ||||
19 | #include "knotificationjobuidelegate.h" | ||||
20 | | ||||
21 | #include <KJob> | ||||
22 | #include <KNotification> | ||||
23 | | ||||
24 | class Q_DECL_HIDDEN KNotificationJobUiDelegate::Private | ||||
kossebau: Not using a nested class `Private` but a normal separate one like here to be named… | |||||
broulik: I thought we wanted to migrate towards nested `Private` class? :0 | |||||
I don't remember any past discussion about this, but as I discovered in KIO commit 3d2330968b, nested Private classes have the problem that you can't forward-declare them elsewhere in order to make them friends of another class. What would be the arguments in favour of nested Private classes? dfaure: I don't remember any past discussion about this, but as I discovered in KIO commit 3d2330968b… | |||||
Someone should update the part about the nested Private classes https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C++#Using_a_d-Pointer ahmadsamir: Someone should update the part about the nested Private classes https://community.kde. | |||||
25 | { | ||||
26 | public: | ||||
27 | Private(); | ||||
28 | | ||||
29 | void showNotification(KNotification::StandardEvent standardEvent, const QString &text); | ||||
30 | }; | ||||
31 | | ||||
32 | KNotificationJobUiDelegate::Private::Private() | ||||
dfaure: remove? | |||||
33 | { | ||||
34 | } | ||||
35 | | ||||
36 | void KNotificationJobUiDelegate::Private::showNotification(KNotification::StandardEvent standardEvent, const QString &text) | ||||
37 | { | ||||
38 | KNotification::event(standardEvent, QString(), text); | ||||
39 | } | ||||
40 | | ||||
41 | KNotificationJobUiDelegate::KNotificationJobUiDelegate() | ||||
42 | : d(new KNotificationJobUiDelegate::Private) | ||||
43 | { | ||||
44 | } | ||||
45 | | ||||
46 | KNotificationJobUiDelegate::~KNotificationJobUiDelegate() | ||||
47 | { | ||||
48 | delete d; | ||||
49 | } | ||||
50 | | ||||
51 | void KNotificationJobUiDelegate::showErrorMessage() | ||||
52 | { | ||||
53 | if (job()->error() == KJob::KilledJobError) { | ||||
54 | return; | ||||
55 | } | ||||
56 | | ||||
57 | d->showNotification(KNotification::Error, job()->errorString()); | ||||
58 | } | ||||
59 | | ||||
60 | void KNotificationJobUiDelegate::slotWarning(KJob *job, const QString &plain, const QString &rich) | ||||
61 | { | ||||
62 | Q_UNUSED(job); | ||||
63 | Q_UNUSED(rich); | ||||
64 | | ||||
65 | if (isAutoErrorHandlingEnabled()) { | ||||
66 | d->showNotification(KNotification::Notification, plain); | ||||
67 | } | ||||
68 | } | ||||
69 | | ||||
70 | #include "knotificationjobuidelegate.moc" |
Not using a nested class Private but a normal separate one like here to be named KNotificationJobUiDelegatePrivate seems more simple, avoids the need for things like Q_DECL_HIDDEN.
At least recently most code uses the latter, so would be good to standardize on that.