* Cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40113 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2011-01-04 19:14:39 +00:00
parent 0341cc7868
commit 5b788d58b7
25 changed files with 528 additions and 514 deletions

View File

@ -1,18 +1,19 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
#ifndef BOOT_DRIVE_H #ifndef BOOT_DRIVE_H
#define BOOT_DRIVE_H #define BOOT_DRIVE_H
#include <File.h> #include <File.h>
#include <Message.h> #include <Message.h>
/*
Setting BMessage Format: /* Setting BMessage Format:
"disk" String (path to boot disk) "disk" String (path to boot disk)
@ -22,27 +23,33 @@
"type" String (short name of file system: bfs, dos) "type" String (short name of file system: bfs, dos)
"path" String (path to partition in /dev/...) "path" String (path to partition in /dev/...)
"size" long (size of partition in bytes) "size" long (size of partition in bytes)
*/ */
enum { enum {
// Not enough space free before first partition for boot loader // Not enough space free before first partition for boot loader
kErrorBootSectorTooSmall = B_ERRORS_END + 1, kErrorBootSectorTooSmall = B_ERRORS_END + 1,
}; };
class BootDrive
{
public:
BootDrive() {}
virtual ~BootDrive() {}
virtual bool IsBootMenuInstalled(BMessage* settings) = 0; class BootDrive {
virtual status_t ReadPartitions(BMessage* settings) = 0; public:
virtual status_t WriteBootMenu(BMessage* settings) = 0; BootDrive() {}
virtual status_t SaveMasterBootRecord(BMessage* settings, BFile* file) = 0; virtual ~BootDrive() {}
virtual status_t RestoreMasterBootRecord(BMessage* settings, BFile* file) = 0;
virtual bool IsBootMenuInstalled(BMessage* settings) = 0;
virtual status_t ReadPartitions(BMessage* settings) = 0;
virtual status_t WriteBootMenu(BMessage* settings) = 0;
virtual status_t SaveMasterBootRecord(BMessage* settings,
BFile* file) = 0;
virtual status_t RestoreMasterBootRecord(BMessage* settings,
BFile* file) = 0;
// Converts the specified text into a text as it will be shown // Converts the specified text into a text as it will be shown
// in the boot menu. // in the boot menu.
virtual status_t GetDisplayText(const char* text, BString& displayText) = 0; virtual status_t GetDisplayText(const char* text,
BString& displayText) = 0;
}; };
#endif // BOOT_DRIVE_H #endif // BOOT_DRIVE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,28 +9,23 @@
#include "BootManagerWindow.h" #include "BootManagerWindow.h"
#include "WizardView.h"
#include "EntryPage.h"
#include "PartitionsPage.h"
#include "DefaultPartitionPage.h"
#include <Application.h> #include <Application.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <math.h> #include <tracker_private.h>
#include "tracker_private.h" #include "DefaultPartitionPage.h"
#include "EntryPage.h"
#include "PartitionsPage.h"
#include "WizardView.h"
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "BootManagerWindow" #define B_TRANSLATE_CONTEXT "BootManagerWindow"
BootManagerWindow::BootManagerWindow() BootManagerWindow::BootManagerWindow()
: :
BWindow(BRect(100, 100, 500, 400), B_TRANSLATE_COMMENT("BootManager", BWindow(BRect(100, 100, 500, 400), B_TRANSLATE_COMMENT("BootManager",

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -39,13 +39,12 @@ enum {
const int32 kTimeoutIndefinitely = -1; const int32 kTimeoutIndefinitely = -1;
const int32 kDefaultTimeout = kTimeoutIndefinitely; const int32 kDefaultTimeout = kTimeoutIndefinitely;
typedef struct { struct TimeoutOption {
int32 timeout; int32 timeout;
const char* label; const char* label;
} TimeoutOption; };
static const TimeoutOption gTimeoutOptions[] = static const TimeoutOption gTimeoutOptions[] = {
{
{ 0, B_TRANSLATE_MARK("Immediately")}, { 0, B_TRANSLATE_MARK("Immediately")},
{ 1, B_TRANSLATE_MARK("After one second")}, { 1, B_TRANSLATE_MARK("After one second")},
{ 2, B_TRANSLATE_MARK("After two seconds")}, { 2, B_TRANSLATE_MARK("After two seconds")},
@ -95,8 +94,13 @@ get_label_for_timeout(int32 timeout)
} }
DefaultPartitionPage::DefaultPartitionPage(BMessage* settings, BRect frame, const char* name) // #pragma mark -
: WizardPageView(settings, frame, name, B_FOLLOW_ALL,
DefaultPartitionPage::DefaultPartitionPage(BMessage* settings, BRect frame,
const char* name)
:
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{ {
_BuildUI(); _BuildUI();
@ -129,34 +133,34 @@ DefaultPartitionPage::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case kMsgPartition: case kMsgPartition:
{ {
int32 index; int32 index;
msg->FindInt32("index", &index); msg->FindInt32("index", &index);
fSettings->ReplaceInt32("defaultPartition", index); fSettings->ReplaceInt32("defaultPartition", index);
}
break; break;
}
case kMsgTimeout: case kMsgTimeout:
{ {
int32 sliderValue = fTimeoutSlider->Value(); int32 sliderValue = fTimeoutSlider->Value();
int32 timeout = get_timeout_for_index(sliderValue); int32 timeout = get_timeout_for_index(sliderValue);
fSettings->ReplaceInt32("timeout", timeout); fSettings->ReplaceInt32("timeout", timeout);
BString label; BString label;
_GetTimeoutLabel(timeout, label); _GetTimeoutLabel(timeout, label);
fTimeoutSlider->SetLabel(label.String()); fTimeoutSlider->SetLabel(label.String());
}
break; break;
}
default: default:
WizardPageView::MessageReceived(msg); WizardPageView::MessageReceived(msg);
} }
} }
#define kTextDistance be_control_look->DefaultItemSpacing();
void void
DefaultPartitionPage::_BuildUI() DefaultPartitionPage::_BuildUI()
{ {
const float kTextDistance = be_control_look->DefaultItemSpacing();
BRect rect(Bounds()); BRect rect(Bounds());
BString text; BString text;
@ -223,8 +227,7 @@ DefaultPartitionPage::_CreatePopUpMenu()
"Pop up menu title")); "Pop up menu title"));
BMessage message; BMessage message;
for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK; for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
i ++) { i++) {
bool show; bool show;
if (message.FindBool("show", &show) != B_OK || !show) if (message.FindBool("show", &show) != B_OK || !show)
continue; continue;
@ -261,6 +264,7 @@ DefaultPartitionPage::_Layout()
{ {
LayoutDescriptionVertically(fDescription); LayoutDescriptionVertically(fDescription);
const float kTextDistance = be_control_look->DefaultItemSpacing();
float left = fDefaultPartition->Frame().left; float left = fDefaultPartition->Frame().left;
float top = fDescription->Frame().bottom + kTextDistance; float top = fDescription->Frame().bottom + kTextDistance;
@ -269,4 +273,3 @@ DefaultPartitionPage::_Layout()
fTimeoutSlider->MoveTo(left, top); fTimeoutSlider->MoveTo(left, top);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -20,27 +20,28 @@ class BSlider;
class BTextView; class BTextView;
class DefaultPartitionPage : public WizardPageView class DefaultPartitionPage : public WizardPageView {
{
public: public:
DefaultPartitionPage(BMessage* settings, BRect frame, const char* name); DefaultPartitionPage(BMessage* settings,
virtual ~DefaultPartitionPage(); BRect frame, const char* name);
virtual ~DefaultPartitionPage();
virtual void FrameResized(float width, float height);
virtual void AttachedToWindow(); virtual void FrameResized(float width, float height);
virtual void MessageReceived(BMessage* msg);
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* msg);
private: private:
void _BuildUI();
BPopUpMenu* _CreatePopUpMenu();
void _GetTimeoutLabel(int32 timeout, BString& label);
void _Layout();
void _BuildUI(); private:
BPopUpMenu* _CreatePopUpMenu(); BTextView* fDescription;
void _GetTimeoutLabel(int32 timeout, BString& label); BMenuField* fDefaultPartition;
void _Layout(); BSlider* fTimeoutSlider;
BTextView* fDescription;
BMenuField* fDefaultPartition;
BSlider* fTimeoutSlider;
}; };
#endif // DEFAULT_PARTITON_PAGE_H #endif // DEFAULT_PARTITON_PAGE_H

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -9,16 +9,16 @@
#include "DescriptionPage.h" #include "DescriptionPage.h"
#include <string.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <TextView.h> #include <TextView.h>
#include <string.h>
DescriptionPage::DescriptionPage(BRect frame, const char* name, DescriptionPage::DescriptionPage(BRect frame, const char* name,
const char* description, bool hasHeading) const char* description, bool hasHeading)
: WizardPageView(NULL, frame, name, B_FOLLOW_ALL, :
WizardPageView(NULL, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{ {
_BuildUI(description, hasHeading); _BuildUI(description, hasHeading);
@ -38,19 +38,17 @@ DescriptionPage::FrameResized(float width, float height)
} }
static const float kTextDistance = 10;
void void
DescriptionPage::_BuildUI(const char* description, bool hasHeading) DescriptionPage::_BuildUI(const char* description, bool hasHeading)
{ {
BRect rect(Bounds()); BRect rect(Bounds());
fDescription = CreateDescription(rect, "description", description); fDescription = CreateDescription(rect, "description", description);
if (hasHeading) if (hasHeading)
MakeHeading(fDescription); MakeHeading(fDescription);
fDescription->SetTabWidth(85); fDescription->SetTabWidth(85);
AddChild(fDescription); AddChild(fDescription);
_Layout(); _Layout();
} }
@ -58,6 +56,6 @@ DescriptionPage::_BuildUI(const char* description, bool hasHeading)
void void
DescriptionPage::_Layout() DescriptionPage::_Layout()
{ {
LayoutDescriptionVertically(fDescription); LayoutDescriptionVertically(fDescription);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -14,20 +14,22 @@
class BTextView; class BTextView;
class DescriptionPage : public WizardPageView class DescriptionPage : public WizardPageView {
{
public: public:
DescriptionPage(BRect frame, const char* name, const char* description, bool hasHeading); DescriptionPage(BRect frame, const char* name,
virtual ~DescriptionPage(); const char* description, bool hasHeading);
virtual ~DescriptionPage();
virtual void FrameResized(float width, float height);
virtual void FrameResized(float width, float height);
private: private:
void _BuildUI(const char* description,
bool hasHeading);
void _Layout();
void _BuildUI(const char* description, bool hasHeading); private:
void _Layout(); BTextView* fDescription;
BTextView* fDescription;
}; };
#endif // DESCRIPTION_PAGE_H #endif // DESCRIPTION_PAGE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008-2009, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,21 +9,21 @@
#include "EntryPage.h" #include "EntryPage.h"
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <ControlLook.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <TextView.h> #include <TextView.h>
#include <string.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "EntryPage" #define B_TRANSLATE_CONTEXT "EntryPage"
EntryPage::EntryPage(BMessage* settings, BRect frame, const char* name) EntryPage::EntryPage(BMessage* settings, BRect frame, const char* name)
: WizardPageView(settings, frame, name, B_FOLLOW_ALL, :
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{ {
_BuildUI(); _BuildUI();
@ -49,7 +49,6 @@ EntryPage::PageCompleted()
fSettings->ReplaceBool("install", fInstall->Value() != 0); fSettings->ReplaceBool("install", fInstall->Value() != 0);
} }
static const float kTextDistance = 10;
void void
EntryPage::_BuildUI() EntryPage::_BuildUI()
@ -63,7 +62,8 @@ EntryPage::_BuildUI()
fInstall->ResizeToPreferred(); fInstall->ResizeToPreferred();
BRect textRect(rect); BRect textRect(rect);
textRect.left = fInstall->Frame().right + kTextDistance; textRect.left = fInstall->Frame().right
+ be_control_look->DefaultItemSpacing();
BString text; BString text;
text << text <<

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -15,25 +15,27 @@
class BRadioButton; class BRadioButton;
class BTextView; class BTextView;
class EntryPage : public WizardPageView
{ class EntryPage : public WizardPageView {
public: public:
EntryPage(BMessage* settings, BRect frame, const char* name); EntryPage(BMessage* settings, BRect frame,
virtual ~EntryPage(); const char* name);
virtual ~EntryPage();
virtual void FrameResized(float width, float height);
virtual void FrameResized(float width, float height);
virtual void PageCompleted();
virtual void PageCompleted();
private: private:
void _BuildUI();
void _Layout();
void _BuildUI(); private:
void _Layout(); BRadioButton* fInstall;
BTextView* fInstallText;
BRadioButton* fInstall; BRadioButton* fUninstall;
BTextView* fInstallText; BTextView* fUninstallText;
BRadioButton* fUninstall;
BTextView* fUninstallText;
}; };
#endif // ENTRY_PAGE_H #endif // ENTRY_PAGE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,18 +9,16 @@
#include "FileSelectionPage.h" #include "FileSelectionPage.h"
#include <string.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <ControlLook.h>
#include <Path.h> #include <Path.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <TextControl.h> #include <TextControl.h>
#include <TextView.h> #include <TextView.h>
#include <string.h>
#include <String.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "FileSelectionPage" #define B_TRANSLATE_CONTEXT "FileSelectionPage"
@ -29,12 +27,13 @@
const uint32 kMsgOpenFilePanel = 'open'; const uint32 kMsgOpenFilePanel = 'open';
FileSelectionPage::FileSelectionPage(BMessage* settings, BRect frame, const char* name, FileSelectionPage::FileSelectionPage(BMessage* settings, BRect frame,
const char* description, file_panel_mode mode) const char* name, const char* description, file_panel_mode mode)
: WizardPageView(settings, frame, name, B_FOLLOW_ALL, :
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) WizardPageView(settings, frame, name, B_FOLLOW_ALL,
, fMode(mode) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
, fFilePanel(NULL) fMode(mode),
fFilePanel(NULL)
{ {
_BuildUI(description); _BuildUI(description);
} }
@ -87,12 +86,12 @@ FileSelectionPage::PageCompleted()
} }
const float kTextDistance = 10;
const float kFileButtonDistance = 10; const float kFileButtonDistance = 10;
void void
FileSelectionPage::_BuildUI(const char* description) FileSelectionPage::_BuildUI(const char* description)
{ {
const float kSpacing = be_control_look->DefaultItemSpacing();
BRect rect(Bounds()); BRect rect(Bounds());
fDescription = CreateDescription(rect, "description", description); fDescription = CreateDescription(rect, "description", description);
@ -110,7 +109,7 @@ FileSelectionPage::_BuildUI(const char* description)
fSelect->ResizeToPreferred(); fSelect->ResizeToPreferred();
float selectLeft = rect.right - fSelect->Bounds().Width(); float selectLeft = rect.right - fSelect->Bounds().Width();
rect.right = selectLeft - kFileButtonDistance; rect.right = selectLeft - kSpacing;
fFile = new BTextControl(rect, "file", fFile = new BTextControl(rect, "file",
B_TRANSLATE_COMMENT("File:", "Text control label"), B_TRANSLATE_COMMENT("File:", "Text control label"),
file.String(), new BMessage()); file.String(), new BMessage());
@ -127,10 +126,11 @@ FileSelectionPage::_BuildUI(const char* description)
void void
FileSelectionPage::_Layout() FileSelectionPage::_Layout()
{ {
const float kSpacing = be_control_look->DefaultItemSpacing();
LayoutDescriptionVertically(fDescription); LayoutDescriptionVertically(fDescription);
float left = fFile->Frame().left; float left = fFile->Frame().left;
float top = fDescription->Frame().bottom + kTextDistance; float top = fDescription->Frame().bottom + kSpacing;
// center "file" text field and "select" button vertically // center "file" text field and "select" button vertically
float selectTop = top; float selectTop = top;
@ -147,7 +147,7 @@ FileSelectionPage::_Layout()
fFile->MoveTo(left, fileTop); fFile->MoveTo(left, fileTop);
float width = fSelect->Frame().left - kFileButtonDistance - left; float width = fSelect->Frame().left - kSpacing - left;
fFile->ResizeTo(width, fileHeight); fFile->ResizeTo(width, fileHeight);
left = fSelect->Frame().left; left = fSelect->Frame().left;
@ -172,11 +172,7 @@ FileSelectionPage::_OpenFilePanel()
BMessenger messenger(this); BMessenger messenger(this);
fFilePanel = new BFilePanel(fMode, &messenger, directory, fFilePanel = new BFilePanel(fMode, &messenger, directory,
B_FILE_NODE, B_FILE_NODE, false, NULL, NULL, true);
false,
NULL,
NULL,
true);
if (fMode == B_SAVE_PANEL && file.Leaf() != NULL) if (fMode == B_SAVE_PANEL && file.Leaf() != NULL)
fFilePanel->SetSaveText(file.Leaf()); fFilePanel->SetSaveText(file.Leaf());
fFilePanel->Show(); fFilePanel->Show();

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -18,33 +18,36 @@ class BButton;
class BTextControl; class BTextControl;
class BTextView; class BTextView;
class FileSelectionPage : public WizardPageView
{ class FileSelectionPage : public WizardPageView {
public: public:
FileSelectionPage(BMessage* settings, BRect frame, const char* name, const char* description, FileSelectionPage(BMessage* settings,
file_panel_mode mode); BRect frame, const char* name,
virtual ~FileSelectionPage(); const char* description,
file_panel_mode mode);
virtual void FrameResized(float width, float height); virtual ~FileSelectionPage();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message); virtual void FrameResized(float width, float height);
virtual void AttachedToWindow();
virtual void PageCompleted(); virtual void MessageReceived(BMessage* message);
virtual void PageCompleted();
private: private:
void _BuildUI(const char* description);
void _Layout();
void _OpenFilePanel();
void _SetFileFromFilePanelMessage(BMessage* message);
void _FilePanelCanceled();
void _BuildUI(const char* description); private:
void _Layout(); file_panel_mode fMode;
void _OpenFilePanel(); BFilePanel* fFilePanel;
void _SetFileFromFilePanelMessage(BMessage* message);
void _FilePanelCanceled();
file_panel_mode fMode;
BFilePanel* fFilePanel;
BTextView* fDescription; BTextView* fDescription;
BTextControl* fFile; BTextControl* fFile;
BButton* fSelect; BButton* fSelect;
}; };
#endif // FILE_SELECTION_PAGE_H #endif // FILE_SELECTION_PAGE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,30 +9,18 @@
#include "LegacyBootDrive.h" #include "LegacyBootDrive.h"
#include <new>
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Drivers.h> #include <DataIO.h>
#include <DiskDevice.h> #include <DiskDevice.h>
#include <DiskDeviceRoster.h> #include <DiskDeviceRoster.h>
#include <DiskDeviceVisitor.h> #include <DiskDeviceVisitor.h>
#include <Locale.h> #include <File.h>
#include <Partition.h> #include <Partition.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
#include <errno.h>
#include <fcntl.h>
#include <memory>
#include <new>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ByteOrder.h>
#include <DataIO.h>
#include <File.h>
#include <String.h>
#include <UTF8.h> #include <UTF8.h>
#include "BootLoader.h" #include "BootLoader.h"
@ -44,29 +32,68 @@
#define GET_FIRST_BIOS_DRIVE 1 #define GET_FIRST_BIOS_DRIVE 1
class Buffer : public BMallocIO struct MasterBootRecord {
{ uint8 bootLoader[440];
public: uint8 diskSignature[4];
Buffer() : BMallocIO() {} uint8 reserved[2];
bool WriteInt8(int8 value); uint8 partition[64];
bool WriteInt16(int16 value); uint8 signature[2];
bool WriteInt32(int32 value);
bool WriteInt64(int64 value);
bool WriteString(const char* value);
bool Align(int16 alignment);
bool Fill(int16 size, int8 fillByte);
}; };
class LittleEndianMallocIO : public BMallocIO {
public:
bool WriteInt8(int8 value);
bool WriteInt16(int16 value);
bool WriteInt32(int32 value);
bool WriteInt64(int64 value);
bool WriteString(const char* value);
bool Align(int16 alignment);
bool Fill(int16 size, int8 fillByte);
};
class PartitionRecorder : public BDiskDeviceVisitor {
public:
PartitionRecorder(BMessage* settings,
int8 drive);
virtual bool Visit(BDiskDevice* device);
virtual bool Visit(BPartition* partition, int32 level);
bool HasPartitions() const;
off_t FirstOffset() const;
private:
bool _Record(BPartition* partition);
private:
BMessage* fSettings;
int8 fDrive;
int32 fIndex;
off_t fFirstOffset;
};
static const uint32 kBlockSize = 512;
static const uint32 kNumberOfBootLoaderBlocks = 4;
// The number of blocks required to store the
// MBR including the Haiku boot loader.
static const uint32 kMBRSignature = 0xAA55;
static const int32 kMaxBootMenuItemLength = 70;
bool bool
Buffer::WriteInt8(int8 value) LittleEndianMallocIO::WriteInt8(int8 value)
{ {
return Write(&value, sizeof(value)) == sizeof(value); return Write(&value, sizeof(value)) == sizeof(value);
} }
bool bool
Buffer::WriteInt16(int16 value) LittleEndianMallocIO::WriteInt16(int16 value)
{ {
return WriteInt8(value & 0xff) return WriteInt8(value & 0xff)
&& WriteInt8(value >> 8); && WriteInt8(value >> 8);
@ -74,7 +101,7 @@ Buffer::WriteInt16(int16 value)
bool bool
Buffer::WriteInt32(int32 value) LittleEndianMallocIO::WriteInt32(int32 value)
{ {
return WriteInt8(value & 0xff) return WriteInt8(value & 0xff)
&& WriteInt8(value >> 8) && WriteInt8(value >> 8)
@ -84,14 +111,14 @@ Buffer::WriteInt32(int32 value)
bool bool
Buffer::WriteInt64(int64 value) LittleEndianMallocIO::WriteInt64(int64 value)
{ {
return WriteInt32(value) && WriteInt32(value >> 32); return WriteInt32(value) && WriteInt32(value >> 32);
} }
bool bool
Buffer::WriteString(const char* value) LittleEndianMallocIO::WriteString(const char* value)
{ {
int len = strlen(value) + 1; int len = strlen(value) + 1;
return WriteInt8(len) return WriteInt8(len)
@ -100,7 +127,7 @@ Buffer::WriteString(const char* value)
bool bool
Buffer::Align(int16 alignment) LittleEndianMallocIO::Align(int16 alignment)
{ {
if ((Position() % alignment) == 0) if ((Position() % alignment) == 0)
return true; return true;
@ -109,7 +136,7 @@ Buffer::Align(int16 alignment)
bool bool
Buffer::Fill(int16 size, int8 fillByte) LittleEndianMallocIO::Fill(int16 size, int8 fillByte)
{ {
for (int i = 0; i < size; i ++) { for (int i = 0; i < size; i ++) {
if (!WriteInt8(fillByte)) if (!WriteInt8(fillByte))
@ -119,32 +146,15 @@ Buffer::Fill(int16 size, int8 fillByte)
} }
class PartitionRecorder : public BDiskDeviceVisitor // #pragma mark -
{
public:
PartitionRecorder(BMessage* settings, int8 drive);
virtual bool Visit(BDiskDevice* device);
virtual bool Visit(BPartition* partition, int32 level);
bool HasPartitions() const;
off_t FirstOffset() const;
private:
bool _Record(BPartition* partition);
BMessage* fSettings;
int8 fDrive;
int32 fIndex;
off_t fFirstOffset;
};
PartitionRecorder::PartitionRecorder(BMessage* settings, int8 drive) PartitionRecorder::PartitionRecorder(BMessage* settings, int8 drive)
: fSettings(settings) :
, fDrive(drive) fSettings(settings),
, fIndex(0) fDrive(drive),
, fFirstOffset(LONGLONG_MAX) fIndex(0),
fFirstOffset(LONGLONG_MAX)
{ {
} }
@ -225,6 +235,9 @@ PartitionRecorder::_Record(BPartition* partition)
} }
// #pragma mark -
LegacyBootDrive::LegacyBootDrive() LegacyBootDrive::LegacyBootDrive()
{ {
} }
@ -323,21 +336,22 @@ LegacyBootDrive::WriteBootMenu(BMessage *settings)
return B_BAD_VALUE; return B_BAD_VALUE;
} }
Buffer newBootLoader; LittleEndianMallocIO newBootLoader;
ssize_t size = sizeof(kBootLoader); ssize_t size = sizeof(kBootLoader);
if (newBootLoader.Write(kBootLoader, size) != size) { if (newBootLoader.Write(kBootLoader, size) != size) {
close(fd); close(fd);
return B_NO_MEMORY; return B_NO_MEMORY;
} }
MasterBootRecord* newMBR = (MasterBootRecord*)newBootLoader.BMallocIO::Buffer(); MasterBootRecord* newMBR = (MasterBootRecord*)newBootLoader.Buffer();
_CopyPartitionTable(newMBR, &oldMBR); _CopyPartitionTable(newMBR, &oldMBR);
int menuEntries = 0; int menuEntries = 0;
int defaultMenuEntry = 0; int defaultMenuEntry = 0;
BMessage partition; BMessage partition;
int32 index; int32 index;
for (index = 0; settings->FindMessage("partition", index, &partition) == B_OK; index ++) { for (index = 0; settings->FindMessage("partition", index,
&partition) == B_OK; index ++) {
bool show; bool show;
partition.FindBool("show", &show); partition.FindBool("show", &show);
if (!show) if (!show)
@ -351,8 +365,8 @@ LegacyBootDrive::WriteBootMenu(BMessage *settings)
newBootLoader.WriteInt16(defaultMenuEntry); newBootLoader.WriteInt16(defaultMenuEntry);
newBootLoader.WriteInt16(timeout); newBootLoader.WriteInt16(timeout);
for (index = 0; settings->FindMessage("partition", index,
for (index = 0; settings->FindMessage("partition", index, &partition) == B_OK; index ++) { &partition) == B_OK; index ++) {
bool show; bool show;
BString name; BString name;
BString path; BString path;
@ -381,7 +395,7 @@ LegacyBootDrive::WriteBootMenu(BMessage *settings)
} }
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
const uint8* buffer = (uint8*)newBootLoader.BMallocIO::Buffer(); const uint8* buffer = (const uint8*)newBootLoader.Buffer();
status_t status = _WriteBlocks(fd, buffer, newBootLoader.Position()); status_t status = _WriteBlocks(fd, buffer, newBootLoader.Position());
close(fd); close(fd);
return status; return status;
@ -593,14 +607,14 @@ LegacyBootDrive::_CopyPartitionTable(MasterBootRecord* destination,
const MasterBootRecord* source) const MasterBootRecord* source)
{ {
memcpy(destination->diskSignature, source->diskSignature, memcpy(destination->diskSignature, source->diskSignature,
sizeof(source->diskSignature) + sizeof(source->reserved) + sizeof(source->diskSignature) + sizeof(source->reserved)
sizeof(source->partition)); + sizeof(source->partition));
} }
bool bool
LegacyBootDrive::_IsValid(const MasterBootRecord* mbr) LegacyBootDrive::_IsValid(const MasterBootRecord* mbr)
{ {
return mbr->signature[0] == (kMBRSignature & 0xff) && return mbr->signature[0] == (kMBRSignature & 0xff)
mbr->signature[1] == (kMBRSignature >> 8); && mbr->signature[1] == (kMBRSignature >> 8);
} }

View File

@ -1,55 +1,49 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
#ifndef LEGACY_BOOT_DRIVE_H #ifndef LEGACY_BOOT_DRIVE_H
#define LEGACY_BOOT_DRIVE_H #define LEGACY_BOOT_DRIVE_H
#include "BootDrive.h" #include "BootDrive.h"
#include <SupportDefs.h> #include <SupportDefs.h>
const uint32 kBlockSize = 512;
// The number of blocks required to store the
// MBR including the Haiku boot loader.
const uint32 kNumberOfBootLoaderBlocks = 4;
const uint32 kMBRSignature = 0xAA55; struct MasterBootRecord;
const int32 kMaxBootMenuItemLength = 70;
typedef struct {
uint8 bootLoader[440];
uint8 diskSignature[4];
uint8 reserved[2];
uint8 partition[64];
uint8 signature[2];
} MasterBootRecord;
class LegacyBootDrive : public BootDrive class LegacyBootDrive : public BootDrive {
{
public: public:
LegacyBootDrive(); LegacyBootDrive();
~LegacyBootDrive(); virtual ~LegacyBootDrive();
bool IsBootMenuInstalled(BMessage* settings); virtual bool IsBootMenuInstalled(BMessage* settings);
status_t ReadPartitions(BMessage* settings); virtual status_t ReadPartitions(BMessage* settings);
status_t WriteBootMenu(BMessage* settings); virtual status_t WriteBootMenu(BMessage* settings);
status_t SaveMasterBootRecord(BMessage* settings, BFile* file); virtual status_t SaveMasterBootRecord(BMessage* settings,
status_t RestoreMasterBootRecord(BMessage* settings, BFile* file); BFile* file);
status_t GetDisplayText(const char* text, BString& displayText); virtual status_t RestoreMasterBootRecord(BMessage* settings,
BFile* file);
virtual status_t GetDisplayText(const char* text,
BString& displayText);
private: private:
bool _ConvertToBIOSText(const char* text, BString& biosText); bool _ConvertToBIOSText(const char* text,
bool _GetBiosDrive(const char* device, int8* drive); BString& biosText);
status_t _ReadBlocks(int fd, uint8* buffer, size_t size); bool _GetBiosDrive(const char* device, int8* drive);
status_t _WriteBlocks(int fd, const uint8* buffer, size_t size); status_t _ReadBlocks(int fd, uint8* buffer, size_t size);
void _CopyPartitionTable(MasterBootRecord* destination, status_t _WriteBlocks(int fd, const uint8* buffer,
const MasterBootRecord* source); size_t size);
bool _IsValid(const MasterBootRecord* mbr); void _CopyPartitionTable(
MasterBootRecord* destination,
const MasterBootRecord* source);
bool _IsValid(const MasterBootRecord* mbr);
}; };
#endif // LEGACY_BOOT_DRIVE_H #endif // LEGACY_BOOT_DRIVE_H

View File

@ -1,8 +1,10 @@
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h>
int main(int argc, char* argv[])
int
main(int argc, char* argv[])
{ {
const char* application = argv[0]; const char* application = argv[0];
if (argc != 3) { if (argc != 3) {
@ -11,13 +13,14 @@ int main(int argc, char* argv[])
} }
const char* variableName = argv[1]; const char* variableName = argv[1];
const char* fileName = argv[2]; const char* fileName = argv[2];
int fd = open(fileName, 0); int fd = open(fileName, 0);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "%s: Error opening file '%s'!\n", application, fileName); fprintf(stderr, "%s: Error opening file '%s'!\n", application,
fileName);
return 1; return 1;
} }
const int kSize = 1024; const int kSize = 1024;
unsigned char buffer[kSize]; unsigned char buffer[kSize];
int size = read(fd, buffer, kSize); int size = read(fd, buffer, kSize);
@ -43,6 +46,6 @@ int main(int argc, char* argv[])
size = read(fd, buffer, kSize); size = read(fd, buffer, kSize);
} }
printf("\n};\n"); printf("\n};\n");
close(fd); close(fd);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -10,20 +10,18 @@
#include "PartitionsPage.h" #include "PartitionsPage.h"
#include <stdio.h>
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <Locale.h> #include <ControlLook.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h> #include <StringView.h>
#include <TextControl.h> #include <TextControl.h>
#include <TextView.h> #include <TextView.h>
#include <stdio.h>
#include <string.h>
#include <String.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "PartitionsPage" #define B_TRANSLATE_CONTEXT "PartitionsPage"
@ -33,8 +31,10 @@ const uint32 kMessageShow = 'show';
const uint32 kMessageName = 'name'; const uint32 kMessageName = 'name';
PartitionsPage::PartitionsPage(BMessage* settings, BRect frame, const char* name) PartitionsPage::PartitionsPage(BMessage* settings, BRect frame,
: WizardPageView(settings, frame, name, B_FOLLOW_ALL, const char* name)
:
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{ {
_BuildUI(); _BuildUI();
@ -91,21 +91,19 @@ PartitionsPage::FrameResized(float width, float height)
} }
static const float kTextDistance = 10;
void void
PartitionsPage::_BuildUI() PartitionsPage::_BuildUI()
{ {
const float kTextDistance = be_control_look->DefaultItemSpacing();
BRect rect(Bounds()); BRect rect(Bounds());
BString text; BString text;
text << text << B_TRANSLATE_COMMENT("Partitions", "Title") << "\n\n"
B_TRANSLATE_COMMENT("Partitions", "Title") << "\n\n" << << B_TRANSLATE("The following partitions were detected. Please "
B_TRANSLATE("The following partitions were detected. Please " "check the box next to the partitions to be included "
"check the box next to the partitions to be included " "in the boot menu. You can also set the names of the "
"in the boot menu. You can also set the names of the " "partitions as you would like them to appear in the "
"partitions as you would like them to appear in the " "boot menu.");
"boot menu.");
fDescription = CreateDescription(rect, "description", text); fDescription = CreateDescription(rect, "description", text);
MakeHeading(fDescription); MakeHeading(fDescription);
AddChild(fDescription); AddChild(fDescription);
@ -116,13 +114,10 @@ PartitionsPage::_BuildUI()
rect.right -= B_V_SCROLL_BAR_WIDTH; rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT + 3; rect.bottom -= B_H_SCROLL_BAR_HEIGHT + 3;
fPartitions = new BView(rect, "partitions", B_FOLLOW_ALL, fPartitions = new BView(rect, "partitions", B_FOLLOW_ALL, B_WILL_DRAW);
B_WILL_DRAW);
fPartitionsScrollView = new BScrollView("scrollView", fPartitions, fPartitionsScrollView = new BScrollView("scrollView", fPartitions,
B_FOLLOW_ALL, B_FOLLOW_ALL, 0, true, true);
0,
true, true);
fPartitionsScrollView->SetViewColor(ViewColor()); fPartitionsScrollView->SetViewColor(ViewColor());
AddChild(fPartitionsScrollView); AddChild(fPartitionsScrollView);
@ -137,6 +132,7 @@ PartitionsPage::_Layout()
{ {
LayoutDescriptionVertically(fDescription); LayoutDescriptionVertically(fDescription);
const float kTextDistance = be_control_look->DefaultItemSpacing();
float left = fPartitionsScrollView->Frame().left; float left = fPartitionsScrollView->Frame().left;
float top = fDescription->Frame().bottom + kTextDistance; float top = fDescription->Frame().bottom + kTextDistance;
fPartitionsScrollView->MoveTo(left, top); fPartitionsScrollView->MoveTo(left, top);
@ -173,10 +169,6 @@ PartitionsPage::_Layout()
} }
const rgb_color kOddRowColor = {224, 255, 224};
const rgb_color kEvenRowColor = {224, 224, 255};
void void
PartitionsPage::_FillPartitionsView(BView* view) PartitionsPage::_FillPartitionsView(BView* view)
{ {
@ -215,7 +207,8 @@ PartitionsPage::_FillPartitionsView(BView* view)
frame.right = frame.left + 65000; frame.right = frame.left + 65000;
BMessage message; BMessage message;
for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK; i ++, rowNumber ++) { for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
i++, rowNumber++) {
// get partition data // get partition data
bool show; bool show;
BString name; BString name;
@ -230,7 +223,6 @@ PartitionsPage::_FillPartitionsView(BView* view)
// create row for partition data // create row for partition data
BView* row = new BView(frame, "row", B_FOLLOW_TOP | B_FOLLOW_LEFT, 0); BView* row = new BView(frame, "row", B_FOLLOW_TOP | B_FOLLOW_LEFT, 0);
row->SetViewColor(((rowNumber % 2) == 0) ? kEvenRowColor : kOddRowColor);
view->AddChild(row); view->AddChild(row);
frame.OffsetBy(0, height + 1); frame.OffsetBy(0, height + 1);
@ -252,8 +244,8 @@ PartitionsPage::_FillPartitionsView(BView* view)
// name // name
rect.right = rect.left + nameWidth; rect.right = rect.left + nameWidth;
BTextControl* nameControl = new BTextControl(rect, "name", "", name.String(), BTextControl* nameControl = new BTextControl(rect, "name", "",
_CreateControlMessage(kMessageName, i)); name.String(), _CreateControlMessage(kMessageName, i));
nameControl->SetDivider(0); nameControl->SetDivider(0);
row->AddChild(nameControl); row->AddChild(nameControl);
rect.OffsetBy(nameWidth + kDistance, 0); rect.OffsetBy(nameWidth + kDistance, 0);
@ -268,7 +260,8 @@ PartitionsPage::_FillPartitionsView(BView* view)
BString sizeText; BString sizeText;
_CreateSizeText(size, &sizeText); _CreateSizeText(size, &sizeText);
rect.right = rect.left + sizeWidth; rect.right = rect.left + sizeWidth;
BStringView* sizeView = new BStringView(rect, "type", sizeText.String()); BStringView* sizeView = new BStringView(rect, "type",
sizeText.String());
sizeView->SetAlignment(B_ALIGN_RIGHT); sizeView->SetAlignment(B_ALIGN_RIGHT);
row->AddChild(sizeView); row->AddChild(sizeView);
rect.OffsetBy(sizeWidth + kDistance, 0); rect.OffsetBy(sizeWidth + kDistance, 0);
@ -279,7 +272,6 @@ PartitionsPage::_FillPartitionsView(BView* view)
row->AddChild(pathView); row->AddChild(pathView);
} }
fPartitionsWidth = totalWidth; fPartitionsWidth = totalWidth;
fPartitionsHeight = frame.top; fPartitionsHeight = frame.top;
} }
@ -287,7 +279,7 @@ PartitionsPage::_FillPartitionsView(BView* view)
void void
PartitionsPage::_ComputeColumnWidths(int32& showWidth, int32& nameWidth, PartitionsPage::_ComputeColumnWidths(int32& showWidth, int32& nameWidth,
int32& typeWidth, int32& sizeWidth, int32& pathWidth) int32& typeWidth, int32& sizeWidth, int32& pathWidth)
{ {
BCheckBox checkBox(BRect(0, 0, 100, 100), "show", "", new BMessage()); BCheckBox checkBox(BRect(0, 0, 100, 100), "show", "", new BMessage());
checkBox.ResizeToPreferred(); checkBox.ResizeToPreferred();
@ -298,7 +290,8 @@ PartitionsPage::_ComputeColumnWidths(int32& showWidth, int32& nameWidth,
const int32 kStringViewInsets = 2; const int32 kStringViewInsets = 2;
BMessage message; BMessage message;
for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK; i ++) { for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
i++) {
// get partition data // get partition data
BString type; BString type;
BString path; BString path;
@ -309,18 +302,18 @@ PartitionsPage::_ComputeColumnWidths(int32& showWidth, int32& nameWidth,
BString sizeText; BString sizeText;
_CreateSizeText(size, &sizeText); _CreateSizeText(size, &sizeText);
int32 width = (int32)ceil(be_plain_font->StringWidth(type.String())) + int32 width = (int32)ceil(be_plain_font->StringWidth(type.String()))
kStringViewInsets; + kStringViewInsets;
if (typeWidth < width) if (typeWidth < width)
typeWidth = width; typeWidth = width;
width = (int32)ceil(be_plain_font->StringWidth(path.String())) + width = (int32)ceil(be_plain_font->StringWidth(path.String()))
kStringViewInsets; + kStringViewInsets;
if (pathWidth < width) if (pathWidth < width)
pathWidth = width; pathWidth = width;
width = (int32)ceil(be_plain_font->StringWidth(sizeText.String())) + width = (int32)ceil(be_plain_font->StringWidth(sizeText.String()))
kStringViewInsets; + kStringViewInsets;
if (sizeWidth < width) if (sizeWidth < width)
sizeWidth = width; sizeWidth = width;
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -15,31 +15,35 @@
class BTextView; class BTextView;
class BScrollView; class BScrollView;
class PartitionsPage : public WizardPageView
{ class PartitionsPage : public WizardPageView {
public: public:
PartitionsPage(BMessage* settings, BRect frame, const char* name); PartitionsPage(BMessage* settings, BRect frame,
virtual ~PartitionsPage(); const char* name);
virtual ~PartitionsPage();
virtual void PageCompleted();
virtual void PageCompleted();
virtual void FrameResized(float width, float height);
virtual void FrameResized(float width, float height);
private: private:
void _BuildUI();
void _Layout();
void _FillPartitionsView(BView* view);
void _CreateSizeText(int64 size, BString* text);
BMessage* _CreateControlMessage(uint32 what,
int32 partitionIndex);
void _ComputeColumnWidths(int32& showWidth,
int32& nameWidth, int32& typeWidth,
int32& sizeWidth, int32& pathWidth);
void _BuildUI(); private:
void _Layout(); BTextView* fDescription;
void _FillPartitionsView(BView* view); BView* fPartitions;
void _CreateSizeText(int64 size, BString* text); BScrollView* fPartitionsScrollView;
BMessage* _CreateControlMessage(uint32 what, int32 partitionIndex); float fPartitionsWidth;
void _ComputeColumnWidths(int32& showWidth, int32& nameWidth, int32& typeWidth, float fPartitionsHeight;
int32& sizeWidth, int32& pathWidth);
BTextView* fDescription;
BView* fPartitions;
BScrollView* fPartitionsScrollView;
float fPartitionsWidth;
float fPartitionsHeight;
}; };
#endif // PARTITONS_PAGE_H #endif // PARTITONS_PAGE_H

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -9,20 +9,6 @@
#include "TestBootDrive.h" #include "TestBootDrive.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ByteOrder.h>
#include <DataIO.h>
#include <File.h>
#include <String.h>
#include "BootLoader.h"
TestBootDrive::TestBootDrive() TestBootDrive::TestBootDrive()
{ {
@ -45,20 +31,20 @@ status_t
TestBootDrive::ReadPartitions(BMessage *settings) TestBootDrive::ReadPartitions(BMessage *settings)
{ {
settings->AddString("disk", "bootcylinder"); settings->AddString("disk", "bootcylinder");
BMessage partition; BMessage partition;
partition.AddBool("show", true); partition.AddBool("show", true);
partition.AddString("name", "Haiku"); partition.AddString("name", "TEST Haiku");
partition.AddString("type", "bfs"); partition.AddString("type", "bfs");
partition.AddString("path", "/dev/disk/ide/ata/0/master/0/0_0"); partition.AddString("path", "/dev/disk/ide/ata/0/master/0/0_0");
partition.AddInt64("size", 3 * (int64)1024 * 1024 * 1024); partition.AddInt64("size", 3 * (int64)1024 * 1024 * 1024);
settings->AddMessage("partition", &partition); settings->AddMessage("partition", &partition);
partition.MakeEmpty();
partition.MakeEmpty();
partition.AddBool("show", true); partition.AddBool("show", true);
partition.AddString("name", "no name"); partition.AddString("name", "TEST no name");
partition.AddString("type", "dos"); partition.AddString("type", "dos");
partition.AddString("path", "/dev/disk/ide/ata/0/slave/0/0_0"); partition.AddString("path", "/dev/disk/ide/ata/0/slave/0/0_0");
partition.AddInt64("size", 10 * (int64)1024 * 1024 * 1024); partition.AddInt64("size", 10 * (int64)1024 * 1024 * 1024);
@ -66,12 +52,12 @@ TestBootDrive::ReadPartitions(BMessage *settings)
partition.MakeEmpty(); partition.MakeEmpty();
partition.AddBool("show", true); partition.AddBool("show", true);
partition.AddString("name", "Data"); partition.AddString("name", "TEST Data");
partition.AddString("type", "unknown"); partition.AddString("type", "unknown");
partition.AddString("path", "/dev/disk/ide/ata/0/slave/0/0_1"); partition.AddString("path", "/dev/disk/ide/ata/0/slave/0/0_1");
partition.AddInt64("size", 250 * (int64)1024 * 1024 * 1024); partition.AddInt64("size", 250 * (int64)1024 * 1024 * 1024);
settings->AddMessage("partition", &partition); settings->AddMessage("partition", &partition);
return B_OK; return B_OK;
} }
@ -81,21 +67,22 @@ TestBootDrive::WriteBootMenu(BMessage *settings)
{ {
printf("WriteBootMenu:\n"); printf("WriteBootMenu:\n");
settings->PrintToStream(); settings->PrintToStream();
BMessage partition; BMessage partition;
int32 index = 0; int32 index = 0;
for (; settings->FindMessage("partition", index, &partition) == B_OK; index ++) { for (; settings->FindMessage("partition", index, &partition) == B_OK;
index++) {
printf("Partition %d:\n", (int)index); printf("Partition %d:\n", (int)index);
partition.PrintToStream(); partition.PrintToStream();
} }
return B_OK; return B_OK;
} }
status_t status_t
TestBootDrive::SaveMasterBootRecord(BMessage* settings, BFile* file) TestBootDrive::SaveMasterBootRecord(BMessage* settings, BFile* file)
{ {
return B_OK; return B_OK;
} }
@ -112,5 +99,3 @@ TestBootDrive::GetDisplayText(const char* text, BString& displayText)
{ {
displayText = text; displayText = text;
} }

View File

@ -1,27 +1,32 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
#ifndef TEST_BOOT_DRIVE_H #ifndef TEST_BOOT_DRIVE_H
#define TEST_BOOT_DRIVE_H #define TEST_BOOT_DRIVE_H
#include "BootDrive.h" #include "BootDrive.h"
class TestBootDrive : public BootDrive
{
public:
TestBootDrive();
~TestBootDrive();
bool IsBootMenuInstalled(BMessage* settings); class TestBootDrive : public BootDrive {
status_t ReadPartitions(BMessage* settings); public:
status_t WriteBootMenu(BMessage* settings); TestBootDrive();
status_t SaveMasterBootRecord(BMessage* settings, BFile* file); virtual ~TestBootDrive();
status_t RestoreMasterBootRecord(BMessage* settings, BFile* file);
status_t GetDisplayText(const char* text, BString& displayText); virtual bool IsBootMenuInstalled(BMessage* settings);
virtual status_t ReadPartitions(BMessage* settings);
virtual status_t WriteBootMenu(BMessage* settings);
virtual status_t SaveMasterBootRecord(BMessage* settings,
BFile* file);
virtual status_t RestoreMasterBootRecord(BMessage* settings,
BFile* file);
virtual status_t GetDisplayText(const char* text,
BString& displayText);
}; };
#endif // TEST_BOOT_DRIVE_H #endif // TEST_BOOT_DRIVE_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,21 +9,23 @@
#include "UninstallPage.h" #include "UninstallPage.h"
#include <string.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h>
#include <RadioButton.h> #include <RadioButton.h>
#include <TextView.h> #include <TextView.h>
#include <string.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "UninstallPage" #define B_TRANSLATE_CONTEXT "UninstallPage"
static const float kTextDistance = 10;
UninstallPage::UninstallPage(BMessage* settings, BRect frame, const char* name) UninstallPage::UninstallPage(BMessage* settings, BRect frame, const char* name)
: WizardPageView(settings, frame, name, B_FOLLOW_ALL, :
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE) B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
{ {
_BuildUI(); _BuildUI();
@ -43,19 +45,16 @@ UninstallPage::FrameResized(float width, float height)
} }
static const float kTextDistance = 10;
void void
UninstallPage::_BuildUI() UninstallPage::_BuildUI()
{ {
BRect rect(Bounds()); BRect rect(Bounds());
BString text; BString text;
text << text << B_TRANSLATE_COMMENT("Uninstall Boot Manager", "Title") << "\n\n"
B_TRANSLATE_COMMENT("Uninstall Boot Manager", "Title") << "\n\n" << << B_TRANSLATE("Please locate the Master Boot Record (MBR) save file "
B_TRANSLATE("Please locate the Master Boot Record (MBR) save file to " "to restore from. This is the file that was created when the "
"restore from. This is the file that was created when the " "boot manager was first installed.");
"boot manager was first installed.");
fDescription = CreateDescription(rect, "description", text); fDescription = CreateDescription(rect, "description", text);
MakeHeading(fDescription); MakeHeading(fDescription);
@ -70,4 +69,3 @@ UninstallPage::_Layout()
{ {
LayoutDescriptionVertically(fDescription); LayoutDescriptionVertically(fDescription);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -14,20 +14,22 @@
class BTextView; class BTextView;
class UninstallPage : public WizardPageView
{ class UninstallPage : public WizardPageView {
public: public:
UninstallPage(BMessage* settings, BRect frame, const char* name); UninstallPage(BMessage* settings, BRect frame,
virtual ~UninstallPage(); const char* name);
virtual ~UninstallPage();
virtual void FrameResized(float width, float height);
virtual void FrameResized(float width, float height);
private: private:
void _BuildUI();
void _Layout();
void _BuildUI(); private:
void _Layout(); BTextView* fDescription;
BTextView* fDescription;
}; };
#endif // UNINSTALL_PAGE_H #endif // UNINSTALL_PAGE_H

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -12,21 +12,23 @@
#include "WizardView.h" #include "WizardView.h"
#include "WizardPageView.h" #include "WizardPageView.h"
void void
WizardController::StateStack::MakeEmpty() WizardController::StateStack::MakeEmpty()
{ {
StateStack* stack = this; StateStack* stack = this;
StateStack* next; StateStack* next;
do { do {
next = stack->Next(); next = stack->Next();
delete stack; delete stack;
stack = next; stack = next;
} while (next != NULL); } while (next != NULL);
} }
WizardController::WizardController() WizardController::WizardController()
: fStack(NULL) :
fStack(NULL)
{ {
} }
@ -53,14 +55,14 @@ void
WizardController::Next(WizardView* wizard) WizardController::Next(WizardView* wizard)
{ {
wizard->PageCompleted(); wizard->PageCompleted();
if (fStack == NULL) if (fStack == NULL)
return; return;
int state = NextState(fStack->State()); int state = NextState(fStack->State());
if (state < 0) if (state < 0)
return; return;
_PushState(state); _PushState(state);
_ShowPage(wizard); _ShowPage(wizard);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -11,56 +11,57 @@
#include <SupportDefs.h> #include <SupportDefs.h>
class WizardView; class WizardView;
class WizardPageView; class WizardPageView;
class WizardController class WizardController {
{
public: public:
WizardController(); WizardController();
virtual ~WizardController(); virtual ~WizardController();
virtual void Initialize(WizardView* wizard);
virtual void Next(WizardView* wizard);
virtual void Previous(WizardView* wizard);
virtual void Initialize(WizardView* wizard);
virtual void Next(WizardView* wizard);
virtual void Previous(WizardView* wizard);
protected: protected:
virtual int32 InitialState() = 0; virtual int32 InitialState() = 0;
virtual int32 NextState(int32 state) = 0; virtual int32 NextState(int32 state) = 0;
virtual WizardPageView* CreatePage(int32 state, WizardView* wizard) = 0; virtual WizardPageView* CreatePage(int32 state, WizardView* wizard) = 0;
private: private:
class StateStack { class StateStack {
public: public:
StateStack(int32 state, StateStack* next) StateStack(int32 state, StateStack* next)
: fState(state) :
, fNext(next) fState(state),
{ fNext(next)
} {
}
int32 State() {
return fState; int32 State()
} {
return fState;
StateStack* Next() { }
return fNext;
} StateStack* Next()
{
void MakeEmpty(); return fNext;
}
private:
int32 fState; void MakeEmpty();
StateStack* fNext;
private:
int32 fState;
StateStack* fNext;
}; };
void _PushState(int32 state); void _PushState(int32 state);
void _ShowPage(WizardView* wizard); void _ShowPage(WizardView* wizard);
StateStack* fStack; private:
StateStack* fStack;
}; };

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -9,17 +9,17 @@
#include "WizardPageView.h" #include "WizardPageView.h"
#include <TextView.h>
#include <math.h> #include <math.h>
#include <string.h> #include <string.h>
#include <TextView.h>
WizardPageView::WizardPageView(BMessage* settings, BRect frame, const char* name,
uint32 resizingMode, uint32 flags) WizardPageView::WizardPageView(BMessage* settings, BRect frame,
: BView(frame, name, resizingMode, flags) const char* name, uint32 resizingMode, uint32 flags)
, fSettings(settings) :
BView(frame, name, resizingMode, flags),
fSettings(settings)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
} }
@ -40,7 +40,7 @@ BTextView*
WizardPageView::CreateDescription(BRect frame, const char* name, WizardPageView::CreateDescription(BRect frame, const char* name,
const char* description) const char* description)
{ {
BTextView* view = new BTextView(frame, "text", BTextView* view = new BTextView(frame, "text",
frame.OffsetToCopy(0, 0), frame.OffsetToCopy(0, 0),
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS); B_WILL_DRAW | B_PULSE_NEEDED | B_FRAME_EVENTS);
@ -72,10 +72,10 @@ void
WizardPageView::LayoutDescriptionVertically(BTextView* view) WizardPageView::LayoutDescriptionVertically(BTextView* view)
{ {
view->SetTextRect(view->Bounds()); view->SetTextRect(view->Bounds());
float height = view->TextHeight(0, 32000); float height = view->TextHeight(0, 32000);
float width = view->Bounds().Width(); float width = view->Bounds().Width();
view->ResizeTo(width, height); view->ResizeTo(width, height);
view->SetTextRect(view->Bounds()); view->SetTextRect(view->Bounds());
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -15,26 +15,28 @@
#include <View.h> #include <View.h>
class WizardPageView : public BView class WizardPageView : public BView {
{
public: public:
WizardPageView(BMessage* settings, BRect frame, const char* name, WizardPageView(BMessage* settings, BRect frame,
uint32 resizingMode = B_FOLLOW_ALL, uint32 flags = B_WILL_DRAW); const char* name,
virtual ~WizardPageView(); uint32 resizingMode = B_FOLLOW_ALL,
uint32 flags = B_WILL_DRAW);
virtual void PageCompleted(); virtual ~WizardPageView();
virtual BTextView* CreateDescription(BRect frame, const char* name, virtual void PageCompleted();
const char* description);
virtual void MakeHeading(BTextView* view);
virtual void LayoutDescriptionVertically(BTextView* view);
protected: virtual BTextView* CreateDescription(BRect frame, const char* name,
BMessage* fSettings; const char* description);
virtual void MakeHeading(BTextView* view);
virtual void LayoutDescriptionVertically(BTextView* view);
private: private:
void _BuildUI(); void _BuildUI();
protected:
BMessage* fSettings;
}; };
#endif // WIZARD_PAGE_VIEW_H #endif // WIZARD_PAGE_VIEW_H

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@ -9,11 +9,10 @@
#include "WizardView.h" #include "WizardView.h"
#include "WizardPageView.h"
#include <Box.h> #include <Box.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h>
#include "WizardPageView.h"
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
@ -27,11 +26,12 @@ static const float kBorderHeight = 5;
WizardView::WizardView(BRect frame, const char* name, uint32 resizingMode) WizardView::WizardView(BRect frame, const char* name, uint32 resizingMode)
: BView(frame, name, resizingMode, 0) :
, fSeparator(NULL) BView(frame, name, resizingMode, 0),
, fPrevious(NULL) fSeparator(NULL),
, fNext(NULL) fPrevious(NULL),
, fPage(NULL) fNext(NULL),
fPage(NULL)
{ {
_BuildUI(); _BuildUI();
SetPreviousButtonHidden(true); SetPreviousButtonHidden(true);
@ -164,7 +164,9 @@ WizardView::_BuildUI()
float buttonTop = height - 1 - buttonHeight - kBorderHeight; float buttonTop = height - 1 - buttonHeight - kBorderHeight;
fPrevious->MoveTo(kBorderWidth, buttonTop); fPrevious->MoveTo(kBorderWidth, buttonTop);
fSeparator->MoveTo(kBorderWidth, buttonTop - kSeparatorDistance - kSeparatorHeight); fSeparator->MoveTo(kBorderWidth,
buttonTop - kSeparatorDistance - kSeparatorHeight);
fNext->MoveTo(width - fNext->Bounds().Width() - kBorderWidth - 1, buttonTop); fNext->MoveTo(width - fNext->Bounds().Width() - kBorderWidth - 1,
buttonTop);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2008, Haiku, Inc. All rights reserved. * Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
* Michael Pfeiffer <laplace@users.sourceforge.net> * Michael Pfeiffer <laplace@users.sourceforge.net>
*/ */
@ -22,32 +22,34 @@ const uint32 kMessageNext = 'next';
const uint32 kMessagePrevious = 'prev'; const uint32 kMessagePrevious = 'prev';
class WizardView : public BView class WizardView : public BView {
{
public: public:
WizardView(BRect frame, const char* name, uint32 resizingMode); WizardView(BRect frame, const char* name,
virtual ~WizardView(); uint32 resizingMode);
virtual ~WizardView();
virtual BRect PageFrame(); virtual BRect PageFrame();
virtual void SetPage(WizardPageView* page); virtual void SetPage(WizardPageView* page);
virtual void PageCompleted();
virtual void SetPreviousButtonEnabled(bool enabled); virtual void PageCompleted();
virtual void SetNextButtonEnabled(bool enabled);
virtual void SetPreviousButtonLabel(const char* text); virtual void SetPreviousButtonEnabled(bool enabled);
virtual void SetNextButtonLabel(const char* text); virtual void SetNextButtonEnabled(bool enabled);
virtual void SetPreviousButtonHidden(bool hide); virtual void SetPreviousButtonLabel(const char* text);
virtual void SetNextButtonLabel(const char* text);
virtual void SetPreviousButtonHidden(bool hide);
private: private:
void _BuildUI(); void _BuildUI();
BBox* fSeparator; private:
BButton* fPrevious; BBox* fSeparator;
BButton* fNext; BButton* fPrevious;
BButton* fNext;
WizardPageView* fPage;
WizardPageView* fPage;
}; };
#endif // WIZARD_VIEW_H #endif // WIZARD_VIEW_H