Plasma
dashboardjs.cpp
Go to the documentation of this file.00001 /* 00002 Copyright (c) 2008 Beat Wolf <asraniel@fryx.ch> 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 00023 #include "dashboardjs.h" 00024 #include <kdebug.h> 00025 00026 #include <KRun> 00027 #include <KConfigGroup> 00028 00029 #include <QPainter> 00030 #include <QStyleOptionGraphicsItem> 00031 #include <QWidget> 00032 00033 #include <QGraphicsItem> 00034 #include <QEvent> 00035 #include <QGraphicsScene> 00036 00037 DashboardJs::DashboardJs(QWebFrame *frame, QObject *parent, Plasma::Applet *applet) 00038 : QObject(parent) 00039 { 00040 m_applet = applet; 00041 m_frame = frame; 00042 } 00043 00044 DashboardJs::~DashboardJs() 00045 { 00046 if(m_frame){ 00047 kDebug() << "deconstructor calles javascript: " << m_onremove; 00048 m_frame->evaluateJavaScript(m_onremove); 00049 } 00050 } 00051 00052 void DashboardJs::openApplication(QString name) 00053 { 00054 //STUB 00055 kDebug() << "not implemented: open application" << name; 00056 00057 //WARNING: this might be dangerous and exploited (or not) 00058 /* create list of applications: 00059 * com.apple.ical 00060 * com.RealNetworks.RealPlayer 00061 */ 00062 } 00063 00064 void DashboardJs::openURL(QString name) 00065 { 00066 //TODO: this could be dangerous(really?). filter valid urls 00067 new KRun(name, 0); 00068 } 00069 00070 QVariant DashboardJs::preferenceForKey(QString key) 00071 { 00072 KConfigGroup conf = m_applet->config(); 00073 00074 if (!conf.hasKey(key)) { 00075 return QVariant(); 00076 } 00077 00078 return conf.readEntry(key,""); 00079 } 00080 00081 void DashboardJs::prepareForTransition(QString transition) 00082 { 00083 //STUB 00084 kDebug() << "not implemented: transition with name" << transition; 00085 //TODO:freeze widget drawing. possible? 00086 //not really needed for things to work, but would be prettier 00087 } 00088 00089 void DashboardJs::performTransition() 00090 { 00091 //STUB 00092 //TODO: enable widget drawing again, perform nice animation. 00093 kDebug() << "not implemented: perform transition"; 00094 //not really needed for things to work, but would be prettier 00095 } 00096 00097 void DashboardJs::setCloseBoxOffset(int x, int y) 00098 { 00099 //STUB, not needed, plasma has its own close box 00100 kDebug() << "not implemented: close box offset" << x << y; 00101 } 00102 00103 void DashboardJs::setPreferenceForKey(QString value, QString key) 00104 { 00105 kDebug() << "save key" << key << value; 00106 KConfigGroup conf = m_applet->config(); 00107 conf.writeEntry(key, value); 00108 } 00109 00110 void DashboardJs::system(QString command, QString handler) 00111 { 00112 //WARNING: this might be dangerous and exploited. 00113 //STUB 00114 kDebug() << "not implemented: system command:" << command << handler; 00115 } 00116 00117 //Property sets and gets 00118 QString DashboardJs::identifier() const 00119 { 00120 return QString::number(m_applet->id()); 00121 } 00122 00123 QString DashboardJs::onshow() const 00124 { 00125 return m_onshow; 00126 } 00127 00128 void DashboardJs::setOnshow(const QString &value) 00129 { 00130 m_onshow = value; 00131 } 00132 00133 QString DashboardJs::onhide() const 00134 { 00135 return m_onhide; 00136 } 00137 00138 void DashboardJs::setOnhide(const QString &value) 00139 { 00140 m_onhide = value; 00141 } 00142 00143 QString DashboardJs::onremove() const 00144 { 00145 return m_onremove; 00146 } 00147 00148 void DashboardJs::setOnremove(const QString &value) 00149 { 00150 m_onremove = value; 00151 } 00152 00153 00154 QString DashboardJs::ondragstart() const 00155 { 00156 return m_ondragstart; 00157 } 00158 00159 void DashboardJs::setOndragstart(const QString &value) 00160 { 00161 m_ondragstart = value; 00162 } 00163 00164 QString DashboardJs::ondragstop() const 00165 { 00166 return m_ondragstop; 00167 } 00168 00169 void DashboardJs::setOndragstop(const QString &value) 00170 { 00171 m_ondragstop = value; 00172 } 00173 //only for testing purpose 00174 //TODO: remove when not needed anymore 00175 void DashboardJs::hello(int test) 00176 { 00177 kDebug() << "hello world" << test; 00178 } 00179