* fix saving settings (don't let the window quit by itself)

* add partition creation menu items
* filter filesystems by their support for "initializing"


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22855 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2007-11-07 22:16:06 +00:00
parent f9ca8faab7
commit c900be6501
4 changed files with 82 additions and 33 deletions

View File

@ -78,15 +78,23 @@ DriveSetup::_StoreSettings()
fWindow->Unlock();
}
if (ret < B_OK)
if (ret < B_OK) {
fprintf(stderr, "failed to store settings: %s\n", strerror(ret));
return ret;
}
BFile file;
ret = _GetSettingsFile(file, true);
if (ret < B_OK)
return ret;
return fSettings.Flatten(&file);
ret = fSettings.Flatten(&file);
if (ret < B_OK) {
fprintf(stderr, "failed to flatten settings: %s\n", strerror(ret));
return ret;
}
return B_OK;
}
@ -95,14 +103,23 @@ DriveSetup::_RestoreSettings()
{
BFile file;
status_t ret = _GetSettingsFile(file, false);
if (ret < B_OK)
return ret;
if (ret >= B_OK)
ret = fSettings.Unflatten(&file);
ret = fSettings.Unflatten(&file);
if (ret < B_OK) {
fprintf(stderr, "failed to unflatten settings: %s\n", strerror(ret));
return ret;
}
fSettings.PrintToStream();
if (ret >= B_OK)
ret = fWindow->RestoreSettings(&fSettings);
ret = fWindow->RestoreSettings(&fSettings);
if (ret < B_OK) {
fprintf(stderr, "failed to restore settings: %s\n", strerror(ret));
return ret;
}
return ret;
return B_OK;
}

View File

@ -2,8 +2,8 @@
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef MAIN_H
#define MAIN_H
#ifndef DRIVE_SETUP_H
#define DRIVE_SETUP_H
#include <Application.h>
@ -34,4 +34,4 @@ private:
};
#endif // MAIN_H
#endif // DRIVE_SETUP_H

View File

@ -95,6 +95,9 @@ enum {
MSG_MOUNT = 'mnts',
MSG_UNMOUNT = 'unmt',
MSG_FORMAT = 'frmt',
MSG_CREATE_PRIMARY = 'crpr',
MSG_CREATE_EXTENDED = 'crex',
MSG_CREATE_LOGICAL = 'crlg',
MSG_INITIALIZE = 'init',
MSG_EJECT = 'ejct',
MSG_SURFACE_TEST = 'sfct',
@ -120,8 +123,10 @@ MainWindow::MainWindow(BRect frame)
// Parition menu
menu = new BMenu("Partition");
BMenu* initMenu = new BMenu("Initialize");
menu->AddItem(initMenu);
BMenu* createMenu = new BMenu("Create");
menu->AddItem(createMenu);
fInitMenu = new BMenu("Initialize");
menu->AddItem(fInitMenu);
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Mount", new BMessage(MSG_MOUNT), 'M'));
menu->AddItem(new BMenuItem("Unmount", new BMessage(MSG_UNMOUNT), 'U'));
@ -132,23 +137,20 @@ MainWindow::MainWindow(BRect frame)
AddChild(rootMenu);
createMenu->AddItem(new BMenuItem("Primary",
new BMessage(MSG_CREATE_PRIMARY)));
createMenu->AddItem(new BMenuItem("Extended",
new BMessage(MSG_CREATE_EXTENDED)));
createMenu->AddItem(new BMenuItem("Logical",
new BMessage(MSG_CREATE_LOGICAL)));
BRect r(Bounds());
r.top = rootMenu->Frame().bottom + 1;
fListView = new PartitionListView(r);
AddChild(fListView);
// Populate the Initialiaze menu with the available file systems
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.IsFileSystem()) {
BMessage* message = new BMessage(MSG_INITIALIZE);
message->AddString("format", diskSystem.Name());
BString label = diskSystem.PrettyName();
label << B_UTF8_ELLIPSIS;
initMenu->AddItem(new BMenuItem(label.String(), message));
}
}
_ScanFileSystems();
// Visit all disks in the system and show their contents
_ScanDrives();
@ -162,31 +164,37 @@ MainWindow::MessageReceived(BMessage* message)
case MSG_MOUNT_ALL:
printf("MSG_MOUNT_ALL\n");
break;
case MSG_MOUNT:
printf("MSG_MOUNT\n");
break;
case MSG_UNMOUNT:
printf("MSG_UNMOUNT\n");
break;
case MSG_FORMAT:
printf("MSG_FORMAT\n");
break;
case MSG_CREATE_PRIMARY:
printf("MSG_CREATE_PRIMARY\n");
break;
case MSG_CREATE_EXTENDED:
printf("MSG_CREATE_EXTENDED\n");
break;
case MSG_CREATE_LOGICAL:
printf("MSG_CREATE_LOGICAL\n");
break;
case MSG_INITIALIZE:
printf("MSG_INITIALIZE\n");
break;
case MSG_EJECT:
printf("MSG_EJECT\n");
break;
case MSG_SURFACE_TEST:
printf("MSG_SURFACE_TEST\n");
break;
case MSG_RESCAN:
_ScanDrives();
break;
@ -203,7 +211,8 @@ MainWindow::QuitRequested()
{
// TODO: ask about any unsaved changes
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
Hide();
return false;
}
@ -249,6 +258,26 @@ MainWindow::_ScanDrives()
}
void
MainWindow::_ScanFileSystems()
{
while (BMenuItem* item = fInitMenu->RemoveItem(0L))
delete item;
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.IsFileSystem() && diskSystem.SupportsInitializing()) {
BMessage* message = new BMessage(MSG_INITIALIZE);
message->AddString("format", diskSystem.Name());
BString label = diskSystem.PrettyName();
label << B_UTF8_ELLIPSIS;
fInitMenu->AddItem(new BMenuItem(label.String(), message));
}
}
}
// #pragma mark - DriveVisitor

View File

@ -10,9 +10,9 @@
#include <Window.h>
class PosSettings;
class BPartition;
class BDiskDevice;
class BPartition;
class BMenu;
class PartitionListView;
@ -35,10 +35,13 @@ public:
private:
void _ScanDrives();
void _ScanFileSystems();
BDiskDeviceRoster fDDRoster;
PartitionListView* fListView;
BMenu* fInitMenu;
};