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

Plasma

dashboardapplet.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2007 Zack Rusin <zack@kde.org>
00003 Copyright (c) 2008 Beat Wolf <asraniel@fryx.ch>
00004 
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011 
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022  */
00023 #include "dashboardapplet.h"
00024 
00025 #include <QWebFrame>
00026 #include <QFile>
00027 #include <QByteArray>
00028 
00029 #include <KGlobal>
00030 #include <KStandardDirs>
00031 
00032 #include <Plasma/WebView>
00033 #include <Plasma/Applet>
00034 #include <Plasma/Package>
00035 
00036 #include "dashboardjs.h"
00037 
00038 DashboardApplet::DashboardApplet(QObject *parent, const QVariantList &args)
00039     : WebApplet(parent, args)
00040 {
00041 }
00042 
00043 DashboardApplet::~DashboardApplet()
00044 {
00045 }
00046 
00047 bool DashboardApplet::init()
00048 {
00049     applet()->setAspectRatioMode(Plasma::FixedSize);
00050     return WebApplet::init();
00051 }
00052 
00053 void DashboardApplet::loadFinished(bool success)
00054 {
00055     WebApplet::loadFinished(success);
00056     if (success) {
00057         page()->resize(page()->mainFrame()->contentsSize());
00058         applet()->resize(page()->mainFrame()->contentsSize());
00059     }
00060 }
00061 
00062 void DashboardApplet::constraintsEvent(Plasma::Constraints constraints)
00063 {
00064     if (constraints & Plasma::FormFactorConstraint) {
00065         applet()->setBackgroundHints(Plasma::Applet::NoBackground);
00066     }
00067 }
00068 
00069 void DashboardApplet::initJsObjects()
00070 {
00071     QWebFrame *frame = qobject_cast<QWebFrame*>(sender());
00072     Q_ASSERT(frame);
00073     frame->addToJavaScriptWindowObject(QLatin1String("applet"), this);
00074     frame->addToJavaScriptWindowObject(QLatin1String("widget"), new DashboardJs(frame, this, applet()));
00075 }
00076 
00077 QByteArray DashboardApplet::dataFor(const QString &str)
00078 {
00079     QFile f(str);
00080     f.open(QIODevice::ReadOnly);
00081     QByteArray data = f.readAll();
00082     f.close();
00083 
00084     //replace the apple javascript imports with the kde ones
00085     QString jsBaseDir = KGlobal::dirs()->findResourceDir("data","plasma/dashboard/button/genericButton.js") 
00086                             + "plasma/dashboard";
00087 
00088     data.replace("file:///System/Library/WidgetResources", jsBaseDir.toUtf8());
00089     data.replace("/System/Library/WidgetResources", jsBaseDir.toUtf8());
00090 
00091     return data;
00092 }
00093 
00094 #include "dashboardapplet.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