Skip to content

Commit

Permalink
MythBrowser: Show a loading indicator on the page tabs.
Browse files Browse the repository at this point in the history
This adds a loading indicator which is shown whenever a page is busy loading.

Also add a default favicon.
  • Loading branch information
Paul Harrison committed May 8, 2011
1 parent 09ec0a6 commit 6eae80f
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 27 deletions.
18 changes: 16 additions & 2 deletions mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp
Expand Up @@ -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,
Expand All @@ -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)
{
}

Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions mythplugins/mythbrowser/mythbrowser/mythbrowser.h
Expand Up @@ -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);
Expand Down Expand Up @@ -74,6 +75,8 @@ class MythBrowser : public MythScreenType

MythDialogBox *m_menuPopup;

MythImage *m_defaultFavIcon;

friend class WebPage;
};

Expand Down
40 changes: 20 additions & 20 deletions mythplugins/mythbrowser/mythbrowser/webpage.cpp
Expand Up @@ -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)
Expand All @@ -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&)),
Expand Down Expand Up @@ -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();
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions mythplugins/mythbrowser/mythbrowser/webpage.h
Expand Up @@ -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;
};

Expand Down
11 changes: 10 additions & 1 deletion mythplugins/mythbrowser/theme/default-wide/browser-ui.xml
Expand Up @@ -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>
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion mythplugins/mythbrowser/theme/theme.pro
@@ -1,6 +1,6 @@
include ( ../../mythconfig.mak )
include ( ../../settings.pro )

QMAKE_STRIP = echo

TARGET = themenop
Expand Down

0 comments on commit 6eae80f

Please sign in to comment.