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-09-27 21:48:51 +02:00
|
|
|
Private(Corona* co, Containment* cont, AppletBrowser* q)
|
2007-09-27 21:39:28 +02:00
|
|
|
: corona(co),
|
|
|
|
containment(cont),
|
|
|
|
appletList(0),
|
2007-10-08 23:50:38 +02:00
|
|
|
config("plasmarc"),
|
|
|
|
configGroup(&config, "Applet Browser"),
|
2007-10-09 11:51:55 +02:00
|
|
|
itemModel(configGroup, q),
|
2007-09-27 21:39:28 +02:00
|
|
|
filterModel(q)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Corona *corona;
|
|
|
|
Plasma::Containment *containment;
|
|
|
|
KCategorizedItemsView *appletList;
|
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-10-08 23:50:38 +02:00
|
|
|
|
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
};
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
AppletBrowser::AppletBrowser(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
|
2007-09-27 21:39:28 +02:00
|
|
|
: KDialog(parent, f),
|
|
|
|
d(new Private(corona, 0, this))
|
2007-09-26 09:44:06 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2007-09-27 21:48:51 +02:00
|
|
|
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
2007-09-27 21:39:28 +02:00
|
|
|
: KDialog(parent, f),
|
|
|
|
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
|
|
|
{
|
|
|
|
d->appletList = new KCategorizedItemsView(this);
|
|
|
|
setMainWidget(d->appletList);
|
|
|
|
|
2007-10-12 19:30:30 +02:00
|
|
|
setWindowTitle("Add Applets");
|
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
|
|
|
|
setButtonText(KDialog::Apply, i18n("Add Applet"));
|
|
|
|
setButtonText(KDialog::User1, i18n("Get New Applets")); //TODO: not overly happy with this text
|
|
|
|
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-15 11:32:57 +02:00
|
|
|
d->filterModel.addFilter(i18n("All Applets"),
|
2007-10-08 23:50:38 +02:00
|
|
|
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
|
2007-10-15 11:32:57 +02:00
|
|
|
d->appletList->addEmblem(i18n("Used in Past"), new KIcon("history"),
|
2007-09-27 21:39:28 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("used", true));
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
// Filters: Special
|
2007-09-27 21:39:28 +02:00
|
|
|
d->filterModel.addFilter(i18n("Favorites"),
|
2007-09-26 09:44:06 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
|
2007-10-15 16:38:36 +02:00
|
|
|
d->filterModel.addFilter(i18n("Used in Past"),
|
2007-09-26 09:44:06 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-27 21:39:28 +02:00
|
|
|
d->filterModel.addSeparator(i18n("Categories:"));
|
2007-09-27 19:50:31 +02:00
|
|
|
|
2007-09-26 09:44:06 +02:00
|
|
|
// Filters: Categories
|
|
|
|
foreach (const QString& category, Plasma::Applet::knownCategories()) {
|
2007-09-27 21:39:28 +02:00
|
|
|
d->filterModel.addFilter(category,
|
2007-09-26 09:44:06 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("category", category));
|
|
|
|
}
|
2007-09-27 19:50:31 +02:00
|
|
|
|
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-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"
|