1 /* This file is part of the KDE project
2 Copyright (C) 2003, George Staikos <staikos@kde.org>
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "web_module.h"
20 #include "favicon_interface.h"
22 #include <QtCore/QFileInfo>
23 #include <QtGui/QSpinBox>
24 #include <QtCore/QTimer>
26 #include <dom/html_inline.h>
31 #include <kparts/browserextension.h>
32 #include <kstandarddirs.h>
36 KonqSideBarWebModule::KonqSideBarWebModule(const KComponentData
&componentData
, QObject
*parent
, QWidget
*widgetParent
, QString
&desktopName
, const char* name
)
37 : KonqSidebarPlugin(componentData
, parent
, widgetParent
, desktopName
, name
)
39 _htmlPart
= new KHTMLSideBar(universalMode());
40 connect(_htmlPart
, SIGNAL(reload()), this, SLOT(reload()));
41 connect(_htmlPart
, SIGNAL(completed()), this, SLOT(pageLoaded()));
43 SIGNAL(setWindowCaption(const QString
&)),
45 SLOT(setTitle(const QString
&)));
47 SIGNAL(openUrlRequest(QString
, KParts::OpenUrlArguments
, KParts::BrowserArguments
)),
49 SLOT(urlClicked(QString
, KParts::OpenUrlArguments
, KParts::BrowserArguments
)));
50 connect(_htmlPart
->browserExtension(),
51 SIGNAL(openUrlRequest(QString
, const KParts::OpenUrlArguments
&, const KParts::BrowserArguments
&)),
53 SLOT(formClicked(QString
, const KParts::OpenUrlArguments
&, const KParts::BrowserArguments
&)) );
55 SIGNAL(setAutoReload()), this, SLOT( setAutoReload() ));
57 SIGNAL(openUrlNewWindow(const QString
&, KParts::OpenUrlArguments
, KParts::BrowserArguments
)),
59 SLOT(urlNewWindow(const QString
&, KParts::OpenUrlArguments
, KParts::BrowserArguments
)));
61 SIGNAL(submitFormRequest(const char*,const QString
&,const QByteArray
&,const QString
&,const QString
&,const QString
&)),
63 SIGNAL(submitFormRequest(const char*,const QString
&,const QByteArray
&,const QString
&,const QString
&,const QString
&)));
65 _desktopName
= desktopName
;
67 KConfig
_ksc( _desktopName
, KConfig::SimpleConfig
);
68 KConfigGroup
ksc(&_ksc
, "Desktop Entry");
69 reloadTimeout
= ksc
.readEntry("Reload", 0);
70 _url
= ksc
.readPathEntry("URL", QString());
71 _htmlPart
->openUrl(_url
);
72 // Must load this delayed
73 QTimer::singleShot(0, this, SLOT(loadFavicon()));
77 KonqSideBarWebModule::~KonqSideBarWebModule() {
83 QWidget
*KonqSideBarWebModule::getWidget() {
84 return _htmlPart
->widget();
87 void KonqSideBarWebModule::setAutoReload(){
90 dlg
.setCaption( i18n("Set Refresh Timeout (0 disables)" ) );
91 dlg
.setButtons( KDialog::Ok
| KDialog::Cancel
);
93 KHBox
*hbox
= new KHBox( &dlg
);
94 dlg
.setMainWidget( hbox
);
96 QSpinBox
*mins
= new QSpinBox( hbox
);
97 mins
->setRange(0, 120);
98 mins
->setSuffix( i18n(" min") );
99 QSpinBox
*secs
= new QSpinBox( 0, 59, 1, hbox
);
100 secs
->setSuffix( i18n(" sec") );
102 if( reloadTimeout
> 0 ) {
103 int seconds
= reloadTimeout
/ 1000;
104 secs
->setValue( seconds
% 60 );
105 mins
->setValue( ( seconds
- secs
->value() ) / 60 );
108 if( dlg
.exec() == KDialog::Accepted
) {
109 int msec
= ( mins
->value() * 60 + secs
->value() ) * 1000;
110 reloadTimeout
= msec
;
111 KConfig
_ksc( _desktopName
, KConfig::SimpleConfig
);
112 KConfigGroup
ksc(&_ksc
, "Desktop Entry");
113 ksc
.writeEntry("Reload", reloadTimeout
);
118 void *KonqSideBarWebModule::provides(const QString
&) {
123 void KonqSideBarWebModule::handleURL(const KUrl
&) {
127 void KonqSideBarWebModule::urlNewWindow(const QString
& url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
& browserArgs
)
129 emit
createNewWindow(KUrl(url
), args
, browserArgs
);
133 void KonqSideBarWebModule::urlClicked(const QString
& url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
& browserArgs
)
135 emit
openUrlRequest(KUrl(url
), args
, browserArgs
);
139 void KonqSideBarWebModule::formClicked(const KUrl
& url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
& browserArgs
)
141 _htmlPart
->setArguments( args
);
142 _htmlPart
->browserExtension()->setBrowserArguments(browserArgs
);
143 _htmlPart
->openUrl(url
);
146 void KonqSideBarWebModule::loadFavicon() {
147 QString icon
= KMimeType::favIconForUrl(_url
);
148 if (icon
.isEmpty()) {
149 org::kde::FavIcon
favicon("org.kde.kded", "/modules/favicons", QDBusConnection::sessionBus());
150 favicon
.downloadHostIcon(_url
.url());
151 icon
= KMimeType::favIconForUrl(_url
);
154 if (!icon
.isEmpty()) {
157 KConfig
_ksc( _desktopName
, KConfig::SimpleConfig
);
158 KConfigGroup
ksc(&_ksc
, "Desktop Entry");
159 if (icon
!= ksc
.readPathEntry("Icon", QString())) {
160 ksc
.writePathEntry("Icon", icon
);
166 void KonqSideBarWebModule::reload() {
167 _htmlPart
->openUrl(_url
);
171 void KonqSideBarWebModule::setTitle(const QString
& title
) {
172 if (!title
.isEmpty()) {
173 emit
setCaption(title
);
175 KConfig
_ksc( _desktopName
, KConfig::SimpleConfig
);
176 KConfigGroup
ksc(&_ksc
, "Desktop Entry");
177 if (title
!= ksc
.readPathEntry("Name", QString())) {
178 ksc
.writePathEntry("Name", title
);
184 void KonqSideBarWebModule::pageLoaded() {
185 if( reloadTimeout
> 0 ) {
186 QTimer::singleShot( reloadTimeout
, this, SLOT( reload() ) );
192 KDE_EXPORT KonqSidebarPlugin
* create_konqsidebar_web(const KComponentData
&componentData
, QObject
*parent
, QWidget
*widget
, QString
&desktopName
, const char *name
) {
193 return new KonqSideBarWebModule(componentData
, parent
, widget
, desktopName
, name
);
199 KDE_EXPORT
bool add_konqsidebar_web(QString
* fn
, QString
* param
, QMap
<QString
,QString
> *map
) {
201 KGlobal::dirs()->addResourceType("websidebardata", "data", "konqsidebartng/websidebar");
203 url
.setProtocol("file");
204 QStringList paths
= KGlobal::dirs()->resourceDirs("websidebardata");
205 for (QStringList::Iterator i
= paths
.begin(); i
!= paths
.end(); ++i
) {
206 if (QFileInfo(*i
+ "websidebar.html").exists()) {
207 url
.setPath(*i
+ "websidebar.html");
212 if (url
.path().isEmpty())
214 map
->insert("Type", "Link");
215 map
->insert("URL", url
.url());
216 map
->insert("Icon", "netscape");
217 map
->insert("Name", i18n("Web SideBar Plugin"));
218 map
->insert("Open", "true");
219 map
->insert("X-KDE-KonqSidebarModule","konqsidebar_web");
220 fn
->setLatin1("websidebarplugin%1.desktop");
226 bool KHTMLSideBar::urlSelected( const QString
&url
, int button
,
227 int state
, const QString
&_target
,
228 const KParts::OpenUrlArguments
& args
,
229 const KParts::BrowserArguments
& browserArgs
)
231 if (button
== Qt::LeftButton
){
232 if (_target
.toLower() == "_self") {
234 } else if (_target
.toLower() == "_blank") {
235 emit
openUrlNewWindow(completeURL(url
).url(), args
);
236 } else { // isEmpty goes here too
237 emit
openUrlRequest(completeURL(url
).url(), args
);
241 if (button
== Qt::MidButton
) {
242 emit
openUrlNewWindow(completeURL(url
).url(),
247 if (button
== 0 && _target
.toLower() == "_self") {
248 openUrl(completeURL(url
));
251 return KHTMLPart::urlSelected(url
, button
, state
, _target
, args
, browserArgs
);
254 #include "web_module.moc"