diff --git a/shell/scripting/appinterface.cpp b/shell/scripting/appinterface.cpp index 631168a66..e78554198 100644 --- a/shell/scripting/appinterface.cpp +++ b/shell/scripting/appinterface.cpp @@ -1,235 +1,232 @@ /* * Copyright 2009 Aaron Seigo * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "appinterface.h" #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_OS_WIN #include #endif #if HAVE_X11 #include #include #endif #include "scriptengine.h" namespace WorkspaceScripting { AppInterface::AppInterface(ScriptEngine *env) : QObject(env), m_env(env) { m_theme = new Plasma::Theme(this); } int AppInterface::screenCount() const { return m_env->corona()->numScreens(); } QJSValue AppInterface::screenGeometry(int screen) const { QRectF rect = m_env->corona()->screenGeometry(screen); QJSValueList args({QJSValue(rect.x()), QJSValue(rect.y()), QJSValue(rect.width()), QJSValue(rect.height())}); return m_env->globalObject().property("QRectF").callAsConstructor(args); } QList AppInterface::activityIds() const { //FIXME: the ints could overflow since Applet::id() returns a uint, // however QScript deals with QList very, very poorly QList containments; foreach (Plasma::Containment *c, m_env->corona()->containments()) { if (!ScriptEngine::isPanel(c)) { containments.append(c->id()); } } return containments; } QList AppInterface::panelIds() const { //FIXME: the ints could overflow since Applet::id() returns a uint, // however QScript deals with QList very, very poorly QList panels; foreach (Plasma::Containment *c, m_env->corona()->containments()) { //qDebug() << "checking" << (QObject*)c << isPanel(c); if (ScriptEngine::isPanel(c)) { panels.append(c->id()); } } return panels; } QString AppInterface::applicationVersion() const { return qApp->applicationVersion(); } QString AppInterface::platformVersion() const { return QString();//KDE::versionString(); } int AppInterface::scriptingVersion() const { return PLASMA_DESKTOP_SCRIPTING_VERSION; } QString AppInterface::theme() const { return m_theme->themeName(); } void AppInterface::setTheme(const QString &name) { m_theme->setThemeName(name); } QString AppInterface::locale() const { return QLocale::system().name(); } QString AppInterface::language() const { return QLocale::system().languageToString(QLocale::system().language()); } QString AppInterface::languageId() const { return QLocale::system().bcp47Name().section(QLatin1Char('-'), 0, 0); } bool AppInterface::multihead() const { return false; } int AppInterface::multiheadScreen() const { return 0; } void AppInterface::lockCorona(bool locked) { m_env->corona()->setImmutability(locked ? Plasma::Types::UserImmutable : Plasma::Types::Mutable); } bool AppInterface::coronaLocked() const { return m_env->corona()->immutability() != Plasma::Types::Mutable; } void AppInterface::sleep(int ms) { - // The nested eventloop here may cause crashes when for example loading a - // LnF because the script runs out of the QML stack. Opening an eventloop - // there and processing QML events may result in touching members objects - // that were meant to be deleted but haven't yet, because the parent event - // loop hasn't returned yet. - qWarning() << "Scripted sleeping starts a nested event loop." \ - " This can cause process instability. Use with care!"; - QEventLoop loop; - QTimer::singleShot(ms, &loop, &QEventLoop::quit); - loop.exec(QEventLoop::ExcludeUserInputEvents); + // TODO KF6 remove + + // Sleep was implemented with a nested event loop which would cause nested + // event processing from QML and offer a wide array of sources for + // segfaulting. There isn't really a need to sleep from the scripting API, + // so it was turned no-op. + qWarning() << "Plasma scripting sleep() is deprecated and does nothing!"; } bool AppInterface::hasBattery() const { QList batteryDevices = Solid::Device::listFromType(Solid::DeviceInterface::Battery); for (auto device: batteryDevices) { Solid::Battery *battery = device.as(); // check for _both_ primary and power supply status // apparently some devices misreport as "primary", and we don't // want to trigger on just having UPC connected to a desktop box if (battery && battery->type() == Solid::Battery::PrimaryBattery && battery->isPowerSupply()) { return true; } } return false; } QStringList AppInterface::knownWidgetTypes() const { if (m_knownWidgets.isEmpty()) { QStringList widgets; KPluginInfo::List infoLs = Plasma::PluginLoader::self()->listAppletInfo(QString()); foreach (const KPluginInfo &info, infoLs) { widgets.append(info.pluginName()); } const_cast(this)->m_knownWidgets = widgets; } return m_knownWidgets; } QStringList AppInterface::knownActivityTypes() const { return knownContainmentTypes(QStringLiteral("desktop")); } QStringList AppInterface::knownPanelTypes() const { return knownContainmentTypes(QStringLiteral("panel")); } QStringList AppInterface::knownContainmentTypes(const QString &type) const { QStringList containments; const KPluginInfo::List infoLs = Plasma::PluginLoader::listContainmentsOfType(type); containments.reserve(infoLs.count()); foreach (const KPluginInfo &info, infoLs) { containments.append(info.pluginName()); } return containments; } }