Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/containmentinterface.cpp
Show First 20 Lines • Show All 229 Lines • ▼ Show 20 Line(s) | 224 | { | |||
---|---|---|---|---|---|
230 | if (appletInterface) { | 230 | if (appletInterface) { | ||
231 | emit appletInterface->externalData(mimetype, data); | 231 | emit appletInterface->externalData(mimetype, data); | ||
232 | } | 232 | } | ||
233 | } | 233 | } | ||
234 | 234 | | |||
235 | QObject *ContainmentInterface::containmentAt(int x, int y) | 235 | QObject *ContainmentInterface::containmentAt(int x, int y) | ||
236 | { | 236 | { | ||
237 | QObject *desktop = nullptr; | 237 | QObject *desktop = nullptr; | ||
238 | foreach (Plasma::Containment *c, m_containment->corona()->containments()) { | 238 | const auto lst = m_containment->corona()->containments(); | ||
239 | for (Plasma::Containment *c : lst) { | ||||
239 | ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value<ContainmentInterface *>(); | 240 | ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value<ContainmentInterface *>(); | ||
240 | 241 | | |||
241 | if (contInterface && contInterface->isVisible()) { | 242 | if (contInterface && contInterface->isVisible()) { | ||
242 | QWindow *w = contInterface->window(); | 243 | QWindow *w = contInterface->window(); | ||
243 | if (w && w->geometry().contains(QPoint(window()->x(), window()->y()) + QPoint(x, y))) { | 244 | if (w && w->geometry().contains(QPoint(window()->x(), window()->y()) + QPoint(x, y))) { | ||
244 | if (c->containmentType() == Plasma::Types::CustomEmbeddedContainment) { | 245 | if (c->containmentType() == Plasma::Types::CustomEmbeddedContainment) { | ||
245 | continue; | 246 | continue; | ||
246 | } | 247 | } | ||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Line(s) | 434 | { | |||
454 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | 455 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | ||
455 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | 456 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | ||
456 | mimeData->setUrls(urls); | 457 | mimeData->setUrls(urls); | ||
457 | } | 458 | } | ||
458 | 459 | | |||
459 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | 460 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | ||
460 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | 461 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | ||
461 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | 462 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||
462 | foreach (const QString &appletName, appletNames) { | 463 | for (const QString &appletName : appletNames) { | ||
463 | qDebug() << "adding" << appletName; | 464 | qDebug() << "adding" << appletName; | ||
464 | 465 | | |||
465 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | 466 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | ||
466 | } | 467 | } | ||
467 | delete m_dropMenu.data(); | 468 | delete m_dropMenu.data(); | ||
468 | } else if (mimeData->hasUrls()) { | 469 | } else if (mimeData->hasUrls()) { | ||
469 | //TODO: collect the mimetypes of available script engines and offer | 470 | //TODO: collect the mimetypes of available script engines and offer | ||
470 | // to create widgets out of the matching URLs, if any | 471 | // to create widgets out of the matching URLs, if any | ||
Show All 20 Lines | |||||
491 | 492 | | |||
492 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | 493 | QObject::connect(job, &KJob::result, this, &ContainmentInterface::dropJobResult); | ||
493 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*, QString)), | 494 | QObject::connect(job, SIGNAL(mimetype(KIO::Job*, QString)), | ||
494 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | 495 | this, SLOT(mimeTypeRetrieved(KIO::Job*,QString))); | ||
495 | 496 | | |||
496 | } else { | 497 | } else { | ||
497 | bool deleteDropMenu = true; | 498 | bool deleteDropMenu = true; | ||
498 | 499 | | |||
499 | QStringList formats = mimeData->formats(); | 500 | const QStringList formats = mimeData->formats(); | ||
500 | QHash<QString, KPluginMetaData> seenPlugins; | 501 | QHash<QString, KPluginMetaData> seenPlugins; | ||
501 | QHash<QString, QString> pluginFormats; | 502 | QHash<QString, QString> pluginFormats; | ||
502 | 503 | | |||
503 | foreach (const QString &format, formats) { | 504 | for (const QString &format : formats) { | ||
504 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | 505 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | ||
505 | 506 | | |||
506 | foreach (const auto &plugin, plugins) { | 507 | for (const auto &plugin : plugins) { | ||
507 | if (seenPlugins.contains(plugin.pluginId())) { | 508 | if (seenPlugins.contains(plugin.pluginId())) { | ||
508 | continue; | 509 | continue; | ||
509 | } | 510 | } | ||
510 | 511 | | |||
511 | seenPlugins.insert(plugin.pluginId(), plugin); | 512 | seenPlugins.insert(plugin.pluginId(), plugin); | ||
512 | pluginFormats.insert(plugin.pluginId(), format); | 513 | pluginFormats.insert(plugin.pluginId(), format); | ||
513 | } | 514 | } | ||
514 | } | 515 | } | ||
515 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | 516 | //qDebug() << "Mimetype ..." << formats << seenPlugins.keys() << pluginFormats.values(); | ||
516 | 517 | | |||
517 | QString selectedPlugin; | 518 | QString selectedPlugin; | ||
518 | 519 | | |||
519 | if (seenPlugins.isEmpty()) { | 520 | if (seenPlugins.isEmpty()) { | ||
520 | //do nothing | 521 | //do nothing | ||
521 | //directly create if only one offer only if the containment didn't pass an existing plugin | 522 | //directly create if only one offer only if the containment didn't pass an existing plugin | ||
522 | } else if (seenPlugins.count() == 1) { | 523 | } else if (seenPlugins.count() == 1) { | ||
523 | selectedPlugin = seenPlugins.constBegin().key(); | 524 | selectedPlugin = seenPlugins.constBegin().key(); | ||
524 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | 525 | Plasma::Applet *applet = createApplet(selectedPlugin, QVariantList(), QRect(x, y, -1, -1)); | ||
525 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | 526 | setAppletArgs(applet, pluginFormats[selectedPlugin], QString::fromUtf8(mimeData->data(pluginFormats[selectedPlugin]))); | ||
526 | } else { | 527 | } else { | ||
527 | QHash<QAction *, QString> actionsToPlugins; | 528 | QHash<QAction *, QString> actionsToPlugins; | ||
528 | foreach (const auto &info, seenPlugins) { | 529 | for (const auto &info : qAsConst(seenPlugins)) { | ||
529 | QAction *action; | 530 | QAction *action; | ||
530 | if (!info.iconName().isEmpty()) { | 531 | if (!info.iconName().isEmpty()) { | ||
531 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), m_dropMenu); | 532 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), m_dropMenu); | ||
532 | } else { | 533 | } else { | ||
533 | action = new QAction(info.name(), m_dropMenu); | 534 | action = new QAction(info.name(), m_dropMenu); | ||
534 | } | 535 | } | ||
535 | m_dropMenu->addAction(action); | 536 | m_dropMenu->addAction(action); | ||
536 | action->setData(info.pluginId()); | 537 | action->setData(info.pluginId()); | ||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 627 | connect(installPlasmaPackageAction, &QAction::triggered, this, [this, packagePath]() { | |||
659 | }); | 660 | }); | ||
660 | }); | 661 | }); | ||
661 | } | 662 | } | ||
662 | 663 | | |||
663 | QAction *action = new QAction(i18n("Widgets"), m_dropMenu); | 664 | QAction *action = new QAction(i18n("Widgets"), m_dropMenu); | ||
664 | action->setSeparator(true); | 665 | action->setSeparator(true); | ||
665 | m_dropMenu->addAction(action); | 666 | m_dropMenu->addAction(action); | ||
666 | 667 | | |||
667 | foreach (const auto &info, appletList) { | 668 | for (const auto &info : qAsConst(appletList)) { | ||
668 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | 669 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | ||
669 | QAction *action = new QAction(actionText, m_dropMenu); | 670 | QAction *action = new QAction(actionText, m_dropMenu); | ||
670 | if (!info.iconName().isEmpty()) { | 671 | if (!info.iconName().isEmpty()) { | ||
671 | action->setIcon(QIcon::fromTheme(info.iconName())); | 672 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
672 | } | 673 | } | ||
673 | m_dropMenu->addAction(action); | 674 | m_dropMenu->addAction(action); | ||
674 | action->setData(info.pluginId()); | 675 | action->setData(info.pluginId()); | ||
675 | const QUrl url = tjob->url(); | 676 | const QUrl url = tjob->url(); | ||
Show All 15 Lines | |||||
691 | 692 | | |||
692 | QHash<QAction *, QString> actionsToWallpapers; | 693 | QHash<QAction *, QString> actionsToWallpapers; | ||
693 | if (!wallpaperList.isEmpty()) { | 694 | if (!wallpaperList.isEmpty()) { | ||
694 | QAction *action = new QAction(i18n("Wallpaper"), m_dropMenu); | 695 | QAction *action = new QAction(i18n("Wallpaper"), m_dropMenu); | ||
695 | action->setSeparator(true); | 696 | action->setSeparator(true); | ||
696 | m_dropMenu->addAction(action); | 697 | m_dropMenu->addAction(action); | ||
697 | 698 | | |||
698 | QMap<QString, KPluginMetaData> sorted; | 699 | QMap<QString, KPluginMetaData> sorted; | ||
699 | foreach (const auto &info, appletList) { | 700 | for (const auto &info : qAsConst(appletList)) { | ||
700 | sorted.insert(info.name(), info); | 701 | sorted.insert(info.name(), info); | ||
701 | } | 702 | } | ||
702 | 703 | | |||
703 | foreach (const KPluginMetaData &info, wallpaperList) { | 704 | for (const KPluginMetaData &info : qAsConst(wallpaperList)) { | ||
704 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | 705 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | ||
705 | QAction *action = new QAction(actionText, m_dropMenu); | 706 | QAction *action = new QAction(actionText, m_dropMenu); | ||
706 | if (!info.iconName().isEmpty()) { | 707 | if (!info.iconName().isEmpty()) { | ||
707 | action->setIcon(QIcon::fromTheme(info.iconName())); | 708 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
708 | } | 709 | } | ||
709 | m_dropMenu->addAction(action); | 710 | m_dropMenu->addAction(action); | ||
710 | actionsToWallpapers.insert(action, info.pluginId()); | 711 | actionsToWallpapers.insert(action, info.pluginId()); | ||
711 | const QUrl url = tjob->url(); | 712 | const QUrl url = tjob->url(); | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 831 | { | |||
831 | //FIXME: giving directly a QList<QAction*> crashes | 832 | //FIXME: giving directly a QList<QAction*> crashes | ||
832 | 833 | | |||
833 | QStringList actionOrder; | 834 | QStringList actionOrder; | ||
834 | actionOrder << QStringLiteral("add widgets") << QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("run associated application") << QStringLiteral("configure"); | 835 | actionOrder << QStringLiteral("add widgets") << QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("run associated application") << QStringLiteral("configure"); | ||
835 | QHash<QString, QAction *> orderedActions; | 836 | QHash<QString, QAction *> orderedActions; | ||
836 | //use a multimap to sort by action type | 837 | //use a multimap to sort by action type | ||
837 | QMultiMap<int, QObject *> actions; | 838 | QMultiMap<int, QObject *> actions; | ||
838 | int i = 0; | 839 | int i = 0; | ||
839 | foreach (QAction *a, m_containment->actions()->actions()) { | 840 | auto listActions = m_containment->actions()->actions(); | ||
841 | for (QAction *a : qAsConst(listActions)) { | ||||
840 | if (!actionOrder.contains(a->objectName())) { | 842 | if (!actionOrder.contains(a->objectName())) { | ||
841 | //FIXME QML visualizations don't support menus for now, *and* there is no way to | 843 | //FIXME QML visualizations don't support menus for now, *and* there is no way to | ||
842 | //distinguish them on QML side | 844 | //distinguish them on QML side | ||
843 | if (!a->menu()) { | 845 | if (!a->menu()) { | ||
844 | actions.insert(a->data().toInt()*100 + i, a); | 846 | actions.insert(a->data().toInt()*100 + i, a); | ||
845 | ++i; | 847 | ++i; | ||
846 | } | 848 | } | ||
847 | } else { | 849 | } else { | ||
848 | orderedActions[a->objectName()] = a; | 850 | orderedActions[a->objectName()] = a; | ||
849 | } | 851 | } | ||
850 | } | 852 | } | ||
851 | 853 | | |||
852 | i = 0; | 854 | i = 0; | ||
853 | foreach (QAction *a, m_containment->corona()->actions()->actions()) { | 855 | listActions = m_containment->corona()->actions()->actions(); | ||
854 | if (a->objectName() == QLatin1String("lock widgets") || a->menu()) { | 856 | for (QAction *a : qAsConst(listActions)) { | ||
857 | if (a->objectName() == QStringLiteral("lock widgets") || a->menu()) { | ||||
ahmadsamir: QLatin1String | |||||
855 | //It is up to the Containment to decide if the user is allowed or not | 858 | //It is up to the Containment to decide if the user is allowed or not | ||
856 | //to lock/unluck the widgets, so corona should not add one when there is none | 859 | //to lock/unluck the widgets, so corona should not add one when there is none | ||
857 | //(user is not allow) and it shouldn't add another one when there is already | 860 | //(user is not allow) and it shouldn't add another one when there is already | ||
858 | //one | 861 | //one | ||
859 | continue; | 862 | continue; | ||
860 | } | 863 | } | ||
861 | 864 | | |||
862 | if (!actionOrder.contains(a->objectName())) { | 865 | if (!actionOrder.contains(a->objectName())) { | ||
863 | actions.insert(a->data().toInt()*100 + i, a); | 866 | actions.insert(a->data().toInt()*100 + i, a); | ||
864 | } else { | 867 | } else { | ||
865 | orderedActions[a->objectName()] = a; | 868 | orderedActions[a->objectName()] = a; | ||
866 | } | 869 | } | ||
867 | ++i; | 870 | ++i; | ||
868 | } | 871 | } | ||
869 | QList<QObject *> actionList = actions.values(); | 872 | QList<QObject *> actionList = actions.values(); | ||
870 | 873 | | |||
871 | foreach (const QString &name, actionOrder) { | 874 | for (const QString &name : qAsConst(actionOrder)) { | ||
872 | QAction *a = orderedActions.value(name); | 875 | QAction *a = orderedActions.value(name); | ||
873 | if (a && !a->menu()) { | 876 | if (a && !a->menu()) { | ||
874 | actionList << a; | 877 | actionList << a; | ||
875 | } | 878 | } | ||
876 | ++i; | 879 | ++i; | ||
877 | } | 880 | } | ||
878 | 881 | | |||
879 | return actionList; | 882 | return actionList; | ||
Show All 32 Lines | 913 | if (plugin->contextualActions().length() == 1) { | |||
912 | action->setData(event->pos()); | 915 | action->setData(event->pos()); | ||
913 | action->trigger(); | 916 | action->trigger(); | ||
914 | event->accept(); | 917 | event->accept(); | ||
915 | return; | 918 | return; | ||
916 | } | 919 | } | ||
917 | 920 | | |||
918 | //FIXME: very inefficient appletAt() implementation | 921 | //FIXME: very inefficient appletAt() implementation | ||
919 | Plasma::Applet *applet = nullptr; | 922 | Plasma::Applet *applet = nullptr; | ||
920 | foreach (QObject *appletObject, m_appletInterfaces) { | 923 | for (QObject *appletObject : qAsConst(m_appletInterfaces)) { | ||
921 | if (AppletInterface *ai = qobject_cast<AppletInterface *>(appletObject)) { | 924 | if (AppletInterface *ai = qobject_cast<AppletInterface *>(appletObject)) { | ||
922 | if (ai->isVisible() && ai->contains(ai->mapFromItem(this, event->localPos()))) { | 925 | if (ai->isVisible() && ai->contains(ai->mapFromItem(this, event->localPos()))) { | ||
923 | applet = ai->applet(); | 926 | applet = ai->applet(); | ||
924 | break; | 927 | break; | ||
925 | } else { | 928 | } else { | ||
926 | ai = nullptr; | 929 | ai = nullptr; | ||
927 | } | 930 | } | ||
928 | } | 931 | } | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 1040 | if (event->key() == Qt::Key_Menu) { | |||
1040 | event->accept(); | 1043 | event->accept(); | ||
1041 | } | 1044 | } | ||
1042 | 1045 | | |||
1043 | AppletInterface::keyPressEvent(event); | 1046 | AppletInterface::keyPressEvent(event); | ||
1044 | } | 1047 | } | ||
1045 | 1048 | | |||
1046 | void ContainmentInterface::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event) | 1049 | void ContainmentInterface::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event) | ||
1047 | { | 1050 | { | ||
1048 | foreach (QAction *action, applet->contextualActions()) { | 1051 | const auto listActions = applet->contextualActions(); | ||
1052 | for (QAction *action : listActions) { | ||||
1049 | if (action) { | 1053 | if (action) { | ||
1050 | desktopMenu->addAction(action); | 1054 | desktopMenu->addAction(action); | ||
1051 | } | 1055 | } | ||
1052 | } | 1056 | } | ||
1053 | 1057 | | |||
1054 | if (!applet->failedToLaunch()) { | 1058 | if (!applet->failedToLaunch()) { | ||
1055 | QAction *runAssociatedApplication = applet->actions()->action(QStringLiteral("run associated application")); | 1059 | QAction *runAssociatedApplication = applet->actions()->action(QStringLiteral("run associated application")); | ||
1056 | if (runAssociatedApplication && runAssociatedApplication->isEnabled()) { | 1060 | if (runAssociatedApplication && runAssociatedApplication->isEnabled()) { | ||
▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines |
QLatin1String