Skip to content

Commit

Permalink
MythBrowser: Focus improvements/fixes and show a default url when cre…
Browse files Browse the repository at this point in the history
…ating a new tab.

Simplify making the active browser active now that MythUIWebBrowser handles most of this
automatically.

Also when creating a new tab show a default url (currently hard coded to
'www.google.com') instead of just showing a blank page. At some point the
bookmark editor should allow you to set a default home page of your choice.
  • Loading branch information
Paul Harrison committed May 5, 2011
1 parent c17798a commit 6f4c698
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
44 changes: 15 additions & 29 deletions mythplugins/mythbrowser/mythbrowser/mythbrowser.cpp
Expand Up @@ -98,8 +98,6 @@ MythUIWebBrowser* MythBrowser::activeBrowser(void)

void MythBrowser::slotEnterURL(void)
{
activeBrowser()->SetActive(false);

MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");

QString message = tr("Enter URL");
Expand All @@ -112,26 +110,26 @@ void MythBrowser::slotEnterURL(void)

connect(dialog, SIGNAL(haveResult(QString)),
SLOT(slotOpenURL(QString)), Qt::QueuedConnection);

connect(dialog, SIGNAL(Exiting()), SLOT(slotExitingMenu()));
}

void MythBrowser::slotAddTab(const QString &url, bool doSwitch)
{
QString name = QString("browser%1").arg(m_browserList.size() + 1);
WebPage *page = new WebPage(
this, m_browserList[0]->getBrowser()->GetArea(),
name.toAscii().constData());
WebPage *page = new WebPage(this, m_browserList[0]->getBrowser()->GetArea(),
name.toAscii().constData());
page->getBrowser()->SetZoom(m_zoom);

if (url != "")
{
QString newUrl = url;
if (!url.startsWith("http://") && !url.startsWith("https://") &&
!url.startsWith("file:/") )
newUrl.prepend("http://");
page->getBrowser()->LoadPage(QUrl::fromEncoded(newUrl.toLocal8Bit()));
}
m_browserList.append(page);

QString newUrl = url;

if (newUrl.isEmpty())
newUrl = "http://www.google.com"; // TODO: add a user definable home page

if (!newUrl.startsWith("http://") && !newUrl.startsWith("https://") &&
!newUrl.startsWith("file:/") )
newUrl.prepend("http://");
page->getBrowser()->LoadPage(QUrl::fromEncoded(newUrl.toLocal8Bit()));

page->SetActive(false);

Expand All @@ -140,8 +138,6 @@ void MythBrowser::slotAddTab(const QString &url, bool doSwitch)
connect(page, SIGNAL(statusBarMessage(const QString&)),
this, SLOT(slotStatusBarMessage(const QString&)));

m_browserList.append(page);

if (doSwitch)
m_pageList->SetItemCurrent(m_browserList.size() -1);
}
Expand Down Expand Up @@ -176,6 +172,8 @@ void MythBrowser::switchTab(int newTab)
if (m_currentBrowser >= 0 && m_currentBrowser < m_browserList.size())
m_browserList[m_currentBrowser]->SetActive(false);

BuildFocusList();

m_browserList[newTab]->SetActive(true);

m_currentBrowser = newTab;
Expand Down Expand Up @@ -216,8 +214,6 @@ void MythBrowser::slotForward()

void MythBrowser::slotAddBookmark()
{
activeBrowser()->SetActive(false);

m_editBookmark.category = "";
m_editBookmark.name = m_pageList->GetValue();
m_editBookmark.url = activeBrowser()->GetUrl().toString();
Expand All @@ -230,8 +226,6 @@ void MythBrowser::slotAddBookmark()

if (editor->Create())
mainStack->AddScreen(editor);

connect(editor, SIGNAL(Exiting()), SLOT(slotExitingMenu()));
}

void MythBrowser::slotLoadStarted(void)
Expand Down Expand Up @@ -331,7 +325,6 @@ bool MythBrowser::keyPressEvent(QKeyEvent *event)

if (action == "MENU")
{
activeBrowser()->SetActive(false);
slotStatusBarMessage("");

QString label = tr("Actions");
Expand All @@ -345,8 +338,6 @@ bool MythBrowser::keyPressEvent(QKeyEvent *event)

m_menuPopup->SetReturnEvent(this, "action");

connect(m_menuPopup, SIGNAL(Exiting()), SLOT(slotExitingMenu()));

m_menuPopup->AddButton(tr("Enter URL"), SLOT(slotEnterURL()));

if (activeBrowser()->CanGoBack())
Expand Down Expand Up @@ -403,9 +394,4 @@ bool MythBrowser::keyPressEvent(QKeyEvent *event)
return handled;
}

void MythBrowser::slotExitingMenu(void)
{
if (GetFocusWidget() == activeBrowser())
activeBrowser()->SetActive(true);
}

1 change: 0 additions & 1 deletion mythplugins/mythbrowser/mythbrowser/mythbrowser.h
Expand Up @@ -52,7 +52,6 @@ class MythBrowser : public MythScreenType
void slotTabSelected(MythUIButtonListItem *item);
void slotTabLosingFocus(void);
void slotIconChanged(void);
void slotExitingMenu(void);

private:
MythUIWebBrowser* activeBrowser(void);
Expand Down

0 comments on commit 6f4c698

Please sign in to comment.