* applet browser's add button works

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=717892
This commit is contained in:
Ivan Čukić 2007-09-27 17:50:31 +00:00
parent ad15bab8c4
commit 8a811e46f7
8 changed files with 98 additions and 24 deletions

View File

@ -52,6 +52,20 @@ set(plasma_LIB_SRCS
widgets/widget.cpp widgets/widget.cpp
widgets/signalplotter.cpp widgets/signalplotter.cpp
widgets/meter.cpp widgets/meter.cpp
appletbrowser.cpp
appletbrowser/appletbrowserwindow.cpp
appletbrowser/kcategorizeditemsview.cpp
appletbrowser/kcategorizeditemsviewdelegate.cpp
appletbrowser/kcategorizeditemsviewmodels.cpp
appletbrowser/plasmaappletitemmodel.cpp
)
kde4_add_ui_files (
plasma_LIB_SRCS
appletbrowser/kcategorizeditemsviewbase.ui
appletbrowser/appletbrowserwindowbase.ui
) )
set(krunner_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/krunner/org.kde.krunner.Interface.xml) set(krunner_xml ${KDEBASE_WORKSPACE_SOURCE_DIR}/krunner/org.kde.krunner.Interface.xml)
@ -92,6 +106,7 @@ set(plasma_LIB_INCLUDES
abstractrunner.h abstractrunner.h
animator.h animator.h
applet.h applet.h
appletbrowser.h
configxml.h configxml.h
containment.h containment.h
corona.h corona.h

View File

@ -36,6 +36,8 @@ AppletBrowserWindow::AppletBrowserWindow(Plasma::Containment * containment, QWid
void AppletBrowserWindow::init() { void AppletBrowserWindow::init() {
setupUi(this); setupUi(this);
connect(buttonAdd, SIGNAL(clicked()), this, SLOT(buttonAddClicked()));
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this); QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
this->addAction(quit); this->addAction(quit);
@ -44,7 +46,7 @@ void AppletBrowserWindow::init() {
KCategorizedItemsViewModels::Filter("recommended", true)); KCategorizedItemsViewModels::Filter("recommended", true));
appletList->addEmblem(i18n("Used in past"), new KIcon("history"), appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
KCategorizedItemsViewModels::Filter("used", true)); KCategorizedItemsViewModels::Filter("used", true));
// Filters: Special // Filters: Special
m_filterModel.addFilter(i18n("All applets"), m_filterModel.addFilter(i18n("All applets"),
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma")); KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
@ -54,21 +56,21 @@ void AppletBrowserWindow::init() {
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark")); KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
m_filterModel.addFilter(i18n("Used in past"), m_filterModel.addFilter(i18n("Used in past"),
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history")); KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
m_filterModel.addSeparator(i18n("Categories:")); m_filterModel.addSeparator(i18n("Categories:"));
// Filters: Categories // Filters: Categories
foreach (const QString& category, Plasma::Applet::knownCategories()) { foreach (const QString& category, Plasma::Applet::knownCategories()) {
m_filterModel.addFilter(category, m_filterModel.addFilter(category,
KCategorizedItemsViewModels::Filter("category", category)); KCategorizedItemsViewModels::Filter("category", category));
} }
appletList->setFilterModel(& m_filterModel); appletList->setFilterModel(& m_filterModel);
// Other models // Other models
appletList->setItemModel(& m_itemModel); appletList->setItemModel(& m_itemModel);
} }
AppletBrowserWindow::~AppletBrowserWindow() AppletBrowserWindow::~AppletBrowserWindow()
@ -78,4 +80,20 @@ AppletBrowserWindow::~AppletBrowserWindow()
delete m_proxyModel;*/ delete m_proxyModel;*/
} }
void AppletBrowserWindow::buttonAddClicked() {
kDebug() << "Button ADD clicked\n";
foreach (AbstractItem * item, appletList->selectedItems()) {
PlasmaAppletItem * selectedItem = (PlasmaAppletItem *) item;
kDebug() << "Adding applet " << selectedItem->name();
if (m_corona) {
kDebug() << " to corona\n";
m_corona->addApplet(selectedItem->pluginName());
} else if (m_containment) {
kDebug() << " to conatainment\n";
m_containment->addApplet(selectedItem->pluginName());
}
}
}
#include "appletbrowserwindow.moc" #include "appletbrowserwindow.moc"

View File

@ -33,12 +33,15 @@
class AppletBrowserWindow: public QDialog, public Ui::AppletBrowserWindowBase class AppletBrowserWindow: public QDialog, public Ui::AppletBrowserWindowBase
{ {
//Q_OBJECT Q_OBJECT
public: public:
explicit AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent = 0, Qt::WindowFlags f = 0); explicit AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent = 0, Qt::WindowFlags f = 0); explicit AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent = 0, Qt::WindowFlags f = 0);
virtual ~AppletBrowserWindow(); virtual ~AppletBrowserWindow();
private slots:
void buttonAddClicked();
private: private:
void init(); void init();
Plasma::Corona * m_corona; Plasma::Corona * m_corona;

View File

@ -36,10 +36,10 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
this, SLOT(searchTermChanged(QString))); this, SLOT(searchTermChanged(QString)));
connect(comboFilters, SIGNAL(currentIndexChanged(int)), connect(comboFilters, SIGNAL(currentIndexChanged(int)),
this, SLOT(filterChanged(int))); this, SLOT(filterChanged(int)));
connect (itemsView, SIGNAL(activated(const QModelIndex &)), connect (itemsView, SIGNAL(activated(const QModelIndex &)),
this, SIGNAL(activated(const QModelIndex &))); this, SIGNAL(activated(const QModelIndex &)));
connect (itemsView, SIGNAL(clicked(const QModelIndex &)), connect (itemsView, SIGNAL(clicked(const QModelIndex &)),
this, SIGNAL(clicked(const QModelIndex &))); this, SIGNAL(clicked(const QModelIndex &)));
connect (itemsView, SIGNAL(entered(const QModelIndex &)), connect (itemsView, SIGNAL(entered(const QModelIndex &)),
@ -48,11 +48,11 @@ KCategorizedItemsView::KCategorizedItemsView(QWidget * parent, Qt::WindowFlags f
this, SIGNAL(pressed(const QModelIndex &))); this, SIGNAL(pressed(const QModelIndex &)));
itemsView->header()->setVisible(false); itemsView->header()->setVisible(false);
itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this)); itemsView->setItemDelegate(m_delegate = new KCategorizedItemsViewDelegate(this));
comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this)); comboFilters->setItemDelegate(new KCategorizedItemsViewFilterDelegate(this));
itemsView->viewport()->setAttribute(Qt::WA_Hover); itemsView->viewport()->setAttribute(Qt::WA_Hover);
QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this); QAction * find = KStandardAction::find(textSearch, SLOT(setFocus()), this);
@ -118,5 +118,21 @@ void KCategorizedItemsView::clearEmblems() {
m_emblems.clear(); m_emblems.clear();
} }
AbstractItem * KCategorizedItemsView::getItemByProxyIndex(const QModelIndex & index) const {
return (AbstractItem *) m_modelItems->itemFromIndex(
m_modelFilterItems->mapToSource(index)
);
}
QList < AbstractItem * > KCategorizedItemsView::selectedItems() const {
QList < AbstractItem * > items;
foreach (QModelIndex index, itemsView->selectionModel()->selectedIndexes()) {
if (index.column() == 0) {
items << getItemByProxyIndex(index);
}
}
return items;
}
#include "kcategorizeditemsview.moc" #include "kcategorizeditemsview.moc"

View File

@ -48,22 +48,24 @@ class KCategorizedItemsView: public QWidget, public Ui::KCategorizedItemsViewBas
{ {
Q_OBJECT Q_OBJECT
public: public:
KCategorizedItemsView(QWidget * parent = 0, Qt::WindowFlags f = 0); KCategorizedItemsView(QWidget * parent = 0, Qt::WindowFlags f = 0);
virtual ~KCategorizedItemsView(); virtual ~KCategorizedItemsView();
void setFilterModel(QStandardItemModel * model); ///< Sets the filters model void setFilterModel(QStandardItemModel * model); ///< Sets the filters model
void setItemModel(QStandardItemModel * model); ///< Sets the item model, as mentioned items must implement AbstractItem class void setItemModel(QStandardItemModel * model); ///< Sets the item model, as mentioned items must implement AbstractItem class
void addEmblem(const QString & title, QIcon * icon, const Filter & filter); void addEmblem(const QString & title, QIcon * icon, const Filter & filter);
void clearEmblems(); void clearEmblems();
QList < AbstractItem * > selectedItems() const;
protected slots: protected slots:
void searchTermChanged(const QString &text); void searchTermChanged(const QString &text);
void filterChanged(int index); void filterChanged(int index);
void resizeEvent ( QResizeEvent * event ); void resizeEvent ( QResizeEvent * event );
void paintEvent ( QPaintEvent * event ); void paintEvent ( QPaintEvent * event );
Q_SIGNALS: Q_SIGNALS:
void activated ( const QModelIndex & index ); void activated ( const QModelIndex & index );
void clicked ( const QModelIndex & index ); void clicked ( const QModelIndex & index );
@ -75,13 +77,14 @@ private:
QStandardItemModel * m_modelCategories; QStandardItemModel * m_modelCategories;
QStandardItemModel * m_modelFilters; QStandardItemModel * m_modelFilters;
QStandardItemModel * m_modelItems; QStandardItemModel * m_modelItems;
DefaultItemFilterProxyModel * m_modelFilterItems; DefaultItemFilterProxyModel * m_modelFilterItems;
KCategorizedItemsViewDelegate * m_delegate; KCategorizedItemsViewDelegate * m_delegate;
int m_viewWidth; int m_viewWidth;
QMap < QString, QPair < Filter, QIcon * > > m_emblems; QMap < QString, QPair < Filter, QIcon * > > m_emblems;
AbstractItem * getItemByProxyIndex(const QModelIndex & index) const;
friend class KCategorizedItemsViewDelegate; friend class KCategorizedItemsViewDelegate;
}; };

View File

@ -121,18 +121,18 @@ private:
InnerProxyModel(QObject * parent = 0); InnerProxyModel(QObject * parent = 0);
Qt::ItemFlags flags(const QModelIndex & index) const; Qt::ItemFlags flags(const QModelIndex & index) const;
QVariant data(const QModelIndex & index, bool favoriteColumn, QVariant data(const QModelIndex & index, bool favoriteColumn,
int role = Qt::DisplayRole) const; int role = Qt::DisplayRole) const;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
bool setData(const QModelIndex & index, const QVariant & value, bool setData(const QModelIndex & index, const QVariant & value,
int role = Qt::EditRole); int role = Qt::EditRole);
QVariant headerData(int section, Qt::Orientation orientation, QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const; int role = Qt::DisplayRole) const;
bool setHeaderData(int section, Qt::Orientation orientation, bool setHeaderData(int section, Qt::Orientation orientation,
const QVariant & value, int role = Qt::EditRole); const QVariant & value, int role = Qt::EditRole);
int rowCount(const QModelIndex & parent = QModelIndex()) const; int rowCount(const QModelIndex & parent = QModelIndex()) const;
int columnCount(const QModelIndex& index) const; int columnCount(const QModelIndex& index) const;
@ -140,7 +140,7 @@ private:
QModelIndex index(int row, int column, QModelIndex index(int row, int column,
const QModelIndex & parent = QModelIndex()) const; const QModelIndex & parent = QModelIndex()) const;
QModelIndex parent(const QModelIndex & index) const; QModelIndex parent(const QModelIndex & index) const;
QMimeData * mimeData(const QModelIndexList & indexes) const; QMimeData * mimeData(const QModelIndexList & indexes) const;
void setSourceModel(QStandardItemModel * sourceModel); void setSourceModel(QStandardItemModel * sourceModel);

View File

@ -49,6 +49,8 @@
#include "ksmserver_interface.h" #include "ksmserver_interface.h"
#include "screensaver_interface.h" #include "screensaver_interface.h"
#include "appletbrowser.h"
namespace Plasma namespace Plasma
{ {
@ -84,12 +86,14 @@ public:
QPixmap* bitmapBackground; QPixmap* bitmapBackground;
QString wallpaperPath; QString wallpaperPath;
QAction *engineExplorerAction; QAction *engineExplorerAction;
QAction *appletBrowserAction;
QAction *runCommandAction; QAction *runCommandAction;
QAction *lockAction; QAction *lockAction;
QAction *logoutAction; QAction *logoutAction;
QSize size; QSize size;
int screen; int screen;
bool immutable; bool immutable;
AppletBrowser *appletBrowser;
}; };
Containment::Containment(QGraphicsItem* parent, Containment::Containment(QGraphicsItem* parent,
@ -98,16 +102,19 @@ Containment::Containment(QGraphicsItem* parent,
: Applet(parent, serviceId, containmentId), : Applet(parent, serviceId, containmentId),
d(new Private) d(new Private)
{ {
d->appletBrowser = new AppletBrowser(this);
} }
Containment::Containment(QObject* parent, const QVariantList& args) Containment::Containment(QObject* parent, const QVariantList& args)
: Applet(parent, args), : Applet(parent, args),
d(new Private) d(new Private)
{ {
d->appletBrowser = new AppletBrowser(this);
} }
Containment::~Containment() Containment::~Containment()
{ {
delete d->appletBrowser;
delete d; delete d;
} }
@ -187,6 +194,13 @@ void Containment::launchExplorer()
KRun::run("plasmaengineexplorer", KUrl::List(), 0); KRun::run("plasmaengineexplorer", KUrl::List(), 0);
} }
void Containment::launchAppletBrowser()
{
d->appletBrowser->show();
}
void Containment::runCommand() void Containment::runCommand()
{ {
if (!KAuthorized::authorizeKAction("run_command")) { if (!KAuthorized::authorizeKAction("run_command")) {
@ -244,10 +258,13 @@ QList<QAction*> Containment::contextActions()
// - pretty up the menu with separators // - pretty up the menu with separators
// - should we offer "Switch User" here? // - should we offer "Switch User" here?
if (!d->engineExplorerAction) { if (!d->appletBrowserAction) {
d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this); d->engineExplorerAction = new QAction(i18n("Engine Explorer"), this);
connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer())); connect(d->engineExplorerAction, SIGNAL(triggered(bool)), this, SLOT(launchExplorer()));
d->appletBrowserAction = new QAction(i18n("Add applet"), this);
connect(d->appletBrowserAction, SIGNAL(triggered(bool)), this, SLOT(launchAppletBrowser()));
d->runCommandAction = new QAction(i18n("Run Command..."), this); d->runCommandAction = new QAction(i18n("Run Command..."), this);
connect(d->runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand())); connect(d->runCommandAction, SIGNAL(triggered(bool)), this, SLOT(runCommand()));
@ -263,6 +280,7 @@ QList<QAction*> Containment::contextActions()
QList<QAction*> actions; QList<QAction*> actions;
actions.append(d->engineExplorerAction); actions.append(d->engineExplorerAction);
actions.append(d->appletBrowserAction);
if (KAuthorized::authorizeKAction("run_command")) { if (KAuthorized::authorizeKAction("run_command")) {
actions.append(d->runCommandAction); actions.append(d->runCommandAction);

View File

@ -229,6 +229,7 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void appletDestroyed(QObject*); void appletDestroyed(QObject*);
void launchExplorer(); void launchExplorer();
void launchAppletBrowser();
void runCommand(); void runCommand();
void lockScreen(); void lockScreen();
void logout(); void logout();