Changeset View
Changeset View
Standalone View
Standalone View
applets/icon/iconapplet.cpp
Show First 20 Lines • Show All 367 Lines • ▼ Show 20 Line(s) | |||||
368 | void IconApplet::run() | 368 | void IconApplet::run() | ||
369 | { | 369 | { | ||
370 | new KRun(QUrl::fromLocalFile(m_localPath), QApplication::desktop()); | 370 | new KRun(QUrl::fromLocalFile(m_localPath), QApplication::desktop()); | ||
371 | } | 371 | } | ||
372 | 372 | | |||
373 | void IconApplet::processDrop(QObject *dropEvent) | 373 | void IconApplet::processDrop(QObject *dropEvent) | ||
374 | { | 374 | { | ||
375 | Q_ASSERT(dropEvent); | 375 | Q_ASSERT(dropEvent); | ||
376 | Q_ASSERT(isAcceptableDrag(dropEvent)); | ||||
376 | 377 | | |||
377 | // DeclarativeDropEvent and co aren't public | 378 | const auto &urls = urlsFromDrop(dropEvent); | ||
378 | const QObject *mimeData = qvariant_cast<QObject *>(dropEvent->property("mimeData")); | | |||
379 | Q_ASSERT(mimeData); | | |||
380 | | ||||
381 | const QJsonArray &droppedUrls = mimeData->property("urls").toJsonArray(); | | |||
382 | | ||||
383 | QList<QUrl> urls; | | |||
384 | urls.reserve(droppedUrls.count()); | | |||
385 | foreach (const QJsonValue &droppedUrl, droppedUrls) { | | |||
386 | const QUrl url(droppedUrl.toString()); | | |||
387 | if (url.isValid()) { | | |||
388 | urls.append(url); | | |||
389 | } | | |||
390 | } | | |||
391 | 379 | | |||
392 | if (urls.isEmpty()) { | 380 | if (urls.isEmpty()) { | ||
393 | return; | 381 | return; | ||
394 | } | 382 | } | ||
395 | 383 | | |||
396 | const QString &localPath = m_url.toLocalFile(); | 384 | const QString &localPath = m_url.toLocalFile(); | ||
397 | 385 | | |||
398 | if (KDesktopFile::isDesktopFile(localPath)) { | 386 | if (KDesktopFile::isDesktopFile(localPath)) { | ||
399 | KRun::runService(KService(localPath), urls, nullptr); | 387 | KRun::runService(KService(localPath), urls, nullptr); | ||
400 | return; | 388 | return; | ||
401 | } | 389 | } | ||
402 | 390 | | |||
403 | QMimeDatabase db; | 391 | QMimeDatabase db; | ||
404 | const QMimeType mimeType = db.mimeTypeForUrl(m_url); | 392 | const QMimeType mimeType = db.mimeTypeForUrl(m_url); | ||
405 | 393 | | |||
406 | if (KAuthorized::authorize(QStringLiteral("shell_access")) | 394 | if (isExecutable(mimeType)) { // isAcceptableDrag has the KAuthorized check for this | ||
407 | && (mimeType.inherits(QStringLiteral("application/x-executable")) | | |||
408 | || mimeType.inherits(QStringLiteral("application/x-shellscript")))) { | | |||
409 | QProcess::startDetached(m_url.toLocalFile(), QUrl::toStringList(urls)); | 395 | QProcess::startDetached(m_url.toLocalFile(), QUrl::toStringList(urls)); | ||
410 | return; | 396 | return; | ||
411 | } | 397 | } | ||
412 | 398 | | |||
413 | if (mimeType.inherits(QStringLiteral("inode/directory"))) { | 399 | if (mimeType.inherits(QStringLiteral("inode/directory"))) { | ||
414 | QMimeData mimeData; | 400 | QMimeData mimeData; | ||
415 | mimeData.setUrls(urls); | 401 | mimeData.setUrls(urls); | ||
416 | 402 | | |||
417 | // DeclarativeDropEvent isn't public | 403 | // DeclarativeDropEvent isn't public | ||
418 | QDropEvent de(QPointF(dropEvent->property("x").toInt(), dropEvent->property("y").toInt()), | 404 | QDropEvent de(QPointF(dropEvent->property("x").toInt(), dropEvent->property("y").toInt()), | ||
419 | static_cast<Qt::DropActions>(dropEvent->property("proposedActions").toInt()), | 405 | static_cast<Qt::DropActions>(dropEvent->property("proposedActions").toInt()), | ||
420 | &mimeData, | 406 | &mimeData, | ||
421 | static_cast<Qt::MouseButtons>(dropEvent->property("buttons").toInt()), | 407 | static_cast<Qt::MouseButtons>(dropEvent->property("buttons").toInt()), | ||
422 | static_cast<Qt::KeyboardModifiers>(dropEvent->property("modifiers").toInt())); | 408 | static_cast<Qt::KeyboardModifiers>(dropEvent->property("modifiers").toInt())); | ||
423 | 409 | | |||
424 | KIO::DropJob *dropJob = KIO::drop(&de, m_url); | 410 | KIO::DropJob *dropJob = KIO::drop(&de, m_url); | ||
425 | KJobWidgets::setWindow(dropJob, QApplication::desktop()); | 411 | KJobWidgets::setWindow(dropJob, QApplication::desktop()); | ||
426 | return; | 412 | return; | ||
427 | } | 413 | } | ||
428 | } | 414 | } | ||
429 | 415 | | |||
416 | bool IconApplet::isAcceptableDrag(QObject *dropEvent) | ||||
417 | { | ||||
418 | Q_ASSERT(dropEvent); | ||||
419 | | ||||
420 | const auto &urls = urlsFromDrop(dropEvent); | ||||
421 | | ||||
422 | if (urls.isEmpty()) { | ||||
423 | return false; | ||||
424 | } | ||||
425 | | ||||
426 | const QString &localPath = m_url.toLocalFile(); | ||||
427 | if (KDesktopFile::isDesktopFile(localPath)) { | ||||
428 | return true; | ||||
429 | } | ||||
430 | | ||||
431 | QMimeDatabase db; | ||||
432 | const QMimeType mimeType = db.mimeTypeForUrl(m_url); | ||||
433 | | ||||
434 | if (KAuthorized::authorize(QStringLiteral("shell_access")) && isExecutable(mimeType)) { | ||||
435 | return true; | ||||
436 | } | ||||
437 | | ||||
438 | if (mimeType.inherits(QStringLiteral("inode/directory"))) { | ||||
439 | return true; | ||||
440 | } | ||||
441 | | ||||
442 | return false; | ||||
443 | } | ||||
444 | | ||||
445 | QList<QUrl> IconApplet::urlsFromDrop(QObject *dropEvent) | ||||
446 | { | ||||
447 | // DeclarativeDropEvent and co aren't public | ||||
448 | const QObject *mimeData = qvariant_cast<QObject *>(dropEvent->property("mimeData")); | ||||
449 | Q_ASSERT(mimeData); | ||||
450 | | ||||
451 | const QJsonArray &droppedUrls = mimeData->property("urls").toJsonArray(); | ||||
452 | | ||||
453 | QList<QUrl> urls; | ||||
454 | urls.reserve(droppedUrls.count()); | ||||
455 | for (const QJsonValue &droppedUrl : droppedUrls) { | ||||
456 | const QUrl url(droppedUrl.toString()); | ||||
457 | if (url.isValid()) { | ||||
458 | urls.append(url); | ||||
459 | } | ||||
460 | } | ||||
461 | | ||||
462 | return urls; | ||||
463 | } | ||||
464 | | ||||
465 | bool IconApplet::isExecutable(const QMimeType &mimeType) | ||||
466 | { | ||||
467 | return (mimeType.inherits(QStringLiteral("application/x-executable")) | ||||
468 | || mimeType.inherits(QStringLiteral("application/x-shellscript"))); | ||||
469 | } | ||||
470 | | ||||
430 | void IconApplet::configure() | 471 | void IconApplet::configure() | ||
431 | { | 472 | { | ||
432 | KPropertiesDialog *dialog = m_configDialog.data(); | 473 | KPropertiesDialog *dialog = m_configDialog.data(); | ||
433 | 474 | | |||
434 | if (dialog) { | 475 | if (dialog) { | ||
435 | dialog->show(); | 476 | dialog->show(); | ||
436 | dialog->raise(); | 477 | dialog->raise(); | ||
437 | return; | 478 | return; | ||
Show All 37 Lines |