• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

appletinterface.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2008 Chani Armitage <chani@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License as
00006  *   published by the Free Software Foundation; either version 2, or
00007  *   (at your option) any later version.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details
00013  *
00014  *   You should have received a copy of the GNU Library General Public
00015  *   License along with this program; if not, write to the
00016  *   Free Software Foundation, Inc.,
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00018  */
00019 
00020 #include "appletinterface.h"
00021 
00022 #include <QAction>
00023 #include <QFile>
00024 #include <QSignalMapper>
00025 
00026 #include <KDE/KIcon>
00027 
00028 #include <Plasma/Plasma>
00029 #include <Plasma/Applet>
00030 #include <Plasma/Context>
00031 #include <Plasma/DataEngine>
00032 #include <Plasma/Package>
00033 
00034 #include "simplejavascriptapplet.h"
00035 
00036 AppletInterface::AppletInterface(SimpleJavaScriptApplet *parent)
00037     : QObject(parent),
00038       m_appletScriptEngine(parent),
00039       m_actionSignals(0)
00040 {
00041     connect(this, SIGNAL(releaseVisualFocus()), applet(), SIGNAL(releaseVisualFocus()));
00042     connect(this, SIGNAL(configNeedsSaving()), applet(), SIGNAL(configNeedsSaving()));
00043 }
00044 
00045 AppletInterface::~AppletInterface()
00046 {
00047 }
00048 
00049 Plasma::DataEngine* AppletInterface::dataEngine(const QString &name)
00050 {
00051     return applet()->dataEngine(name);
00052 }
00053 
00054 AppletInterface::FormFactor AppletInterface::formFactor()
00055 {
00056     return static_cast<FormFactor>(applet()->formFactor());
00057 }
00058 
00059 AppletInterface::Location AppletInterface::location()
00060 {
00061     return static_cast<Location>(applet()->location());
00062 }
00063 
00064 QString AppletInterface::currentActivity()
00065 {
00066     return applet()->context()->currentActivity();
00067 }
00068 
00069 AppletInterface::AspectRatioMode AppletInterface::aspectRatioMode()
00070 {
00071     return static_cast<AspectRatioMode>(applet()->aspectRatioMode());
00072 }
00073 
00074 void AppletInterface::setAspectRatioMode(AppletInterface::AspectRatioMode mode)
00075 {
00076     applet()->setAspectRatioMode(static_cast<Plasma::AspectRatioMode>(mode));
00077 }
00078 
00079 bool AppletInterface::shouldConserveResources()
00080 {
00081     return applet()->shouldConserveResources();
00082 }
00083 
00084 void AppletInterface::setFailedToLaunch(bool failed, const QString &reason)
00085 {
00086     m_appletScriptEngine->setFailedToLaunch(failed, reason);
00087 }
00088 
00089 bool AppletInterface::isBusy()
00090 {
00091     return applet()->isBusy();
00092 }
00093 
00094 void AppletInterface::setBusy(bool busy)
00095 {
00096     applet()->setBusy(busy);
00097 }
00098 
00099 void AppletInterface::setConfigurationRequired(bool needsConfiguring, const QString &reason)
00100 {
00101     m_appletScriptEngine->setConfigurationRequired(needsConfiguring, reason);
00102 }
00103 
00104 void AppletInterface::update()
00105 {
00106     applet()->update();
00107 }
00108 
00109 QString AppletInterface::activeConfig() const
00110 {
00111     return m_currentConfig.isEmpty() ? "main" : m_currentConfig;
00112 }
00113 
00114 void AppletInterface::setActiveConfig(const QString &name)
00115 {
00116     if (name == "main") {
00117         m_currentConfig = QString();
00118         return;
00119     }
00120 
00121     Plasma::ConfigLoader *loader = m_configs.value(name, 0);
00122 
00123     if (!loader) {
00124         QString path = applet()->package()->filePath("config", name + ".xml");
00125         if (path.isEmpty()) {
00126             return;
00127         }
00128 
00129         QFile f(path);
00130         KConfigGroup cg = applet()->config();
00131         loader = new Plasma::ConfigLoader(&cg, &f, this);
00132         m_configs.insert(name, loader);
00133     }
00134 
00135     m_currentConfig = name;
00136 }
00137 
00138 void AppletInterface::writeConfig(const QString &entry, const QVariant &value)
00139 {
00140     Plasma::ConfigLoader *config = 0;
00141     if (m_currentConfig.isEmpty()) {
00142         config = applet()->configScheme();
00143     } else {
00144         config = m_configs.value(m_currentConfig, 0);
00145     }
00146 
00147     if (config) {
00148         KConfigSkeletonItem *item = config->findItemByName(entry);
00149         if (item) {
00150             item->setProperty(value);
00151             config->writeConfig();
00152             m_appletScriptEngine->configNeedsSaving();
00153         }
00154     }
00155 }
00156 
00157 QVariant AppletInterface::readConfig(const QString &entry) const
00158 {
00159     Plasma::ConfigLoader *config = 0;
00160     if (m_currentConfig.isEmpty()) {
00161         config = applet()->configScheme();
00162     } else {
00163         config = m_configs.value(m_currentConfig, 0);
00164     }
00165 
00166     if (config) {
00167         return config->property(entry);
00168     }
00169 
00170     return QVariant();
00171 }
00172 
00173 const Plasma::Package *AppletInterface::package() const
00174 {
00175     return m_appletScriptEngine->package();
00176 }
00177 
00178 QList<QAction*> AppletInterface::contextualActions() const
00179 {
00180     QList<QAction*> actions;
00181     Plasma::Applet *a = applet();
00182 
00183     foreach (const QString name, m_actions) {
00184         QAction *action = a->action(name);
00185 
00186         if (action) {
00187             actions << action;
00188         }
00189     }
00190 
00191     return actions;
00192 }
00193 
00194 QSizeF AppletInterface::size() const
00195 {
00196     return applet()->size();
00197 }
00198 
00199 void AppletInterface::setAction(const QString &name, const QString &text, const QString &icon, const QString &shortcut)
00200 {
00201     Plasma::Applet *a = applet();
00202     QAction *action = a->action(name);
00203 
00204     if (action) {
00205         action->setText(text);
00206     } else {
00207         action = new QAction(text, this);
00208         a->addAction(name, action);
00209 
00210         Q_ASSERT(!m_actions.contains(name));
00211         m_actions.insert(name);
00212 
00213         if (!m_actionSignals) {
00214             m_actionSignals = new QSignalMapper(this);
00215             connect(m_actionSignals, SIGNAL(mapped(QString)),
00216                     m_appletScriptEngine, SLOT(executeAction(QString)));
00217         }
00218 
00219         connect(action, SIGNAL(triggered()), m_actionSignals, SLOT(map()));
00220         m_actionSignals->setMapping(action, name);
00221     }
00222 
00223     action->setIcon(icon.isEmpty() ? QIcon() : KIcon(icon));
00224     action->setShortcut(shortcut);
00225     action->setObjectName(name);
00226 }
00227 
00228 void AppletInterface::removeAction(const QString &name)
00229 {
00230     Plasma::Applet *a = applet();
00231     QAction *action = a->action(name);
00232 
00233     if (action) {
00234         if (m_actionSignals) {
00235             m_actionSignals->removeMappings(action);
00236         }
00237 
00238         delete action;
00239     }
00240 
00241     m_actions.remove(name);
00242 }
00243 
00244 void AppletInterface::resize(qreal w, qreal h)
00245 {
00246     applet()->resize(w,h);
00247 }
00248 
00249 void AppletInterface::setMinimumSize(qreal w, qreal h)
00250 {
00251     applet()->setMinimumSize(w,h);
00252 }
00253 
00254 void AppletInterface::setPreferredSize(qreal w, qreal h)
00255 {
00256     applet()->setPreferredSize(w,h);
00257 }
00258 
00259 void AppletInterface::dataUpdated(QString source, Plasma::DataEngine::Data data)
00260 {
00261     m_appletScriptEngine->dataUpdated(source, data);
00262 }
00263 
00264 Plasma::Applet *AppletInterface::applet() const
00265 {
00266     return m_appletScriptEngine->applet();
00267 }
00268 
00269 #include "appletinterface.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal