* Finished testing of downloads interaction with listener and removed debug
output. * Optimized download restoration at program start and moved it into download window thread in order not to block app startup. * Downloads which have been removed meanwhile, are displayed with dimmed icon, and the option to Restart it is given. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@342 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
636f175b15
commit
0430f93fe3
@@ -54,6 +54,8 @@
|
|||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
INIT = 'init',
|
||||||
|
OPEN_DOWNLOADS_FOLDER = 'odnf',
|
||||||
REMOVE_FINISHED_DOWNLOADS = 'rmfd',
|
REMOVE_FINISHED_DOWNLOADS = 'rmfd',
|
||||||
OPEN_DOWNLOAD = 'opdn',
|
OPEN_DOWNLOAD = 'opdn',
|
||||||
RESTART_DOWNLOAD = 'rsdn',
|
RESTART_DOWNLOAD = 'rsdn',
|
||||||
@@ -65,10 +67,21 @@ enum {
|
|||||||
|
|
||||||
class IconView : public BView {
|
class IconView : public BView {
|
||||||
public:
|
public:
|
||||||
|
IconView(const BEntry& entry)
|
||||||
|
:
|
||||||
|
BView("Download icon", B_WILL_DRAW),
|
||||||
|
fIconBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32),
|
||||||
|
fDimmedIcon(false)
|
||||||
|
{
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
SetTo(entry);
|
||||||
|
}
|
||||||
|
|
||||||
IconView()
|
IconView()
|
||||||
:
|
:
|
||||||
BView("Download icon", B_WILL_DRAW),
|
BView("Download icon", B_WILL_DRAW),
|
||||||
fIconBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32)
|
fIconBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32),
|
||||||
|
fDimmedIcon(false)
|
||||||
{
|
{
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
memset(fIconBitmap.Bits(), 0, fIconBitmap.BitsLength());
|
memset(fIconBitmap.Bits(), 0, fIconBitmap.BitsLength());
|
||||||
@@ -77,7 +90,8 @@ public:
|
|||||||
IconView(BMessage* archive)
|
IconView(BMessage* archive)
|
||||||
:
|
:
|
||||||
BView("Download icon", B_WILL_DRAW),
|
BView("Download icon", B_WILL_DRAW),
|
||||||
fIconBitmap(archive)
|
fIconBitmap(archive),
|
||||||
|
fDimmedIcon(true)
|
||||||
{
|
{
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
}
|
}
|
||||||
@@ -90,6 +104,14 @@ public:
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetIconDimmed(bool iconDimmed)
|
||||||
|
{
|
||||||
|
if (fDimmedIcon != iconDimmed) {
|
||||||
|
fDimmedIcon = iconDimmed;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
status_t SaveSettings(BMessage* archive)
|
status_t SaveSettings(BMessage* archive)
|
||||||
{
|
{
|
||||||
return fIconBitmap.Archive(archive);
|
return fIconBitmap.Archive(archive);
|
||||||
@@ -102,6 +124,11 @@ public:
|
|||||||
|
|
||||||
virtual void Draw(BRect updateRect)
|
virtual void Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
if (fDimmedIcon) {
|
||||||
|
SetDrawingMode(B_OP_ALPHA);
|
||||||
|
SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
|
||||||
|
SetHighColor(0, 0, 0, 100);
|
||||||
|
}
|
||||||
DrawBitmapAsync(&fIconBitmap);
|
DrawBitmapAsync(&fIconBitmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,6 +149,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BBitmap fIconBitmap;
|
BBitmap fIconBitmap;
|
||||||
|
bool fDimmedIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -183,12 +211,18 @@ public:
|
|||||||
fStatusBar->SetMaxValue(100);
|
fStatusBar->SetMaxValue(100);
|
||||||
fStatusBar->SetBarHeight(12);
|
fStatusBar->SetBarHeight(12);
|
||||||
|
|
||||||
if (archive)
|
// fPath is only valid when constructed from archive (fDownload == NULL)
|
||||||
|
BEntry entry(fPath.Path());
|
||||||
|
|
||||||
|
if (archive) {
|
||||||
|
if (!entry.Exists())
|
||||||
fIconView = new IconView(archive);
|
fIconView = new IconView(archive);
|
||||||
else
|
else
|
||||||
|
fIconView = new IconView(entry);
|
||||||
|
} else
|
||||||
fIconView = new IconView();
|
fIconView = new IconView();
|
||||||
|
|
||||||
if (!fDownload && fStatusBar->CurrentValue() < 100)
|
if (!fDownload && (fStatusBar->CurrentValue() < 100 || !entry.Exists()))
|
||||||
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
||||||
else {
|
else {
|
||||||
fTopButton = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
fTopButton = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
||||||
@@ -258,7 +292,6 @@ public:
|
|||||||
fPath.SetTo(path);
|
fPath.SetTo(path);
|
||||||
BEntry entry(fPath.Path());
|
BEntry entry(fPath.Path());
|
||||||
fIconView->SetTo(entry);
|
fIconView->SetTo(entry);
|
||||||
printf("B_DOWNLOAD_STARTED: %s\n", fPath.Leaf());
|
|
||||||
fStatusBar->Reset(fPath.Leaf());
|
fStatusBar->Reset(fPath.Leaf());
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
@@ -428,7 +461,9 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible,
|
|||||||
fDownloadViewsLayout = downloadsGroupView->GroupLayout();
|
fDownloadViewsLayout = downloadsGroupView->GroupLayout();
|
||||||
|
|
||||||
BMenuBar* menuBar = new BMenuBar("Menu bar");
|
BMenuBar* menuBar = new BMenuBar("Menu bar");
|
||||||
BMenu* menu = new BMenu("Window");
|
BMenu* menu = new BMenu("Downloads");
|
||||||
|
menu->AddItem(new BMenuItem("Open downloads folder",
|
||||||
|
new BMessage(OPEN_DOWNLOADS_FOLDER)));
|
||||||
menu->AddItem(new BMenuItem("Hide", new BMessage(B_QUIT_REQUESTED), 'H'));
|
menu->AddItem(new BMenuItem("Hide", new BMessage(B_QUIT_REQUESTED), 'H'));
|
||||||
menuBar->AddItem(menu);
|
menuBar->AddItem(menu);
|
||||||
|
|
||||||
@@ -450,9 +485,7 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible,
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
_LoadSettings();
|
PostMessage(INIT);
|
||||||
// Small trick to get the correct enabled status of the Remove finished button
|
|
||||||
_DownloadFinished(NULL);
|
|
||||||
|
|
||||||
if (!visible)
|
if (!visible)
|
||||||
Hide();
|
Hide();
|
||||||
@@ -471,6 +504,14 @@ void
|
|||||||
DownloadWindow::MessageReceived(BMessage* message)
|
DownloadWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case INIT:
|
||||||
|
{
|
||||||
|
_LoadSettings();
|
||||||
|
// Small trick to get the correct enabled status of the Remove
|
||||||
|
// finished button
|
||||||
|
_DownloadFinished(NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case B_DOWNLOAD_ADDED:
|
case B_DOWNLOAD_ADDED:
|
||||||
{
|
{
|
||||||
BWebDownload* download;
|
BWebDownload* download;
|
||||||
@@ -489,6 +530,22 @@ DownloadWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case OPEN_DOWNLOADS_FOLDER:
|
||||||
|
{
|
||||||
|
entry_ref ref;
|
||||||
|
status_t status = get_ref_for_path(fDownloadPath.String(), &ref);
|
||||||
|
if (status == B_OK)
|
||||||
|
status = be_roster->Launch(&ref);
|
||||||
|
if (status != B_OK && status != B_ALREADY_RUNNING) {
|
||||||
|
BString errorString("The downloads folder could not be "
|
||||||
|
"opened.\n\n");
|
||||||
|
errorString << "Error: " << strerror(status);
|
||||||
|
BAlert* alert = new BAlert("Error opening downloads folder",
|
||||||
|
errorString.String(), "OK");
|
||||||
|
alert->Go(NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case REMOVE_FINISHED_DOWNLOADS:
|
case REMOVE_FINISHED_DOWNLOADS:
|
||||||
_RemoveFinishedDownloads();
|
_RemoveFinishedDownloads();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user