More work on the download window GUI. The scroll view is broken, downloads are
not persistent. Resolved TODO in WebProcess about race condition when dispatching download notifications. Just block until there is a reply. WebDownload pointers are just used for extracting information at init time, and then later only as cookie to match view and download. Although as soon as we want to cancel downloads, refcounting may become necessary again. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@57 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
@@ -30,22 +30,56 @@
|
||||
|
||||
#include "WebDownload.h"
|
||||
#include "WebProcess.h"
|
||||
#include <Button.h>
|
||||
#include <GridLayoutBuilder.h>
|
||||
#include <GroupLayout.h>
|
||||
#include <GroupLayoutBuilder.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <ScrollView.h>
|
||||
#include <SeparatorView.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <StatusBar.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum {
|
||||
REMOVE_FINISHED_DOWNLOADS = 'rmfd'
|
||||
};
|
||||
|
||||
DownloadWindow::DownloadWindow(BRect frame, bool visible)
|
||||
: BWindow(frame, "Downloads",
|
||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
||||
{
|
||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||
|
||||
BGroupView* downloadsGroupView = new BGroupView(B_VERTICAL);
|
||||
downloadsGroupView->SetViewColor(245, 245, 245);
|
||||
m_downloadViewsLayout = downloadsGroupView->GroupLayout();
|
||||
|
||||
BMenuBar* menuBar = new BMenuBar("Menu bar");
|
||||
BMenu* menu = new BMenu("Window");
|
||||
menu->AddItem(new BMenuItem("Minimize", new BMessage(B_QUIT_REQUESTED), 'M'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
BScrollView* scrollView = new BScrollView("Downloads scroll view",
|
||||
downloadsGroupView, 0, false, true, B_NO_BORDER);
|
||||
|
||||
m_removeFinishedButton = new BButton("Remove finished",
|
||||
new BMessage(REMOVE_FINISHED_DOWNLOADS));
|
||||
m_removeFinishedButton->SetEnabled(false);
|
||||
|
||||
AddChild(BGroupLayoutBuilder(B_VERTICAL)
|
||||
.Add(menuBar)
|
||||
.Add(scrollView)
|
||||
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
|
||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL)
|
||||
.AddGlue()
|
||||
.Add(m_removeFinishedButton)
|
||||
.SetInsets(5, 5, 5, 5)
|
||||
)
|
||||
);
|
||||
|
||||
if (!visible)
|
||||
Minimize(true);
|
||||
Show();
|
||||
@@ -70,6 +104,9 @@ void DownloadWindow::MessageReceived(BMessage* message)
|
||||
downloadFinished(download);
|
||||
break;
|
||||
}
|
||||
case REMOVE_FINISHED_DOWNLOADS:
|
||||
removeFinishedDownloads();
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
break;
|
||||
@@ -90,6 +127,7 @@ public:
|
||||
, m_download(download)
|
||||
, m_expectedSize(download->expectedSize())
|
||||
{
|
||||
SetViewColor(245, 245, 245);
|
||||
GroupLayout()->SetInsets(5, 5, 5, 5);
|
||||
m_statusBar = new BStatusBar("download progress", download->filename().String());
|
||||
m_statusBar->SetMaxValue(100);
|
||||
@@ -120,6 +158,11 @@ public:
|
||||
return m_download;
|
||||
}
|
||||
|
||||
void downloadFinished()
|
||||
{
|
||||
m_download = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
BStatusBar* m_statusBar;
|
||||
WebDownload* m_download;
|
||||
@@ -128,9 +171,36 @@ private:
|
||||
|
||||
void DownloadWindow::downloadStarted(WebDownload* download)
|
||||
{
|
||||
AddChild(new DownloadProgressView(download));
|
||||
m_downloadViewsLayout->AddView(new DownloadProgressView(download));
|
||||
}
|
||||
|
||||
void DownloadWindow::downloadFinished(WebDownload* download)
|
||||
{
|
||||
int32 finishedCount = 0;
|
||||
for (int32 i = 0; BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i++) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
if (view->download() == download) {
|
||||
view->downloadFinished();
|
||||
finishedCount++;
|
||||
} else if (!view->download())
|
||||
finishedCount++;
|
||||
}
|
||||
m_removeFinishedButton->SetEnabled(finishedCount > 0);
|
||||
}
|
||||
|
||||
void DownloadWindow::removeFinishedDownloads()
|
||||
{
|
||||
for (int32 i = m_downloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
if (!view->download()) {
|
||||
view->RemoveSelf();
|
||||
delete view;
|
||||
}
|
||||
}
|
||||
m_removeFinishedButton->SetEnabled(false);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
class BButton;
|
||||
class BGroupLayout;
|
||||
class WebDownload;
|
||||
|
||||
class DownloadWindow : public BWindow {
|
||||
@@ -40,10 +42,14 @@ public:
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
void downloadStarted(WebDownload* download);
|
||||
void downloadFinished(WebDownload* download);
|
||||
void removeFinishedDownloads();
|
||||
|
||||
private:
|
||||
BGroupLayout* m_downloadViewsLayout;
|
||||
BButton* m_removeFinishedButton;
|
||||
};
|
||||
|
||||
#endif // DownloadWindow_h
|
||||
|
||||
Reference in New Issue
Block a user