* An unfinished download is no longer considered finished, just because it isn't

currently in progress anymore.
* Added feature to remove "missing" downloads, i.e. those for which no
  corresponding file exists.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@346 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi 2010-03-23 15:11:29 +00:00 committed by Alexandre Deckner
parent b65e0ec04e
commit f28abe9d24
2 changed files with 61 additions and 4 deletions

View File

@ -58,6 +58,7 @@ enum {
INIT = 'init', INIT = 'init',
OPEN_DOWNLOADS_FOLDER = 'odnf', OPEN_DOWNLOADS_FOLDER = 'odnf',
REMOVE_FINISHED_DOWNLOADS = 'rmfd', REMOVE_FINISHED_DOWNLOADS = 'rmfd',
REMOVE_MISSING_DOWNLOADS = 'rmmd',
OPEN_DOWNLOAD = 'opdn', OPEN_DOWNLOAD = 'opdn',
RESTART_DOWNLOAD = 'rsdn', RESTART_DOWNLOAD = 'rsdn',
CANCEL_DOWNLOAD = 'cndn', CANCEL_DOWNLOAD = 'cndn',
@ -112,6 +113,11 @@ public:
Invalidate(); Invalidate();
} }
} }
bool IsIconDimmed() const
{
return fDimmedIcon;
}
status_t SaveSettings(BMessage* archive) status_t SaveSettings(BMessage* archive)
{ {
@ -408,6 +414,16 @@ public:
return fURL; return fURL;
} }
bool IsMissing() const
{
return fIconView->IsIconDimmed();
}
bool IsFinished() const
{
return !fDownload && fStatusBar->CurrentValue() == 100;
}
void DownloadFinished() void DownloadFinished()
{ {
fDownload = NULL; fDownload = NULL;
@ -549,12 +565,17 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible,
new BMessage(REMOVE_FINISHED_DOWNLOADS)); new BMessage(REMOVE_FINISHED_DOWNLOADS));
fRemoveFinishedButton->SetEnabled(false); fRemoveFinishedButton->SetEnabled(false);
fRemoveMissingButton = new BButton("Remove missing",
new BMessage(REMOVE_MISSING_DOWNLOADS));
fRemoveMissingButton->SetEnabled(false);
AddChild(BGroupLayoutBuilder(B_VERTICAL) AddChild(BGroupLayoutBuilder(B_VERTICAL)
.Add(menuBar) .Add(menuBar)
.Add(scrollView) .Add(scrollView)
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
.Add(BGroupLayoutBuilder(B_HORIZONTAL) .Add(BGroupLayoutBuilder(B_HORIZONTAL)
.AddGlue() .AddGlue()
.Add(fRemoveMissingButton)
.Add(fRemoveFinishedButton) .Add(fRemoveFinishedButton)
.SetInsets(5, 5, 5, 5) .SetInsets(5, 5, 5, 5)
) )
@ -624,6 +645,9 @@ DownloadWindow::MessageReceived(BMessage* message)
case REMOVE_FINISHED_DOWNLOADS: case REMOVE_FINISHED_DOWNLOADS:
_RemoveFinishedDownloads(); _RemoveFinishedDownloads();
break; break;
case REMOVE_MISSING_DOWNLOADS:
_RemoveMissingDownloads();
break;
case SAVE_SETTINGS: case SAVE_SETTINGS:
_SaveSettings(); _SaveSettings();
break; break;
@ -660,6 +684,7 @@ DownloadWindow::_DownloadStarted(BWebDownload* download)
download->Start(BPath(fDownloadPath.String())); download->Start(BPath(fDownloadPath.String()));
int32 finishedCount = 0; int32 finishedCount = 0;
int32 missingCount = 0;
int32 index = 0; int32 index = 0;
for (int32 i = fDownloadViewsLayout->CountItems() - 1; for (int32 i = fDownloadViewsLayout->CountItems() - 1;
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) { BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
@ -671,10 +696,15 @@ DownloadWindow::_DownloadStarted(BWebDownload* download)
index = i; index = i;
view->RemoveSelf(); view->RemoveSelf();
delete view; delete view;
} else if (!view->Download()) continue;
}
if (view->IsFinished())
finishedCount++; finishedCount++;
if (view->IsMissing())
missingCount++;
} }
fRemoveFinishedButton->SetEnabled(finishedCount > 0); fRemoveFinishedButton->SetEnabled(finishedCount > 0);
fRemoveMissingButton->SetEnabled(missingCount > 0);
DownloadProgressView* view = new DownloadProgressView(download); DownloadProgressView* view = new DownloadProgressView(download);
if (!view->Init()) if (!view->Init())
return; return;
@ -691,19 +721,25 @@ void
DownloadWindow::_DownloadFinished(BWebDownload* download) DownloadWindow::_DownloadFinished(BWebDownload* download)
{ {
int32 finishedCount = 0; int32 finishedCount = 0;
int32 missingCount = 0;
for (int32 i = 0; for (int32 i = 0;
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i++) { BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i++) {
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>( DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
item->View()); item->View());
if (!view) if (!view)
continue; continue;
if (view->Download() == download) { if (download && view->Download() == download) {
view->DownloadFinished(); view->DownloadFinished();
finishedCount++; finishedCount++;
} else if (!view->Download()) continue;
}
if (view->IsFinished())
finishedCount++; finishedCount++;
if (view->IsMissing())
missingCount++;
} }
fRemoveFinishedButton->SetEnabled(finishedCount > 0); fRemoveFinishedButton->SetEnabled(finishedCount > 0);
fRemoveMissingButton->SetEnabled(missingCount > 0);
if (download) if (download)
_SaveSettings(); _SaveSettings();
} }
@ -718,7 +754,7 @@ DownloadWindow::_RemoveFinishedDownloads()
item->View()); item->View());
if (!view) if (!view)
continue; continue;
if (!view->Download()) { if (view->IsFinished()) {
view->RemoveSelf(); view->RemoveSelf();
delete view; delete view;
} }
@ -728,6 +764,25 @@ DownloadWindow::_RemoveFinishedDownloads()
} }
void
DownloadWindow::_RemoveMissingDownloads()
{
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
item->View());
if (!view)
continue;
if (view->IsMissing()) {
view->RemoveSelf();
delete view;
}
}
fRemoveMissingButton->SetEnabled(false);
_SaveSettings();
}
void void
DownloadWindow::_SaveSettings() DownloadWindow::_SaveSettings()
{ {

View File

@ -51,6 +51,7 @@ private:
void _DownloadStarted(BWebDownload* download); void _DownloadStarted(BWebDownload* download);
void _DownloadFinished(BWebDownload* download); void _DownloadFinished(BWebDownload* download);
void _RemoveFinishedDownloads(); void _RemoveFinishedDownloads();
void _RemoveMissingDownloads();
void _SaveSettings(); void _SaveSettings();
void _LoadSettings(); void _LoadSettings();
bool _OpenSettingsFile(BFile& file, uint32 mode); bool _OpenSettingsFile(BFile& file, uint32 mode);
@ -58,6 +59,7 @@ private:
private: private:
BGroupLayout* fDownloadViewsLayout; BGroupLayout* fDownloadViewsLayout;
BButton* fRemoveFinishedButton; BButton* fRemoveFinishedButton;
BButton* fRemoveMissingButton;
BString fDownloadPath; BString fDownloadPath;
}; };