~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to konqueror/sidebar/web_module/web_module.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-27 12:09:48 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20080527120948-dottsyd5rcwhzd36
Tags: 4:4.0.80-1ubuntu1
* Merge with Debian
 - remove 97_fix_target_link_libraries.diff
 - Add replaces/conflicts on -kde4 packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
   Copyright (C) 2003 George Staikos <staikos@kde.org>
3
 
 
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.
7
 
 
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.
12
 
 
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.
17
 
*/
18
 
 
19
 
#ifndef web_module_h
20
 
#define web_module_h
21
 
 
22
 
#include <assert.h>
23
 
#include <khtml_part.h>
24
 
#include <kiconloader.h>
25
 
#include <klocale.h>
26
 
#include <konqsidebarplugin.h>
27
 
#include <kpopupmenu.h>
28
 
#include <qobject.h>
29
 
 
30
 
 
31
 
// A wrapper for KHTMLPart to make it behave the way we want it to.
32
 
class KHTMLSideBar : public KHTMLPart
33
 
{
34
 
        Q_OBJECT
35
 
        public:
36
 
                KHTMLSideBar(bool universal) : KHTMLPart() {
37
 
                        setStatusMessagesEnabled(false);
38
 
                        setMetaRefreshEnabled(true);
39
 
                        setJavaEnabled(false);
40
 
                        setPluginsEnabled(false);
41
 
 
42
 
                        setFormNotification(KHTMLPart::Only);
43
 
                        connect(this,
44
 
                                SIGNAL(formSubmitNotification(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&)),
45
 
                                this,
46
 
                                SLOT(formProxy(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&))
47
 
                                );
48
 
 
49
 
 
50
 
                        _linkMenu = new KPopupMenu(widget(),
51
 
                                        "link context menu");
52
 
                        if (!universal) {
53
 
                                _linkMenu->insertItem(i18n("&Open Link"),
54
 
                                                this, SLOT(loadPage()));
55
 
                                _linkMenu->insertItem(i18n("Open in New &Window"),
56
 
                                                this, SLOT(loadNewWindow()));
57
 
                        } else {
58
 
                                _linkMenu->insertItem(i18n("Open in New &Window"),
59
 
                                                this, SLOT(loadPage()));
60
 
                        }
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()));
65
 
 
66
 
                        connect(this,
67
 
                                SIGNAL(popupMenu(const QString&,const QPoint&)),
68
 
                                this,
69
 
                                SLOT(showMenu(const QString&, const QPoint&)));
70
 
 
71
 
                }
72
 
                virtual ~KHTMLSideBar() {}
73
 
 
74
 
        signals:
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);
78
 
                void reload();
79
 
                void setAutoReload();
80
 
 
81
 
        protected:
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") {
87
 
                                        openURL(url);
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);
92
 
                                }
93
 
                                return;
94
 
                        }
95
 
                        if (button == MidButton) {
96
 
                                emit openURLNewWindow(completeURL(url).url(),
97
 
                                                args);
98
 
                                return;
99
 
                        }
100
 
                        // A refresh
101
 
                        if (button == 0 && _target.lower() == "_self") {
102
 
                                openURL(completeURL(url));
103
 
                                return;
104
 
                        }
105
 
                        KHTMLPart::urlSelected(url,button,state,_target,args);
106
 
                }
107
 
 
108
 
        protected slots:
109
 
                void loadPage() {
110
 
                        emit openURLRequest(completeURL(_lastUrl).url(),
111
 
                                                KParts::URLArgs());
112
 
                }
113
 
 
114
 
                void loadNewWindow() {
115
 
                        emit openURLNewWindow(completeURL(_lastUrl).url(),
116
 
                                                KParts::URLArgs());
117
 
                }
118
 
 
119
 
                void showMenu(const QString& url, const QPoint& pos) {
120
 
                        if (url.isEmpty()) {
121
 
                                _menu->popup(pos);
122
 
                        } else {
123
 
                                _lastUrl = url;
124
 
                                _linkMenu->popup(pos);
125
 
                        }
126
 
                }
127
 
 
128
 
                void formProxy(const char *action,
129
 
                                const QString& url,
130
 
                                const QByteArray& formData,
131
 
                                const QString& target,
132
 
                                const QString& contentType,
133
 
                                const QString& boundary) {
134
 
                        QString t = target.lower();
135
 
                        QString u;
136
 
 
137
 
                        if (QCString(action).lower() != "post") {
138
 
                                // GET
139
 
                                KURL kurl = completeURL(url);
140
 
                                kurl.setQuery(formData.data());
141
 
                                u = kurl.url();
142
 
                        } else {
143
 
                                u = completeURL(url).url();
144
 
                        }
145
 
 
146
 
                        // Some sites seem to use empty targets to send to the
147
 
                        // main frame.
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);
156
 
                        }
157
 
                }
158
 
        private:
159
 
                KPopupMenu *_menu, *_linkMenu;
160
 
                QString _lastUrl;
161
 
};
162
 
 
163
 
 
164
 
 
165
 
class KonqSideBarWebModule : public KonqSidebarPlugin
166
 
{
167
 
        Q_OBJECT
168
 
        public:
169
 
                KonqSideBarWebModule(KInstance *instance, QObject *parent,
170
 
                                QWidget *widgetParent, QString &desktopName,
171
 
                                const char *name);
172
 
                virtual ~KonqSideBarWebModule();
173
 
 
174
 
                virtual QWidget *getWidget();
175
 
                virtual void *provides(const QString &);
176
 
 
177
 
        signals:
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);
181
 
        protected:
182
 
                virtual void handleURL(const KURL &url);
183
 
 
184
 
        private slots:
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);
188
 
                void pageLoaded();
189
 
                void loadFavicon();
190
 
                void setTitle(const QString&);
191
 
                void setAutoReload();
192
 
                void reload();
193
 
 
194
 
        private:
195
 
                KHTMLSideBar *_htmlPart;
196
 
                KURL _url;
197
 
                int reloadTimeout;
198
 
                QString _desktopName;
199
 
};
200
 
 
201
 
#endif
202