2007-09-26 09:44:06 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-10-12 10:44:02 +02:00
|
|
|
* it under the terms of the GNU Library/Lesser General Public License
|
|
|
|
* version 2, or (at your option) any later version, as published by the
|
|
|
|
* Free Software Foundation
|
2007-09-26 09:44:06 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
2007-10-12 10:44:02 +02:00
|
|
|
* You should have received a copy of the GNU Library/Lesser General Public
|
2007-09-26 09:44:06 +02:00
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-09-27 21:55:18 +02:00
|
|
|
#include "plasma/appletbrowser.h"
|
2007-09-27 20:51:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
#include <KAction>
|
|
|
|
#include <KStandardAction>
|
2007-10-08 23:50:38 +02:00
|
|
|
#include <KConfig>
|
|
|
|
#include <KConfigGroup>
|
2007-09-26 09:44:06 +02:00
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
|
|
|
|
#include "plasma/corona.h"
|
|
|
|
#include "plasma/containment.h"
|
2007-09-27 21:55:18 +02:00
|
|
|
#include "plasma/appletbrowser/plasmaappletitemmodel_p.h"
|
|
|
|
#include "plasma/appletbrowser/kcategorizeditemsview_p.h"
|
2007-09-27 21:39:28 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
class AppletBrowser::Private
|
2007-09-27 21:39:28 +02:00
|
|
|
{
|
|
|
|
public:
|
2007-11-06 22:10:11 +01:00
|
|
|
Private(Corona* co, Containment* cont, AppletBrowser* q)
|
|
|
|
: corona(co),
|
2007-09-27 21:39:28 +02:00
|
|
|
containment(cont),
|
|
|
|
appletList(0),
|
2007-10-08 23:50:38 +02:00
|
|
|
config("plasmarc"),
|
|
|
|
configGroup(&config, "Applet Browser"),
|
2007-11-06 22:10:11 +01:00
|
|
|
itemModel(configGroup, q),
|
2007-09-27 21:39:28 +02:00
|
|
|
filterModel(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-06 22:10:11 +01:00
|
|
|
void initFilters();
|
|
|
|
|
2007-11-06 03:45:24 +01:00
|
|
|
QString application;
|
2007-09-27 21:39:28 +02:00
|
|
|
Plasma::Corona *corona;
|
|
|
|
Plasma::Containment *containment;
|
|
|
|
KCategorizedItemsView *appletList;
|
2007-10-23 22:14:29 +02:00
|
|
|
|
2007-10-08 23:50:38 +02:00
|
|
|
KConfig config;
|
|
|
|
KConfigGroup configGroup;
|
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
PlasmaAppletItemModel itemModel;
|
|
|
|
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
|
|
|
|
};
|
|
|
|
|
2007-11-06 22:10:11 +01:00
|
|
|
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)
|
2007-09-27 21:39:28 +02:00
|
|
|
: KDialog(parent, f),
|
2007-11-06 22:10:11 +01:00
|
|
|
d(new Private(corona, 0, this))
|
2007-09-26 09:44:06 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2007-11-06 22:10:11 +01:00
|
|
|
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
2007-09-27 21:39:28 +02:00
|
|
|
: KDialog(parent, f),
|
2007-11-06 22:10:11 +01:00
|
|
|
d(new Private(0, containment, this))
|
2007-09-26 09:44:06 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
void AppletBrowser::init()
|
2007-09-27 21:39:28 +02:00
|
|
|
{
|
2007-11-02 16:31:34 +01:00
|
|
|
d->appletList = new KCategorizedItemsView(this); //TODO: focus the lineedit on startup
|
2007-10-23 22:14:29 +02:00
|
|
|
connect(d->appletList, SIGNAL(activated(const QModelIndex &)), this, SLOT(addApplet()));
|
2007-09-27 21:39:28 +02:00
|
|
|
setMainWidget(d->appletList);
|
|
|
|
|
2007-10-31 02:35:53 +01:00
|
|
|
setWindowTitle(i18n("Widgets"));
|
2007-10-12 19:30:30 +02:00
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
|
2007-10-31 02:35:53 +01:00
|
|
|
setButtonText(KDialog::Apply, i18n("Add Widget"));
|
|
|
|
setButtonText(KDialog::User1, i18n("Get New Widgets")); //TODO: not overly happy with this text
|
2007-09-27 21:39:28 +02:00
|
|
|
enableButton(KDialog::User1, false); //TODO: enable when GHNS integration is implemented
|
2007-09-26 09:44:06 +02:00
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
connect(this, SIGNAL(applyClicked()), this, SLOT(addApplet()));
|
|
|
|
connect(this, SIGNAL(user1Clicked()), this, SLOT(downloadApplets()));
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
|
2007-09-27 21:39:28 +02:00
|
|
|
addAction(quit);
|
2007-09-26 09:44:06 +02:00
|
|
|
|
2007-10-08 23:50:38 +02:00
|
|
|
// Other Emblems
|
2007-10-31 02:35:53 +01:00
|
|
|
d->appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("history"),
|
2007-09-27 21:39:28 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("used", true));
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-11-06 22:10:11 +01:00
|
|
|
d->initFilters();
|
2007-09-27 21:39:28 +02:00
|
|
|
d->appletList->setFilterModel(&d->filterModel);
|
2007-09-26 09:44:06 +02:00
|
|
|
|
|
|
|
// Other models
|
2007-09-27 21:39:28 +02:00
|
|
|
d->appletList->setItemModel(&d->itemModel);
|
2007-09-26 09:44:06 +02:00
|
|
|
}
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
AppletBrowser::~AppletBrowser()
|
2007-09-26 09:44:06 +02:00
|
|
|
{
|
2007-10-27 16:27:25 +02:00
|
|
|
delete d;
|
2007-09-26 09:44:06 +02:00
|
|
|
}
|
|
|
|
|
2007-11-06 22:10:11 +01:00
|
|
|
void AppletBrowser::setApplication(const QString& app)
|
2007-11-06 03:45:24 +01:00
|
|
|
{
|
|
|
|
d->application = app;
|
2007-11-06 22:10:11 +01:00
|
|
|
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);
|
2007-11-06 03:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString AppletBrowser::Application()
|
|
|
|
{
|
|
|
|
return d->application;
|
|
|
|
}
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
void AppletBrowser::addApplet()
|
2007-09-27 21:39:28 +02:00
|
|
|
{
|
|
|
|
kDebug() << "Button ADD clicked";
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
foreach (AbstractItem *item, d->appletList->selectedItems()) {
|
|
|
|
PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) item;
|
2007-09-27 19:50:31 +02:00
|
|
|
kDebug() << "Adding applet " << selectedItem->name();
|
2007-09-27 21:39:28 +02:00
|
|
|
if (d->corona) {
|
2007-09-27 19:50:31 +02:00
|
|
|
kDebug() << " to corona\n";
|
2007-10-12 19:30:30 +02:00
|
|
|
d->corona->addApplet(selectedItem->pluginName(),
|
|
|
|
selectedItem->arguments());
|
2007-09-27 21:39:28 +02:00
|
|
|
} else if (d->containment) {
|
2007-10-12 19:30:30 +02:00
|
|
|
kDebug() << " to containment\n";
|
|
|
|
d->containment->addApplet(selectedItem->pluginName(),
|
|
|
|
selectedItem->arguments());
|
2007-09-27 19:50:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2007-09-27 20:51:31 +02:00
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
void AppletBrowser::downloadApplets()
|
2007-09-27 21:39:28 +02:00
|
|
|
{
|
|
|
|
//TODO: implement
|
|
|
|
kDebug() << "GHNS button clicked";
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
#include "appletbrowser.moc"
|