Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/containmentinterface.cpp
Show All 23 Lines | |||||
24 | #include <kdeclarative/qmlobject.h> | 24 | #include <kdeclarative/qmlobject.h> | ||
25 | 25 | | |||
26 | #include <QClipboard> | 26 | #include <QClipboard> | ||
27 | #include <QQmlExpression> | 27 | #include <QQmlExpression> | ||
28 | #include <QQmlProperty> | 28 | #include <QQmlProperty> | ||
29 | #include <QMimeData> | 29 | #include <QMimeData> | ||
30 | #include <QVersionNumber> | 30 | #include <QVersionNumber> | ||
31 | #include <QScreen> | 31 | #include <QScreen> | ||
32 | #include <QApplication> | ||||
32 | 33 | | |||
33 | #include <kactioncollection.h> | 34 | #include <kactioncollection.h> | ||
34 | #include <KAcceleratorManager> | 35 | #include <KAcceleratorManager> | ||
35 | #include <kauthorized.h> | 36 | #include <kauthorized.h> | ||
36 | #include <QDebug> | 37 | #include <QDebug> | ||
37 | #include <klocalizedstring.h> | 38 | #include <klocalizedstring.h> | ||
38 | #include <kurlmimedata.h> | 39 | #include <kurlmimedata.h> | ||
39 | #include <QMimeDatabase> | 40 | #include <QMimeDatabase> | ||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Line(s) | |||||
428 | } | 429 | } | ||
429 | 430 | | |||
430 | void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y, KIO::DropJob *dropJob) | 431 | void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y, KIO::DropJob *dropJob) | ||
431 | { | 432 | { | ||
432 | if (!mimeData) { | 433 | if (!mimeData) { | ||
433 | return; | 434 | return; | ||
434 | } | 435 | } | ||
435 | 436 | | |||
437 | m_multipleMimenames = false; | ||||
438 | m_urlsHaveSameMimename.clear(); | ||||
439 | m_dropActions.clear(); | ||||
440 | | ||||
436 | //const QMimeData *mimeData = data; | 441 | //const QMimeData *mimeData = data; | ||
437 | 442 | | |||
438 | qDebug() << "Arrived mimeData" << mimeData->urls() << mimeData->formats() << "at" << x << ", " << y; | 443 | qDebug() << "Arrived mimeData" << mimeData->urls() << mimeData->formats() << "at" << x << ", " << y; | ||
439 | 444 | | |||
440 | // Catch drops from a Task Manager and convert to usable URL. | 445 | // Catch drops from a Task Manager and convert to usable URL. | ||
441 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | 446 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | ||
442 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | 447 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | ||
443 | mimeData->setUrls(urls); | 448 | mimeData->setUrls(urls); | ||
444 | } | 449 | } | ||
445 | 450 | | |||
446 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | 451 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | ||
447 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | 452 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | ||
448 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | 453 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||
449 | foreach (const QString &appletName, appletNames) { | 454 | foreach (const QString &appletName, appletNames) { | ||
450 | qDebug() << "adding" << appletName; | 455 | qDebug() << "adding" << appletName; | ||
451 | 456 | | |||
452 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | 457 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | ||
453 | } | 458 | } | ||
454 | } else if (mimeData->hasUrls()) { | 459 | } else if (mimeData->hasUrls()) { | ||
455 | //TODO: collect the mimetypes of available script engines and offer | 460 | //TODO: collect the mimetypes of available script engines and offer | ||
456 | // to create widgets out of the matching URLs, if any | 461 | // to create widgets out of the matching URLs, if any | ||
457 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | 462 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | ||
458 | foreach (const QUrl &url, urls) { | 463 | QMenu *choices = nullptr; | ||
464 | | ||||
465 | if (!urls.at(0).isLocalFile()) { | ||||
466 | QApplication::setOverrideCursor(Qt::WaitCursor); | ||||
467 | } | ||||
468 | | ||||
469 | if (!dropJob) { | ||||
470 | choices = new QMenu(i18n("Content dropped")); | ||||
471 | | ||||
472 | if (choices->winId()) { | ||||
473 | choices->windowHandle()->setTransientParent(window()); | ||||
474 | } | ||||
475 | } | ||||
476 | | ||||
459 | QMimeDatabase db; | 477 | QMimeDatabase db; | ||
478 | QSet<QString> mimenames; | ||||
479 | | ||||
480 | foreach (const QUrl &url, urls) { | ||||
460 | const QMimeType &mime = db.mimeTypeForUrl(url); | 481 | const QMimeType &mime = db.mimeTypeForUrl(url); | ||
461 | QString mimeName = mime.name(); | 482 | QString mimeName = mime.name(); | ||
462 | QVariantList args; | 483 | m_urlsHaveSameMimename << url; | ||
463 | args << url.url(); | 484 | mimenames << mimeName; | ||
464 | qDebug() << "can decode" << mimeName << args; | 485 | qDebug() << "can decode" << mimeName; // << args; | ||
486 | } | ||||
465 | 487 | | |||
488 | if (mimenames.size() > 1) { | ||||
489 | m_multipleMimenames = true; | ||||
490 | } | ||||
466 | // It may be a directory or a file, let's stat | 491 | // It may be a directory or a file, let's stat | ||
467 | KIO::JobFlags flags = KIO::HideProgressInfo; | 492 | KIO::JobFlags flags = KIO::HideProgressInfo; | ||
468 | KIO::MimetypeJob *job = KIO::mimetype(url, flags); | 493 | KIO::MimetypeJob *job = KIO::mimetype(m_urlsHaveSameMimename.at(0), flags); | ||
469 | m_dropPoints[job] = QPoint(x, y); | 494 | m_dropPoints[job] = QPoint(x, y); | ||
470 | 495 | | |||
471 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | | |||
472 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*,QString)), | | |||
473 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | | |||
474 | | ||||
475 | if (dropJob) { | 496 | if (dropJob) { | ||
476 | m_dropJobs[job] = dropJob; | 497 | m_dropJobs[job] = dropJob; | ||
477 | } else { | 498 | } else { | ||
478 | QMenu *choices = new QMenu(i18n("Content dropped")); | | |||
479 | if (choices->winId()) { | | |||
480 | choices->windowHandle()->setTransientParent(window()); | | |||
481 | } | | |||
482 | choices->addAction(QIcon::fromTheme(QStringLiteral("process-working")), i18n("Fetching file type...")); | | |||
483 | choices->popup(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | | |||
484 | | ||||
485 | m_dropMenus[job] = choices; | 499 | m_dropMenus[job] = choices; | ||
486 | } | 500 | } | ||
487 | } | 501 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | ||
502 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*, QString)), | ||||
503 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | ||||
488 | 504 | | |||
489 | } else { | 505 | } else { | ||
490 | QStringList formats = mimeData->formats(); | 506 | QStringList formats = mimeData->formats(); | ||
491 | QHash<QString, KPluginMetaData> seenPlugins; | 507 | QHash<QString, KPluginMetaData> seenPlugins; | ||
492 | QHash<QString, QString> pluginFormats; | 508 | QHash<QString, QString> pluginFormats; | ||
493 | 509 | | |||
494 | foreach (const QString &format, formats) { | 510 | foreach (const QString &format, formats) { | ||
495 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | 511 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | ||
496 | 512 | | |||
497 | foreach (const auto &plugin, plugins) { | 513 | foreach (const auto &plugin, plugins) { | ||
498 | if (seenPlugins.contains(plugin.pluginId())) { | 514 | if (seenPlugins.contains(plugin.pluginId())) { | ||
499 | continue; | 515 | continue; | ||
500 | } | 516 | } | ||
501 | 517 | | |||
502 | seenPlugins.insert(plugin.pluginId(), plugin); | 518 | seenPlugins.insert(plugin.pluginId(), plugin); | ||
503 | pluginFormats.insert(plugin.pluginId(), format); | 519 | pluginFormats.insert(plugin.pluginId(), format); | ||
504 | } | 520 | } | ||
505 | } | 521 | } | ||
506 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | 522 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | ||
507 | 523 | | |||
508 | QString selectedPlugin; | 524 | QString selectedPlugin; | ||
509 | 525 | | |||
510 | if (seenPlugins.isEmpty()) { | 526 | if (seenPlugins.isEmpty()) { | ||
511 | // do nothing | 527 | //do nothing | ||
512 | //directly create if only one offer only if the containment didn't pass an existing plugin | 528 | //directly create if only one offer only if the containment didn't pass an existing plugin | ||
513 | } else if (seenPlugins.count() == 1) { | 529 | } else if (seenPlugins.count() == 1) { | ||
514 | selectedPlugin = seenPlugins.constBegin().key(); | 530 | selectedPlugin = seenPlugins.constBegin().key(); | ||
515 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | 531 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | ||
516 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | 532 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | ||
517 | } else { | 533 | } else { | ||
518 | QMenu *choices = nullptr; | 534 | QMenu *choices = nullptr; | ||
519 | if (!dropJob) { | 535 | if (!dropJob) { | ||
Show All 23 Lines | 543 | foreach (const auto &info, seenPlugins) { | |||
543 | }); | 559 | }); | ||
544 | 560 | | |||
545 | actionsToPlugins.insert(action, info.pluginId()); | 561 | actionsToPlugins.insert(action, info.pluginId()); | ||
546 | } | 562 | } | ||
547 | 563 | | |||
548 | //if the menu was created by ourselves, delete it | 564 | //if the menu was created by ourselves, delete it | ||
549 | if (choices) { | 565 | if (choices) { | ||
550 | QAction *choice = choices->exec(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | 566 | QAction *choice = choices->exec(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | ||
551 | | ||||
552 | delete choices; | 567 | delete choices; | ||
553 | } else { | 568 | } else { | ||
554 | Q_ASSERT(dropJob); | 569 | Q_ASSERT(dropJob); | ||
555 | dropJob->setApplicationActions(extraActions); | 570 | dropJob->setApplicationActions(extraActions); | ||
556 | } | 571 | } | ||
557 | } | 572 | } | ||
558 | } | 573 | } | ||
559 | } | 574 | } | ||
560 | 575 | | |||
561 | void ContainmentInterface::clearDataForMimeJob(KIO::Job *job) | 576 | void ContainmentInterface::clearDataForMimeJob(KIO::Job *job) | ||
562 | { | 577 | { | ||
563 | QObject::disconnect(job, nullptr, this, nullptr); | 578 | QObject::disconnect(job, nullptr, this, nullptr); | ||
579 | auto dropJob = m_dropJobs.value(job); | ||||
580 | auto dropPoint = m_dropPoints.value(job); | ||||
581 | | ||||
564 | m_dropPoints.remove(job); | 582 | m_dropPoints.remove(job); | ||
565 | QMenu *choices = m_dropMenus.take(job); | 583 | QMenu *choices = m_dropMenus.take(job); | ||
566 | m_dropJobs.remove(job); | 584 | m_dropJobs.remove(job); | ||
567 | job->kill(); | 585 | job->kill(); | ||
586 | | ||||
587 | if (choices) { | ||||
588 | choices->popup(dropPoint); | ||||
589 | } else { | ||||
davidedmundson: can you be sure urls has at least 1 at this point? | |||||
Yes, because all clearDataForMimeJob are called from inside of mimeTypeRetrieved which is only called from here: https://phabricator.kde.org/source/plasma-framework/browse/master/src/scriptengines/qml/plasmoid/containmentinterface.cpp$454 trmdi: Yes, because all `clearDataForMimeJob` are called from inside of `mimeTypeRetrieved` which is… | |||||
590 | showDropjobMenu(dropJob, dropPoint); | ||||
591 | } | ||||
592 | | ||||
Don't add uncategorized qDebug, i see it exists in code base but they should be ported as well. anthonyfieroni: Don't add uncategorized qDebug, i see it exists in code base but they should be ported as well. | |||||
593 | if (!m_urlsHaveSameMimename.at(0).isLocalFile()) { | ||||
594 | QApplication::restoreOverrideCursor(); | ||||
595 | } | ||||
568 | } | 596 | } | ||
569 | 597 | | |||
570 | void ContainmentInterface::dropJobResult(KJob *job) | 598 | void ContainmentInterface::dropJobResult(KJob *job) | ||
571 | { | 599 | { | ||
572 | if (job->error()) { | 600 | if (job->error()) { | ||
573 | qDebug() << "ERROR" << job->error() << ' ' << job->errorString(); | 601 | qDebug() << "ERROR" << job->error() << ' ' << job->errorString(); | ||
602 | clearDataForMimeJob(dynamic_cast<KIO::Job *>(job)); | ||||
574 | } | 603 | } | ||
575 | } | 604 | } | ||
576 | 605 | | |||
577 | void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimetype) | 606 | void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimetype) | ||
578 | { | 607 | { | ||
579 | qDebug() << "Mimetype Job returns." << mimetype; | 608 | qDebug() << "Mimetype Job returns." << mimetype; | ||
580 | 609 | | |||
581 | KIO::TransferJob *tjob = dynamic_cast<KIO::TransferJob *>(job); | 610 | KIO::TransferJob *tjob = dynamic_cast<KIO::TransferJob *>(job); | ||
582 | if (!tjob) { | 611 | if (!tjob) { | ||
583 | qDebug() << "job should be a TransferJob, but isn't"; | 612 | qDebug() << "job should be a TransferJob, but isn't"; | ||
584 | clearDataForMimeJob(job); | 613 | clearDataForMimeJob(job); | ||
585 | return; | 614 | return; | ||
586 | } | 615 | } | ||
616 | | ||||
587 | QList<KPluginMetaData> appletList = Plasma::PluginLoader::self()->listAppletMetaDataForUrl(tjob->url()); | 617 | QList<KPluginMetaData> appletList = Plasma::PluginLoader::self()->listAppletMetaDataForUrl(tjob->url()); | ||
588 | if (mimetype.isEmpty() && appletList.isEmpty()) { | 618 | if (mimetype.isEmpty() && appletList.isEmpty()) { | ||
589 | clearDataForMimeJob(job); | 619 | clearDataForMimeJob(job); | ||
590 | qDebug() << "No applets found matching the url (" << tjob->url() << ") or the mimetype (" << mimetype << ")"; | 620 | qDebug() << "No applets found matching the url (" << tjob->url() << ") or the mimetype (" << mimetype << ")"; | ||
591 | return; | 621 | return; | ||
592 | } else { | 622 | } else { | ||
593 | 623 | | |||
594 | QPoint posi; // will be overwritten with the event's position | 624 | QPoint posi; // will be overwritten with the event's position | ||
595 | if (m_dropPoints.contains(tjob)) { | 625 | if (m_dropPoints.contains(tjob)) { | ||
596 | posi = m_dropPoints.value(tjob); | 626 | posi = m_dropPoints.value(tjob); | ||
597 | qDebug() << "Received a suitable dropEvent at" << posi; | 627 | qDebug() << "Received a suitable dropEvent at" << posi; | ||
598 | } else { | 628 | } else { | ||
599 | qDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob"; | 629 | qDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob"; | ||
600 | clearDataForMimeJob(job); | 630 | clearDataForMimeJob(job); | ||
601 | return; | 631 | return; | ||
602 | } | 632 | } | ||
603 | 633 | | |||
604 | QMenu *choices = m_dropMenus.value(tjob); | 634 | QMenu *choices = m_dropMenus.value(tjob); | ||
605 | QList<QAction *> dropActions; | | |||
606 | KIO::DropJob *dropJob = m_dropJobs.value(tjob); | 635 | KIO::DropJob *dropJob = m_dropJobs.value(tjob); | ||
636 | auto dropPoint = m_dropPoints.value(job); | ||||
607 | 637 | | |||
608 | if (!choices && !dropJob) { | 638 | if (!choices && !dropJob) { | ||
609 | qDebug() << "Bailing out. No QMenu or drop job found for this job."; | 639 | qDebug() << "Bailing out. No QMenu or drop job found for this job."; | ||
610 | clearDataForMimeJob(job); | 640 | clearDataForMimeJob(job); | ||
611 | return; | 641 | return; | ||
612 | } | 642 | } | ||
613 | 643 | | |||
614 | qDebug() << "Creating menu for:" << mimetype << posi; | 644 | qDebug() << "Creating menu for:" << mimetype << posi; | ||
Show All 9 Lines | 653 | if (m_wallpaperInterface && m_wallpaperInterface->supportsMimetype(mimetype)) { | |||
624 | wallpaperList << m_wallpaperInterface->kPackage().metadata(); | 654 | wallpaperList << m_wallpaperInterface->kPackage().metadata(); | ||
625 | } else { | 655 | } else { | ||
626 | wallpaperList = WallpaperInterface::listWallpaperMetadataForMimetype(mimetype); | 656 | wallpaperList = WallpaperInterface::listWallpaperMetadataForMimetype(mimetype); | ||
627 | } | 657 | } | ||
628 | } | 658 | } | ||
629 | 659 | | |||
630 | const bool isPlasmaPackage = (mimetype == QLatin1String("application/x-plasma")); | 660 | const bool isPlasmaPackage = (mimetype == QLatin1String("application/x-plasma")); | ||
631 | 661 | | |||
632 | if (!appletList.isEmpty() || !wallpaperList.isEmpty() || isPlasmaPackage) { | 662 | if ((!appletList.isEmpty() || !wallpaperList.isEmpty() || isPlasmaPackage) && !m_multipleMimenames) { | ||
633 | QAction *installPlasmaPackageAction = nullptr; | 663 | QAction *installPlasmaPackageAction = nullptr; | ||
634 | if (isPlasmaPackage) { | 664 | if (isPlasmaPackage) { | ||
635 | if (choices) { | 665 | if (choices) { | ||
636 | choices->addSection(i18n("Plasma Package")); | 666 | choices->addSection(i18n("Plasma Package")); | ||
637 | installPlasmaPackageAction = choices->addAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install")); | 667 | installPlasmaPackageAction = choices->addAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install")); | ||
638 | } else { | 668 | } else { | ||
639 | QAction *action = new QAction(i18n("Plasma Package"), nullptr); | 669 | QAction *action = new QAction(i18n("Plasma Package"), nullptr); | ||
640 | action->setSeparator(true); | 670 | action->setSeparator(true); | ||
641 | dropActions << action; | 671 | m_dropActions << action; | ||
642 | 672 | | |||
643 | installPlasmaPackageAction = new QAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install"), nullptr); | 673 | installPlasmaPackageAction = new QAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install"), nullptr); | ||
644 | Q_ASSERT(dropJob); | 674 | Q_ASSERT(dropJob); | ||
645 | dropActions << installPlasmaPackageAction; | 675 | m_dropActions << installPlasmaPackageAction; | ||
646 | dropJob->setApplicationActions(dropActions); | | |||
647 | } | 676 | } | ||
677 | | ||||
648 | const QString &packagePath = tjob->url().toLocalFile(); | 678 | const QString &packagePath = tjob->url().toLocalFile(); | ||
649 | connect(installPlasmaPackageAction, &QAction::triggered, this, [this, posi, packagePath]() { | 679 | connect(installPlasmaPackageAction, &QAction::triggered, this, [this, posi, packagePath]() { | ||
650 | using namespace KPackage; | 680 | using namespace KPackage; | ||
651 | PackageStructure *structure = PackageLoader::self()->loadPackageStructure(QStringLiteral("Plasma/Applet")); | 681 | PackageStructure *structure = PackageLoader::self()->loadPackageStructure(QStringLiteral("Plasma/Applet")); | ||
652 | Package package(structure); | 682 | Package package(structure); | ||
653 | 683 | | |||
654 | KJob *installJob = package.update(packagePath); | 684 | KJob *installJob = package.update(packagePath); | ||
655 | connect(installJob, &KJob::result, this, [this, packagePath, structure, posi](KJob *job) { | 685 | connect(installJob, &KJob::result, this, [this, packagePath, structure, posi](KJob *job) { | ||
Show All 27 Lines | |||||
683 | }); | 713 | }); | ||
684 | } | 714 | } | ||
685 | 715 | | |||
686 | if (choices) { | 716 | if (choices) { | ||
687 | choices->addSection(i18n("Widgets")); | 717 | choices->addSection(i18n("Widgets")); | ||
688 | } else { | 718 | } else { | ||
689 | QAction *action = new QAction(i18n("Widgets"), nullptr); | 719 | QAction *action = new QAction(i18n("Widgets"), nullptr); | ||
690 | action->setSeparator(true); | 720 | action->setSeparator(true); | ||
691 | dropActions << action; | 721 | m_dropActions << action; | ||
692 | } | 722 | } | ||
693 | foreach (const auto &info, appletList) { | 723 | foreach (const auto &info, appletList) { | ||
694 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | 724 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | ||
695 | QAction *action = new QAction(actionText, nullptr); | 725 | QAction *action = new QAction(actionText, nullptr); | ||
696 | if (!info.iconName().isEmpty()) { | 726 | if (!info.iconName().isEmpty()) { | ||
697 | action->setIcon(QIcon::fromTheme(info.iconName())); | 727 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
698 | } | 728 | } | ||
699 | if (choices) { | 729 | if (choices) { | ||
700 | choices->addAction(action); | 730 | choices->addAction(action); | ||
701 | } | 731 | } | ||
702 | dropActions << action; | 732 | m_dropActions << action; | ||
703 | action->setData(info.pluginId()); | 733 | action->setData(info.pluginId()); | ||
704 | const QUrl url = tjob->url(); | 734 | const QUrl url = tjob->url(); | ||
705 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url]() { | 735 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url]() { | ||
706 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | 736 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | ||
707 | setAppletArgs(applet, mimetype, url.toString()); | 737 | setAppletArgs(applet, mimetype, url.toString()); | ||
708 | }); | 738 | }); | ||
709 | } | 739 | } | ||
710 | { | 740 | { | ||
711 | QAction *action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | 741 | QAction *action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | ||
712 | if (choices) { | 742 | if (choices) { | ||
713 | choices->addAction(action); | 743 | choices->addAction(action); | ||
714 | } | 744 | } | ||
715 | dropActions << action; | 745 | m_dropActions << action; | ||
716 | action->setData(QStringLiteral("org.kde.plasma.icon")); | 746 | action->setData(QStringLiteral("org.kde.plasma.icon")); | ||
717 | const QUrl url = tjob->url(); | 747 | const QUrl url = tjob->url(); | ||
718 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url](){ | 748 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url](){ | ||
719 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | 749 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | ||
720 | setAppletArgs(applet, mimetype, url.toString()); | 750 | setAppletArgs(applet, mimetype, url.toString()); | ||
721 | }); | 751 | }); | ||
722 | } | 752 | } | ||
723 | 753 | | |||
724 | QHash<QAction *, QString> actionsToWallpapers; | 754 | QHash<QAction *, QString> actionsToWallpapers; | ||
725 | if (!wallpaperList.isEmpty()) { | 755 | if (!wallpaperList.isEmpty()) { | ||
726 | if (choices) { | 756 | if (choices) { | ||
727 | choices->addSection(i18n("Wallpaper")); | 757 | choices->addSection(i18n("Wallpaper")); | ||
728 | } else { | 758 | } else { | ||
729 | QAction *action = new QAction(i18n("Wallpaper"), nullptr); | 759 | QAction *action = new QAction(i18n("Wallpaper"), nullptr); | ||
730 | action->setSeparator(true); | 760 | action->setSeparator(true); | ||
731 | dropActions << action; | 761 | m_dropActions << action; | ||
732 | } | 762 | } | ||
733 | 763 | | |||
734 | QMap<QString, KPluginMetaData> sorted; | 764 | QMap<QString, KPluginMetaData> sorted; | ||
735 | foreach (const auto &info, appletList) { | 765 | foreach (const auto &info, appletList) { | ||
736 | sorted.insert(info.name(), info); | 766 | sorted.insert(info.name(), info); | ||
737 | } | 767 | } | ||
738 | 768 | | |||
739 | foreach (const KPluginMetaData &info, wallpaperList) { | 769 | foreach (const KPluginMetaData &info, wallpaperList) { | ||
740 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | 770 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | ||
741 | QAction *action = new QAction(actionText, nullptr); | 771 | QAction *action = new QAction(actionText, nullptr); | ||
742 | if (!info.iconName().isEmpty()) { | 772 | if (!info.iconName().isEmpty()) { | ||
743 | action->setIcon(QIcon::fromTheme(info.iconName())); | 773 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
744 | } | 774 | } | ||
745 | 775 | | |||
746 | if (choices) { | 776 | if (choices) { | ||
747 | choices->addAction(action); | 777 | choices->addAction(action); | ||
748 | } | 778 | } | ||
749 | dropActions << action; | 779 | m_dropActions << action; | ||
750 | actionsToWallpapers.insert(action, info.pluginId()); | 780 | actionsToWallpapers.insert(action, info.pluginId()); | ||
751 | const QUrl url = tjob->url(); | 781 | const QUrl url = tjob->url(); | ||
752 | connect(action, &QAction::triggered, this, [this, url]() { | 782 | connect(action, &QAction::triggered, this, [this, url]() { | ||
753 | //set wallpapery stuff | 783 | //set wallpapery stuff | ||
754 | if (m_wallpaperInterface && url.isValid()) { | 784 | if (m_wallpaperInterface && url.isValid()) { | ||
755 | m_wallpaperInterface->setUrl(url); | 785 | m_wallpaperInterface->setUrl(url); | ||
756 | } | 786 | } | ||
757 | }); | 787 | }); | ||
758 | } | 788 | } | ||
759 | } | 789 | } | ||
760 | | ||||
761 | } else { | 790 | } else { | ||
762 | //case in which we created the menu ourselves, just the "fetching type entry, directly create the icon applet | 791 | //case in which we created the menu ourselves, just the "fetching type entry, directly create the icon applet | ||
763 | if (choices) { | 792 | if (choices) { | ||
764 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | 793 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | ||
765 | setAppletArgs(applet, mimetype, tjob->url().toString()); | 794 | setAppletArgs(applet, mimetype, tjob->url().toString()); | ||
766 | } else { | 795 | } else { | ||
767 | QAction *action; | 796 | QAction *action; | ||
768 | if (choices) { | 797 | if (choices) { | ||
769 | choices->addSection(i18n("Widgets")); | 798 | choices->addSection(i18n("Widgets")); | ||
770 | action = choices->addAction(i18nc("Add icon widget", "Add Icon")); | 799 | action = choices->addAction(i18nc("Add icon widget", "Add Icon")); | ||
771 | } else { | 800 | } else { | ||
772 | QAction *sep = new QAction(i18n("Widgets"), nullptr); | 801 | QAction *sep = new QAction(i18n("Widgets"), nullptr); | ||
773 | sep->setSeparator(true); | 802 | sep->setSeparator(true); | ||
774 | dropActions << sep; | 803 | m_dropActions << sep; | ||
775 | // we can at least create an icon as a link to the URL | 804 | // we can at least create an icon as a link to the URL | ||
776 | action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | 805 | action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | ||
777 | dropActions << action; | 806 | m_dropActions << action; | ||
778 | } | 807 | } | ||
779 | 808 | | |||
780 | const QUrl url = tjob->url(); | 809 | const QUrl url = tjob->url(); | ||
781 | connect(action, &QAction::triggered, this, [this, posi, mimetype, url](){ | 810 | connect(action, &QAction::triggered, this, [this, posi, mimetype, url](){ | ||
782 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | 811 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | ||
783 | setAppletArgs(applet, mimetype, url.toString()); | 812 | setAppletArgs(applet, mimetype, url.toString()); | ||
784 | }); | 813 | }); | ||
785 | } | 814 | } | ||
786 | } | 815 | } | ||
787 | 816 | | |||
788 | if (choices) { | | |||
789 | // HACK If the QMenu becomes empty at any point after the "determining mimetype" | | |||
790 | // popup was shown, it self-destructs, does not matter if we call clear() or remove | | |||
791 | // the action manually, hence we remove the aforementioned item after we populated the menu | | |||
792 | choices->removeAction(choices->actions().at(0)); | | |||
793 | choices->exec(); | | |||
794 | } else { | | |||
795 | dropJob->setApplicationActions(dropActions); | | |||
796 | } | | |||
797 | | ||||
798 | clearDataForMimeJob(tjob); | 817 | clearDataForMimeJob(tjob); | ||
anthonyfieroni: Remove, don't leave commented code | |||||
799 | } | 818 | } | ||
800 | } | 819 | } | ||
801 | 820 | | |||
802 | void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) | 821 | void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) | ||
803 | { | 822 | { | ||
804 | if (!applet) { | 823 | if (!applet) { | ||
805 | return; | 824 | return; | ||
806 | } | 825 | } | ||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Line(s) | 1130 | if (!applet->failedToLaunch()) { | |||
1118 | if (configureApplet && configureApplet->isEnabled()) { | 1137 | if (configureApplet && configureApplet->isEnabled()) { | ||
1119 | desktopMenu->addAction(configureApplet); | 1138 | desktopMenu->addAction(configureApplet); | ||
1120 | } | 1139 | } | ||
1121 | QAction *appletAlternatives = applet->actions()->action(QStringLiteral("alternatives")); | 1140 | QAction *appletAlternatives = applet->actions()->action(QStringLiteral("alternatives")); | ||
1122 | if (appletAlternatives && appletAlternatives->isEnabled()) { | 1141 | if (appletAlternatives && appletAlternatives->isEnabled()) { | ||
1123 | desktopMenu->addAction(appletAlternatives); | 1142 | desktopMenu->addAction(appletAlternatives); | ||
1124 | } | 1143 | } | ||
1125 | } | 1144 | } | ||
1126 | | ||||
1127 | desktopMenu->addSeparator(); | 1145 | desktopMenu->addSeparator(); | ||
1146 | | ||||
1128 | if (m_containment->containmentType() == Plasma::Types::DesktopContainment) { | 1147 | if (m_containment->containmentType() == Plasma::Types::DesktopContainment) { | ||
1129 | auto action = m_containment->corona()->actions()->action(QStringLiteral("edit mode")); | 1148 | auto action = m_containment->corona()->actions()->action(QStringLiteral("edit mode")); | ||
1130 | if (action) { | 1149 | if (action) { | ||
1131 | desktopMenu->addAction(action); | 1150 | desktopMenu->addAction(action); | ||
1132 | } | 1151 | } | ||
1133 | } else { | 1152 | } else { | ||
1134 | addContainmentActions(desktopMenu, event); | 1153 | addContainmentActions(desktopMenu, event); | ||
1135 | } | 1154 | } | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
1196 | { | 1215 | { | ||
1197 | bool loading = AppletInterface::isLoading(); | 1216 | bool loading = AppletInterface::isLoading(); | ||
1198 | if (m_wallpaperInterface) { | 1217 | if (m_wallpaperInterface) { | ||
1199 | loading |= m_wallpaperInterface->isLoading(); | 1218 | loading |= m_wallpaperInterface->isLoading(); | ||
1200 | } | 1219 | } | ||
1201 | return loading; | 1220 | return loading; | ||
1202 | } | 1221 | } | ||
1203 | 1222 | | |||
1223 | void ContainmentInterface::showDropjobMenu(KIO::DropJob *dropJob, QPoint dropPos) { | ||||
1224 | dropJob->setApplicationActions(m_dropActions); | ||||
1225 | dropJob->showMenu(dropPos); | ||||
1226 | } | ||||
1204 | 1227 | | |||
1205 | #include "moc_containmentinterface.cpp" | 1228 | #include "moc_containmentinterface.cpp" |
can you be sure urls has at least 1 at this point?