Changeset View
Changeset View
Standalone View
Standalone View
src/core/job.cpp
Show All 27 Lines | |||||
28 | #include <QLinkedList> | 28 | #include <QLinkedList> | ||
29 | 29 | | |||
30 | #include <klocalizedstring.h> | 30 | #include <klocalizedstring.h> | ||
31 | #include <kstringhandler.h> | 31 | #include <kstringhandler.h> | ||
32 | 32 | | |||
33 | #include <kio/jobuidelegateextension.h> | 33 | #include <kio/jobuidelegateextension.h> | ||
34 | #include "slave.h" | 34 | #include "slave.h" | ||
35 | #include "scheduler.h" | 35 | #include "scheduler.h" | ||
36 | #include "slavebase.h" | | |||
37 | 36 | | |||
38 | using namespace KIO; | 37 | using namespace KIO; | ||
39 | 38 | | |||
40 | Job::Job() : KCompositeJob(nullptr) | 39 | Job::Job() : KCompositeJob(nullptr) | ||
41 | , d_ptr(new JobPrivate) | 40 | , d_ptr(new JobPrivate) | ||
42 | { | 41 | { | ||
43 | d_ptr->q_ptr = this; | 42 | d_ptr->q_ptr = this; | ||
44 | setCapabilities(KJob::Killable | KJob::Suspendable); | 43 | setCapabilities(KJob::Killable | KJob::Suspendable); | ||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | 253 | for (; it != values.end(); ++it) | |||
258 | } | 257 | } | ||
259 | } | 258 | } | ||
260 | 259 | | |||
261 | MetaData Job::outgoingMetaData() const | 260 | MetaData Job::outgoingMetaData() const | ||
262 | { | 261 | { | ||
263 | return d_func()->m_outgoingMetaData; | 262 | return d_func()->m_outgoingMetaData; | ||
264 | } | 263 | } | ||
265 | 264 | | |||
266 | PrivilegeOperationStatus JobPrivate::tryAskPrivilegeOpConfirmation() | 265 | QByteArray JobPrivate::privilegeOperationData() | ||
267 | { | 266 | { | ||
268 | if (m_confirmationAsked) { | 267 | PrivilegeOperationStatus status = OperationNotAllowed; | ||
269 | return OperationAllowed; | | |||
270 | } | | |||
271 | 268 | | |||
272 | if (m_parentJob) { | 269 | if (m_parentJob) { | ||
dfaure: This feels like C code ;)
| |||||
273 | if (!m_parentJob->d_func()->m_privilegeExecutionEnabled) { | 270 | QByteArray jobData = m_parentJob->d_func()->privilegeOperationData(); | ||
274 | return OperationNotAllowed; | | |||
275 | } | | |||
276 | | ||||
277 | if (!m_parentJob->d_func()->m_confirmationAsked) { | | |||
278 | PrivilegeOperationStatus opStatus = m_parentJob->d_func()->tryAskPrivilegeOpConfirmation(); | | |||
279 | if (opStatus == OperationAllowed) { | | |||
280 | // Copy meta-data from parent job | 271 | // Copy meta-data from parent job | ||
281 | m_incomingMetaData.insert(QStringLiteral("TestData"), m_parentJob->queryMetaData(QStringLiteral("TestData"))); | 272 | m_incomingMetaData.insert(QStringLiteral("TestData"), m_parentJob->queryMetaData(QStringLiteral("TestData"))); | ||
282 | m_confirmationAsked = true; | 273 | return jobData; | ||
283 | } | | |||
284 | return opStatus; | | |||
285 | } else { | 274 | } else { | ||
286 | return OperationAllowed; | 275 | if (m_privilegeExecutionEnabled) { | ||
287 | } | 276 | status = OperationAllowed; | ||
288 | } else { | | |||
289 | // In case of SimpleJob like chmod, chown, etc. which don't accept JobFlags | | |||
290 | if (!m_privilegeExecutionEnabled) { | | |||
291 | return OperationNotAllowed; | | |||
292 | } | | |||
293 | } | | |||
294 | | ||||
295 | switch (m_operationType) { | 277 | switch (m_operationType) { | ||
296 | case ChangeAttr: | 278 | case ChangeAttr: | ||
297 | m_caption = i18n("Change Attribute"); | 279 | m_caption = i18n("Change Attribute"); | ||
298 | m_message = i18n("Root privileges are required to change file attributes. " | 280 | m_message = i18n("Root privileges are required to change file attributes. " | ||
299 | "Do you want to continue?"); | 281 | "Do you want to continue?"); | ||
300 | break; | 282 | break; | ||
301 | case Copy: | 283 | case Copy: | ||
302 | m_caption = i18n("Copy Files"); | 284 | m_caption = i18n("Copy Files"); | ||
303 | m_message = i18n("Root privileges are required to complete the copy operation. " | 285 | m_message = i18n("Root privileges are required to complete the copy operation. " | ||
304 | "Do you want to continue?"); | 286 | "Do you want to continue?"); | ||
305 | break; | 287 | break; | ||
306 | case Delete: | 288 | case Delete: | ||
307 | m_caption = i18n("Delete Files"); | 289 | m_caption = i18n("Delete Files"); | ||
308 | m_message = i18n("Root privileges are required to complete the delete operation. " | 290 | m_message = i18n("Root privileges are required to complete the delete operation. " | ||
309 | "However, doing so may damage your system. Do you want to continue?"); | 291 | "However, doing so may damage your system. Do you want to continue?"); | ||
310 | break; | 292 | break; | ||
311 | case MkDir: | 293 | case MkDir: | ||
312 | m_caption = i18n("Create Folder"); | 294 | m_caption = i18n("Create Folder"); | ||
313 | m_message = i18n("Root privileges are required to create this folder. " | 295 | m_message = i18n("Root privileges are required to create this folder. " | ||
314 | "Do you want to continue?"); | 296 | "Do you want to continue?"); | ||
315 | break; | 297 | break; | ||
316 | case Move: | 298 | case Move: | ||
317 | m_caption = i18n("Move Items"); | 299 | m_caption = i18n("Move Items"); | ||
318 | m_message = i18n("Root privileges are required to complete the move operation. " | 300 | m_message = i18n("Root privileges are required to complete the move operation. " | ||
319 | "Do you want to continue?"); | 301 | "Do you want to continue?"); | ||
320 | break; | 302 | break; | ||
321 | case Rename: | 303 | case Rename: | ||
322 | m_caption = i18n("Rename"); | 304 | m_caption = i18n("Rename"); | ||
323 | m_message = i18n("Root privileges are required to complete renaming. " | 305 | m_message = i18n("Root privileges are required to complete renaming. " | ||
324 | "Do you want to continue?"); | 306 | "Do you want to continue?"); | ||
325 | break; | 307 | break; | ||
326 | case Symlink: | 308 | case Symlink: | ||
327 | m_caption = i18n("Create Symlink"); | 309 | m_caption = i18n("Create Symlink"); | ||
328 | m_message = i18n("Root privileges are required to create a symlink. " | 310 | m_message = i18n("Root privileges are required to create a symlink. " | ||
329 | "Do you want to continue?"); | 311 | "Do you want to continue?"); | ||
330 | break; | 312 | break; | ||
331 | case Transfer: | 313 | case Transfer: | ||
332 | m_caption = i18n("Transfer data"); | 314 | m_caption = i18n("Transfer data"); | ||
333 | m_message = i18n("Root privileges are required to complete transferring data. " | 315 | m_message = i18n("Root privileges are required to complete transferring data. " | ||
334 | "Do you want to continue?"); | 316 | "Do you want to continue?"); | ||
335 | default: | 317 | default: | ||
336 | break; | 318 | break; | ||
337 | } | 319 | } | ||
Either declare a var here, or return that directly (after swapping with next statement of course). dfaure: Either declare a var here, or return that directly (after swapping with next statement of… | |||||
338 | 320 | | |||
339 | if (m_outgoingMetaData.value(QStringLiteral("UnitTesting")) == QLatin1String("true")) { | 321 | if (m_outgoingMetaData.value(QStringLiteral("UnitTesting")) == QLatin1String("true")) { | ||
340 | // Set meta-data for the top-level job | 322 | // Set meta-data for the top-level job | ||
341 | m_incomingMetaData.insert(QStringLiteral("TestData"), QStringLiteral("PrivilegeOperationAllowed")); | 323 | m_incomingMetaData.insert(QStringLiteral("TestData"), QStringLiteral("PrivilegeOperationAllowed")); | ||
342 | return OperationAllowed; | | |||
343 | } | 324 | } | ||
344 | | ||||
345 | if (!m_uiDelegateExtension) { | | |||
346 | return OperationNotAllowed; | | |||
347 | } | 325 | } | ||
348 | | ||||
349 | int status = m_uiDelegateExtension->requestMessageBox(JobUiDelegateExtension::WarningContinueCancel, | | |||
350 | m_message, m_caption, i18n("Continue"), i18n("Cancel")); | | |||
351 | m_confirmationAsked = true; | | |||
352 | | ||||
353 | if (status == SlaveBase::Cancel) { | | |||
354 | return OperationCanceled; | | |||
355 | } | 326 | } | ||
dfaure: This overwrites m_data everytime, so it might as well be a local variable. | |||||
dfaure: And here you can declare another QByteArray, more locally. | |||||
356 | return OperationAllowed; | 327 | | ||
328 | QByteArray parentJobData; | ||||
329 | QDataStream ds(&parentJobData, QIODevice::WriteOnly); | ||||
330 | ds << status << m_caption << m_message; | ||||
331 | return parentJobData; | ||||
357 | } | 332 | } | ||
358 | 333 | | |||
359 | ////////////////////////// | 334 | ////////////////////////// | ||
360 | 335 | | |||
361 | class KIO::DirectCopyJobPrivate: public KIO::SimpleJobPrivate | 336 | class KIO::DirectCopyJobPrivate: public KIO::SimpleJobPrivate | ||
362 | { | 337 | { | ||
363 | public: | 338 | public: | ||
364 | DirectCopyJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs) | 339 | DirectCopyJobPrivate(const QUrl &url, int command, const QByteArray &packedArgs) | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |
This feels like C code ;)