On Thursday 11 September 2008 19:27:06 Petri Damstén wrote: > Diff attached is very much work in progress, but it's a start.
More features added, still have problems with background. Background was hidden under the webpage. Now it shows but it also shows in dashboard applet and I also cannot get background to be transparent (It should be possible?). It runs the html test applet here: http://kotisivu.lumonetti.fi/damu0/kde/html_test.zip http://kotisivu.lumonetti.fi/damu0/kde/screenshot.jpeg Petri
Index: webapplet_package.cpp =================================================================== --- webapplet_package.cpp (revision 0) +++ webapplet_package.cpp (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. +*/ + +#include "webapplet_package.h" + +#include <Plasma/Applet> + +WebAppletPackage::WebAppletPackage(QObject *parent, QVariantList args) +: Plasma::PackageStructure(parent, "Web") +{ + Q_UNUSED(args) + // copy the main applet structure + Plasma::PackageStructure::operator=(*Plasma::Applet::packageStructure()); + addFileDefinition("mainscript", "code/main.html", i18n("Main Script File")); + // For Webapplet::init() + addDirectoryDefinition("root", "/", i18n("Root html dir")); +} Index: webapplet_plugin.cpp =================================================================== --- webapplet_plugin.cpp (revision 860117) +++ 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 860117) +++ dashboardapplet.h (working copy) @@ -38,6 +38,10 @@ ~DashboardApplet(); bool init(); + +protected slots: + virtual void loadFinished(bool success); + virtual void initJsObjects(); }; 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(webkit, WebAppletPackage) + +#endif Index: bundle.cpp =================================================================== --- bundle.cpp (revision 860117) +++ 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 860117) +++ 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,34 @@ 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"; + //kDebug() << config.config()->name() << config.name(); + m_config = config; } +QVariant ConfigGroupWrapper::readEntry(const QString &key, const QVariant &aDefault) const +{ + // Should KConfig do this? + // There is readEntry(key, QVariant) but it does not seem to work + // (if writeEntry was not QVariant??) + if (aDefault.type() == QVariant::Int) { + return m_config.readEntry(key, aDefault.toInt()); + } else { + return m_config.readEntry(key, aDefault.toString()); + } +} + +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 +99,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 +119,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 +152,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 860117) +++ 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 860117) +++ 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,13 +44,16 @@ 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; }; @@ -74,18 +66,38 @@ 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; }; +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) const; + void writeEntry(const QString &key, const QVariant& value); + +private: + KConfigGroup m_config; +}; + #endif Index: plasmawebapplet.cpp =================================================================== --- plasmawebapplet.cpp (revision 0) +++ plasmawebapplet.cpp (revision 0) @@ -0,0 +1,214 @@ +/* +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 <QWebPage> +#include <QWebFrame> + +#include <KColorScheme> + +#include <Plasma/WebContent> +#include <Plasma/Applet> +#include <Plasma/Theme> + +#define JS_CONSTANTS \ +"var NoConstraint = 0;\n"\ +"var FormFactorConstraint = 1;\n"\ +"var LocationConstraint = 2;\n"\ +"var ScreenConstraint = 4;\n"\ +"var SizeConstraint = 8;\n"\ +"var ImmutableConstraint = 16;\n"\ +"var StartupCompletedConstraint = 32;\n"\ +"var ContextConstraint = 64;\n"\ +"var AllConstraints = FormFactorConstraint | LocationConstraint | ScreenConstraint |"\ + " SizeConstraint | ImmutableConstraint | ContextConstraint;\n"\ +"var NoBackground = 0;\n"\ +"var StandardBackground = 1\n"\ +"var TranslucentBackground = 2\n"\ +"var ShadowedBackground = 4\n"\ +"var DefaultBackground = StandardBackground | ShadowedBackground\n"\ +"var Horizontal = 1;\n"\ +"var Vertical = 2;\n"\ +"var ScrollBarAsNeeded = 0;\n"\ +"var ScrollBarAlwaysOff = 1;\n"\ +"var ScrollBarAlwaysOn = 2;\n"\ +"var InvalidAspectRatioMode = -1;\n"\ +"var IgnoreAspectRatio = 0;\n"\ +"var KeepAspectRatio = 1;\n"\ +"var Square = 2;\n"\ +"var ConstrainedSquare = 3;\n"\ +"" + +#define CSS "body { font-family: %3; font-size: %4pt; color:%1; background-color:%2 }\n" + +PlasmaWebApplet::PlasmaWebApplet(QObject *parent, const QVariantList &args) +: WebApplet(parent, args) +{ +} + +PlasmaWebApplet::~PlasmaWebApplet() +{ +} + +bool PlasmaWebApplet::init() +{ + applet()->setBackgroundHints(Plasma::Applet::DefaultBackground); + // FIXME: xml based config does not work with normal applet config + //config.setConfig(applet->config()); + m_config.setConfig(KConfigGroup(applet()->config().config(), applet()->pluginName())); + if (WebApplet::init()) { + connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), + this, SLOT(makeStylesheet())); + makeStylesheet(); + return true; + } + return false; +} + +void PlasmaWebApplet::makeStylesheet() +{ + if (m_temp.open()) { + KColorScheme plasmaColorTheme = KColorScheme(QPalette::Active, KColorScheme::View, + Plasma::Theme::defaultTheme()->colorScheme()); + //QColor headerColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::HighlightColor); + QColor textColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + QColor backgroundColor = + Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor); + QFont font = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont); + QString css = QString(CSS).arg(textColor.name()) + .arg(backgroundColor.name()) + .arg(font.family()) + .arg(font.pointSize()); + m_temp.write(css.toUtf8()); + kDebug() << m_temp.fileName(); + page()->page()->settings()->setUserStyleSheetUrl(QUrl(m_temp.fileName())); + m_temp.close(); + } +} + +void PlasmaWebApplet::loadFinished(bool success) +{ + if (success) { + page()->mainFrame()->evaluateJavaScript(JS_CONSTANTS); + callJsFunction("init"); + } +} + +void PlasmaWebApplet::constraintsEvent(Plasma::Constraints constraints) +{ + WebApplet::constraintsEvent(constraints); + callJsFunction("constraintsEvent", QVariantList() << (int)constraints); +} + +QVariant PlasmaWebApplet::arg(int index) const +{ + return m_args[index]; +} + +QObject* PlasmaWebApplet::objArg(int index) const +{ + return m_args[index].value<QObject*>(); +} + +QString PlasmaWebApplet::name() const +{ + return applet()->name(); +} + +QObject* PlasmaWebApplet::dataEngine(const QString& name) +{ + Plasma::DataEngine *de = applet()->dataEngine(name); + DataEngineWrapper *wrapper = de->findChild<DataEngineWrapper*>(); + if (!wrapper) { + wrapper = new DataEngineWrapper(de, this); + } + return wrapper; +} + +QObject* PlasmaWebApplet::config() +{ + return &m_config; +} + +void PlasmaWebApplet::resize(qreal w, qreal h) +{ + applet()->resize(w, h); +} + +void PlasmaWebApplet::setBackgroundHints(int hints) +{ + applet()->setBackgroundHints((Plasma::Applet::BackgroundHints)hints); +} + +void PlasmaWebApplet::setScrollBarPolicy(int orientation, int policy) +{ + page()->mainFrame()->setScrollBarPolicy((Qt::Orientation)orientation, + (Qt::ScrollBarPolicy)policy); +} + +void PlasmaWebApplet::setAspectRatioMode(int mode) +{ + applet()->setAspectRatioMode((Plasma::AspectRatioMode)mode); +} + +QVariant PlasmaWebApplet::callJsFunction(const QString& func, const QVariantList& args) +{ + m_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 PlasmaWebApplet::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data) +{ + m_dataEngineData.setData(data); + callJsFunction("dataUpdated", + QVariantList() << source << QVariant::fromValue((QObject*)&m_dataEngineData)); +} + +void PlasmaWebApplet::configChanged() +{ + callJsFunction("configChanged"); +} + +void PlasmaWebApplet::initJsObjects() +{ + QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); + Q_ASSERT(frame); + frame->addToJavaScriptWindowObject(QLatin1String("applet"), this); + frame->addToJavaScriptWindowObject(QLatin1String("plasma"), new PlasmaJs(this)); +} + +#include "plasmawebapplet.moc" Index: webapplet.cpp =================================================================== --- webapplet.cpp (revision 860117) +++ webapplet.cpp (working copy) @@ -22,15 +22,15 @@ #include "webapplet.h" #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; @@ -48,7 +48,8 @@ loaded = false; Plasma::Applet *applet = q->applet(); - applet->resize(150, 150); + applet->resize(300, 225); + applet->setAcceptsHoverEvents(true); page = new Plasma::WebContent(applet); page->setPage(new WebPage(page)); @@ -60,6 +61,10 @@ page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff); page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff); + + QPalette palette = page->palette(); + palette.setBrush(QPalette::Background, QBrush(Qt::transparent)); + page->setPalette(palette); } Plasma::WebContent *page; @@ -81,13 +86,33 @@ bool WebApplet::init() { d->init(this); + + QString webpage; + if (!package()->filePath("webpage").isEmpty()) { + webpage = package()->filePath("webpage"); // dashboard + } else { + webpage = package()->filePath("mainscript"); // plasma web applet + } + //kDebug() << page << "webpage is at" << webpage; + if (webpage.isEmpty()) { + return false; + } + //kDebug() << QUrl(package()->path()); + if (package()->filePath("root").isEmpty()) { + setHtml(dataFor(webpage), QUrl(package()->path())); // dashboard + } else { + setHtml(dataFor(webpage), QUrl(package()->filePath("root"))); // plasma web applet + } 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); @@ -113,17 +138,19 @@ void WebApplet::loadFinished(bool success) { - kDebug() << success; - if (success) { - QSize newSize = d->page->mainFrame()->contentsSize(); - applet()->setGeometry(QRectF(QPoint(), newSize)); - } + Q_UNUSED(success) } void WebApplet::constraintsEvent(Plasma::Constraints constraints) { if (d->page && constraints & Plasma::SizeConstraint) { - d->page->resize(size()); + qreal left; + qreal top; + qreal right; + qreal bottom; + applet()->getContentsMargins(&left, &top, &right, &bottom); + d->page->setPos(QPointF(left, top)); + d->page->resize(size() - QSizeF(left + right, top + bottom)); } } @@ -135,10 +162,6 @@ void WebApplet::initJsObjects() { - QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); - Q_ASSERT(frame); - frame->addToJavaScriptWindowObject(QLatin1String("applet"), this); - frame->addToJavaScriptWindowObject(QLatin1String("plasma"), new PlasmaJs(this)); } void WebApplet::setHtml(const QByteArray &html, const QUrl &baseUrl) @@ -163,4 +186,18 @@ 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; +} + #include "webapplet.moc" Index: plasmawebapplet.h =================================================================== --- plasmawebapplet.h (revision 0) +++ plasmawebapplet.h (revision 0) @@ -0,0 +1,73 @@ +/* +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" +#include "plasmajs.h" + +#include <KTemporaryFile> + +class PlasmaWebApplet : public WebApplet +{ + Q_OBJECT + Q_PROPERTY(QString name READ name) +public: + PlasmaWebApplet(QObject *parent, const QVariantList &args); + virtual ~PlasmaWebApplet(); + + virtual bool init(); + + QString name() const; + +public slots: + QObject* dataEngine(const QString& name); + QObject* config(); + void resize(qreal w, qreal h); + void setBackgroundHints(int hints); + void setScrollBarPolicy(int orientation, int policy); + void setAspectRatioMode(int mode); + + QVariant arg(int index) const; + QObject* objArg(int index) const; + void dataUpdated(const QString& source, const Plasma::DataEngine::Data &data); + void configChanged(); + void makeStylesheet(); + +protected: + QVariant callJsFunction(const QString &func, const QVariantList &args = QVariantList()); + void constraintsEvent(Plasma::Constraints constraints); + +protected slots: + virtual void loadFinished(bool success); + virtual void initJsObjects(); + +private: + QVariantList m_args; + DataEngineDataWrapper m_dataEngineData; + ConfigGroupWrapper m_config; + KTemporaryFile m_temp; +}; + +#endif Index: webapplet.h =================================================================== --- webapplet.h (revision 860117) +++ webapplet.h (working copy) @@ -24,6 +24,7 @@ #include <QUrl> +#include <Plasma/DataEngine> #include <plasma/scripting/appletscript.h> class QWebFrame; @@ -39,6 +40,7 @@ public: WebApplet(QObject *parent, const QVariantList &args); ~WebApplet(); + bool init(); public slots: @@ -52,11 +54,13 @@ const QStyleOptionGraphicsItem *option, const QRect &contentsRect); void constraintsEvent(Plasma::Constraints constraints); + static QByteArray dataFor(const QString &str); + Plasma::WebContent* page(); -private slots: - void loadFinished(bool); +protected slots: void connectFrame(QWebFrame *); - void initJsObjects(); + virtual void loadFinished(bool); + virtual void initJsObjects(); private: class Private; 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=webkit +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 860117) +++ 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=webkit Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 860117) +++ CMakeLists.txt (working copy) @@ -1,23 +1,27 @@ 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 plasmawebapplet.cpp plasmajs.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) + webpage.cpp webapplet.cpp dashboardapplet.cpp bundle.cpp) kde4_add_plugin(plasma_appletscriptengine_dashboard ${dashboardapplet_SRCS}) target_link_libraries(plasma_appletscriptengine_dashboard plasma ${KDE4_KIO_LIBS} ${QT_QTWEBKIT_LIBRARY} ) 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 860117) +++ 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,22 @@ 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; +void DashboardApplet::loadFinished(bool success) +{ + if (success) { + applet()->resize(page()->mainFrame()->contentsSize()); } +} - //kDebug() << QUrl(package()->path()); - setHtml(dataFor(webpage), QUrl(package()->path())); - return true; +void DashboardApplet::initJsObjects() +{ + QWebFrame *frame = qobject_cast<QWebFrame*>(sender()); + Q_ASSERT(frame); + frame->addToJavaScriptWindowObject(QLatin1String("applet"), this); } #include "dashboardapplet.moc"
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