diff --git a/Makefile.am b/Makefile.am index 1309e4797..bd594f888 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = $(all_includes) KDE_CXXFLAGS = -UQT3_SUPPORT lib_LTLIBRARIES = libplasma.la -libplasma_la_SOURCES = appletinfo.cpp +libplasma_la_SOURCES = appletinfo.cpp plasma.cpp applet.cpp appletChain.cpp libplasma_la_METASOURCES = AUTO @@ -11,9 +11,9 @@ libplasma_la_LIBADD = $(LIB_KIO) libplasma_la_includedir = $(includedir)/plasma -noinst_HEADERS = +noinst_HEADERS = -libplasma_la_include_HEADERS = appletinfo.h +libplasma_la_include_HEADERS = appletinfo.h applet.h plasma.h #kde_kcfg_DATA = plasmaSettings.kcfg extensionSettings.kcfg diff --git a/applet.cpp b/applet.cpp new file mode 100644 index 000000000..f71318d71 --- /dev/null +++ b/applet.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +#include + +#include "applet.h" + +namespace Plasma +{ + +class Applet::Private +{ + public: + Private(KService::Ptr appletDescription, int uniqueID, + const AppletChain::Ptr appletChain) + : id(uniqueID), + globalConfig(0), + appletConfig(0), + appletDescription(appletDescription), + chain(appletChain) + { } + +// ~Private() +// { +// } + + int id; + KSharedConfig::Ptr globalConfig; + KSharedConfig::Ptr appletConfig; + KService::Ptr appletDescription; + QList watchedForFocus; + AppletChain::Ptr chain; +}; + +Applet::Applet(QWidget* parent, + KService::Ptr appletDescription, + const AppletChain::Ptr chain, + int id) + : QWidget(parent), + d(new Private(appletDescription, id, chain)) +{ +} + +Applet::~Applet() +{ + needsFocus(false); + delete d; +} + +KSharedConfig::Ptr Applet::globalAppletConfig() const +{ + if (!d->globalConfig) + { + QString file = locateLocal("config", + "plasma_" + globalName() + "rc", + true); + d->globalConfig = KSharedConfig::openConfig(file, false, true); + } + + return d->globalConfig; +} + +KSharedConfig::Ptr Applet::appletConfig() const +{ + if (!d->appletConfig) + { + QString file = locateLocal("appdata", + "applets/" + instanceName() + "rc", + true); + d->appletConfig = KSharedConfig::openConfig(file, false, true); + } + + return d->appletConfig; +} + +const AppletChain::Ptr Applet::chain() const +{ + return d->chain; +} + +void Applet::setChain(const AppletChain::Ptr appletChain) +{ + d->chain = appletChain; +} + +void Applet::constraintsUpdated() +{ +} + +QString Applet::globalName() const +{ + return d->appletDescription->library(); +} + +QString Applet::instanceName() const +{ + return d->appletDescription->library() + QString::number(d->id); +} + +void Applet::watchForFocus(QWidget* widget, bool watch) +{ + if (!widget) + { + return; + } + + int index = d->watchedForFocus.indexOf(widget); + if (watch) + { + if (index == -1) + { + d->watchedForFocus.append(widget); + widget->installEventFilter(this); + } + } + else if (index != -1) + { + d->watchedForFocus.removeAt(index); + widget->removeEventFilter(this); + } +} + +void Applet::needsFocus(bool focus) +{ + if (focus == hasFocus()) + { + return; + } + + emit requestFocus(focus); +} + +bool Applet::eventFilter(QObject *o, QEvent * e) +{ + if (!d->watchedForFocus.contains(o)) + { + if (e->type() == QEvent::MouseButtonRelease || + e->type() == QEvent::FocusIn) + { + needsFocus(true); + } + else if (e->type() == QEvent::FocusOut) + { + needsFocus(false); + } + } + + return QWidget::eventFilter(o, e); +} + +} // Plasma namespace + +#include "applet.moc" diff --git a/applet.h b/applet.h new file mode 100644 index 000000000..35bf09945 --- /dev/null +++ b/applet.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef PLASMA_APPLET_H +#define PLASMA_APPLET_H + +#include + +#include +#include + +#include "plasma.h" +#include "appletChain.h" + +namespace Plasma +{ + +class KDE_EXPORT Applet : public QWidget +{ + Q_OBJECT + + public: + typedef QList List; + + Applet(QWidget* parent, + KService::Ptr appletDescription, + const AppletChain::Ptr chain, + int id); + ~Applet(); + + /** + * Returns the KConfig object to access the applets configuration. + * + * For unique applets this config object will write to a config file + * named \rc in the user's local %KDE directory. + * + * For normal applets this config object will write to an instance + * specific config file nameed \\rc + * in the user's local %KDE directory. + **/ + KSharedConfig::Ptr globalAppletConfig() const; + KSharedConfig::Ptr appletConfig() const; + + const AppletChain::Ptr chain() const; + void setChain(const AppletChain::Ptr); + + /* + * called when any of the geometry constraints have been updated + * this is always called prior to painting and should be used as an + * opportunity to layout the widget, calculate sizings, etc. + * @property constraint + */ + virtual void constraintsUpdated(); + + signals: + void requestFocus(bool focus); + + protected: + + QString globalName() const; + QString instanceName() const; + + /** + * Register widgets that can receive keyboard focus with this this method + * This call results in an eventFilter being places on the widget. + * @param widget the widget to watch for keyboard focus + * @param watch whether to start watching the widget, or to stop doing so + */ + void watchForFocus(QWidget* widget, bool watch = true); + + /** + * Call this whenever focus is needed or not needed. You do not have to + * call this method for widgets that have been registered with + * watchForFocus + * @see watchForFocus + * @param focus whether to or not to request focus + */ + void needsFocus(bool focus); + + + bool eventFilter(QObject *o, QEvent *e); + + private: + class Private; + Private* d; +}; + +} // Plasma namespace + +#endif // multiple inclusion guard diff --git a/appletChain.cpp b/appletChain.cpp new file mode 100644 index 000000000..1be64d631 --- /dev/null +++ b/appletChain.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "applet.h" +#include "appletChain.h" + +namespace Plasma +{ + +class AppletChain::Private +{ + public: + Private() + : popupDirection(Up), + constraint(Plasma::NoConstraint), + screenEdge(BottomEdge) + { + } + + + Direction popupDirection; + AppletConstraint constraint; + ScreenEdge screenEdge; + Applet::List applets; + + // configuration items kept in the display widget: + // - start coordinates and length for docked chain + // - dimensions for floating chain + // - display order of applets +}; + +AppletChain::AppletChain(QObject* parent) + : QObject(parent), + d(new Private()) +{ +} + +AppletChain::~AppletChain() +{ +} + +Plasma::AppletConstraint AppletChain::constraint() +{ + return d->constraint; +} + +void AppletChain::setConstraint(Plasma::AppletConstraint constraint) +{ + if (d->constraint == constraint) + { + return; + } + + d->constraint = constraint; + + foreach (Applet* applet, d->applets) + { + applet->constraintsUpdated(); + } +} + +void AppletChain::setScreenEdge(Plasma::ScreenEdge edge) +{ + d->screenEdge = edge; +} + +Plasma::ScreenEdge AppletChain::screenEdge() +{ + return d->screenEdge; +} + +Plasma::Direction AppletChain::popupDirection() const +{ + return Plasma::edgeToPopupDirection(d->screenEdge); +} + +} // Plasma namespace + +#include "appletChain.moc" diff --git a/appletChain.h b/appletChain.h new file mode 100644 index 000000000..6f8709ccc --- /dev/null +++ b/appletChain.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef PLASMA_APPLETCHAIN_H +#define PLASMA_APPLETCHAIN_H + +#include + +#include "plasma.h" + +namespace Plasma +{ + +class KDE_EXPORT AppletChain : public QObject, public KShared +{ + Q_OBJECT + Q_PROPERTY(AppletConstraint constraint READ constraint WRITE setConstraint) + + public: + typedef KSharedPtr Ptr; + + AppletChain(QObject* parent); + ~AppletChain(); + + Plasma::AppletConstraint constraint(); + void setConstraint(Plasma::AppletConstraint constraint); + Plasma::Direction popupDirection() const; + + void setScreenEdge(Plasma::ScreenEdge edge); + Plasma::ScreenEdge screenEdge(); + + + private: + class Private; + Private* d; +}; + +} // Plasma namespace + +#endif // multiple inclusion guard diff --git a/appletinfo.cpp b/appletinfo.cpp index 5f633adf6..39335fd23 100644 --- a/appletinfo.cpp +++ b/appletinfo.cpp @@ -19,9 +19,10 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ******************************************************************/ -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/plasma.cpp b/plasma.cpp new file mode 100644 index 000000000..b8c724129 --- /dev/null +++ b/plasma.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +namespace Plasma +{ + +int plasmaIDs = 0; + +void setMinID(int minID) +{ + plasmaIDs = minID + 1; +} + +int uniqueID() +{ + return ++plasmaIDs; +} + +Direction edgeToPopupDirection(ScreenEdge edge) +{ + switch (edge) + { + case Floating: + case Desktop: + case TopEdge: + return Down; + case BottomEdge: + return Up; + case LeftEdge: + return Right; + case RightEdge: + return Left; + } +} + +} // Plasma namespace diff --git a/plasma.h b/plasma.h new file mode 100644 index 000000000..c553d2076 --- /dev/null +++ b/plasma.h @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2005 by 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 version 2 as + * published by the Free Software Foundation + * + * 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., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef PLASMA_DEFS_H +#define PLASMA_DEFS_H + +#include + +namespace Plasma +{ + +enum AppletConstraint { NoConstraint = 0, + Width = 1, + Height = 2, + MaxAppletConstraint = Height }; + +enum Direction { Down = 0, + Up, + Left, + Right }; + +enum ScreenEdge { Floating = 0, Desktop, + TopEdge, BottomEdge, LeftEdge, RightEdge }; + +KDE_EXPORT void setMinID(int minID); +KDE_EXPORT int uniqueID(); +KDE_EXPORT Direction edgeToPopupDirection(ScreenEdge edge); + +} // Plasma namespace + +#endif // multiple inclusion guard