From 6eae80f8861f515ec466a8e35cc8cde7e16dd2f4 Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Sun, 8 May 2011 12:56:28 +0100 Subject: [PATCH] MythBrowser: Show a loading indicator on the page tabs. This adds a loading indicator which is shown whenever a page is busy loading. Also add a default favicon. --- .../mythbrowser/mythbrowser/mythbrowser.cpp | 18 +++++++- .../mythbrowser/mythbrowser/mythbrowser.h | 3 ++ .../mythbrowser/mythbrowser/webpage.cpp | 40 +++++++++--------- mythplugins/mythbrowser/mythbrowser/webpage.h | 6 +-- .../theme/default-wide/browser-ui.xml | 11 ++++- .../default/images/mb_default_favicon.png | Bin 0 -> 1304 bytes .../theme/default/images/mb_loading_1.png | Bin 0 -> 895 bytes .../theme/default/images/mb_loading_2.png | Bin 0 -> 908 bytes .../theme/default/images/mb_loading_3.png | Bin 0 -> 889 bytes .../theme/default/images/mb_loading_4.png | Bin 0 -> 878 bytes .../theme/default/images/mb_loading_5.png | Bin 0 -> 900 bytes .../theme/default/images/mb_loading_6.png | Bin 0 -> 911 bytes .../theme/default/images/mb_loading_7.png | Bin 0 -> 919 bytes .../theme/default/images/mb_loading_8.png | Bin 0 -> 880 bytes mythplugins/mythbrowser/theme/theme.pro | 2 +- 15 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_default_favicon.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_1.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_2.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_3.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_4.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_5.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_6.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_7.png create mode 100644 mythplugins/mythbrowser/theme/default/images/mb_loading_8.png diff --git a/mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp b/mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp index f72bd8bce15..2ef75c21947 100644 --- a/mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp +++ b/mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp @@ -7,13 +7,15 @@ // myth #include "mythverbose.h" #include "mythcontext.h" -#include "libmythui/mythmainwindow.h" +#include "mythmainwindow.h" +#include "mythuihelper.h" // mythbrowser #include "webpage.h" #include "bookmarkeditor.h" #include "mythbrowser.h" + using namespace std; MythBrowser::MythBrowser(MythScreenStack *parent, @@ -22,7 +24,8 @@ MythBrowser::MythBrowser(MythScreenStack *parent, m_urlList(urlList), m_pageList(NULL), m_progressBar(NULL), m_titleText(NULL), m_statusText(NULL), m_currentBrowser(-1), - m_zoom(zoom), m_menuPopup(NULL) + m_zoom(zoom), m_menuPopup(NULL), + m_defaultFavIcon(NULL) { } @@ -57,6 +60,17 @@ bool MythBrowser::Create(void) connect(m_pageList, SIGNAL(itemSelected(MythUIButtonListItem*)), this, SLOT(slotTabSelected(MythUIButtonListItem*))); + // create the default favicon + QString favIcon = "mb_default_favicon.png"; + GetMythUI()->FindThemeFile(favIcon); + if (QFile::exists(favIcon)) + { + QImage image(favIcon); + m_defaultFavIcon = GetMythPainter()->GetFormatImage(); + m_defaultFavIcon->Assign(image); + m_defaultFavIcon->UpRef(); + } + // this is the template for all other browser tabs WebPage *page = new WebPage(this, browser); diff --git a/mythplugins/mythbrowser/mythbrowser/mythbrowser.h b/mythplugins/mythbrowser/mythbrowser/mythbrowser.h index 2c22df92079..5096e0193ac 100644 --- a/mythplugins/mythbrowser/mythbrowser/mythbrowser.h +++ b/mythplugins/mythbrowser/mythbrowser/mythbrowser.h @@ -26,6 +26,7 @@ class MythBrowser : public MythScreenType bool keyPressEvent(QKeyEvent *); void setDefaultSaveDirectory(const QString saveDir) { m_defaultSaveDir = saveDir; } + MythImage* getDefaultFavIcon(void) { return m_defaultFavIcon; } public slots: void slotOpenURL(const QString &url); @@ -74,6 +75,8 @@ class MythBrowser : public MythScreenType MythDialogBox *m_menuPopup; + MythImage *m_defaultFavIcon; + friend class WebPage; }; diff --git a/mythplugins/mythbrowser/mythbrowser/webpage.cpp b/mythplugins/mythbrowser/mythbrowser/webpage.cpp index 87fdf006094..66d9425b414 100644 --- a/mythplugins/mythbrowser/mythbrowser/webpage.cpp +++ b/mythplugins/mythbrowser/mythbrowser/webpage.cpp @@ -38,8 +38,6 @@ WebPage::WebPage(MythBrowser *parent, QRect area, const char* name) 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) @@ -56,9 +54,6 @@ WebPage::WebPage(MythBrowser *parent, MythUIWebBrowser *browser) 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&)), @@ -99,26 +94,23 @@ void WebPage::SetActive(bool active) void WebPage::slotIconChanged(void) { + if (!m_listItem) + return; + QIcon icon = m_browser->GetIcon(); if (icon.isNull()) - { - //FIXME use a default icon here? - m_listItem->SetImage("", "favicon"); - } + m_listItem->setImage(m_parent->getDefaultFavIcon(), "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"); - } + 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(); @@ -127,6 +119,10 @@ void WebPage::slotIconChanged(void) void WebPage::slotLoadStarted(void) { m_listItem->SetText(tr("Loading...")); + m_listItem->DisplayState("loading", "loadingstate"); + m_listItem->setImage(NULL, "favicon"); + m_listItem->SetImage("", "favicon"); + m_parent->m_pageList->Update(); } @@ -134,9 +130,13 @@ void WebPage::slotLoadFinished(bool OK) { (void) OK; + m_listItem->DisplayState("off", "loadingstate"); + slotLoadProgress(0); slotIconChanged(); + + m_listItem->SetText(m_browser->GetTitle()); } void WebPage::slotLoadProgress(int progress) diff --git a/mythplugins/mythbrowser/mythbrowser/webpage.h b/mythplugins/mythbrowser/mythbrowser/webpage.h index 35b02525b5c..e07ee2edd5d 100644 --- a/mythplugins/mythbrowser/mythbrowser/webpage.h +++ b/mythplugins/mythbrowser/mythbrowser/webpage.h @@ -43,10 +43,10 @@ class WebPage : public QObject protected: private: - bool m_active; + bool m_active; - MythBrowser *m_parent; - MythUIWebBrowser *m_browser; + MythBrowser *m_parent; + MythUIWebBrowser *m_browser; MythUIButtonListItem *m_listItem; }; diff --git a/mythplugins/mythbrowser/theme/default-wide/browser-ui.xml b/mythplugins/mythbrowser/theme/default-wide/browser-ui.xml index cc0982816db..08c7610549a 100644 --- a/mythplugins/mythbrowser/theme/default-wide/browser-ui.xml +++ b/mythplugins/mythbrowser/theme/default-wide/browser-ui.xml @@ -11,8 +11,17 @@ 0,0,610,44 6,6,32,32 - shared/grid_noimage.png + + 9,9 + + + 0,0 + mb_loading_%1.png + 160 + + +