Changeset View
Changeset View
Standalone View
Standalone View
src/core/usernotificationhandler.cpp
Show All 30 Lines | |||||
31 | QString UserNotificationHandler::Request::key() const | 31 | QString UserNotificationHandler::Request::key() const | ||
32 | { | 32 | { | ||
33 | QString key; | 33 | QString key; | ||
34 | if (slave) { | 34 | if (slave) { | ||
35 | key = slave->protocol(); | 35 | key = slave->protocol(); | ||
36 | key += slave->host(); | 36 | key += slave->host(); | ||
37 | key += slave->port(); | 37 | key += slave->port(); | ||
38 | key += QLatin1Char('-'); | 38 | key += QLatin1Char('-'); | ||
39 | key += type; | 39 | key += (int)type; | ||
40 | key += QLatin1Char('-'); | ||||
41 | key += msgType; | ||||
40 | } | 42 | } | ||
41 | return key; | 43 | return key; | ||
42 | } | 44 | } | ||
43 | 45 | | |||
44 | UserNotificationHandler::UserNotificationHandler(QObject *parent) | 46 | UserNotificationHandler::UserNotificationHandler(QObject *parent) | ||
45 | : QObject(parent) | 47 | : QObject(parent) | ||
46 | { | 48 | { | ||
47 | } | 49 | } | ||
48 | 50 | | |||
49 | UserNotificationHandler::~UserNotificationHandler() | 51 | UserNotificationHandler::~UserNotificationHandler() | ||
50 | { | 52 | { | ||
51 | qDeleteAll(m_pendingRequests); | 53 | qDeleteAll(m_pendingRequests); | ||
52 | } | 54 | } | ||
53 | 55 | | |||
54 | void UserNotificationHandler::requestMessageBox(SlaveInterface *iface, int type, const QHash<MessageBoxDataType, QVariant> &data) | 56 | void UserNotificationHandler::createRequest(SlaveInterface *iface, RequestType type, const QHash<MessageBoxDataType, QVariant> &data) | ||
55 | { | 57 | { | ||
56 | Request *r = new Request; | 58 | Request *r = new Request; | ||
57 | r->type = type; | 59 | r->type = type; | ||
58 | r->slave = qobject_cast<KIO::Slave *>(iface); | 60 | r->slave = qobject_cast<KIO::Slave *>(iface); | ||
59 | r->data = data; | 61 | r->data = data; | ||
62 | r->msgType = r->data.value(MSG_TYPE).toInt(); | ||||
60 | 63 | | |||
61 | m_pendingRequests.append(r); | 64 | m_pendingRequests.append(r); | ||
62 | if (m_pendingRequests.count() == 1) { | 65 | if (m_pendingRequests.count() == 1) { | ||
63 | QTimer::singleShot(0, this, SLOT(processRequest())); | 66 | QTimer::singleShot(0, this, SLOT(processRequest())); | ||
64 | } | 67 | } | ||
65 | } | 68 | } | ||
66 | 69 | | |||
67 | void UserNotificationHandler::processRequest() | 70 | void UserNotificationHandler::processRequest() | ||
68 | { | 71 | { | ||
69 | if (m_pendingRequests.isEmpty()) { | 72 | if (m_pendingRequests.isEmpty()) { | ||
70 | return; | 73 | return; | ||
71 | } | 74 | } | ||
72 | 75 | | |||
73 | int result = -1; | 76 | QVariant result; | ||
74 | Request *r = m_pendingRequests.first(); | 77 | Request *r = m_pendingRequests.first(); | ||
75 | 78 | | |||
76 | if (r->slave) { | 79 | if (r->slave) { | ||
77 | const QString key = r->key(); | 80 | const QString key = r->key(); | ||
78 | 81 | | |||
79 | if (m_cachedResults.contains(key)) { | 82 | if (m_cachedResults.contains(key)) { | ||
80 | result = *(m_cachedResults[key]); | 83 | result = *(m_cachedResults[key]); | ||
81 | } else { | 84 | } else { | ||
82 | JobUiDelegateExtension *delegateExtension = nullptr; | 85 | JobUiDelegateExtension *delegateExtension = nullptr; | ||
83 | if (r->slave->job()) | 86 | if (r->slave->job()) | ||
84 | delegateExtension = SimpleJobPrivate::get(r->slave->job())->m_uiDelegateExtension; | 87 | delegateExtension = SimpleJobPrivate::get(r->slave->job())->m_uiDelegateExtension; | ||
85 | if (!delegateExtension) | 88 | if (!delegateExtension) | ||
86 | delegateExtension = KIO::defaultJobUiDelegateExtension(); | 89 | delegateExtension = KIO::defaultJobUiDelegateExtension(); | ||
87 | if (delegateExtension) { | 90 | if (delegateExtension) { | ||
88 | const JobUiDelegateExtension::MessageBoxType type = static_cast<JobUiDelegateExtension::MessageBoxType>(r->type); | 91 | if (r->type == REQUEST_MSGBOX) { | ||
89 | result = delegateExtension->requestMessageBox(type, | 92 | result = delegateExtension->requestMessageBox(static_cast<JobUiDelegateExtension::MessageBoxType>(r->msgType), | ||
90 | r->data.value(MSG_TEXT).toString(), | 93 | r->data.value(MSG_TEXT).toString(), | ||
91 | r->data.value(MSG_CAPTION).toString(), | 94 | r->data.value(MSG_CAPTION).toString(), | ||
92 | r->data.value(MSG_YES_BUTTON_TEXT).toString(), | 95 | r->data.value(MSG_YES_BUTTON_TEXT).toString(), | ||
93 | r->data.value(MSG_NO_BUTTON_TEXT).toString(), | 96 | r->data.value(MSG_NO_BUTTON_TEXT).toString(), | ||
94 | r->data.value(MSG_YES_BUTTON_ICON).toString(), | 97 | r->data.value(MSG_YES_BUTTON_ICON).toString(), | ||
95 | r->data.value(MSG_NO_BUTTON_ICON).toString(), | 98 | r->data.value(MSG_NO_BUTTON_ICON).toString(), | ||
96 | r->data.value(MSG_DONT_ASK_AGAIN).toString(), | 99 | r->data.value(MSG_DONT_ASK_AGAIN).toString(), | ||
97 | r->data.value(MSG_META_DATA).toMap()); | 100 | r->data.value(MSG_META_DATA).toMap()); | ||
101 | } else if (r->type == REQUEST_PRIVILEGE_CONFIRMATION) { | ||||
102 | result = delegateExtension->askPrivilegeOperationConfirmation(r->data.value(MSG_CAPTION).toString(), | ||||
103 | r->data.value(MSG_TEXT).toString(), | ||||
104 | r->data.value(MSG_DETAILS).toString()); | ||||
98 | } | 105 | } | ||
99 | m_cachedResults.insert(key, new int(result)); | 106 | } | ||
107 | m_cachedResults.insert(key, new QVariant(result)); | ||||
100 | } | 108 | } | ||
101 | } else { | 109 | } else { | ||
102 | qCWarning(KIO_CORE) << "Cannot prompt user because the requesting ioslave died!" << r->slave; | 110 | qCWarning(KIO_CORE) << "Cannot prompt user because the requesting ioslave died!" << r->slave; | ||
103 | } | 111 | } | ||
104 | 112 | | |||
105 | r->slave->sendMessageBoxAnswer(result); | 113 | if (r->type == REQUEST_MSGBOX) { | ||
114 | int res = result.isValid() ? result.toInt() : -1; | ||||
115 | r->slave->sendMessageBoxAnswer(res); | ||||
116 | } else if (r->type == REQUEST_PRIVILEGE_CONFIRMATION) { | ||||
117 | bool conf = result.isValid() ? result.toBool() : false; | ||||
118 | r->slave->sendPrivilegeConfirmationAnswer(conf); | ||||
119 | } | ||||
106 | m_pendingRequests.removeFirst(); | 120 | m_pendingRequests.removeFirst(); | ||
107 | delete r; | 121 | delete r; | ||
108 | 122 | | |||
109 | if (m_pendingRequests.isEmpty()) { | 123 | if (m_pendingRequests.isEmpty()) { | ||
110 | m_cachedResults.clear(); | 124 | m_cachedResults.clear(); | ||
111 | } else { | 125 | } else { | ||
112 | QTimer::singleShot(0, this, SLOT(processRequest())); | 126 | QTimer::singleShot(0, this, SLOT(processRequest())); | ||
113 | } | 127 | } | ||
114 | } | 128 | } |