Work in progress on better download management...
* Allow to specify the downloads folder in the General settings page. * Added necessary wiring. * The listener notification was not synchronous anymore because of mixed up default function params in BWebPage. * Added temporary debug output to WebDownloadPrivate.cpp... the restarting downloads code path needs testing yet. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@341 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
1beb8c8035
commit
636f175b15
@@ -145,7 +145,8 @@ BrowserApp::ReadyToRun()
|
|||||||
BRect());
|
BRect());
|
||||||
bool showDownloads = fSettings->GetValue("show downloads", false);
|
bool showDownloads = fSettings->GetValue("show downloads", false);
|
||||||
|
|
||||||
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads);
|
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads,
|
||||||
|
fSettings);
|
||||||
fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
|
fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
|
||||||
|
|
||||||
BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));
|
BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#include <StatusBar.h>
|
#include <StatusBar.h>
|
||||||
|
|
||||||
#include "BrowserApp.h"
|
#include "BrowserApp.h"
|
||||||
|
#include "SettingsMessage.h"
|
||||||
#include "WebDownload.h"
|
#include "WebDownload.h"
|
||||||
#include "WebPage.h"
|
#include "WebPage.h"
|
||||||
|
|
||||||
@@ -64,15 +65,13 @@ enum {
|
|||||||
|
|
||||||
class IconView : public BView {
|
class IconView : public BView {
|
||||||
public:
|
public:
|
||||||
IconView(const BEntry& entry)
|
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)
|
||||||
{
|
{
|
||||||
BNode node(&entry);
|
|
||||||
BNodeInfo info(&node);
|
|
||||||
info.GetTrackerIcon(&fIconBitmap, B_LARGE_ICON);
|
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
|
memset(fIconBitmap.Bits(), 0, fIconBitmap.BitsLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
IconView(BMessage* archive)
|
IconView(BMessage* archive)
|
||||||
@@ -83,6 +82,14 @@ public:
|
|||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetTo(const BEntry& entry)
|
||||||
|
{
|
||||||
|
BNode node(&entry);
|
||||||
|
BNodeInfo info(&node);
|
||||||
|
info.GetTrackerIcon(&fIconBitmap, B_LARGE_ICON);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
status_t SaveSettings(BMessage* archive)
|
status_t SaveSettings(BMessage* archive)
|
||||||
{
|
{
|
||||||
return fIconBitmap.Archive(archive);
|
return fIconBitmap.Archive(archive);
|
||||||
@@ -162,27 +169,24 @@ public:
|
|||||||
|
|
||||||
bool Init(BMessage* archive = NULL)
|
bool Init(BMessage* archive = NULL)
|
||||||
{
|
{
|
||||||
BEntry entry(fPath.Path());
|
|
||||||
if (!entry.Exists() && !archive)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
SetViewColor(245, 245, 245);
|
SetViewColor(245, 245, 245);
|
||||||
SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW);
|
SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW);
|
||||||
|
|
||||||
BGridLayout* layout = GridLayout();
|
BGridLayout* layout = GridLayout();
|
||||||
fStatusBar = new BStatusBar("download progress", fPath.Leaf());
|
|
||||||
fStatusBar->SetMaxValue(100);
|
|
||||||
if (archive) {
|
if (archive) {
|
||||||
|
fStatusBar = new BStatusBar("download progress", fPath.Leaf());
|
||||||
float value;
|
float value;
|
||||||
if (archive->FindFloat("value", &value) == B_OK)
|
if (archive->FindFloat("value", &value) == B_OK)
|
||||||
fStatusBar->SetTo(value);
|
fStatusBar->SetTo(value);
|
||||||
}
|
} else
|
||||||
|
fStatusBar = new BStatusBar("download progress", "Download");
|
||||||
|
fStatusBar->SetMaxValue(100);
|
||||||
fStatusBar->SetBarHeight(12);
|
fStatusBar->SetBarHeight(12);
|
||||||
|
|
||||||
if (entry.Exists())
|
if (archive)
|
||||||
fIconView = new IconView(entry);
|
|
||||||
else
|
|
||||||
fIconView = new IconView(archive);
|
fIconView = new IconView(archive);
|
||||||
|
else
|
||||||
|
fIconView = new IconView();
|
||||||
|
|
||||||
if (!fDownload && fStatusBar->CurrentValue() < 100)
|
if (!fDownload && fStatusBar->CurrentValue() < 100)
|
||||||
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
||||||
@@ -247,6 +251,17 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message)
|
virtual void MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case B_DOWNLOAD_STARTED: {
|
||||||
|
BString path;
|
||||||
|
if (message->FindString("path", &path) != B_OK)
|
||||||
|
break;
|
||||||
|
fPath.SetTo(path);
|
||||||
|
BEntry entry(fPath.Path());
|
||||||
|
fIconView->SetTo(entry);
|
||||||
|
printf("B_DOWNLOAD_STARTED: %s\n", fPath.Leaf());
|
||||||
|
fStatusBar->Reset(fPath.Leaf());
|
||||||
|
break;
|
||||||
|
};
|
||||||
case B_DOWNLOAD_PROGRESS: {
|
case B_DOWNLOAD_PROGRESS: {
|
||||||
float progress;
|
float progress;
|
||||||
if (message->FindFloat("progress", &progress) == B_OK)
|
if (message->FindFloat("progress", &progress) == B_OK)
|
||||||
@@ -391,11 +406,22 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
DownloadWindow::DownloadWindow(BRect frame, bool visible)
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
DownloadWindow::DownloadWindow(BRect frame, bool visible,
|
||||||
|
SettingsMessage* settings)
|
||||||
: BWindow(frame, "Downloads",
|
: BWindow(frame, "Downloads",
|
||||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||||
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
|
||||||
{
|
{
|
||||||
|
settings->AddListener(BMessenger(this));
|
||||||
|
BPath downloadPath;
|
||||||
|
if (find_directory(B_DESKTOP_DIRECTORY, &downloadPath) != B_OK)
|
||||||
|
downloadPath.SetTo("/boot/home/Desktop");
|
||||||
|
fDownloadPath = settings->GetValue("download path", downloadPath.Path());
|
||||||
|
settings->SetValue("download path", fDownloadPath);
|
||||||
|
|
||||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||||
|
|
||||||
DownloadsContainerView* downloadsGroupView = new DownloadsContainerView();
|
DownloadsContainerView* downloadsGroupView = new DownloadsContainerView();
|
||||||
@@ -445,7 +471,8 @@ void
|
|||||||
DownloadWindow::MessageReceived(BMessage* message)
|
DownloadWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case B_DOWNLOAD_ADDED: {
|
case B_DOWNLOAD_ADDED:
|
||||||
|
{
|
||||||
BWebDownload* download;
|
BWebDownload* download;
|
||||||
if (message->FindPointer("download", reinterpret_cast<void**>(
|
if (message->FindPointer("download", reinterpret_cast<void**>(
|
||||||
&download)) == B_OK) {
|
&download)) == B_OK) {
|
||||||
@@ -453,7 +480,8 @@ DownloadWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case B_DOWNLOAD_REMOVED: {
|
case B_DOWNLOAD_REMOVED:
|
||||||
|
{
|
||||||
BWebDownload* download;
|
BWebDownload* download;
|
||||||
if (message->FindPointer("download", reinterpret_cast<void**>(
|
if (message->FindPointer("download", reinterpret_cast<void**>(
|
||||||
&download)) == B_OK) {
|
&download)) == B_OK) {
|
||||||
@@ -467,6 +495,17 @@ DownloadWindow::MessageReceived(BMessage* message)
|
|||||||
case SAVE_SETTINGS:
|
case SAVE_SETTINGS:
|
||||||
_SaveSettings();
|
_SaveSettings();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SETTINGS_VALUE_CHANGED:
|
||||||
|
{
|
||||||
|
BString string;
|
||||||
|
if (message->FindString("name", &string) == B_OK
|
||||||
|
&& string == "download path"
|
||||||
|
&& message->FindString("value", &string) == B_OK) {
|
||||||
|
fDownloadPath = string;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -486,6 +525,8 @@ DownloadWindow::QuitRequested()
|
|||||||
void
|
void
|
||||||
DownloadWindow::_DownloadStarted(BWebDownload* download)
|
DownloadWindow::_DownloadStarted(BWebDownload* download)
|
||||||
{
|
{
|
||||||
|
download->Start(BPath(fDownloadPath.String()));
|
||||||
|
|
||||||
int32 finishedCount = 0;
|
int32 finishedCount = 0;
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
|
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
|
||||||
|
|||||||
@@ -28,17 +28,20 @@
|
|||||||
#define DOWNLOAD_WINDOW_H
|
#define DOWNLOAD_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
class BButton;
|
class BButton;
|
||||||
class BFile;
|
class BFile;
|
||||||
class BGroupLayout;
|
class BGroupLayout;
|
||||||
class BWebDownload;
|
class BWebDownload;
|
||||||
|
class SettingsMessage;
|
||||||
|
|
||||||
|
|
||||||
class DownloadWindow : public BWindow {
|
class DownloadWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
DownloadWindow(BRect frame, bool visible);
|
DownloadWindow(BRect frame, bool visible,
|
||||||
|
SettingsMessage* settings);
|
||||||
virtual ~DownloadWindow();
|
virtual ~DownloadWindow();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
@@ -55,6 +58,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
BGroupLayout* fDownloadViewsLayout;
|
BGroupLayout* fDownloadViewsLayout;
|
||||||
BButton* fRemoveFinishedButton;
|
BButton* fRemoveFinishedButton;
|
||||||
|
BString fDownloadPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOAD_WINDOW_H
|
#endif // DOWNLOAD_WINDOW_H
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ SettingsWindow::_CreateGeneralPage(float spacing)
|
|||||||
{
|
{
|
||||||
fDownloadFolderControl = new BTextControl("download folder",
|
fDownloadFolderControl = new BTextControl("download folder",
|
||||||
TR("Download folder:"), "", new BMessage(MSG_DOWNLOAD_FOLDER_CHANGED));
|
TR("Download folder:"), "", new BMessage(MSG_DOWNLOAD_FOLDER_CHANGED));
|
||||||
fDownloadFolderControl->SetEnabled(false);
|
fDownloadFolderControl->SetText(fSettings->GetValue("download path", ""));
|
||||||
|
|
||||||
fNewPageBehaviorCloneCurrentItem = new BMenuItem(TR("Clone current page"),
|
fNewPageBehaviorCloneCurrentItem = new BMenuItem(TR("Clone current page"),
|
||||||
NULL);
|
NULL);
|
||||||
@@ -312,7 +312,20 @@ SettingsWindow::_CreateFontsPage(float spacing)
|
|||||||
void
|
void
|
||||||
SettingsWindow::_ApplySettings()
|
SettingsWindow::_ApplySettings()
|
||||||
{
|
{
|
||||||
// Store settings
|
// Store general settings
|
||||||
|
int32 maxHistoryAge = atoi(fDaysInGoMenuControl->Text());
|
||||||
|
if (maxHistoryAge <= 0)
|
||||||
|
maxHistoryAge = 1;
|
||||||
|
if (maxHistoryAge >= 35)
|
||||||
|
maxHistoryAge = 35;
|
||||||
|
BString text;
|
||||||
|
text << maxHistoryAge;
|
||||||
|
fDaysInGoMenuControl->SetText(text.String());
|
||||||
|
BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(maxHistoryAge);
|
||||||
|
|
||||||
|
fSettings->SetValue("download path", fDownloadFolderControl->Text());
|
||||||
|
|
||||||
|
// Store fond settings
|
||||||
fSettings->SetValue("standard font", fStandardFontView->Font());
|
fSettings->SetValue("standard font", fStandardFontView->Font());
|
||||||
fSettings->SetValue("serif font", fSerifFontView->Font());
|
fSettings->SetValue("serif font", fSerifFontView->Font());
|
||||||
fSettings->SetValue("sans serif font", fSansSerifFontView->Font());
|
fSettings->SetValue("sans serif font", fSansSerifFontView->Font());
|
||||||
@@ -335,16 +348,6 @@ SettingsWindow::_ApplySettings()
|
|||||||
// This will find all currently instantiated page settings and apply
|
// This will find all currently instantiated page settings and apply
|
||||||
// the default values, unless the page settings have local overrides.
|
// the default values, unless the page settings have local overrides.
|
||||||
BWebSettings::Default()->Apply();
|
BWebSettings::Default()->Apply();
|
||||||
|
|
||||||
int32 maxHistoryAge = atoi(fDaysInGoMenuControl->Text());
|
|
||||||
if (maxHistoryAge <= 0)
|
|
||||||
maxHistoryAge = 1;
|
|
||||||
if (maxHistoryAge >= 35)
|
|
||||||
maxHistoryAge = 35;
|
|
||||||
BString text;
|
|
||||||
text << maxHistoryAge;
|
|
||||||
fDaysInGoMenuControl->SetText(text.String());
|
|
||||||
BrowsingHistory::DefaultInstance()->SetMaxHistoryItemAge(maxHistoryAge);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
@@ -52,6 +53,8 @@ SettingsMessage::InitCheck() const
|
|||||||
status_t
|
status_t
|
||||||
SettingsMessage::Load()
|
SettingsMessage::Load()
|
||||||
{
|
{
|
||||||
|
BAutolock _(this);
|
||||||
|
|
||||||
BFile file(fPath.Path(), B_READ_ONLY);
|
BFile file(fPath.Path(), B_READ_ONLY);
|
||||||
status_t status = file.InitCheck();
|
status_t status = file.InitCheck();
|
||||||
|
|
||||||
@@ -65,6 +68,8 @@ SettingsMessage::Load()
|
|||||||
status_t
|
status_t
|
||||||
SettingsMessage::Save() const
|
SettingsMessage::Save() const
|
||||||
{
|
{
|
||||||
|
BAutolock _(const_cast<SettingsMessage*>(this));
|
||||||
|
|
||||||
BFile file(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
BFile file(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
|
||||||
status_t status = file.InitCheck();
|
status_t status = file.InitCheck();
|
||||||
|
|
||||||
@@ -78,6 +83,8 @@ SettingsMessage::Save() const
|
|||||||
bool
|
bool
|
||||||
SettingsMessage::AddListener(const BMessenger& listener)
|
SettingsMessage::AddListener(const BMessenger& listener)
|
||||||
{
|
{
|
||||||
|
BAutolock _(this);
|
||||||
|
|
||||||
BMessenger* listenerCopy = new(std::nothrow) BMessenger(listener);
|
BMessenger* listenerCopy = new(std::nothrow) BMessenger(listener);
|
||||||
if (listenerCopy && fListeners.AddItem(listenerCopy))
|
if (listenerCopy && fListeners.AddItem(listenerCopy))
|
||||||
return true;
|
return true;
|
||||||
@@ -89,6 +96,8 @@ SettingsMessage::AddListener(const BMessenger& listener)
|
|||||||
void
|
void
|
||||||
SettingsMessage::RemoveListener(const BMessenger& listener)
|
SettingsMessage::RemoveListener(const BMessenger& listener)
|
||||||
{
|
{
|
||||||
|
BAutolock _(this);
|
||||||
|
|
||||||
for (int32 i = fListeners.CountItems() - 1; i >= 0; i--) {
|
for (int32 i = fListeners.CountItems() - 1; i >= 0; i--) {
|
||||||
BMessenger* listenerItem = reinterpret_cast<BMessenger*>(
|
BMessenger* listenerItem = reinterpret_cast<BMessenger*>(
|
||||||
fListeners.ItemAtFast(i));
|
fListeners.ItemAtFast(i));
|
||||||
@@ -401,6 +410,16 @@ SettingsMessage::GetValue(const char* name, const BString& defaultValue) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
SettingsMessage::GetValue(const char* name, const char* defaultValue) const
|
||||||
|
{
|
||||||
|
const char* value;
|
||||||
|
if (FindString(name, &value) != B_OK)
|
||||||
|
return defaultValue;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BPoint
|
BPoint
|
||||||
SettingsMessage::GetValue(const char *name, BPoint defaultValue) const
|
SettingsMessage::GetValue(const char *name, BPoint defaultValue) const
|
||||||
{
|
{
|
||||||
@@ -473,7 +492,7 @@ SettingsMessage::GetValue(const char* name, const BFont& defaultValue) const
|
|||||||
void
|
void
|
||||||
SettingsMessage::_NotifyValueChanged(const char* name) const
|
SettingsMessage::_NotifyValueChanged(const char* name) const
|
||||||
{
|
{
|
||||||
BMessage message(MSG_SETTINGS_VALUE_CHANGED);
|
BMessage message(SETTINGS_VALUE_CHANGED);
|
||||||
message.AddString("name", name);
|
message.AddString("name", name);
|
||||||
|
|
||||||
// Add the value of that name to the notification.
|
// Add the value of that name to the notification.
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#include <FindDirectory.h>
|
#include <FindDirectory.h>
|
||||||
#include <Font.h>
|
#include <Font.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
|
#include <Locker.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
@@ -19,11 +20,11 @@ class BString;
|
|||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_SETTINGS_VALUE_CHANGED = 'stvc'
|
SETTINGS_VALUE_CHANGED = '_svc'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class SettingsMessage : public BMessage {
|
class SettingsMessage : public BMessage, public BLocker {
|
||||||
public:
|
public:
|
||||||
SettingsMessage(directory_which directory,
|
SettingsMessage(directory_which directory,
|
||||||
const char* filename);
|
const char* filename);
|
||||||
@@ -49,9 +50,11 @@ public:
|
|||||||
const char* value);
|
const char* value);
|
||||||
status_t SetValue(const char* name,
|
status_t SetValue(const char* name,
|
||||||
const BString& value);
|
const BString& value);
|
||||||
status_t SetValue(const char *name, const BPoint& value);
|
status_t SetValue(const char *name,
|
||||||
|
const BPoint& value);
|
||||||
status_t SetValue(const char* name, const BRect& value);
|
status_t SetValue(const char* name, const BRect& value);
|
||||||
status_t SetValue(const char* name, const entry_ref& value);
|
status_t SetValue(const char* name,
|
||||||
|
const entry_ref& value);
|
||||||
status_t SetValue(const char* name,
|
status_t SetValue(const char* name,
|
||||||
const BMessage& value);
|
const BMessage& value);
|
||||||
status_t SetValue(const char* name,
|
status_t SetValue(const char* name,
|
||||||
@@ -75,6 +78,8 @@ public:
|
|||||||
float defaultValue) const;
|
float defaultValue) const;
|
||||||
double GetValue(const char* name,
|
double GetValue(const char* name,
|
||||||
double defaultValue) const;
|
double defaultValue) const;
|
||||||
|
const char* GetValue(const char* name,
|
||||||
|
const char* defaultValue) const;
|
||||||
BString GetValue(const char* name,
|
BString GetValue(const char* name,
|
||||||
const BString& defaultValue) const;
|
const BString& defaultValue) const;
|
||||||
BPoint GetValue(const char *name,
|
BPoint GetValue(const char *name,
|
||||||
|
|||||||
Reference in New Issue
Block a user