On Thursday 11 September 2008 17:47:27 Aaron J. Seigo wrote:
> there is a configChanged() signal from KCoreConfigSkeleton as well; we
> might be able to use that. it gets emitted when writeConfig() is called...
> soooo ... we could do sth like:
>
> * connect d->configXml configChanged to a configChanged signal (or slot?)
> * create dialog using d->configXml
> * writeConfig gets called by the dialog (for free) and that triggers things

I'll write a patch based on this and test it with html applet.

> Petri, since you're working on an html based applet, would you mind coming
> up with an example patch to the webkit appletscript engine that would work
> for you as a consumer of that api?

Diff attached is very much work in progress, but it's a start. At least I 
would like to do something to following issues:
- css from plasma theme colors (Or could plasma theme have some default 
stylesheet, that would benefit news applet too)?
- Background does not work currently.
- more applet functions (setBackgroundHints, resize, etc.)
- Is it ok that dashboard widgets get all the plasma functionality too? Or 
should this be a separate scriptengine.

Petri


Index: webapplet_package.cpp
===================================================================
--- webapplet_package.cpp	(revision 0)
+++ webapplet_package.cpp	(revision 0)
@@ -0,0 +1,34 @@
+/*
+Copyright (c) 2008 Petri Damstén <[EMAIL PROTECTED]>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "webapplet_package.h"
+
+WebAppletPackage::WebAppletPackage(QObject *parent, QVariantList args)
+: Plasma::PackageStructure(parent, "Web")
+{
+    Q_UNUSED(args)
+    addFileDefinition("webpage", "html/index.html", i18n("Main Html"));
+    setRequired("webpage", true);
+    addFileDefinition("mainconfigui", "ui/config.ui", i18n("Config user interface"));
+    addFileDefinition("mainconfigxml", "config/config.kcfg", i18n("Config xml definition"));
+    addFileDefinition("screenshot", "screenshot.png", i18n("Screenshot"));
+}
Index: webapplet_plugin.cpp
===================================================================
--- webapplet_plugin.cpp	(revision 859729)
+++ webapplet_plugin.cpp	(working copy)
@@ -19,7 +19,7 @@
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
  */
-#include "webapplet.h"
+#include "plasmawebapplet.h"
 
-K_EXPORT_PLASMA_APPLETSCRIPTENGINE(webapplet, WebApplet)
+K_EXPORT_PLASMA_APPLETSCRIPTENGINE(webkit, PlasmaWebApplet)
 
Index: dashboardapplet.h
===================================================================
--- dashboardapplet.h	(revision 859729)
+++ dashboardapplet.h	(working copy)
@@ -38,6 +38,9 @@
     ~DashboardApplet();
 
     bool init();
+
+protected:
+    virtual void pageLoadFinished();
 };
 
 K_EXPORT_PLASMA_APPLETSCRIPTENGINE(dashboard, DashboardApplet)
Index: webapplet_package.h
===================================================================
--- webapplet_package.h	(revision 0)
+++ webapplet_package.h	(revision 0)
@@ -0,0 +1,36 @@
+/*
+Copyright (c) 2008 Petri Damstén <[EMAIL PROTECTED]>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef WEBAPPLET_PACKAGE_H
+#define WEBAPPLET_PACKAGE_H
+
+#include <Plasma/PackageStructure>
+
+class WebAppletPackage : public Plasma::PackageStructure
+{
+public:
+    WebAppletPackage(QObject *parent, QVariantList args);
+};
+
+K_EXPORT_PLASMA_PACKAGESTRUCTURE(webapplet, WebAppletPackage)
+
+#endif
Index: bundle.cpp
===================================================================
--- bundle.cpp	(revision 859729)
+++ bundle.cpp	(working copy)
@@ -120,6 +120,8 @@
       m_width(0),
       m_height(0)
 {
+    Q_UNUSED(parent)
+    Q_UNUSED(args)
     setContentsPrefix(QString());
 }
 
Index: plasmajs.cpp
===================================================================
--- plasmajs.cpp	(revision 859729)
+++ plasmajs.cpp	(working copy)
@@ -20,12 +20,11 @@
 THE SOFTWARE.
  */
 #include "plasmajs.h"
+#include "plasmawebapplet.h"
 
 #include "plasma/dataenginemanager.h"
 #include "plasma/dataengine.h"
 
-#include <QDebug>
-
 using namespace Plasma;
 
 PlasmaJs::PlasmaJs(QObject *parent)
@@ -37,25 +36,24 @@
 {
     DataEngine *engine = DataEngineManager::self()->engine(name);
     DataEngineWrapper *wrapper =  new DataEngineWrapper(engine);
-    qDebug()<<"engine is "<<wrapper;
-    qDebug()<<"\t name = "<<wrapper->engineName()<<", valid = "<<wrapper->isValid();
+    //kDebug() << "engine is " << wrapper;
+    //kDebug() << "\t name = " << wrapper->engineName() << ", valid = " << wrapper->isValid();
     return wrapper;
 }
 
 QObject *PlasmaJs::loadDataEngine(const QString& name)
 {
     DataEngine *engine = DataEngineManager::self()->loadEngine(name);
-    //engine = new TestJs(this);
     DataEngineWrapper *wrapper = new DataEngineWrapper(engine);
-    qDebug()<<"engine is "<<wrapper;
-    qDebug()<<"engine sources "<<wrapper->sources();
-    qDebug()<<"res = "<<wrapper->query("world");
+    //kDebug() << "engine is " << wrapper;
+    //kDebug() << "engine sources " << wrapper->sources();
+    //kDebug() << "res = " << wrapper->query("world");
     return wrapper;
 }
 
 void PlasmaJs::unloadDataEngine(const QString& name)
 {
-    return DataEngineManager::self()->unloadEngine(name);
+    DataEngineManager::self()->unloadEngine(name);
 }
 
 QStringList PlasmaJs::knownEngines()
@@ -63,17 +61,28 @@
     return DataEngineManager::listAllEngines();
 }
 
-TestJs::TestJs(QObject *parent)
-    : QObject(parent)
+ConfigGroupWrapper::ConfigGroupWrapper(const KConfigGroup &config)
+: m_config(config)
 {
 }
 
-void TestJs::test()
+void ConfigGroupWrapper::setConfig(const KConfigGroup &config)
 {
-    qDebug()<<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
-    qDebug()<<"XXXXXXX YES XXXXXXX";
+    m_config = config;
 }
 
+QVariant ConfigGroupWrapper::readEntry(const QString &key, const QVariant &aDefault) const
+{
+    kDebug() << m_config.config()->name() << m_config.name();
+    kDebug() << key << m_config.readEntry(key, aDefault);
+    return m_config.readEntry(key, aDefault);
+}
+
+void ConfigGroupWrapper::writeEntry(const QString &key, const QVariant& value)
+{
+    m_config.writeEntry(key, value);
+}
+
 DataEngineDataWrapper::DataEngineDataWrapper(const DataEngine::Data &data)
     : m_data(data)
 {
@@ -84,6 +93,11 @@
     return m_data.count();
 }
 
+void DataEngineDataWrapper::setData(const Plasma::DataEngine::Data &data)
+{
+    m_data = data;
+}
+
 QVariant DataEngineDataWrapper::value(const QString &key) const
 {
     return m_data[key];
@@ -99,10 +113,9 @@
     return m_data.keys().at(i);
 }
 
-DataEngineWrapper::DataEngineWrapper(Plasma::DataEngine *engine)
-    : QObject(engine), m_engine(engine)
+DataEngineWrapper::DataEngineWrapper(Plasma::DataEngine *engine, QObject *applet)
+    : QObject(engine), m_engine(engine), m_applet(applet)
 {
-    DataEngineManager::self()->loadEngine(engine->name()); //FIXME it's getting loaded twice
 }
 
 QStringList DataEngineWrapper::sources() const
@@ -133,7 +146,15 @@
 
 DataEngineWrapper::~DataEngineWrapper()
 {
-    DataEngineManager::self()->unloadEngine(m_engine->name()); //FIXME it might be getting unloaded twice
 }
 
+void DataEngineWrapper::connectSource(const QString& source,
+                                      uint pollingInterval, uint intervalAlignment)
+{
+    if (m_applet) {
+        m_engine->connectSource(source, m_applet, pollingInterval,
+                                (Plasma::IntervalAlignment)intervalAlignment);
+    }
+}
+
 #include "plasmajs.moc"
Index: webpage.cpp
===================================================================
--- webpage.cpp	(revision 859729)
+++ webpage.cpp	(working copy)
@@ -43,17 +43,20 @@
 
 void WebPage::javaScriptAlert(QWebFrame *frame, const QString& message)
 {
+    Q_UNUSED(frame)
     qDebug()<< "JS ALERT: "<< message;
 }
 
 void WebPage::javaScriptConsoleMessage(const QString& message, int lineNumber,
                                        const QString& sourceID)
 {
+    Q_UNUSED(sourceID)
     qDebug()<< "JS CONSOLE MESSAGE: line "<< lineNumber<<": " << message;
 }
 
 bool WebPage::javaScriptConfirm(QWebFrame *frame, const QString& msg)
 {
+    Q_UNUSED(frame)
     qDebug()<< "JS CONFIRM: "<< msg;
     return true;
 }
@@ -61,6 +64,7 @@
 bool WebPage::javaScriptPrompt(QWebFrame *frame, const QString& msg,
                                const QString& defaultValue, QString* result)
 {
+    Q_UNUSED(frame)
     qDebug()<<"JS PROMPT: "<< msg <<", default text: "<<defaultValue;
     *result = defaultValue;
     return true;
Index: plasmajs.h
===================================================================
--- plasmajs.h	(revision 859729)
+++ plasmajs.h	(working copy)
@@ -22,27 +22,16 @@
 #ifndef PLASMAJS_H
 #define PLASMAJS_H
 
-#include <plasma/dataengine.h>
 #include <QObject>
+#include <KConfigGroup>
+#include <Plasma/DataEngine>
 
-namespace Plasma {
-    class DataEngine;
-}
-
-class TestJs : public QObject
-{
-    Q_OBJECT
-public:
-    TestJs(QObject *parent=0);
-public Q_SLOTS:
-    void test();
-};
-
 class PlasmaJs : public QObject
 {
     Q_OBJECT
 public:
     PlasmaJs(QObject *parent=0);
+
 public Q_SLOTS:
     QObject *dataEngine(const QString &name);
     QObject *loadDataEngine(const QString& name);
@@ -55,17 +44,36 @@
     Q_OBJECT
     Q_PROPERTY(int size READ size)
 public:
-    DataEngineDataWrapper(const Plasma::DataEngine::Data &data);
+    DataEngineDataWrapper(const Plasma::DataEngine::Data &data = Plasma::DataEngine::Data());
 
     int size() const;
+    void setData(const Plasma::DataEngine::Data &data);
+
 public Q_SLOTS:
     QVariant value(const QString &key) const;
     QStringList keys() const;
     QString key(int i) const;
+
 private:
     Plasma::DataEngine::Data m_data;
 };
 
+class ConfigGroupWrapper : public QObject
+{
+    Q_OBJECT
+public:
+    ConfigGroupWrapper(const KConfigGroup &config = KConfigGroup());
+
+    void setConfig(const KConfigGroup &config);
+
+public Q_SLOTS:
+    QVariant readEntry(const QString &key, const QVariant &aDefault = QVariant()) const;
+    void writeEntry(const QString &key, const QVariant& value);
+
+private:
+    KConfigGroup m_config;
+};
+
 class DataEngineWrapper : public QObject
 {
     Q_OBJECT
@@ -74,18 +82,22 @@
     Q_PROPERTY(QString icon READ icon)
     Q_PROPERTY(QString engineName READ engineName)
 public:
-    DataEngineWrapper(Plasma::DataEngine *engine);
+    DataEngineWrapper(Plasma::DataEngine *engine, QObject *applet = 0);
     ~DataEngineWrapper();
 
     QStringList sources() const;
     QString engineName() const;
     bool isValid() const;
     QString icon() const;
+
 public Q_SLOTS:
     QObject *query(const QString &str) const;
+    void connectSource(const QString& source,
+                       uint pollingInterval = 0, uint intervalAlignment = 0);
 
 private:
     Plasma::DataEngine *m_engine;
+    QObject *m_applet;
 };
 
 #endif
Index: plasmawebapplet.cpp
===================================================================
--- plasmawebapplet.cpp	(revision 0)
+++ plasmawebapplet.cpp	(revision 0)
@@ -0,0 +1,52 @@
+/*
+Copyright (c) 2007 Zack Rusin <[EMAIL PROTECTED]>
+Copyright (c) 2008 Petri Damstén <[EMAIL PROTECTED]>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#include "plasmawebapplet.h"
+#include "plasmajs.h"
+
+#include <QWebFrame>
+
+#include <Plasma/WebContent>
+#include <Plasma/Applet>
+
+PlasmaWebApplet::PlasmaWebApplet(QObject *parent, const QVariantList &args)
+: WebApplet(parent, args)
+{
+}
+
+PlasmaWebApplet::~PlasmaWebApplet()
+{
+}
+
+bool PlasmaWebApplet::init()
+{
+    applet()->setBackgroundHints(Plasma::Applet::DefaultBackground);
+    return WebApplet::init();
+}
+
+void PlasmaWebApplet::pageLoadFinished()
+{
+    callJsFunction("init");
+}
+
+#include "plasmawebapplet.moc"
Index: webapplet.cpp
===================================================================
--- webapplet.cpp	(revision 859729)
+++ webapplet.cpp	(working copy)
@@ -24,13 +24,14 @@
 #include "webpage.h"
 #include "plasmajs.h"
 
-#include <QDebug>
 #include <QPainter>
 #include <QWebView>
 #include <QWebFrame>
 #include <QWebPage>
+#include <QFile>
 
 #include <plasma/applet.h>
+#include <plasma/package.h>
 #include <plasma/widgets/webcontent.h>
 
 using namespace Plasma;
@@ -49,6 +50,10 @@
 
         Plasma::Applet *applet = q->applet();
         applet->resize(150, 150);
+        applet->setAcceptsHoverEvents(true);
+        // FIXME: xml based config does not work with normal applet config
+        //config.setConfig(applet->config());
+        config.setConfig(KConfigGroup(applet->config().config(), applet->pluginName()));
 
         page = new Plasma::WebContent(applet);
         page->setPage(new WebPage(page));
@@ -64,6 +69,10 @@
 
     Plasma::WebContent *page;
     bool loaded;
+    QVariantList args;
+    DataEngineDataWrapper dataEngineData;
+    QHash<Plasma::DataEngine*, DataEngineWrapper*> dataEngines;
+    ConfigGroupWrapper config;
 };
 
 WebApplet::WebApplet(QObject *parent, const QVariantList &args)
@@ -81,13 +90,24 @@
 bool WebApplet::init()
 {
     d->init(this);
+
+    QString webpage = package()->filePath("webpage");
+    //kDebug() << page << "webpage is at" << webpage;
+    if (webpage.isEmpty()) {
+        return false;
+    }
+    kDebug() << QUrl(package()->path());
+    setHtml(dataFor(webpage), QUrl(package()->path()));
     return true;
 }
 
 void WebApplet::paintInterface(QPainter *painter,
-                               const QStyleOptionGraphicsItem *,
-                               const QRect & contentsRect)
+                               const QStyleOptionGraphicsItem *option,
+                               const QRect &contentsRect)
 {
+    Q_UNUSED(painter)
+    Q_UNUSED(option)
+    Q_UNUSED(contentsRect)
     //painter->save();
     /*QPalette pal = painter->palette();
     pal.setBrush(QPalette::Background, Qt::transparent);
@@ -111,12 +131,15 @@
     return d->page;
 }
 
+void WebApplet::pageLoadFinished()
+{
+}
+
 void WebApplet::loadFinished(bool success)
 {
-    kDebug() << success;
+    //kDebug() << success;
     if (success) {
-        QSize newSize = d->page->mainFrame()->contentsSize();
-        applet()->setGeometry(QRectF(QPoint(), newSize));
+        pageLoadFinished();
     }
 }
 
@@ -163,4 +186,79 @@
     d->page->mainFrame()->load(url);
 }
 
+QByteArray WebApplet::dataFor(const QString &str)
+{
+    QFile f(str);
+    f.open(QIODevice::ReadOnly);
+    QByteArray data = f.readAll();
+    f.close();
+    return data;
+}
+
+Plasma::WebContent* WebApplet::page()
+{
+    return d->page;
+}
+
+QVariant WebApplet::arg(int index) const
+{
+    return d->args[index];
+}
+
+QObject* WebApplet::objArg(int index) const
+{
+    return d->args[index].value<QObject*>();
+}
+
+QString WebApplet::name() const
+{
+    return applet()->name();
+}
+
+QObject* WebApplet::dataEngine(const QString& name)
+{
+    Plasma::DataEngine* de = applet()->dataEngine(name);
+    if (d->dataEngines.keys().contains(de)) {
+        return d->dataEngines[de];
+    }
+    d->dataEngines[de] = new DataEngineWrapper(de, this);
+    return d->dataEngines[de];
+}
+
+QObject* WebApplet::config() const
+{
+    return &d->config;
+}
+
+QVariant WebApplet::callJsFunction(const QString& func, const QVariantList& args)
+{
+    d->args = args;
+    QString cmd = func + '(';
+    for(int i = 0; i < args.count(); ++i) {
+        if (i > 0) {
+            cmd += ',';
+        }
+        if (args[i].canConvert<QObject*>()) {
+            cmd += QString("window.applet.objArg(%1)").arg(i);
+        } else {
+            cmd += QString("window.applet.arg(%1)").arg(i);
+        }
+    }
+    cmd += ')';
+    //kDebug() << cmd;
+    return page()->mainFrame()->evaluateJavaScript(cmd);
+}
+
+void WebApplet::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data)
+{
+    d->dataEngineData.setData(data);
+    callJsFunction("dataUpdated",
+                   QVariantList() << source << QVariant::fromValue((QObject*)&d->dataEngineData));
+}
+
+void WebApplet::configAccepted()
+{
+    callJsFunction("configAccepted");
+}
+
 #include "webapplet.moc"
Index: plasmawebapplet.h
===================================================================
--- plasmawebapplet.h	(revision 0)
+++ plasmawebapplet.h	(revision 0)
@@ -0,0 +1,42 @@
+/*
+Copyright (c) 2007 Zack Rusin <[EMAIL PROTECTED]>
+Copyright (c) 2008 Petri Damstén <[EMAIL PROTECTED]>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+
+#ifndef PLASMAWEBAPPLET_H
+#define PLASMAWEBAPPLET_H
+
+#include "webapplet.h"
+
+class PlasmaWebApplet : public WebApplet
+{
+    Q_OBJECT
+public:
+    PlasmaWebApplet(QObject *parent, const QVariantList &args);
+    virtual ~PlasmaWebApplet();
+
+    virtual bool init();
+
+protected:
+    virtual void pageLoadFinished();
+};
+
+#endif
Index: webapplet.h
===================================================================
--- webapplet.h	(revision 859729)
+++ webapplet.h	(working copy)
@@ -24,6 +24,7 @@
 
 #include <QUrl>
 
+#include <Plasma/DataEngine>
 #include <plasma/scripting/appletscript.h>
 
 class QWebFrame;
@@ -36,22 +37,36 @@
 class WebApplet : public Plasma::AppletScript
 {
     Q_OBJECT
+    Q_PROPERTY(QString name READ name)
 public:
     WebApplet(QObject *parent, const QVariantList &args);
     ~WebApplet();
     bool init();
 
+    QString name() const;
+
 public slots:
+    QObject* dataEngine(const QString& name);
+    QObject* config() const;
+
+    QVariant arg(int index) const;
+    QObject* objArg(int index) const;
+    void dataUpdated(const QString& source, const Plasma::DataEngine::Data &data);
     void load(const QUrl &url);
     void setHtml(const QByteArray &html, const QUrl &baseUrl = QUrl());
     void loadHtml(const QUrl &baseUrl = QUrl());
+    void configAccepted();
 
 protected:
+    virtual void pageLoadFinished();
     Plasma::WebContent *view() const;
     void paintInterface(QPainter *painter,
                                 const QStyleOptionGraphicsItem *option,
                                 const QRect &contentsRect);
     void constraintsEvent(Plasma::Constraints constraints);
+    static QByteArray dataFor(const QString &str);
+    Plasma::WebContent* page();
+    QVariant callJsFunction(const QString &func, const QVariantList &args = QVariantList());
 
 private slots:
     void loadFinished(bool);
Index: plasma-packagestructure-web.desktop
===================================================================
--- plasma-packagestructure-web.desktop	(revision 0)
+++ plasma-packagestructure-web.desktop	(revision 0)
@@ -0,0 +1,18 @@
+[Desktop Entry]
+Name=Web Widget
+Comment=HTML widget
+Type=Service
+ServiceTypes=Plasma/PackageStructure
+
+X-KDE-Library=plasma_packagestructure_web
+X-KDE-PluginInfo-Author=Petri Damstén
[EMAIL PROTECTED]
+X-KDE-PluginInfo-Name=webapplet
+X-KDE-PluginInfo-Version=pre0.1
+X-KDE-PluginInfo-Website=http://plasma.kde.org/
+X-KDE-PluginInfo-Category=Applet
+X-KDE-PluginInfo-Depends=
+X-KDE-PluginInfo-License=BSD
+X-KDE-PluginInfo-EnabledByDefault=true
+X-Plasma-PackageFileFilter=*
+X-Plasma-PackageFileMimetypes=application/zip
Index: plasma-scriptengine-applet-web.desktop
===================================================================
--- plasma-scriptengine-applet-web.desktop	(revision 859729)
+++ plasma-scriptengine-applet-web.desktop	(working copy)
@@ -99,3 +99,4 @@
 X-KDE-PluginInfo-EnabledByDefault=true
 X-Plasma-API=webkit
 X-Plasma-ComponentTypes=Applet
+X-Plasma-PackageFormat=webapplet
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 859729)
+++ CMakeLists.txt	(working copy)
@@ -1,14 +1,19 @@
 project(plasma-webapplet)
 
-set(webapplet_SRCS
-    webpage.cpp webapplet.cpp webapplet_plugin.cpp plasmajs.cpp)
-
 include_directories( ${QT_INCLUDE_DIR}/QtWebKit )
 
+set(webapplet_SRCS
+    webpage.cpp webapplet.cpp plasmajs.cpp plasmawebapplet.cpp webapplet_plugin.cpp)
 kde4_add_plugin(plasma_appletscriptengine_webapplet ${webapplet_SRCS})
 target_link_libraries(plasma_appletscriptengine_webapplet plasma ${KDE4_KIO_LIBS} ${QT_QTWEBKIT_LIBRARY} )
 install(TARGETS plasma_appletscriptengine_webapplet DESTINATION ${PLUGIN_INSTALL_DIR})
 
+set(webappletpackage_SRCS
+    webapplet_package.cpp)
+kde4_add_plugin(plasma_packagestructure_web ${webappletpackage_SRCS})
+target_link_libraries(plasma_packagestructure_web plasma ${KDE4_KIO_LIBS} ${QT_QTWEBKIT_LIBRARY} )
+install(TARGETS plasma_packagestructure_web DESTINATION ${PLUGIN_INSTALL_DIR})
+
 set(dashboardapplet_SRCS
     webpage.cpp webapplet.cpp plasmajs.cpp dashboardapplet.cpp bundle.cpp)
 kde4_add_plugin(plasma_appletscriptengine_dashboard ${dashboardapplet_SRCS})
@@ -16,8 +21,7 @@
 install(TARGETS plasma_appletscriptengine_dashboard DESTINATION ${PLUGIN_INSTALL_DIR})
 
 set(bundlepackage_SRCS
-    bundle.cpp
-    dashboard_plugin.cpp)
+    bundle.cpp dashboard_plugin.cpp)
 kde4_add_plugin(plasma_packagestructure_dashboard ${bundlepackage_SRCS})
 target_link_libraries(plasma_packagestructure_dashboard  plasma ${KDE4_KIO_LIBS} ${QT_QTWEBKIT_LIBRARY} )
 install(TARGETS plasma_packagestructure_dashboard DESTINATION ${PLUGIN_INSTALL_DIR})
@@ -25,4 +29,5 @@
 install(FILES plasma-scriptengine-applet-web.desktop
               plasma-scriptengine-applet-dashboard.desktop
               plasma-packagestructure-dashboard.desktop
+              plasma-packagestructure-web.desktop
         DESTINATION ${SERVICES_INSTALL_DIR})
Index: dashboardapplet.cpp
===================================================================
--- dashboardapplet.cpp	(revision 859729)
+++ dashboardapplet.cpp	(working copy)
@@ -21,27 +21,11 @@
  */
 #include "dashboardapplet.h"
 
-#include <QGraphicsSceneMouseEvent>
-#include <kstandarddirs.h>
+#include <QWebFrame>
 
-#include <QApplication>
-#include <QPainter>
-#include <qdebug.h>
-#include <QtNetwork>
-#include <math.h>
+#include <Plasma/WebContent>
+#include <Plasma/Applet>
 
-#include <plasma/applet.h>
-#include <plasma/package.h>
-
-static inline QByteArray dataFor(const QString &str)
-{
-    QFile f(str);
-    f.open(QIODevice::ReadOnly);
-    QByteArray data = f.readAll();
-    f.close();
-    return data;
-}
-
 DashboardApplet::DashboardApplet(QObject *parent, const QVariantList &args)
     : WebApplet(parent, args)
 {
@@ -53,21 +37,14 @@
 
 bool DashboardApplet::init()
 {
-    WebApplet::init();
-    //applet()->setHasConfigurationInterface(false);
-    applet()->setAcceptsHoverEvents(true);
-    //FIXME: setBackgroundHints is protected now
-    //applet()->setBackgroundHints(Plasma::Applet::NoBackground);
-    QString webpage = package()->filePath("webpage");
-    //kDebug() << "webpage is at" << webpage;
+    applet()->setBackgroundHints(Plasma::Applet::NoBackground);
+    return WebApplet::init();
+}
 
-    if (webpage.isEmpty()) {
-        return false;
-    }
-
-    //kDebug() << QUrl(package()->path());
-    setHtml(dataFor(webpage), QUrl(package()->path()));
-    return true;
+void DashboardApplet::pageLoadFinished()
+{
+    QSize newSize = page()->mainFrame()->contentsSize();
+    applet()->setGeometry(QRectF(QPoint(), newSize));
 }
 
 #include "dashboardapplet.moc"

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to