Converted to Haiku coding style.
git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@337 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
committed by
Alexandre Deckner
parent
aa5ba348ea
commit
9ccfda9c50
@@ -25,12 +25,10 @@
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "DownloadWindow.h"
|
||||
|
||||
#include "BrowserApp.h"
|
||||
#include "WebDownload.h"
|
||||
#include "WebPage.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Bitmap.h>
|
||||
#include <Button.h>
|
||||
@@ -48,7 +46,11 @@
|
||||
#include <SeparatorView.h>
|
||||
#include <SpaceLayoutItem.h>
|
||||
#include <StatusBar.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "BrowserApp.h"
|
||||
#include "WebDownload.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
|
||||
enum {
|
||||
REMOVE_FINISHED_DOWNLOADS = 'rmfd',
|
||||
@@ -59,28 +61,31 @@ enum {
|
||||
SAVE_SETTINGS = 'svst'
|
||||
};
|
||||
|
||||
|
||||
class IconView : public BView {
|
||||
public:
|
||||
IconView(const BEntry& entry)
|
||||
: BView("Download icon", B_WILL_DRAW)
|
||||
, m_iconBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32)
|
||||
:
|
||||
BView("Download icon", B_WILL_DRAW),
|
||||
fIconBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32)
|
||||
{
|
||||
BNode node(&entry);
|
||||
BNodeInfo info(&node);
|
||||
info.GetTrackerIcon(&m_iconBitmap, B_LARGE_ICON);
|
||||
info.GetTrackerIcon(&fIconBitmap, B_LARGE_ICON);
|
||||
SetDrawingMode(B_OP_OVER);
|
||||
}
|
||||
|
||||
IconView(BMessage* archive)
|
||||
: BView("Download icon", B_WILL_DRAW)
|
||||
, m_iconBitmap(archive)
|
||||
:
|
||||
BView("Download icon", B_WILL_DRAW),
|
||||
fIconBitmap(archive)
|
||||
{
|
||||
SetDrawingMode(B_OP_OVER);
|
||||
}
|
||||
|
||||
status_t saveSettings(BMessage* archive)
|
||||
status_t SaveSettings(BMessage* archive)
|
||||
{
|
||||
return m_iconBitmap.Archive(archive);
|
||||
return fIconBitmap.Archive(archive);
|
||||
}
|
||||
|
||||
virtual void AttachedToWindow()
|
||||
@@ -90,12 +95,12 @@ public:
|
||||
|
||||
virtual void Draw(BRect updateRect)
|
||||
{
|
||||
DrawBitmapAsync(&m_iconBitmap);
|
||||
DrawBitmapAsync(&fIconBitmap);
|
||||
}
|
||||
|
||||
virtual BSize MinSize()
|
||||
{
|
||||
return BSize(m_iconBitmap.Bounds().Width(), m_iconBitmap.Bounds().Height());
|
||||
return BSize(fIconBitmap.Bounds().Width(), fIconBitmap.Bounds().Height());
|
||||
}
|
||||
|
||||
virtual BSize PreferredSize()
|
||||
@@ -109,13 +114,15 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
BBitmap m_iconBitmap;
|
||||
BBitmap fIconBitmap;
|
||||
};
|
||||
|
||||
|
||||
class SmallButton : public BButton {
|
||||
public:
|
||||
SmallButton(const char* label, BMessage* message = NULL)
|
||||
: BButton(label, message)
|
||||
:
|
||||
BButton(label, message)
|
||||
{
|
||||
BFont font;
|
||||
GetFont(&font);
|
||||
@@ -125,34 +132,37 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DownloadProgressView : public BGridView {
|
||||
public:
|
||||
DownloadProgressView(BWebDownload* download)
|
||||
: BGridView(8, 3)
|
||||
, m_download(download)
|
||||
, m_url(download->URL())
|
||||
, m_path(download->Path())
|
||||
, m_expectedSize(download->ExpectedSize())
|
||||
:
|
||||
BGridView(8, 3),
|
||||
fDownload(download),
|
||||
fURL(download->URL()),
|
||||
fPath(download->Path()),
|
||||
fExpectedSize(download->ExpectedSize())
|
||||
{
|
||||
}
|
||||
|
||||
DownloadProgressView(const BMessage* archive)
|
||||
: BGridView(8, 3)
|
||||
, m_download(NULL)
|
||||
, m_url()
|
||||
, m_path()
|
||||
, m_expectedSize(0)
|
||||
:
|
||||
BGridView(8, 3),
|
||||
fDownload(NULL),
|
||||
fURL(),
|
||||
fPath(),
|
||||
fExpectedSize(0)
|
||||
{
|
||||
const char* string;
|
||||
if (archive->FindString("path", &string) == B_OK)
|
||||
m_path.SetTo(string);
|
||||
fPath.SetTo(string);
|
||||
if (archive->FindString("url", &string) == B_OK)
|
||||
m_url = string;
|
||||
fURL = string;
|
||||
}
|
||||
|
||||
bool init(BMessage* archive = NULL)
|
||||
bool Init(BMessage* archive = NULL)
|
||||
{
|
||||
BEntry entry(m_path.Path());
|
||||
BEntry entry(fPath.Path());
|
||||
if (!entry.Exists() && !archive)
|
||||
return false;
|
||||
|
||||
@@ -160,62 +170,62 @@ public:
|
||||
SetFlags(Flags() | B_FULL_UPDATE_ON_RESIZE | B_WILL_DRAW);
|
||||
|
||||
BGridLayout* layout = GridLayout();
|
||||
m_statusBar = new BStatusBar("download progress", m_path.Leaf());
|
||||
m_statusBar->SetMaxValue(100);
|
||||
fStatusBar = new BStatusBar("download progress", fPath.Leaf());
|
||||
fStatusBar->SetMaxValue(100);
|
||||
if (archive) {
|
||||
float value;
|
||||
if (archive->FindFloat("value", &value) == B_OK)
|
||||
m_statusBar->SetTo(value);
|
||||
fStatusBar->SetTo(value);
|
||||
}
|
||||
m_statusBar->SetBarHeight(12);
|
||||
fStatusBar->SetBarHeight(12);
|
||||
|
||||
if (entry.Exists())
|
||||
m_iconView = new IconView(entry);
|
||||
fIconView = new IconView(entry);
|
||||
else
|
||||
m_iconView = new IconView(archive);
|
||||
fIconView = new IconView(archive);
|
||||
|
||||
if (!m_download && m_statusBar->CurrentValue() < 100)
|
||||
m_button1 = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
||||
if (!fDownload && fStatusBar->CurrentValue() < 100)
|
||||
fTopButton = new SmallButton("Restart", new BMessage(RESTART_DOWNLOAD));
|
||||
else {
|
||||
m_button1 = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
||||
m_button1->SetEnabled(m_download == NULL);
|
||||
fTopButton = new SmallButton("Open", new BMessage(OPEN_DOWNLOAD));
|
||||
fTopButton->SetEnabled(fDownload == NULL);
|
||||
}
|
||||
if (m_download)
|
||||
m_button2 = new SmallButton("Cancel", new BMessage(CANCEL_DOWNLOAD));
|
||||
if (fDownload)
|
||||
fBottomButton = new SmallButton("Cancel", new BMessage(CANCEL_DOWNLOAD));
|
||||
else {
|
||||
m_button2 = new SmallButton("Remove", new BMessage(REMOVE_DOWNLOAD));
|
||||
m_button2->SetEnabled(m_download == NULL);
|
||||
fBottomButton = new SmallButton("Remove", new BMessage(REMOVE_DOWNLOAD));
|
||||
fBottomButton->SetEnabled(fDownload == NULL);
|
||||
}
|
||||
|
||||
layout->SetInsets(8, 5, 5, 6);
|
||||
layout->AddView(m_iconView, 0, 0, 1, 2);
|
||||
layout->AddView(m_statusBar, 1, 0, 1, 2);
|
||||
layout->AddView(m_button1, 2, 0);
|
||||
layout->AddView(m_button2, 2, 1);
|
||||
layout->AddView(fIconView, 0, 0, 1, 2);
|
||||
layout->AddView(fStatusBar, 1, 0, 1, 2);
|
||||
layout->AddView(fTopButton, 2, 0);
|
||||
layout->AddView(fBottomButton, 2, 1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
status_t saveSettings(BMessage* archive)
|
||||
status_t SaveSettings(BMessage* archive)
|
||||
{
|
||||
if (!archive)
|
||||
return B_BAD_VALUE;
|
||||
status_t ret = archive->AddString("path", m_path.Path());
|
||||
status_t ret = archive->AddString("path", fPath.Path());
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddString("url", m_url.String());
|
||||
ret = archive->AddString("url", fURL.String());
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddFloat("value", m_statusBar->CurrentValue());
|
||||
ret = archive->AddFloat("value", fStatusBar->CurrentValue());
|
||||
if (ret == B_OK)
|
||||
ret = m_iconView->saveSettings(archive);
|
||||
ret = fIconView->SaveSettings(archive);
|
||||
return ret;
|
||||
}
|
||||
|
||||
virtual void AttachedToWindow()
|
||||
{
|
||||
if (m_download)
|
||||
m_download->SetProgressListener(BMessenger(this));
|
||||
m_button1->SetTarget(this);
|
||||
m_button2->SetTarget(this);
|
||||
if (fDownload)
|
||||
fDownload->SetProgressListener(BMessenger(this));
|
||||
fTopButton->SetTarget(this);
|
||||
fBottomButton->SetTarget(this);
|
||||
}
|
||||
|
||||
virtual void AllAttached()
|
||||
@@ -240,13 +250,13 @@ public:
|
||||
case B_DOWNLOAD_PROGRESS: {
|
||||
float progress;
|
||||
if (message->FindFloat("progress", &progress) == B_OK)
|
||||
m_statusBar->SetTo(progress);
|
||||
fStatusBar->SetTo(progress);
|
||||
break;
|
||||
}
|
||||
case OPEN_DOWNLOAD: {
|
||||
// TODO: In case of executable files, ask the user first!
|
||||
entry_ref ref;
|
||||
status_t status = get_ref_for_path(m_path.Path(), &ref);
|
||||
status_t status = get_ref_for_path(fPath.Path(), &ref);
|
||||
if (status == B_OK)
|
||||
status = be_roster->Launch(&ref);
|
||||
if (status != B_OK && status != B_ALREADY_RUNNING) {
|
||||
@@ -257,12 +267,12 @@ public:
|
||||
break;
|
||||
}
|
||||
case RESTART_DOWNLOAD:
|
||||
BWebPage::RequestDownload(m_url);
|
||||
BWebPage::RequestDownload(fURL);
|
||||
break;
|
||||
|
||||
case CANCEL_DOWNLOAD:
|
||||
m_download->Cancel();
|
||||
downloadCanceled();
|
||||
fDownload->Cancel();
|
||||
DownloadCanceled();
|
||||
break;
|
||||
|
||||
case REMOVE_DOWNLOAD: {
|
||||
@@ -283,51 +293,53 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
BWebDownload* download() const
|
||||
BWebDownload* Download() const
|
||||
{
|
||||
return m_download;
|
||||
return fDownload;
|
||||
}
|
||||
|
||||
const BString& url() const
|
||||
const BString& URL() const
|
||||
{
|
||||
return m_url;
|
||||
return fURL;
|
||||
}
|
||||
|
||||
void downloadFinished()
|
||||
void DownloadFinished()
|
||||
{
|
||||
m_download = NULL;
|
||||
m_button1->SetEnabled(true);
|
||||
m_button2->SetLabel("Remove");
|
||||
m_button2->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||
m_button2->SetEnabled(true);
|
||||
fDownload = NULL;
|
||||
fTopButton->SetEnabled(true);
|
||||
fBottomButton->SetLabel("Remove");
|
||||
fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||
fBottomButton->SetEnabled(true);
|
||||
}
|
||||
|
||||
void downloadCanceled()
|
||||
void DownloadCanceled()
|
||||
{
|
||||
m_download = NULL;
|
||||
m_button1->SetLabel("Restart");
|
||||
m_button1->SetMessage(new BMessage(RESTART_DOWNLOAD));
|
||||
m_button1->SetEnabled(true);
|
||||
m_button2->SetLabel("Remove");
|
||||
m_button2->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||
m_button2->SetEnabled(true);
|
||||
fDownload = NULL;
|
||||
fTopButton->SetLabel("Restart");
|
||||
fTopButton->SetMessage(new BMessage(RESTART_DOWNLOAD));
|
||||
fTopButton->SetEnabled(true);
|
||||
fBottomButton->SetLabel("Remove");
|
||||
fBottomButton->SetMessage(new BMessage(REMOVE_DOWNLOAD));
|
||||
fBottomButton->SetEnabled(true);
|
||||
}
|
||||
|
||||
private:
|
||||
IconView* m_iconView;
|
||||
BStatusBar* m_statusBar;
|
||||
SmallButton* m_button1;
|
||||
SmallButton* m_button2;
|
||||
BWebDownload* m_download;
|
||||
BString m_url;
|
||||
BPath m_path;
|
||||
off_t m_expectedSize;
|
||||
IconView* fIconView;
|
||||
BStatusBar* fStatusBar;
|
||||
SmallButton* fTopButton;
|
||||
SmallButton* fBottomButton;
|
||||
BWebDownload* fDownload;
|
||||
BString fURL;
|
||||
BPath fPath;
|
||||
off_t fExpectedSize;
|
||||
};
|
||||
|
||||
|
||||
class DownloadsContainerView : public BGroupView {
|
||||
public:
|
||||
DownloadsContainerView()
|
||||
: BGroupView(B_VERTICAL)
|
||||
:
|
||||
BGroupView(B_VERTICAL)
|
||||
{
|
||||
SetViewColor(245, 245, 245);
|
||||
AddChild(BSpaceLayoutItem::CreateGlue());
|
||||
@@ -356,10 +368,13 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DownloadContainerScrollView : public BScrollView {
|
||||
public:
|
||||
DownloadContainerScrollView(BView* target)
|
||||
: BScrollView("Downloads scroll view", target, 0, false, true, B_NO_BORDER)
|
||||
:
|
||||
BScrollView("Downloads scroll view", target, 0, false, true,
|
||||
B_NO_BORDER)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -375,6 +390,7 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
DownloadWindow::DownloadWindow(BRect frame, bool visible)
|
||||
: BWindow(frame, "Downloads",
|
||||
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
@@ -383,18 +399,19 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible)
|
||||
SetLayout(new BGroupLayout(B_VERTICAL));
|
||||
|
||||
DownloadsContainerView* downloadsGroupView = new DownloadsContainerView();
|
||||
m_downloadViewsLayout = downloadsGroupView->GroupLayout();
|
||||
fDownloadViewsLayout = downloadsGroupView->GroupLayout();
|
||||
|
||||
BMenuBar* menuBar = new BMenuBar("Menu bar");
|
||||
BMenu* menu = new BMenu("Window");
|
||||
menu->AddItem(new BMenuItem("Hide", new BMessage(B_QUIT_REQUESTED), 'H'));
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
BScrollView* scrollView = new DownloadContainerScrollView(downloadsGroupView);
|
||||
BScrollView* scrollView = new DownloadContainerScrollView(
|
||||
downloadsGroupView);
|
||||
|
||||
m_removeFinishedButton = new BButton("Remove finished",
|
||||
fRemoveFinishedButton = new BButton("Remove finished",
|
||||
new BMessage(REMOVE_FINISHED_DOWNLOADS));
|
||||
m_removeFinishedButton->SetEnabled(false);
|
||||
fRemoveFinishedButton->SetEnabled(false);
|
||||
|
||||
AddChild(BGroupLayoutBuilder(B_VERTICAL)
|
||||
.Add(menuBar)
|
||||
@@ -402,46 +419,53 @@ DownloadWindow::DownloadWindow(BRect frame, bool visible)
|
||||
.Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER))
|
||||
.Add(BGroupLayoutBuilder(B_HORIZONTAL)
|
||||
.AddGlue()
|
||||
.Add(m_removeFinishedButton)
|
||||
.Add(fRemoveFinishedButton)
|
||||
.SetInsets(5, 5, 5, 5)
|
||||
)
|
||||
);
|
||||
|
||||
loadSettings();
|
||||
_LoadSettings();
|
||||
// Small trick to get the correct enabled status of the Remove finished button
|
||||
downloadFinished(NULL);
|
||||
_DownloadFinished(NULL);
|
||||
|
||||
if (!visible)
|
||||
Hide();
|
||||
Show();
|
||||
}
|
||||
|
||||
|
||||
DownloadWindow::~DownloadWindow()
|
||||
{
|
||||
// Only necessary to save the current progress of unfinished downloads:
|
||||
saveSettings();
|
||||
_SaveSettings();
|
||||
}
|
||||
|
||||
void DownloadWindow::MessageReceived(BMessage* message)
|
||||
|
||||
void
|
||||
DownloadWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case B_DOWNLOAD_ADDED: {
|
||||
BWebDownload* download;
|
||||
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
||||
downloadStarted(download);
|
||||
if (message->FindPointer("download", reinterpret_cast<void**>(
|
||||
&download)) == B_OK) {
|
||||
_DownloadStarted(download);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case B_DOWNLOAD_REMOVED: {
|
||||
BWebDownload* download;
|
||||
if (message->FindPointer("download", reinterpret_cast<void**>(&download)) == B_OK)
|
||||
downloadFinished(download);
|
||||
if (message->FindPointer("download", reinterpret_cast<void**>(
|
||||
&download)) == B_OK) {
|
||||
_DownloadFinished(download);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REMOVE_FINISHED_DOWNLOADS:
|
||||
removeFinishedDownloads();
|
||||
_RemoveFinishedDownloads();
|
||||
break;
|
||||
case SAVE_SETTINGS:
|
||||
saveSettings();
|
||||
_SaveSettings();
|
||||
break;
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
@@ -449,111 +473,133 @@ void DownloadWindow::MessageReceived(BMessage* message)
|
||||
}
|
||||
}
|
||||
|
||||
bool DownloadWindow::QuitRequested()
|
||||
|
||||
bool
|
||||
DownloadWindow::QuitRequested()
|
||||
{
|
||||
if (!IsHidden())
|
||||
Hide();
|
||||
return false;
|
||||
}
|
||||
|
||||
void DownloadWindow::downloadStarted(BWebDownload* download)
|
||||
|
||||
void
|
||||
DownloadWindow::_DownloadStarted(BWebDownload* download)
|
||||
{
|
||||
int32 finishedCount = 0;
|
||||
int32 index = 0;
|
||||
for (int32 i = m_downloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
|
||||
item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
if (view->url() == download->URL()) {
|
||||
if (view->URL() == download->URL()) {
|
||||
index = i;
|
||||
view->RemoveSelf();
|
||||
delete view;
|
||||
} else if (!view->download())
|
||||
} else if (!view->Download())
|
||||
finishedCount++;
|
||||
}
|
||||
m_removeFinishedButton->SetEnabled(finishedCount > 0);
|
||||
fRemoveFinishedButton->SetEnabled(finishedCount > 0);
|
||||
DownloadProgressView* view = new DownloadProgressView(download);
|
||||
if (!view->init())
|
||||
if (!view->Init())
|
||||
return;
|
||||
m_downloadViewsLayout->AddView(index, view);
|
||||
saveSettings();
|
||||
fDownloadViewsLayout->AddView(index, view);
|
||||
_SaveSettings();
|
||||
|
||||
SetWorkspaces(B_CURRENT_WORKSPACE);
|
||||
if (IsHidden())
|
||||
Show();
|
||||
}
|
||||
|
||||
void DownloadWindow::downloadFinished(BWebDownload* download)
|
||||
|
||||
void
|
||||
DownloadWindow::_DownloadFinished(BWebDownload* download)
|
||||
{
|
||||
int32 finishedCount = 0;
|
||||
for (int32 i = 0; BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i++) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
for (int32 i = 0;
|
||||
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i++) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
|
||||
item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
if (view->download() == download) {
|
||||
view->downloadFinished();
|
||||
if (view->Download() == download) {
|
||||
view->DownloadFinished();
|
||||
finishedCount++;
|
||||
} else if (!view->download())
|
||||
} else if (!view->Download())
|
||||
finishedCount++;
|
||||
}
|
||||
m_removeFinishedButton->SetEnabled(finishedCount > 0);
|
||||
fRemoveFinishedButton->SetEnabled(finishedCount > 0);
|
||||
if (download)
|
||||
saveSettings();
|
||||
_SaveSettings();
|
||||
}
|
||||
|
||||
void DownloadWindow::removeFinishedDownloads()
|
||||
|
||||
void
|
||||
DownloadWindow::_RemoveFinishedDownloads()
|
||||
{
|
||||
for (int32 i = m_downloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
|
||||
item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
if (!view->download()) {
|
||||
if (!view->Download()) {
|
||||
view->RemoveSelf();
|
||||
delete view;
|
||||
}
|
||||
}
|
||||
m_removeFinishedButton->SetEnabled(false);
|
||||
saveSettings();
|
||||
fRemoveFinishedButton->SetEnabled(false);
|
||||
_SaveSettings();
|
||||
}
|
||||
|
||||
void DownloadWindow::saveSettings()
|
||||
|
||||
void
|
||||
DownloadWindow::_SaveSettings()
|
||||
{
|
||||
BFile file;
|
||||
if (!openSettingsFile(file, B_ERASE_FILE | B_CREATE_FILE | B_WRITE_ONLY))
|
||||
if (!_OpenSettingsFile(file, B_ERASE_FILE | B_CREATE_FILE | B_WRITE_ONLY))
|
||||
return;
|
||||
BMessage message;
|
||||
for (int32 i = m_downloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = m_downloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(item->View());
|
||||
for (int32 i = fDownloadViewsLayout->CountItems() - 1;
|
||||
BLayoutItem* item = fDownloadViewsLayout->ItemAt(i); i--) {
|
||||
DownloadProgressView* view = dynamic_cast<DownloadProgressView*>(
|
||||
item->View());
|
||||
if (!view)
|
||||
continue;
|
||||
BMessage downloadArchive;
|
||||
if (view->saveSettings(&downloadArchive) == B_OK)
|
||||
if (view->SaveSettings(&downloadArchive) == B_OK)
|
||||
message.AddMessage("download", &downloadArchive);
|
||||
}
|
||||
message.Flatten(&file);
|
||||
}
|
||||
|
||||
void DownloadWindow::loadSettings()
|
||||
|
||||
void
|
||||
DownloadWindow::_LoadSettings()
|
||||
{
|
||||
BFile file;
|
||||
if (!openSettingsFile(file, B_READ_ONLY))
|
||||
if (!_OpenSettingsFile(file, B_READ_ONLY))
|
||||
return;
|
||||
BMessage message;
|
||||
if (message.Unflatten(&file) != B_OK)
|
||||
return;
|
||||
BMessage downloadArchive;
|
||||
for (int32 i = 0; message.FindMessage("download", i, &downloadArchive) == B_OK; i++) {
|
||||
DownloadProgressView* view = new DownloadProgressView(&downloadArchive);
|
||||
if (!view->init(&downloadArchive))
|
||||
for (int32 i = 0;
|
||||
message.FindMessage("download", i, &downloadArchive) == B_OK;
|
||||
i++) {
|
||||
DownloadProgressView* view = new DownloadProgressView(
|
||||
&downloadArchive);
|
||||
if (!view->Init(&downloadArchive))
|
||||
continue;
|
||||
m_downloadViewsLayout->AddView(0, view);
|
||||
fDownloadViewsLayout->AddView(0, view);
|
||||
}
|
||||
}
|
||||
|
||||
bool DownloadWindow::openSettingsFile(BFile& file, uint32 mode)
|
||||
|
||||
bool
|
||||
DownloadWindow::_OpenSettingsFile(BFile& file, uint32 mode)
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef DOWNLOAD_WINDOW_H
|
||||
#define DOWNLOAD_WINDOW_H
|
||||
|
||||
#ifndef DownloadWindow_h
|
||||
#define DownloadWindow_h
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
@@ -35,26 +35,27 @@ class BFile;
|
||||
class BGroupLayout;
|
||||
class BWebDownload;
|
||||
|
||||
|
||||
class DownloadWindow : public BWindow {
|
||||
public:
|
||||
DownloadWindow(BRect frame, bool visible);
|
||||
virtual ~DownloadWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
void downloadStarted(BWebDownload* download);
|
||||
void downloadFinished(BWebDownload* download);
|
||||
void removeFinishedDownloads();
|
||||
void saveSettings();
|
||||
void loadSettings();
|
||||
bool openSettingsFile(BFile& file, uint32 mode);
|
||||
void _DownloadStarted(BWebDownload* download);
|
||||
void _DownloadFinished(BWebDownload* download);
|
||||
void _RemoveFinishedDownloads();
|
||||
void _SaveSettings();
|
||||
void _LoadSettings();
|
||||
bool _OpenSettingsFile(BFile& file, uint32 mode);
|
||||
|
||||
private:
|
||||
BGroupLayout* m_downloadViewsLayout;
|
||||
BButton* m_removeFinishedButton;
|
||||
BGroupLayout* fDownloadViewsLayout;
|
||||
BButton* fRemoveFinishedButton;
|
||||
};
|
||||
|
||||
#endif // DownloadWindow_h
|
||||
|
||||
#endif // DOWNLOAD_WINDOW_H
|
||||
|
||||
Reference in New Issue
Block a user