From ea4a368a4277ba31d2f8a5ebcc0d2dd588ae38ea Mon Sep 17 00:00:00 2001 From: Alexander Wiedenbruch Date: Fri, 12 Oct 2007 17:30:30 +0000 Subject: [PATCH] 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 --- CMakeLists.txt | 1 - appletbrowser.cpp | 10 ++- appletbrowser/plasmaappletitemmodel.cpp | 103 ++++++++++++++++++++---- appletbrowser/plasmaappletitemmodel_p.h | 8 +- containment.cpp | 24 ------ containment.h | 5 -- corona.cpp | 14 ---- corona.h | 7 -- karambamanager.cpp | 47 ----------- karambamanager.h | 39 --------- 10 files changed, 101 insertions(+), 157 deletions(-) delete mode 100644 karambamanager.cpp delete mode 100644 karambamanager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 762ebda82..1e3771d8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,6 @@ set(plasma_LIB_SRCS shadowitem.cpp svg.cpp theme.cpp - karambamanager.cpp uiloader.cpp widgets/boxlayout.cpp widgets/borderlayout.cpp diff --git a/appletbrowser.cpp b/appletbrowser.cpp index 73b3fb386..2338b2fae 100644 --- a/appletbrowser.cpp +++ b/appletbrowser.cpp @@ -79,6 +79,8 @@ void AppletBrowser::init() d->appletList = new KCategorizedItemsView(this); setMainWidget(d->appletList); + setWindowTitle("Add Applets"); + setButtons(KDialog::Apply | KDialog::Close | KDialog::User1); setButtonText(KDialog::Apply, i18n("Add Applet")); 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(); if (d->corona) { kDebug() << " to corona\n"; - d->corona->addApplet(selectedItem->pluginName()); + d->corona->addApplet(selectedItem->pluginName(), + selectedItem->arguments()); } else if (d->containment) { - kDebug() << " to conatainment\n"; - d->containment->addApplet(selectedItem->pluginName()); + kDebug() << " to containment\n"; + d->containment->addApplet(selectedItem->pluginName(), + selectedItem->arguments()); } } diff --git a/appletbrowser/plasmaappletitemmodel.cpp b/appletbrowser/plasmaappletitemmodel.cpp index 04140ce83..9214a37ff 100644 --- a/appletbrowser/plasmaappletitemmodel.cpp +++ b/appletbrowser/plasmaappletitemmodel.cpp @@ -19,22 +19,19 @@ #include "plasmaappletitemmodel_p.h" -PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const KPluginInfo& info, +PlasmaAppletItem::PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap& info, FilterFlags flags, QMap * extraAttrs) : QObject(model), m_model(model) { - QMap attrs; - attrs.insert("name", info.name()); - attrs.insert("pluginName", info.pluginName()); - attrs.insert("description", info.comment()); - attrs.insert("category", info.category()); + QMap attrs(info); + attrs.insert("favorite", flags & Favorite ? true : false); attrs.insert("used", flags & Used ? true : false); //attrs.insert("recommended", flags & Recommended ? true : false); if (extraAttrs) attrs.unite(* extraAttrs); - setText(info.name() + " - "+ info.category()); + setText(info["name"].toString() + " - "+ info["category"].toString()); setData(attrs); - setIcon(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon())); + setIcon(qvariant_cast(info["icon"])); } QString PlasmaAppletItem::name() const @@ -57,7 +54,19 @@ void PlasmaAppletItem::setFavorite(bool favorite) QMap attrs = data().toMap(); attrs.insert("favorite", favorite ? true : false); 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(attrs["arguments"])[0].toString(); + + m_model->setFavorite(pluginName + " - " + themePath, favorite); + } else { + m_model->setFavorite(pluginName, favorite); + } } bool PlasmaAppletItem::passesFiltering( @@ -66,6 +75,11 @@ bool PlasmaAppletItem::passesFiltering( return data().toMap()[filter.first] == filter.second; } +QVariantList PlasmaAppletItem::arguments() const +{ + return qvariant_cast(data().toMap()["arguments"]); +} + PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) : KCategorizedItemsViewModels::DefaultItemModel(parent), m_configGroup(configGroup) @@ -79,23 +93,37 @@ PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * i.next(); if (!rx.exactMatch(i.key())) continue; QString id = rx.cap(1); - + foreach (QString plugin, i.value().split(",")) { extraPluginAttrs[plugin]["recommended." + id] = true; } } 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() foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) { kDebug() << info.pluginName() << " is the name of the plugin\n"; - - appendRow(new PlasmaAppletItem(this, info, + + QMap 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(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon()))); + + appendRow(new PlasmaAppletItem(this, attrs, ((m_favorites.contains(info.pluginName())) ? PlasmaAppletItem::Favorite : PlasmaAppletItem::NoFilter) | ((m_used.contains(info.pluginName())) ? PlasmaAppletItem::Used : PlasmaAppletItem::NoFilter) , &(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; } -void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite) { +void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite) +{ if (favorite) { if (!m_favorites.contains(plugin)) { m_favorites.append(plugin); @@ -146,3 +175,47 @@ void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite) { m_configGroup.sync(); } + +/* + * Define function type to get the SuperKaramba themes + * from skapplet (see skapplet.cpp in kdeutils/superkaramba) + */ +extern "C" { + typedef QList > (*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 > themeMetadata = loadThemes(); + + QMap metadata; + foreach (metadata, themeMetadata) { + metadata.insert("pluginName", "skapplet"); + metadata.insert("category", "SuperKaramba"); + + QString favorite = info.pluginName() + " - " + qvariant_cast(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; + } +} + diff --git a/appletbrowser/plasmaappletitemmodel_p.h b/appletbrowser/plasmaappletitemmodel_p.h index 86fce01db..ee9e452eb 100644 --- a/appletbrowser/plasmaappletitemmodel_p.h +++ b/appletbrowser/plasmaappletitemmodel_p.h @@ -41,7 +41,7 @@ public: Q_DECLARE_FLAGS(FilterFlags, FilterFlag) - PlasmaAppletItem(PlasmaAppletItemModel * model, const KPluginInfo& info, + PlasmaAppletItem(PlasmaAppletItemModel * model, const QMap& info, FilterFlags flags = NoFilter, QMap * extraAttrs = NULL); virtual QString name() const; @@ -50,6 +50,8 @@ public: virtual void setFavorite(bool favorite); virtual bool passesFiltering( const KCategorizedItemsViewModels::Filter & filter) const; + virtual QVariantList arguments() const; + private: PlasmaAppletItemModel * m_model; }; @@ -68,8 +70,10 @@ public: private: QStringList m_favorites; + QStringList m_used; KConfigGroup m_configGroup; - + + void loadSuperKarambaThemes(const KPluginInfo &info); }; Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags) diff --git a/containment.cpp b/containment.cpp index f8b934792..17ff152a0 100644 --- a/containment.cpp +++ b/containment.cpp @@ -36,7 +36,6 @@ #include #include "corona.h" -#include "karambamanager.h" #include "phase.h" #include "svg.h" @@ -210,18 +209,6 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) } QPointF point = event->scenePos(); - /* - * example for displaying the SuperKaramba context menu - QGraphicsItem *item = itemAt(point); - if(item) { - QObject *object = dynamic_cast(item->parentItem()); - if(object && object->objectName().startsWith("karamba")) { - QContextMenuEvent event(QContextMenuEvent::Mouse, point); - contextMenuEvent(&event); - return; -} -} - */ QGraphicsItem* item = scene()->itemAt(point); if (item == this) { item = 0; @@ -425,17 +412,6 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui 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) { // we do a static_cast here since it really isn't an Applet by this diff --git a/containment.h b/containment.h index 0aca77e8d..89b524f7a 100644 --- a/containment.h +++ b/containment.h @@ -195,11 +195,6 @@ class PLASMA_EXPORT Containment : public Applet */ void saveConstraints(KConfigGroup* group) const; - /** - * Adds a Superkaramba theme to this Containment - */ - void addKaramba(const KUrl& path); - /** * @internal */ diff --git a/corona.cpp b/corona.cpp index c0dd4bb0e..3284d033a 100644 --- a/corona.cpp +++ b/corona.cpp @@ -36,7 +36,6 @@ #include "containment.h" #include "dataengine.h" -#include "karambamanager.h" #include "phase.h" #include "widgets/freelayout.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); } -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) { // kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)"; diff --git a/corona.h b/corona.h index e06626685..1eea1efec 100644 --- a/corona.h +++ b/corona.h @@ -145,13 +145,6 @@ public Q_SLOTS: */ QList 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 */ diff --git a/karambamanager.cpp b/karambamanager.cpp deleted file mode 100644 index 4b4c46de9..000000000 --- a/karambamanager.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2007 Alexander Wiedenbruch - * - * 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 - -#include -#include -#include - -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; -} - diff --git a/karambamanager.h b/karambamanager.h deleted file mode 100644 index 80e5ff7f1..000000000 --- a/karambamanager.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2007 Alexander Wiedenbruch - * - * 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 -#include - -#include - -#include - -extern "C" { - typedef QGraphicsItemGroup* (*startKaramba)(const KUrl &theme, QGraphicsView *view); -} - -namespace KarambaManager -{ -PLASMA_EXPORT QGraphicsItemGroup* loadKaramba(const KUrl &themePath, QGraphicsScene *scene); -} - -#endif