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:
stippi 2010-03-23 00:02:05 +00:00 committed by Alexandre Deckner
parent 1beb8c8035
commit 636f175b15
6 changed files with 109 additions and 36 deletions

View File

@ -145,7 +145,8 @@ BrowserApp::ReadyToRun()
BRect());
bool showDownloads = fSettings->GetValue("show downloads", false);
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads);
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads,
fSettings);
fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings);
BWebPage::SetDownloadListener(BMessenger(fDownloadWindow));

View File

@ -48,6 +48,7 @@
#include <StatusBar.h>
#include "BrowserApp.h"
#include "SettingsMessage.h"
#include "WebDownload.h"
#include "WebPage.h"
@ -64,15 +65,13 @@ enum {
class IconView : public BView {
public:
IconView(const BEntry& entry)
IconView()
:
BView("Download icon", B_WILL_DRAW),
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);
memset(fIconBitmap.Bits(), 0, fIconBitmap.BitsLength());
}
IconView(BMessage* archive)
@ -83,6 +82,14 @@ public:
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)
{
return fIconBitmap.Archive(archive);
@ -162,27 +169,24 @@ public:
bool Init(BMessage* archive = NULL)
{
BEntry entry(fPath.Path());
if (!entry.Exists() && !archive)
return false;
SetViewColor(245, 245, 245);
SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW);
BGridLayout* layout = GridLayout();
fStatusBar = new BStatusBar("download progress", fPath.Leaf());
fStatusBar->SetMaxValue(100);
if (archive) {
fStatusBar = new BStatusBar("download progress", fPath.Leaf());
float value;
if (archive->FindFloat("value", &value) == B_OK)
fStatusBar->SetTo(value);
}
} else
fStatusBar = new BStatusBar("download progress", "Download");
fStatusBar->SetMaxValue(100);
fStatusBar->SetBarHeight(12);
if (entry.Exists())
fIconView = new IconView(entry);
else
if (archive)
fIconView = new IconView(archive);
else
fIconView = new IconView();
if (!fDownload && fStatusBar->CurrentValue() < 100)
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
@ -247,6 +251,17 @@ public:
virtual void MessageReceived(BMessage* message)
{
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: {
float progress;
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",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
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));
DownloadsContainerView* downloadsGroupView = new DownloadsContainerView();
@ -445,7 +471,8 @@ void
DownloadWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_DOWNLOAD_ADDED: {
case B_DOWNLOAD_ADDED:
{
BWebDownload* download;
if (message->FindPointer("download", reinterpret_cast<void**>(
&download)) == B_OK) {
@ -453,7 +480,8 @@ DownloadWindow::MessageReceived(BMessage* message)
}
break;
}
case B_DOWNLOAD_REMOVED: {
case B_DOWNLOAD_REMOVED:
{
BWebDownload* download;
if (message->FindPointer("download", reinterpret_cast<void**>(
&download)) == B_OK) {
@ -467,6 +495,17 @@ DownloadWindow::MessageReceived(BMessage* message)
case SAVE_SETTINGS:
_SaveSettings();
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:
BWindow::MessageReceived(message);
break;
@ -486,6 +525,8 @@ DownloadWindow::QuitRequested()
void
DownloadWindow::_DownloadStarted(BWebDownload* download)
{
download->Start(BPath(fDownloadPath.String()));
int32 finishedCount = 0;
int32 index = 0;
for (int32 i = fDownloadViewsLayout->CountItems() - 1;

View File

@ -28,17 +28,20 @@
#define DOWNLOAD_WINDOW_H
#include <String.h>
#include <Window.h>
class BButton;
class BFile;
class BGroupLayout;
class BWebDownload;
class SettingsMessage;
class DownloadWindow : public BWindow {
public:
DownloadWindow(BRect frame, bool visible);
DownloadWindow(BRect frame, bool visible,
SettingsMessage* settings);
virtual ~DownloadWindow();
virtual void MessageReceived(BMessage* message);
@ -55,6 +58,7 @@ private:
private:
BGroupLayout* fDownloadViewsLayout;
BButton* fRemoveFinishedButton;
BString fDownloadPath;
};
#endif // DOWNLOAD_WINDOW_H

View File

@ -202,7 +202,7 @@ SettingsWindow::_CreateGeneralPage(float spacing)
{
fDownloadFolderControl = new BTextControl("download folder",
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"),
NULL);
@ -312,7 +312,20 @@ SettingsWindow::_CreateFontsPage(float spacing)
void
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("serif font", fSerifFontView->Font());
fSettings->SetValue("sans serif font", fSansSerifFontView->Font());
@ -335,16 +348,6 @@ SettingsWindow::_ApplySettings()
// This will find all currently instantiated page settings and apply
// the default values, unless the page settings have local overrides.
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);
}

View File

@ -11,6 +11,7 @@
#include <new>
#include <Autolock.h>
#include <Entry.h>
#include <File.h>
#include <Messenger.h>
@ -52,6 +53,8 @@ SettingsMessage::InitCheck() const
status_t
SettingsMessage::Load()
{
BAutolock _(this);
BFile file(fPath.Path(), B_READ_ONLY);
status_t status = file.InitCheck();
@ -65,6 +68,8 @@ SettingsMessage::Load()
status_t
SettingsMessage::Save() const
{
BAutolock _(const_cast<SettingsMessage*>(this));
BFile file(fPath.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
status_t status = file.InitCheck();
@ -78,6 +83,8 @@ SettingsMessage::Save() const
bool
SettingsMessage::AddListener(const BMessenger& listener)
{
BAutolock _(this);
BMessenger* listenerCopy = new(std::nothrow) BMessenger(listener);
if (listenerCopy && fListeners.AddItem(listenerCopy))
return true;
@ -89,6 +96,8 @@ SettingsMessage::AddListener(const BMessenger& listener)
void
SettingsMessage::RemoveListener(const BMessenger& listener)
{
BAutolock _(this);
for (int32 i = fListeners.CountItems() - 1; i >= 0; i--) {
BMessenger* listenerItem = reinterpret_cast<BMessenger*>(
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
SettingsMessage::GetValue(const char *name, BPoint defaultValue) const
{
@ -473,7 +492,7 @@ SettingsMessage::GetValue(const char* name, const BFont& defaultValue) const
void
SettingsMessage::_NotifyValueChanged(const char* name) const
{
BMessage message(MSG_SETTINGS_VALUE_CHANGED);
BMessage message(SETTINGS_VALUE_CHANGED);
message.AddString("name", name);
// Add the value of that name to the notification.

View File

@ -11,6 +11,7 @@
#include <FindDirectory.h>
#include <Font.h>
#include <List.h>
#include <Locker.h>
#include <Message.h>
#include <Path.h>
@ -19,11 +20,11 @@ class BString;
enum {
MSG_SETTINGS_VALUE_CHANGED = 'stvc'
SETTINGS_VALUE_CHANGED = '_svc'
};
class SettingsMessage : public BMessage {
class SettingsMessage : public BMessage, public BLocker {
public:
SettingsMessage(directory_which directory,
const char* filename);
@ -49,9 +50,11 @@ public:
const char* value);
status_t SetValue(const char* name,
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 entry_ref& value);
status_t SetValue(const char* name,
const entry_ref& value);
status_t SetValue(const char* name,
const BMessage& value);
status_t SetValue(const char* name,
@ -75,6 +78,8 @@ public:
float defaultValue) const;
double GetValue(const char* name,
double defaultValue) const;
const char* GetValue(const char* name,
const char* defaultValue) const;
BString GetValue(const char* name,
const BString& defaultValue) const;
BPoint GetValue(const char *name,