Add KarambaManager for easier loading of SuperKaramba themes

svn path=/trunk/KDE/kdebase/workspace/plasma/lib/; revision=670527
This commit is contained in:
Alexander Wiedenbruch 2007-06-01 21:32:03 +00:00
parent 7815a31298
commit 0de27801c9
5 changed files with 103 additions and 20 deletions

View File

@ -13,6 +13,7 @@ set(plasma_LIB_SRCS
plasma_export.h plasma_export.h
svg.cpp svg.cpp
theme.cpp theme.cpp
karambamanager.cpp
widgets/checkbox.cpp widgets/checkbox.cpp
widgets/icon.cpp widgets/icon.cpp
widgets/lineedit.cpp widgets/lineedit.cpp

View File

@ -32,6 +32,7 @@
#include "applet.h" #include "applet.h"
#include "dataengine.h" #include "dataengine.h"
#include "widgets/vboxlayout.h" #include "widgets/vboxlayout.h"
#include "karambamanager.h"
#ifdef ICON_DEMO #ifdef ICON_DEMO
#include "widgets/icon.h" #include "widgets/icon.h"
@ -40,9 +41,6 @@
#include "corona.h" #include "corona.h"
using namespace Plasma; using namespace Plasma;
extern "C" {
typedef QGraphicsItem* (*loadKaramba)(const KUrl &theme, QGraphicsView *view);
}
namespace Plasma namespace Plasma
{ {
@ -116,23 +114,6 @@ void Corona::init()
kDebug() << "=========================" << endl; kDebug() << "=========================" << endl;
*/ */
// Loading SuperKaramba themes example
/*
QString karambaLib = QFile::encodeName(KLibLoader::self()->findLibrary(QLatin1String("libsuperkaramba")));
KLibLoader* loader = KLibLoader::self();
KLibrary* lib = loader->library(karambaLib);
if (lib) {
loadKaramba startKaramba = 0;
startKaramba = (loadKaramba)lib->resolveFunction("startKaramba");
if (startKaramba) {
startKaramba(KUrl("~/themes/aero_aio.skz"), this);
}
lib->unload();
}
*/
// connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayContextMenu(QPoint))); // connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(displayContextMenu(QPoint)));
d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this); d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer(bool))); connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer(bool)));
@ -205,6 +186,16 @@ void Corona::addPlasmoid(const QString& name)
} }
} }
void Corona::addKaramba(const KUrl& path)
{
QGraphicsItemGroup* karamba = KarambaManager::loadKaramba(path, this);
if (karamba) {
addItem(karamba);
} else {
kDebug() << "Karamba " << path << " could not be loaded." << endl;
}
}
void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event) void Corona::dragEnterEvent( QGraphicsSceneDragDropEvent *event)
{ {
kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)" << endl; kDebug() << "Corona::dragEnterEvent(QGraphicsSceneDragDropEvent* event)" << endl;

View File

@ -81,6 +81,13 @@ public Q_SLOTS:
*/ */
void addPlasmoid(const QString& name); void addPlasmoid(const QString& name);
/**
* Adds a SuperKaramba theme to the scene
*
* @param path the path to the theme file
*/
void addKaramba(const KUrl& path);
protected: protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent* event); void dragEnterEvent(QGraphicsSceneDragDropEvent* event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent* event); void dragLeaveEvent(QGraphicsSceneDragDropEvent* event);

48
karambamanager.cpp Normal file
View File

@ -0,0 +1,48 @@
/*
* Copyright (C) 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 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.,
* 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 << endl;
}
return karamba;
}
#include "karambamanager.moc"

36
karambamanager.h Normal file
View File

@ -0,0 +1,36 @@
/*
* Copyright (C) 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 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KARAMBA_MANAGER_H
#define KARAMBA_MANAGER_H
#include <QObject>
#include <QGraphicsScene>
#include <KUrl>
extern "C" {
typedef QGraphicsItemGroup* (*startKaramba)(const KUrl &theme, QGraphicsView *view);
}
class KarambaManager
{
public:
static QGraphicsItemGroup* loadKaramba(const KUrl &themePath, QGraphicsScene *scene);
};
#endif