* Now stores the URL of downloads in the DownloadProgressView and in the settings,

so that we can eventually restart downloads.
* Checks if a downloaded file already has a previous download and replaces it.
  (Actually, this should take the path into account, not only URL.)
* Stores the URL as "META:url" attribute, as the good old NetPositive did.


git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@60 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi
2010-02-13 13:17:45 +00:00
parent a8d8342dfa
commit 8260b39fbc
+30 -4
View File
@@ -126,6 +126,7 @@ public:
DownloadProgressView(WebDownload* download) DownloadProgressView(WebDownload* download)
: BGridView(8, 3) : BGridView(8, 3)
, m_download(download) , m_download(download)
, m_url(download->url())
, m_path(download->path()) , m_path(download->path())
, m_expectedSize(download->expectedSize()) , m_expectedSize(download->expectedSize())
{ {
@@ -134,12 +135,15 @@ public:
DownloadProgressView(const BMessage* archive) DownloadProgressView(const BMessage* archive)
: BGridView(8, 3) : BGridView(8, 3)
, m_download(NULL) , m_download(NULL)
, m_url()
, m_path() , m_path()
, m_expectedSize(0) , m_expectedSize(0)
{ {
const char* path; const char* string;
if (archive->FindString("path", &path) == B_OK) if (archive->FindString("path", &string) == B_OK)
m_path.SetTo(path); m_path.SetTo(string);
if (archive->FindString("url", &string) == B_OK)
m_url = string;
} }
bool init(BMessage* archive = NULL) bool init(BMessage* archive = NULL)
@@ -185,6 +189,8 @@ public:
if (!archive) if (!archive)
return B_BAD_VALUE; return B_BAD_VALUE;
status_t ret = archive->AddString("path", m_path.Path()); status_t ret = archive->AddString("path", m_path.Path());
if (ret == B_OK)
ret = archive->AddString("url", m_url.String());
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddFloat("value", m_statusBar->CurrentValue()); ret = archive->AddFloat("value", m_statusBar->CurrentValue());
if (ret == B_OK) if (ret == B_OK)
@@ -255,6 +261,11 @@ public:
return m_download; return m_download;
} }
const BString& url() const
{
return m_url;
}
void downloadFinished() void downloadFinished()
{ {
m_download = NULL; m_download = NULL;
@@ -268,6 +279,7 @@ private:
SmallButton* m_button1; SmallButton* m_button1;
SmallButton* m_button2; SmallButton* m_button2;
WebDownload* m_download; WebDownload* m_download;
BString m_url;
BPath m_path; BPath m_path;
off_t m_expectedSize; off_t m_expectedSize;
}; };
@@ -406,10 +418,24 @@ bool DownloadWindow::QuitRequested()
void DownloadWindow::downloadStarted(WebDownload* download) void DownloadWindow::downloadStarted(WebDownload* download)
{ {
int32 finishedCount = 0;
int32 index = 0;
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->url() == download->url()) {
index = i;
view->RemoveSelf();
delete view;
}
}
m_removeFinishedButton->SetEnabled(finishedCount > 0);
DownloadProgressView* view = new DownloadProgressView(download); DownloadProgressView* view = new DownloadProgressView(download);
if (!view->init()) if (!view->init())
return; return;
m_downloadViewsLayout->AddView(0, view); m_downloadViewsLayout->AddView(index, view);
saveSettings(); saveSettings();
} }