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
|
|
|
|
* it under the terms of the GNU General Public License version 2 (or,
|
|
|
|
* at your option, any later version) as published by the Free Software
|
|
|
|
* Foundation
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* 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-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),
|
|
|
|
itemModel(q),
|
|
|
|
filterModel(q)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Corona *corona;
|
|
|
|
Plasma::Containment *containment;
|
|
|
|
KCategorizedItemsView *appletList;
|
|
|
|
PlasmaAppletItemModel itemModel;
|
|
|
|
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// Emblems
|
2007-09-27 21:39:28 +02:00
|
|
|
d->appletList->addEmblem(i18n("Recommended by KDE"), new KIcon("about-kde"),
|
|
|
|
KCategorizedItemsViewModels::Filter("recommended", true));
|
|
|
|
d->appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
|
|
|
|
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("All applets"),
|
2007-09-26 09:44:06 +02:00
|
|
|
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
|
2007-09-27 21:39:28 +02:00
|
|
|
d->filterModel.addFilter(i18n("Recommended by KDE"),
|
2007-09-26 09:44:06 +02:00
|
|
|
KCategorizedItemsViewModels::Filter("recommended", true), new KIcon("about-kde"));
|
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-09-27 21:39:28 +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-09-27 21:39:28 +02:00
|
|
|
d->corona->addApplet(selectedItem->pluginName());
|
|
|
|
} else if (d->containment) {
|
2007-09-27 19:50:31 +02:00
|
|
|
kDebug() << " to conatainment\n";
|
2007-09-27 21:39:28 +02:00
|
|
|
d->containment->addApplet(selectedItem->pluginName());
|
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"
|