* setting the application in the ctor is really ugly. use an accessor for that.
* upon using the accessor i disocvered they didn't actually do anything except set the member variable; no changes actually took place in the dialogs. eventually, we should probably consider moving the application name to a central location in libplasma, e.g. a Plasma::setMainComponent(KComponentData&) that initializes itself to the app's mainComponent()... there's too many of these app name things around also, when the item model updates itself, the view in the dialog doesn't. i've added a hack in AppletBrowser::setApplication to re-set the item model on the view. maybe Ivan you could take a look at that sometime? it's not overly critical as it works for now due to the hack. CCMAIL:lfranchi@gmail.com CCMAIL:ivan.cukic+kde@gmail.com svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=733614
This commit is contained in:
parent
90afba547f
commit
3d3beac449
@ -36,18 +36,19 @@ namespace Plasma
|
|||||||
class AppletBrowser::Private
|
class AppletBrowser::Private
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private(Corona* co, Containment* cont, AppletBrowser* q, const QString& app)
|
Private(Corona* co, Containment* cont, AppletBrowser* q)
|
||||||
: application( app ),
|
: corona(co),
|
||||||
corona(co),
|
|
||||||
containment(cont),
|
containment(cont),
|
||||||
appletList(0),
|
appletList(0),
|
||||||
config("plasmarc"),
|
config("plasmarc"),
|
||||||
configGroup(&config, "Applet Browser"),
|
configGroup(&config, "Applet Browser"),
|
||||||
itemModel(configGroup, app, q),
|
itemModel(configGroup, q),
|
||||||
filterModel(q)
|
filterModel(q)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initFilters();
|
||||||
|
|
||||||
QString application;
|
QString application;
|
||||||
Plasma::Corona *corona;
|
Plasma::Corona *corona;
|
||||||
Plasma::Containment *containment;
|
Plasma::Containment *containment;
|
||||||
@ -60,16 +61,61 @@ public:
|
|||||||
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
|
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
|
||||||
};
|
};
|
||||||
|
|
||||||
AppletBrowser::AppletBrowser(Plasma::Corona * corona, const QString& application, QWidget * parent, Qt::WindowFlags f)
|
void AppletBrowser::Private::initFilters()
|
||||||
|
{
|
||||||
|
filterModel.clear();
|
||||||
|
|
||||||
|
filterModel.addFilter(i18n("All Widgets"),
|
||||||
|
KCategorizedItemsViewModels::Filter(), new KIcon("plasmagik"));
|
||||||
|
|
||||||
|
// Recommended emblems and filters
|
||||||
|
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]caption");
|
||||||
|
QMapIterator<QString, QString> i(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 = configGroup.readEntry("recommended." + id + ".caption");
|
||||||
|
QString icon = configGroup.readEntry("recommended." + id + ".icon");
|
||||||
|
QString plugins = configGroup.readEntry("recommended." + id + ".plugins");
|
||||||
|
|
||||||
|
appletList->addEmblem(i18n("Recommended by %1", caption), new KIcon(icon),
|
||||||
|
KCategorizedItemsViewModels::Filter("recommended." + id, true));
|
||||||
|
filterModel.addFilter(i18n("Recommended by %1", caption),
|
||||||
|
KCategorizedItemsViewModels::Filter("recommended." + id, true), new KIcon(icon));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filters: Special
|
||||||
|
filterModel.addFilter(i18n("My Favorite Widgets"),
|
||||||
|
KCategorizedItemsViewModels::Filter("favorite", true),
|
||||||
|
new KIcon("bookmark"));
|
||||||
|
filterModel.addFilter(i18n("Widgets I Have Used Before"),
|
||||||
|
KCategorizedItemsViewModels::Filter("used", true),
|
||||||
|
new KIcon("history"));
|
||||||
|
|
||||||
|
filterModel.addSeparator(i18n("Categories:"));
|
||||||
|
|
||||||
|
foreach (const QString& category, Plasma::Applet::knownCategories(application)) {
|
||||||
|
filterModel.addFilter(category,
|
||||||
|
KCategorizedItemsViewModels::Filter("category", category));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AppletBrowser::AppletBrowser(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
|
||||||
: KDialog(parent, f),
|
: KDialog(parent, f),
|
||||||
d(new Private(corona, 0, this, application))
|
d(new Private(corona, 0, this))
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletBrowser::AppletBrowser(Plasma::Containment * containment, const QString& application, QWidget * parent, Qt::WindowFlags f)
|
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
||||||
: KDialog(parent, f),
|
: KDialog(parent, f),
|
||||||
d(new Private(0, containment, this, application))
|
d(new Private(0, containment, this))
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@ -93,48 +139,11 @@ void AppletBrowser::init()
|
|||||||
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
|
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
|
||||||
addAction(quit);
|
addAction(quit);
|
||||||
|
|
||||||
d->filterModel.addFilter(i18n("All Widgets"),
|
|
||||||
KCategorizedItemsViewModels::Filter(), new KIcon("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
|
// Other Emblems
|
||||||
d->appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("history"),
|
d->appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("history"),
|
||||||
KCategorizedItemsViewModels::Filter("used", true));
|
KCategorizedItemsViewModels::Filter("used", true));
|
||||||
|
|
||||||
// Filters: Special
|
d->initFilters();
|
||||||
d->filterModel.addFilter(i18n("My Favorite Widgets"),
|
|
||||||
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
|
|
||||||
d->filterModel.addFilter(i18n("Widgets I Have Used Before"),
|
|
||||||
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
|
|
||||||
|
|
||||||
d->filterModel.addSeparator(i18n("Categories:"));
|
|
||||||
|
|
||||||
|
|
||||||
foreach (const QString& category, Plasma::Applet::knownCategories(d->application)) {
|
|
||||||
d->filterModel.addFilter(category,
|
|
||||||
KCategorizedItemsViewModels::Filter("category", category));
|
|
||||||
}
|
|
||||||
|
|
||||||
d->appletList->setFilterModel(&d->filterModel);
|
d->appletList->setFilterModel(&d->filterModel);
|
||||||
|
|
||||||
// Other models
|
// Other models
|
||||||
@ -146,10 +155,15 @@ AppletBrowser::~AppletBrowser()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletBrowser::setApplication( const QString& app )
|
void AppletBrowser::setApplication(const QString& app)
|
||||||
{
|
{
|
||||||
d->application = app;
|
d->application = app;
|
||||||
d->itemModel.setApplication( app );
|
d->initFilters();
|
||||||
|
d->itemModel.setApplication(app);
|
||||||
|
|
||||||
|
//FIXME: AFAIK this shouldn't be necessary ... but here it is. need to find out what in that
|
||||||
|
// maze of models and views is screwing up
|
||||||
|
d->appletList->setItemModel(&d->itemModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppletBrowser::Application()
|
QString AppletBrowser::Application()
|
||||||
|
@ -34,11 +34,11 @@ class PLASMA_EXPORT AppletBrowser: public KDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AppletBrowser(Plasma::Corona *corona, const QString& app = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
|
explicit AppletBrowser(Plasma::Corona *corona, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
explicit AppletBrowser(Plasma::Containment *containment, const QString& = QString(), QWidget *parent = 0, Qt::WindowFlags f = 0);
|
explicit AppletBrowser(Plasma::Containment *containment, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
virtual ~AppletBrowser();
|
virtual ~AppletBrowser();
|
||||||
|
|
||||||
void setApplication( const QString& application );
|
void setApplication(const QString& application = QString());
|
||||||
QString Application();
|
QString Application();
|
||||||
|
|
||||||
protected Q_SLOTS:
|
protected Q_SLOTS:
|
||||||
|
@ -90,7 +90,9 @@ void KCategorizedItemsView::setFilterModel(QStandardItemModel * model)
|
|||||||
|
|
||||||
void KCategorizedItemsView::setItemModel(QStandardItemModel * model)
|
void KCategorizedItemsView::setItemModel(QStandardItemModel * model)
|
||||||
{
|
{
|
||||||
if (!m_modelFilterItems) m_modelFilterItems = new DefaultItemFilterProxyModel(this);
|
if (!m_modelFilterItems) {
|
||||||
|
m_modelFilterItems = new DefaultItemFilterProxyModel(this);
|
||||||
|
}
|
||||||
|
|
||||||
m_modelItems = model;
|
m_modelItems = model;
|
||||||
m_modelFilterItems->setSourceModel(m_modelItems);
|
m_modelFilterItems->setSourceModel(m_modelItems);
|
||||||
|
@ -80,11 +80,18 @@ QVariantList PlasmaAppletItem::arguments() const
|
|||||||
return qvariant_cast<QVariantList>(data().toMap()["arguments"]);
|
return qvariant_cast<QVariantList>(data().toMap()["arguments"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QString app, QObject * parent) :
|
PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent) :
|
||||||
KCategorizedItemsViewModels::DefaultItemModel(parent),
|
KCategorizedItemsViewModels::DefaultItemModel(parent),
|
||||||
m_application( app ),
|
|
||||||
m_configGroup(configGroup)
|
m_configGroup(configGroup)
|
||||||
{
|
{
|
||||||
|
m_used = m_configGroup.readEntry("used").split(",");
|
||||||
|
m_favorites = m_configGroup.readEntry("favorites").split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlasmaAppletItemModel::populateModel()
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
//kDebug() << "populating model, our application is" << m_application;
|
||||||
|
|
||||||
// Recommended emblems and filters
|
// Recommended emblems and filters
|
||||||
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]plugins");
|
QRegExp rx("recommended[.]([0-9A-Za-z]+)[.]plugins");
|
||||||
@ -100,11 +107,9 @@ PlasmaAppletItemModel::PlasmaAppletItemModel(KConfigGroup configGroup, QString a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_favorites = m_configGroup.readEntry("favorites").split(",");
|
//TODO: get recommended, favorite, used, etc out of knownApplets()
|
||||||
m_used = m_configGroup.readEntry("used").split(",");
|
//kDebug() << "number of applets is" << Plasma::Applet::knownApplets(QString(), m_application).count();
|
||||||
|
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets(QString(), m_application)) {
|
||||||
//TODO: get recommended, favorit, used, etc out of knownApplets()
|
|
||||||
foreach (const KPluginInfo& info, Plasma::Applet::knownApplets( QString(), m_application)) {
|
|
||||||
//kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool();
|
//kDebug() << info.pluginName() << "NoDisplay" << info.property("NoDisplay").toBool();
|
||||||
if (info.property("NoDisplay").toBool()) {
|
if (info.property("NoDisplay").toBool()) {
|
||||||
// we don't want to show the hidden category
|
// we don't want to show the hidden category
|
||||||
@ -185,6 +190,7 @@ void PlasmaAppletItemModel::setFavorite(QString plugin, bool favorite)
|
|||||||
void PlasmaAppletItemModel::setApplication(const QString& app)
|
void PlasmaAppletItemModel::setApplication(const QString& app)
|
||||||
{
|
{
|
||||||
m_application = app;
|
m_application = app;
|
||||||
|
populateModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString& PlasmaAppletItemModel::Application()
|
QString& PlasmaAppletItemModel::Application()
|
||||||
|
@ -60,7 +60,7 @@ class PlasmaAppletItemModel :
|
|||||||
public KCategorizedItemsViewModels::DefaultItemModel
|
public KCategorizedItemsViewModels::DefaultItemModel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlasmaAppletItemModel(KConfigGroup configGroup, QString parentApp = QString(), QObject * parent = 0);
|
PlasmaAppletItemModel(KConfigGroup configGroup, QObject * parent = 0);
|
||||||
|
|
||||||
QStringList mimeTypes() const;
|
QStringList mimeTypes() const;
|
||||||
|
|
||||||
@ -77,6 +77,7 @@ private:
|
|||||||
KConfigGroup m_configGroup;
|
KConfigGroup m_configGroup;
|
||||||
|
|
||||||
void loadSuperKarambaThemes(const KPluginInfo &info);
|
void loadSuperKarambaThemes(const KPluginInfo &info);
|
||||||
|
void populateModel();
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PlasmaAppletItem::FilterFlags)
|
||||||
|
Loading…
Reference in New Issue
Block a user