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