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

View File

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