Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/containmentinterface.cpp
Show All 15 Lines | |||||
16 | * You should have received a copy of the GNU Library General Public | 16 | * You should have received a copy of the GNU Library General Public | ||
17 | * License along with this program; if not, write to the | 17 | * License along with this program; if not, write to the | ||
18 | * Free Software Foundation, Inc., | 18 | * Free Software Foundation, Inc., | ||
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "containmentinterface.h" | 22 | #include "containmentinterface.h" | ||
23 | #include "wallpaperinterface.h" | 23 | #include "wallpaperinterface.h" | ||
24 | #include "dropmenu.h" | ||||
24 | #include <kdeclarative/qmlobject.h> | 25 | #include <kdeclarative/qmlobject.h> | ||
25 | 26 | | |||
26 | #include <QClipboard> | 27 | #include <QClipboard> | ||
27 | #include <QQmlExpression> | 28 | #include <QQmlExpression> | ||
28 | #include <QQmlProperty> | 29 | #include <QQmlProperty> | ||
29 | #include <QMimeData> | 30 | #include <QMimeData> | ||
30 | #include <QVersionNumber> | 31 | #include <QVersionNumber> | ||
31 | #include <QScreen> | 32 | #include <QScreen> | ||
33 | #include <QApplication> | ||||
32 | 34 | | |||
33 | #include <kactioncollection.h> | 35 | #include <kactioncollection.h> | ||
34 | #include <KAcceleratorManager> | 36 | #include <KAcceleratorManager> | ||
35 | #include <kauthorized.h> | 37 | #include <kauthorized.h> | ||
36 | #include <QDebug> | 38 | #include <QDebug> | ||
37 | #include <klocalizedstring.h> | 39 | #include <klocalizedstring.h> | ||
38 | #include <kurlmimedata.h> | 40 | #include <kurlmimedata.h> | ||
39 | #include <QMimeDatabase> | 41 | #include <QMimeDatabase> | ||
▲ Show 20 Lines • Show All 388 Lines • ▼ Show 20 Line(s) | |||||
428 | } | 430 | } | ||
429 | 431 | | |||
430 | void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y, KIO::DropJob *dropJob) | 432 | void ContainmentInterface::processMimeData(QMimeData *mimeData, int x, int y, KIO::DropJob *dropJob) | ||
431 | { | 433 | { | ||
432 | if (!mimeData) { | 434 | if (!mimeData) { | ||
433 | return; | 435 | return; | ||
434 | } | 436 | } | ||
435 | 437 | | |||
438 | if (m_dropMenu) { | ||||
439 | if (dropJob) { | ||||
440 | dropJob->kill(); | ||||
441 | } | ||||
442 | return; | ||||
443 | } | ||||
444 | m_dropMenu = QPointer<DropMenu>(new DropMenu(dropJob, QPoint(x, y), this)); | ||||
445 | if (dropJob) { | ||||
446 | dropJob->setParent(m_dropMenu); | ||||
447 | } | ||||
448 | | ||||
436 | //const QMimeData *mimeData = data; | 449 | //const QMimeData *mimeData = data; | ||
437 | 450 | | |||
438 | qDebug() << "Arrived mimeData" << mimeData->urls() << mimeData->formats() << "at" << x << ", " << y; | 451 | qDebug() << "Arrived mimeData" << mimeData->urls() << mimeData->formats() << "at" << x << ", " << y; | ||
439 | 452 | | |||
440 | // Catch drops from a Task Manager and convert to usable URL. | 453 | // Catch drops from a Task Manager and convert to usable URL. | ||
441 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | 454 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | ||
442 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | 455 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | ||
443 | mimeData->setUrls(urls); | 456 | mimeData->setUrls(urls); | ||
444 | } | 457 | } | ||
445 | 458 | | |||
446 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | 459 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | ||
447 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | 460 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | ||
448 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | 461 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||
449 | foreach (const QString &appletName, appletNames) { | 462 | foreach (const QString &appletName, appletNames) { | ||
450 | qDebug() << "adding" << appletName; | 463 | qDebug() << "adding" << appletName; | ||
451 | 464 | | |||
452 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | 465 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | ||
453 | } | 466 | } | ||
467 | delete m_dropMenu.data(); | ||||
454 | } else if (mimeData->hasUrls()) { | 468 | } else if (mimeData->hasUrls()) { | ||
455 | //TODO: collect the mimetypes of available script engines and offer | 469 | //TODO: collect the mimetypes of available script engines and offer | ||
456 | // to create widgets out of the matching URLs, if any | 470 | // to create widgets out of the matching URLs, if any | ||
457 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | 471 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | ||
458 | foreach (const QUrl &url, urls) { | 472 | m_dropMenu->setUrls(urls); | ||
473 | | ||||
474 | if (!urls.at(0).isLocalFile()) { | ||||
475 | QApplication::setOverrideCursor(Qt::WaitCursor); | ||||
476 | } | ||||
477 | | ||||
459 | QMimeDatabase db; | 478 | QMimeDatabase db; | ||
460 | const QMimeType &mime = db.mimeTypeForUrl(url); | 479 | QMimeType firstMimetype = db.mimeTypeForUrl(urls.at(0)); | ||
461 | QString mimeName = mime.name(); | 480 | foreach (const QUrl &url, urls) { | ||
462 | QVariantList args; | 481 | if (firstMimetype != db.mimeTypeForUrl(url)) { | ||
463 | args << url.url(); | 482 | m_dropMenu->setMultipleMimetypes(true); | ||
464 | qDebug() << "can decode" << mimeName << args; | 483 | break; | ||
484 | } | ||||
485 | } | ||||
465 | 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_dropMenu->urls().at(0), flags); | ||
469 | m_dropPoints[job] = QPoint(x, y); | 490 | job->setParent(m_dropMenu.data()); | ||
470 | 491 | | |||
471 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | 492 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | ||
472 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*,QString)), | 493 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*, QString)), | ||
473 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | 494 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | ||
474 | 495 | | |||
475 | if (dropJob) { | | |||
476 | m_dropJobs[job] = dropJob; | | |||
477 | } else { | 496 | } else { | ||
478 | QMenu *choices = new QMenu(i18n("Content dropped")); | 497 | bool deleteDropMenu = true; | ||
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; | | |||
486 | } | | |||
487 | } | | |||
488 | 498 | | |||
489 | } else { | | |||
490 | QStringList formats = mimeData->formats(); | 499 | QStringList formats = mimeData->formats(); | ||
491 | QHash<QString, KPluginMetaData> seenPlugins; | 500 | QHash<QString, KPluginMetaData> seenPlugins; | ||
492 | QHash<QString, QString> pluginFormats; | 501 | QHash<QString, QString> pluginFormats; | ||
493 | 502 | | |||
494 | foreach (const QString &format, formats) { | 503 | foreach (const QString &format, formats) { | ||
495 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | 504 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | ||
496 | 505 | | |||
497 | foreach (const auto &plugin, plugins) { | 506 | foreach (const auto &plugin, plugins) { | ||
498 | if (seenPlugins.contains(plugin.pluginId())) { | 507 | if (seenPlugins.contains(plugin.pluginId())) { | ||
499 | continue; | 508 | continue; | ||
500 | } | 509 | } | ||
501 | 510 | | |||
502 | seenPlugins.insert(plugin.pluginId(), plugin); | 511 | seenPlugins.insert(plugin.pluginId(), plugin); | ||
503 | pluginFormats.insert(plugin.pluginId(), format); | 512 | pluginFormats.insert(plugin.pluginId(), format); | ||
504 | } | 513 | } | ||
505 | } | 514 | } | ||
506 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | 515 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | ||
507 | 516 | | |||
508 | QString selectedPlugin; | 517 | QString selectedPlugin; | ||
509 | 518 | | |||
510 | if (seenPlugins.isEmpty()) { | 519 | if (seenPlugins.isEmpty()) { | ||
511 | // do nothing | 520 | //do nothing | ||
512 | //directly create if only one offer only if the containment didn't pass an existing plugin | 521 | //directly create if only one offer only if the containment didn't pass an existing plugin | ||
513 | } else if (seenPlugins.count() == 1) { | 522 | } else if (seenPlugins.count() == 1) { | ||
514 | selectedPlugin = seenPlugins.constBegin().key(); | 523 | selectedPlugin = seenPlugins.constBegin().key(); | ||
515 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | 524 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | ||
516 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | 525 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | ||
517 | } else { | 526 | } else { | ||
518 | QMenu *choices = nullptr; | | |||
519 | if (!dropJob) { | | |||
520 | choices = new QMenu(); | | |||
521 | if (choices->winId()) { | | |||
522 | choices->windowHandle()->setTransientParent(window()); | | |||
523 | } | | |||
524 | } | | |||
525 | QList<QAction *> extraActions; | | |||
526 | QHash<QAction *, QString> actionsToPlugins; | 527 | QHash<QAction *, QString> actionsToPlugins; | ||
527 | foreach (const auto &info, seenPlugins) { | 528 | foreach (const auto &info, seenPlugins) { | ||
528 | QAction *action; | 529 | QAction *action; | ||
529 | if (!info.iconName().isEmpty()) { | 530 | if (!info.iconName().isEmpty()) { | ||
530 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), nullptr); | 531 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), m_dropMenu); | ||
531 | } else { | 532 | } else { | ||
532 | action = new QAction(info.name(), nullptr); | 533 | action = new QAction(info.name(), m_dropMenu); | ||
533 | } | | |||
534 | extraActions << action; | | |||
535 | if (choices) { | | |||
536 | choices->addAction(action); | | |||
537 | } | 534 | } | ||
535 | m_dropMenu->addAction(action); | ||||
538 | action->setData(info.pluginId()); | 536 | action->setData(info.pluginId()); | ||
539 | connect(action, &QAction::triggered, this, [this, x, y, mimeData, action]() { | 537 | connect(action, &QAction::triggered, this, [this, x, y, mimeData, action]() { | ||
540 | const QString selectedPlugin = action->data().toString(); | 538 | const QString selectedPlugin = action->data().toString(); | ||
541 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | 539 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | ||
542 | setAppletArgs(applet, selectedPlugin, QString::fromUtf8(mimeData->data(selectedPlugin))); | 540 | setAppletArgs(applet, selectedPlugin, QString::fromUtf8(mimeData->data(selectedPlugin))); | ||
543 | }); | 541 | }); | ||
544 | 542 | | |||
545 | actionsToPlugins.insert(action, info.pluginId()); | 543 | actionsToPlugins.insert(action, info.pluginId()); | ||
546 | } | 544 | } | ||
547 | 545 | m_dropMenu->show(); | |||
548 | //if the menu was created by ourselves, delete it | 546 | deleteDropMenu = false; | ||
549 | if (choices) { | | |||
550 | QAction *choice = choices->exec(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | | |||
551 | | ||||
552 | delete choices; | | |||
553 | } else { | | |||
554 | Q_ASSERT(dropJob); | | |||
555 | dropJob->setApplicationActions(extraActions); | | |||
556 | } | 547 | } | ||
548 | | ||||
549 | if (deleteDropMenu) { | ||||
550 | // in case m_dropMenu has not been shown | ||||
551 | delete m_dropMenu.data(); | ||||
557 | } | 552 | } | ||
558 | } | 553 | } | ||
559 | } | 554 | } | ||
560 | 555 | | |||
561 | void ContainmentInterface::clearDataForMimeJob(KIO::Job *job) | 556 | void ContainmentInterface::clearDataForMimeJob(KIO::Job *job) | ||
562 | { | 557 | { | ||
563 | QObject::disconnect(job, nullptr, this, nullptr); | 558 | QObject::disconnect(job, nullptr, this, nullptr); | ||
564 | m_dropPoints.remove(job); | | |||
565 | QMenu *choices = m_dropMenus.take(job); | | |||
566 | m_dropJobs.remove(job); | | |||
567 | job->kill(); | 559 | job->kill(); | ||
560 | | ||||
561 | m_dropMenu->show(); | ||||
562 | | ||||
563 | if (!m_dropMenu->urls().at(0).isLocalFile()) { | ||||
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… | |||||
564 | QApplication::restoreOverrideCursor(); | ||||
565 | } | ||||
568 | } | 566 | } | ||
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 | 567 | | |||
570 | void ContainmentInterface::dropJobResult(KJob *job) | 568 | void ContainmentInterface::dropJobResult(KJob *job) | ||
571 | { | 569 | { | ||
572 | if (job->error()) { | 570 | if (job->error()) { | ||
573 | qDebug() << "ERROR" << job->error() << ' ' << job->errorString(); | 571 | qDebug() << "ERROR" << job->error() << ' ' << job->errorString(); | ||
572 | clearDataForMimeJob(dynamic_cast<KIO::Job *>(job)); | ||||
574 | } | 573 | } | ||
575 | } | 574 | } | ||
576 | 575 | | |||
577 | void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimetype) | 576 | void ContainmentInterface::mimeTypeRetrieved(KIO::Job *job, const QString &mimetype) | ||
578 | { | 577 | { | ||
579 | qDebug() << "Mimetype Job returns." << mimetype; | 578 | qDebug() << "Mimetype Job returns." << mimetype; | ||
580 | 579 | | |||
581 | KIO::TransferJob *tjob = dynamic_cast<KIO::TransferJob *>(job); | 580 | KIO::TransferJob *tjob = dynamic_cast<KIO::TransferJob *>(job); | ||
582 | if (!tjob) { | 581 | if (!tjob) { | ||
583 | qDebug() << "job should be a TransferJob, but isn't"; | 582 | qDebug() << "job should be a TransferJob, but isn't"; | ||
584 | clearDataForMimeJob(job); | 583 | clearDataForMimeJob(job); | ||
585 | return; | 584 | return; | ||
586 | } | 585 | } | ||
586 | | ||||
587 | QList<KPluginMetaData> appletList = Plasma::PluginLoader::self()->listAppletMetaDataForUrl(tjob->url()); | 587 | QList<KPluginMetaData> appletList = Plasma::PluginLoader::self()->listAppletMetaDataForUrl(tjob->url()); | ||
588 | if (mimetype.isEmpty() && appletList.isEmpty()) { | 588 | if (mimetype.isEmpty() && appletList.isEmpty()) { | ||
589 | clearDataForMimeJob(job); | 589 | clearDataForMimeJob(job); | ||
590 | qDebug() << "No applets found matching the url (" << tjob->url() << ") or the mimetype (" << mimetype << ")"; | 590 | qDebug() << "No applets found matching the url (" << tjob->url() << ") or the mimetype (" << mimetype << ")"; | ||
591 | return; | 591 | return; | ||
592 | } else { | 592 | } else { | ||
593 | 593 | | |||
594 | QPoint posi; // will be overwritten with the event's position | 594 | qDebug() << "Received a suitable dropEvent at " << m_dropMenu->dropPoint(); | ||
595 | if (m_dropPoints.contains(tjob)) { | | |||
596 | posi = m_dropPoints.value(tjob); | | |||
597 | qDebug() << "Received a suitable dropEvent at" << posi; | | |||
598 | } else { | | |||
599 | qDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob"; | 595 | qDebug() << "Bailing out. Cannot find associated dropEvent related to the TransferJob"; | ||
600 | clearDataForMimeJob(job); | | |||
601 | return; | | |||
602 | } | | |||
603 | | ||||
604 | QMenu *choices = m_dropMenus.value(tjob); | | |||
605 | QList<QAction *> dropActions; | | |||
606 | KIO::DropJob *dropJob = m_dropJobs.value(tjob); | | |||
607 | | ||||
608 | if (!choices && !dropJob) { | | |||
609 | qDebug() << "Bailing out. No QMenu or drop job found for this job."; | | |||
610 | clearDataForMimeJob(job); | | |||
611 | return; | | |||
612 | } | | |||
613 | 596 | | |||
614 | qDebug() << "Creating menu for:" << mimetype << posi; | 597 | qDebug() << "Creating menu for: " << mimetype; | ||
615 | 598 | | |||
616 | appletList << Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(mimetype); | 599 | appletList << Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(mimetype); | ||
617 | 600 | | |||
618 | QList<KPluginMetaData> wallpaperList; | 601 | QList<KPluginMetaData> wallpaperList; | ||
619 | 602 | | |||
620 | if (m_containment->containmentType() != Plasma::Types::PanelContainment | 603 | if (m_containment->containmentType() != Plasma::Types::PanelContainment | ||
621 | && m_containment->containmentType() != Plasma::Types::CustomPanelContainment) { | 604 | && m_containment->containmentType() != Plasma::Types::CustomPanelContainment) { | ||
622 | 605 | | |||
623 | if (m_wallpaperInterface && m_wallpaperInterface->supportsMimetype(mimetype)) { | 606 | if (m_wallpaperInterface && m_wallpaperInterface->supportsMimetype(mimetype)) { | ||
624 | wallpaperList << m_wallpaperInterface->kPackage().metadata(); | 607 | wallpaperList << m_wallpaperInterface->kPackage().metadata(); | ||
625 | } else { | 608 | } else { | ||
626 | wallpaperList = WallpaperInterface::listWallpaperMetadataForMimetype(mimetype); | 609 | wallpaperList = WallpaperInterface::listWallpaperMetadataForMimetype(mimetype); | ||
627 | } | 610 | } | ||
628 | } | 611 | } | ||
629 | 612 | | |||
630 | const bool isPlasmaPackage = (mimetype == QLatin1String("application/x-plasma")); | 613 | const bool isPlasmaPackage = (mimetype == QLatin1String("application/x-plasma")); | ||
631 | 614 | | |||
632 | if (!appletList.isEmpty() || !wallpaperList.isEmpty() || isPlasmaPackage) { | 615 | if ((!appletList.isEmpty() || !wallpaperList.isEmpty() || isPlasmaPackage) && !m_dropMenu->isMultipleMimetypes()) { | ||
633 | QAction *installPlasmaPackageAction = nullptr; | 616 | QAction *installPlasmaPackageAction = nullptr; | ||
634 | if (isPlasmaPackage) { | 617 | if (isPlasmaPackage) { | ||
635 | if (choices) { | 618 | QAction *action = new QAction(i18n("Plasma Package"), m_dropMenu); | ||
636 | choices->addSection(i18n("Plasma Package")); | | |||
637 | installPlasmaPackageAction = choices->addAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install")); | | |||
638 | } else { | | |||
639 | QAction *action = new QAction(i18n("Plasma Package"), nullptr); | | |||
640 | action->setSeparator(true); | 619 | action->setSeparator(true); | ||
641 | dropActions << action; | 620 | m_dropMenu->addAction(action); | ||
621 | | ||||
622 | installPlasmaPackageAction = new QAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install"), m_dropMenu); | ||||
623 | m_dropMenu->addAction(installPlasmaPackageAction); | ||||
642 | 624 | | |||
643 | installPlasmaPackageAction = new QAction(QIcon::fromTheme(QStringLiteral("application-x-plasma")), i18n("Install"), nullptr); | | |||
644 | Q_ASSERT(dropJob); | | |||
645 | dropActions << installPlasmaPackageAction; | | |||
646 | dropJob->setApplicationActions(dropActions); | | |||
647 | } | | |||
648 | const QString &packagePath = tjob->url().toLocalFile(); | 625 | const QString &packagePath = tjob->url().toLocalFile(); | ||
649 | connect(installPlasmaPackageAction, &QAction::triggered, this, [this, posi, packagePath]() { | 626 | connect(installPlasmaPackageAction, &QAction::triggered, this, [this, packagePath]() { | ||
650 | using namespace KPackage; | 627 | using namespace KPackage; | ||
651 | PackageStructure *structure = PackageLoader::self()->loadPackageStructure(QStringLiteral("Plasma/Applet")); | 628 | PackageStructure *structure = PackageLoader::self()->loadPackageStructure(QStringLiteral("Plasma/Applet")); | ||
652 | Package package(structure); | 629 | Package package(structure); | ||
653 | 630 | | |||
654 | KJob *installJob = package.update(packagePath); | 631 | KJob *installJob = package.update(packagePath); | ||
655 | connect(installJob, &KJob::result, this, [this, packagePath, structure, posi](KJob *job) { | 632 | connect(installJob, &KJob::result, this, [this, packagePath, structure](KJob *job) { | ||
656 | auto fail = [](const QString &text) { | 633 | auto fail = [](const QString &text) { | ||
657 | KNotification::event(QStringLiteral("plasmoidInstallationFailed"), i18n("Package Installation Failed"), | 634 | KNotification::event(QStringLiteral("plasmoidInstallationFailed"), i18n("Package Installation Failed"), | ||
658 | text, QStringLiteral("dialog-error"), nullptr, KNotification::CloseOnTimeout, QStringLiteral("plasma_workspace")); | 635 | text, QStringLiteral("dialog-error"), nullptr, KNotification::CloseOnTimeout, QStringLiteral("plasma_workspace")); | ||
659 | }; | 636 | }; | ||
660 | 637 | | |||
661 | // if the applet is already installed, just add it to the containment | 638 | // if the applet is already installed, just add it to the containment | ||
662 | if (job->error() != KJob::NoError | 639 | if (job->error() != KJob::NoError | ||
663 | && job->error() != Package::PackageAlreadyInstalledError | 640 | && job->error() != Package::PackageAlreadyInstalledError | ||
Show All 9 Lines | |||||
673 | package.setPath(packagePath); | 650 | package.setPath(packagePath); | ||
674 | 651 | | |||
675 | // TODO how can I get the plugin id? Package::metadata() is deprecated | 652 | // TODO how can I get the plugin id? Package::metadata() is deprecated | ||
676 | if (!package.isValid() || !package.metadata().isValid()) { | 653 | if (!package.isValid() || !package.metadata().isValid()) { | ||
677 | fail(i18n("The package you just dropped is invalid.")); | 654 | fail(i18n("The package you just dropped is invalid.")); | ||
678 | return; | 655 | return; | ||
679 | } | 656 | } | ||
680 | 657 | | |||
681 | createApplet(package.metadata().pluginId(), QVariantList(), QRect(posi, QSize(-1,-1))); | 658 | createApplet(package.metadata().pluginId(), QVariantList(), QRect(m_dropMenu->dropPoint(), QSize(-1,-1))); | ||
682 | }); | 659 | }); | ||
683 | }); | 660 | }); | ||
684 | } | 661 | } | ||
685 | 662 | | |||
686 | if (choices) { | 663 | QAction *action = new QAction(i18n("Widgets"), m_dropMenu); | ||
687 | choices->addSection(i18n("Widgets")); | | |||
688 | } else { | | |||
689 | QAction *action = new QAction(i18n("Widgets"), nullptr); | | |||
690 | action->setSeparator(true); | 664 | action->setSeparator(true); | ||
691 | dropActions << action; | 665 | m_dropMenu->addAction(action); | ||
692 | } | 666 | | ||
693 | foreach (const auto &info, appletList) { | 667 | foreach (const auto &info, appletList) { | ||
694 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | 668 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | ||
695 | QAction *action = new QAction(actionText, nullptr); | 669 | QAction *action = new QAction(actionText, m_dropMenu); | ||
696 | if (!info.iconName().isEmpty()) { | 670 | if (!info.iconName().isEmpty()) { | ||
697 | action->setIcon(QIcon::fromTheme(info.iconName())); | 671 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
698 | } | 672 | } | ||
699 | if (choices) { | 673 | m_dropMenu->addAction(action); | ||
700 | choices->addAction(action); | | |||
701 | } | | |||
702 | dropActions << action; | | |||
703 | action->setData(info.pluginId()); | 674 | action->setData(info.pluginId()); | ||
704 | const QUrl url = tjob->url(); | 675 | const QUrl url = tjob->url(); | ||
705 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url]() { | 676 | connect(action, &QAction::triggered, this, [this, action, mimetype, url]() { | ||
706 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | 677 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(m_dropMenu->dropPoint(), QSize(-1,-1))); | ||
707 | setAppletArgs(applet, mimetype, url.toString()); | 678 | setAppletArgs(applet, mimetype, url.toString()); | ||
708 | }); | 679 | }); | ||
709 | } | 680 | } | ||
710 | { | 681 | { | ||
711 | QAction *action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | 682 | QAction *action = new QAction(i18nc("Add icon widget", "Add Icon"), m_dropMenu); | ||
712 | if (choices) { | 683 | m_dropMenu->addAction(action); | ||
713 | choices->addAction(action); | | |||
714 | } | | |||
715 | dropActions << action; | | |||
716 | action->setData(QStringLiteral("org.kde.plasma.icon")); | 684 | action->setData(QStringLiteral("org.kde.plasma.icon")); | ||
717 | const QUrl url = tjob->url(); | 685 | const QUrl url = tjob->url(); | ||
718 | connect(action, &QAction::triggered, this, [this, action, posi, mimetype, url](){ | 686 | connect(action, &QAction::triggered, this, [this, action, mimetype, url](){ | ||
719 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(posi, QSize(-1,-1))); | 687 | Plasma::Applet *applet = createApplet(action->data().toString(), QVariantList(), QRect(m_dropMenu->dropPoint(), QSize(-1,-1))); | ||
720 | setAppletArgs(applet, mimetype, url.toString()); | 688 | setAppletArgs(applet, mimetype, url.toString()); | ||
721 | }); | 689 | }); | ||
722 | } | 690 | } | ||
723 | 691 | | |||
724 | QHash<QAction *, QString> actionsToWallpapers; | 692 | QHash<QAction *, QString> actionsToWallpapers; | ||
725 | if (!wallpaperList.isEmpty()) { | 693 | if (!wallpaperList.isEmpty()) { | ||
726 | if (choices) { | 694 | QAction *action = new QAction(i18n("Wallpaper"), m_dropMenu); | ||
727 | choices->addSection(i18n("Wallpaper")); | | |||
728 | } else { | | |||
729 | QAction *action = new QAction(i18n("Wallpaper"), nullptr); | | |||
730 | action->setSeparator(true); | 695 | action->setSeparator(true); | ||
731 | dropActions << action; | 696 | m_dropMenu->addAction(action); | ||
732 | } | | |||
733 | 697 | | |||
734 | QMap<QString, KPluginMetaData> sorted; | 698 | QMap<QString, KPluginMetaData> sorted; | ||
735 | foreach (const auto &info, appletList) { | 699 | foreach (const auto &info, appletList) { | ||
736 | sorted.insert(info.name(), info); | 700 | sorted.insert(info.name(), info); | ||
737 | } | 701 | } | ||
738 | 702 | | |||
739 | foreach (const KPluginMetaData &info, wallpaperList) { | 703 | foreach (const KPluginMetaData &info, wallpaperList) { | ||
740 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | 704 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | ||
741 | QAction *action = new QAction(actionText, nullptr); | 705 | QAction *action = new QAction(actionText, m_dropMenu); | ||
742 | if (!info.iconName().isEmpty()) { | 706 | if (!info.iconName().isEmpty()) { | ||
743 | action->setIcon(QIcon::fromTheme(info.iconName())); | 707 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
744 | } | 708 | } | ||
745 | 709 | m_dropMenu->addAction(action); | |||
746 | if (choices) { | | |||
747 | choices->addAction(action); | | |||
748 | } | | |||
749 | dropActions << action; | | |||
750 | actionsToWallpapers.insert(action, info.pluginId()); | 710 | actionsToWallpapers.insert(action, info.pluginId()); | ||
751 | const QUrl url = tjob->url(); | 711 | const QUrl url = tjob->url(); | ||
752 | connect(action, &QAction::triggered, this, [this, url]() { | 712 | connect(action, &QAction::triggered, this, [this, url]() { | ||
753 | //set wallpapery stuff | 713 | //set wallpapery stuff | ||
754 | if (m_wallpaperInterface && url.isValid()) { | 714 | if (m_wallpaperInterface && url.isValid()) { | ||
755 | m_wallpaperInterface->setUrl(url); | 715 | m_wallpaperInterface->setUrl(url); | ||
756 | } | 716 | } | ||
757 | }); | 717 | }); | ||
758 | } | 718 | } | ||
759 | } | 719 | } | ||
760 | | ||||
761 | } else { | 720 | } else { | ||
762 | //case in which we created the menu ourselves, just the "fetching type entry, directly create the icon applet | 721 | //case in which we created the menu ourselves, just the "fetching type entry, directly create the icon applet | ||
763 | if (choices) { | 722 | if (!m_dropMenu->isDropjobMenu()) { | ||
764 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | 723 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(m_dropMenu->dropPoint(), QSize(-1,-1))); | ||
765 | setAppletArgs(applet, mimetype, tjob->url().toString()); | 724 | setAppletArgs(applet, mimetype, tjob->url().toString()); | ||
766 | } else { | 725 | } else { | ||
767 | QAction *action; | 726 | QAction *action; | ||
768 | if (choices) { | 727 | QAction *sep = new QAction(i18n("Widgets"), m_dropMenu); | ||
769 | choices->addSection(i18n("Widgets")); | | |||
770 | action = choices->addAction(i18nc("Add icon widget", "Add Icon")); | | |||
771 | } else { | | |||
772 | QAction *sep = new QAction(i18n("Widgets"), nullptr); | | |||
773 | sep->setSeparator(true); | 728 | sep->setSeparator(true); | ||
774 | dropActions << sep; | 729 | m_dropMenu->addAction(sep); | ||
775 | // we can at least create an icon as a link to the URL | 730 | // we can at least create an icon as a link to the URL | ||
776 | action = new QAction(i18nc("Add icon widget", "Add Icon"), nullptr); | 731 | action = new QAction(i18nc("Add icon widget", "Add Icon"), m_dropMenu); | ||
777 | dropActions << action; | 732 | m_dropMenu->addAction(action); | ||
778 | } | | |||
779 | 733 | | |||
780 | const QUrl url = tjob->url(); | 734 | const QUrl url = tjob->url(); | ||
781 | connect(action, &QAction::triggered, this, [this, posi, mimetype, url](){ | 735 | connect(action, &QAction::triggered, this, [this, mimetype, url](){ | ||
782 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(posi, QSize(-1,-1))); | 736 | Plasma::Applet *applet = createApplet(QStringLiteral("org.kde.plasma.icon"), QVariantList(), QRect(m_dropMenu->dropPoint(), QSize(-1,-1))); | ||
783 | setAppletArgs(applet, mimetype, url.toString()); | 737 | setAppletArgs(applet, mimetype, url.toString()); | ||
784 | }); | 738 | }); | ||
785 | } | 739 | } | ||
786 | } | 740 | } | ||
787 | | ||||
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); | 741 | clearDataForMimeJob(tjob); | ||
anthonyfieroni: Remove, don't leave commented code | |||||
799 | } | 742 | } | ||
800 | } | 743 | } | ||
801 | 744 | | |||
802 | void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) | 745 | void ContainmentInterface::appletAddedForward(Plasma::Applet *applet) | ||
803 | { | 746 | { | ||
804 | if (!applet) { | 747 | if (!applet) { | ||
805 | return; | 748 | return; | ||
806 | } | 749 | } | ||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Line(s) | 1054 | if (!applet->failedToLaunch()) { | |||
1118 | if (configureApplet && configureApplet->isEnabled()) { | 1061 | if (configureApplet && configureApplet->isEnabled()) { | ||
1119 | desktopMenu->addAction(configureApplet); | 1062 | desktopMenu->addAction(configureApplet); | ||
1120 | } | 1063 | } | ||
1121 | QAction *appletAlternatives = applet->actions()->action(QStringLiteral("alternatives")); | 1064 | QAction *appletAlternatives = applet->actions()->action(QStringLiteral("alternatives")); | ||
1122 | if (appletAlternatives && appletAlternatives->isEnabled()) { | 1065 | if (appletAlternatives && appletAlternatives->isEnabled()) { | ||
1123 | desktopMenu->addAction(appletAlternatives); | 1066 | desktopMenu->addAction(appletAlternatives); | ||
1124 | } | 1067 | } | ||
1125 | } | 1068 | } | ||
1126 | | ||||
1127 | desktopMenu->addSeparator(); | 1069 | desktopMenu->addSeparator(); | ||
1070 | | ||||
1128 | if (m_containment->containmentType() == Plasma::Types::DesktopContainment) { | 1071 | if (m_containment->containmentType() == Plasma::Types::DesktopContainment) { | ||
1129 | auto action = m_containment->corona()->actions()->action(QStringLiteral("edit mode")); | 1072 | auto action = m_containment->corona()->actions()->action(QStringLiteral("edit mode")); | ||
1130 | if (action) { | 1073 | if (action) { | ||
1131 | desktopMenu->addAction(action); | 1074 | desktopMenu->addAction(action); | ||
1132 | } | 1075 | } | ||
1133 | } else { | 1076 | } else { | ||
1134 | addContainmentActions(desktopMenu, event); | 1077 | addContainmentActions(desktopMenu, event); | ||
1135 | } | 1078 | } | ||
▲ Show 20 Lines • Show All 70 Lines • Show Last 20 Lines |
can you be sure urls has at least 1 at this point?