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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/* ============================================================
*
* This file is a part of the rekonq project
*
* Copyright (C) 2008-2010 by Andrea Diamantini <adjam7 at gmail dot com>
* Copyright (C) 2009-2010 by Lionel Chauvin <megabigbug@yahoo.fr>
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ============================================================ */
// Self Includes
#include "webtab.h"
#include "webtab.moc"
// Auto Includes
#include "rekonq.h"
// Local Includes
#include "application.h"
#include "mainwindow.h"
#include "mainview.h"
#include "webpage.h"
#include "bookmarksmanager.h"
#include "walletbar.h"
#include "previewselectorbar.h"
// KDE Includes
#include <KService>
#include <KUriFilterData>
#include <KStandardShortcut>
#include <KMenu>
#include <KActionMenu>
#include <KWebView>
#include <kwebwallet.h>
#include <KDE/KMessageBox>
// Qt Includes
#include <QContextMenuEvent>
#include <QWheelEvent>
#include <QMouseEvent>
#include <QClipboard>
#include <QKeyEvent>
#include <QAction>
#include <QVBoxLayout>
// Defines
#define QL1S(x) QLatin1String(x)
WebTab::WebTab(QWidget *parent)
: QWidget(parent)
, m_progress(0)
{
QVBoxLayout *l = new QVBoxLayout(this);
l->setMargin(0);
l->setSpacing(0);
QWidget *messageBar = new QWidget(this);
l->addWidget(messageBar);
messageBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Minimum);
QVBoxLayout *l2 = new QVBoxLayout(messageBar);
l2->setMargin(0);
l2->setSpacing(0);
WebView *view = new WebView(this);
l->addWidget(view);
view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// fix focus handling
setFocusProxy( view );
KWebWallet *wallet = view->page()->wallet();
if(wallet)
{
connect(wallet, SIGNAL(saveFormDataRequested(const QString &, const QUrl &)),
this, SLOT(createWalletBar(const QString &, const QUrl &)));
}
connect(view, SIGNAL(loadProgress(int)), this, SLOT(updateProgress(int)));
connect(view, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool)));
}
WebTab::~WebTab()
{
}
WebView *WebTab::view()
{
WebView *view = qobject_cast<WebView *>( layout()->itemAt(1)->widget() );
return view;
}
WebPage *WebTab::page()
{
return view()->page();
}
KUrl WebTab::url()
{
return KUrl( view()->url() );
}
int WebTab::progress()
{
return m_progress;
}
void WebTab::updateProgress(int p)
{
m_progress = p;
}
void WebTab::loadFinished(bool)
{
m_progress = 0;
}
void WebTab::createWalletBar(const QString &key, const QUrl &url)
{
// check if the url is in the wallet blacklist
QString urlString = url.toString();
QStringList blackList = ReKonfig::walletBlackList();
if( blackList.contains( urlString ) )
return;
KWebWallet *wallet = page()->wallet();
QWidget *messageBar = layout()->itemAt(0)->widget();
WalletBar *walletBar = new WalletBar(messageBar);
walletBar->onSaveFormData(key,url);
messageBar->layout()->addWidget(walletBar);
connect(walletBar, SIGNAL(saveFormDataAccepted(const QString &)),
wallet, SLOT(acceptSaveFormDataRequest(const QString &)));
connect(walletBar, SIGNAL(saveFormDataRejected(const QString &)),
wallet, SLOT(rejectSaveFormDataRequest(const QString &)));
}
void WebTab::createPreviewSelectorBar(int index)
{
QWidget *messageBar = layout()->itemAt(0)->widget();
PreviewSelectorBar *bar = new PreviewSelectorBar(index, messageBar);
messageBar->layout()->addWidget(bar);
connect(page(), SIGNAL(loadStarted()), bar, SLOT(loadProgress()));
connect(page(), SIGNAL(loadProgress(int)), bar, SLOT(loadProgress()));
connect(page(), SIGNAL(loadFinished(bool)), bar, SLOT(loadFinished()));
connect(page()->mainFrame(), SIGNAL(urlChanged(QUrl)), bar, SLOT(verifyUrl()));
}
bool WebTab::hasRSSInfo()
{
_rssList.clear();
QWebElementCollection col = page()->mainFrame()->findAllElements("link");
foreach(QWebElement el, col)
{
if( el.attribute("type") == QL1S("application/rss+xml") || el.attribute("type") == QL1S("application/rss+xml") )
{
KUrl u = KUrl( el.attribute("href") );
if(u.isRelative())
{
u = url();
// NOTE
// cd() is probably better than setPath() here,
// for all those url sites just having a path
if(u.cd( el.attribute("href") ))
_rssList << u;
}
else
_rssList << u;
}
}
return !_rssList.isEmpty();
}
void WebTab::showRSSInfo()
{
QString urlList = QString("Here are the rss link found: <br /><br />");
foreach(const KUrl &url, _rssList)
{
urlList += QString("<a href=\"") + url.url() + QString("\">") + url.url() + QString("</a><br />");
}
urlList += QString("<br />Enough for now.. waiting for some cool akonadi based feeds management :)");
KMessageBox::information( view(),
urlList,
"RSS Management"
);
}
|