now populates menus

improved size to string formating for GB and TB


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14531 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2005-10-26 19:45:38 +00:00
parent 6a4b16f094
commit 1eedf23081
7 changed files with 87 additions and 18 deletions

View File

@ -10,6 +10,8 @@
#include <DiskDeviceTypes.h>
#include <Path.h>
extern void SizeAsString(int32 size, char *string);
class SourceVisitor : public BDiskDeviceVisitor
{
public:
@ -28,6 +30,7 @@ public:
virtual bool Visit(BDiskDevice *device);
virtual bool Visit(BPartition *partition, int32 level);
private:
void MakeLabel(BPartition *partition, char *label, char *menuLabel);
BMenu *fMenu;
};
@ -103,8 +106,9 @@ SourceVisitor::Visit(BDiskDevice *device)
return false;
BPath path;
if (device->GetPath(&path)==B_OK)
printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n", path.Path(), device->Type(), device->ContentType());
fMenu->AddItem(new PartitionMenuItem(device->Name(), new BMessage(SRC_PARTITION), device->ID()));
printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n",
path.Path(), device->Type(), device->ContentType());
fMenu->AddItem(new PartitionMenuItem(NULL, device->ContentName(), NULL, new BMessage(SRC_PARTITION), device->ID()));
return false;
}
@ -118,7 +122,7 @@ SourceVisitor::Visit(BPartition *partition, int32 level)
if (partition->GetPath(&path)==B_OK)
printf("SourceVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("SourceVisitor::Visit(BPartition *) : %s\n", partition->Name());
fMenu->AddItem(new PartitionMenuItem(partition->Name(), new BMessage(SRC_PARTITION), partition->ID()));
fMenu->AddItem(new PartitionMenuItem(NULL, partition->ContentName(), NULL, new BMessage(SRC_PARTITION), partition->ID()));
return false;
}
@ -137,7 +141,9 @@ TargetVisitor::Visit(BDiskDevice *device)
BPath path;
if (device->GetPath(&path)==B_OK)
printf("TargetVisitor::Visit(BDiskDevice *) : %s\n", path.Path());
fMenu->AddItem(new PartitionMenuItem(device->Name(), new BMessage(TARGET_PARTITION), device->ID()));
char label[255], menuLabel[255];
MakeLabel(device, label, menuLabel);
fMenu->AddItem(new PartitionMenuItem(device->ContentName(), label, menuLabel, new BMessage(TARGET_PARTITION), device->ID()));
return false;
}
@ -151,6 +157,25 @@ TargetVisitor::Visit(BPartition *partition, int32 level)
if (partition->GetPath(&path)==B_OK)
printf("TargetVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("TargetVisitor::Visit(BPartition *) : %s\n", partition->Name());
fMenu->AddItem(new PartitionMenuItem(partition->Name(), new BMessage(TARGET_PARTITION), partition->ID()));
char label[255], menuLabel[255];
MakeLabel(partition, label, menuLabel);
fMenu->AddItem(new PartitionMenuItem(partition->ContentName(), label, menuLabel, new BMessage(TARGET_PARTITION), partition->ID()));
return false;
}
void
TargetVisitor::MakeLabel(BPartition *partition, char *label, char *menuLabel)
{
char size[15];
SizeAsString(partition->ContentSize(), size);
BPath path;
if (partition->Parent())
partition->Parent()->GetPath(&path);
sprintf(label, "%s - %s [%s] [%s partition:%li]", partition->ContentName(), size, partition->ContentType(),
path.Path(), partition->ID());
sprintf(menuLabel, "%s - %s [%s]", partition->ContentName(), size, partition->ContentType());
}

View File

@ -24,6 +24,7 @@ public:
private:
void LaunchInitScript(BVolume *volume);
void LaunchFinishScript(BVolume *volume);
InstallerWindow *fWindow;
BDiskDeviceRoster fDDRoster;
};

View File

@ -113,8 +113,8 @@ InstallerWindow::InstallerWindow(BRect frame_rect)
"options_button", "Fewer options", "More options", new BMessage(SHOW_BOTTOM_MESSAGE));
fBackBox->AddChild(fDrawButton);
fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS);
fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS);
fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
BRect fieldRect(bounds.left+50, bounds.top+70, bounds.right-13, bounds.top+90);
fSrcMenuField = new BMenuField(fieldRect, "srcMenuField",
@ -170,6 +170,10 @@ InstallerWindow::MessageReceived(BMessage *msg)
break;
case SRC_PARTITION:
PublishPackages();
AdjustMenus();
break;
case TARGET_PARTITION:
AdjustMenus();
break;
case SETUP_MESSAGE:
LaunchDriveSetup();
@ -271,17 +275,34 @@ InstallerWindow::StartScan()
fCopyEngine.ScanDisksPartitions(fSrcMenu, fDestMenu);
/*fSrcMenu->AddItem(new PartitionMenuItem("BeOS 5 PE Max Edition V3.1 beta",
new BMessage(SRC_PARTITION), "/BeOS 5 PE Max Edition V3.1 beta"));
*/
if (fSrcMenu->ItemAt(0)) {
fSrcMenu->ItemAt(0)->SetMarked(true);
PublishPackages();
}
AdjustMenus();
SetStatusMessage("Choose the disk you want to install onto from the pop-up menu. Then click \"Begin\".");
}
void
InstallerWindow::AdjustMenus()
{
PartitionMenuItem *item1 = (PartitionMenuItem *)fSrcMenu->FindMarked();
if (!item1) {
} else {
fSrcMenuField->MenuItem()->SetLabel(item1->MenuLabel());
}
PartitionMenuItem *item2 = (PartitionMenuItem *)fDestMenu->FindMarked();
if (!item2) {
} else {
fDestMenuField->MenuItem()->SetLabel(item2->MenuLabel());
}
char message[255];
sprintf(message, "Press the Begin button to install from '%s' onto '%s'", item1->Name(), item2->Name());
SetStatusMessage(message);
}
void
InstallerWindow::PublishPackages()
{
@ -295,10 +316,10 @@ InstallerWindow::PublishPackages()
BDiskDevice device;
BPartition *partition;
if (roster.GetPartitionWithID(item->ID(), &device, &partition) == B_OK) {
if (partition->GetPath(&directory)!=B_OK)
if (partition->GetMountPoint(&directory)!=B_OK)
return;
} else if (roster.GetDeviceWithID(item->ID(), &device) == B_OK) {
if (device.GetPath(&directory)!=B_OK)
if (device.GetMountPoint(&directory)!=B_OK)
return;
} else
return; // shouldn't happen

View File

@ -33,6 +33,7 @@ private:
void PublishPackages();
void ShowBottom();
void StartScan();
void AdjustMenus();
static int ComparePackages(const void *firstArg, const void *secondArg);
BBox *fBackBox;
BButton *fBeginButton, *fSetupButton;

View File

@ -13,7 +13,9 @@
#define ICON_ATTRIBUTE "INSTALLER PACKAGE: ICON"
static void
void SizeAsString(int32 size, char *string);
void
SizeAsString(int32 size, char *string)
{
float kb = size / 1024.0;
@ -26,7 +28,17 @@ SizeAsString(int32 size, char *string)
sprintf(string, "%3.1f KB", kb);
return;
}
sprintf(string, "%3.1f MB", mb);
float gb = mb / 1024.0;
if (gb < 1.0) {
sprintf(string, "%3.1f MB", mb);
return;
}
float tb = gb / 1024.0;
if (tb < 1.0) {
sprintf(string, "%3.1f GB", gb);
return;
}
sprintf(string, "%3.1f TB", tb);
}

View File

@ -9,14 +9,18 @@
#include "PartitionMenuItem.h"
PartitionMenuItem::PartitionMenuItem(const char *label, BMessage *msg, partition_id id)
PartitionMenuItem::PartitionMenuItem(const char *name, const char *label, const char *menuLabel,
BMessage *msg, partition_id id)
: BMenuItem(label, msg)
{
fID = id;
fMenuLabel = strdup(menuLabel);
fName = strdup(name);
}
PartitionMenuItem::~PartitionMenuItem()
{
free(fMenuLabel);
free(fName);
}

View File

@ -14,11 +14,16 @@ const uint32 TARGET_PARTITION = 'iTPT';
class PartitionMenuItem : public BMenuItem {
public:
PartitionMenuItem(const char *label, BMessage *msg, partition_id id);
PartitionMenuItem(const char *name, const char *label,
const char* menuLabel, BMessage *msg, partition_id id);
~PartitionMenuItem();
partition_id ID() const { return fID; };
const char *MenuLabel() { return fMenuLabel ? fMenuLabel : Label(); };
const char *Name() { return fName ? fName : Label(); };
private:
partition_id fID;
char *fMenuLabel;
char *fName;
};
#endif /* __PARTITIONMENUITEM_H_ */