First basic GUI download progress display...

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@54 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi 2010-02-12 21:16:25 +00:00
parent c08684de2a
commit 4b059d47cd
6 changed files with 91 additions and 5 deletions

View File

@ -28,6 +28,8 @@
#include "config.h"
#include "DownloadWindow.h"
#include "WebDownload.h"
#include "WebProcess.h"
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
@ -35,7 +37,7 @@
#include <MenuItem.h>
#include <SeparatorView.h>
#include <SpaceLayoutItem.h>
#include <StatusBar.h>
#include <stdio.h>
DownloadWindow::DownloadWindow(BRect frame)
@ -43,6 +45,7 @@ DownloadWindow::DownloadWindow(BRect frame)
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{
SetLayout(new BGroupLayout(B_VERTICAL));
Minimize(true);
Show();
}
@ -54,6 +57,18 @@ DownloadWindow::~DownloadWindow()
void DownloadWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case DOWNLOAD_ADDED: {
WebDownload* download;
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
downloadStarted(download);
break;
}
case DOWNLOAD_REMOVED: {
WebDownload* download;
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
downloadFinished(download);
break;
}
default:
BWindow::MessageReceived(message);
break;
@ -66,3 +81,55 @@ bool DownloadWindow::QuitRequested()
Minimize(true);
return false;
}
class DownloadProgressView : public BGroupView {
public:
DownloadProgressView(WebDownload* download)
: BGroupView(B_HORIZONTAL)
, m_download(download)
, m_expectedSize(download->expectedSize())
{
GroupLayout()->SetInsets(5, 5, 5, 5);
m_statusBar = new BStatusBar("download progress", download->filename().String());
m_statusBar->SetMaxValue(100);
AddChild(m_statusBar);
}
virtual void AttachedToWindow()
{
m_download->setProgressListener(BMessenger(this));
}
virtual void MessageReceived(BMessage* message)
{
switch (message->what) {
case WebDownload::DOWNLOAD_PROGRESS: {
float progress;
if (message->FindFloat("progress", &progress) == B_OK)
m_statusBar->SetTo(progress);
break;
}
default:
BGroupView::MessageReceived(message);
}
}
WebDownload* download() const
{
return m_download;
}
private:
BStatusBar* m_statusBar;
WebDownload* m_download;
off_t m_expectedSize;
};
void DownloadWindow::downloadStarted(WebDownload* download)
{
AddChild(new DownloadProgressView(download));
}
void DownloadWindow::downloadFinished(WebDownload* download)
{
}

View File

@ -30,6 +30,8 @@
#include <Window.h>
class WebDownload;
class DownloadWindow : public BWindow {
public:
DownloadWindow(BRect frame);
@ -38,6 +40,9 @@ public:
virtual void MessageReceived(BMessage*);
virtual bool QuitRequested();
void downloadStarted(WebDownload* download);
void downloadFinished(WebDownload* download);
private:
};

View File

@ -29,6 +29,7 @@
#include "config.h"
#include "LauncherApp.h"
#include "DownloadWindow.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "LauncherWindow.h"
@ -56,6 +57,7 @@ LauncherApp::LauncherApp()
, m_lastWindowFrame(100, 100, 700, 750)
, m_launchRefsMessage(0)
, m_initialized(false)
, m_downloadWindow(0)
{
}
@ -86,6 +88,8 @@ void LauncherApp::ReadyToRun()
WebProcess::initializeOnce();
WebProcess::setCacheModel(WEBKIT_CACHE_MODEL_WEB_BROWSER);
m_downloadWindow = new DownloadWindow(BRect(100, 100, 300, 250));
BFile settingsFile;
BRect windowFrameFromSettings = m_lastWindowFrame;
if (openSettingsFile(settingsFile, B_READ_ONLY)) {
@ -102,7 +106,8 @@ void LauncherApp::ReadyToRun()
delete m_launchRefsMessage;
m_launchRefsMessage = 0;
} else {
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame);
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame,
BMessenger(m_downloadWindow));
window->Show();
}
}
@ -232,7 +237,8 @@ void LauncherApp::newWindow(const BString& url)
if (!BScreen().Frame().Contains(m_lastWindowFrame))
m_lastWindowFrame.OffsetTo(50, 50);
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame);
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame,
BMessenger(m_downloadWindow));
window->Show();
if (url.Length())
window->webView()->loadRequest(url.String());

View File

@ -32,6 +32,7 @@
#include <Rect.h>
class BFile;
class DownloadWindow;
class LauncherWindow;
class LauncherApp : public BApplication {
@ -54,6 +55,8 @@ private:
BRect m_lastWindowFrame;
BMessage* m_launchRefsMessage;
bool m_initialized;
DownloadWindow* m_downloadWindow;
};
extern const char* kApplicationSignature;

View File

@ -31,6 +31,7 @@
#include "config.h"
#include "LauncherWindow.h"
#include "WebProcess.h"
#include "WebView.h"
#include "WebViewConstants.h"
@ -75,7 +76,8 @@ static BLayoutItem* layoutItemFor(BView* view)
return layout->ItemAt(index);
}
LauncherWindow::LauncherWindow(BRect frame, ToolbarPolicy toolbarPolicy)
LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
ToolbarPolicy toolbarPolicy)
: WebViewWindow(frame, "HaikuLauncher",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS)
@ -187,6 +189,8 @@ LauncherWindow::LauncherWindow(BRect frame, ToolbarPolicy toolbarPolicy)
);
}
webView()->webProcess()->setDownloadListener(downloadListener);
m_findGroup->SetVisible(false);
AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT));

View File

@ -55,7 +55,8 @@ enum {
class LauncherWindow : public WebViewWindow {
public:
LauncherWindow(BRect frame, ToolbarPolicy = HaveToolbar);
LauncherWindow(BRect frame, const BMessenger& downloadListener,
ToolbarPolicy = HaveToolbar);
virtual ~LauncherWindow();
virtual void MessageReceived(BMessage* message);