* Refactored WebDownload into BWebDownload and BPrivate::WebDownloadPrivate.
* Fixed a bug where the "Remove Finished" button in the downloads window would be wrongly disabled whenever a new download started. * Implemented cancelling downloads. * Prepared restarting downloads as far as the GUI goes. Need to research this first how a download can be triggered independently from anything else in WebCore... git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@196 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
|
#include <Path.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
#include <SeparatorView.h>
|
#include <SeparatorView.h>
|
||||||
@@ -51,6 +52,8 @@
|
|||||||
enum {
|
enum {
|
||||||
REMOVE_FINISHED_DOWNLOADS = 'rmfd',
|
REMOVE_FINISHED_DOWNLOADS = 'rmfd',
|
||||||
OPEN_DOWNLOAD = 'opdn',
|
OPEN_DOWNLOAD = 'opdn',
|
||||||
|
RESTART_DOWNLOAD = 'rsdn',
|
||||||
|
CANCEL_DOWNLOAD = 'cndn',
|
||||||
REMOVE_DOWNLOAD = 'rmdn',
|
REMOVE_DOWNLOAD = 'rmdn',
|
||||||
SAVE_SETTINGS = 'svst'
|
SAVE_SETTINGS = 'svst'
|
||||||
};
|
};
|
||||||
@@ -123,12 +126,12 @@ public:
|
|||||||
|
|
||||||
class DownloadProgressView : public BGridView {
|
class DownloadProgressView : public BGridView {
|
||||||
public:
|
public:
|
||||||
DownloadProgressView(WebDownload* download)
|
DownloadProgressView(BWebDownload* download)
|
||||||
: BGridView(8, 3)
|
: BGridView(8, 3)
|
||||||
, m_download(download)
|
, m_download(download)
|
||||||
, m_url(download->url())
|
, m_url(download->URL())
|
||||||
, m_path(download->path())
|
, m_path(download->Path())
|
||||||
, m_expectedSize(download->expectedSize())
|
, m_expectedSize(download->ExpectedSize())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,10 +173,18 @@ public:
|
|||||||
else
|
else
|
||||||
m_iconView = new IconView(archive);
|
m_iconView = new IconView(archive);
|
||||||
|
|
||||||
m_button1 = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
if (!m_download && m_statusBar->CurrentValue() < 100)
|
||||||
m_button2 = new SmallButton("Remove", new BMessage(REMOVE_DOWNLOAD));
|
m_button1 = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
||||||
m_button1->SetEnabled(m_download == NULL);
|
else {
|
||||||
m_button2->SetEnabled(m_download == NULL);
|
m_button1 = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
||||||
|
m_button1->SetEnabled(m_download == NULL);
|
||||||
|
}
|
||||||
|
if (m_download)
|
||||||
|
m_button2 = new SmallButton("Cancel", new BMessage(CANCEL_DOWNLOAD));
|
||||||
|
else {
|
||||||
|
m_button2 = new SmallButton("Remove", new BMessage(REMOVE_DOWNLOAD));
|
||||||
|
m_button2->SetEnabled(m_download == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
layout->SetInsets(8, 5, 5, 6);
|
layout->SetInsets(8, 5, 5, 6);
|
||||||
layout->AddView(m_iconView, 0, 0, 1, 2);
|
layout->AddView(m_iconView, 0, 0, 1, 2);
|
||||||
@@ -201,7 +212,7 @@ public:
|
|||||||
virtual void AttachedToWindow()
|
virtual void AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (m_download)
|
if (m_download)
|
||||||
m_download->setProgressListener(BMessenger(this));
|
m_download->SetProgressListener(BMessenger(this));
|
||||||
m_button1->SetTarget(this);
|
m_button1->SetTarget(this);
|
||||||
m_button2->SetTarget(this);
|
m_button2->SetTarget(this);
|
||||||
}
|
}
|
||||||
@@ -225,7 +236,7 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message)
|
virtual void MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case WebDownload::DOWNLOAD_PROGRESS: {
|
case B_DOWNLOAD_PROGRESS: {
|
||||||
float progress;
|
float progress;
|
||||||
if (message->FindFloat("progress", &progress) == B_OK)
|
if (message->FindFloat("progress", &progress) == B_OK)
|
||||||
m_statusBar->SetTo(progress);
|
m_statusBar->SetTo(progress);
|
||||||
@@ -244,6 +255,15 @@ public:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case RESTART_DOWNLOAD:
|
||||||
|
// TODO:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CANCEL_DOWNLOAD:
|
||||||
|
m_download->Cancel();
|
||||||
|
downloadCanceled();
|
||||||
|
break;
|
||||||
|
|
||||||
case REMOVE_DOWNLOAD: {
|
case REMOVE_DOWNLOAD: {
|
||||||
Window()->PostMessage(SAVE_SETTINGS);
|
Window()->PostMessage(SAVE_SETTINGS);
|
||||||
RemoveSelf();
|
RemoveSelf();
|
||||||
@@ -256,7 +276,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebDownload* download() const
|
BWebDownload* download() const
|
||||||
{
|
{
|
||||||
return m_download;
|
return m_download;
|
||||||
}
|
}
|
||||||
@@ -270,6 +290,19 @@ public:
|
|||||||
{
|
{
|
||||||
m_download = NULL;
|
m_download = NULL;
|
||||||
m_button1->SetEnabled(true);
|
m_button1->SetEnabled(true);
|
||||||
|
m_button2->SetLabel("Remove");
|
||||||
|
m_button2->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||||
|
m_button2->SetEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void downloadCanceled()
|
||||||
|
{
|
||||||
|
m_download = NULL;
|
||||||
|
m_button1->SetLabel("Restart");
|
||||||
|
m_button1->SetMessage(new BMessage(RESTART_DOWNLOAD));
|
||||||
|
m_button1->SetEnabled(true);
|
||||||
|
m_button2->SetLabel("Remove");
|
||||||
|
m_button2->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||||
m_button2->SetEnabled(true);
|
m_button2->SetEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +311,7 @@ private:
|
|||||||
BStatusBar* m_statusBar;
|
BStatusBar* m_statusBar;
|
||||||
SmallButton* m_button1;
|
SmallButton* m_button1;
|
||||||
SmallButton* m_button2;
|
SmallButton* m_button2;
|
||||||
WebDownload* m_download;
|
BWebDownload* m_download;
|
||||||
BString m_url;
|
BString m_url;
|
||||||
BPath m_path;
|
BPath m_path;
|
||||||
off_t m_expectedSize;
|
off_t m_expectedSize;
|
||||||
@@ -386,13 +419,13 @@ void DownloadWindow::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case B_DOWNLOAD_ADDED: {
|
case B_DOWNLOAD_ADDED: {
|
||||||
WebDownload* download;
|
BWebDownload* download;
|
||||||
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
||||||
downloadStarted(download);
|
downloadStarted(download);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_DOWNLOAD_REMOVED: {
|
case B_DOWNLOAD_REMOVED: {
|
||||||
WebDownload* download;
|
BWebDownload* download;
|
||||||
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
||||||
downloadFinished(download);
|
downloadFinished(download);
|
||||||
break;
|
break;
|
||||||
@@ -416,7 +449,7 @@ bool DownloadWindow::QuitRequested()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadWindow::downloadStarted(WebDownload* download)
|
void DownloadWindow::downloadStarted(BWebDownload* download)
|
||||||
{
|
{
|
||||||
int32 finishedCount = 0;
|
int32 finishedCount = 0;
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
@@ -425,11 +458,12 @@ void DownloadWindow::downloadStarted(WebDownload* download)
|
|||||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||||
if (!view)
|
if (!view)
|
||||||
continue;
|
continue;
|
||||||
if (view->url() == download->url()) {
|
if (view->url() == download->URL()) {
|
||||||
index = i;
|
index = i;
|
||||||
view->RemoveSelf();
|
view->RemoveSelf();
|
||||||
delete view;
|
delete view;
|
||||||
}
|
} else if (!view->download())
|
||||||
|
finishedCount++;
|
||||||
}
|
}
|
||||||
m_removeFinishedButton->SetEnabled(finishedCount > 0);
|
m_removeFinishedButton->SetEnabled(finishedCount > 0);
|
||||||
DownloadProgressView* view = new DownloadProgressView(download);
|
DownloadProgressView* view = new DownloadProgressView(download);
|
||||||
@@ -443,7 +477,7 @@ void DownloadWindow::downloadStarted(WebDownload* download)
|
|||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadWindow::downloadFinished(WebDownload* download)
|
void DownloadWindow::downloadFinished(BWebDownload* download)
|
||||||
{
|
{
|
||||||
int32 finishedCount = 0;
|
int32 finishedCount = 0;
|
||||||
for (int32 i = 0; BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i++) {
|
for (int32 i = 0; BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i++) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
class BButton;
|
class BButton;
|
||||||
class BFile;
|
class BFile;
|
||||||
class BGroupLayout;
|
class BGroupLayout;
|
||||||
class WebDownload;
|
class BWebDownload;
|
||||||
|
|
||||||
class DownloadWindow : public BWindow {
|
class DownloadWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
@@ -44,8 +44,8 @@ public:
|
|||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void downloadStarted(WebDownload* download);
|
void downloadStarted(BWebDownload* download);
|
||||||
void downloadFinished(WebDownload* download);
|
void downloadFinished(BWebDownload* download);
|
||||||
void removeFinishedDownloads();
|
void removeFinishedDownloads();
|
||||||
void saveSettings();
|
void saveSettings();
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user