KJobWidgets

knotificationjobuidelegate.cpp
1/*
2 This file is part of the KDE Frameworks
3 SPDX-FileCopyrightText: 2020 Kai Uwe Broulik <kde@broulik.de>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "knotificationjobuidelegate.h"
9
10#include <QString>
11
12#include <KJob>
13#include <KNotification>
14
15class KNotificationJobUiDelegatePrivate
16{
17public:
18 void showNotification(KNotification::StandardEvent standardEvent, const QString &text);
19
20 QString description;
21};
22
23void KNotificationJobUiDelegatePrivate::showNotification(KNotification::StandardEvent standardEvent, const QString &text)
24{
25 QString title = description;
26 if (standardEvent == KNotification::Error && !title.isEmpty()) {
27 //: Job name, e.g. Copying has failed
28 title = KNotificationJobUiDelegate::tr("%1 (Failed)").arg(title);
29 }
30 KNotification::event(standardEvent, title, text);
31}
32
34 : KJobUiDelegate(flags)
35 , d(new KNotificationJobUiDelegatePrivate)
36{
37}
38
40
41bool KNotificationJobUiDelegate::setJob(KJob *job)
42{
43 const bool ok = KJobUiDelegate::setJob(job);
44
45 if (ok) {
46 connect(job, &KJob::description, this, [this](KJob *, const QString &title, const QPair<QString, QString> &, const QPair<QString, QString> &) {
47 d->description = title;
48 });
49 }
50
51 return ok;
52}
53
55{
56 if (job()->error() == KJob::KilledJobError) {
57 return;
58 }
59
60 d->showNotification(KNotification::Error, job()->errorString());
61}
62
63void KNotificationJobUiDelegate::slotWarning(KJob *job, const QString &message)
64{
65 Q_UNUSED(job);
66
68 d->showNotification(KNotification::Notification, message);
69 }
70}
71
72#include "moc_knotificationjobuidelegate.cpp"
bool isAutoErrorHandlingEnabled() const
KJob * job() const
virtual bool setJob(KJob *job)
void description(KJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
~KNotificationJobUiDelegate() override
Destroys the KNotificationJobUiDelegate.
KNotificationJobUiDelegate(KJobUiDelegate::Flags flags={KJobUiDelegate::AutoHandlingDisabled})
Constructs a new KNotificationJobUiDelegate.
void showErrorMessage() override
Display a notification to inform the user of the error given by this job.
static KNotification * event(const QString &eventId, const QString &text=QString(), const QPixmap &pixmap=QPixmap(), const NotificationFlags &flags=CloseOnTimeout, const QString &componentName=QString())
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.