• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
usernotificationhandler.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2012 Dawit Alemayehu <adawit@kde.org>
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 "usernotificationhandler_p.h"
20
21#include "slave.h"
22#include "jobuidelegate.h"
23
24#include <kdebug.h>
25
26#include <QTimer>
27
28using namespace KIO;
29
30QString UserNotificationHandler::Request::key() const
31{
32 QString key;
33 if (slave) {
34 key = slave->protocol();
35 key += slave->host();
36 key += slave->port();
37 key += QLatin1Char('-');
38 key += type;
39 }
40 return key;
41}
42
43UserNotificationHandler::UserNotificationHandler(QObject* parent)
44 :QObject(parent)
45{
46}
47
48UserNotificationHandler::~UserNotificationHandler()
49{
50 qDeleteAll(m_pendingRequests);
51}
52
53void UserNotificationHandler::requestMessageBox(SlaveInterface* iface, int type, const QHash<MessageBoxDataType, QVariant>& data)
54{
55 Request* r = new Request;
56 r->type = type;
57 r->slave = qobject_cast<KIO::Slave*>(iface);
58 r->data = data;
59
60 m_pendingRequests.append(r);
61 if (m_pendingRequests.count() == 1) {
62 QTimer::singleShot(0, this, SLOT(processRequest()));
63 }
64}
65
66void UserNotificationHandler::processRequest()
67{
68 if (m_pendingRequests.isEmpty())
69 return;
70
71 int result = -1;
72 Request* r = m_pendingRequests.first();
73
74 if (r->slave) {
75 const QString key = r->key();
76
77 if (m_cachedResults.contains(key)) {
78 result = *(m_cachedResults[key]);
79 } else {
80 JobUiDelegate ui;
81 const JobUiDelegate::MessageBoxType type = static_cast<JobUiDelegate::MessageBoxType>(r->type);
82 result = ui.requestMessageBox(type,
83 r->data.value(MSG_TEXT).toString(),
84 r->data.value(MSG_CAPTION).toString(),
85 r->data.value(MSG_YES_BUTTON_TEXT).toString(),
86 r->data.value(MSG_NO_BUTTON_TEXT).toString(),
87 r->data.value(MSG_YES_BUTTON_ICON).toString(),
88 r->data.value(MSG_NO_BUTTON_ICON).toString(),
89 r->data.value(MSG_DONT_ASK_AGAIN).toString(),
90 r->data.value(MSG_META_DATA).toMap());
91 m_cachedResults.insert(key, new int(result));
92 }
93 } else {
94 kWarning() << "Cannot prompt user because the requesting ioslave died!" << r->slave;
95 }
96
97 r->slave->sendMessageBoxAnswer(result);
98 m_pendingRequests.removeFirst();
99 delete r;
100
101 if (m_pendingRequests.isEmpty()) {
102 m_cachedResults.clear();
103 } else {
104 QTimer::singleShot(0, this, SLOT(processRequest()));
105 }
106}
107
108#include "usernotificationhandler_p.moc"
KIO::JobUiDelegate
A UI delegate tuned to be used with KIO Jobs.
Definition: jobuidelegate.h:40
KIO::JobUiDelegate::requestMessageBox
int requestMessageBox(MessageBoxType type, const QString &text, const QString &caption, const QString &buttonYes, const QString &buttonNo, const QString &iconYes=QString(), const QString &iconNo=QString(), const QString &dontAskAgainName=QString(), const KIO::MetaData &sslMetaData=KIO::MetaData())
This function allows for the delegation user prompts from the ioslaves.
Definition: jobuidelegate.cpp:200
KIO::JobUiDelegate::MessageBoxType
MessageBoxType
Message box types.
Definition: jobuidelegate.h:141
KIO::SlaveInterface
There are two classes that specifies the protocol between application ( KIO::Job) and kioslave.
Definition: slaveinterface.h:99
KIO::UserNotificationHandler::Request
Definition: usernotificationhandler_p.h:49
KIO::UserNotificationHandler::Request::slave
QPointer< Slave > slave
Definition: usernotificationhandler_p.h:55
KIO::UserNotificationHandler::Request::key
QString key() const
Definition: usernotificationhandler.cpp:30
KIO::UserNotificationHandler::Request::type
int type
Definition: usernotificationhandler_p.h:54
KIO::UserNotificationHandler::Request::data
QHash< MessageBoxDataType, QVariant > data
Definition: usernotificationhandler_p.h:56
KIO::UserNotificationHandler::MSG_TEXT
@ MSG_TEXT
Definition: usernotificationhandler_p.h:38
KIO::UserNotificationHandler::MSG_NO_BUTTON_ICON
@ MSG_NO_BUTTON_ICON
Definition: usernotificationhandler_p.h:43
KIO::UserNotificationHandler::MSG_CAPTION
@ MSG_CAPTION
Definition: usernotificationhandler_p.h:39
KIO::UserNotificationHandler::MSG_NO_BUTTON_TEXT
@ MSG_NO_BUTTON_TEXT
Definition: usernotificationhandler_p.h:41
KIO::UserNotificationHandler::MSG_YES_BUTTON_ICON
@ MSG_YES_BUTTON_ICON
Definition: usernotificationhandler_p.h:42
KIO::UserNotificationHandler::MSG_DONT_ASK_AGAIN
@ MSG_DONT_ASK_AGAIN
Definition: usernotificationhandler_p.h:44
KIO::UserNotificationHandler::MSG_META_DATA
@ MSG_META_DATA
Definition: usernotificationhandler_p.h:45
KIO::UserNotificationHandler::MSG_YES_BUTTON_TEXT
@ MSG_YES_BUTTON_TEXT
Definition: usernotificationhandler_p.h:40
KIO::UserNotificationHandler::UserNotificationHandler
UserNotificationHandler(QObject *parent=0)
Definition: usernotificationhandler.cpp:43
KIO::UserNotificationHandler::requestMessageBox
void requestMessageBox(SlaveInterface *iface, int type, const QHash< MessageBoxDataType, QVariant > &data)
Definition: usernotificationhandler.cpp:53
KIO::UserNotificationHandler::~UserNotificationHandler
virtual ~UserNotificationHandler()
Definition: usernotificationhandler.cpp:48
QHash
QObject
kWarning
#define kWarning
jobuidelegate.h
kdebug.h
KIO
A namespace for KIO globals.
Definition: kbookmarkmenu.h:55
slave.h
usernotificationhandler_p.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal