00001 #include <stdlib.h>
00002 #include <iostream>
00003
00004
00005 #include <QEvent>
00006 #include <QIcon>
00007
00008
00009 #include "mythlogging.h"
00010 #include "libmythui/mythmainwindow.h"
00011
00012
00013 #include "mythbrowser.h"
00014 #include "webpage.h"
00015
00016 using namespace std;
00017
00018 WebPage::WebPage(MythBrowser *parent, QRect area, const char* name)
00019 {
00020 m_parent = parent;
00021
00022 m_listItem = new MythUIButtonListItem(parent->m_pageList, "", "", false,
00023 MythUIButtonListItem::CantCheck, false);
00024
00025 m_browser = new MythUIWebBrowser(parent, name);
00026 m_browser->SetArea(area);
00027 m_browser->Init();
00028
00029 m_active = false;
00030
00031 connect(m_browser, SIGNAL(loadStarted()),
00032 this, SLOT(slotLoadStarted()));
00033 connect(m_browser, SIGNAL(loadFinished(bool)),
00034 this, SLOT(slotLoadFinished(bool)));
00035 connect(m_browser, SIGNAL(loadProgress(int)),
00036 this, SLOT(slotLoadProgress(int)));
00037 connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
00038 this, SLOT(slotStatusBarMessage(const QString&)));
00039 connect(m_browser, SIGNAL(titleChanged(const QString&)),
00040 this, SLOT(slotTitleChanged(const QString&)));
00041 }
00042
00043 WebPage::WebPage(MythBrowser *parent, MythUIWebBrowser *browser)
00044 {
00045 m_parent = parent;
00046
00047 m_listItem = new MythUIButtonListItem(parent->m_pageList, "");
00048
00049 m_browser = browser;
00050
00051 connect(m_browser, SIGNAL(loadStarted()),
00052 this, SLOT(slotLoadStarted()));
00053 connect(m_browser, SIGNAL(loadFinished(bool)),
00054 this, SLOT(slotLoadFinished(bool)));
00055 connect(m_browser, SIGNAL(titleChanged(const QString&)),
00056 this, SLOT(slotTitleChanged(const QString&)));
00057 connect(m_browser, SIGNAL(loadProgress(int)),
00058 this, SLOT(slotLoadProgress(int)));
00059 connect(m_browser, SIGNAL(statusBarMessage(const QString&)),
00060 this, SLOT(slotStatusBarMessage(const QString&)));
00061 }
00062
00063 WebPage::~WebPage()
00064 {
00065 if (m_browser)
00066 {
00067 m_browser->disconnect();
00068 m_parent->DeleteChild(m_browser);
00069 m_browser = NULL;
00070 }
00071
00072 if (m_listItem)
00073 {
00074 delete m_listItem;
00075 m_listItem = NULL;
00076 }
00077 }
00078
00079 void WebPage::SetActive(bool active)
00080 {
00081 if (active)
00082 {
00083 m_browser->SetActive(true);
00084 m_browser->Show();
00085 }
00086 else
00087 {
00088 m_browser->SetActive(false);
00089 m_browser->Hide();
00090 }
00091
00092 m_active = active;
00093 }
00094
00095 void WebPage::slotIconChanged(void)
00096 {
00097 if (!m_listItem)
00098 return;
00099
00100 QIcon icon = m_browser->GetIcon();
00101
00102 if (icon.isNull())
00103 m_listItem->setImage(m_parent->getDefaultFavIcon(), "favicon");
00104 else
00105 {
00106 QPixmap pixmap = icon.pixmap(32, 32);
00107 QImage image = pixmap.toImage();
00108 image = image.scaled(
00109 QSize(32,32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
00110 MythImage *mimage = GetMythPainter()->GetFormatImage();
00111 mimage->Assign(image);
00112
00113 m_listItem->setImage(mimage, "favicon");
00114 }
00115
00116 m_parent->m_pageList->Refresh();
00117 }
00118
00119 void WebPage::slotLoadStarted(void)
00120 {
00121 m_listItem->SetText(tr("Loading..."));
00122 m_listItem->DisplayState("loading", "loadingstate");
00123 m_listItem->setImage(NULL, "favicon");
00124 m_listItem->SetImage("", "favicon");
00125
00126 m_parent->m_pageList->Update();
00127 }
00128
00129 void WebPage::slotLoadFinished(bool OK)
00130 {
00131 (void) OK;
00132
00133 m_listItem->DisplayState("off", "loadingstate");
00134
00135 slotLoadProgress(0);
00136
00137 slotIconChanged();
00138
00139 m_listItem->SetText(m_browser->GetTitle());
00140 }
00141
00142 void WebPage::slotLoadProgress(int progress)
00143 {
00144 if (m_active)
00145 emit loadProgress(progress);
00146 }
00147
00148 void WebPage::slotStatusBarMessage(const QString &text)
00149 {
00150 if (m_active)
00151 emit statusBarMessage(text);
00152 }
00153
00154 void WebPage::slotTitleChanged(const QString &title)
00155 {
00156 m_listItem->SetText(title);
00157 m_parent->m_pageList->Update();
00158 }