Changeset View
Changeset View
Standalone View
Standalone View
src/scriptengines/qml/plasmoid/containmentinterface.cpp
Show First 20 Lines • Show All 233 Lines • ▼ Show 20 Line(s) | 228 | { | |||
---|---|---|---|---|---|
234 | if (appletInterface) { | 234 | if (appletInterface) { | ||
235 | emit appletInterface->externalData(mimetype, data); | 235 | emit appletInterface->externalData(mimetype, data); | ||
236 | } | 236 | } | ||
237 | } | 237 | } | ||
238 | 238 | | |||
239 | QObject *ContainmentInterface::containmentAt(int x, int y) | 239 | QObject *ContainmentInterface::containmentAt(int x, int y) | ||
240 | { | 240 | { | ||
241 | QObject *desktop = nullptr; | 241 | QObject *desktop = nullptr; | ||
242 | foreach (Plasma::Containment *c, m_containment->corona()->containments()) { | 242 | const auto lst = m_containment->corona()->containments(); | ||
243 | for (Plasma::Containment *c : lst) { | ||||
243 | ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value<ContainmentInterface *>(); | 244 | ContainmentInterface *contInterface = c->property("_plasma_graphicObject").value<ContainmentInterface *>(); | ||
244 | 245 | | |||
245 | if (contInterface && contInterface->isVisible()) { | 246 | if (contInterface && contInterface->isVisible()) { | ||
246 | QWindow *w = contInterface->window(); | 247 | QWindow *w = contInterface->window(); | ||
247 | if (w && w->geometry().contains(QPoint(window()->x(), window()->y()) + QPoint(x, y))) { | 248 | if (w && w->geometry().contains(QPoint(window()->x(), window()->y()) + QPoint(x, y))) { | ||
248 | if (c->containmentType() == Plasma::Types::CustomEmbeddedContainment) { | 249 | if (c->containmentType() == Plasma::Types::CustomEmbeddedContainment) { | ||
249 | continue; | 250 | continue; | ||
250 | } | 251 | } | ||
▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Line(s) | 442 | { | |||
451 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | 452 | if (!mimeData->hasUrls() && mimeData->hasFormat(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))) { | ||
452 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | 453 | QList<QUrl> urls = {QUrl(QString::fromUtf8(mimeData->data(QStringLiteral("text/x-orgkdeplasmataskmanager_taskurl"))))}; | ||
453 | mimeData->setUrls(urls); | 454 | mimeData->setUrls(urls); | ||
454 | } | 455 | } | ||
455 | 456 | | |||
456 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | 457 | if (mimeData->hasFormat(QStringLiteral("text/x-plasmoidservicename"))) { | ||
457 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | 458 | QString data = QString::fromUtf8( mimeData->data(QStringLiteral("text/x-plasmoidservicename")) ); | ||
458 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | 459 | const QStringList appletNames = data.split(QLatin1Char('\n'), QString::SkipEmptyParts); | ||
459 | foreach (const QString &appletName, appletNames) { | 460 | for (const QString &appletName : appletNames) { | ||
460 | qDebug() << "adding" << appletName; | 461 | qDebug() << "adding" << appletName; | ||
461 | 462 | | |||
462 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | 463 | metaObject()->invokeMethod(this, "createApplet", Qt::QueuedConnection, Q_ARG(QString, appletName), Q_ARG(QVariantList, QVariantList()), Q_ARG(QRectF, QRectF(x, y, -1, -1))); | ||
463 | } | 464 | } | ||
464 | } else if (mimeData->hasUrls()) { | 465 | } else if (mimeData->hasUrls()) { | ||
465 | //TODO: collect the mimetypes of available script engines and offer | 466 | //TODO: collect the mimetypes of available script engines and offer | ||
466 | // to create widgets out of the matching URLs, if any | 467 | // to create widgets out of the matching URLs, if any | ||
467 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | 468 | const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData); | ||
468 | foreach (const QUrl &url, urls) { | 469 | for (const QUrl &url : urls) { | ||
469 | QMimeDatabase db; | 470 | QMimeDatabase db; | ||
470 | const QMimeType &mime = db.mimeTypeForUrl(url); | 471 | const QMimeType &mime = db.mimeTypeForUrl(url); | ||
471 | QString mimeName = mime.name(); | 472 | QString mimeName = mime.name(); | ||
472 | QVariantList args; | 473 | QVariantList args; | ||
473 | args << url.url(); | 474 | args << url.url(); | ||
474 | qDebug() << "can decode" << mimeName << args; | 475 | qDebug() << "can decode" << mimeName << args; | ||
475 | 476 | | |||
476 | // It may be a directory or a file, let's stat | 477 | // It may be a directory or a file, let's stat | ||
Show All 15 Lines | 488 | } else { | |||
492 | choices->addAction(QIcon::fromTheme(QStringLiteral("process-working")), i18n("Fetching file type...")); | 493 | choices->addAction(QIcon::fromTheme(QStringLiteral("process-working")), i18n("Fetching file type...")); | ||
493 | choices->popup(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | 494 | choices->popup(window() ? window()->mapToGlobal(QPoint(x, y)) : QPoint(x, y)); | ||
494 | 495 | | |||
495 | m_dropMenus[job] = choices; | 496 | m_dropMenus[job] = choices; | ||
496 | } | 497 | } | ||
497 | } | 498 | } | ||
498 | 499 | | |||
499 | } else { | 500 | } else { | ||
500 | QStringList formats = mimeData->formats(); | 501 | const QStringList formats = mimeData->formats(); | ||
501 | QHash<QString, KPluginMetaData> seenPlugins; | 502 | QHash<QString, KPluginMetaData> seenPlugins; | ||
502 | QHash<QString, QString> pluginFormats; | 503 | QHash<QString, QString> pluginFormats; | ||
503 | 504 | | |||
504 | foreach (const QString &format, formats) { | 505 | for (const QString &format : formats) { | ||
505 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | 506 | const auto plugins = Plasma::PluginLoader::self()->listAppletMetaDataForMimeType(format); | ||
506 | 507 | | |||
507 | foreach (const auto &plugin, plugins) { | 508 | for (const auto &plugin : plugins) { | ||
508 | if (seenPlugins.contains(plugin.pluginId())) { | 509 | if (seenPlugins.contains(plugin.pluginId())) { | ||
509 | continue; | 510 | continue; | ||
510 | } | 511 | } | ||
511 | 512 | | |||
512 | seenPlugins.insert(plugin.pluginId(), plugin); | 513 | seenPlugins.insert(plugin.pluginId(), plugin); | ||
513 | pluginFormats.insert(plugin.pluginId(), format); | 514 | pluginFormats.insert(plugin.pluginId(), format); | ||
514 | } | 515 | } | ||
515 | } | 516 | } | ||
Show All 13 Lines | 528 | } else { | |||
529 | if (!dropJob) { | 530 | if (!dropJob) { | ||
530 | choices = new QMenu(); | 531 | choices = new QMenu(); | ||
531 | if (choices->winId()) { | 532 | if (choices->winId()) { | ||
532 | choices->windowHandle()->setTransientParent(window()); | 533 | choices->windowHandle()->setTransientParent(window()); | ||
533 | } | 534 | } | ||
534 | } | 535 | } | ||
535 | QList<QAction *> extraActions; | 536 | QList<QAction *> extraActions; | ||
536 | QHash<QAction *, QString> actionsToPlugins; | 537 | QHash<QAction *, QString> actionsToPlugins; | ||
537 | foreach (const auto &info, seenPlugins) { | 538 | for (const auto &info : qAsConst(seenPlugins)) { | ||
538 | QAction *action; | 539 | QAction *action; | ||
539 | if (!info.iconName().isEmpty()) { | 540 | if (!info.iconName().isEmpty()) { | ||
540 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), nullptr); | 541 | action = new QAction(QIcon::fromTheme(info.iconName()), info.name(), nullptr); | ||
541 | } else { | 542 | } else { | ||
542 | action = new QAction(info.name(), nullptr); | 543 | action = new QAction(info.name(), nullptr); | ||
543 | } | 544 | } | ||
544 | extraActions << action; | 545 | extraActions << action; | ||
545 | if (choices) { | 546 | if (choices) { | ||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Line(s) | 643 | if (!appletList.isEmpty() || !wallpaperList.isEmpty() || isPlasmaPackage) { | |||
695 | 696 | | |||
696 | if (choices) { | 697 | if (choices) { | ||
697 | choices->addSection(i18n("Widgets")); | 698 | choices->addSection(i18n("Widgets")); | ||
698 | } else { | 699 | } else { | ||
699 | QAction *action = new QAction(i18n("Widgets"), nullptr); | 700 | QAction *action = new QAction(i18n("Widgets"), nullptr); | ||
700 | action->setSeparator(true); | 701 | action->setSeparator(true); | ||
701 | dropActions << action; | 702 | dropActions << action; | ||
702 | } | 703 | } | ||
703 | foreach (const auto &info, appletList) { | 704 | for (const auto &info : qAsConst(appletList)) { | ||
704 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | 705 | const QString actionText = i18nc("Add widget", "Add %1", info.name()); | ||
705 | QAction *action = new QAction(actionText, nullptr); | 706 | QAction *action = new QAction(actionText, nullptr); | ||
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 | if (choices) { | 710 | if (choices) { | ||
710 | choices->addAction(action); | 711 | choices->addAction(action); | ||
711 | } | 712 | } | ||
Show All 25 Lines | 737 | if (choices) { | |||
737 | choices->addSection(i18n("Wallpaper")); | 738 | choices->addSection(i18n("Wallpaper")); | ||
738 | } else { | 739 | } else { | ||
739 | QAction *action = new QAction(i18n("Wallpaper"), nullptr); | 740 | QAction *action = new QAction(i18n("Wallpaper"), nullptr); | ||
740 | action->setSeparator(true); | 741 | action->setSeparator(true); | ||
741 | dropActions << action; | 742 | dropActions << action; | ||
742 | } | 743 | } | ||
743 | 744 | | |||
744 | QMap<QString, KPluginMetaData> sorted; | 745 | QMap<QString, KPluginMetaData> sorted; | ||
745 | foreach (const auto &info, appletList) { | 746 | for (const auto &info : qAsConst(appletList)) { | ||
746 | sorted.insert(info.name(), info); | 747 | sorted.insert(info.name(), info); | ||
747 | } | 748 | } | ||
748 | 749 | | |||
749 | foreach (const KPluginMetaData &info, wallpaperList) { | 750 | for (const KPluginMetaData &info : qAsConst(wallpaperList)) { | ||
750 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | 751 | const QString actionText = i18nc("Set wallpaper", "Set %1", info.name()); | ||
751 | QAction *action = new QAction(actionText, nullptr); | 752 | QAction *action = new QAction(actionText, nullptr); | ||
752 | if (!info.iconName().isEmpty()) { | 753 | if (!info.iconName().isEmpty()) { | ||
753 | action->setIcon(QIcon::fromTheme(info.iconName())); | 754 | action->setIcon(QIcon::fromTheme(info.iconName())); | ||
754 | } | 755 | } | ||
755 | 756 | | |||
756 | if (choices) { | 757 | if (choices) { | ||
757 | choices->addAction(action); | 758 | choices->addAction(action); | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | 899 | { | |||
899 | //FIXME: giving directly a QList<QAction*> crashes | 900 | //FIXME: giving directly a QList<QAction*> crashes | ||
900 | 901 | | |||
901 | QStringList actionOrder; | 902 | QStringList actionOrder; | ||
902 | actionOrder << QStringLiteral("add widgets") << QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("run associated application") << QStringLiteral("configure"); | 903 | actionOrder << QStringLiteral("add widgets") << QStringLiteral("manage activities") << QStringLiteral("remove") << QStringLiteral("lock widgets") << QStringLiteral("run associated application") << QStringLiteral("configure"); | ||
903 | QHash<QString, QAction *> orderedActions; | 904 | QHash<QString, QAction *> orderedActions; | ||
904 | //use a multimap to sort by action type | 905 | //use a multimap to sort by action type | ||
905 | QMultiMap<int, QObject *> actions; | 906 | QMultiMap<int, QObject *> actions; | ||
906 | int i = 0; | 907 | int i = 0; | ||
907 | foreach (QAction *a, m_containment->actions()->actions()) { | 908 | auto listActions = m_containment->actions()->actions(); | ||
909 | for (QAction *a : qAsConst(listActions)) { | ||||
908 | if (!actionOrder.contains(a->objectName())) { | 910 | if (!actionOrder.contains(a->objectName())) { | ||
909 | //FIXME QML visualizations don't support menus for now, *and* there is no way to | 911 | //FIXME QML visualizations don't support menus for now, *and* there is no way to | ||
910 | //distinguish them on QML side | 912 | //distinguish them on QML side | ||
911 | if (!a->menu()) { | 913 | if (!a->menu()) { | ||
912 | actions.insert(a->data().toInt()*100 + i, a); | 914 | actions.insert(a->data().toInt()*100 + i, a); | ||
913 | ++i; | 915 | ++i; | ||
914 | } | 916 | } | ||
915 | } else { | 917 | } else { | ||
916 | orderedActions[a->objectName()] = a; | 918 | orderedActions[a->objectName()] = a; | ||
917 | } | 919 | } | ||
918 | } | 920 | } | ||
919 | 921 | | |||
920 | i = 0; | 922 | i = 0; | ||
921 | foreach (QAction *a, m_containment->corona()->actions()->actions()) { | 923 | listActions = m_containment->corona()->actions()->actions(); | ||
924 | for (QAction *a : qAsConst(listActions)) { | ||||
922 | if (a->objectName() == QStringLiteral("lock widgets") || a->menu()) { | 925 | if (a->objectName() == QStringLiteral("lock widgets") || a->menu()) { | ||
923 | //It is up to the Containment to decide if the user is allowed or not | 926 | //It is up to the Containment to decide if the user is allowed or not | ||
924 | //to lock/unluck the widgets, so corona should not add one when there is none | 927 | //to lock/unluck the widgets, so corona should not add one when there is none | ||
ahmadsamir: QLatin1String | |||||
925 | //(user is not allow) and it shouldn't add another one when there is already | 928 | //(user is not allow) and it shouldn't add another one when there is already | ||
926 | //one | 929 | //one | ||
927 | continue; | 930 | continue; | ||
928 | } | 931 | } | ||
929 | 932 | | |||
930 | if (!actionOrder.contains(a->objectName())) { | 933 | if (!actionOrder.contains(a->objectName())) { | ||
931 | actions.insert(a->data().toInt()*100 + i, a); | 934 | actions.insert(a->data().toInt()*100 + i, a); | ||
932 | } else { | 935 | } else { | ||
933 | orderedActions[a->objectName()] = a; | 936 | orderedActions[a->objectName()] = a; | ||
934 | } | 937 | } | ||
935 | ++i; | 938 | ++i; | ||
936 | } | 939 | } | ||
937 | QList<QObject *> actionList = actions.values(); | 940 | QList<QObject *> actionList = actions.values(); | ||
938 | 941 | | |||
939 | foreach (const QString &name, actionOrder) { | 942 | for (const QString &name : qAsConst(actionOrder)) { | ||
940 | QAction *a = orderedActions.value(name); | 943 | QAction *a = orderedActions.value(name); | ||
941 | if (a && !a->menu()) { | 944 | if (a && !a->menu()) { | ||
942 | actionList << a; | 945 | actionList << a; | ||
943 | } | 946 | } | ||
944 | ++i; | 947 | ++i; | ||
945 | } | 948 | } | ||
946 | 949 | | |||
947 | return actionList; | 950 | return actionList; | ||
Show All 32 Lines | 981 | if (plugin->contextualActions().length() == 1) { | |||
980 | action->setData(event->pos()); | 983 | action->setData(event->pos()); | ||
981 | action->trigger(); | 984 | action->trigger(); | ||
982 | event->accept(); | 985 | event->accept(); | ||
983 | return; | 986 | return; | ||
984 | } | 987 | } | ||
985 | 988 | | |||
986 | //FIXME: very inefficient appletAt() implementation | 989 | //FIXME: very inefficient appletAt() implementation | ||
987 | Plasma::Applet *applet = nullptr; | 990 | Plasma::Applet *applet = nullptr; | ||
988 | foreach (QObject *appletObject, m_appletInterfaces) { | 991 | for (QObject *appletObject : qAsConst(m_appletInterfaces)) { | ||
989 | if (AppletInterface *ai = qobject_cast<AppletInterface *>(appletObject)) { | 992 | if (AppletInterface *ai = qobject_cast<AppletInterface *>(appletObject)) { | ||
990 | if (ai->isVisible() && ai->contains(ai->mapFromItem(this, event->localPos()))) { | 993 | if (ai->isVisible() && ai->contains(ai->mapFromItem(this, event->localPos()))) { | ||
991 | applet = ai->applet(); | 994 | applet = ai->applet(); | ||
992 | break; | 995 | break; | ||
993 | } else { | 996 | } else { | ||
994 | ai = nullptr; | 997 | ai = nullptr; | ||
995 | } | 998 | } | ||
996 | } | 999 | } | ||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Line(s) | 1108 | if (event->key() == Qt::Key_Menu) { | |||
1108 | event->accept(); | 1111 | event->accept(); | ||
1109 | } | 1112 | } | ||
1110 | 1113 | | |||
1111 | AppletInterface::keyPressEvent(event); | 1114 | AppletInterface::keyPressEvent(event); | ||
1112 | } | 1115 | } | ||
1113 | 1116 | | |||
1114 | void ContainmentInterface::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event) | 1117 | void ContainmentInterface::addAppletActions(QMenu *desktopMenu, Plasma::Applet *applet, QEvent *event) | ||
1115 | { | 1118 | { | ||
1116 | foreach (QAction *action, applet->contextualActions()) { | 1119 | const auto listActions = applet->contextualActions(); | ||
1120 | for (QAction *action : listActions) { | ||||
1117 | if (action) { | 1121 | if (action) { | ||
1118 | desktopMenu->addAction(action); | 1122 | desktopMenu->addAction(action); | ||
1119 | } | 1123 | } | ||
1120 | } | 1124 | } | ||
1121 | 1125 | | |||
1122 | if (!applet->failedToLaunch()) { | 1126 | if (!applet->failedToLaunch()) { | ||
1123 | QAction *runAssociatedApplication = applet->actions()->action(QStringLiteral("run associated application")); | 1127 | QAction *runAssociatedApplication = applet->actions()->action(QStringLiteral("run associated application")); | ||
1124 | if (runAssociatedApplication && runAssociatedApplication->isEnabled()) { | 1128 | if (runAssociatedApplication && runAssociatedApplication->isEnabled()) { | ||
Show All 24 Lines | 1151 | while (enabled < 3 && actionsIt.hasNext()) { | |||
1149 | if (action->isVisible() && !action->isSeparator()) { | 1153 | if (action->isVisible() && !action->isSeparator()) { | ||
1150 | ++enabled; | 1154 | ++enabled; | ||
1151 | } | 1155 | } | ||
1152 | } | 1156 | } | ||
1153 | 1157 | | |||
1154 | if (enabled) { | 1158 | if (enabled) { | ||
1155 | //if there is only one, don't create a submenu | 1159 | //if there is only one, don't create a submenu | ||
1156 | if (enabled < 2) { | 1160 | if (enabled < 2) { | ||
1157 | foreach (QAction *action, containmentMenu->actions()) { | 1161 | const auto listActions = containmentMenu->actions(); | ||
1162 | for (QAction *action : listActions) { | ||||
1158 | if (action->isVisible() && !action->isSeparator()) { | 1163 | if (action->isVisible() && !action->isSeparator()) { | ||
1159 | desktopMenu->addAction(action); | 1164 | desktopMenu->addAction(action); | ||
1160 | } | 1165 | } | ||
1161 | } | 1166 | } | ||
1162 | } else { | 1167 | } else { | ||
1163 | desktopMenu->addMenu(containmentMenu); | 1168 | desktopMenu->addMenu(containmentMenu); | ||
1164 | } | 1169 | } | ||
1165 | } | 1170 | } | ||
▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines |
QLatin1String