2010-03-17 19:00:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* 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 <QEventLoop>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2010-11-18 02:16:57 +01:00
|
|
|
#include <KGlobalSettings>
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
#include <Plasma/Containment>
|
|
|
|
#include <Plasma/Corona>
|
|
|
|
#include <Plasma/DataEngineManager>
|
2010-11-18 02:16:57 +01:00
|
|
|
#include <Plasma/Theme>
|
2010-03-17 19:00:07 +01:00
|
|
|
|
2010-11-19 03:27:32 +01:00
|
|
|
#ifdef Q_WS_X11
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <fixx11h.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
#include "scriptengine.h"
|
|
|
|
|
2010-05-19 19:13:29 +02:00
|
|
|
namespace WorkspaceScripting
|
|
|
|
{
|
|
|
|
|
2010-11-18 02:16:57 +01:00
|
|
|
AppInterface::AppInterface(ScriptEngine *env)
|
|
|
|
: QObject(env),
|
|
|
|
m_env(env)
|
2010-03-17 19:00:07 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int AppInterface::screenCount() const
|
|
|
|
{
|
2010-11-18 02:16:57 +01:00
|
|
|
return m_env->corona()->numScreens();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QRectF AppInterface::screenGeometry(int screen) const
|
|
|
|
{
|
2010-11-18 02:16:57 +01:00
|
|
|
return m_env->corona()->screenGeometry(screen);
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> AppInterface::activityIds() const
|
|
|
|
{
|
|
|
|
//FIXME: the ints could overflow since Applet::id() returns a uint,
|
|
|
|
// however QScript deals with QList<uint> very, very poory
|
|
|
|
QList<int> containments;
|
|
|
|
|
2010-11-18 02:16:57 +01:00
|
|
|
foreach (Plasma::Containment *c, m_env->corona()->containments()) {
|
2010-03-17 19:00:07 +01:00
|
|
|
if (!ScriptEngine::isPanel(c)) {
|
|
|
|
containments.append(c->id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return containments;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<int> AppInterface::panelIds() const
|
|
|
|
{
|
|
|
|
//FIXME: the ints could overflow since Applet::id() returns a uint,
|
|
|
|
// however QScript deals with QList<uint> very, very poory
|
|
|
|
QList<int> panels;
|
|
|
|
|
2010-11-18 02:16:57 +01:00
|
|
|
foreach (Plasma::Containment *c, m_env->corona()->containments()) {
|
2010-03-17 19:00:07 +01:00
|
|
|
//kDebug() << "checking" << (QObject*)c << isPanel(c);
|
|
|
|
if (ScriptEngine::isPanel(c)) {
|
|
|
|
panels.append(c->id());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return panels;
|
|
|
|
}
|
|
|
|
|
2010-11-18 02:16:57 +01:00
|
|
|
QString AppInterface::applicationVersion() const
|
|
|
|
{
|
|
|
|
return KGlobal::mainComponent().aboutData()->version();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppInterface::platformVersion() const
|
|
|
|
{
|
|
|
|
return KDE::versionString();
|
|
|
|
}
|
|
|
|
|
|
|
|
int AppInterface::scriptingVersion() const
|
|
|
|
{
|
|
|
|
return PLASMA_DESKTOP_SCRIPTING_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AppInterface::theme() const
|
|
|
|
{
|
|
|
|
return Plasma::Theme::defaultTheme()->themeName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppInterface::setTheme(const QString &name)
|
|
|
|
{
|
|
|
|
Plasma::Theme::defaultTheme()->setThemeName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppInterface::multihead() const
|
|
|
|
{
|
|
|
|
return KGlobalSettings::isMultiHead();
|
|
|
|
}
|
|
|
|
|
2010-11-19 03:27:32 +01:00
|
|
|
int AppInterface::multiheadScreen() const
|
|
|
|
{
|
|
|
|
int id = -1;
|
|
|
|
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
if (KGlobalSettings::isMultiHead()) {
|
|
|
|
// with multihead, we "lie" and say that screen 0 is the default screen, in fact, we pretend
|
|
|
|
// we have only one screen at all
|
|
|
|
Display *dpy = XOpenDisplay(NULL);
|
|
|
|
if (dpy) {
|
|
|
|
id = DefaultScreen(dpy);
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
void AppInterface::lockCorona(bool locked)
|
|
|
|
{
|
2010-11-18 02:16:57 +01:00
|
|
|
m_env->corona()->setImmutability(locked ? Plasma::UserImmutable : Plasma::Mutable);
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AppInterface::coronaLocked() const
|
|
|
|
{
|
2010-11-18 02:16:57 +01:00
|
|
|
return m_env->corona()->immutability() != Plasma::Mutable;
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppInterface::sleep(int ms)
|
|
|
|
{
|
|
|
|
QEventLoop loop;
|
|
|
|
QTimer::singleShot(ms, &loop, SLOT(quit()));
|
|
|
|
loop.exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppInterface::hasBattery() const
|
|
|
|
{
|
|
|
|
Plasma::DataEngineManager *engines = Plasma::DataEngineManager::self();
|
|
|
|
Plasma::DataEngine *power = engines->loadEngine("powermanagement");
|
|
|
|
|
2010-05-04 23:58:16 +02:00
|
|
|
const QStringList batteries = power->query("Battery")["Sources"].toStringList();
|
2010-03-17 19:00:07 +01:00
|
|
|
engines->unloadEngine("powermanagement");
|
|
|
|
return !batteries.isEmpty();
|
|
|
|
}
|
|
|
|
|
2010-04-27 23:50:16 +02:00
|
|
|
QStringList AppInterface::knownWidgetTypes() const
|
|
|
|
{
|
|
|
|
QStringList widgets;
|
2010-04-30 00:24:25 +02:00
|
|
|
KPluginInfo::List infoLs = Plasma::Applet::listAppletInfo();
|
2010-04-27 23:50:16 +02:00
|
|
|
|
2010-04-30 00:24:25 +02:00
|
|
|
foreach (const KPluginInfo &info, infoLs) {
|
2010-04-27 23:50:16 +02:00
|
|
|
widgets.append(info.pluginName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return widgets;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList AppInterface::knownActivityTypes() const
|
|
|
|
{
|
|
|
|
return knownContainmentTypes("desktop");
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList AppInterface::knownPanelTypes() const
|
|
|
|
{
|
|
|
|
return knownContainmentTypes("panel");
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList AppInterface::knownContainmentTypes(const QString &type) const
|
|
|
|
{
|
|
|
|
QStringList containments;
|
2010-04-30 00:24:25 +02:00
|
|
|
KPluginInfo::List infoLs = Plasma::Containment::listContainmentsOfType(type);
|
2010-04-27 23:50:16 +02:00
|
|
|
|
2010-04-30 00:24:25 +02:00
|
|
|
foreach (const KPluginInfo &info, infoLs) {
|
2010-04-27 23:50:16 +02:00
|
|
|
containments.append(info.pluginName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return containments;
|
|
|
|
}
|
|
|
|
|
2010-05-19 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
#include "appinterface.moc"
|
|
|
|
|