file dialogs work, as do extensions. wicked.

svn path=/trunk/KDE/kdebase/runtime/; revision=1050287
This commit is contained in:
Aaron J. Seigo 2009-11-17 03:56:06 +00:00
parent cd8258f76c
commit 2105167c6c
4 changed files with 72 additions and 26 deletions

View File

@ -18,16 +18,22 @@
#include "filedialogproxy.h"
#include <QScriptEngine>
#include <KDebug>
FileDialogProxy::FileDialogProxy(KFileDialog::OperationMode mode, QObject *parent)
: QObject(parent),
m_dialog(new KFileDialog(KUrl("~"), QString(), 0))
{
kDebug() << "hello beautiful";
m_dialog->setOperationMode(mode);
connect(m_dialog, SIGNAL(okClicked()), this, SIGNAL(finished()));
connect(m_dialog, SIGNAL(okClicked()), this, SLOT(dialogFinished()));
}
FileDialogProxy::~FileDialogProxy()
{
kDebug() << "bye bye";
delete m_dialog;
}
@ -118,5 +124,53 @@ void FileDialogProxy::show()
m_dialog->show();
}
void FileDialogProxy::dialogFinished()
{
emit finished(this);
}
Q_DECLARE_METATYPE(FileDialogProxy *)
typedef FileDialogProxy* FileDialogProxyPtr;
QScriptValue qScriptValueFromFileDialogProxy(QScriptEngine *engine, const FileDialogProxyPtr &fd)
{
return engine->newQObject(const_cast<FileDialogProxy *>(fd));
}
void fileDialogProxyFromQScriptValue(const QScriptValue &scriptValue, FileDialogProxyPtr &fd)
{
QObject *obj = scriptValue.toQObject();
fd = static_cast<FileDialogProxy *>(obj);
}
void FileDialogProxy::registerWithRuntime(QScriptEngine *engine)
{
QScriptValue global = engine->globalObject();
qScriptRegisterMetaType<FileDialogProxy*>(engine, qScriptValueFromFileDialogProxy, fileDialogProxyFromQScriptValue);
global.setProperty("OpenFileDialog", engine->newFunction(FileDialogProxy::fileDialogOpen));
global.setProperty("SaveFileDialog", engine->newFunction(FileDialogProxy::fileDialogSave));
}
QScriptValue FileDialogProxy::fileDialogSave(QScriptContext *context, QScriptEngine *engine)
{
QObject *parent = 0;
if (context->argumentCount()) {
parent = context->argument(0).toQObject();
}
FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Saving, parent);
return engine->newQObject(fd, QScriptEngine::ScriptOwnership, QScriptEngine::ExcludeSuperClassContents);
}
QScriptValue FileDialogProxy::fileDialogOpen(QScriptContext *context, QScriptEngine *engine)
{
QObject *parent = 0;
if (context->argumentCount()) {
parent = context->argument(0).toQObject();
}
FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Opening, parent);
return engine->newQObject(fd, QScriptEngine::ScriptOwnership, QScriptEngine::ExcludeSuperClassContents);
}
#include "filedialogproxy.moc"

View File

@ -20,8 +20,13 @@
#define FILEDIALOGPROXY_H
#include <QObject>
#include <QScriptValue>
#include <KFileDialog>
class QScriptEngine;
class QScriptContext;
class FileDialogProxy : public QObject
{
Q_OBJECT
@ -59,11 +64,18 @@ public:
bool existingOnly() const;
void setExistingOnly(bool existingOnly);
static void registerWithRuntime(QScriptEngine *global);
static QScriptValue fileDialogSave(QScriptContext *context, QScriptEngine *engine);
static QScriptValue fileDialogOpen(QScriptContext *context, QScriptEngine *engine);
public Q_SLOTS:
void show();
Q_SIGNALS:
void finished();
void finished(FileDialogProxy *);
private Q_SLOTS:
void dialogFinished();
private:
KFileDialog *m_dialog;

View File

@ -396,11 +396,9 @@ bool SimpleJavaScriptApplet::init()
bool SimpleJavaScriptApplet::importBuiltinExtesion(const QString &extension)
{
kDebug() << extension;
if ("filedialog" == extension) {
//qScriptRegisterMetaType<KFileDialog*>(m_engine, qScriptValueFromKFileDialog, kFileDialogFromQScriptValue);
QScriptValue global = m_engine->globalObject();
global.setProperty("OpenFileDialog", m_engine->newFunction(SimpleJavaScriptApplet::fileDialogOpen));
global.setProperty("SaveFileDialog", m_engine->newFunction(SimpleJavaScriptApplet::fileDialogSave));
FileDialogProxy::registerWithRuntime(m_engine);
return true;
} else if ("launchapp" == extension) {
return true;
@ -418,7 +416,7 @@ bool SimpleJavaScriptApplet::importBuiltinExtesion(const QString &extension)
bool SimpleJavaScriptApplet::importExtensions()
{
KPluginInfo info = description();
QStringList requiredExtensions = info.property("X-Plasma-RequiredExtensions").toStringList();
QStringList requiredExtensions = info.service()->property("X-Plasma-RequiredExtensions", QVariant::StringList).toStringList();
kDebug() << "required extensions are" << requiredExtensions;
foreach (const QString &ext, requiredExtensions) {
QString extension = ext.toLower();
@ -445,7 +443,7 @@ bool SimpleJavaScriptApplet::importExtensions()
}
}
QStringList optionalExtensions = info.property("X-Plasma-OptionalExtensions").toStringList();
QStringList optionalExtensions = info.service()->property("X-Plasma-OptionalExtensions", QVariant::StringList).toStringList();
kDebug() << "extensions are" << optionalExtensions;
foreach (const QString &ext, requiredExtensions) {
QString extension = ext.toLower();
@ -808,22 +806,6 @@ QScriptValue SimpleJavaScriptApplet::newPlasmaFrameSvg(QScriptContext *context,
return engine->newQObject(frameSvg);
}
QScriptValue SimpleJavaScriptApplet::fileDialogSave(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(context);
FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Saving);
return engine->newQObject(fd);
}
QScriptValue SimpleJavaScriptApplet::fileDialogOpen(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(context);
FileDialogProxy *fd = new FileDialogProxy(KFileDialog::Opening);
return engine->newQObject(fd);
}
void SimpleJavaScriptApplet::installWidgets(QScriptEngine *engine)
{
QScriptValue globalObject = engine->globalObject();

View File

@ -77,8 +77,6 @@ private:
static QScriptValue loadui(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaSvg(QScriptContext *context, QScriptEngine *engine);
static QScriptValue newPlasmaFrameSvg(QScriptContext *context, QScriptEngine *engine);
static QScriptValue fileDialogSave(QScriptContext *context, QScriptEngine *engine);
static QScriptValue fileDialogOpen(QScriptContext *context, QScriptEngine *engine);
void installWidgets( QScriptEngine *engine );
static QScriptValue createWidget(QScriptContext *context, QScriptEngine *engine);