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
+68 -1
View File
@@ -28,6 +28,8 @@
#include "config.h" #include "config.h"
#include "DownloadWindow.h" #include "DownloadWindow.h"
#include "WebDownload.h"
#include "WebProcess.h"
#include <GridLayoutBuilder.h> #include <GridLayoutBuilder.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
@@ -35,7 +37,7 @@
#include <MenuItem.h> #include <MenuItem.h>
#include <SeparatorView.h> #include <SeparatorView.h>
#include <SpaceLayoutItem.h> #include <SpaceLayoutItem.h>
#include <StatusBar.h>
#include <stdio.h> #include <stdio.h>
DownloadWindow::DownloadWindow(BRect frame) DownloadWindow::DownloadWindow(BRect frame)
@@ -43,6 +45,7 @@ DownloadWindow::DownloadWindow(BRect frame)
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{ {
SetLayout(new BGroupLayout(B_VERTICAL));
Minimize(true); Minimize(true);
Show(); Show();
} }
@@ -54,6 +57,18 @@ DownloadWindow::~DownloadWindow()
void DownloadWindow::MessageReceived(BMessage* message) void DownloadWindow::MessageReceived(BMessage* message)
{ {
switch (message->what) { 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: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -66,3 +81,55 @@ bool DownloadWindow::QuitRequested()
Minimize(true); Minimize(true);
return false; 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)
{
}
+5
View File
@@ -30,6 +30,8 @@
#include <Window.h> #include <Window.h>
class WebDownload;
class DownloadWindow : public BWindow { class DownloadWindow : public BWindow {
public: public:
DownloadWindow(BRect frame); DownloadWindow(BRect frame);
@@ -38,6 +40,9 @@ public:
virtual void MessageReceived(BMessage*); virtual void MessageReceived(BMessage*);
virtual bool QuitRequested(); virtual bool QuitRequested();
void downloadStarted(WebDownload* download);
void downloadFinished(WebDownload* download);
private: private:
}; };
+8 -2
View File
@@ -29,6 +29,7 @@
#include "config.h" #include "config.h"
#include "LauncherApp.h" #include "LauncherApp.h"
#include "DownloadWindow.h"
#include "FrameView.h" #include "FrameView.h"
#include "GraphicsContext.h" #include "GraphicsContext.h"
#include "LauncherWindow.h" #include "LauncherWindow.h"
@@ -56,6 +57,7 @@ LauncherApp::LauncherApp()
, m_lastWindowFrame(100, 100, 700, 750) , m_lastWindowFrame(100, 100, 700, 750)
, m_launchRefsMessage(0) , m_launchRefsMessage(0)
, m_initialized(false) , m_initialized(false)
, m_downloadWindow(0)
{ {
} }
@@ -86,6 +88,8 @@ void LauncherApp::ReadyToRun()
WebProcess::initializeOnce(); WebProcess::initializeOnce();
WebProcess::setCacheModel(WEBKIT_CACHE_MODEL_WEB_BROWSER); WebProcess::setCacheModel(WEBKIT_CACHE_MODEL_WEB_BROWSER);
m_downloadWindow = new DownloadWindow(BRect(100, 100, 300, 250));
BFile settingsFile; BFile settingsFile;
BRect windowFrameFromSettings = m_lastWindowFrame; BRect windowFrameFromSettings = m_lastWindowFrame;
if (openSettingsFile(settingsFile, B_READ_ONLY)) { if (openSettingsFile(settingsFile, B_READ_ONLY)) {
@@ -102,7 +106,8 @@ void LauncherApp::ReadyToRun()
delete m_launchRefsMessage; delete m_launchRefsMessage;
m_launchRefsMessage = 0; m_launchRefsMessage = 0;
} else { } else {
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame); LauncherWindow* window = new LauncherWindow(m_lastWindowFrame,
BMessenger(m_downloadWindow));
window->Show(); window->Show();
} }
} }
@@ -232,7 +237,8 @@ void LauncherApp::newWindow(const BString& url)
if (!BScreen().Frame().Contains(m_lastWindowFrame)) if (!BScreen().Frame().Contains(m_lastWindowFrame))
m_lastWindowFrame.OffsetTo(50, 50); m_lastWindowFrame.OffsetTo(50, 50);
LauncherWindow* window = new LauncherWindow(m_lastWindowFrame); LauncherWindow* window = new LauncherWindow(m_lastWindowFrame,
BMessenger(m_downloadWindow));
window->Show(); window->Show();
if (url.Length()) if (url.Length())
window->webView()->loadRequest(url.String()); window->webView()->loadRequest(url.String());
+3
View File
@@ -32,6 +32,7 @@
#include <Rect.h> #include <Rect.h>
class BFile; class BFile;
class DownloadWindow;
class LauncherWindow; class LauncherWindow;
class LauncherApp : public BApplication { class LauncherApp : public BApplication {
@@ -54,6 +55,8 @@ private:
BRect m_lastWindowFrame; BRect m_lastWindowFrame;
BMessage* m_launchRefsMessage; BMessage* m_launchRefsMessage;
bool m_initialized; bool m_initialized;
DownloadWindow* m_downloadWindow;
}; };
extern const char* kApplicationSignature; extern const char* kApplicationSignature;
+5 -1
View File
@@ -31,6 +31,7 @@
#include "config.h" #include "config.h"
#include "LauncherWindow.h" #include "LauncherWindow.h"
#include "WebProcess.h"
#include "WebView.h" #include "WebView.h"
#include "WebViewConstants.h" #include "WebViewConstants.h"
@@ -75,7 +76,8 @@ static BLayoutItem* layoutItemFor(BView* view)
return layout->ItemAt(index); return layout->ItemAt(index);
} }
LauncherWindow::LauncherWindow(BRect frame, ToolbarPolicy toolbarPolicy) LauncherWindow::LauncherWindow(BRect frame, const BMessenger& downloadListener,
ToolbarPolicy toolbarPolicy)
: WebViewWindow(frame, "HaikuLauncher", : WebViewWindow(frame, "HaikuLauncher",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) 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); m_findGroup->SetVisible(false);
AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT)); AddShortcut('G', B_COMMAND_KEY, new BMessage(TEXT_FIND_NEXT));
+2 -1
View File
@@ -55,7 +55,8 @@ enum {
class LauncherWindow : public WebViewWindow { class LauncherWindow : public WebViewWindow {
public: public:
LauncherWindow(BRect frame, ToolbarPolicy = HaveToolbar); LauncherWindow(BRect frame, const BMessenger& downloadListener,
ToolbarPolicy = HaveToolbar);
virtual ~LauncherWindow(); virtual ~LauncherWindow();
virtual void MessageReceived(BMessage* message); virtual void MessageReceived(BMessage* message);