File: web_module.h

package info (click to toggle)
kde-baseapps 4%3A16.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,308 kB
  • ctags: 12,389
  • sloc: cpp: 109,033; ansic: 2,197; python: 943; xml: 853; sh: 197; ruby: 112; makefile: 7
file content (145 lines) | stat: -rw-r--r-- 4,758 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* This file is part of the KDE project
   Copyright (C) 2003 George Staikos <staikos@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef web_module_h
#define web_module_h

#include <assert.h>
#include <khtml_part.h>
#include <kiconloader.h>
#include <klocale.h>
#include <konqsidebarplugin.h>
#include <kmenu.h>
#include <QtCore/QObject>


// A wrapper for KHTMLPart to make it behave the way we want it to.
class KHTMLSideBar : public KHTMLPart
{
    Q_OBJECT
public:
    KHTMLSideBar();
    virtual ~KHTMLSideBar() {}

	Q_SIGNALS:
		void submitFormRequest(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&);
		void openUrlRequest(const QString& url,
                                    const KParts::OpenUrlArguments& args = KParts::OpenUrlArguments(),
                                    const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments() );
		void openUrlNewWindow(const QString& url,
                                      const KParts::OpenUrlArguments& args = KParts::OpenUrlArguments(),
                                      const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments(),
                                      const KParts::WindowArgs& windowArgs = KParts::WindowArgs());
		void reload();
		void setAutoReload();

	protected:
    virtual bool urlSelected( const QString &url, int button,
                              int state, const QString &_target,
                              const KParts::OpenUrlArguments& args = KParts::OpenUrlArguments(),
                              const KParts::BrowserArguments& browserArgs = KParts::BrowserArguments() );

	protected Q_SLOTS:
		void loadPage() {
			emit openUrlRequest(completeURL(_lastUrl).url());
		}

		void loadNewWindow() {
			emit openUrlNewWindow(completeURL(_lastUrl).url());
		}

		void showMenu(const QString& url, const QPoint& pos) {
			if (url.isEmpty()) {
				_menu->popup(pos);
			} else {
				_lastUrl = url;
				_linkMenu->popup(pos);
			}
		}

		void formProxy(const char *action,
				const QString& url,
				const QByteArray& formData,
				const QString& target,
				const QString& contentType,
				const QString& boundary) {
			QString t = target.toLower();
			QString u;

			if (QString(action).toLower() != "post") {
				// GET
				KUrl kurl = completeURL(url);
				kurl.setQuery(formData.data());
				u = kurl.url();
			} else {
				u = completeURL(url).url();
			}

			// Some sites seem to use empty targets to send to the
			// main frame.
			if (t == "_content") {
				emit submitFormRequest(action, u, formData,
						target, contentType, boundary);
			} else if (t.isEmpty() || t == "_self") {
				setFormNotification(KHTMLPart::NoNotification);
				submitFormProxy(action, u, formData, target,
						contentType, boundary);
				setFormNotification(KHTMLPart::Only);
			}
		}
	private:
		KMenu *_menu, *_linkMenu;
		QString _lastUrl;
};



class KonqSideBarWebModule : public KonqSidebarModule
{
	Q_OBJECT
	public:
		KonqSideBarWebModule(const KComponentData &componentData, QWidget *parent,
                                     const KConfigGroup& configGroup);
		virtual ~KonqSideBarWebModule();

		virtual QWidget *getWidget();

	Q_SIGNALS:
                // TODO move to base class
		void submitFormRequest(const char*,const QString&,const QByteArray&,const QString&,const QString&,const QString&);
	protected:
		virtual void handleURL(const KUrl &url);

	private Q_SLOTS:
		void urlClicked(const QString& url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments& browserArgs);
    void formClicked(const KUrl& url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments& browserArgs);
		void urlNewWindow(const QString& url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments& browserArgs, const KParts::WindowArgs& windowArgs = KParts::WindowArgs());
		void pageLoaded();
		void loadFavicon();
		void setTitle(const QString&);
		void setAutoReload();
		void reload();

	private:
		KHTMLSideBar *_htmlPart;
		KUrl _url;
		int reloadTimeout;
};

#endif