-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpagewindow.cpp
executable file
·192 lines (171 loc) · 5.04 KB
/
webpagewindow.cpp
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
#include "webpagewindow.h"
#include "ui_webpagewindow.h"
#include <QUrl>
#include <QProgressBar>
#include <QLabel>
#include <QWebSettings>
#include <QCloseEvent>
//trying to disable history
#include <QWebHistory>
WebPageWindow::WebPageWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::WebPageWindow)
{
this->Init();
m_pUrl = NULL;
}
WebPageWindow::WebPageWindow(QString givenUrl,QWidget *parent) :
QMainWindow(parent),
ui(new Ui::WebPageWindow)
{
m_pUrl = new QUrl(givenUrl);
this->Init();
LoadPage();
}
/**
one common method to add the the UI's common init tasks, to make it easier to modify afterwords
*/
void WebPageWindow::Init()
{
ui->setupUi(this);
this->CreateToolBarActions();
this->SetupStatusBar();
this->AddWebViewSignals();
LoadWebSettings();
}
void WebPageWindow::SetupStatusBar()
{
m_pStatusLabel = new QLabel(this);
ui->m_statusbar->addWidget(m_pStatusLabel,4);
m_pProgressBar = new QProgressBar(this);
m_pProgressBar->setMinimum(0);
m_pProgressBar->setMaximum(100);
ui->m_statusbar->addWidget(m_pProgressBar,1);
m_pProgressBar->hide();
}
WebPageWindow::~WebPageWindow()
{
qDebug("in WebPageWindow DEstructor");
this->DeleteToolBarActions();
if (m_pProgressBar)
delete m_pProgressBar;
if (m_pStatusLabel)
delete m_pStatusLabel;
if (m_pUrl)
delete m_pUrl;
delete ui;
qDebug("After finishing the destructor");
}
void WebPageWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void WebPageWindow::CreateToolBarActions()
{
m_pBackAction = new QAction("Back",this);
connect(m_pBackAction,SIGNAL(triggered()),
ui->m_webView,SLOT(back()) );
ui->m_toolBar->addAction(m_pBackAction);
m_pForwardAction = new QAction("Forward",this);
connect(m_pForwardAction,SIGNAL(triggered()),
ui->m_webView,SLOT(forward()) );
ui->m_toolBar->addAction(m_pForwardAction);
m_pRealoadAction = new QAction("Reload",this);
connect(m_pRealoadAction,SIGNAL(triggered()),
ui->m_webView,SLOT(reload()) );
ui->m_toolBar->addAction(m_pRealoadAction);
m_pStopActoin = new QAction("Stop",this);
connect(m_pStopActoin,SIGNAL(triggered()),
ui->m_webView,SLOT(stop()));
ui->m_toolBar->addAction(m_pStopActoin);
}
void WebPageWindow::DeleteToolBarActions()
{
qDebug("void WebPageWindow::DeleteToolBarActions()");
if (m_pBackAction)
delete m_pBackAction;
if (m_pForwardAction)
delete m_pForwardAction;
if (m_pRealoadAction)
delete m_pRealoadAction;
if (m_pStopActoin)
delete m_pStopActoin;
}
void WebPageWindow::LoadPage()
{
qDebug("in LoadPAge, WebPageWindow");
if (m_pUrl && ! m_pUrl->isEmpty() && m_pUrl->isValid()){
ui->m_webView->load(*m_pUrl);
setWindowTitle(m_pUrl->toString()+" - ReallySimpleReader.");
}
}
void WebPageWindow::LoadPage(QString url)
{
qDebug("in LoadPAge, WebPageWindow");
SetURL(url);
if (m_pUrl && ! m_pUrl->isEmpty() && m_pUrl->isValid()){
ui->m_webView->load(*m_pUrl);
setWindowTitle(m_pUrl->toString()+" - ReallySimpleReader.");
}
}
void WebPageWindow::SetURL(QString givenurl)
{
if (m_pUrl)
delete m_pUrl;
m_pUrl = new QUrl(givenurl);
}
void WebPageWindow::AddWebViewSignals()
{
connect(ui->m_webView,SIGNAL(loadStarted()),
this,SLOT(HandleWebViewLoadStarted()) );
connect(ui->m_webView,SIGNAL(loadProgress(int)),
m_pProgressBar,SLOT(setValue(int)) );
connect(ui->m_webView,SIGNAL(loadFinished(bool)),
this,SLOT(HandleWebViewLoadFinished(bool)) );
}
void WebPageWindow::HandleWebViewLoadStarted()
{
qDebug("Load Started");
m_pProgressBar->show();
m_pProgressBar->reset();
m_pStatusLabel->setText("Loading Page "+ m_pUrl->toString() );
}
void WebPageWindow::HandleWebViewLoadFinished(bool ok)
{
qDebug("load Finished");
if (ok){
m_pProgressBar->hide();
m_pStatusLabel->clear();
}else{
m_pProgressBar->hide();
m_pStatusLabel->setText("Error Loading "+m_pUrl->toString());
}
}
//
void WebPageWindow::LoadWebSettings()
{
m_pSettings = ui->m_webView->settings();
m_pSettings->setAttribute(QWebSettings::JavaEnabled,false);
m_pSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows,false);
m_pSettings->setAttribute(QWebSettings::PluginsEnabled,false);
m_pSettings->setAttribute(QWebSettings::PrivateBrowsingEnabled,true);
// try to disable cache
m_pSettings->setMaximumPagesInCache(0);
m_pSettings->setObjectCacheCapacities(0, 0, 0);
//trying to disable history
ui->m_webView->page()->history()->setMaximumItemCount(0);
}
// trying to send a signal to the main window to tell it that the window has been closed
//so the main window deletes it
void WebPageWindow::closeEvent ( QCloseEvent * event )
{
emit WebWindowClosing(m_pUrl->toString());
event->accept();
}