• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

webapplet.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2007 Zack Rusin <zack@kde.org>
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021  */
00022 #include "webapplet.h"
00023 
00024 #include "webpage.h"
00025 
00026 #include <QPainter>
00027 #include <QWebView>
00028 #include <QWebFrame>
00029 #include <QWebPage>
00030 #include <QFile>
00031 
00032 #include <Plasma/Applet>
00033 #include <Plasma/Package>
00034 #include <Plasma/WebView>
00035 
00036 using namespace Plasma;
00037 
00038 class WebApplet::Private
00039 {
00040 public:
00041     Private()
00042         : page(0)
00043     {
00044     }
00045 
00046     void init(WebApplet *q)
00047     {
00048         loaded = false;
00049 
00050         Plasma::Applet *applet = q->applet();
00051         applet->setAcceptsHoverEvents(true);
00052 
00053         page = new Plasma::WebView(applet);
00054         page->setPage(new WebPage(page));
00055         QObject::connect(page, SIGNAL(loadFinished(bool)),
00056                          q, SLOT(loadFinished(bool)));
00057         QObject::connect(page->page(), SIGNAL(frameCreated(QWebFrame *)),
00058                          q, SLOT(connectFrame(QWebFrame *)));
00059         q->connectFrame(page->mainFrame());
00060 
00061         page->mainFrame()->setScrollBarPolicy(Qt::Horizontal, Qt::ScrollBarAlwaysOff);
00062         page->mainFrame()->setScrollBarPolicy(Qt::Vertical, Qt::ScrollBarAlwaysOff);
00063 
00064         QPalette palette = page->palette();
00065         palette.setBrush(QPalette::Background, QBrush(Qt::transparent));
00066         page->setPalette(palette);
00067     }
00068 
00069     Plasma::WebView *page;
00070     bool loaded;
00071 };
00072 
00073 WebApplet::WebApplet(QObject *parent, const QVariantList &args)
00074     : AppletScript(parent),
00075       d(new Private)
00076 {
00077     Q_UNUSED(args)
00078 }
00079 
00080 WebApplet::~WebApplet()
00081 {
00082     delete d;
00083 }
00084 
00085 bool WebApplet::init()
00086 {
00087     d->init(this);
00088 
00089     QString webpage;
00090     webpage = package()->filePath("mainscript");
00091     //kDebug() << "webpage is at" << webpage;
00092     if (webpage.isEmpty()) {
00093         return false;
00094     }
00095     //kDebug() << package()->path() << package()->filePath("root");
00096     d->page->mainFrame()->setHtml(dataFor(webpage), QUrl(package()->filePath("root")));
00097     return true;
00098 }
00099 
00100 void WebApplet::paintInterface(QPainter *painter,
00101                                const QStyleOptionGraphicsItem *option,
00102                                const QRect &contentsRect)
00103 {
00104     Q_UNUSED(painter)
00105     Q_UNUSED(option)
00106     Q_UNUSED(contentsRect)
00107 }
00108 
00109 Plasma::WebView* WebApplet::view() const
00110 {
00111     return d->page;
00112 }
00113 
00114 void WebApplet::loadFinished(bool success)
00115 {
00116     d->loaded = success;
00117 }
00118 
00119 void WebApplet::connectFrame(QWebFrame *frame)
00120 {
00121     connect(frame, SIGNAL(javaScriptWindowObjectCleared()),
00122             this, SLOT(initJsObjects()));
00123 }
00124 
00125 void WebApplet::initJsObjects()
00126 {
00127 }
00128 
00129 QByteArray WebApplet::dataFor(const QString &str)
00130 {
00131     QFile f(str);
00132     f.open(QIODevice::ReadOnly);
00133     QByteArray data = f.readAll();
00134     f.close();
00135     return data;
00136 }
00137 
00138 Plasma::WebView* WebApplet::page()
00139 {
00140     return d->page;
00141 }
00142 
00143 bool WebApplet::loaded()
00144 {
00145     return d->loaded;
00146 }
00147 
00148 #include "webapplet.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal