From 5675f44e8462b10aa718b2bcceb72f9ac60eca87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 5 Jan 2011 23:36:35 +0000 Subject: [PATCH] * Work in progress of being able to choose the drive to install the menu to. Note, the BootManager might not work right now, anymore. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40130 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bootmanager/BootDrive.h | 49 +-- .../bootmanager/BootManagerController.cpp | 43 +-- src/apps/bootmanager/BootManagerController.h | 7 +- src/apps/bootmanager/BootMenu.h | 49 +++ src/apps/bootmanager/DrivesPage.cpp | 306 ++++++++++++++++++ src/apps/bootmanager/DrivesPage.h | 42 +++ src/apps/bootmanager/EntryPage.cpp | 90 ------ src/apps/bootmanager/EntryPage.h | 37 --- src/apps/bootmanager/Jamfile | 4 +- ...LegacyBootDrive.cpp => LegacyBootMenu.cpp} | 66 ++-- .../{LegacyBootDrive.h => LegacyBootMenu.h} | 16 +- src/apps/bootmanager/WizardController.cpp | 10 + src/apps/bootmanager/WizardController.h | 2 + src/apps/bootmanager/WizardView.cpp | 7 +- 14 files changed, 492 insertions(+), 236 deletions(-) create mode 100644 src/apps/bootmanager/BootMenu.h create mode 100644 src/apps/bootmanager/DrivesPage.cpp create mode 100644 src/apps/bootmanager/DrivesPage.h delete mode 100644 src/apps/bootmanager/EntryPage.cpp delete mode 100644 src/apps/bootmanager/EntryPage.h rename src/apps/bootmanager/{LegacyBootDrive.cpp => LegacyBootMenu.cpp} (87%) rename src/apps/bootmanager/{LegacyBootDrive.h => LegacyBootMenu.h} (79%) diff --git a/src/apps/bootmanager/BootDrive.h b/src/apps/bootmanager/BootDrive.h index 22b3993147..0f72b778e0 100644 --- a/src/apps/bootmanager/BootDrive.h +++ b/src/apps/bootmanager/BootDrive.h @@ -1,54 +1,29 @@ /* - * Copyright 2008-2010, Haiku, Inc. All rights reserved. + * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. - * - * Authors: - * Michael Pfeiffer */ #ifndef BOOT_DRIVE_H #define BOOT_DRIVE_H #include -#include - - -/* Setting BMessage Format: - - "disk" String (path to boot disk) - - "partition" array of BMessage: - "show" bool (flag if entry should be added to boot menu) - "name" String (the name as shown in boot menu) - "type" String (short name of file system: bfs, dos) - "path" String (path to partition in /dev/...) - "size" long (size of partition in bytes) -*/ - - -enum { - // Not enough space free before first partition for boot loader - kErrorBootSectorTooSmall = B_ERRORS_END + 1, -}; class BootDrive { public: - BootDrive() {} - virtual ~BootDrive() {} + BootDrive(); + virtual ~BootDrive(); - 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; + bool IsBootMenuInstalled() const; + bool CanBootMenuBeInstalled() const; - // Converts the specified text into a text as it will be shown - // in the boot menu. - virtual status_t GetDisplayText(const char* text, - BString& displayText) = 0; + bool IsBootDrive() const; + + status_t GetStream(BPositionIO* stream); + status_t GetBIOSDrive(uint8* drive); + +private: + BPath fPath; }; diff --git a/src/apps/bootmanager/BootManagerController.cpp b/src/apps/bootmanager/BootManagerController.cpp index f49abd3c5e..412b0b834d 100644 --- a/src/apps/bootmanager/BootManagerController.cpp +++ b/src/apps/bootmanager/BootManagerController.cpp @@ -20,9 +20,9 @@ #include "DefaultPartitionPage.h" #include "DescriptionPage.h" -#include "EntryPage.h" +#include "DrivesPage.h" #include "FileSelectionPage.h" -#include "LegacyBootDrive.h" +#include "LegacyBootMenu.h" #include "PartitionsPage.h" #include "WizardView.h" @@ -41,9 +41,9 @@ BootManagerController::BootManagerController() { #if USE_TEST_BOOT_DRIVE - fBootDrive = new TestBootDrive(); + fBootMenu = new TestBootDrive(); #else - fBootDrive = new LegacyBootDrive(); + fBootMenu = new LegacyBootMenu(); #endif // set defaults @@ -65,7 +65,7 @@ BootManagerController::BootManagerController() fSettings.AddString("file", ""); } - fReadPartitionsStatus = fBootDrive->ReadPartitions(&fSettings); + fReadPartitionsStatus = fBootMenu->ReadPartitions(&fSettings); } @@ -74,6 +74,18 @@ BootManagerController::~BootManagerController() } +void +BootManagerController::Previous(WizardView* wizard) +{ + if (CurrentState() != kStateEntry) + WizardController::Previous(wizard); + else { + WizardController::Next(wizard); + fSettings.ReplaceBool("install", false); + } +} + + int32 BootManagerController::InitialState() { @@ -89,10 +101,8 @@ BootManagerController::NextState(int32 state) switch (state) { case kStateEntry: { - bool install; - fSettings.FindBool("install", &install); - if (install) { - if (fBootDrive->IsBootMenuInstalled(&fSettings)) + if (fSettings.FindBool("install")) { + if (fBootMenu->IsBootMenuInstalled(&fSettings)) return kStatePartitions; return kStateSaveMBR; @@ -176,7 +186,7 @@ BootManagerController::_WriteBootMenu() if (alert->Go() == 1) return false; - fWriteBootMenuStatus = fBootDrive->WriteBootMenu(&fSettings); + fWriteBootMenuStatus = fBootMenu->WriteBootMenu(&fSettings); return true; } @@ -187,7 +197,7 @@ BootManagerController::_SaveMBR() BString path; fSettings.FindString("file", &path); BFile file(path.String(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); - fSaveMBRStatus = fBootDrive->SaveMasterBootRecord(&fSettings, &file); + fSaveMBRStatus = fBootMenu->SaveMasterBootRecord(&fSettings, &file); return true; } @@ -215,7 +225,7 @@ BootManagerController::_RestoreMBR() return false; BFile file(path.String(), B_READ_ONLY); - fRestoreMBRStatus = fBootDrive->RestoreMasterBootRecord(&fSettings, &file); + fRestoreMBRStatus = fBootMenu->RestoreMasterBootRecord(&fSettings, &file); return true; } @@ -228,8 +238,7 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard) switch (state) { case kStateEntry: - page = new EntryPage(&fSettings, "entry"); - wizard->SetPreviousButtonHidden(true); + page = new DrivesPage(wizard, &fSettings, "drives"); break; case kStateErrorEntry: page = _CreateErrorEntryPage(); @@ -252,7 +261,6 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard) break; case kStateInstallSummary: page = _CreateInstallSummaryPage(); - wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button")); break; case kStateInstalled: page = _CreateInstalledPage(); @@ -261,7 +269,6 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard) case kStateUninstall: page = _CreateUninstallPage(frame); wizard->SetPreviousButtonHidden(false); - wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button")); break; case kStateUninstalled: // TODO prevent overwriting MBR after clicking "Previous" @@ -279,7 +286,7 @@ BootManagerController::_CreateErrorEntryPage() { BString description; - if (fReadPartitionsStatus == kErrorBootSectorTooSmall) { + if (fReadPartitionsStatus == B_PARTITION_TOO_SMALL) { description << B_TRANSLATE_COMMENT("Partition table not compatible", "Title") << "\n\n" << B_TRANSLATE("The partition table of the first hard disk is not " @@ -371,7 +378,7 @@ BootManagerController::_CreateInstallSummaryPage() message.FindString("path", &path); BString displayName; - if (fBootDrive->GetDisplayText(name.String(), displayName) == B_OK) + if (fBootMenu->GetDisplayText(name.String(), displayName) == B_OK) description << displayName << "\t(" << path << ")\n"; else description << name << "\t(" << path << ")\n"; diff --git a/src/apps/bootmanager/BootManagerController.h b/src/apps/bootmanager/BootManagerController.h index b901c8ca21..a7fcb4f1a5 100644 --- a/src/apps/bootmanager/BootManagerController.h +++ b/src/apps/bootmanager/BootManagerController.h @@ -15,10 +15,9 @@ class BootDrive; - +class BootMenu; class WizardView; class WizardPageView; -class BRect; /* Remainder of Settings Message Format: @@ -34,6 +33,8 @@ public: BootManagerController(); virtual ~BootManagerController(); + virtual void Previous(WizardView* wizard); + protected: virtual int32 InitialState(); virtual int32 NextState(int32 state); @@ -71,7 +72,7 @@ private: WizardPageView* _CreateUninstalledPage(); BMessage fSettings; - BootDrive* fBootDrive; + BootMenu* fBootMenu; status_t fReadPartitionsStatus; status_t fWriteBootMenuStatus; diff --git a/src/apps/bootmanager/BootMenu.h b/src/apps/bootmanager/BootMenu.h new file mode 100644 index 0000000000..23e32fd47d --- /dev/null +++ b/src/apps/bootmanager/BootMenu.h @@ -0,0 +1,49 @@ +/* + * Copyright 2008-2011, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Michael Pfeiffer + */ +#ifndef BOOT_MENU_H +#define BOOT_MENU_H + + +#include +#include + + +/* Setting BMessage Format: + + "disk" String (path to boot disk) + + "partition" array of BMessage: + "show" bool (flag if entry should be added to boot menu) + "name" String (the name as shown in boot menu) + "type" String (short name of file system: bfs, dos) + "path" String (path to partition in /dev/...) + "size" long (size of partition in bytes) +*/ + + +class BootMenu { +public: + BootMenu() {} + virtual ~BootMenu() {} + + 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 + // in the boot menu. + virtual status_t GetDisplayText(const char* text, + BString& displayText) = 0; +}; + + +#endif // BOOT_MENU_H diff --git a/src/apps/bootmanager/DrivesPage.cpp b/src/apps/bootmanager/DrivesPage.cpp new file mode 100644 index 0000000000..004161d7ca --- /dev/null +++ b/src/apps/bootmanager/DrivesPage.cpp @@ -0,0 +1,306 @@ +/* + * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include "DrivesPage.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "BootDrive.h" +#include "WizardView.h" + + +#undef B_TRANSLATE_CONTEXT +#define B_TRANSLATE_CONTEXT "DrivesPage" + + +const uint32 kMsgSelectionChanged = 'slch'; + + +class DriveItem : public BListItem { +public: + DriveItem(const BDiskDevice& device); + virtual ~DriveItem(); + + bool IsInstalled() const; + bool CanBeInstalled() const; + bool IsBootDrive() const; + const char* Path() const { return fPath.Path(); } + + BMessage& Settings() { return fSettings; } + BootDrive* Drive() { return fDrive; } + +protected: + virtual void DrawItem(BView* owner, BRect frame, + bool complete = false); + virtual void Update(BView* owner, const BFont* font); + +private: + BMessage fSettings; + BootDrive* fDrive; + BString fName; + BPath fPath; + BString fSize; + float fBaselineOffset; + float fSecondBaselineOffset; + float fSizeWidth; +}; + + +DriveItem::DriveItem(const BDiskDevice& device) + : + fBaselineOffset(0), + fSizeWidth(0) +{ + // TODO: retrieve disk name! + if (device.Name() != NULL && device.Name()[0]) + fName = device.Name(); + else + fName = B_TRANSLATE_COMMENT("Hard Drive", "Default disk name"); + + device.GetPath(&fPath); + + char buffer[256]; + fSize = string_for_size(device.Size(), buffer, sizeof(buffer)); +} + + +DriveItem::~DriveItem() +{ +} + + +bool +DriveItem::IsInstalled() const +{ + return true; +} + + +bool +DriveItem::CanBeInstalled() const +{ + return true; +} + + +bool +DriveItem::IsBootDrive() const +{ + return true; +} + + +void +DriveItem::DrawItem(BView* owner, BRect frame, bool complete) +{ + owner->PushState(); + + if (IsSelected() || complete) { + if (IsSelected()) { + owner->SetHighColor(tint_color(owner->LowColor(), B_DARKEN_2_TINT)); + owner->SetLowColor(owner->HighColor()); + } else + owner->SetHighColor(owner->LowColor()); + + owner->FillRect(frame); + } + + rgb_color black = {0, 0, 0, 255}; + + if (!IsEnabled()) + owner->SetHighColor(tint_color(black, B_LIGHTEN_2_TINT)); + else + owner->SetHighColor(black); + + // device + owner->MovePenTo(frame.left + 4, frame.top + fSecondBaselineOffset); + owner->DrawString(fPath.Path()); + + // size + owner->MovePenTo(frame.right - 4 - fSizeWidth, frame.top + fBaselineOffset); + owner->DrawString(fSize.String()); + + // name + BFont boldFont; + owner->GetFont(&boldFont); + boldFont.SetFace(B_BOLD_FACE); + owner->SetFont(&boldFont); + + owner->MovePenTo(frame.left + 4, frame.top + fBaselineOffset); + owner->DrawString(fName.String()); + + owner->PopState(); +} + + +void +DriveItem::Update(BView* owner, const BFont* font) +{ + fSizeWidth = font->StringWidth(fSize.String()); + + BFont boldFont(font); + boldFont.SetFace(B_BOLD_FACE); + float width = 8 + boldFont.StringWidth(fPath.Path()) + + be_control_look->DefaultItemSpacing() + fSizeWidth; + float pathWidth = font->StringWidth(fPath.Path()); + if (width < pathWidth) + width = pathWidth; + + SetWidth(width); + + font_height fheight; + font->GetHeight(&fheight); + + float lineHeight = ceilf(fheight.ascent) + ceilf(fheight.descent) + + ceilf(fheight.leading); + + fBaselineOffset = 2 + ceilf(fheight.ascent + fheight.leading / 2); + fSecondBaselineOffset = fBaselineOffset + lineHeight; + + SetHeight(2 * lineHeight + 4); +} + + +// #pragma mark - + + +DrivesPage::DrivesPage(WizardView* wizardView, BMessage* settings, + const char* name) + : + WizardPageView(settings, name), + fWizardView(wizardView) +{ + BString text; + text << B_TRANSLATE_COMMENT("Drives", "Title") << "\n" + << B_TRANSLATE("Please select the drive you want the boot manager to " + "be installed to or uninstalled from."); + BTextView* description = CreateDescription("description", text); + MakeHeading(description); + + fDrivesView = new BListView("drives"); + fDrivesView->SetSelectionMessage(new BMessage(kMsgSelectionChanged)); + + bool any = _FillDrivesView(); + + BScrollView* scrollView = new BScrollView("scrollView", fDrivesView, 0, + false, true); + + SetLayout(new BGroupLayout(B_VERTICAL)); + + BLayoutBuilder::Group<>((BGroupLayout*)GetLayout()) + .Add(description, 0.5) + .Add(scrollView, 1); + + if (any) { + fWizardView->SetPreviousButtonLabel( + B_TRANSLATE_COMMENT("Uninstall", "Button")); + fWizardView->SetPreviousButtonHidden(false); + } else { + fWizardView->SetPreviousButtonHidden(true); + fWizardView->SetNextButtonLabel( + B_TRANSLATE_COMMENT("Quit", "Button")); + } +} + + +DrivesPage::~DrivesPage() +{ +} + + +void +DrivesPage::PageCompleted() +{ + DriveItem* item = _SelectedDriveItem(); + + if (fSettings->ReplaceString("disk", item->Path()) != B_OK) + fSettings->AddString("disk", item->Path()); + + fSettings->ReplaceBool("install", true); +} + + +void +DrivesPage::AttachedToWindow() +{ + fDrivesView->SetTarget(this); +} + + +void +DrivesPage::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgSelectionChanged: + { + _UpdateWizardButtons(_SelectedDriveItem()); + break; + } + + default: + WizardPageView::MessageReceived(message); + break; + } +} + + +/*! Builds the list view items, and adds them to fDriveView. + Returns whether there were any possible install targets. Automatically + selects the boot drive. +*/ +bool +DrivesPage::_FillDrivesView() +{ + bool any = false; + + BDiskDeviceRoster roster; + BDiskDevice device; + while (roster.GetNextDevice(&device) == B_OK) { + if (device.HasMedia() && !device.IsReadOnly()) { + DriveItem* item = new DriveItem(device); + if (item->CanBeInstalled()) + any = true; + fDrivesView->AddItem(item); + if (item->IsBootDrive()) { + fDrivesView->Select(fDrivesView->CountItems() - 1); + _UpdateWizardButtons(item); + } + } + } + + return any; +} + + +DriveItem* +DrivesPage::_SelectedDriveItem() +{ + return (DriveItem*)fDrivesView->ItemAt(fDrivesView->CurrentSelection()); +} + + +void +DrivesPage::_UpdateWizardButtons(DriveItem* item) +{ + fWizardView->SetPreviousButtonEnabled( + item->CanBeInstalled() && item->IsInstalled()); + fWizardView->SetNextButtonEnabled(item->CanBeInstalled()); + + fWizardView->SetNextButtonLabel( + item->IsInstalled() && item->CanBeInstalled() + ? B_TRANSLATE_COMMENT("Update", "Button") + : B_TRANSLATE_COMMENT("Install", "Button")); +} diff --git a/src/apps/bootmanager/DrivesPage.h b/src/apps/bootmanager/DrivesPage.h new file mode 100644 index 0000000000..5681eac3ce --- /dev/null +++ b/src/apps/bootmanager/DrivesPage.h @@ -0,0 +1,42 @@ +/* + * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef DRIVES_PAGE_H +#define DRIVES_PAGE_H + + +#include "WizardPageView.h" + + +class BListView; +class BTextView; +class BScrollView; +class DriveItem; +class WizardView; + + +class DrivesPage : public WizardPageView { +public: + DrivesPage(WizardView* wizardView, + BMessage* settings, const char* name); + virtual ~DrivesPage(); + + virtual void PageCompleted(); + +protected: + void AttachedToWindow(); + void MessageReceived(BMessage* message); + +private: + bool _FillDrivesView(); + DriveItem* _SelectedDriveItem(); + void _UpdateWizardButtons(DriveItem* item); + +private: + WizardView* fWizardView; + BListView* fDrivesView; +}; + + +#endif // DRIVES_PAGE_H diff --git a/src/apps/bootmanager/EntryPage.cpp b/src/apps/bootmanager/EntryPage.cpp deleted file mode 100644 index 08a09a9fb1..0000000000 --- a/src/apps/bootmanager/EntryPage.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2008-2011, Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Michael Pfeiffer - */ - - -#include "EntryPage.h" - -#include - -#include -#include -#include -#include - - -#undef B_TRANSLATE_CONTEXT -#define B_TRANSLATE_CONTEXT "EntryPage" - - -EntryPage::EntryPage(BMessage* settings, const char* name) - : - WizardPageView(settings, name) -{ - _BuildUI(); -} - - -EntryPage::~EntryPage() -{ -} - - -void -EntryPage::PageCompleted() -{ - fSettings->ReplaceBool("install", fInstallButton->Value() != 0); -} - - -void -EntryPage::_BuildUI() -{ - fInstallButton = new BRadioButton("install", NULL, NULL); - - BString text; - text << B_TRANSLATE_COMMENT("Install boot menu", "Title") << "\n" - << B_TRANSLATE("Choose this option to install a boot menu, " - "allowing you to select which operating " - "system to boot when you turn on your " - "computer.") << "\n"; - fInstallText = CreateDescription("installText", text); - MakeHeading(fInstallText); - - fUninstallButton = new BRadioButton("uninstall", NULL, NULL); - - text.Truncate(0); - text << B_TRANSLATE_COMMENT("Uninstall boot menu", "Title") << "\n" - << B_TRANSLATE("Choose this option to remove the boot menu " - "previously installed by this program.\n"); - fUninstallText = CreateDescription("uninstallText", text); - MakeHeading(fUninstallText); - - SetLayout(new BGroupLayout(B_VERTICAL)); - - BLayoutBuilder::Group<>((BGroupLayout*)GetLayout()) - .AddGroup(B_HORIZONTAL, 0) - .AddGroup(B_VERTICAL, 0, 0) - .Add(fInstallButton) - .AddGlue() - .End() - .Add(fInstallText, 1) - .End() - .AddGroup(B_HORIZONTAL, 0) - .AddGroup(B_VERTICAL, 0, 0) - .Add(fUninstallButton) - .AddGlue() - .End() - .Add(fUninstallText) - .End() - .AddGlue(); - - if (fSettings->FindBool("install")) - fInstallButton->SetValue(1); - else - fUninstallButton->SetValue(1); -} diff --git a/src/apps/bootmanager/EntryPage.h b/src/apps/bootmanager/EntryPage.h deleted file mode 100644 index 0542d72a10..0000000000 --- a/src/apps/bootmanager/EntryPage.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2008-2011, Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Michael Pfeiffer - */ -#ifndef ENTRY_PAGE_H -#define ENTRY_PAGE_H - - -#include "WizardPageView.h" - - -class BRadioButton; -class BTextView; - - -class EntryPage : public WizardPageView { -public: - EntryPage(BMessage* settings, const char* name); - virtual ~EntryPage(); - - virtual void PageCompleted(); - -private: - void _BuildUI(); - -private: - BRadioButton* fInstallButton; - BTextView* fInstallText; - BRadioButton* fUninstallButton; - BTextView* fUninstallText; -}; - - -#endif // ENTRY_PAGE_H diff --git a/src/apps/bootmanager/Jamfile b/src/apps/bootmanager/Jamfile index 6cf71df5a5..e1d9caf32d 100644 --- a/src/apps/bootmanager/Jamfile +++ b/src/apps/bootmanager/Jamfile @@ -8,9 +8,9 @@ Application BootManager : BootManagerWindow.cpp DefaultPartitionPage.cpp DescriptionPage.cpp - EntryPage.cpp + DrivesPage.cpp FileSelectionPage.cpp - LegacyBootDrive.cpp + LegacyBootMenu.cpp PartitionsPage.cpp # TestBootDrive.cpp UninstallPage.cpp diff --git a/src/apps/bootmanager/LegacyBootDrive.cpp b/src/apps/bootmanager/LegacyBootMenu.cpp similarity index 87% rename from src/apps/bootmanager/LegacyBootDrive.cpp rename to src/apps/bootmanager/LegacyBootMenu.cpp index 354033dba0..981361da29 100644 --- a/src/apps/bootmanager/LegacyBootDrive.cpp +++ b/src/apps/bootmanager/LegacyBootMenu.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010, Haiku, Inc. All rights reserved. + * Copyright 2008-2011, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -7,7 +7,7 @@ */ -#include "LegacyBootDrive.h" +#include "LegacyBootMenu.h" #include #include @@ -27,7 +27,7 @@ #undef B_TRANSLATE_CONTEXT -#define B_TRANSLATE_CONTEXT "LegacyBootDrive" +#define B_TRANSLATE_CONTEXT "LegacyBootMenu" #define USE_SECOND_DISK 0 #define GET_FIRST_BIOS_DRIVE 1 @@ -238,18 +238,18 @@ PartitionRecorder::_Record(BPartition* partition) // #pragma mark - -LegacyBootDrive::LegacyBootDrive() +LegacyBootMenu::LegacyBootMenu() { } -LegacyBootDrive::~LegacyBootDrive() +LegacyBootMenu::~LegacyBootMenu() { } bool -LegacyBootDrive::IsBootMenuInstalled(BMessage* settings) +LegacyBootMenu::IsBootMenuInstalled(BMessage* settings) { // TODO detect bootman return false; @@ -257,17 +257,18 @@ LegacyBootDrive::IsBootMenuInstalled(BMessage* settings) status_t -LegacyBootDrive::ReadPartitions(BMessage *settings) +LegacyBootMenu::ReadPartitions(BMessage *settings) { + status_t status = B_ERROR; + BDiskDeviceRoster diskDeviceRoster; BDiskDevice device; bool diskFound = false; while (diskDeviceRoster.GetNextDevice(&device) == B_OK) { - BPath path; status_t status = device.GetPath(&path); if (status != B_OK) - return status; + continue; // skip not from BIOS bootable drives int8 drive; @@ -281,33 +282,20 @@ LegacyBootDrive::ReadPartitions(BMessage *settings) settings->AddString("disk", path.Path()); diskFound = true; - #if !USE_SECOND_DISK - // Enough space to write boot menu to drive? - // (ignored in test build) - off_t size = sizeof(kBootLoader); - if (!recorder.HasPartitions() || recorder.FirstOffset() < size) - return kErrorBootSectorTooSmall; - - // TODO remove when booting from all drives works - break; - #endif + // Enough space to write boot menu to drive? + // (ignored in test build) + off_t size = sizeof(kBootLoader); + if (!recorder.HasPartitions() || recorder.FirstOffset() < size) + status = B_PARTITION_TOO_SMALL; } } - #if USE_SECOND_DISK - // for testing only write boot menu to second hdd - settings->ReplaceString("disk", "/dev/disk/ata/1/master/raw"); - #endif - - if (diskFound) - return B_OK; - else - return B_ERROR; + return diskFound ? B_OK : status; } status_t -LegacyBootDrive::WriteBootMenu(BMessage *settings) +LegacyBootMenu::WriteBootMenu(BMessage *settings) { BString path; if (settings->FindString("disk", &path) != B_OK) @@ -375,7 +363,7 @@ LegacyBootDrive::WriteBootMenu(BMessage *settings) partition.FindBool("show", &show); partition.FindString("name", &name); partition.FindString("path", &path); - // LegacyBootDrive specific data + // LegacyBootMenu specific data partition.FindInt64("offset", &offset); partition.FindInt8("drive", &drive); if (!show) @@ -403,7 +391,7 @@ LegacyBootDrive::WriteBootMenu(BMessage *settings) status_t -LegacyBootDrive::SaveMasterBootRecord(BMessage* settings, BFile* file) +LegacyBootMenu::SaveMasterBootRecord(BMessage* settings, BFile* file) { BString path; @@ -444,7 +432,7 @@ LegacyBootDrive::SaveMasterBootRecord(BMessage* settings, BFile* file) status_t -LegacyBootDrive::RestoreMasterBootRecord(BMessage* settings, BFile* file) +LegacyBootMenu::RestoreMasterBootRecord(BMessage* settings, BFile* file) { BString path; if (settings->FindString("disk", &path) != B_OK) @@ -496,7 +484,7 @@ LegacyBootDrive::RestoreMasterBootRecord(BMessage* settings, BFile* file) status_t -LegacyBootDrive::GetDisplayText(const char* text, BString& displayText) +LegacyBootMenu::GetDisplayText(const char* text, BString& displayText) { BString biosText; if (!_ConvertToBIOSText(text, biosText)) { @@ -524,7 +512,7 @@ LegacyBootDrive::GetDisplayText(const char* text, BString& displayText) bool -LegacyBootDrive::_ConvertToBIOSText(const char* text, BString& biosText) +LegacyBootMenu::_ConvertToBIOSText(const char* text, BString& biosText) { // convert text in UTF-8 to 'code page 437' int32 textLength = strlen(text); @@ -550,7 +538,7 @@ LegacyBootDrive::_ConvertToBIOSText(const char* text, BString& biosText) bool -LegacyBootDrive::_GetBiosDrive(const char* device, int8* drive) +LegacyBootMenu::_GetBiosDrive(const char* device, int8* drive) { #if !GET_FIRST_BIOS_DRIVE int fd = open(device, O_RDONLY); @@ -567,7 +555,7 @@ LegacyBootDrive::_GetBiosDrive(const char* device, int8* drive) status_t -LegacyBootDrive::_ReadBlocks(int fd, uint8* buffer, size_t size) +LegacyBootMenu::_ReadBlocks(int fd, uint8* buffer, size_t size) { if (size % kBlockSize != 0) { fprintf(stderr, "_ReadBlocks buffer size must be a multiple of %d\n", @@ -585,7 +573,7 @@ LegacyBootDrive::_ReadBlocks(int fd, uint8* buffer, size_t size) status_t -LegacyBootDrive::_WriteBlocks(int fd, const uint8* buffer, size_t size) +LegacyBootMenu::_WriteBlocks(int fd, const uint8* buffer, size_t size) { if (size % kBlockSize != 0) { fprintf(stderr, "_WriteBlocks buffer size must be a multiple of %d\n", @@ -603,7 +591,7 @@ LegacyBootDrive::_WriteBlocks(int fd, const uint8* buffer, size_t size) void -LegacyBootDrive::_CopyPartitionTable(MasterBootRecord* destination, +LegacyBootMenu::_CopyPartitionTable(MasterBootRecord* destination, const MasterBootRecord* source) { memcpy(destination->diskSignature, source->diskSignature, @@ -613,7 +601,7 @@ LegacyBootDrive::_CopyPartitionTable(MasterBootRecord* destination, bool -LegacyBootDrive::_IsValid(const MasterBootRecord* mbr) +LegacyBootMenu::_IsValid(const MasterBootRecord* mbr) { return mbr->signature[0] == (kMBRSignature & 0xff) && mbr->signature[1] == (kMBRSignature >> 8); diff --git a/src/apps/bootmanager/LegacyBootDrive.h b/src/apps/bootmanager/LegacyBootMenu.h similarity index 79% rename from src/apps/bootmanager/LegacyBootDrive.h rename to src/apps/bootmanager/LegacyBootMenu.h index 12bafdcbb1..e6f9b6399a 100644 --- a/src/apps/bootmanager/LegacyBootDrive.h +++ b/src/apps/bootmanager/LegacyBootMenu.h @@ -1,15 +1,15 @@ /* - * Copyright 2008-2010, Haiku, Inc. All rights reserved. + * Copyright 2008-2011, Haiku, Inc. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Michael Pfeiffer */ -#ifndef LEGACY_BOOT_DRIVE_H -#define LEGACY_BOOT_DRIVE_H +#ifndef LEGACY_BOOT_MENU_H +#define LEGACY_BOOT_MENU_H -#include "BootDrive.h" +#include "BootMenu.h" #include @@ -17,10 +17,10 @@ struct MasterBootRecord; -class LegacyBootDrive : public BootDrive { +class LegacyBootMenu : public BootMenu { public: - LegacyBootDrive(); - virtual ~LegacyBootDrive(); + LegacyBootMenu(); + virtual ~LegacyBootMenu(); virtual bool IsBootMenuInstalled(BMessage* settings); virtual status_t ReadPartitions(BMessage* settings); @@ -46,4 +46,4 @@ private: }; -#endif // LEGACY_BOOT_DRIVE_H +#endif // LEGACY_BOOT_MENU_H diff --git a/src/apps/bootmanager/WizardController.cpp b/src/apps/bootmanager/WizardController.cpp index e1851409be..c7e5e5571e 100644 --- a/src/apps/bootmanager/WizardController.cpp +++ b/src/apps/bootmanager/WizardController.cpp @@ -82,6 +82,16 @@ WizardController::Previous(WizardView* wizard) } +int32 +WizardController::CurrentState() const +{ + if (fStack == NULL) + return -1; + + return fStack->State(); +} + + void WizardController::_PushState(int32 state) { diff --git a/src/apps/bootmanager/WizardController.h b/src/apps/bootmanager/WizardController.h index dc7bb9b9a7..a83ef94658 100644 --- a/src/apps/bootmanager/WizardController.h +++ b/src/apps/bootmanager/WizardController.h @@ -30,6 +30,8 @@ protected: virtual int32 NextState(int32 state) = 0; virtual WizardPageView* CreatePage(int32 state, WizardView* wizard) = 0; + int32 CurrentState() const; + private: class StateStack { public: diff --git a/src/apps/bootmanager/WizardView.cpp b/src/apps/bootmanager/WizardView.cpp index cd3f901eb4..2b126f9256 100644 --- a/src/apps/bootmanager/WizardView.cpp +++ b/src/apps/bootmanager/WizardView.cpp @@ -24,7 +24,7 @@ WizardView::WizardView(const char* name) : - BGroupView(name, B_VERTICAL), + BGroupView(name, B_VERTICAL, 0), fPrevious(NULL), fNext(NULL), fPage(NULL) @@ -63,6 +63,9 @@ WizardView::PageCompleted() { if (fPage != NULL) fPage->PageCompleted(); + + SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button")); + SetPreviousButtonLabel(B_TRANSLATE_COMMENT("Previous", "Button")); } @@ -123,7 +126,7 @@ WizardView::_BuildUI() .Add(fPageContainer) .Add(new BSeparatorView(B_HORIZONTAL)) .AddGroup(B_HORIZONTAL) - .SetInsets(B_USE_DEFAULT_SPACING, 0, + .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .AddGlue() .Add(fPrevious)