/
webpage.cpp
158 lines (129 loc) · 3.72 KB
/
webpage.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
#include <stdlib.h>
#include <iostream>
// qt
#include <QEvent>
#include <QIcon>
// myth
#include "mythverbose.h"
#include "libmythui/mythmainwindow.h"
// mythbrowser
#include "mythbrowser.h"
#include "webpage.h"
using namespace std;
WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
{
m_parent = parent;
m_listItem = new MythUIButtonListItem(parent->m_pageList, "", "", false,
MythUIButtonListItem::CantCheck, false);
m_browser = new MythUIWebBrowser(parent, name);
m_browser->SetArea(area);
m_browser->Init();
m_active = false;
connect(m_browser, SIGNAL(loadStarted()),
this, SLOT(slotLoadStarted()));
connect(m_browser, SIGNAL(loadFinished(bool)),
this, SLOT(slotLoadFinished(bool)));
connect(m_browser, SIGNAL(loadProgress(int)),
this, SLOT(slotLoadProgress(int)));
connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
this, SLOT(slotStatusBarMessage(const QString&)));
connect(m_browser, SIGNAL(titleChanged(const QString&)),
this, SLOT(slotTitleChanged(const QString&)));
connect(m_browser, SIGNAL(iconChanged(void)),
this, SLOT(slotIconChanged(void)));
}
WebPage::WebPage(MythBrowser *parent, MythUIWebBrowser *browser)
{
m_parent = parent;
m_listItem = new MythUIButtonListItem(parent->m_pageList, "");
m_browser = browser;
connect(m_browser, SIGNAL(loadStarted()),
this, SLOT(slotLoadStarted()));
connect(m_browser, SIGNAL(loadFinished(bool)),
this, SLOT(slotLoadFinished(bool)));
connect(m_browser, SIGNAL(titleChanged(const QString&)),
this, SLOT(slotTitleChanged(const QString&)));
connect(m_browser, SIGNAL(iconChanged(void)),
this, SLOT(slotIconChanged(void)));
connect(m_browser, SIGNAL(loadProgress(int)),
this, SLOT(slotLoadProgress(int)));
connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
this, SLOT(slotStatusBarMessage(const QString&)));
}
WebPage::~WebPage()
{
if (m_browser)
{
m_browser->disconnect();
m_parent->DeleteChild(m_browser);
m_browser = NULL;
}
if (m_listItem)
{
delete m_listItem;
m_listItem = NULL;
}
}
void WebPage::SetActive(bool active)
{
if (active)
{
m_browser->SetActive(true);
m_browser->Show();
}
else
{
m_browser->SetActive(false);
m_browser->Hide();
}
m_active = active;
}
void WebPage::slotIconChanged(void)
{
QIcon icon = m_browser->GetIcon();
if (icon.isNull())
{
//FIXME use a default icon here?
m_listItem->SetImage("", "favicon");
}
else
{
if (m_listItem)
{
QPixmap pixmap = icon.pixmap(32, 32);
QImage image = pixmap.toImage();
image = image.scaled(
QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
MythImage *mimage = GetMythPainter()->GetFormatImage();
mimage->Assign(image);
m_listItem->setImage(mimage, "favicon");
}
}
m_parent->m_pageList->Refresh();
}
void WebPage::slotLoadStarted(void)
{
m_listItem->SetText(tr("Loading..."));
m_parent->m_pageList->Update();
}
void WebPage::slotLoadFinished(bool OK)
{
(void) OK;
slotLoadProgress(0);
slotIconChanged();
}
void WebPage::slotLoadProgress(int progress)
{
if (m_active)
emit loadProgress(progress);
}
void WebPage::slotStatusBarMessage(const QString &text)
{
if (m_active)
emit statusBarMessage(text);
}
void WebPage::slotTitleChanged(const QString &title)
{
m_listItem->SetText(title);
m_parent->m_pageList->Update();
}