2005-12-29 22:55:22 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
2006-01-23 12:37:31 +01:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-29 22:55:22 +01:00
|
|
|
*/
|
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "applet.h"
|
|
|
|
|
2007-08-05 16:24:24 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <limits>
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QApplication>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QEvent>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <QFile>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QList>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QPainter>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QSize>
|
2007-07-26 01:42:43 +02:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2007-11-04 06:31:18 +01:00
|
|
|
#include <QTextDocument>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QUiLoader>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-26 01:42:43 +02:00
|
|
|
#include <KIcon>
|
2007-11-04 07:58:20 +01:00
|
|
|
#include <KColorScheme>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <KConfigDialog>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <KDialog>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KPluginInfo>
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KStandardDirs>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KService>
|
2007-05-24 22:01:12 +02:00
|
|
|
#include <KServiceTypeTrader>
|
2007-07-26 01:42:43 +02:00
|
|
|
#include <KIconLoader>
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-07-30 18:00:29 +02:00
|
|
|
#include "plasma/configxml.h"
|
2007-09-18 23:22:45 +02:00
|
|
|
#include "plasma/containment.h"
|
2007-06-22 22:28:42 +02:00
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/dataenginemanager.h"
|
2007-07-20 05:28:34 +02:00
|
|
|
#include "plasma/package.h"
|
|
|
|
#include "plasma/packages_p.h"
|
2007-06-22 22:28:42 +02:00
|
|
|
#include "plasma/plasma.h"
|
2007-07-23 09:42:29 +02:00
|
|
|
#include "plasma/scriptengine.h"
|
2007-08-05 10:41:55 +02:00
|
|
|
#include "plasma/shadowitem_p.h"
|
2007-06-22 22:28:42 +02:00
|
|
|
#include "plasma/svg.h"
|
2007-11-04 07:58:20 +01:00
|
|
|
#include "plasma/theme.h"
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
#include "plasma/widgets/widget.h"
|
|
|
|
#include "plasma/widgets/lineedit.h"
|
2007-08-03 17:23:56 +02:00
|
|
|
#include "plasma/widgets/pushbutton.h"
|
2007-09-01 14:34:22 +02:00
|
|
|
#include "plasma/widgets/boxlayout.h"
|
2007-07-12 20:34:53 +02:00
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
//#define DYNAMIC_SHADOWS
|
2005-12-29 22:55:22 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Applet::Private
|
|
|
|
{
|
2007-07-20 05:28:34 +02:00
|
|
|
public:
|
|
|
|
Private(KService::Ptr service, int uniqueID)
|
|
|
|
: appletId(uniqueID),
|
|
|
|
globalConfig(0),
|
|
|
|
appletConfig(0),
|
2007-07-23 01:10:53 +02:00
|
|
|
appletDescription(service),
|
2007-07-20 05:28:34 +02:00
|
|
|
package(0),
|
|
|
|
background(0),
|
|
|
|
failureText(0),
|
2007-07-23 11:21:45 +02:00
|
|
|
scriptEngine(0),
|
2007-07-30 18:00:29 +02:00
|
|
|
configXml(0),
|
2007-08-05 10:41:55 +02:00
|
|
|
shadow(0),
|
|
|
|
cachedBackground(0),
|
2007-10-26 03:04:56 +02:00
|
|
|
pendingConstraints(NoConstraint),
|
2007-07-27 23:05:45 +02:00
|
|
|
kioskImmutable(false),
|
2007-07-20 05:28:34 +02:00
|
|
|
immutable(false),
|
|
|
|
hasConfigurationInterface(false),
|
2007-07-31 02:21:08 +02:00
|
|
|
failed(false),
|
2007-08-03 17:23:56 +02:00
|
|
|
needsConfig(false)
|
2007-07-20 05:28:34 +02:00
|
|
|
{
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = nextId();
|
|
|
|
}
|
2007-07-12 20:34:53 +02:00
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
if (appletId > s_maxAppletId) {
|
|
|
|
s_maxAppletId = appletId;
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
2007-07-20 05:28:34 +02:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
foreach ( const QString& engine, loadedEngines ) {
|
|
|
|
DataEngineManager::self()->unloadDataEngine( engine );
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
2007-07-20 05:28:34 +02:00
|
|
|
delete background;
|
|
|
|
delete package;
|
2007-07-30 18:00:29 +02:00
|
|
|
delete configXml;
|
2007-08-05 10:41:55 +02:00
|
|
|
delete shadow;
|
2007-07-31 02:21:08 +02:00
|
|
|
delete cachedBackground;
|
2007-07-20 05:28:34 +02:00
|
|
|
}
|
|
|
|
|
2007-07-20 10:12:20 +02:00
|
|
|
void init(Applet* applet)
|
|
|
|
{
|
2007-08-05 10:41:55 +02:00
|
|
|
applet->setZValue(100);
|
2007-07-27 23:05:45 +02:00
|
|
|
kioskImmutable = applet->globalConfig().isImmutable() ||
|
|
|
|
applet->config().isImmutable();
|
|
|
|
applet->setImmutable(kioskImmutable);
|
2007-07-26 04:07:18 +02:00
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!appletDescription.isValid()) {
|
2007-07-20 10:12:20 +02:00
|
|
|
applet->setFailedToLaunch(true);
|
2007-07-23 17:59:10 +02:00
|
|
|
return;
|
2007-07-20 10:12:20 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 09:42:29 +02:00
|
|
|
QString language = appletDescription.property("X-Plasma-Language").toString();
|
|
|
|
|
|
|
|
// we have a scripted plasmoid
|
|
|
|
if (!language.isEmpty()) {
|
|
|
|
// find where the Package is
|
|
|
|
QString path = KStandardDirs::locate("appdata",
|
|
|
|
"plasmoids/" +
|
|
|
|
appletDescription.pluginName());
|
|
|
|
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
// create the package and see if we have something real
|
|
|
|
package = new Package(path,
|
|
|
|
appletDescription.pluginName(),
|
|
|
|
PlasmoidStructure());
|
|
|
|
if (package->isValid()) {
|
|
|
|
// now we try and set up the script engine.
|
|
|
|
// it will be parented to this applet and so will get
|
|
|
|
// deleted when the applet does
|
|
|
|
|
2007-07-23 11:21:45 +02:00
|
|
|
scriptEngine = ScriptEngine::load(language, applet);
|
|
|
|
if (!scriptEngine) {
|
2007-07-23 09:42:29 +02:00
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!package) {
|
|
|
|
applet->setFailedToLaunch(true);
|
2007-07-30 18:00:29 +02:00
|
|
|
} else {
|
|
|
|
setupScriptSupport(applet);
|
2007-07-23 09:42:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-07-20 10:12:20 +02:00
|
|
|
}
|
|
|
|
|
2007-07-30 18:00:29 +02:00
|
|
|
// put all setup routines for script here. at this point we can assume that
|
|
|
|
// package exists and that we have a script engin
|
|
|
|
void setupScriptSupport(Applet* applet)
|
|
|
|
{
|
|
|
|
Q_ASSERT(package);
|
|
|
|
QString xmlPath = package->filePath("mainconfigxml");
|
|
|
|
if (!xmlPath.isEmpty()) {
|
|
|
|
QFile file(xmlPath);
|
2007-07-30 18:19:07 +02:00
|
|
|
configXml = new ConfigXml(config(), &file);
|
2007-07-30 18:00:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!package->filePath("mainconfigui").isEmpty()) {
|
|
|
|
applet->setHasConfigurationInterface(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-31 02:21:08 +02:00
|
|
|
void paintBackground(QPainter* p2, Applet* q)
|
2007-07-24 21:27:58 +02:00
|
|
|
{
|
2007-09-30 20:07:44 +02:00
|
|
|
if (q->formFactor() != Plasma::Planar) {
|
|
|
|
// we don't paint special backgrounds for other form factors
|
|
|
|
// if that changes in the future, this method is where such
|
|
|
|
// background painting code should be added
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-07-26 04:36:53 +02:00
|
|
|
QSize contents = contentSize(q).toSize();
|
2007-07-25 21:15:23 +02:00
|
|
|
const int contentWidth = contents.width();
|
|
|
|
const int contentHeight = contents.height();
|
2007-07-31 02:21:08 +02:00
|
|
|
|
2007-07-24 23:04:31 +02:00
|
|
|
background->resize();
|
|
|
|
|
2007-07-25 01:46:54 +02:00
|
|
|
const int topHeight = background->elementSize("top").height();
|
|
|
|
const int topWidth = background->elementSize("top").width();
|
|
|
|
const int leftWidth = background->elementSize("left").width();
|
|
|
|
const int leftHeight = background->elementSize("left").height();
|
|
|
|
const int rightWidth = background->elementSize("right").width();
|
|
|
|
const int bottomHeight = background->elementSize("bottom").height();
|
2007-07-25 21:15:23 +02:00
|
|
|
//const int lrWidths = leftWidth + rightWidth;
|
|
|
|
//const int tbHeights = topHeight + bottomHeight;
|
|
|
|
|
|
|
|
// contents top-left corner is (0,0). We need to draw up and left of that
|
|
|
|
const int topOffset = 0 - topHeight;
|
|
|
|
const int leftOffset = 0 - leftWidth;
|
|
|
|
const int rightOffset = contentWidth;
|
|
|
|
const int bottomOffset = contentHeight;
|
|
|
|
const int contentTop = 0;
|
|
|
|
const int contentLeft = 0;
|
2007-09-18 23:22:45 +02:00
|
|
|
QSize s = QSize(leftWidth + contentWidth + rightWidth,
|
|
|
|
topHeight + contentHeight + bottomHeight);
|
|
|
|
if (!cachedBackground || cachedBackground->size() != s) {
|
2007-07-31 02:21:08 +02:00
|
|
|
delete cachedBackground;
|
|
|
|
cachedBackground = new QPixmap(leftWidth + contentWidth + rightWidth, topHeight + contentHeight + bottomHeight);
|
|
|
|
cachedBackground->fill(Qt::transparent);
|
|
|
|
QPainter p(cachedBackground);
|
|
|
|
p.translate(leftWidth, topHeight);
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
p.setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
|
2007-10-08 05:41:56 +02:00
|
|
|
//FIXME: This is a hack to fix a drawing problems with svg files where a thin transparent border is drawn around the svg image.
|
|
|
|
// the transparent border around the svg seems to vary in size depending on the size of the svg and as a result increasing the
|
|
|
|
// svn image by 2 all around didn't resolve the issue. For now it resizes based on the border size.
|
|
|
|
|
|
|
|
background->resize(contentWidth, contentHeight);
|
|
|
|
background->paint(&p, QRect(contentLeft-leftWidth, contentTop-topHeight, contentWidth+leftWidth*2, contentHeight+topHeight*2), "center");
|
|
|
|
background->resize();
|
|
|
|
|
2007-10-01 07:50:57 +02:00
|
|
|
background->paint(&p, QRect(leftOffset, topOffset, leftWidth, topHeight), "topleft");
|
|
|
|
background->paint(&p, QRect(rightOffset, topOffset,rightWidth, topHeight), "topright");
|
|
|
|
background->paint(&p, QRect(leftOffset, bottomOffset, leftWidth, bottomHeight), "bottomleft");
|
2007-07-31 02:21:08 +02:00
|
|
|
background->paint(&p, QRect(rightOffset, bottomOffset, rightWidth, bottomHeight), "bottomright");
|
|
|
|
|
2007-09-07 15:05:28 +02:00
|
|
|
if (stretchBackgroundBorders) {
|
2007-09-18 23:22:45 +02:00
|
|
|
background->paint(&p, QRect(leftOffset, contentTop, leftWidth, contentHeight), "left");
|
|
|
|
background->paint(&p, QRect(rightOffset, contentTop, rightWidth, contentHeight), "right");
|
|
|
|
background->paint(&p, QRect(contentLeft, topOffset, contentWidth, topHeight), "top");
|
|
|
|
background->paint(&p, QRect(contentLeft, bottomOffset, contentWidth, bottomHeight), "bottom");
|
2007-09-07 15:05:28 +02:00
|
|
|
} else {
|
|
|
|
QPixmap left(leftWidth, leftHeight);
|
|
|
|
left.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&left);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
background->paint(&sidePainter, QPoint(0, 0), "left");
|
|
|
|
}
|
|
|
|
p.drawTiledPixmap(QRect(leftOffset, contentTop, leftWidth, contentHeight), left);
|
|
|
|
|
|
|
|
QPixmap right(rightWidth, leftHeight);
|
|
|
|
right.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&right);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
background->paint(&sidePainter, QPoint(0, 0), "right");
|
|
|
|
}
|
|
|
|
p.drawTiledPixmap(QRect(rightOffset, contentTop, rightWidth, contentHeight), right);
|
|
|
|
|
|
|
|
QPixmap top(topWidth, topHeight);
|
|
|
|
top.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&top);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
background->paint(&sidePainter, QPoint(0, 0), "top");
|
|
|
|
}
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft, topOffset, contentWidth, topHeight), top);
|
|
|
|
|
|
|
|
QPixmap bottom(topWidth, bottomHeight);
|
|
|
|
bottom.fill(Qt::transparent);
|
|
|
|
{
|
|
|
|
QPainter sidePainter(&bottom);
|
|
|
|
sidePainter.setCompositionMode(QPainter::CompositionMode_Source);
|
|
|
|
background->paint(&sidePainter, QPoint(0, 0), "bottom");
|
|
|
|
}
|
|
|
|
p.drawTiledPixmap(QRect(contentLeft, bottomOffset, contentWidth, bottomHeight), bottom);
|
2007-07-31 02:21:08 +02:00
|
|
|
}
|
2007-07-25 01:46:54 +02:00
|
|
|
|
2007-10-23 22:14:29 +02:00
|
|
|
// re-enable this once Qt's svg rendering is un-buggered
|
|
|
|
//background->resize(contentWidth, contentHeight);
|
|
|
|
//background->paint(&p, QRect(contentLeft, contentTop, contentWidth, contentHeight), "center");
|
2007-07-25 01:46:54 +02:00
|
|
|
}
|
2007-10-01 07:50:57 +02:00
|
|
|
|
2007-07-31 02:21:08 +02:00
|
|
|
p2->drawPixmap(leftOffset, topOffset, *cachedBackground);
|
2007-07-24 21:27:58 +02:00
|
|
|
}
|
|
|
|
|
2007-08-17 17:05:01 +02:00
|
|
|
void paintHover(QPainter* , Applet* )
|
2007-07-26 01:42:43 +02:00
|
|
|
{
|
|
|
|
//TODO draw hover interface for close, configure, info and move
|
|
|
|
}
|
|
|
|
|
2007-07-26 04:36:53 +02:00
|
|
|
QSizeF contentSize(const Applet* q)
|
|
|
|
{
|
|
|
|
if (scriptEngine) {
|
|
|
|
return scriptEngine->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (failureText) {
|
|
|
|
return failureText->geometry().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return q->contentSize();
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
static uint nextId()
|
|
|
|
{
|
|
|
|
++s_maxAppletId;
|
|
|
|
return s_maxAppletId;
|
|
|
|
}
|
2007-05-24 22:01:12 +02:00
|
|
|
|
2007-07-30 18:19:07 +02:00
|
|
|
KSharedConfig::Ptr config() {
|
|
|
|
if (!appletConfig) {
|
|
|
|
QString file = KStandardDirs::locateLocal("appdata",
|
|
|
|
"applets/" + instanceName() + "rc",
|
|
|
|
true);
|
|
|
|
appletConfig = KSharedConfig::openConfig(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString instanceName()
|
|
|
|
{
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletDescription.service()->library() + QString::number(appletId);
|
|
|
|
}
|
|
|
|
|
2007-08-17 17:05:01 +02:00
|
|
|
void getBorderSize(int& left , int& top, int &right, int& bottom)
|
|
|
|
{
|
|
|
|
if (!background) {
|
|
|
|
top = left = right = bottom = 0;
|
2007-09-01 14:34:22 +02:00
|
|
|
} else {
|
2007-08-17 17:05:01 +02:00
|
|
|
top = background->elementSize("top").height();
|
|
|
|
left = background->elementSize("left").width();
|
|
|
|
right = background->elementSize("right").width();
|
|
|
|
bottom = background->elementSize("bottom").height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-26 03:04:56 +02:00
|
|
|
void scheduleConstraintsUpdate(Plasma::Constraints c, Applet* applet)
|
|
|
|
{
|
|
|
|
if (pendingConstraints == NoConstraint) {
|
|
|
|
QTimer::singleShot(0, applet, SLOT(flushUpdatedConstraints()));
|
|
|
|
}
|
|
|
|
pendingConstraints |= c;
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:28:34 +02:00
|
|
|
//TODO: examine the usage of memory here; there's a pretty large
|
|
|
|
// number of members at this point.
|
|
|
|
uint appletId;
|
|
|
|
KSharedConfig::Ptr globalConfig;
|
|
|
|
KSharedConfig::Ptr appletConfig;
|
2007-07-23 01:10:53 +02:00
|
|
|
KPluginInfo appletDescription;
|
2007-07-20 05:28:34 +02:00
|
|
|
Package* package;
|
|
|
|
QList<QObject*> watchedForFocus;
|
|
|
|
QStringList loadedEngines;
|
|
|
|
static uint s_maxAppletId;
|
|
|
|
Plasma::Svg *background;
|
2007-09-07 15:05:28 +02:00
|
|
|
bool stretchBackgroundBorders;
|
2007-07-20 05:28:34 +02:00
|
|
|
Plasma::LineEdit *failureText;
|
2007-07-23 11:21:45 +02:00
|
|
|
ScriptEngine* scriptEngine;
|
2007-07-30 18:00:29 +02:00
|
|
|
ConfigXml* configXml;
|
2007-08-05 10:41:55 +02:00
|
|
|
ShadowItem* shadow;
|
2007-08-03 17:23:56 +02:00
|
|
|
QPixmap* cachedBackground;
|
2007-10-26 03:04:56 +02:00
|
|
|
Plasma::Constraints pendingConstraints;
|
2007-07-27 23:05:45 +02:00
|
|
|
bool kioskImmutable : 1;
|
2007-07-20 05:28:34 +02:00
|
|
|
bool immutable : 1;
|
|
|
|
bool hasConfigurationInterface : 1;
|
|
|
|
bool failed : 1;
|
2007-08-03 17:23:56 +02:00
|
|
|
bool needsConfig : 1;
|
2005-12-29 22:55:22 +01:00
|
|
|
};
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
uint Applet::Private::s_maxAppletId = 0;
|
|
|
|
|
|
|
|
Applet::Applet(QGraphicsItem *parent,
|
|
|
|
const QString& serviceID,
|
2007-07-12 20:34:53 +02:00
|
|
|
uint appletId)
|
2007-08-03 18:00:10 +02:00
|
|
|
: Widget(parent),
|
|
|
|
d(new Private(KService::serviceByStorageId(serviceID), appletId))
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-07-20 10:12:20 +02:00
|
|
|
d->init(this);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
Applet::Applet(QObject* parentObject, const QVariantList& args)
|
2007-08-17 17:05:01 +02:00
|
|
|
: Widget(0,parentObject),
|
2007-08-29 04:33:22 +02:00
|
|
|
d(new Private(KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()),
|
2007-08-03 18:00:10 +02:00
|
|
|
args.count() > 1 ? args[1].toInt() : 0))
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2007-07-20 10:12:20 +02:00
|
|
|
d->init(this);
|
2007-09-28 07:46:37 +02:00
|
|
|
// the brain damage seen in the initialization list is due to the
|
2007-06-20 08:45:08 +02:00
|
|
|
// inflexibility of KService::createInstance
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
Applet::~Applet()
|
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
needsFocus( false );
|
2007-08-05 11:39:32 +02:00
|
|
|
|
|
|
|
if (d->appletConfig) {
|
|
|
|
d->appletConfig->sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->globalConfig) {
|
|
|
|
d->globalConfig->sync();
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2007-09-13 19:00:57 +02:00
|
|
|
void Applet::init()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
uint Applet::id() const
|
|
|
|
{
|
|
|
|
return d->appletId;
|
|
|
|
}
|
|
|
|
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup Applet::config() const
|
2006-04-13 02:11:16 +02:00
|
|
|
{
|
2007-07-30 18:19:07 +02:00
|
|
|
return KConfigGroup(d->config(), "General");
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:22:45 +02:00
|
|
|
void Applet::save(KConfigGroup* group) const
|
|
|
|
{
|
|
|
|
group->writeEntry("plugin", pluginName());
|
2007-10-26 03:04:56 +02:00
|
|
|
//FIXME: for containments, we need to have some special values here w/regards to
|
|
|
|
// screen affinity (e.g. "bottom of screen 0")
|
2007-10-29 06:01:35 +01:00
|
|
|
//kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() << "bounding rect is" << boundingRect();
|
2007-10-29 05:39:23 +01:00
|
|
|
group->writeEntry("geometry", geometry());
|
2007-09-18 23:22:45 +02:00
|
|
|
|
|
|
|
Containment* c = containment();
|
|
|
|
if (c) {
|
|
|
|
group->writeEntry("containment", c->id());
|
|
|
|
}
|
|
|
|
|
|
|
|
saveState(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::saveState(KConfigGroup* group) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(group)
|
|
|
|
}
|
|
|
|
|
2007-07-12 21:14:23 +02:00
|
|
|
KConfigGroup Applet::config(const QString& group) const
|
|
|
|
{
|
|
|
|
KConfigGroup cg = config();
|
2007-10-24 04:04:02 +02:00
|
|
|
return KConfigGroup(cg.config(), instanceName() + '-' + group);
|
2007-07-12 21:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::globalConfig() const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !d->globalConfig ) {
|
|
|
|
QString file = KStandardDirs::locateLocal( "config", "plasma_" + globalName() + "rc" );
|
|
|
|
d->globalConfig = KSharedConfig::openConfig( file );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-05-25 04:36:22 +02:00
|
|
|
return KConfigGroup(d->globalConfig, "General");
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-08-05 11:39:32 +02:00
|
|
|
void Applet::destroy()
|
|
|
|
{
|
|
|
|
if (d->configXml) {
|
|
|
|
d->configXml->setDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->appletConfig) {
|
|
|
|
foreach (const QString& group, d->appletConfig->groupList()) {
|
|
|
|
d->appletConfig->deleteGroup(group);
|
|
|
|
}
|
|
|
|
d->appletConfig = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigXml* Applet::configXml() const
|
2007-07-30 18:19:07 +02:00
|
|
|
{
|
|
|
|
return d->configXml;
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
DataEngine* Applet::dataEngine(const QString& name) const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-06-02 19:29:39 +02:00
|
|
|
int index = d->loadedEngines.indexOf(name);
|
|
|
|
if (index != -1) {
|
|
|
|
return DataEngineManager::self()->dataEngine(name);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-06-02 19:29:39 +02:00
|
|
|
DataEngine* engine = DataEngineManager::self()->loadDataEngine(name);
|
2007-07-11 03:24:43 +02:00
|
|
|
if (engine->isValid()) {
|
2007-06-02 19:29:39 +02:00
|
|
|
d->loadedEngines.append(name);
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-11 03:24:43 +02:00
|
|
|
return engine;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
const Package* Applet::package() const
|
|
|
|
{
|
|
|
|
return d->package;
|
|
|
|
}
|
|
|
|
|
2007-10-02 01:24:38 +02:00
|
|
|
void Applet::updateConstraints(Plasma::Constraints constraints)
|
2007-08-05 10:41:55 +02:00
|
|
|
{
|
2007-10-26 03:04:56 +02:00
|
|
|
d->scheduleConstraintsUpdate(constraints, this);
|
2007-08-05 10:41:55 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 01:24:38 +02:00
|
|
|
void Applet::constraintsUpdated(Plasma::Constraints constraints)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-11-03 03:52:45 +01:00
|
|
|
Q_UNUSED(constraints)
|
2007-10-26 03:06:03 +02:00
|
|
|
//kDebug() << constraints << "constraints are FormFactor: " << formFactor() << ", Location: " << location();
|
2007-06-01 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
QString Applet::name() const
|
2007-06-05 21:31:48 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return i18n("Unknown Applet");
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.name();
|
2007-06-05 21:31:48 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 08:12:38 +02:00
|
|
|
QString Applet::icon() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.icon();
|
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
QString Applet::pluginName() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.pluginName();
|
|
|
|
}
|
|
|
|
|
2007-07-12 15:24:35 +02:00
|
|
|
QString Applet::category() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-08-05 15:01:09 +02:00
|
|
|
return i18n("Miscellaneous");
|
2007-07-18 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
return d->appletDescription.category();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
QString Applet::category(const KPluginInfo& applet)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
return applet.property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category(const QString& appletName)
|
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
return offers.first()->property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 02:24:36 +02:00
|
|
|
bool Applet::isImmutable() const
|
2007-06-21 20:24:05 +02:00
|
|
|
{
|
2007-07-27 23:05:45 +02:00
|
|
|
return d->immutable || d->kioskImmutable;
|
2007-06-21 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setImmutable(bool immutable)
|
|
|
|
{
|
|
|
|
d->immutable = immutable;
|
2007-07-31 03:11:25 +02:00
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, d->immutable || d->kioskImmutable ||
|
|
|
|
!scene() || !static_cast<Corona*>(scene())->isImmutable());
|
2007-06-21 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
bool Applet::drawStandardBackground()
|
|
|
|
{
|
|
|
|
return d->background != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setDrawStandardBackground(bool drawBackground)
|
|
|
|
{
|
|
|
|
if (drawBackground) {
|
|
|
|
if (!d->background) {
|
2007-07-30 18:00:29 +02:00
|
|
|
prepareGeometryChange();
|
2007-06-22 22:28:42 +02:00
|
|
|
d->background = new Plasma::Svg("widgets/background");
|
2007-09-07 15:05:28 +02:00
|
|
|
d->stretchBackgroundBorders = d->background->elementExists("hint-stretch-borders");
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
2007-07-30 18:00:29 +02:00
|
|
|
} else if (d->background) {
|
|
|
|
prepareGeometryChange();
|
2007-06-22 22:28:42 +02:00
|
|
|
delete d->background;
|
|
|
|
d->background = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-12 20:34:53 +02:00
|
|
|
bool Applet::failedToLaunch() const
|
|
|
|
{
|
|
|
|
return d->failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString visibleFailureText(const QString& reason)
|
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
if (reason.isEmpty()) {
|
|
|
|
text = i18n("This object could not be created.");
|
|
|
|
} else {
|
2007-11-04 06:31:18 +01:00
|
|
|
text = i18n("This object could not be created for the following reason:<p><b>%1</b></p>", reason);
|
2007-07-12 20:34:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
|
|
|
{
|
|
|
|
if (d->failed == failed) {
|
|
|
|
if (d->failureText) {
|
|
|
|
d->failureText->setHtml(visibleFailureText(reason));
|
2007-11-03 03:52:45 +01:00
|
|
|
setGeometry(QRectF(geometry().topLeft(), d->failureText->sizeHint()));
|
2007-07-12 20:34:53 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->failed = failed;
|
2007-07-26 04:36:53 +02:00
|
|
|
prepareGeometryChange();
|
2007-07-12 20:34:53 +02:00
|
|
|
qDeleteAll(QGraphicsItem::children());
|
|
|
|
delete layout();
|
|
|
|
|
|
|
|
if (failed) {
|
2007-08-03 17:23:56 +02:00
|
|
|
setDrawStandardBackground(true);
|
2007-11-03 03:52:45 +01:00
|
|
|
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
|
|
|
|
failureLayout->setMargin(0);
|
2007-11-04 06:31:18 +01:00
|
|
|
d->failureText = new LineEdit(this);
|
|
|
|
d->failureText->setStyled(false);
|
|
|
|
d->failureText->document()->setTextWidth(200);
|
2007-07-12 20:34:53 +02:00
|
|
|
d->failureText->setHtml(visibleFailureText(reason));
|
2007-11-04 06:31:18 +01:00
|
|
|
//FIXME: this needs to get the colour from the theme's colour scheme
|
2007-11-04 07:58:20 +01:00
|
|
|
d->failureText->setDefaultTextColor(KStatefulBrush(KColorScheme::Window,
|
|
|
|
KColorScheme::NormalText,
|
|
|
|
Theme::self()->colors())
|
|
|
|
.brush(QPalette::Normal).color());
|
2007-07-12 20:34:53 +02:00
|
|
|
failureLayout->addItem(d->failureText);
|
2007-11-03 03:52:45 +01:00
|
|
|
setGeometry(QRectF(geometry().topLeft(), d->failureText->sizeHint()));
|
2007-07-12 20:34:53 +02:00
|
|
|
} else {
|
|
|
|
d->failureText = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-08-03 17:23:56 +02:00
|
|
|
bool Applet::needsConfiguring() const
|
|
|
|
{
|
|
|
|
return d->needsConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setNeedsConfiguring(bool needsConfig)
|
|
|
|
{
|
|
|
|
if (d->needsConfig == needsConfig) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->needsConfig = needsConfig;
|
|
|
|
prepareGeometryChange();
|
|
|
|
qDeleteAll(QGraphicsItem::children());
|
|
|
|
delete layout();
|
|
|
|
|
|
|
|
if (needsConfig) {
|
|
|
|
setDrawStandardBackground(true);
|
2007-09-01 14:34:22 +02:00
|
|
|
Layout* layout = new BoxLayout(BoxLayout::TopToBottom,this);
|
2007-08-03 17:23:56 +02:00
|
|
|
PushButton* button = new PushButton(this);
|
|
|
|
button->setText(i18n("Configure..."));
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(performSetupConfig()));
|
|
|
|
layout->addItem(button);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::performSetupConfig()
|
|
|
|
{
|
|
|
|
qDeleteAll(QGraphicsItem::children());
|
|
|
|
delete layout();
|
|
|
|
showConfigurationInterface();
|
|
|
|
}
|
|
|
|
|
2007-10-26 03:04:56 +02:00
|
|
|
void Applet::flushUpdatedConstraints()
|
|
|
|
{
|
|
|
|
if (d->pendingConstraints == NoConstraint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-26 03:06:03 +02:00
|
|
|
//kDebug() << "fushing constraints: " << d->pendingConstraints << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
|
2007-10-26 03:04:56 +02:00
|
|
|
Plasma::Constraints c = d->pendingConstraints;
|
|
|
|
d->pendingConstraints = NoConstraint;
|
|
|
|
|
2007-11-07 20:20:33 +01:00
|
|
|
if (c & Plasma::FormFactorConstraint) {
|
|
|
|
FormFactor f = formFactor();
|
|
|
|
setShadowShown(f == Planar);
|
|
|
|
setDrawStandardBackground(qobject_cast<Containment*>(this) == 0 && f != Vertical && f != Horizontal);
|
|
|
|
}
|
|
|
|
|
2007-10-26 03:04:56 +02:00
|
|
|
constraintsUpdated(c);
|
|
|
|
|
|
|
|
if (layout()) {
|
|
|
|
layout()->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-23 00:01:10 +02:00
|
|
|
int Applet::type() const
|
|
|
|
{
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2007-07-31 03:11:25 +02:00
|
|
|
QRectF Applet::boundingRect() const
|
2007-07-12 20:34:53 +02:00
|
|
|
{
|
2007-07-26 04:36:53 +02:00
|
|
|
QRectF rect = QRectF(QPointF(0,0), d->contentSize(this));
|
2007-07-23 11:21:45 +02:00
|
|
|
|
2007-08-17 17:05:01 +02:00
|
|
|
int left;
|
|
|
|
int right;
|
|
|
|
int top;
|
|
|
|
int bottom;
|
|
|
|
|
|
|
|
d->getBorderSize(left,top,right,bottom);
|
2007-09-28 07:46:37 +02:00
|
|
|
|
|
|
|
|
2007-09-01 14:34:22 +02:00
|
|
|
//qDebug() << "Background , Border size" << d->background << left << top << right << bottom;
|
2007-09-28 07:46:37 +02:00
|
|
|
|
2007-08-17 17:05:01 +02:00
|
|
|
return rect.adjusted(-left,-top,right,bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Applet::sizeHint() const
|
|
|
|
{
|
|
|
|
int left;
|
|
|
|
int right;
|
|
|
|
int top;
|
|
|
|
int bottom;
|
|
|
|
|
|
|
|
d->getBorderSize(left,top,right,bottom);
|
2007-07-25 21:15:23 +02:00
|
|
|
|
2007-09-01 14:34:22 +02:00
|
|
|
//qDebug() << "Applet content size hint: " << contentSizeHint();
|
|
|
|
|
|
|
|
return contentSizeHint() + QSizeF(left+right,top+bottom);
|
2007-07-12 20:34:53 +02:00
|
|
|
}
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2007-07-31 02:20:19 +02:00
|
|
|
QList<QAction*> Applet::contextActions()
|
|
|
|
{
|
2007-10-11 10:36:22 +02:00
|
|
|
kDebug() << "empty actions";
|
2007-07-31 02:20:19 +02:00
|
|
|
return QList<QAction*>();
|
|
|
|
}
|
|
|
|
|
2007-07-27 00:58:30 +02:00
|
|
|
QColor Applet::color() const
|
|
|
|
{
|
|
|
|
// TODO: add more colors for more categories and
|
|
|
|
// maybe read from config?
|
2007-07-28 23:07:18 +02:00
|
|
|
QString c = category();
|
2007-07-29 06:36:38 +02:00
|
|
|
int alpha = 200;
|
2007-07-28 23:07:18 +02:00
|
|
|
// Colors taken from Oxygen color palette
|
|
|
|
if (c == "Date and Time") {
|
|
|
|
return QColor(191, 94, 0, alpha);
|
|
|
|
} else if (c == "Environment & Weather") {
|
|
|
|
return QColor(191, 0, 0, alpha);
|
|
|
|
} else if (c == "Examples") {
|
|
|
|
return QColor(204, 0, 154, alpha);
|
|
|
|
} else if (c == "File System") {
|
|
|
|
return QColor(90, 0, 179, alpha);
|
|
|
|
} else if (c == "Graphics") {
|
|
|
|
return QColor(0, 0, 255, alpha);
|
|
|
|
} else if (c == "Language") {
|
|
|
|
return QColor(0, 191, 0, alpha);
|
|
|
|
} else if (c == "Mapping") {
|
|
|
|
return QColor(191, 245, 0, alpha);
|
|
|
|
} else if (c == "Online Services") {
|
|
|
|
return QColor(255, 213, 0, alpha);
|
|
|
|
} else if (c == "System Information") {
|
|
|
|
return QColor(0, 196, 204, alpha);
|
|
|
|
} else if (c == "Windows and Tasks") {
|
|
|
|
return QColor(255, 126, 0, alpha);
|
2007-07-27 00:58:30 +02:00
|
|
|
} else {
|
2007-07-28 23:07:18 +02:00
|
|
|
return QColor(136, 136, 136, alpha);
|
2007-07-27 00:58:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-10 20:50:36 +02:00
|
|
|
void Applet::paintWidget(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-06-22 22:28:42 +02:00
|
|
|
{
|
2007-07-24 23:04:31 +02:00
|
|
|
Q_UNUSED(widget)
|
2007-08-05 10:41:55 +02:00
|
|
|
if (d->shadow && d->shadow->shadowedSize() != boundingRect().size()) {
|
|
|
|
//kDebug() << "sizes are " << d->shadow->shadowedSize() << boundingRect().size();
|
|
|
|
d->shadow->generate();
|
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
//qreal zoomLevel = painter->transform().m11() / transform().m11();
|
2007-08-05 16:24:24 +02:00
|
|
|
//kDebug() << "qreal " << zoomLevel << " = " << painter->transform().m11() << " / " << transform().m11();
|
2007-08-28 20:49:44 +02:00
|
|
|
//if (fabs(zoomLevel - scalingFactor(Plasma::DesktopZoom)) < std::numeric_limits<double>::epsilon()) { // Show Desktop
|
2007-07-26 01:42:43 +02:00
|
|
|
if (d->background) {
|
|
|
|
d->paintBackground(painter, this);
|
|
|
|
}
|
2007-07-24 23:04:31 +02:00
|
|
|
|
2007-08-03 17:23:56 +02:00
|
|
|
if (!d->failed && !d->needsConfig) {
|
|
|
|
paintInterface(painter, option, QRect(QPoint(0,0), d->contentSize(this).toSize()));
|
2007-07-26 01:42:43 +02:00
|
|
|
}
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2007-07-26 01:42:43 +02:00
|
|
|
d->paintHover(painter, this);
|
2007-08-28 20:49:44 +02:00
|
|
|
/*} else if (fabs(zoomLevel - scalingFactor(Plasma::GroupZoom)) < std::numeric_limits<double>::epsilon()) {
|
2007-08-05 16:24:24 +02:00
|
|
|
// Show Groups + Applet outline
|
2007-07-26 01:42:43 +02:00
|
|
|
//TODO: make pretty.
|
2007-07-27 00:58:30 +02:00
|
|
|
painter->setBrush(QBrush(color(), Qt::SolidPattern));
|
2007-07-29 06:36:38 +02:00
|
|
|
painter->drawRoundRect(boundingRect());
|
2007-10-01 17:09:41 +02:00
|
|
|
int iconDim = KIconLoader::global()->currentSize(KIconLoader::Desktop);
|
2007-08-17 17:05:01 +02:00
|
|
|
qreal midX = (boundingRect().width() / 2) - (iconDim / 2);
|
|
|
|
qreal midY = (boundingRect().height() / 2) - (iconDim / 2);
|
2007-08-24 09:14:24 +02:00
|
|
|
KIcon ico(icon());
|
|
|
|
ico.paint(painter, (int)midX, (int)midY, iconDim, iconDim);
|
2007-08-28 20:49:44 +02:00
|
|
|
} else if (zoomLevel == scalingFactor(Plasma::OverviewZoom)) { //Show Groups only
|
2007-07-26 01:42:43 +02:00
|
|
|
} */
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
|
|
|
|
2007-07-24 23:04:31 +02:00
|
|
|
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
|
|
const QRect & contentsRect)
|
2007-06-20 08:45:08 +02:00
|
|
|
{
|
2007-07-24 23:04:31 +02:00
|
|
|
Q_UNUSED(contentsRect)
|
2007-07-23 11:21:45 +02:00
|
|
|
|
|
|
|
if (d->scriptEngine) {
|
|
|
|
d->scriptEngine->paintInterface(painter, option);
|
2007-07-24 23:04:31 +02:00
|
|
|
} else {
|
2007-08-02 15:12:59 +02:00
|
|
|
//kDebug() << "Applet::paintInterface() default impl";
|
2007-07-23 11:21:45 +02:00
|
|
|
}
|
2007-06-20 08:45:08 +02:00
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
FormFactor Applet::formFactor() const
|
|
|
|
{
|
2007-09-18 23:22:45 +02:00
|
|
|
Containment* c = containment();
|
|
|
|
|
|
|
|
if (!c) {
|
2007-06-02 00:58:48 +02:00
|
|
|
return Plasma::Planar;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:22:45 +02:00
|
|
|
return c->formFactor();
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment* Applet::containment() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<Containment*>(parentItem());
|
2007-06-01 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Location Applet::location() const
|
|
|
|
{
|
2007-09-18 23:22:45 +02:00
|
|
|
Containment* c = containment();
|
|
|
|
|
|
|
|
if (!c) {
|
2007-06-02 00:58:48 +02:00
|
|
|
return Plasma::Desktop;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:22:45 +02:00
|
|
|
return c->location();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-25 21:15:23 +02:00
|
|
|
QSizeF Applet::contentSize() const
|
2007-09-01 14:34:22 +02:00
|
|
|
{
|
|
|
|
int top , left , right , bottom;
|
|
|
|
d->getBorderSize(left,top,right,bottom);
|
2007-09-18 23:22:45 +02:00
|
|
|
|
|
|
|
// qDebug() << "Geometry size: " << geometry().size();
|
|
|
|
// qDebug() << "Borders: " << left << top << right << bottom;
|
2007-09-01 14:34:22 +02:00
|
|
|
|
|
|
|
return geometry().size() - QSizeF(left+right,top+bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Applet::contentSizeHint() const
|
2007-07-24 23:04:31 +02:00
|
|
|
{
|
2007-07-29 01:41:40 +02:00
|
|
|
if (layout()) {
|
|
|
|
return layout()->sizeHint();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QSizeF(0, 0);
|
2007-07-24 23:04:31 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
QString Applet::globalName() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.service()->library();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::instanceName() const
|
|
|
|
{
|
2007-07-31 03:11:25 +02:00
|
|
|
return d->instanceName();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-03-01 02:09:20 +01:00
|
|
|
void Applet::watchForFocus(QObject *widget, bool watch)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !widget ) {
|
2005-12-29 22:55:22 +01:00
|
|
|
return;
|
2007-03-03 02:41:27 +01:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
int index = d->watchedForFocus.indexOf(widget);
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( watch ) {
|
|
|
|
if ( index == -1 ) {
|
|
|
|
d->watchedForFocus.append( widget );
|
|
|
|
widget->installEventFilter( this );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
2007-03-03 02:41:27 +01:00
|
|
|
} else if ( index != -1 ) {
|
|
|
|
d->watchedForFocus.removeAt( index );
|
|
|
|
widget->removeEventFilter( this );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
void Applet::needsFocus(bool focus)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-05-24 22:01:12 +02:00
|
|
|
if (focus == QGraphicsItem::hasFocus()) {
|
2005-12-29 22:55:22 +01:00
|
|
|
return;
|
2007-03-03 02:41:27 +01:00
|
|
|
}
|
2005-12-29 22:55:22 +01:00
|
|
|
|
|
|
|
emit requestFocus(focus);
|
|
|
|
}
|
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
bool Applet::hasConfigurationInterface()
|
|
|
|
{
|
|
|
|
return d->hasConfigurationInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
|
|
|
d->hasConfigurationInterface = hasInterface;
|
|
|
|
}
|
|
|
|
|
2007-03-03 02:41:27 +01:00
|
|
|
bool Applet::eventFilter( QObject *o, QEvent * e )
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( !d->watchedForFocus.contains( o ) )
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-03-03 02:41:27 +01:00
|
|
|
if ( e->type() == QEvent::MouseButtonRelease ||
|
|
|
|
e->type() == QEvent::FocusIn ) {
|
|
|
|
needsFocus( true );
|
|
|
|
} else if ( e->type() == QEvent::FocusOut ) {
|
|
|
|
needsFocus( false );
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
return QObject::eventFilter(o, e);
|
|
|
|
}
|
|
|
|
|
2007-07-02 12:58:03 +02:00
|
|
|
void Applet::showConfigurationInterface()
|
2007-07-02 12:47:34 +02:00
|
|
|
{
|
2007-07-30 18:00:29 +02:00
|
|
|
if (d->package && d->configXml) {
|
|
|
|
QString uiFile = d->package->filePath("mainconfigui");
|
|
|
|
if (uiFile.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigDialog *dialog = new KConfigDialog(0, "", d->configXml);
|
|
|
|
dialog->setWindowTitle(i18n("%1 Settings", name()));
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
QUiLoader loader;
|
|
|
|
QString filename = d->package->filePath("mainconfigui");
|
|
|
|
QFile f(filename);
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) {
|
|
|
|
delete dialog;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *w = loader.load(&f);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
|
|
|
|
dialog->show();
|
|
|
|
}
|
2007-07-02 12:47:34 +02:00
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
KPluginInfo::List Applet::knownApplets(const QString &category,
|
|
|
|
const QString &parentApp)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
|
|
|
}
|
|
|
|
|
2007-07-18 00:26:18 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
2007-08-05 15:01:09 +02:00
|
|
|
if (category == "Miscellaneous") {
|
2007-07-18 00:26:18 +02:00
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2007-07-17 23:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2007-08-02 15:12:59 +02:00
|
|
|
//kDebug() << "Applet::knownApplets constraint was '" << constraint << "' which got us " << offers.count() << " matches";
|
2007-05-24 22:01:12 +02:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2007-07-31 12:56:05 +02:00
|
|
|
KPluginInfo::List Applet::knownAppletsForMimetype(const QString &mimetype)
|
2007-07-31 12:52:05 +02:00
|
|
|
{
|
2007-08-05 23:52:35 +02:00
|
|
|
QString constraint = QString("'%1' in MimeTypes").arg(mimetype);
|
|
|
|
//kDebug() << "knownAppletsForMimetype with" << mimetype << constraint;
|
2007-07-31 12:52:05 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
QStringList Applet::knownCategories(const QString &parentApp)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint = "exist [X-KDE-PluginInfo-Category]";
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append(" and not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2007-07-12 15:24:35 +02:00
|
|
|
QStringList categories;
|
|
|
|
foreach (KService::Ptr applet, offers) {
|
2007-07-17 23:30:27 +02:00
|
|
|
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
|
2007-08-05 10:41:55 +02:00
|
|
|
//kDebug() << " and we have " << appletCategory;
|
2007-07-17 23:30:27 +02:00
|
|
|
if (appletCategory.isEmpty()) {
|
2007-08-05 15:01:09 +02:00
|
|
|
if (!categories.contains(i18n("Miscellaneous"))) {
|
|
|
|
categories << i18n("Miscellaneous");
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
} else if (!categories.contains(appletCategory)) {
|
|
|
|
categories << appletCategory;
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
|
|
|
|
categories.sort();
|
2007-07-12 15:24:35 +02:00
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
Applet* Applet::loadApplet(const QString& appletName, uint appletId, const QVariantList& args)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
//TODO: what would be -really- cool is offer to try and download the applet
|
|
|
|
// from the network at this point
|
2007-08-02 15:12:59 +02:00
|
|
|
kDebug() << "Applet::loadApplet: offers is empty for \"" << appletName << "\"";
|
2007-05-24 22:01:12 +02:00
|
|
|
return 0;
|
2007-10-26 03:06:03 +02:00
|
|
|
} /* else if (offers.count() > 1) {
|
2007-10-11 10:36:22 +02:00
|
|
|
kDebug() << "hey! we got more than one! let's blindly take the first one";
|
2007-10-26 03:06:03 +02:00
|
|
|
} */
|
2007-05-24 22:01:12 +02:00
|
|
|
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = Private::nextId();
|
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
QVariantList allArgs;
|
|
|
|
allArgs << offers.first()->storageId() << appletId << args;
|
|
|
|
QString error;
|
2007-09-27 01:01:57 +02:00
|
|
|
Applet* applet = offers.first()->createInstance<Plasma::Applet>(0, allArgs, &error);
|
2007-05-24 22:01:12 +02:00
|
|
|
|
|
|
|
if (!applet) {
|
2007-08-29 04:33:22 +02:00
|
|
|
kDebug() << "Couldn't load applet \"" << appletName << "\"! reason given: " << error;
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return applet;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
Applet* Applet::loadApplet(const KPluginInfo& info, uint appletId, const QVariantList& args)
|
2007-05-24 22:51:59 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!info.isValid()) {
|
2007-05-24 22:51:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return loadApplet(info.pluginName(), appletId, args);
|
2007-05-24 22:51:59 +02:00
|
|
|
}
|
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
void Applet::setShadowShown(bool shown)
|
|
|
|
{
|
|
|
|
//There are various problems with shadows right now:
|
|
|
|
//
|
|
|
|
//1) shadows can be seen through translucent areas, which is probably technically correct ubt
|
|
|
|
//looks odd
|
|
|
|
//2) the shape of the item odesn't conform to the shape of the standard background, e.g. with
|
|
|
|
//rounded corners
|
|
|
|
#ifdef DYNAMIC_SHADOWS
|
|
|
|
if (shown) {
|
|
|
|
if (d->shadow) {
|
|
|
|
d->shadow->setVisible(true);
|
|
|
|
} else {
|
|
|
|
d->shadow = new ShadowItem(this);
|
|
|
|
if (scene()) {
|
|
|
|
scene()->addItem(d->shadow);
|
|
|
|
d->shadow->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete d->shadow;
|
|
|
|
d->shadow = 0;
|
|
|
|
}
|
2007-08-17 17:05:01 +02:00
|
|
|
#else
|
|
|
|
Q_UNUSED(shown);
|
2007-08-05 10:41:55 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isShadowShown() const
|
|
|
|
{
|
|
|
|
return d->shadow && d->shadow->isVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
if (!d->shadow) {
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (change) {
|
|
|
|
case ItemPositionChange:
|
|
|
|
d->shadow->adjustPosition();
|
|
|
|
break;
|
|
|
|
case ItemSceneChange: {
|
|
|
|
QGraphicsScene *newScene = qvariant_cast<QGraphicsScene*>(value);
|
|
|
|
if (d->shadow->scene())
|
|
|
|
d->shadow->scene()->removeItem(d->shadow);
|
|
|
|
if (newScene) {
|
|
|
|
newScene->addItem(d->shadow);
|
|
|
|
d->shadow->generate();
|
|
|
|
d->shadow->adjustPosition();
|
|
|
|
d->shadow->show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ItemVisibleChange:
|
|
|
|
d->shadow->setVisible(isVisible());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return QGraphicsItem::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2007-09-28 07:46:37 +02:00
|
|
|
void Applet::setGeometry(const QRectF& geometry)
|
|
|
|
{
|
2007-10-11 21:16:01 +02:00
|
|
|
if (geometry.size().width() > 0 && geometry.size().height() > 0 && size() != geometry.size()) {
|
2007-09-28 07:46:37 +02:00
|
|
|
prepareGeometryChange();
|
|
|
|
qreal width = qBound(minimumSize().width(), geometry.size().width(), maximumSize().width());
|
|
|
|
qreal height = qBound(minimumSize().height(), geometry.size().height(), maximumSize().height());
|
|
|
|
|
|
|
|
setSize(QSizeF(width, height));
|
|
|
|
|
|
|
|
if (layout()) {
|
|
|
|
layout()->setGeometry(QRectF(QPoint(0, 0), contentSize()));
|
|
|
|
}
|
2007-11-04 06:31:18 +01:00
|
|
|
|
|
|
|
if (managingLayout()) {
|
|
|
|
managingLayout()->invalidate();
|
|
|
|
}
|
2007-09-28 07:46:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setPos(geometry.topLeft());
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-09-27 01:01:57 +02:00
|
|
|
void Applet::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
//kDebug() << "context menu event!";
|
|
|
|
if (!scene()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet* containment = dynamic_cast<Plasma::Applet*>(topLevelItem());
|
|
|
|
|
|
|
|
if (!containment) {
|
|
|
|
Widget::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we want to pass up the context menu event to the Containment at
|
|
|
|
// this point
|
|
|
|
containment->contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "applet.moc"
|