make the alternatives *dialog* a helper

this places the responsibility on the shell package and removes
the assumption that the alternatives UI is a dialog that is placed
alongside the applet. that, my friends, is a desktop form factor
assumption.
wilder-5.14
Aaron Seigo 12 years ago
parent f4ab2f16bc
commit 2db8cd6373
  1. 45
      shell/alternativesdialog.cpp
  2. 19
      shell/alternativesdialog.h
  3. 37
      shell/shellcorona.cpp
  4. 1
      shell/shellcorona.h

@ -23,51 +23,35 @@
#include <QQmlEngine>
#include <QQmlContext>
#include <kdeclarative/qmlobject.h>
#include <Plasma/Package>
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/PluginLoader>
AlternativesDialog::AlternativesDialog(Plasma::Applet *applet, QQuickItem *parent)
: PlasmaQuick::Dialog(parent),
AlternativesHelper::AlternativesHelper(Plasma::Applet *applet, QObject *parent)
: QObject(parent),
m_applet(applet)
{
setVisualParent(applet->property("_plasma_graphicObject").value<QQuickItem *>());
connect(applet, &QObject::destroyed, this, &AlternativesDialog::close);
setLocation(applet->location());
setFlags(flags()|Qt::WindowStaysOnTopHint);
//We already have the proper shellpluginloader
Plasma::Package pkg;
if (applet && applet->containment() && applet->containment()->corona()) {
pkg = applet->containment()->corona()->package();
}
//TODO: use the proper package: we must be in the corona
pkg.setPath("org.kde.plasma.desktop");
m_qmlObj = new KDeclarative::QmlObject(this);
m_qmlObj->setInitializationDelayed(true);
m_qmlObj->setSource(QUrl::fromLocalFile(pkg.filePath("appletalternativesui")));
m_qmlObj->engine()->rootContext()->setContextProperty("alternativesDialog", this);
m_qmlObj->completeInitialization();
setMainItem(qobject_cast<QQuickItem *>(m_qmlObj->rootObject()));
}
AlternativesDialog::~AlternativesDialog()
AlternativesHelper::~AlternativesHelper()
{
}
QStringList AlternativesDialog::appletProvides() const
QStringList AlternativesHelper::appletProvides() const
{
return m_applet->pluginInfo().property("X-Plasma-Provides").value<QStringList>();
}
QString AlternativesDialog::currentPlugin() const
QString AlternativesHelper::currentPlugin() const
{
return m_applet->pluginInfo().pluginName();
}
void AlternativesDialog::loadAlternative(const QString &plugin)
QQuickItem *AlternativesHelper::applet() const
{
return m_applet->property("_plasma_graphicObject").value<QQuickItem *>();
}
void AlternativesHelper::loadAlternative(const QString &plugin)
{
if (plugin == m_applet->pluginInfo().pluginName() || m_applet->isContainment()) {
return;
@ -90,12 +74,5 @@ void AlternativesDialog::loadAlternative(const QString &plugin)
m_applet->destroy();
}
//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have
void AlternativesDialog::hideEvent(QHideEvent *ev)
{
QQuickWindow::hideEvent(ev);
deleteLater();
}
#include "moc_alternativesdialog.cpp"

@ -22,34 +22,27 @@
#include <Plasma/Applet>
#include <plasmaquick/dialog.h>
#include <QQuickItem>
namespace KDeclarative {
class QmlObject;
}
//FIXME: this thing really ought to be in the shell
class AlternativesDialog : public PlasmaQuick::Dialog
class AlternativesHelper : public QObject
{
Q_OBJECT
Q_PROPERTY(QStringList appletProvides READ appletProvides CONSTANT)
Q_PROPERTY(QString currentPlugin READ currentPlugin CONSTANT)
Q_PROPERTY(QQuickItem *applet READ applet CONSTANT)
public:
AlternativesDialog(Plasma::Applet *applet, QQuickItem *parent = 0);
~AlternativesDialog();
AlternativesHelper(Plasma::Applet *applet, QObject *parent = 0);
~AlternativesHelper();
QQuickItem *applet() const;
QStringList appletProvides() const;
QString currentPlugin() const;
Q_INVOKABLE void loadAlternative(const QString &plugin);
protected:
void hideEvent(QHideEvent *ev);
private:
Plasma::Applet *m_applet;
KDeclarative::QmlObject *m_qmlObj;
};
#endif

@ -41,6 +41,7 @@
#include <KAuthorized>
#include <KWindowSystem>
#include <kdeclarative/kdeclarative.h>
#include <kdeclarative/qmlobject.h>
#include <KMessageBox>
#include <KScreen/Config>
@ -112,11 +113,11 @@ public:
QMenu *addPanelsMenu;
Plasma::Package lookNFeelPackage;
QSet<KScreen::Output *> redundantOutputs;
QList<KDeclarative::QmlObject *> alternativesObjects;
#if HAVE_KTEXTEDITOR
QWeakPointer<InteractiveConsole> console;
#endif
QPointer <AlternativesDialog> alternativesDialog;
KScreen::Config *screenConfiguration;
QTimer waitingPanelsTimer;
QTimer appConfigSyncTimer;
@ -449,17 +450,41 @@ void ShellCorona::screenInvariants() const
void ShellCorona::showAlternativesForApplet(Plasma::Applet *applet)
{
if (package().filePath("appletalternativesui").isEmpty()) {
const QString alternativesQML = package().filePath("appletalternativesui");
if (alternativesQML.isEmpty()) {
return;
}
if (!d->alternativesDialog) {
d->alternativesDialog = new AlternativesDialog(applet);
}
KDeclarative::QmlObject *qmlObj = new KDeclarative::QmlObject(this);
qmlObj->setInitializationDelayed(true);
qmlObj->setSource(QUrl::fromLocalFile(alternativesQML));
AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj);
qmlObj->engine()->rootContext()->setContextProperty("alternativesHelper", helper);
d->alternativesDialog->show();
d->alternativesObjects << qmlObj;
qmlObj->completeInitialization();
connect(qmlObj->rootObject(), SIGNAL(visibleChanged(bool)),
this, SLOT(alternativesVisibilityChanged(bool)));
}
void ShellCorona::alternativesVisibilityChanged(bool visible)
{
if (visible) {
return;
}
QObject *root = sender();
QMutableListIterator<KDeclarative::QmlObject *> it(d->alternativesObjects);
while (it.hasNext()) {
KDeclarative::QmlObject *obj = it.next();
if (obj->rootObject() == root) {
it.remove();
obj->deleteLater();
}
}
}
void ShellCorona::unload()
{

@ -156,6 +156,7 @@ private Q_SLOTS:
void activityRemoved();
void desktopContainmentDestroyed(QObject*);
void showOpenGLNotCompatibleWarning();
void alternativesVisibilityChanged(bool visible);
private:
KScreen::Output *findPrimaryOutput() const;

Loading…
Cancel
Save