From 4b059d47cd6434ee931e315b9f7698fb532ca42a Mon Sep 17 00:00:00 2001 From: stippi Date: Fri, 12 Feb 2010 21:16:25 +0000 Subject: [PATCH] First basic GUI download progress display... git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@54 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/DownloadWindow.cpp | 69 ++++++++++++++++++++++++- src/apps/webpositive/DownloadWindow.h | 5 ++ src/apps/webpositive/LauncherApp.cpp | 10 +++- src/apps/webpositive/LauncherApp.h | 3 ++ src/apps/webpositive/LauncherWindow.cpp | 6 ++- src/apps/webpositive/LauncherWindow.h | 3 +- 6 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/apps/webpositive/DownloadWindow.cpp b/src/apps/webpositive/DownloadWindow.cpp index b27acf86a9..d6b932d6a5 100644 --- a/src/apps/webpositive/DownloadWindow.cpp +++ b/src/apps/webpositive/DownloadWindow.cpp @@ -28,6 +28,8 @@ #include "config.h" #include "DownloadWindow.h" +#include "WebDownload.h" +#include "WebProcess.h" #include #include #include @@ -35,7 +37,7 @@ #include #include #include - +#include #include 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(&download)) == B_OK) + downloadStarted(download); + break; + } + case DOWNLOAD_REMOVED: { + WebDownload* download; + if (message->FindPointer("download", reinterpret_cast(&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) +{ +} diff --git a/src/apps/webpositive/DownloadWindow.h b/src/apps/webpositive/DownloadWindow.h index d263ddf387..dc652f7442 100644 --- a/src/apps/webpositive/DownloadWindow.h +++ b/src/apps/webpositive/DownloadWindow.h @@ -30,6 +30,8 @@ #include +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: }; diff --git a/src/apps/webpositive/LauncherApp.cpp b/src/apps/webpositive/LauncherApp.cpp index fab6e75589..403e750055 100644 --- a/src/apps/webpositive/LauncherApp.cpp +++ b/src/apps/webpositive/LauncherApp.cpp @@ -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()); diff --git a/src/apps/webpositive/LauncherApp.h b/src/apps/webpositive/LauncherApp.h index 8afdfc4192..f7efb72dcb 100644 --- a/src/apps/webpositive/LauncherApp.h +++ b/src/apps/webpositive/LauncherApp.h @@ -32,6 +32,7 @@ #include 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; diff --git a/src/apps/webpositive/LauncherWindow.cpp b/src/apps/webpositive/LauncherWindow.cpp index 2407f34b45..0a171db2bd 100644 --- a/src/apps/webpositive/LauncherWindow.cpp +++ b/src/apps/webpositive/LauncherWindow.cpp @@ -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)); diff --git a/src/apps/webpositive/LauncherWindow.h b/src/apps/webpositive/LauncherWindow.h index 6d5dab8721..46fde08bac 100644 --- a/src/apps/webpositive/LauncherWindow.h +++ b/src/apps/webpositive/LauncherWindow.h @@ -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);