* don't crash when we don't have a containment
* don't duplicate the buttons in the appletbrowser: if you want buttons, you want the dialog * start of get widgets options svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=779727
This commit is contained in:
parent
df25f5422e
commit
758f9ecb0b
@ -20,10 +20,13 @@
|
|||||||
#include "plasma/appletbrowser.h"
|
#include "plasma/appletbrowser.h"
|
||||||
|
|
||||||
#include <KAction>
|
#include <KAction>
|
||||||
#include <KStandardAction>
|
|
||||||
#include <KConfig>
|
#include <KConfig>
|
||||||
#include <KConfigGroup>
|
#include <KConfigGroup>
|
||||||
|
#include <KFileDialog>
|
||||||
|
#include <KMenu>
|
||||||
|
#include <KPushButton>
|
||||||
|
#include <KServiceTypeTrader>
|
||||||
|
#include <KStandardAction>
|
||||||
|
|
||||||
#include "plasma/corona.h"
|
#include "plasma/corona.h"
|
||||||
#include "plasma/containment.h"
|
#include "plasma/containment.h"
|
||||||
@ -110,19 +113,9 @@ void AppletBrowserWidget::Private::initFilters()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
AppletBrowserWidget::AppletBrowserWidget(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
||||||
AppletBrowserWidget::AppletBrowserWidget(Plasma::Corona * corona, bool showButtons, QWidget * parent, Qt::WindowFlags f)
|
|
||||||
: QWidget(parent, f),
|
: QWidget(parent, f),
|
||||||
d(new Private(0, this)),
|
d(new Private(containment, this))
|
||||||
m_showButtons( showButtons )
|
|
||||||
{
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
AppletBrowserWidget::AppletBrowserWidget(Plasma::Containment * containment, bool showButtons, QWidget * parent, Qt::WindowFlags f)
|
|
||||||
: QWidget(parent, f),
|
|
||||||
d(new Private(containment, this)),
|
|
||||||
m_showButtons( showButtons )
|
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@ -140,23 +133,6 @@ void AppletBrowserWidget::init()
|
|||||||
connect(d->appletList, SIGNAL(activated(const QModelIndex &)), this, SLOT(addApplet()));
|
connect(d->appletList, SIGNAL(activated(const QModelIndex &)), this, SLOT(addApplet()));
|
||||||
layout->addWidget( d->appletList );
|
layout->addWidget( d->appletList );
|
||||||
|
|
||||||
if( m_showButtons ) {
|
|
||||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
|
||||||
buttonLayout->setSpacing( KDialog::spacingHint() );
|
|
||||||
buttonLayout->setMargin( KDialog::marginHint() );
|
|
||||||
|
|
||||||
QPushButton *addButton = new QPushButton(i18n("Add Widget"), this );
|
|
||||||
connect(addButton, SIGNAL(clicked()), this, SLOT(addApplet()));
|
|
||||||
buttonLayout->addWidget( addButton );
|
|
||||||
|
|
||||||
QPushButton *newButton = new QPushButton(i18n("Get New Widgets"), this ); //TODO: not overly happy with this text
|
|
||||||
newButton->setEnabled( false ); //TODO: enable when GHNS integration is implemented
|
|
||||||
connect(newButton, SIGNAL(clicked()), this, SLOT(downloadApplets()));
|
|
||||||
buttonLayout->addWidget( newButton );
|
|
||||||
|
|
||||||
layout->addLayout( buttonLayout );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Other Emblems
|
// Other Emblems
|
||||||
d->appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("view-history"),
|
d->appletList->addEmblem(i18n("Widgets I Have Used Before"), new KIcon("view-history"),
|
||||||
KCategorizedItemsViewModels::Filter("used", true));
|
KCategorizedItemsViewModels::Filter("used", true));
|
||||||
@ -174,6 +150,10 @@ void AppletBrowserWidget::init()
|
|||||||
void AppletBrowserWidget::initRunningApplets()
|
void AppletBrowserWidget::initRunningApplets()
|
||||||
{
|
{
|
||||||
//get applets from corona, count them, send results to model
|
//get applets from corona, count them, send results to model
|
||||||
|
if (!d->containment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
kDebug() << d->runningApplets.count();
|
kDebug() << d->runningApplets.count();
|
||||||
Plasma::Corona *c = d->containment->corona();
|
Plasma::Corona *c = d->containment->corona();
|
||||||
|
|
||||||
@ -204,7 +184,6 @@ void AppletBrowserWidget::initRunningApplets()
|
|||||||
|
|
||||||
void AppletBrowserWidget::setApplication(const QString& app)
|
void AppletBrowserWidget::setApplication(const QString& app)
|
||||||
{
|
{
|
||||||
|
|
||||||
d->application = app;
|
d->application = app;
|
||||||
d->initFilters();
|
d->initFilters();
|
||||||
d->itemModel.setApplication(app);
|
d->itemModel.setApplication(app);
|
||||||
@ -280,6 +259,10 @@ void AppletBrowserWidget::appletDestroyed(QObject* applet)
|
|||||||
|
|
||||||
void AppletBrowserWidget::destroyApplets(const QString &name)
|
void AppletBrowserWidget::destroyApplets(const QString &name)
|
||||||
{
|
{
|
||||||
|
if (!d->containment) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Plasma::Corona *c = d->containment->corona();
|
Plasma::Corona *c = d->containment->corona();
|
||||||
|
|
||||||
//we've tried our best to get a corona
|
//we've tried our best to get a corona
|
||||||
@ -304,61 +287,76 @@ void AppletBrowserWidget::destroyApplets(const QString &name)
|
|||||||
d->itemModel.setRunningApplets(name, 0);
|
d->itemModel.setRunningApplets(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletBrowserWidget::downloadApplets()
|
void AppletBrowserWidget::downloadWidgets()
|
||||||
{
|
{
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
kDebug() << "GHNS button clicked";
|
kDebug() << "GHNS button clicked";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppletBrowserWidget::openWidgetFile()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*AppletBrowser::AppletBrowser(Plasma::Corona * corona, QWidget * parent, Qt::WindowFlags f)
|
|
||||||
: KDialog(parent, f),
|
|
||||||
m_widget(new AppletBrowserWidget(corona, false, this))
|
|
||||||
{
|
{
|
||||||
winId(); // this is to get us a win id so that the next line doesn't abort on us
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/PackageStructure");
|
||||||
setWindowRole("appletbrowser");
|
QStringList filters;
|
||||||
init();
|
filters << ("*.plasmoid|Plasma Widget");
|
||||||
}*/
|
/*
|
||||||
|
foreach (const KService::Ptr &offer, offers) {
|
||||||
|
QString glob = offer
|
||||||
|
QString filter(
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
KFileDialog fd(KUrl(), QString(), this);
|
||||||
|
fd.setOperationMode(KFileDialog::Opening);
|
||||||
|
fd.setMode(KFile::Files | KFile::ExistingOnly);
|
||||||
|
fd.setFilter(filters.join("\n"));
|
||||||
|
fd.exec();
|
||||||
|
kDebug() << "selected file" << fd.selectedUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
class AppletBrowser::Private
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void init(AppletBrowser*, Plasma::Containment*);
|
||||||
|
AppletBrowserWidget *widget;
|
||||||
|
};
|
||||||
|
|
||||||
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
AppletBrowser::AppletBrowser(Plasma::Containment * containment, QWidget * parent, Qt::WindowFlags f)
|
||||||
: KDialog(parent, f),
|
: KDialog(parent, f),
|
||||||
m_widget(new AppletBrowserWidget(containment, false, this))
|
d(new Private)
|
||||||
{
|
{
|
||||||
init();
|
d->init(this, containment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletBrowser::init()
|
void AppletBrowser::Private::init(AppletBrowser *q, Plasma::Containment *containment)
|
||||||
{
|
{
|
||||||
setMainWidget(m_widget);
|
widget = new AppletBrowserWidget(containment, q);
|
||||||
|
|
||||||
setWindowTitle(i18n("Widgets"));
|
q->setMainWidget(widget);
|
||||||
|
q->setWindowTitle(i18n("Widgets"));
|
||||||
|
|
||||||
setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
|
q->setButtons(KDialog::Apply | KDialog::Close | KDialog::User1);
|
||||||
setButtonText(KDialog::Apply, i18n("Add Widget"));
|
q->setButtonText(KDialog::Apply, i18n("Add Widget"));
|
||||||
setButtonText(KDialog::User1, i18n("Get New Widgets")); //TODO: not overly happy with this text
|
q->setButtonText(KDialog::User1, i18n("Get New Widgets"));
|
||||||
enableButton(KDialog::User1, false); //TODO: enable when GHNS integration is implemented
|
|
||||||
|
|
||||||
setButtonToolTip(KDialog::Close, i18n("Close the dialog"));
|
KMenu *widgetsMenu = new KMenu(i18n("Get New Widgets"), q);
|
||||||
setButtonWhatsThis(KDialog::Close, i18n("<qt>When clicking <b>Close</b>, this dialog will be closed with no further action taken.</qt>"));
|
QAction *action = new QAction(KIcon("applications-internet"),
|
||||||
setButtonToolTip(KDialog::Apply, i18n("Add selected widgets"));
|
i18n("Download from the Internet"), q);
|
||||||
setButtonWhatsThis(KDialog::Apply, i18n("<qt>When clicking <b>Add Widget</b>, the selected widgets will be added to your desktop.</qt>"));
|
connect(action, SIGNAL(triggered(bool)), widget, SLOT(downloadWidgets()));
|
||||||
setButtonToolTip(KDialog::User1, i18n("Download new widgets"));
|
widgetsMenu->addAction(action);
|
||||||
setButtonWhatsThis(KDialog::User1, i18n("<qt>When clicking <b>Get New Widgets</b>, a dialog will open to allow you to download new widgets. You need to be connected to the Internet.</qt>"));
|
|
||||||
|
|
||||||
connect(this, SIGNAL(applyClicked()), m_widget, SLOT(addApplet()));
|
action = new QAction(KIcon("applications-internet"),
|
||||||
connect(this, SIGNAL(user1Clicked()), m_widget, SLOT(downloadApplets()));
|
i18n("Load from file"), q);
|
||||||
|
connect(action, SIGNAL(triggered(bool)), widget, SLOT(openWidgetFile()));
|
||||||
|
widgetsMenu->addAction(action);
|
||||||
|
q->button(KDialog::User1)->setMenu(widgetsMenu);
|
||||||
|
|
||||||
QAction* quit = KStandardAction::quit(qApp, SLOT(quit()), this);
|
q->setButtonToolTip(KDialog::Close, i18n("Close the dialog"));
|
||||||
addAction(quit);
|
q->setButtonWhatsThis(KDialog::Close, i18n("<qt>When clicking <b>Close</b>, this dialog will be closed with no further action taken.</qt>"));
|
||||||
|
q->setButtonToolTip(KDialog::Apply, i18n("Add selected widgets"));
|
||||||
|
q->setButtonWhatsThis(KDialog::Apply, i18n("<qt>When clicking <b>Add Widget</b>, the selected widgets will be added to your desktop.</qt>"));
|
||||||
|
q->setButtonToolTip(KDialog::User1, i18n("Download new widgets"));
|
||||||
|
q->setButtonWhatsThis(KDialog::User1, i18n("<qt>When clicking <b>Get New Widgets</b>, a dialog will open to allow you to download new widgets. You need to be connected to the Internet.</qt>"));
|
||||||
|
|
||||||
|
connect(q, SIGNAL(applyClicked()), widget, SLOT(addApplet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletBrowser::~AppletBrowser()
|
AppletBrowser::~AppletBrowser()
|
||||||
@ -367,22 +365,22 @@ AppletBrowser::~AppletBrowser()
|
|||||||
|
|
||||||
void AppletBrowser::setApplication(const QString& app)
|
void AppletBrowser::setApplication(const QString& app)
|
||||||
{
|
{
|
||||||
m_widget->setApplication( app );
|
d->widget->setApplication( app );
|
||||||
}
|
}
|
||||||
|
|
||||||
QString AppletBrowser::application()
|
QString AppletBrowser::application()
|
||||||
{
|
{
|
||||||
return m_widget->application();
|
return d->widget->application();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletBrowser::setContainment(Plasma::Containment *containment)
|
void AppletBrowser::setContainment(Plasma::Containment *containment)
|
||||||
{
|
{
|
||||||
m_widget->setContainment(containment);
|
d->widget->setContainment(containment);
|
||||||
}
|
}
|
||||||
|
|
||||||
Containment* AppletBrowser::containment() const
|
Containment* AppletBrowser::containment() const
|
||||||
{
|
{
|
||||||
return m_widget->containment();
|
return d->widget->containment();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
@ -35,7 +35,7 @@ class PLASMA_EXPORT AppletBrowserWidget : public QWidget
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AppletBrowserWidget(Plasma::Containment *containment, bool showButtons, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
AppletBrowserWidget(Plasma::Containment *containment, QWidget *parent = 0, Qt::WindowFlags f = 0);
|
||||||
virtual ~AppletBrowserWidget();
|
virtual ~AppletBrowserWidget();
|
||||||
|
|
||||||
void setApplication(const QString& application = QString());
|
void setApplication(const QString& application = QString());
|
||||||
@ -77,14 +77,18 @@ protected Q_SLOTS:
|
|||||||
/**
|
/**
|
||||||
* Launches a download dialog to retrieve new applets from the Internet
|
* Launches a download dialog to retrieve new applets from the Internet
|
||||||
*/
|
*/
|
||||||
void downloadApplets();
|
void downloadWidgets();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file dialog to open a widget from a local file
|
||||||
|
*/
|
||||||
|
void openWidgetFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
void initRunningApplets();
|
void initRunningApplets();
|
||||||
class Private;
|
class Private;
|
||||||
Private * const d;
|
Private * const d;
|
||||||
bool m_showButtons;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class PLASMA_EXPORT AppletBrowser: public KDialog
|
class PLASMA_EXPORT AppletBrowser: public KDialog
|
||||||
@ -110,8 +114,8 @@ public:
|
|||||||
Containment* containment() const;
|
Containment* containment() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
class Private;
|
||||||
AppletBrowserWidget *m_widget;
|
Private * const d;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Plasma
|
} // namespace Plasma
|
||||||
|
Loading…
Reference in New Issue
Block a user