add support for filtering applets based on specified application. useful for non-plasma targets (e.g. amarok). default behavious remains the same.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=733292
This commit is contained in:
Leo Franchi 2007-11-06 02:45:24 +00:00
parent 0f889fd7c8
commit 845139ae0a
4 changed files with 47 additions and 18 deletions

View File

@ -36,17 +36,19 @@ namespace Plasma
class AppletBrowser::Private
{
public:
Private(Corona* co, Containment* cont, AppletBrowser* q)
: corona(co),
Private(Corona* co, Containment* cont, AppletBrowser* q, const QString& app)
: application( app ),
corona(co),
containment(cont),
appletList(0),
config("plasmarc"),
configGroup(&config, "Applet Browser"),
itemModel(configGroup, q),
itemModel(configGroup, app, q),
filterModel(q)
{
}
QString application;
Plasma::Corona *corona;
Plasma::Containment *containment;
KCategorizedItemsView *appletList;
@ -58,16 +60,16 @@ public:
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
};
AppletBrowser::AppletBrowser(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
AppletBrowser::AppletBrowser(Plasma::Corona * corona, const QString& application, QWidget * parent, Qt::WindowFlags f)
: KDialog(parent, f),
d(new Private(corona, 0, this))
d(new Private(corona, 0, this, application))
{
init();
}
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
AppletBrowser::AppletBrowser(Plasma::Containment * containment, const QString& application, QWidget * parent, Qt::WindowFlags f)
: KDialog(parent, f),
d(new Private(0, containment, this))
d(new Private(0, containment, this, application))
{
init();
}
@ -126,13 +128,13 @@ void AppletBrowser::init()
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
d->filterModel.addSeparator(i18n("Categories:"));
// Filters: Categories
foreach (const QString& category, Plasma::Applet::knownCategories()) {
foreach (const QString& category, Plasma::Applet::knownCategories(d->application)) {
d->filterModel.addFilter(category,
KCategorizedItemsViewModels::Filter("category", category));
KCategorizedItemsViewModels::Filter("category", category));
}
d->appletList->setFilterModel(&d->filterModel);
// Other models
@ -144,6 +146,17 @@ AppletBrowser::~AppletBrowser()
delete d;
}
void AppletBrowser::setApplication( const QString& app )
{
d->application = app;
d->itemModel.setApplication( app );
}
QString AppletBrowser::Application()
{
return d->application;
}
void AppletBrowser::addApplet()
{
kDebug() << "Button ADD clicked";

View File

@ -34,10 +34,13 @@ class PLASMA_EXPORT AppletBrowser: public KDialog
{
Q_OBJECT
public:
explicit AppletBrowser(Plasma::Corona *corona, QWidget *parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowser(Plasma::Containment *containment, QWidget *parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowser(Plasma::Corona *corona, const QString& app = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowser(Plasma::Containment *containment, const QString& = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
virtual ~AppletBrowser();
void setApplication( const QString& application );
QString Application();
protected Q_SLOTS:
/**
* Adds currently selected applets

View File

@ -80,8 +80,9 @@ QVariantList PlasmaAppletItem::arguments() const
return qvariant_cast<QVariantList>(data().toMap()["arguments"]);
}
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) :
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QString app, QObject * parent) :
KCategorizedItemsViewModels::DefaultItemModel(parent),
m_application( app ),
m_configGroup(configGroup)
{
@ -103,7 +104,7 @@ PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject *
m_used = m_configGroup.readEntry("used").split(",");
//TODO: get recommended, favorit, used, etc out of knownApplets()
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) {
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets( QString(), m_application)) {
//kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool();
if (info.property("NoDisplay").toBool()) {
// we don't want to show the hidden category
@ -181,6 +182,16 @@ void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite)
}
void PlasmaAppletItemModel::setApplication(const QString& app)
{
m_application = app;
}
QString& PlasmaAppletItemModel::Application()
{
return m_application;
}
/*
* Define function type to get the SuperKaramba themes
* from skapplet (see skapplet.cpp in kdeutils/superkaramba)
@ -223,4 +234,3 @@ void PlasmaAppletItemModel::loadSuperKarambaThemes(const KPluginInfo &info)
kWarning() << "Could not load" << libName;
}
}

View File

@ -60,15 +60,18 @@ class PlasmaAppletItemModel :
public KCategorizedItemsViewModels::DefaultItemModel
{
public:
PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent = 0);
PlasmaAppletItemModel(KConfigGroup configGroup, QString parentApp = QString(), QObject * parent = 0);
QStringList mimeTypes() const;
QMimeData* mimeData(const QModelIndexList & indexes) const;
void setFavorite(QString plugin, bool favorite);
void setApplication(const QString& app);
QString& Application();
private:
QString m_application;
QStringList m_favorites;
QStringList m_used;
KConfigGroup m_configGroup;