* use failed to launch of fatal errors

* error nicely in in it( )so there is more visible feedback with meaning to the user
* sketch in the beginnings of extension loading

svn path=/trunk/KDE/kdebase/runtime/; revision=1047344
This commit is contained in:
Aaron J. Seigo 2009-11-11 02:09:25 +00:00
parent dbc0337ba2
commit 9d91ea5a8c
2 changed files with 45 additions and 22 deletions

View File

@ -25,6 +25,7 @@
#include <QWidget> #include <QWidget>
#include <KDebug> #include <KDebug>
#include <KIcon>
#include <KLocale> #include <KLocale>
#include <KStandardDirs> #include <KStandardDirs>
#include <KConfigGroup> #include <KConfigGroup>
@ -163,7 +164,7 @@ void kConfigGroupFromScriptValue(const QScriptValue& obj, KConfigGroup &config)
void registerEnums(QScriptEngine *engine, QScriptValue &scriptValue, const QMetaObject &meta) void registerEnums(QScriptEngine *engine, QScriptValue &scriptValue, const QMetaObject &meta)
{ {
//manually create enum values. ugh //manually create enum values. ugh
for (int i=0; i < meta.enumeratorCount(); ++i) { for (int i = 0; i < meta.enumeratorCount(); ++i) {
QMetaEnum e = meta.enumerator(i); QMetaEnum e = meta.enumerator(i);
//kDebug() << e.name(); //kDebug() << e.name();
for (int i=0; i < e.keyCount(); ++i) { for (int i=0; i < e.keyCount(); ++i) {
@ -183,7 +184,6 @@ SimpleJavaScriptApplet::SimpleJavaScriptApplet(QObject *parent, const QVariantLi
// kDebug() << "Script applet launched, args" << applet()->startupArguments(); // kDebug() << "Script applet launched, args" << applet()->startupArguments();
m_engine = new QScriptEngine(this); m_engine = new QScriptEngine(this);
importExtensions();
} }
SimpleJavaScriptApplet::~SimpleJavaScriptApplet() SimpleJavaScriptApplet::~SimpleJavaScriptApplet()
@ -193,10 +193,22 @@ SimpleJavaScriptApplet::~SimpleJavaScriptApplet()
} }
} }
void SimpleJavaScriptApplet::reportError(QScriptEngine *engine) void SimpleJavaScriptApplet::reportError(QScriptEngine *engine, bool fatal)
{ {
kDebug() << "Error: " << engine->uncaughtException().toString() SimpleJavaScriptApplet *jsApplet = qobject_cast<SimpleJavaScriptApplet *>(engine->parent());
<< " at line " << engine->uncaughtExceptionLineNumber() << endl; const QString failureMsg = i18n("Script failure on line %1:\n%2",
QString::number(engine->uncaughtExceptionLineNumber()),
engine->uncaughtException().toString());
if (jsApplet) {
if (fatal) {
jsApplet->setFailedToLaunch(true, failureMsg);
} else {
jsApplet->showMessage(KIcon("dialog-error"), failureMsg, Plasma::ButtonNone);
}
} else {
kDebug() << failureMsg;
}
kDebug() << engine->uncaughtExceptionBacktrace(); kDebug() << engine->uncaughtExceptionBacktrace();
} }
@ -340,6 +352,10 @@ bool SimpleJavaScriptApplet::init()
setupObjects(); setupObjects();
populateAnimationsHash(); populateAnimationsHash();
if (!importExtensions()) {
return false;
}
kDebug() << "ScriptName:" << applet()->name(); kDebug() << "ScriptName:" << applet()->name();
kDebug() << "ScriptCategory:" << applet()->category(); kDebug() << "ScriptCategory:" << applet()->category();
@ -354,30 +370,37 @@ bool SimpleJavaScriptApplet::init()
m_engine->evaluate(script); m_engine->evaluate(script);
if (m_engine->hasUncaughtException()) { if (m_engine->hasUncaughtException()) {
reportError(m_engine); reportError(m_engine, true);
return false; return false;
} }
return true; return true;
} }
void SimpleJavaScriptApplet::importExtensions() bool SimpleJavaScriptApplet::importExtensions()
{ {
return; // no extension, so do bother wasting cycles KPluginInfo info = description();
QStringList requiredExtensions = info.property("X-Plasma-RequiredExtensions").toStringList();
/* kDebug() << "required extensions are" << requiredExtensions;
QStringList extensions; foreach (const QString &extension, requiredExtensions) {
//extensions << "qt.core" << "qt.gui" << "qt.svg" << "qt.xml" << "qt.plasma"; if (!applet()->hasAuthorization(extension)) {
//extensions << "qt.core" << "qt.gui" << "qt.xml"; setFailedToLaunch(true,
foreach (const QString &ext, extensions) { i18n("Authorization for required extension '%1' was denied.",
kDebug() << "importing " << ext << "..."; extension));
QScriptValue ret = m_engine->importExtension(ext); return false;
if (ret.isError()) { } else {
kDebug() << "failed to import extension" << ext << ":" << ret.toString(); m_engine->importExtension(extension);
if (m_engine->hasUncaughtException()) {
reportError(m_engine, true);
return false;
}
} }
} }
kDebug() << "done importing extensions.";
*/ QStringList optionalExtensions = info.property("X-Plasma-OptionalExtensions").toStringList();
kDebug() << "extensions are" << optionalExtensions;
return true;
} }
typedef AbstractAnimation* AbstractAnimationPtr; typedef AbstractAnimation* AbstractAnimationPtr;

View File

@ -41,7 +41,7 @@ public:
~SimpleJavaScriptApplet(); ~SimpleJavaScriptApplet();
bool init(); bool init();
static void reportError(QScriptEngine *error); static void reportError(QScriptEngine *error, bool fatal = false);
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect); void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect);
QList<QAction*> contextualActions(); QList<QAction*> contextualActions();
@ -60,7 +60,7 @@ public slots:
void executeAction(const QString &name); void executeAction(const QString &name);
private: private:
void importExtensions(); bool importExtensions();
void setupObjects(); void setupObjects();
void callFunction(const QString &functionName, const QScriptValueList &args = QScriptValueList()); void callFunction(const QString &functionName, const QScriptValueList &args = QScriptValueList());
static void populateAnimationsHash(); static void populateAnimationsHash();