- make AppletBrowserWindow a KDialog not a QDialog

- use standard buttons
- get rid of the completely superfluous ui file for the dialog
- add a dptr, move to Plasma namespace (why will become apparent shortly)


svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=717956
This commit is contained in:
Aaron J. Seigo 2007-09-27 19:39:28 +00:00
parent b2419420e5
commit 7ec22e70a1
4 changed files with 91 additions and 138 deletions

View File

@ -63,7 +63,6 @@ set(plasma_LIB_SRCS
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)

View File

@ -22,80 +22,123 @@
#include <KAction>
#include <KStandardAction>
AppletBrowserWindow::AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f) :
QDialog(parent, f), m_corona(corona), m_containment(NULL), m_itemModel(this), m_filterModel(this)
#include "plasma/corona.h"
#include "plasma/containment.h"
#include "plasmaappletitemmodel_p.h"
#include "kcategorizeditemsview_p.h"
namespace Plasma
{
class AppletBrowserWindow::Private
{
public:
Private(Corona* co, Containment* cont, AppletBrowserWindow* q)
: corona(co),
containment(cont),
appletList(0),
itemModel(q),
filterModel(q)
{
}
Plasma::Corona *corona;
Plasma::Containment *containment;
KCategorizedItemsView *appletList;
PlasmaAppletItemModel itemModel;
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
};
AppletBrowserWindow::AppletBrowserWindow(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
: KDialog(parent, f),
d(new Private(corona, 0, this))
{
init();
}
AppletBrowserWindow::AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f) :
QDialog(parent, f), m_corona(NULL), m_containment(containment), m_itemModel(this), m_filterModel(this)
AppletBrowserWindow::AppletBrowserWindow(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
: KDialog(parent, f),
d(new Private(0, containment, this))
{
init();
}
void AppletBrowserWindow::init() {
setupUi(this);
void AppletBrowserWindow::init()
{
d->appletList = new KCategorizedItemsView(this);
setMainWidget(d->appletList);
connect(buttonAdd, SIGNAL(clicked()), this, SLOT(buttonAddClicked()));
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
connect(this, SIGNAL(applyClicked()), this, SLOT(addApplet()));
connect(this, SIGNAL(user1Clicked()), this, SLOT(downloadApplets()));
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
this->addAction(quit);
addAction(quit);
// Emblems
appletList->addEmblem(i18n("Recommended by KDE"), new KIcon("about-kde"),
KCategorizedItemsViewModels::Filter("recommended", true));
appletList->addEmblem(i18n("Used in past"), new KIcon("history"),
KCategorizedItemsViewModels::Filter("used", true));
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));
// Filters: Special
m_filterModel.addFilter(i18n("All applets"),
d->filterModel.addFilter(i18n("All applets"),
KCategorizedItemsViewModels::Filter(), new KIcon("application-x-plasma"));
m_filterModel.addFilter(i18n("Recommended by KDE"),
d->filterModel.addFilter(i18n("Recommended by KDE"),
KCategorizedItemsViewModels::Filter("recommended", true), new KIcon("about-kde"));
m_filterModel.addFilter(i18n("Favorites"),
d->filterModel.addFilter(i18n("Favorites"),
KCategorizedItemsViewModels::Filter("favorite", true), new KIcon("bookmark"));
m_filterModel.addFilter(i18n("Used in past"),
d->filterModel.addFilter(i18n("Used in past"),
KCategorizedItemsViewModels::Filter("used", true), new KIcon("history"));
m_filterModel.addSeparator(i18n("Categories:"));
d->filterModel.addSeparator(i18n("Categories:"));
// Filters: Categories
foreach (const QString& category, Plasma::Applet::knownCategories()) {
m_filterModel.addFilter(category,
d->filterModel.addFilter(category,
KCategorizedItemsViewModels::Filter("category", category));
}
appletList->setFilterModel(& m_filterModel);
d->appletList->setFilterModel(&d->filterModel);
// Other models
appletList->setItemModel(& m_itemModel);
d->appletList->setItemModel(&d->itemModel);
}
AppletBrowserWindow::~AppletBrowserWindow()
{
/*delete m_itemModel;
delete m_filterModel;
delete m_proxyModel;*/
}
void AppletBrowserWindow::buttonAddClicked() {
kDebug() << "Button ADD clicked\n";
void AppletBrowserWindow::addApplet()
{
kDebug() << "Button ADD clicked";
foreach (AbstractItem * item, appletList->selectedItems()) {
PlasmaAppletItem * selectedItem = (PlasmaAppletItem *) item;
foreach (AbstractItem *item, d->appletList->selectedItems()) {
PlasmaAppletItem *selectedItem = (PlasmaAppletItem *) item;
kDebug() << "Adding applet " << selectedItem->name();
if (m_corona) {
if (d->corona) {
kDebug() << " to corona\n";
m_corona->addApplet(selectedItem->pluginName());
} else if (m_containment) {
d->corona->addApplet(selectedItem->pluginName());
} else if (d->containment) {
kDebug() << " to conatainment\n";
m_containment->addApplet(selectedItem->pluginName());
d->containment->addApplet(selectedItem->pluginName());
}
}
}
void AppletBrowserWindow::downloadApplets()
{
//TODO: implement
kDebug() << "GHNS button clicked";
}
} // namespace Plasma
#include "appletbrowserwindow_p.moc"

View File

@ -20,34 +20,32 @@
#ifndef APPLETBROWSERWINDOW_H_
#define APPLETBROWSERWINDOW_H_
#include <QtGui>
#include <QtCore>
#include <KDialog>
#include "ui_appletbrowserwindowbase.h"
namespace Plasma
{
#include "plasmaappletitemmodel_p.h"
#include "kcategorizeditemsview_p.h"
class Corona;
class Containment;
#include "plasma/corona.h"
#include "plasma/containment.h"
class AppletBrowserWindow: public QDialog, public Ui::AppletBrowserWindowBase
class AppletBrowserWindow: public KDialog
{
Q_OBJECT
public:
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::Corona *corona, QWidget *parent = 0, Qt::WindowFlags f = 0);
explicit AppletBrowserWindow(Plasma::Containment *containment, QWidget *parent = 0, Qt::WindowFlags f = 0);
virtual ~AppletBrowserWindow();
private slots:
void buttonAddClicked();
protected Q_SLOTS:
void addApplet();
void downloadApplets();
private:
void init();
Plasma::Corona * m_corona;
Plasma::Containment * m_containment;
PlasmaAppletItemModel m_itemModel;
KCategorizedItemsViewModels::DefaultFilterModel m_filterModel;
class Private;
Private * const d;
};
} // namespace Plasma
#endif /*APPLETBROWSERWINDOW_H_*/

View File

@ -1,87 +0,0 @@
<ui version="4.0" >
<class>AppletBrowserWindowBase</class>
<widget class="QDialog" name="AppletBrowserWindowBase" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>536</width>
<height>441</height>
</rect>
</property>
<property name="windowTitle" >
<string>Dialog</string>
</property>
<layout class="QGridLayout" >
<item row="0" column="0" colspan="4" >
<widget class="KCategorizedItemsView" native="1" name="appletList" />
</item>
<item row="1" column="0" >
<widget class="QPushButton" name="buttonGHNS" >
<property name="text" >
<string>Download from Internet</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="2" >
<widget class="QPushButton" name="buttonAdd" >
<property name="text" >
<string>Add Applet</string>
</property>
</widget>
</item>
<item row="1" column="3" >
<widget class="QPushButton" name="buttonClose" >
<property name="text" >
<string>Close</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KCategorizedItemsView</class>
<extends>QWidget</extends>
<header>appletbrowser/kcategorizeditemsview_p.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>buttonAdd</tabstop>
<tabstop>buttonClose</tabstop>
<tabstop>buttonGHNS</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonClose</sender>
<signal>clicked()</signal>
<receiver>AppletBrowserWindowBase</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel" >
<x>491</x>
<y>418</y>
</hint>
<hint type="destinationlabel" >
<x>494</x>
<y>444</y>
</hint>
</hints>
</connection>
</connections>
</ui>