Skip to content
Permalink
Browse files

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.
  • Loading branch information
Paul Harrison
Paul Harrison committed May 8, 2011
1 parent 09ec0a6 commit 6eae80f8861f515ec466a8e35cc8cde7e16dd2f4
@@ -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);

@@ -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;
};

@@ -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,16 +119,24 @@ 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();
}

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)
@@ -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;
};

@@ -11,8 +11,17 @@
<area>0,0,610,44</area>
<imagetype name="favicon">
<area>6,6,32,32</area>
<filename>shared/grid_noimage.png</filename>
</imagetype>
<statetype name="loadingstate">
<position>9,9</position>
<state name="loading">
<imagetype name="animation">
<position>0,0</position>
<filepattern low="1" high="8">mb_loading_%1.png</filepattern>
<delay>160</delay>
</imagetype>
</state>
</statetype>
<textarea name="buttontext">
<area>40,2,568,40</area>
<align>allcenter</align>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
include ( ../../mythconfig.mak )
include ( ../../settings.pro )

QMAKE_STRIP = echo

TARGET = themenop

0 comments on commit 6eae80f

Please sign in to comment.
You can’t perform that action at this time.