MythTV  master
webpage.cpp
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 
4 // qt
5 #include <QEvent>
6 #include <QIcon>
7 
8 // myth
9 #include "mythlogging.h"
10 #include "mythmainwindow.h"
11 
12 // mythbrowser
13 #include "mythbrowser.h"
14 #include "webpage.h"
15 
16 using namespace std;
17 
18 WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
19 {
20  m_parent = parent;
21 
22  m_listItem = new MythUIButtonListItem(parent->m_pageList, "", "", false,
24 
25  m_browser = new MythUIWebBrowser(parent, name);
26  m_browser->SetArea(area);
27  m_browser->Init();
28 
29  connect(m_browser, SIGNAL(loadStarted()),
30  this, SLOT(slotLoadStarted()));
31  connect(m_browser, SIGNAL(loadFinished(bool)),
32  this, SLOT(slotLoadFinished(bool)));
33  connect(m_browser, SIGNAL(loadProgress(int)),
34  this, SLOT(slotLoadProgress(int)));
35  connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
36  this, SLOT(slotStatusBarMessage(const QString&)));
37  connect(m_browser, SIGNAL(titleChanged(const QString&)),
38  this, SLOT(slotTitleChanged(const QString&)));
39 }
40 
42 {
43  m_parent = parent;
44 
45  m_listItem = new MythUIButtonListItem(parent->m_pageList, "");
46 
47  m_browser = browser;
48 
49  connect(m_browser, SIGNAL(loadStarted()),
50  this, SLOT(slotLoadStarted()));
51  connect(m_browser, SIGNAL(loadFinished(bool)),
52  this, SLOT(slotLoadFinished(bool)));
53  connect(m_browser, SIGNAL(titleChanged(const QString&)),
54  this, SLOT(slotTitleChanged(const QString&)));
55  connect(m_browser, SIGNAL(loadProgress(int)),
56  this, SLOT(slotLoadProgress(int)));
57  connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
58  this, SLOT(slotStatusBarMessage(const QString&)));
59 }
60 
62 {
63  if (m_browser)
64  {
65  m_browser->disconnect();
66  m_parent->DeleteChild(m_browser);
67  m_browser = nullptr;
68  }
69 
70  if (m_listItem)
71  {
72  delete m_listItem;
73  m_listItem = nullptr;
74  }
75 }
76 
77 void WebPage::SetActive(bool active)
78 {
79  if (active)
80  {
81  m_browser->SetActive(true);
82  m_browser->Show();
83  }
84  else
85  {
86  m_browser->SetActive(false);
87  m_browser->Hide();
88  }
89 
90  m_active = active;
91 }
92 
94 {
95  if (!m_listItem)
96  return;
97 
98  QIcon icon = m_browser->GetIcon();
99 
100  if (icon.isNull())
101  {
102  MythImage *mimage = m_parent->GetDefaultFavIcon();
103  m_listItem->SetImage(mimage, "favicon");
104  mimage->DecrRef();
105  }
106  else
107  {
108  QPixmap pixmap = icon.pixmap(32, 32);
109  QImage image = pixmap.toImage();
110  image = image.scaled(
111  QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
112  MythImage *mimage = GetMythPainter()->GetFormatImage();
113  mimage->Assign(image);
114 
115  m_listItem->SetImage(mimage, "favicon");
116  mimage->DecrRef();
117  }
118 
119  m_parent->m_pageList->Refresh();
120 }
121 
123 {
124  m_listItem->SetText(tr("Loading..."));
125  m_listItem->DisplayState("loading", "loadingstate");
126  m_listItem->SetImage(nullptr, "favicon");
127  m_listItem->SetImage("", "favicon");
128 
129  m_parent->m_pageList->Update();
130 }
131 
133 {
134  m_listItem->DisplayState("off", "loadingstate");
135 
136  slotIconChanged();
137 
138  m_listItem->SetText(m_browser->GetTitle());
139 
140  emit loadFinished(OK);
141 }
142 
144 {
145  if (m_active)
146  emit loadProgress(progress);
147 }
148 
149 void WebPage::slotStatusBarMessage(const QString &text)
150 {
151  if (m_active)
152  emit statusBarMessage(text);
153 }
154 
155 void WebPage::slotTitleChanged(const QString &title)
156 {
157  m_listItem->SetText(title);
158  m_parent->m_pageList->Update();
159 }
#define OK
Definition: dvbci.cpp:69
void slotTitleChanged(const QString &title)
Definition: webpage.cpp:155
int DecrRef(void) override
Decrements reference count and deletes on 0.
Definition: mythimage.cpp:55
MythPainter * GetMythPainter(void)
void SetActive(bool active)
Definition: webpage.cpp:77
~WebPage()
Definition: webpage.cpp:61
void slotLoadStarted(void)
Definition: webpage.cpp:122
MythUIButtonList * m_pageList
Definition: mythbrowser.h:70
void slotStatusBarMessage(const QString &text)
Definition: webpage.cpp:149
const char * name
Definition: ParseText.cpp:328
void slotIconChanged(void)
Definition: webpage.cpp:93
void slotLoadProgress(int progress)
Definition: webpage.cpp:143
WebPage(MythBrowser *parent, QRect area, const char *name)
Definition: webpage.cpp:18
void Assign(const QImage &img)
Definition: mythimage.cpp:80
Web browsing widget.
MythImage * GetFormatImage()
Returns a blank reference counted image in the format required for the Draw functions for this painte...
void slotLoadFinished(bool OK)
Definition: webpage.cpp:132