Made recommended plugins configurable. The default 'Recommended by KDE' is removed and should be added to the default plasmarc file.

Example plasmarc section:

[Applet Browser]
recommended.kde.icon=help-about-kde
recommended.kde.caption=KDE
recommended.kde.plugins=digital-clock

recommended.debian.icon=debian-logo
recommended.debian.caption=Debian
recommended.debian.plugins=groupphoto

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=723162
This commit is contained in:
Ivan Čukić 2007-10-08 21:50:38 +00:00
parent 82b947252e
commit 9ef8749a7f
3 changed files with 59 additions and 56 deletions

View File

@ -21,6 +21,8 @@
#include <KAction>
#include <KStandardAction>
#include <KConfig>
#include <KConfigGroup>
#include "plasma/corona.h"
@ -38,17 +40,24 @@ public:
: corona(co),
containment(cont),
appletList(0),
itemModel(q),
config("plasmarc"),
configGroup(&config, "Applet Browser"),
itemModel(q, &configGroup),
filterModel(q)
{
}
Plasma::Corona *corona;
Plasma::Containment *containment;
KCategorizedItemsView *appletList;
KConfig config;
KConfigGroup configGroup;
PlasmaAppletItemModel itemModel;
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
};
AppletBrowser::AppletBrowser(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
@ -81,17 +90,35 @@ void AppletBrowser::init()
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
addAction(quit);
// Emblems
d->appletList->addEmblem(i18n("Recommended by KDE"), new KIcon("about-kde"),
KCategorizedItemsViewModels::Filter("recommended", true));
d->filterModel.addFilter(i18n("All applets"),
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
// Recommended emblems and filters
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]caption");
QMapIterator<QString, QString> i(d->configGroup.entryMap());
while (i.hasNext()) {
i.next();
if (!rx.exactMatch(i.key())) continue;
kDebug() << "These are the key/vals in rc file " << rx.cap(1) << "\n";
QString id = rx.cap(1);
QString caption = d->configGroup.readEntry("recommended." + id + ".caption");
QString icon = d->configGroup.readEntry("recommended." + id + ".icon");
QString plugins = d->configGroup.readEntry("recommended." + id + ".plugins");
d->appletList->addEmblem(i18n("Recommended by %1", caption), new KIcon(icon),
KCategorizedItemsViewModels::Filter("recommended." + id, true));
d->filterModel.addFilter(i18n("Recommended by %1", caption),
KCategorizedItemsViewModels::Filter("recommended." + id, true), new KIcon(icon));
//foreach (QString plugin, plugins.split(",")) {}
}
// Other Emblems
d->appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
KCategorizedItemsViewModels::Filter("used", true));
// Filters: Special
d->filterModel.addFilter(i18n("All applets"),
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
d->filterModel.addFilter(i18n("Recommended by KDE"),
KCategorizedItemsViewModels::Filter("recommended", true), new KIcon("about-kde"));
d->filterModel.addFilter(i18n("Favorites"),
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
d->filterModel.addFilter(i18n("Used in past"),

View File

@ -19,26 +19,8 @@
#include "plasmaappletitemmodel_p.h"
PlasmaAppletItem::PlasmaAppletItem(QObject * parent, QString name,
QString pluginName, QString description, QString category, QIcon icon,
FilterFlags flags) :
QObject(parent)
{
QMap<QString, QVariant> attrs;
attrs.insert("name", QVariant(name));
attrs.insert("pluginName", QVariant(pluginName));
attrs.insert("description", QVariant(description));
attrs.insert("category", QVariant(category));
attrs.insert("favorite", flags & Favorite ? true : false);
attrs.insert("used", flags & Used ? true : false);
attrs.insert("recommended", flags & Recommended ? true : false);
setText(name + " - "+ description);
setData(QVariant(attrs));
setIcon(icon);
}
PlasmaAppletItem::PlasmaAppletItem(QObject *parent, const KPluginInfo& info,
FilterFlags flags) :
FilterFlags flags, QMap<QString, QVariant> * extraAttrs) :
QObject(parent)
{
QMap<QString, QVariant> attrs;
@ -48,7 +30,8 @@ PlasmaAppletItem::PlasmaAppletItem(QObject *parent, const KPluginInfo& info,
attrs.insert("category", info.category());
attrs.insert("favorite", flags & Favorite ? 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);
setText(info.name() + " - "+ info.category());
setData(attrs);
setIcon(KIcon(info.icon().isEmpty()?"application-x-plasma":info.icon()));
@ -82,30 +65,28 @@ bool PlasmaAppletItem::passesFiltering(
return data().toMap()[filter.first] == filter.second;
}
PlasmaAppletItemModel::PlasmaAppletItemModel(QObject * parent) :
PlasmaAppletItemModel::PlasmaAppletItemModel(QObject * parent, KConfigGroup * configGroup) :
KCategorizedItemsViewModels::DefaultItemModel(parent)
{
/* some test items that do have FilterFlags as well as overly long text
appendRow(new PlasmaAppletItem(this,
i18n("This is a very long name for an applet, isn't it?"), "null",
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
QString("graph"),
QIcon("/usr/share/icons/oxygen/64x64/apps/k3b.png"), PlasmaAppletItem::Used));
appendRow(new PlasmaAppletItem(this,
i18n("This is a very long name for another applet, isn't it?"), "null",
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
QString("graph"),
QIcon("/usr/share/icons/oxygen/64x64/apps/kfind.png"), PlasmaAppletItem::Used | PlasmaAppletItem::Recommended));
appendRow(new PlasmaAppletItem(this,
i18n("This is my favorite item!"), "null",
i18n("This is a Graphics applet whose description is even longer than it's title. And it was hard to achieve!"),
QString("graph"),
QIcon("/usr/share/icons/oxygen/64x64/apps/okular.png"), PlasmaAppletItem::Favorite | PlasmaAppletItem::Recommended));
*/
// Recommended emblems and filters
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]plugins");
QMapIterator<QString, QString> i(configGroup->entryMap());
QMap < QString, QMap < QString, QVariant > > extraPluginAttrs;
while (i.hasNext()) {
i.next();
if (!rx.exactMatch(i.key())) continue;
QString id = rx.cap(1);
foreach (QString plugin, i.value().split(",")) {
extraPluginAttrs[plugin]["recommended." + id] = true;
}
}
//TODO: get recommended, favorit, used, etc out of knownApplets()
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets()) {
appendRow(new PlasmaAppletItem(this, info));
kDebug() << info.pluginName() << " is the name of the plugin\n";
appendRow(new PlasmaAppletItem(this, info, PlasmaAppletItem::NoFilter, &(extraPluginAttrs[info.pluginName()])));
}
}

View File

@ -35,17 +35,12 @@ class PlasmaAppletItem : public KCategorizedItemsViewModels::AbstractItem,
public:
enum FilterFlag {NoFilter = 0,
Favorite = 1,
Used = 2,
Recommended = 4};
Used = 2};
Q_DECLARE_FLAGS(FilterFlags, FilterFlag)
PlasmaAppletItem(QObject * parent, QString name, QString pluginName,
QString description, QString category, QIcon icon,
FilterFlags flags = NoFilter);
PlasmaAppletItem(QObject *parent, const KPluginInfo& info,
FilterFlags flags = NoFilter);
FilterFlags flags = NoFilter, QMap<QString, QVariant> * extraAttrs = NULL);
virtual QString name() const;
QString pluginName() const;
@ -59,7 +54,7 @@ class PlasmaAppletItemModel :
public KCategorizedItemsViewModels::DefaultItemModel
{
public:
PlasmaAppletItemModel(QObject * parent = 0);
PlasmaAppletItemModel(QObject * parent = 0, KConfigGroup * configGroup = NULL);
QStringList mimeTypes() const;