diff --git a/src/preferences/drivesetup/Jamfile b/src/preferences/drivesetup/Jamfile index 895692f07f..347ca9a82b 100644 --- a/src/preferences/drivesetup/Jamfile +++ b/src/preferences/drivesetup/Jamfile @@ -1,5 +1,7 @@ SubDir HAIKU_TOP src preferences drivesetup ; +UsePrivateHeaders interface storage shared ; + AddResources DriveSetup : DriveSetup.rdef ; Preference DriveSetup : main.cpp MainWindow.cpp PosSettings.cpp ; diff --git a/src/preferences/drivesetup/MainWindow.cpp b/src/preferences/drivesetup/MainWindow.cpp index c79341b26f..70564847e4 100644 --- a/src/preferences/drivesetup/MainWindow.cpp +++ b/src/preferences/drivesetup/MainWindow.cpp @@ -5,19 +5,69 @@ * */ -#ifndef MAIN_WINDOW_H +#include "MainWindow.h" - #include "MainWindow.h" - -#endif +#include "PosSettings.h" + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +class DriveVisitor : public BDiskDeviceVisitor +{ +public: + DriveVisitor(MainWindow* win); + + bool Visit(BDiskDevice *device); + bool Visit(BPartition *partition, int32 level); +private: + MainWindow* fDSWindow; +}; + +const char* +SizeAsString(off_t size, char *string) +{ + double kb = size / 1024.0; + if (kb < 1.0) { + sprintf(string, "%Ld B", size); + return string; + } + float mb = kb / 1024.0; + if (mb < 1.0) { + sprintf(string, "%3.1f KB", kb); + return string; + } + float gb = mb / 1024.0; + if (gb < 1.0) { + sprintf(string, "%3.1f MB", mb); + return string; + } + float tb = gb / 1024.0; + if (tb < 1.0) { + sprintf(string, "%3.1f GB", gb); + return string; + } + sprintf(string, "%.1f TB", tb); + return string; +} /** * Constructor. * @param frame The size to make the window. */ MainWindow::MainWindow(BRect frame, PosSettings *Settings) - :BWindow(frame, "DriveSetup", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE){ - + : BWindow(frame, "DriveSetup", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) +{ BRect bRect; BMenu *menu; BMenu *tmpMenu; @@ -28,7 +78,7 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings) bRect = Bounds(); bRect.bottom = 18.0; - rootMenu = new BMenuBar(bRect, "root menu"); + BMenuBar* rootMenu = new BMenuBar(bRect, "root menu"); //Setup Mount menu menu = new BMenu("Mount"); menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M')); @@ -44,31 +94,45 @@ MainWindow::MainWindow(BRect frame, PosSettings *Settings) //Setup Setup menu menu = new BMenu("Setup"); - menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F')); - tmpMenu = new BMenu("Partition"); - tmpMenu->AddItem(new BMenuItem("apple...", new BMessage(SETUP_PARTITION_APPLE_MSG))); - tmpMenu->AddItem(new BMenuItem("intel...", new BMessage(SETUP_PARTITION_INTEL_MSG))); - menu->AddItem(tmpMenu); - tmpMenu = new BMenu("Initialize"); - //add menu for formats - menu->AddItem(tmpMenu); - + menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F')); + tmpMenu = new BMenu("Partition"); + menu->AddItem(tmpMenu); + tmpMenu = new BMenu("Initialize"); + //add menu for formats + menu->AddItem(tmpMenu); rootMenu->AddItem(menu); //Setup Options menu menu = new BMenu("Options"); - menu->AddItem(new BMenuItem("Eject", new BMessage(OPTIONS_EJECT_MSG), 'E')); - menu->AddItem(new BMenuItem("Surface Test", new BMessage(OPTIONS_SURFACE_TEST_MSG), 'T')); + menu->AddItem(new BMenuItem("Eject", new BMessage(OPTIONS_EJECT_MSG), 'E')); + menu->AddItem(new BMenuItem("Surface Test", new BMessage(OPTIONS_SURFACE_TEST_MSG), 'T')); rootMenu->AddItem(menu); //Setup Rescan menu menu = new BMenu("Rescan"); - menu->AddItem(new BMenuItem("IDE", new BMessage(RESCAN_IDE_MSG))); - menu->AddItem(new BMenuItem("SCSI", new BMessage(RESCAN_SCSI_MSG))); + menu->AddItem(new BMenuItem("IDE", new BMessage(RESCAN_IDE_MSG))); + menu->AddItem(new BMenuItem("SCSI", new BMessage(RESCAN_SCSI_MSG))); rootMenu->AddItem(menu); AddChild(rootMenu); - + + BRect r(Bounds()); + r.top = rootMenu->Frame().bottom +1; + fListView = new BColumnListView(r, "storagelist", B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true); + fListView->AddColumn(new BStringColumn("Device", 100, 500, 50, 0), 1); + fListView->AddColumn(new BStringColumn("Map style", 100, 500, 50, 0), 2); + fListView->AddColumn(new BStringColumn("Partition Type", 100, 500, 50, 0), 3); + fListView->AddColumn(new BStringColumn("Filesystem", 100, 500, 50, 0), 4); + fListView->AddColumn(new BStringColumn("Volume Name", 100, 500, 50, 0), 5); + fListView->AddColumn(new BStringColumn("Mounted At", 100, 500, 50, 0), 6); + fListView->AddColumn(new BStringColumn("Size", 100, 500, 50, 0), 7); + AddChild(fListView); + + // Now visit all disks in the system and show their contents + DriveVisitor driveVisitor(this); + BPartition *partition = NULL; + BDiskDevice device; + fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition); } /** @@ -99,16 +163,6 @@ void MainWindow::MessageReceived(BMessage *message){ printf("SETUP_FORMAT_MSG\n"); break; - case SETUP_PARTITION_APPLE_MSG: - - printf("SETUP_PARTITION_APPLE_MSG\n"); - break; - - case SETUP_PARTITION_INTEL_MSG: - - printf("SETUP_PARTITION_INTEL_MSG\n"); - break; - case SETUP_INITIALIZE_MSG: printf("SETUP_INITIALIZE_MSG\n"); @@ -143,66 +197,118 @@ void MainWindow::MessageReceived(BMessage *message){ } /** - * Quits and Saves. - * Sets the swap size and turns the virtual memory on by writing to the - * /boot/home/config/settings/kernel/drivers/virtual_memory file. + * Quits and Saves settings. */ -bool MainWindow::QuitRequested(){ - - be_app->PostMessage(B_QUIT_REQUESTED); - return(true); +bool +MainWindow::QuitRequested() +{ + bool accepted = BWindow::QuitRequested(); + if (accepted) { + fSettings->SetWindowPosition(Frame()); + be_app->PostMessage(B_QUIT_REQUESTED); + } + return accepted; } -void MainWindow::FrameMoved(BPoint origin) -{//MainWindow::FrameMoved - fSettings->SetWindowPosition(Frame()); -}//MainWindow::FrameMoved +static void +dump_partition_info(BPartition* partition) +{ + printf("\tOffset(): %Ld\n", partition->Offset()); + printf("\tSize(): %Ld\n", partition->Size()); + printf("\tContentSize(): %Ld\n", partition->ContentSize()); + printf("\tBlockSize(): %ld\n", partition->BlockSize()); + printf("\tIndex(): %ld\n", partition->Index()); + printf("\tStatus(): %ld\n\n", partition->Status()); + printf("\tContainsFileSystem(): %s\n", partition->ContainsFileSystem() ? "true" : "false"); + printf("\tContainsPartitioningSystem(): %s\n\n", partition->ContainsPartitioningSystem() ? "true" : "false"); + printf("\tIsDevice(): %s\n", partition->IsDevice() ? "true" : "false"); + printf("\tIsReadOnly(): %s\n", partition->IsReadOnly() ? "true" : "false"); + printf("\tIsMounted(): %s\n", partition->IsMounted() ? "true" : "false"); + printf("\tIsBusy(): %s\n\n", partition->IsBusy() ? "true" : "false"); + printf("\tFlags(): %lx\n\n", partition->Flags()); + printf("\tName(): %s\n", partition->Name()); + printf("\tContentName(): %s\n", partition->ContentName()); + printf("\tType(): %s\n", partition->Type()); + printf("\tContentType(): %s\n", partition->ContentType()); + printf("\tID(): %x\n\n", partition->ID()); +} -void MainWindow::AddDeviceInfo(dev_info d){ +void +MainWindow::AddDrive(BDiskDevice* device) +{ + printf("AddDrive(%p)\n", device); - BMenuItem *tmp; - int cnt; + BPath path; + if (device->GetPath(&path) == B_OK) { + BRow* row = new BRow(); + row->SetField(new BStringField(path.Path()), 1); - printf("Got %s\n", d.device); - - cnt = 0; - while(cnt < d.numParts){ - - if(d.parts[cnt].mounted){ - - //Check to see if we have to get rid of the item - if(strcmp(rootMenu->SubmenuAt(1)->ItemAt(0)->Label(), "") == 0){ - - rootMenu->SubmenuAt(1)->RemoveItem((int32) 0); - - }//if - //add to Unmount menu - tmp = new BMenuItem(d.parts[cnt].mount_pt, new BMessage(UNMOUNT_UNMOUNT_SELECTED_MSG)); - if(strcmp(d.parts[cnt].mount_pt, "/boot") == 0){ - - tmp->SetEnabled(false); - - }//if - rootMenu->SubmenuAt(1)->AddItem(tmp); - - }//if - - //add to Mount menu - //This label comes from the type mapping - tmp = new BMenuItem(d.parts[cnt].fs, new BMessage(MOUNT_MOUNT_SELECTED_MSG)); - if(d.parts[cnt].mounted){ - - tmp->SetEnabled(false); - - }//if - rootMenu->SubmenuAt(0)->AddItem(tmp); - - cnt++; - - }//while - - //send to view + printf("\tPath=%s\n", path.Path()); -}//SetDeviceInfo + if (device->ContainsPartitioningSystem()) { + row->SetField(new BStringField(device->Type()), 3); + } + char size[1024]; + row->SetField(new BStringField(SizeAsString(device->Size(), size)), 7); + + fListView->AddRow(row); + } + + dump_partition_info(device); +} + +void +MainWindow::AddPartition(BPartition *partition, int32 level) +{ + printf("AddPartition(%p, %d)\n", partition, level); + + BPath path; + if (partition->GetPath(&path) == B_OK) { + BRow* row = new BRow(); + row->SetField(new BStringField(path.Path()), 1); + + printf("\tPath=%s\n", path.Path()); + + if (partition->ContainsFileSystem()) { + row->SetField(new BStringField(partition->Type()), 3); // Partition Type + row->SetField(new BStringField(partition->ContentType()), 4); // Filesystem + row->SetField(new BStringField(partition->ContentName()), 5); // Volume Name + + if (partition->GetMountPoint(&path) == B_OK) + row->SetField(new BStringField(path.Path()), 6); + } + + char size[1024]; + row->SetField(new BStringField(SizeAsString(partition->Size(), size)), 7); + + fListView->AddRow(row); + } + + dump_partition_info(partition); +} + + +DriveVisitor::DriveVisitor(MainWindow* win) + : fDSWindow(win) +{ +} + +bool +DriveVisitor::Visit(BDiskDevice* device) +{ + if (fDSWindow != NULL) + fDSWindow->AddDrive(device); + + return false; // Don't stop yet! +} + +bool +DriveVisitor::Visit(BPartition* partition, int32 level) +{ + if (fDSWindow != NULL) + fDSWindow->AddPartition(partition, level); + + return false; // Don't stop yet! +} diff --git a/src/preferences/drivesetup/MainWindow.h b/src/preferences/drivesetup/MainWindow.h index 89ea07df28..719733f0d6 100644 --- a/src/preferences/drivesetup/MainWindow.h +++ b/src/preferences/drivesetup/MainWindow.h @@ -4,82 +4,49 @@ */ #ifndef MAIN_WINDOW_H - - #define MAIN_WINDOW_H - - #define MOUNT_MOUNT_ALL_MSG 'mall' - #define MOUNT_MOUNT_SELECTED_MSG 'msel' - #define UNMOUNT_UNMOUNT_SELECTED_MSG 'usel' - #define SETUP_FORMAT_MSG 'sfor' - #define SETUP_PARTITION_APPLE_MSG 'spaa' - #define SETUP_PARTITION_INTEL_MSG 'spai' - #define SETUP_INITIALIZE_MSG 'sini' - #define OPTIONS_EJECT_MSG 'oeje' - #define OPTIONS_SURFACE_TEST_MSG 'osut' - #define RESCAN_IDE_MSG 'ride' - #define RESCAN_SCSI_MSG 'rscs' - - #ifndef _APPLICATION_H +#define MAIN_WINDOW_H - #include - - #endif - #ifndef _WINDOW_H - - #include - - #endif - #ifndef _MENU_BAR_H - - #include - - #endif - #ifndef _MENU_ITEM_H - - #include - - #endif - #ifndef _RECT_H - - #include - - #endif - #ifndef _STDIO_H - - #include - - #endif - #ifndef POS_SETTINGS_H - - #include "PosSettings.h" + #define MOUNT_MOUNT_ALL_MSG 'mall' + #define MOUNT_MOUNT_SELECTED_MSG 'msel' + #define UNMOUNT_UNMOUNT_SELECTED_MSG 'usel' + #define SETUP_FORMAT_MSG 'sfor' + #define SETUP_PARTITION_SELECTED_MSG 'spsl' + #define SETUP_INITIALIZE_MSG 'sini' + #define OPTIONS_EJECT_MSG 'oeje' + #define OPTIONS_SURFACE_TEST_MSG 'osut' + #define RESCAN_IDE_MSG 'ride' + #define RESCAN_SCSI_MSG 'rscs' - #endif - #ifndef STRUCTS_H - - #include "structs.h" - - #endif + #include + #include + + // Forward declarations + class PosSettings; + class BPartition; + class BDiskDevice; + class BColumnListView; /** * The main window of the app. * * Sets up and displays everything you need for the app. */ - class MainWindow : public BWindow{ - + + class MainWindow : public BWindow + { private: - - PosSettings *fSettings; - BMenuBar *rootMenu; - + PosSettings* fSettings; + BDiskDeviceRoster fDDRoster; + BColumnListView* fListView; public: - MainWindow(BRect frame, PosSettings *fSettings); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - virtual void FrameMoved(BPoint origin); - void AddDeviceInfo(dev_info d); - + + bool QuitRequested(); + void MessageReceived(BMessage *message); + + // These are public for visitor.... + void AddPartition(BPartition* partition, int32 level); + void AddDrive(BDiskDevice* device); }; #endif diff --git a/src/preferences/drivesetup/PosSettings.cpp b/src/preferences/drivesetup/PosSettings.cpp index 0e1fe15db5..3cfcaf63ad 100644 --- a/src/preferences/drivesetup/PosSettings.cpp +++ b/src/preferences/drivesetup/PosSettings.cpp @@ -16,15 +16,14 @@ #include -const char PosSettings::kVMSettingsFile[] = "DriveSetup_prefs"; +const char PosSettings::kSettingsFile[] = "DriveSetup_prefs"; PosSettings::PosSettings() -{//VMSettings::VMSettings - +{ BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK) { - path.Append(kVMSettingsFile); + path.Append(kSettingsFile); BFile file(path.Path(), B_READ_ONLY); if (file.InitCheck() != B_OK) be_app->PostMessage(B_QUIT_REQUESTED); @@ -34,7 +33,7 @@ PosSettings::PosSettings() if (file.Read(&brCorner, sizeof(BPoint)) != sizeof(BPoint)) be_app->PostMessage(B_QUIT_REQUESTED); } - printf("VM settings file read.\n"); + printf("settings file read.\n"); printf("=========================\n"); printf("fcorner read in as "); fcorner.PrintToStream(); @@ -53,42 +52,34 @@ PosSettings::PosSettings() return; // If they are not, lets just stick the window in the middle // of the screen. - - //I don't want to deal with this now - MSM - - /*fWindowFrame = screen.Frame(); - fWindowFrame.left = (fWindowFrame.right-269)/2; + + fWindowFrame = screen.Frame(); + fWindowFrame.left = (fWindowFrame.right-269) /2; fWindowFrame.right = fWindowFrame.left + 269; - fWindowFrame.top = (fWindowFrame.bottom-172)/2; + fWindowFrame.top = (fWindowFrame.bottom-172) /2; fWindowFrame.bottom = fWindowFrame.top + 172; -*/ -}//VMSettings::VMSettings +} PosSettings::~PosSettings() -{//VMSettings::~VMSettings -//printf("enter\n"); +{ BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK) return; -//printf("find_directory\n"); - path.Append(kVMSettingsFile); -//printf("path.Append\n"); + + path.Append(kSettingsFile); BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE); -//printf("create file\n"); if (file.InitCheck() == B_OK) { - //printf("in if statement\n"); file.Write(&fcorner, sizeof(BPoint)); file.Write(&brCorner, sizeof(BPoint)); } -//printf("exit\n"); -}//MouseSettings::~MouseSettings +} void PosSettings::SetWindowPosition(BRect f) -{//VMSettings::SetWindowFrame +{ fcorner.x=f.left; fcorner.y=f.top; brCorner.x=f.right; brCorner.y=f.bottom; brCorner.PrintToStream(); -}//VMSettings::SetWindowFrame +} diff --git a/src/preferences/drivesetup/PosSettings.h b/src/preferences/drivesetup/PosSettings.h index c4b592ab68..dbec37b1bc 100644 --- a/src/preferences/drivesetup/PosSettings.h +++ b/src/preferences/drivesetup/PosSettings.h @@ -12,7 +12,7 @@ public : void SetWindowPosition(BRect); private: - static const char kVMSettingsFile[]; + static const char kSettingsFile[]; BRect fWindowFrame; BPoint fcorner; BPoint brCorner; diff --git a/src/preferences/drivesetup/main.cpp b/src/preferences/drivesetup/main.cpp index d015172c43..b7494939a2 100644 --- a/src/preferences/drivesetup/main.cpp +++ b/src/preferences/drivesetup/main.cpp @@ -6,16 +6,10 @@ * */ -#ifndef MAIN_WINDOW_H +#include "MainWindow.h" +#include "main.h" - #include "MainWindow.h" - -#endif -#ifndef MAIN_H - - #include "main.h" - -#endif +#include "PosSettings.h" /** * Main method. @@ -41,77 +35,19 @@ int main(int, char**){ * Provides a contstructor for the application. */ DriveSetup::DriveSetup() - :BApplication("application/x-vnd.MSM-DriveSetupPrefPanel"){ + : BApplication("application/x-vnd.MSM-DriveSetupPrefPanel") +{ fSettings = new PosSettings(); /* * The main interface window. */ - MainWindow *Main; - dev_info devs; - partition_info partitions[4]; - - Main = new MainWindow(fSettings->WindowPosition(), fSettings); - - //This section is to set up defaults that I can use for testing. - //set up floppy drive - partitions[0].type = 11; - partitions[0].fs = "dos"; - partitions[0].name = ""; - partitions[0].mount_pt = ""; - partitions[0].size = 1.4; - partitions[0].mounted = FALSE; - devs.device = "/dev/disk/floppy"; - devs.map = 1; - devs.numParts = 1; - devs.parts = partitions; - Main->AddDeviceInfo(devs); - - partitions[0].type = 11; - partitions[0].fs = "dos"; - partitions[0].name = "winxp"; - partitions[0].mount_pt = "/winxp"; - partitions[0].size = 5600.0; - partitions[0].mounted = TRUE; - partitions[1].type = 12; - partitions[1].fs = "dos"; - partitions[1].name = "windata"; - partitions[1].mount_pt = "/windata"; - partitions[1].size = 3600.0; - partitions[1].mounted = TRUE; - partitions[2].type = 235; - partitions[2].fs = "Be File System"; - partitions[2].name = "BeOS"; - partitions[2].mount_pt = "/boot"; - partitions[2].size = 4900.0; - partitions[2].mounted = TRUE; - devs.device = "/dev/disk/ide/ata/0/master/0"; - devs.map = 1; - devs.numParts = 3; - devs.parts = partitions; - Main->AddDeviceInfo(devs); - - partitions[0].type = 11; - partitions[0].fs = "iso9660"; - partitions[0].name = ""; - partitions[0].mount_pt = "/OUTLAWSTAR_D1"; - partitions[0].size = 2200.0; - partitions[0].mounted = TRUE; - devs.device = "/dev/disk/ide/atapi/1/master/0"; - devs.map = 2; - devs.numParts = 1; - devs.parts = partitions; - Main->AddDeviceInfo(devs); - - //End set up of defaults - + MainWindow *Main = new MainWindow(fSettings->WindowPosition(), fSettings); Main->Show(); - } DriveSetup::~DriveSetup() { - delete fSettings; + delete fSettings; } - diff --git a/src/preferences/drivesetup/main.h b/src/preferences/drivesetup/main.h index 3226358cb6..67d780726e 100644 --- a/src/preferences/drivesetup/main.h +++ b/src/preferences/drivesetup/main.h @@ -4,30 +4,11 @@ */ #ifndef MAIN_H +#define MAIN_H - #define MAIN_H + #include - #ifndef _APPLICATION_H - - #include - - #endif - - #ifndef _STDIO_H - - #include - - #endif - #ifndef POS_SETTINGS_H - - #include "PosSettings.h" - - #endif - #ifndef STRUCTS_H - - #include "structs.h" - - #endif + class PosSettings; /** @@ -35,8 +16,8 @@ * * Gets everything going. */ - class DriveSetup : public BApplication{ - + class DriveSetup : public BApplication + { public: /** @@ -47,7 +28,6 @@ private: PosSettings *fSettings; - }; #endif