cleaned up the code:

* conforming app signature
* tracked down copyright info
* removed too technical list columns
* reimplemented storing/restoring settings (removed PosSettings)
* relayouted/simplified menu structure
* rewrote rdef
* enabled debug output for now


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22853 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-11-07 20:10:19 +00:00
parent f7e414f22b
commit 753e3d4ef7
11 changed files with 466 additions and 466 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
#include "InstallerWindow.h" #include "InstallerWindow.h"
#include "PartitionMenuItem.h" #include "PartitionMenuItem.h"
#define DRIVESETUP_SIG "application/x-vnd.Be-DRV$" #define DRIVESETUP_SIG "application/x-vnd.Haiku-DriveSetup"
const uint32 BEGIN_MESSAGE = 'iBGN'; const uint32 BEGIN_MESSAGE = 'iBGN';
const uint32 SHOW_BOTTOM_MESSAGE = 'iSBT'; const uint32 SHOW_BOTTOM_MESSAGE = 'iSBT';
+20 -34
View File
@@ -1,8 +1,24 @@
resource(1, "BEOS:FILE_TYPES") message; resource app_signature "application/x-vnd.Haiku-DriveSetup";
resource(101, "BEOS:L:STD_ICON") #'ICON' array resource app_version {
{ major = 1,
middle = 0,
minor = 0,
/* 0 = development 1 = alpha 2 = beta
3 = gamma 4 = golden master 5 = final */
variety = 0,
internal = 0,
short_info = "DriveSetup",
long_info = "DriveSetup ©2002-2007 Haiku"
};
resource app_flags B_SINGLE_LAUNCH;
resource large_icon {
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
@@ -37,8 +53,7 @@ resource(101, "BEOS:L:STD_ICON") #'ICON' array
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
}; };
resource(101, "BEOS:M:STD_ICON") #'MICN' array resource mini_icon {
{
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" $"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FF0000FFFFFF0000FFFFFFFFFF0000FF" $"FF0000FFFFFF0000FFFFFFFFFF0000FF"
@@ -57,32 +72,3 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array
$"FFFFFFFFFFFFFF0000000E0FFFFFFFFF" $"FFFFFFFFFFFFFF0000000E0FFFFFFFFF"
}; };
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.MSM-DriveSetupPrefPanel";
resource(1, "BEOS:APP_VERSION") #'APPV' array
{
$"0000000000000000010000000000000000000000564D20507265660000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000447269766553657475702050"
$"7265666572656E636573204170706C6574000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000000000000000000000000000"
$"0000000000000000000000000000000000000000010000000100000001000000"
$"0100000001000000010000000100000001000000680200007202000001000000"
$"3600000020000000200000002000000020000000200000002000000020000000"
$"2000000020000000200000002000000020000000200000002000000020000000"
$"FC000000420000008000000046000000480000004A000000BC0000004C000000"
$"540000005000000052000000BE00000056000000100000000A00000002000000"
$"16000000010000005E000000540000005A00000012000000E2000000EE000000"
$"CA000000E4000000E8000000F2000000EA000000D2000000DE000000E0000000"
$"F6000000FA000000F8000000FE00000008000000180000006E00000070000000"
$"720000005600000001000000C2000000E6000000C8000000CC000000CE000000"
$"D0000000D4000000D6000000D800000074000000440000001400000068000000"
$"6A0000006C000000"
};
resource(1, "BEOS:APP_FLAGS") #'APPF' $"00000000";
+9 -3
View File
@@ -1,9 +1,15 @@
SubDir HAIKU_TOP src preferences drivesetup ; SubDir HAIKU_TOP src preferences drivesetup ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders interface storage shared ; UsePrivateHeaders interface storage shared ;
AddResources DriveSetup : DriveSetup.rdef ; AddResources DriveSetup : DriveSetup.rdef ;
Preference DriveSetup : main.cpp MainWindow.cpp PartitionList.cpp PosSettings.cpp ; Preference DriveSetup :
main.cpp
LinkAgainst DriveSetup : be ; MainWindow.cpp
PartitionList.cpp
:
be
;
+175 -158
View File
@@ -1,36 +1,38 @@
/*! \file MainWindow.cpp /*
* \brief Code for the MainWindow class. * Copyright 2002-2007 Haiku Inc. All rights reserved.
* * Distributed under the terms of the MIT license.
* Displays the main window, the essence of the app.
* *
*/ * Authors:
* Erik Jaesler <[email protected]>
* Ithamar R. Adema <[email protected]>
* Stephan Aßmus <[email protected]>
*/
#include "MainWindow.h" #include "MainWindow.h"
#include "PartitionList.h" #include "PartitionList.h"
#include "PosSettings.h"
#include <interface/MenuItem.h> #include <Application.h>
#include <interface/MenuBar.h>
#include <interface/Menu.h>
#include <interface/ColumnListView.h> #include <DiskDeviceVisitor.h>
#include <interface/ColumnTypes.h> #include <DiskSystem.h>
#include <DiskDevice.h>
#include <Partition.h>
#include <Path.h>
#include <app/Application.h> #include <ColumnListView.h>
#include <ColumnTypes.h>
#include <MenuItem.h>
#include <MenuBar.h>
#include <Menu.h>
#include <Screen.h>
#include <storage/DiskDeviceVisitor.h>
#include <storage/DiskSystem.h>
#include <storage/DiskDevice.h>
#include <storage/Partition.h>
#include <storage/Path.h>
class DriveVisitor : public BDiskDeviceVisitor class DriveVisitor : public BDiskDeviceVisitor {
{
public: public:
DriveVisitor(PartitionListView* list); DriveVisitor(PartitionListView* list);
bool Visit(BDiskDevice *device); virtual bool Visit(BDiskDevice* device);
bool Visit(BPartition *partition, int32 level); virtual bool Visit(BPartition* partition, int32 level);
private: private:
PartitionListView* fPartitionList; PartitionListView* fPartitionList;
}; };
@@ -62,7 +64,7 @@ SizeAsString(off_t size, char *string)
return string; return string;
} }
#if DEBUG
static void static void
dump_partition_info(BPartition* partition) dump_partition_info(BPartition* partition)
{ {
@@ -86,187 +88,202 @@ dump_partition_info(BPartition* partition)
printf("\tContentType(): %s\n", partition->ContentType()); printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %lx\n\n", partition->ID()); printf("\tID(): %lx\n\n", partition->ID());
} }
#endif
/**
* Constructor. enum {
* @param frame The size to make the window. MSG_MOUNT_ALL = 'mnta',
*/ MSG_MOUNT = 'mnts',
MainWindow::MainWindow(BRect frame, PosSettings *Settings) MSG_UNMOUNT = 'unmt',
: BWindow(frame, "DriveSetup", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) MSG_FORMAT = 'frmt',
MSG_INITIALIZE = 'init',
MSG_EJECT = 'ejct',
MSG_SURFACE_TEST = 'sfct',
MSG_RESCAN = 'rscn',
};
MainWindow::MainWindow(BRect frame)
: BWindow(frame, "DriveSetup", B_DOCUMENT_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{ {
BMenu *partitionMenu, *initMenu;
BMenu *menu;
fSettings = Settings;
BMenuBar* rootMenu = new BMenuBar(Bounds(), "root menu"); BMenuBar* rootMenu = new BMenuBar(Bounds(), "root menu");
//Setup Mount menu
menu = new BMenu("Mount"); // Disk menu
menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M')); BMenu* menu = new BMenu("Disk");
menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Format", new BMessage(MSG_FORMAT), 'F'));
menu->AddItem(new BMenuItem("Eject", new BMessage(MSG_EJECT), 'E'));
menu->AddItem(new BMenuItem("Surface Test",
new BMessage(MSG_SURFACE_TEST), 'T'));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Rescan", new BMessage(MSG_RESCAN)));
rootMenu->AddItem(menu); rootMenu->AddItem(menu);
//Setup Unmount menu // Parition menu
menu = new BMenu("Unmount"); menu = new BMenu("Partition");
rootMenu->AddItem(menu); BMenu* initMenu = new BMenu("Initialize");
//Setup Setup menu
menu = new BMenu("Setup");
menu->AddItem(new BMenuItem("Format", new BMessage(SETUP_FORMAT_MSG), 'F'));
partitionMenu = new BMenu("Partition");
menu->AddItem(partitionMenu);
initMenu = new BMenu("Initialize");
//add menu for formats
menu->AddItem(initMenu); menu->AddItem(initMenu);
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Mount", new BMessage(MSG_MOUNT), 'M'));
menu->AddItem(new BMenuItem("Unmount", new BMessage(MSG_UNMOUNT), 'U'));
menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Mount All",
new BMessage(MSG_MOUNT_ALL), 'M', B_SHIFT_KEY));
rootMenu->AddItem(menu); 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'));
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)));
rootMenu->AddItem(menu);
AddChild(rootMenu); AddChild(rootMenu);
BRect r(Bounds()); BRect r(Bounds());
r.top = rootMenu->Frame().bottom +1; r.top = rootMenu->Frame().bottom + 1;
fListView = new PartitionListView(r); fListView = new PartitionListView(r);
AddChild(fListView); AddChild(fListView);
// Now update filesystem/partition menus with values // Populate the Initialiaze menu with the available file systems
BDiskSystem diskSystem; BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems(); fDDRoster.RewindDiskSystems();
while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) { while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.IsPartitioningSystem()) { if (diskSystem.IsFileSystem()) {
BMessage* msg = new BMessage(SETUP_PARTITION_SELECTED_MSG); BMessage* message = new BMessage(MSG_INITIALIZE);
msg->AddString("bdisksystem:name", diskSystem.Name()); message->AddString("format", diskSystem.Name());
partitionMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg)); BString label = diskSystem.PrettyName();
} else if (diskSystem.IsFileSystem()) { label << B_UTF8_ELLIPSIS;
BMessage* msg = new BMessage(SETUP_INITIALIZE_MSG); initMenu->AddItem(new BMenuItem(label.String(), message));
msg->AddString("bdisksystem:name", diskSystem.Name());
initMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg));
} }
} }
// Now visit all disks in the system and show their contents // Visit all disks in the system and show their contents
_ScanDrives();
}
void
MainWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
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_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;
default:
BWindow::MessageReceived(message);
break;
}
}
bool
MainWindow::QuitRequested()
{
// TODO: ask about any unsaved changes
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
// #pragma mark -
status_t
MainWindow::StoreSettings(BMessage* archive) const
{
if (archive->ReplaceRect("window frame", Frame()) < B_OK)
archive->AddRect("window frame", Frame());
// TODO: store column list settings
return B_OK;
}
status_t
MainWindow::RestoreSettings(BMessage* archive)
{
BRect frame;
if (archive->FindRect("window frame", &frame) == B_OK) {
BScreen screen(this);
if (frame.Intersects(screen.Frame())) {
MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height());
}
}
// TODO: restore column list settings
return B_OK;
}
// #pragma mark -
void
MainWindow::_ScanDrives()
{
DriveVisitor driveVisitor(fListView); DriveVisitor driveVisitor(fListView);
BPartition *partition = NULL; BPartition* partition = NULL;
BDiskDevice device; BDiskDevice device;
fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition); fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition);
} }
/**
* Handles messages.
* @param message The message recieved by the window.
*/
void MainWindow::MessageReceived(BMessage *message){
switch(message->what){ // #pragma mark - DriveVisitor
case MOUNT_MOUNT_ALL_MSG:
printf("MOUNT_MOUNT_ALL_MSG\n");
break;
case MOUNT_MOUNT_SELECTED_MSG:
printf("MOUNT_MOUNT_SELECTED_MSG\n");
break;
case UNMOUNT_UNMOUNT_SELECTED_MSG:
printf("UNMOUNT_UNMOUNT_SELECTED_MSG\n");
break;
case SETUP_FORMAT_MSG:
printf("SETUP_FORMAT_MSG\n");
break;
case SETUP_INITIALIZE_MSG:
printf("SETUP_INITIALIZE_MSG\n");
break;
case OPTIONS_EJECT_MSG:
printf("OPTIONS_EJECT_MSG\n");
break;
case OPTIONS_SURFACE_TEST_MSG:
printf("OPTIONS_SURFACE_TEST_MSG\n");
break;
case RESCAN_IDE_MSG:
printf("RESCAN_IDE_MSG\n");
break;
case RESCAN_SCSI_MSG:
printf("RESCAN_SCSI_MSG\n");
break;
default:
BWindow::MessageReceived(message);
}//switch
}
/**
* Quits and Saves settings.
*/
bool
MainWindow::QuitRequested()
{
bool accepted = BWindow::QuitRequested();
if (accepted) {
fSettings->SetWindowPosition(Frame());
be_app->PostMessage(B_QUIT_REQUESTED);
}
return accepted;
}
DriveVisitor::DriveVisitor(PartitionListView* list) DriveVisitor::DriveVisitor(PartitionListView* list)
: fPartitionList(list) : fPartitionList(list)
{ {
// start with an empty list
int32 rows = fPartitionList->CountRows();
for (int32 i = rows - 1; i >= 0; i--) {
BRow* row = fPartitionList->RowAt(i);
fPartitionList->RemoveRow(row);
delete row;
}
} }
bool bool
DriveVisitor::Visit(BDiskDevice* device) DriveVisitor::Visit(BDiskDevice* device)
{ {
if (fPartitionList != NULL) fPartitionList->AddPartition(device);
fPartitionList->AddPartition(device);
DEBUG_ONLY(
printf("Visit(%p)\n", device); printf("Visit(%p)\n", device);
dump_partition_info(device); dump_partition_info(device);
);
return false; // Don't stop yet! return false; // Don't stop yet!
} }
bool bool
DriveVisitor::Visit(BPartition* partition, int32 level) DriveVisitor::Visit(BPartition* partition, int32 level)
{ {
if (fPartitionList != NULL) fPartitionList->AddPartition(partition);
fPartitionList->AddPartition(partition);
DEBUG_ONLY( printf("Visit(%p, %ld)\n", partition, level);
printf("Visit(%p, %d)\n", partition, level);
dump_partition_info(partition); dump_partition_info(partition);
);
return false; // Don't stop yet! return false; // Don't stop yet!
} }
+39 -46
View File
@@ -1,52 +1,45 @@
/*! \file MainWindow.h /*
\brief Header for the MainWindow class. * Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/ */
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
#define 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_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'
#include <interface/Window.h> #include <DiskDeviceRoster.h>
#include <storage/DiskDeviceRoster.h> #include <Window.h>
// Forward declarations
class PosSettings;
class BPartition;
class BDiskDevice;
class PartitionListView;
/**
* The main window of the app.
*
* Sets up and displays everything you need for the app.
*/
class MainWindow : public BWindow class PosSettings;
{ class BPartition;
private: class BDiskDevice;
PosSettings* fSettings; class PartitionListView;
BDiskDeviceRoster fDDRoster;
PartitionListView* fListView;
public: class MainWindow : public BWindow {
MainWindow(BRect frame, PosSettings *fSettings); public:
MainWindow(BRect frame);
bool QuitRequested();
void MessageReceived(BMessage *message); // BWindow interface
virtual bool QuitRequested();
// These are public for visitor.... virtual void MessageReceived(BMessage* message);
void AddPartition(BPartition* partition, int32 level);
void AddDrive(BDiskDevice* device); // MainWindow
}; status_t StoreSettings(BMessage* archive) const;
status_t RestoreSettings(BMessage* archive);
#endif
// These are public for visitor....
void AddPartition(BPartition* partition,
int32 level);
void AddDrive(BDiskDevice* device);
private:
void _ScanDrives();
BDiskDeviceRoster fDDRoster;
PartitionListView* fListView;
};
#endif // MAIN_WINDOW_H
+38 -30
View File
@@ -1,15 +1,23 @@
/*
* Copyright 2006-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Ithamar R. Adema <[email protected]>
*/
#include "PartitionList.h" #include "PartitionList.h"
#include <interface/ColumnTypes.h> #include <ColumnTypes.h>
#include <storage/Path.h> #include <Path.h>
extern const char* extern const char*
SizeAsString(off_t size, char *string);; //FIXME: from MainWindow.cpp SizeAsString(off_t size, char* string); //FIXME: from MainWindow.cpp
PartitionListRow::PartitionListRow(BPartition* partition) PartitionListRow::PartitionListRow(BPartition* partition)
: Inherited(), : Inherited()
fPartitionID(partition->ID()) , fPartitionID(partition->ID())
{ {
BPath path; BPath path;
char size[1024]; char size[1024];
@@ -23,50 +31,47 @@ PartitionListRow::PartitionListRow(BPartition* partition)
else else
SetField(new BStringField(""), 1); SetField(new BStringField(""), 1);
if (partition->ContainsPartitioningSystem()) { // if (partition->ContainsPartitioningSystem()) {
SetField(new BStringField(partition->ContentType()), 2); // SetField(new BStringField(partition->ContentType()), 2);
} else { // } else {
SetField(new BStringField("n/a"), 2); // SetField(new BStringField("n/a"), 2);
} // }
// For now, Partition type is always empty (as we do not care)
SetField(new BStringField(""), 3);
if (partition->ContainsFileSystem()) { if (partition->ContainsFileSystem()) {
SetField(new BStringField(partition->ContentType()), 4); // Filesystem SetField(new BStringField(partition->ContentType()), 2); // Filesystem
SetField(new BStringField(partition->ContentName()), 5); // Volume Name SetField(new BStringField(partition->ContentName()), 3); // Volume Name
} else { } else {
SetField(new BStringField(""), 4); SetField(new BStringField(""), 2);
SetField(new BStringField(""), 5); SetField(new BStringField(""), 3);
} }
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) { if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
SetField(new BStringField(path.Path()), 6); SetField(new BStringField(path.Path()), 4);
} else { } else {
SetField(new BStringField(""), 6); SetField(new BStringField(""), 4);
} }
SetField(new BStringField(SizeAsString(partition->Size(), size)), 7); SetField(new BStringField(SizeAsString(partition->Size(), size)), 5);
} }
PartitionListView::PartitionListView(const BRect& frame) PartitionListView::PartitionListView(const BRect& frame)
: Inherited(frame, "storagelist", B_FOLLOW_ALL, 0, B_PLAIN_BORDER, true) : Inherited(frame, "storagelist", B_FOLLOW_ALL, 0, B_NO_BORDER, true)
{ {
AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), 0); AddColumn(new BBitmapColumn("", 20, 20, 100, B_ALIGN_CENTER), 0);
AddColumn(new BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1); AddColumn(new BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1);
AddColumn(new BStringColumn("Map style", 100, 50, 500, B_TRUNCATE_MIDDLE), 2); AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
AddColumn(new BStringColumn("Partition Type", 100, 50, 500, B_TRUNCATE_MIDDLE), 3); AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 4); AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 5); AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 5);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 6);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 7);
} }
PartitionListRow* PartitionListRow*
PartitionListView::FindRow(partition_id id) PartitionListView::FindRow(partition_id id)
{ {
for (int32 idx=0; idx < CountRows(); idx++) { for (int32 i = 0; i < CountRows(); i++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(idx)); PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(i));
if (item != NULL && item->ID() == id) if (item != NULL && item->ID() == id)
return item; return item;
} }
@@ -74,6 +79,7 @@ PartitionListView::FindRow(partition_id id)
return NULL; return NULL;
} }
PartitionListRow* PartitionListRow*
PartitionListView::AddPartition(BPartition* partition) PartitionListView::AddPartition(BPartition* partition)
{ {
@@ -81,7 +87,7 @@ PartitionListView::AddPartition(BPartition* partition)
PartitionListRow* partitionrow = NULL; PartitionListRow* partitionrow = NULL;
// Forget about it if this partition is already in the listview // Forget about it if this partition is already in the listview
if ((partitionrow=FindRow(partition->ID())) != NULL) if ((partitionrow = FindRow(partition->ID())) != NULL)
return partitionrow; return partitionrow;
// Create the row for this partition // Create the row for this partition
@@ -89,6 +95,7 @@ PartitionListView::AddPartition(BPartition* partition)
// If this partition has a parent... // If this partition has a parent...
if (partition->Parent() != NULL) { if (partition->Parent() != NULL) {
printf("partition has parent\n");
// check if it is in the listview // check if it is in the listview
parent = FindRow(partition->Parent()->ID()); parent = FindRow(partition->Parent()->ID());
// If parent of this partition is not yet in the list // If parent of this partition is not yet in the list
@@ -97,6 +104,7 @@ PartitionListView::AddPartition(BPartition* partition)
// Now it is ok to add this partition under its parent // Now it is ok to add this partition under its parent
AddRow(partitionrow, parent); AddRow(partitionrow, parent);
} else { } else {
printf("partition has NO parent\n");
// If this partition has no parent, add it in the 'root' // If this partition has no parent, add it in the 'root'
AddRow(partitionrow); AddRow(partitionrow);
} }
+21 -14
View File
@@ -1,34 +1,41 @@
/*
* Copyright 2006-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/
#ifndef PARTITIONLIST_H #ifndef PARTITIONLIST_H
#define PARTITIONLIST_H #define PARTITIONLIST_H
class PartitionListRow; class PartitionListRow;
class PartitionListView; class PartitionListView;
#include <interface/ColumnListView.h>
#include <storage/Partition.h>
// Forward declarations #include <ColumnListView.h>
#include <Partition.h>
class BPartition; class BPartition;
class PartitionListRow : public BRow
{ class PartitionListRow : public BRow {
typedef BRow Inherited; typedef BRow Inherited;
public: public:
PartitionListRow(BPartition* partition); PartitionListRow(BPartition* partition);
partition_id ID() { return fPartitionID; } partition_id ID() { return fPartitionID; }
private: private:
partition_id fPartitionID; partition_id fPartitionID;
}; };
class PartitionListView : public BColumnListView
{ class PartitionListView : public BColumnListView {
typedef BColumnListView Inherited; typedef BColumnListView Inherited;
public: public:
PartitionListView(const BRect& frame); PartitionListView(const BRect& frame);
PartitionListRow* FindRow(partition_id id); PartitionListRow* FindRow(partition_id id);
PartitionListRow* AddPartition(BPartition* partition); PartitionListRow* AddPartition(BPartition* partition);
}; };
#endif /* PARTITIONLIST_H */
#endif // PARTITIONLIST_H
@@ -1,85 +0,0 @@
#ifndef POS_SETTINGS_H
#include "PosSettings.h"
#endif
#ifndef _APPLICATION_H
#include <Application.h>
#endif
#ifndef _FILE_H
#include <File.h>
#endif
#ifndef _PATH_H
#include <Path.h>
#endif
#ifndef _FINDDIRECTORY_H
#include <FindDirectory.h>
#endif
#include <stdio.h>
const char PosSettings::kSettingsFile[] = "DriveSetup_prefs";
PosSettings::PosSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) == B_OK)
{
path.Append(kSettingsFile);
BFile file(path.Path(), B_READ_ONLY);
if (file.InitCheck() != B_OK)
be_app->PostMessage(B_QUIT_REQUESTED);
// Now read in the data
if (file.Read(&fcorner, sizeof(BPoint)) != sizeof(BPoint))
be_app->PostMessage(B_QUIT_REQUESTED);
if (file.Read(&brCorner, sizeof(BPoint)) != sizeof(BPoint))
be_app->PostMessage(B_QUIT_REQUESTED);
}
printf("settings file read.\n");
printf("=========================\n");
printf("fcorner read in as ");
fcorner.PrintToStream();
printf("brCorner read in as ");
brCorner.PrintToStream();
fWindowFrame.left=fcorner.x;
fWindowFrame.top=fcorner.y;
fWindowFrame.right=brCorner.x;
fWindowFrame.bottom=brCorner.y;
//Check to see if the co-ords of the window are in the range of the Screen
BScreen screen;
if (screen.Frame().right >= fWindowFrame.right
&& screen.Frame().bottom >= fWindowFrame.bottom)
return;
// If they are not, lets just stick the window in the middle
// of the screen.
fWindowFrame = screen.Frame();
fWindowFrame.left = (fWindowFrame.right-269) /2;
fWindowFrame.right = fWindowFrame.left + 269;
fWindowFrame.top = (fWindowFrame.bottom-172) /2;
fWindowFrame.bottom = fWindowFrame.top + 172;
}
PosSettings::~PosSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY,&path) < B_OK)
return;
path.Append(kSettingsFile);
BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE);
if (file.InitCheck() == B_OK)
{
file.Write(&fcorner, sizeof(BPoint));
file.Write(&brCorner, sizeof(BPoint));
}
}
void PosSettings::SetWindowPosition(BRect f)
{
fcorner.x=f.left;
fcorner.y=f.top;
brCorner.x=f.right;
brCorner.y=f.bottom;
brCorner.PrintToStream();
}
-21
View File
@@ -1,21 +0,0 @@
#ifndef POS_SETTINGS_H_
#define POS_SETTINGS_H_
#include <SupportDefs.h>
#include <Screen.h>
class PosSettings{
public :
PosSettings();
virtual ~PosSettings();
BRect WindowPosition() const { return fWindowFrame; }
void SetWindowPosition(BRect);
private:
static const char kSettingsFile[];
BRect fWindowFrame;
BPoint fcorner;
BPoint brCorner;
};
#endif
+130 -45
View File
@@ -1,53 +1,138 @@
/*! \file main.cpp
* \brief Code for the main class.
*
* This file contains the code for the main class. This class sets up all
* of the initial conditions for the app.
*
*/
#include "MainWindow.h"
#include "main.h"
#include "PosSettings.h"
/**
* Main method.
*
* Starts the whole thing.
*/
int main(int, char**){
/**
* An instance of the application.
*/
DriveSetup dsApp;
dsApp.Run();
return(0);
}
/* /*
* Constructor. * Copyright 2002-2007 Haiku Inc. All rights reserved.
* * Distributed under the terms of the MIT license.
* Provides a contstructor for the application. *
* Authors:
* Erik Jaesler <[email protected]>
* Ithamar R. Adema <[email protected]>
* Stephan Aßmus <[email protected]>
*/ */
DriveSetup::DriveSetup() #include "main.h"
: BApplication("application/x-vnd.MSM-DriveSetupPrefPanel") #include "MainWindow.h"
#include <stdio.h>
#include <string.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
int
main(int, char**)
{ {
DriveSetup app;
fSettings = new PosSettings(); app.Run();
return 0;
/*
* The main interface window.
*/
MainWindow *Main = new MainWindow(fSettings->WindowPosition(), fSettings);
Main->Show();
} }
// #pragma mark -
DriveSetup::DriveSetup()
: BApplication("application/x-vnd.Haiku-DriveSetup")
, fWindow(NULL)
, fSettings(0UL)
{
}
DriveSetup::~DriveSetup() DriveSetup::~DriveSetup()
{ {
delete fSettings;
} }
void
DriveSetup::ReadyToRun()
{
fWindow = new MainWindow(BRect(50, 50, 600, 450));
_RestoreSettings();
fWindow->Show();
}
bool
DriveSetup::QuitRequested()
{
_StoreSettings();
if (fWindow->Lock()) {
fWindow->Quit();
fWindow = NULL;
}
return true;
}
// #pragma mark -
status_t
DriveSetup::_StoreSettings()
{
status_t ret = B_ERROR;
if (fWindow->Lock()) {
ret = fWindow->StoreSettings(&fSettings);
fWindow->Unlock();
}
if (ret < B_OK)
return ret;
BFile file;
ret = _GetSettingsFile(file, true);
if (ret < B_OK)
return ret;
return fSettings.Flatten(&file);
}
status_t
DriveSetup::_RestoreSettings()
{
BFile file;
status_t ret = _GetSettingsFile(file, false);
if (ret >= B_OK)
ret = fSettings.Unflatten(&file);
if (ret >= B_OK)
ret = fWindow->RestoreSettings(&fSettings);
return ret;
}
status_t
DriveSetup::_GetSettingsFile(BFile& file, bool forWriting) const
{
BPath path;
status_t ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
if (ret != B_OK) {
fprintf(stderr, "failed to get user settings folder: %s\n",
strerror(ret));
return ret;
}
ret = path.Append("DriveSetup");
if (ret != B_OK) {
fprintf(stderr, "failed to construct path: %s\n", strerror(ret));
return ret;
}
uint32 writeFlags = B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY;
uint32 readFlags = B_READ_ONLY;
ret = file.SetTo(path.Path(), forWriting ? writeFlags : readFlags);
if (ret != B_OK) {
fprintf(stderr, "failed to init file: %s\n", strerror(ret));
return ret;
}
return B_OK;
}
+33 -29
View File
@@ -1,33 +1,37 @@
/*! \file main.h /*
\brief Header file for the main class. * Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*/ */
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H #define MAIN_H
#include <Application.h> #include <Application.h>
#include <Message.h>
class BFile;
class MainWindow;
class PosSettings; class DriveSetup : public BApplication {
public:
DriveSetup();
/** virtual ~DriveSetup();
* Main class.
* virtual void ReadyToRun();
* Gets everything going. virtual bool QuitRequested();
*/
class DriveSetup : public BApplication private:
{ status_t _StoreSettings();
public: status_t _RestoreSettings();
status_t _GetSettingsFile(BFile& file,
/** bool forWriting) const;
* Constructor.
*/ MainWindow* fWindow;
DriveSetup();
virtual ~DriveSetup(); BMessage fSettings;
};
private:
PosSettings *fSettings;
}; #endif // MAIN_H
#endif