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.
23
#include <khtml_part.h>
24
#include <kiconloader.h>
26
#include <konqsidebarplugin.h>
27
#include <kpopupmenu.h>
31
// A wrapper for KHTMLPart to make it behave the way we want it to.
32
class KHTMLSideBar : public KHTMLPart
36
KHTMLSideBar(bool universal) : KHTMLPart() {
37
setStatusMessagesEnabled(false);
38
setMetaRefreshEnabled(true);
39
setJavaEnabled(false);
40
setPluginsEnabled(false);
42
setFormNotification(KHTMLPart::Only);
44
SIGNAL(formSubmitNotification(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&)),
46
SLOT(formProxy(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&))
50
_linkMenu = new KPopupMenu(widget(),
53
_linkMenu->insertItem(i18n("&Open Link"),
54
this, SLOT(loadPage()));
55
_linkMenu->insertItem(i18n("Open in New &Window"),
56
this, SLOT(loadNewWindow()));
58
_linkMenu->insertItem(i18n("Open in New &Window"),
59
this, SLOT(loadPage()));
61
_menu = new KPopupMenu(widget(), "context menu");
62
_menu->insertItem(SmallIcon("reload"), i18n("&Reload"),
63
this, SIGNAL(reload()));
64
_menu->insertItem(SmallIcon("reload"), i18n("Set &Automatic Reload"), this, SIGNAL(setAutoReload()));
67
SIGNAL(popupMenu(const QString&,const QPoint&)),
69
SLOT(showMenu(const QString&, const QPoint&)));
72
virtual ~KHTMLSideBar() {}
75
void submitFormRequest(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&);
76
void openURLRequest(const QString& url, KParts::URLArgs args);
77
void openURLNewWindow(const QString& url, KParts::URLArgs args);
82
virtual void urlSelected( const QString &url, int button,
83
int state, const QString &_target,
84
KParts::URLArgs args = KParts::URLArgs()) {
85
if (button == LeftButton ){
86
if (_target.lower() == "_self") {
88
} else if (_target.lower() == "_blank") {
89
emit openURLNewWindow(completeURL(url).url(), args);
90
} else { // isEmpty goes here too
91
emit openURLRequest(completeURL(url).url(), args);
95
if (button == MidButton) {
96
emit openURLNewWindow(completeURL(url).url(),
101
if (button == 0 && _target.lower() == "_self") {
102
openURL(completeURL(url));
105
KHTMLPart::urlSelected(url,button,state,_target,args);
110
emit openURLRequest(completeURL(_lastUrl).url(),
114
void loadNewWindow() {
115
emit openURLNewWindow(completeURL(_lastUrl).url(),
119
void showMenu(const QString& url, const QPoint& pos) {
124
_linkMenu->popup(pos);
128
void formProxy(const char *action,
130
const QByteArray& formData,
131
const QString& target,
132
const QString& contentType,
133
const QString& boundary) {
134
QString t = target.lower();
137
if (QCString(action).lower() != "post") {
139
KURL kurl = completeURL(url);
140
kurl.setQuery(formData.data());
143
u = completeURL(url).url();
146
// Some sites seem to use empty targets to send to the
148
if (t == "_content") {
149
emit submitFormRequest(action, u, formData,
150
target, contentType, boundary);
151
} else if (t.isEmpty() || t == "_self") {
152
setFormNotification(KHTMLPart::NoNotification);
153
submitFormProxy(action, u, formData, target,
154
contentType, boundary);
155
setFormNotification(KHTMLPart::Only);
159
KPopupMenu *_menu, *_linkMenu;
165
class KonqSideBarWebModule : public KonqSidebarPlugin
169
KonqSideBarWebModule(KInstance *instance, QObject *parent,
170
QWidget *widgetParent, QString &desktopName,
172
virtual ~KonqSideBarWebModule();
174
virtual QWidget *getWidget();
175
virtual void *provides(const QString &);
178
void submitFormRequest(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&);
179
void openURLRequest(const KURL &url, const KParts::URLArgs &args);
180
void createNewWindow(const KURL &url, const KParts::URLArgs &args);
182
virtual void handleURL(const KURL &url);
185
void urlClicked(const QString& url, KParts::URLArgs args);
186
void formClicked(const KURL& url, const KParts::URLArgs& args);
187
void urlNewWindow(const QString& url, KParts::URLArgs args);
190
void setTitle(const QString&);
191
void setAutoReload();
195
KHTMLSideBar *_htmlPart;
198
QString _desktopName;