The integration of SuperKaramba into Plasma is now done

by the SuperKaramba Plasma Applet alone that comes with SuperKaramba itself.

- Remove all previous functions to load SuperKaramba themes
- Add special code into applet browser to handle the theme loading

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=724563
This commit is contained in:
Alexander Wiedenbruch 2007-10-12 17:30:30 +00:00
parent f22a71a22d
commit ea4a368a42
10 changed files with 101 additions and 157 deletions

View File

@ -37,7 +37,6 @@ set(plasma_LIB_SRCS
shadowitem.cpp shadowitem.cpp
svg.cpp svg.cpp
theme.cpp theme.cpp
karambamanager.cpp
uiloader.cpp uiloader.cpp
widgets/boxlayout.cpp widgets/boxlayout.cpp
widgets/borderlayout.cpp widgets/borderlayout.cpp

View File

@ -79,6 +79,8 @@ void AppletBrowser::init()
d->appletList = new KCategorizedItemsView(this); d->appletList = new KCategorizedItemsView(this);
setMainWidget(d->appletList); setMainWidget(d->appletList);
setWindowTitle("Add Applets");
setButtons(KDialog::Apply | KDialog::Close | KDialog::User1); setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
setButtonText(KDialog::Apply, i18n("Add Applet")); setButtonText(KDialog::Apply, i18n("Add Applet"));
setButtonText(KDialog::User1, i18n("Get New Applets")); //TODO: not overly happy with this text setButtonText(KDialog::User1, i18n("Get New Applets")); //TODO: not overly happy with this text
@ -151,10 +153,12 @@ void AppletBrowser::addApplet()
kDebug() << "Adding applet " << selectedItem->name(); kDebug() << "Adding applet " << selectedItem->name();
if (d->corona) { if (d->corona) {
kDebug() << " to corona\n"; kDebug() << " to corona\n";
d->corona->addApplet(selectedItem->pluginName()); d->corona->addApplet(selectedItem->pluginName(),
selectedItem->arguments());
} else if (d->containment) { } else if (d->containment) {
kDebug() << " to conatainment\n"; kDebug() << " to containment\n";
d->containment->addApplet(selectedItem->pluginName()); d->containment->addApplet(selectedItem->pluginName(),
selectedItem->arguments());
} }
} }

View File

@ -19,22 +19,19 @@
#include "plasmaappletitemmodel_p.h" #include "plasmaappletitemmodel_p.h"
PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const KPluginInfo& info, PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap<QString, QVariant>& info,
FilterFlags flags, QMap<QString, QVariant> * extraAttrs) : FilterFlags flags, QMap<QString, QVariant> * extraAttrs) :
QObject(model), m_model(model) QObject(model), m_model(model)
{ {
QMap<QString, QVariant> attrs; QMap<QString, QVariant> attrs(info);
attrs.insert("name", info.name());
attrs.insert("pluginName", info.pluginName());
attrs.insert("description", info.comment());
attrs.insert("category", info.category());
attrs.insert("favorite", flags & Favorite ? true : false); attrs.insert("favorite", flags & Favorite ? true : false);
attrs.insert("used", flags & Used ? true : false); attrs.insert("used", flags & Used ? true : false);
//attrs.insert("recommended", flags & Recommended ? true : false); //attrs.insert("recommended", flags & Recommended ? true : false);
if (extraAttrs) attrs.unite(* extraAttrs); if (extraAttrs) attrs.unite(* extraAttrs);
setText(info.name() + " - "+ info.category()); setText(info["name"].toString() + " - "+ info["category"].toString());
setData(attrs); setData(attrs);
setIcon(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon())); setIcon(qvariant_cast<QIcon>(info["icon"]));
} }
QString PlasmaAppletItem::name() const QString PlasmaAppletItem::name() const
@ -57,7 +54,19 @@ void PlasmaAppletItem::setFavorite(bool favorite)
QMap<QString, QVariant> attrs = data().toMap(); QMap<QString, QVariant> attrs = data().toMap();
attrs.insert("favorite", favorite ? true : false); attrs.insert("favorite", favorite ? true : false);
setData(QVariant(attrs)); setData(QVariant(attrs));
m_model->setFavorite(attrs["pluginName"].toString(), favorite);
QString pluginName = attrs["pluginName"].toString();
if (pluginName == "skapplet" && attrs.contains("arguments")) {
// skapplet can be used with all SuperKaramba themes,
// so when setting skapplet as favorite it is also
// necessary to know which theme is meant
QString themePath = qvariant_cast<QVariantList>(attrs["arguments"])[0].toString();
m_model->setFavorite(pluginName + " - " + themePath, favorite);
} else {
m_model->setFavorite(pluginName, favorite);
}
} }
bool PlasmaAppletItem::passesFiltering( bool PlasmaAppletItem::passesFiltering(
@ -66,6 +75,11 @@ bool PlasmaAppletItem::passesFiltering(
return data().toMap()[filter.first] == filter.second; return data().toMap()[filter.first] == filter.second;
} }
QVariantList PlasmaAppletItem::arguments() const
{
return qvariant_cast<QVariantList>(data().toMap()["arguments"]);
}
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) : PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) :
KCategorizedItemsViewModels::DefaultItemModel(parent), KCategorizedItemsViewModels::DefaultItemModel(parent),
m_configGroup(configGroup) m_configGroup(configGroup)
@ -86,16 +100,30 @@ PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject *
} }
m_favorites = m_configGroup.readEntry("favorites").split(","); m_favorites = m_configGroup.readEntry("favorites").split(",");
QStringList m_used = m_configGroup.readEntry("used").split(","); m_used = m_configGroup.readEntry("used").split(",");
//TODO: get recommended, favorit, used, etc out of knownApplets() //TODO: get recommended, favorit, used, etc out of knownApplets()
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) { foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) {
kDebug() << info.pluginName() << " is the name of the plugin\n"; kDebug() << info.pluginName() << " is the name of the plugin\n";
appendRow(new PlasmaAppletItem(this, info, QMap<QString, QVariant> attrs;
attrs.insert("name", info.name());
attrs.insert("pluginName", info.pluginName());
attrs.insert("description", info.comment());
attrs.insert("category", info.category());
attrs.insert("icon", static_cast<QIcon>(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon())));
appendRow(new PlasmaAppletItem(this, attrs,
((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) | ((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) |
((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter) ((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter)
, &(extraPluginAttrs[info.pluginName()]))); , &(extraPluginAttrs[info.pluginName()])));
// If there is the SuperKaramba applet,
// add SuperKaramba themes to the
// model too
if (info.pluginName() == "skapplet") {
loadSuperKarambaThemes(info);
}
} }
} }
@ -132,7 +160,8 @@ QMimeData* PlasmaAppletItemModel::mimeData(const QModelIndexList & indexes) cons
return data; return data;
} }
void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite) { void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite)
{
if (favorite) { if (favorite) {
if (!m_favorites.contains(plugin)) { if (!m_favorites.contains(plugin)) {
m_favorites.append(plugin); m_favorites.append(plugin);
@ -146,3 +175,47 @@ void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite) {
m_configGroup.sync(); m_configGroup.sync();
} }
/*
* Define function type to get the SuperKaramba themes
* from skapplet (see skapplet.cpp in kdeutils/superkaramba)
*/
extern "C" {
typedef QList<QMap<QString, QVariant> > (*installedThemes)();
}
void PlasmaAppletItemModel::loadSuperKarambaThemes(const KPluginInfo &info)
{
KService::Ptr service = info.service();
QString libName = service->library();
// Load the Plugin as library to get access
// to installedThemes() in skapplet
KLibrary *lib = KLibLoader::self()->library(libName);
if (lib) {
installedThemes loadThemes = 0;
loadThemes = (installedThemes)lib->resolveFunction("installedThemes");
if (loadThemes) {
// loadThemes() returns the name, description, the icon
// and one argument (file path) from the theme
QList<QMap<QString, QVariant> > themeMetadata = loadThemes();
QMap <QString, QVariant> metadata;
foreach (metadata, themeMetadata) {
metadata.insert("pluginName", "skapplet");
metadata.insert("category", "SuperKaramba");
QString favorite = info.pluginName() + " - " + qvariant_cast<QVariantList>(metadata["arguments"])[0].toString();
appendRow(new PlasmaAppletItem(this, metadata,
((m_favorites.contains(favorite)) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) |
((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter)));
}
}
} else {
kWarning() << "Could not load" << libName;
}
}

View File

@ -41,7 +41,7 @@ public:
Q_DECLARE_FLAGS(FilterFlags, FilterFlag) Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
PlasmaAppletItem(PlasmaAppletItemModel * model, const KPluginInfo& info, PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap<QString, QVariant>& info,
FilterFlags flags = NoFilter, QMap<QString, QVariant> * extraAttrs = NULL); FilterFlags flags = NoFilter, QMap<QString, QVariant> * extraAttrs = NULL);
virtual QString name() const; virtual QString name() const;
@ -50,6 +50,8 @@ public:
virtual void setFavorite(bool favorite); virtual void setFavorite(bool favorite);
virtual bool passesFiltering( virtual bool passesFiltering(
const KCategorizedItemsViewModels::Filter & filter) const; const KCategorizedItemsViewModels::Filter & filter) const;
virtual QVariantList arguments() const;
private: private:
PlasmaAppletItemModel * m_model; PlasmaAppletItemModel * m_model;
}; };
@ -68,8 +70,10 @@ public:
private: private:
QStringList m_favorites; QStringList m_favorites;
QStringList m_used;
KConfigGroup m_configGroup; KConfigGroup m_configGroup;
void loadSuperKarambaThemes(const KPluginInfo &info);
}; };
Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags) Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags)

View File

@ -36,7 +36,6 @@
#include <KServiceTypeTrader> #include <KServiceTypeTrader>
#include "corona.h" #include "corona.h"
#include "karambamanager.h"
#include "phase.h" #include "phase.h"
#include "svg.h" #include "svg.h"
@ -210,18 +209,6 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
} }
QPointF point = event->scenePos(); QPointF point = event->scenePos();
/*
* example for displaying the SuperKaramba context menu
QGraphicsItem *item = itemAt(point);
if(item) {
QObject *object = dynamic_cast<QObject*>(item->parentItem());
if(object && object->objectName().startsWith("karamba")) {
QContextMenuEvent event(QContextMenuEvent::Mouse, point);
contextMenuEvent(&event);
return;
}
}
*/
QGraphicsItem* item = scene()->itemAt(point); QGraphicsItem* item = scene()->itemAt(point);
if (item == this) { if (item == this) {
item = 0; item = 0;
@ -425,17 +412,6 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui
return applet; return applet;
} }
void Containment::addKaramba(const KUrl& path)
{
QGraphicsItemGroup* karamba = KarambaManager::loadKaramba(path, scene());
if (karamba) {
karamba->setParentItem(this);
Phase::self()->animateItem(karamba, Phase::Appear);
} else {
kDebug() << "Karamba " << path << " could not be loaded.";
}
}
void Containment::appletDestroyed(QObject* object) void Containment::appletDestroyed(QObject* object)
{ {
// we do a static_cast here since it really isn't an Applet by this // we do a static_cast here since it really isn't an Applet by this

View File

@ -195,11 +195,6 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void saveConstraints(KConfigGroup* group) const; void saveConstraints(KConfigGroup* group) const;
/**
* Adds a Superkaramba theme to this Containment
*/
void addKaramba(const KUrl& path);
/** /**
* @internal * @internal
*/ */

View File

@ -36,7 +36,6 @@
#include "containment.h" #include "containment.h"
#include "dataengine.h" #include "dataengine.h"
#include "karambamanager.h"
#include "phase.h" #include "phase.h"
#include "widgets/freelayout.h" #include "widgets/freelayout.h"
#include "widgets/boxlayout.h" #include "widgets/boxlayout.h"
@ -301,19 +300,6 @@ Applet* Corona::addApplet(const QString& name, const QVariantList& args, uint id
return d->containments[0]->addApplet(name, args, id, geometry); return d->containments[0]->addApplet(name, args, id, geometry);
} }
void Corona::addKaramba(const KUrl& path)
{
//FIXME: i think this is slightly broken now that we have containments?
// it should go into a containment...
QGraphicsItemGroup* karamba = KarambaManager::loadKaramba(path, this);
if (karamba) {
addItem(karamba);
Phase::self()->animateItem(karamba, Phase::Appear);
} else {
kDebug() << "Karamba " << path << " could not be loaded.";
}
}
void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event) void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
{ {
// kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)"; // kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)";

View File

@ -145,13 +145,6 @@ public Q_SLOTS:
*/ */
QList<Containment*> containments() const; QList<Containment*> containments() const;
/**
* Adds a SuperKaramba theme to the scene
*
* @param path the path to the theme file
*/
void addKaramba(const KUrl& path);
/** /**
* Sets if the applets are Immutable * Sets if the applets are Immutable
*/ */

View File

@ -1,47 +0,0 @@
/*
* Copyright 2007 Alexander Wiedenbruch <wirr01@gmail.com>
*
* 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 "karambamanager.h"
#include <QFile>
#include <KLibLoader>
#include <KLibrary>
#include <KDebug>
QGraphicsItemGroup* KarambaManager::loadKaramba(const KUrl &themePath, QGraphicsScene *scene)
{
QString karambaLib = QFile::encodeName(KLibLoader::self()->findLibrary(QLatin1String("libsuperkaramba")));
QGraphicsItemGroup *karamba = 0;
KLibrary *lib = KLibLoader::self()->library(karambaLib);
if (lib) {
startKaramba createKaramba = 0;
createKaramba = (startKaramba)lib->resolveFunction("startKaramba");
if (createKaramba) {
karamba = createKaramba(themePath, scene->views()[0]);
}
} else {
kWarning() << "Could not load " << karambaLib ;
}
return karamba;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright 2007 Alexander Wiedenbruch <wirr01@gmail.com>
*
* 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.
*/
#ifndef KARAMBA_MANAGER_H
#define KARAMBA_MANAGER_H
#include <QtCore/QObject>
#include <QtGui/QGraphicsScene>
#include <KUrl>
#include <plasma/plasma_export.h>
extern "C" {
typedef QGraphicsItemGroup* (*startKaramba)(const KUrl &theme, QGraphicsView *view);
}
namespace KarambaManager
{
PLASMA_EXPORT QGraphicsItemGroup* loadKaramba(const KUrl &themePath, QGraphicsScene *scene);
}
#endif