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

View File

@ -19,7 +19,7 @@
#include "InstallerWindow.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 SHOW_BOTTOM_MESSAGE = 'iSBT';

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"
$"FFFFFFFFFFFFFFFFFFFFFFFF00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
@ -37,8 +53,7 @@ resource(101, "BEOS:L:STD_ICON") #'ICON' array
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
resource(101, "BEOS:M:STD_ICON") #'MICN' array
{
resource mini_icon {
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FF0000FFFFFF0000FFFFFFFFFF0000FF"
@ -57,32 +72,3 @@ resource(101, "BEOS:M:STD_ICON") #'MICN' array
$"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";

View File

@ -1,9 +1,15 @@
SubDir HAIKU_TOP src preferences drivesetup ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders interface storage shared ;
AddResources DriveSetup : DriveSetup.rdef ;
Preference DriveSetup : main.cpp MainWindow.cpp PartitionList.cpp PosSettings.cpp ;
LinkAgainst DriveSetup : be ;
Preference DriveSetup :
main.cpp
MainWindow.cpp
PartitionList.cpp
:
be
;

View File

@ -1,36 +1,38 @@
/*! \file MainWindow.cpp
* \brief Code for the MainWindow class.
*
* Displays the main window, the essence of the app.
/*
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
*/
* Authors:
* Erik Jaesler <ejakowatz@users.sourceforge.net>
* Ithamar R. Adema <ithamar@unet.nl>
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "MainWindow.h"
#include "PartitionList.h"
#include "PosSettings.h"
#include <interface/MenuItem.h>
#include <interface/MenuBar.h>
#include <interface/Menu.h>
#include <Application.h>
#include <interface/ColumnListView.h>
#include <interface/ColumnTypes.h>
#include <DiskDeviceVisitor.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:
DriveVisitor(PartitionListView* list);
bool Visit(BDiskDevice *device);
bool Visit(BPartition *partition, int32 level);
virtual bool Visit(BDiskDevice* device);
virtual bool Visit(BPartition* partition, int32 level);
private:
PartitionListView* fPartitionList;
};
@ -62,7 +64,7 @@ SizeAsString(off_t size, char *string)
return string;
}
#if DEBUG
static void
dump_partition_info(BPartition* partition)
{
@ -86,187 +88,202 @@ dump_partition_info(BPartition* partition)
printf("\tContentType(): %s\n", partition->ContentType());
printf("\tID(): %lx\n\n", partition->ID());
}
#endif
/**
* Constructor.
* @param frame The size to make the window.
*/
MainWindow::MainWindow(BRect frame, PosSettings *Settings)
: BWindow(frame, "DriveSetup", B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
enum {
MSG_MOUNT_ALL = 'mnta',
MSG_MOUNT = 'mnts',
MSG_UNMOUNT = 'unmt',
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");
//Setup Mount menu
menu = new BMenu("Mount");
menu->AddItem(new BMenuItem("Mount All Partitions", new BMessage(MOUNT_MOUNT_ALL_MSG), 'M'));
menu->AddSeparatorItem();
// Disk menu
BMenu* menu = new BMenu("Disk");
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);
//Setup Unmount menu
menu = new BMenu("Unmount");
rootMenu->AddItem(menu);
//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
// Parition menu
menu = new BMenu("Partition");
BMenu* initMenu = new BMenu("Initialize");
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);
//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);
BRect r(Bounds());
r.top = rootMenu->Frame().bottom +1;
r.top = rootMenu->Frame().bottom + 1;
fListView = new PartitionListView(r);
AddChild(fListView);
// Now update filesystem/partition menus with values
// Populate the Initialiaze menu with the available file systems
BDiskSystem diskSystem;
fDDRoster.RewindDiskSystems();
while(fDDRoster.GetNextDiskSystem(&diskSystem) == B_OK) {
if (diskSystem.IsPartitioningSystem()) {
BMessage* msg = new BMessage(SETUP_PARTITION_SELECTED_MSG);
msg->AddString("bdisksystem:name", diskSystem.Name());
partitionMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg));
} else if (diskSystem.IsFileSystem()) {
BMessage* msg = new BMessage(SETUP_INITIALIZE_MSG);
msg->AddString("bdisksystem:name", diskSystem.Name());
initMenu->AddItem(new BMenuItem(diskSystem.PrettyName(), msg));
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));
}
}
// 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);
BPartition *partition = NULL;
BPartition* partition = NULL;
BDiskDevice device;
fDDRoster.VisitEachPartition(&driveVisitor, &device, &partition);
}
/**
* Handles messages.
* @param message The message recieved by the window.
*/
void MainWindow::MessageReceived(BMessage *message){
switch(message->what){
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
}
// #pragma mark - DriveVisitor
/**
* 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)
: 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
DriveVisitor::Visit(BDiskDevice* device)
{
if (fPartitionList != NULL)
fPartitionList->AddPartition(device);
fPartitionList->AddPartition(device);
DEBUG_ONLY(
printf("Visit(%p)\n", device);
dump_partition_info(device);
);
return false; // Don't stop yet!
}
bool
DriveVisitor::Visit(BPartition* partition, int32 level)
{
if (fPartitionList != NULL)
fPartitionList->AddPartition(partition);
fPartitionList->AddPartition(partition);
DEBUG_ONLY(
printf("Visit(%p, %d)\n", partition, level);
printf("Visit(%p, %ld)\n", partition, level);
dump_partition_info(partition);
);
return false; // Don't stop yet!
}

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
#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 <storage/DiskDeviceRoster.h>
#include <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
{
private:
PosSettings* fSettings;
BDiskDeviceRoster fDDRoster;
PartitionListView* fListView;
public:
MainWindow(BRect frame, PosSettings *fSettings);
bool QuitRequested();
void MessageReceived(BMessage *message);
// These are public for visitor....
void AddPartition(BPartition* partition, int32 level);
void AddDrive(BDiskDevice* device);
};
#endif
class PosSettings;
class BPartition;
class BDiskDevice;
class PartitionListView;
class MainWindow : public BWindow {
public:
MainWindow(BRect frame);
// BWindow interface
virtual bool QuitRequested();
virtual void MessageReceived(BMessage* message);
// MainWindow
status_t StoreSettings(BMessage* archive) const;
status_t RestoreSettings(BMessage* archive);
// 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

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 <ithamar@unet.nl>
*/
#include "PartitionList.h"
#include <interface/ColumnTypes.h>
#include <storage/Path.h>
#include <ColumnTypes.h>
#include <Path.h>
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)
: Inherited(),
fPartitionID(partition->ID())
: Inherited()
, fPartitionID(partition->ID())
{
BPath path;
char size[1024];
@ -23,50 +31,47 @@ PartitionListRow::PartitionListRow(BPartition* partition)
else
SetField(new BStringField(""), 1);
if (partition->ContainsPartitioningSystem()) {
SetField(new BStringField(partition->ContentType()), 2);
} else {
SetField(new BStringField("n/a"), 2);
}
// For now, Partition type is always empty (as we do not care)
SetField(new BStringField(""), 3);
// if (partition->ContainsPartitioningSystem()) {
// SetField(new BStringField(partition->ContentType()), 2);
// } else {
// SetField(new BStringField("n/a"), 2);
// }
if (partition->ContainsFileSystem()) {
SetField(new BStringField(partition->ContentType()), 4); // Filesystem
SetField(new BStringField(partition->ContentName()), 5); // Volume Name
SetField(new BStringField(partition->ContentType()), 2); // Filesystem
SetField(new BStringField(partition->ContentName()), 3); // Volume Name
} else {
SetField(new BStringField(""), 4);
SetField(new BStringField(""), 5);
SetField(new BStringField(""), 2);
SetField(new BStringField(""), 3);
}
if (partition->IsMounted() && partition->GetMountPoint(&path) == B_OK) {
SetField(new BStringField(path.Path()), 6);
SetField(new BStringField(path.Path()), 4);
} 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)
: 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 BStringColumn("Device", 100, 50, 500, B_TRUNCATE_MIDDLE), 1);
AddColumn(new BStringColumn("Map style", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
AddColumn(new BStringColumn("Partition Type", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 5);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 6);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 7);
AddColumn(new BStringColumn("Filesystem", 100, 50, 500, B_TRUNCATE_MIDDLE), 2);
AddColumn(new BStringColumn("Volume Name", 100, 50, 500, B_TRUNCATE_MIDDLE), 3);
AddColumn(new BStringColumn("Mounted At", 100, 50, 500, B_TRUNCATE_MIDDLE), 4);
AddColumn(new BStringColumn("Size", 100, 50, 500, B_TRUNCATE_END), 5);
}
PartitionListRow*
PartitionListView::FindRow(partition_id id)
{
for (int32 idx=0; idx < CountRows(); idx++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(idx));
for (int32 i = 0; i < CountRows(); i++) {
PartitionListRow* item = dynamic_cast<PartitionListRow*>(RowAt(i));
if (item != NULL && item->ID() == id)
return item;
}
@ -74,6 +79,7 @@ PartitionListView::FindRow(partition_id id)
return NULL;
}
PartitionListRow*
PartitionListView::AddPartition(BPartition* partition)
{
@ -81,7 +87,7 @@ PartitionListView::AddPartition(BPartition* partition)
PartitionListRow* partitionrow = NULL;
// 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;
// Create the row for this partition
@ -89,6 +95,7 @@ PartitionListView::AddPartition(BPartition* partition)
// If this partition has a parent...
if (partition->Parent() != NULL) {
printf("partition has parent\n");
// check if it is in the listview
parent = FindRow(partition->Parent()->ID());
// 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
AddRow(partitionrow, parent);
} else {
printf("partition has NO parent\n");
// If this partition has no parent, add it in the 'root'
AddRow(partitionrow);
}

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
#define PARTITIONLIST_H
class PartitionListRow;
class PartitionListView;
#include <interface/ColumnListView.h>
#include <storage/Partition.h>
// Forward declarations
#include <ColumnListView.h>
#include <Partition.h>
class BPartition;
class PartitionListRow : public BRow
{
class PartitionListRow : public BRow {
typedef BRow Inherited;
public:
PartitionListRow(BPartition* partition);
PartitionListRow(BPartition* partition);
partition_id ID() { return fPartitionID; }
partition_id ID() { return fPartitionID; }
private:
partition_id fPartitionID;
partition_id fPartitionID;
};
class PartitionListView : public BColumnListView
{
class PartitionListView : public BColumnListView {
typedef BColumnListView Inherited;
public:
PartitionListView(const BRect& frame);
PartitionListView(const BRect& frame);
PartitionListRow* FindRow(partition_id id);
PartitionListRow* AddPartition(BPartition* partition);
PartitionListRow* FindRow(partition_id id);
PartitionListRow* AddPartition(BPartition* partition);
};
#endif /* PARTITIONLIST_H */
#endif // PARTITIONLIST_H

View File

@ -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();
}

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

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.
*
* Provides a contstructor for the application.
* Copyright 2002-2007 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Authors:
* Erik Jaesler <ejakowatz@users.sourceforge.net>
* Ithamar R. Adema <ithamar@unet.nl>
* Stephan Aßmus <superstippi@gmx.de>
*/
DriveSetup::DriveSetup()
: BApplication("application/x-vnd.MSM-DriveSetupPrefPanel")
#include "main.h"
#include "MainWindow.h"
#include <stdio.h>
#include <string.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
int
main(int, char**)
{
fSettings = new PosSettings();
/*
* The main interface window.
*/
MainWindow *Main = new MainWindow(fSettings->WindowPosition(), fSettings);
Main->Show();
DriveSetup app;
app.Run();
return 0;
}
// #pragma mark -
DriveSetup::DriveSetup()
: BApplication("application/x-vnd.Haiku-DriveSetup")
, fWindow(NULL)
, fSettings(0UL)
{
}
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;
}

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
#define MAIN_H
#include <Application.h>
#include <Application.h>
#include <Message.h>
class BFile;
class MainWindow;
class PosSettings;
/**
* Main class.
*
* Gets everything going.
*/
class DriveSetup : public BApplication
{
public:
/**
* Constructor.
*/
DriveSetup();
virtual ~DriveSetup();
private:
PosSettings *fSettings;
};
#endif
class DriveSetup : public BApplication {
public:
DriveSetup();
virtual ~DriveSetup();
virtual void ReadyToRun();
virtual bool QuitRequested();
private:
status_t _StoreSettings();
status_t _RestoreSettings();
status_t _GetSettingsFile(BFile& file,
bool forWriting) const;
MainWindow* fWindow;
BMessage fSettings;
};
#endif // MAIN_H