* Remember in PartitionMenuItem if a partition is a suitable install target.

* Show non-BFS partitions again, but show them disabled and show the content
  type in the menu label. BFS partitions don't get the content type shown, so
  that it looks more like the reason why they are disabled if the content
  type is shown.
* Small cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30611 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2009-05-03 17:35:09 +00:00
parent 517256e7d7
commit fab3e4a5b2
4 changed files with 83 additions and 55 deletions

View File

@ -633,18 +633,17 @@ InstallerWindow::_UpdateControls()
}
fSrcMenuField->MenuItem()->SetLabel(label.String());
if (srcItem) {
// Prevent the user from having picked the same partition as source
// and destination.
for (int32 i = fDestMenu->CountItems() - 1; i >= 0; i--) {
PartitionMenuItem* dstItem
= (PartitionMenuItem*)fDestMenu->ItemAt(i);
if (dstItem->ID() == srcItem->ID()) {
dstItem->SetEnabled(false);
dstItem->SetMarked(false);
} else
dstItem->SetEnabled(true);
}
// Disable any unsuitable target items
for (int32 i = fDestMenu->CountItems() - 1; i >= 0; i--) {
PartitionMenuItem* dstItem
= (PartitionMenuItem*)fDestMenu->ItemAt(i);
if (srcItem != NULL && dstItem->ID() == srcItem->ID()) {
// Prevent the user from having picked the same partition as source
// and destination.
dstItem->SetEnabled(false);
dstItem->SetMarked(false);
} else
dstItem->SetEnabled(dstItem->IsValidTarget());
}
PartitionMenuItem* dstItem = (PartitionMenuItem*)fDestMenu->FindMarked();

View File

@ -12,11 +12,12 @@
PartitionMenuItem::PartitionMenuItem(const char* name, const char* label,
const char* menuLabel, BMessage* message, partition_id id)
:
BMenuItem(label, message)
BMenuItem(label, message),
fID(id),
fMenuLabel(strdup(menuLabel)),
fName(strdup(name)),
fIsValidTarget(true)
{
fID = id;
fMenuLabel = strdup(menuLabel);
fName = strdup(name);
}
@ -37,13 +38,27 @@ PartitionMenuItem::ID() const
const char*
PartitionMenuItem::MenuLabel() const
{
return fMenuLabel ? fMenuLabel : Label();
return fMenuLabel != NULL ? fMenuLabel : Label();
}
const char*
PartitionMenuItem::Name() const
{
return fName ? fName : Label();
return fName != NULL ? fName : Label();
}
void
PartitionMenuItem::SetIsValidTarget(bool isValidTarget)
{
fIsValidTarget = isValidTarget;
}
bool
PartitionMenuItem::IsValidTarget() const
{
return fIsValidTarget;
}

View File

@ -24,10 +24,14 @@ public:
const char* MenuLabel() const;
const char* Name() const;
void SetIsValidTarget(bool isValidTarget);
bool IsValidTarget() const;
private:
partition_id fID;
char* fMenuLabel;
char* fName;
bool fIsValidTarget;
};
#endif // PARTITION_MENU_ITEM_H_

View File

@ -42,32 +42,34 @@
const char BOOT_PATH[] = "/boot";
extern void SizeAsString(off_t size, char *string);
extern void SizeAsString(off_t size, char* string);
const uint32 MSG_START_INSTALLING = 'eSRT';
class SourceVisitor : public BDiskDeviceVisitor
{
public:
SourceVisitor(BMenu *menu);
virtual bool Visit(BDiskDevice *device);
virtual bool Visit(BPartition *partition, int32 level);
private:
BMenu *fMenu;
class SourceVisitor : public BDiskDeviceVisitor {
public:
SourceVisitor(BMenu* menu);
virtual bool Visit(BDiskDevice* device);
virtual bool Visit(BPartition* partition, int32 level);
private:
BMenu* fMenu;
};
class TargetVisitor : public BDiskDeviceVisitor
{
public:
TargetVisitor(BMenu *menu);
virtual bool Visit(BDiskDevice *device);
virtual bool Visit(BPartition *partition, int32 level);
private:
void _MakeLabel(BPartition *partition, char *label, char *menuLabel);
BMenu *fMenu;
class TargetVisitor : public BDiskDeviceVisitor {
public:
TargetVisitor(BMenu* menu);
virtual bool Visit(BDiskDevice* device);
virtual bool Visit(BPartition* partition, int32 level);
private:
void _MakeLabel(BPartition* partition, char* label, char* menuLabel,
bool showContentType);
BMenu* fMenu;
};
@ -532,13 +534,6 @@ TargetVisitor::Visit(BPartition *partition, int32 level)
printf("TargetVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("TargetVisitor::Visit(BPartition *) : %s\n", partition->ContentName());
if (partition->ContentType() == NULL
|| strcmp(partition->ContentType(), kPartitionTypeBFS) != 0) {
// Except only valid BFS partitions
printf(" not BFS\n");
return false;
}
if (partition->ContentSize() < 20 * 1024 * 1024) {
// reject partitions which are too small anyways
// TODO: Could depend on the source size
@ -556,31 +551,46 @@ TargetVisitor::Visit(BPartition *partition, int32 level)
// TODO: After running DriveSetup and doing another scan, it would
// be great to pick the partition which just appeared!
// Only BFS partitions are valid targets, but we want to display the
// other partitions as well, in order not to irritate the user.
bool isValidTarget = partition->ContentType() != NULL
&& strcmp(partition->ContentType(), kPartitionTypeBFS) == 0;
char label[255], menuLabel[255];
_MakeLabel(partition, label, menuLabel);
fMenu->AddItem(new PartitionMenuItem(partition->ContentName(), label,
menuLabel, new BMessage(TARGET_PARTITION), partition->ID()));
_MakeLabel(partition, label, menuLabel, !isValidTarget);
PartitionMenuItem* item = new PartitionMenuItem(partition->ContentName(),
label, menuLabel, new BMessage(TARGET_PARTITION), partition->ID());
item->SetIsValidTarget(isValidTarget);
fMenu->AddItem(item);
return false;
}
void
TargetVisitor::_MakeLabel(BPartition *partition, char *label, char *menuLabel)
TargetVisitor::_MakeLabel(BPartition* partition, char* label, char* menuLabel,
bool showContentType)
{
char size[15];
SizeAsString(partition->ContentSize(), size);
BPath path;
partition->GetPath(&path);
// TODO: Reenable the printing of the content type once Haiku supports
// installing to other file systems than BFS.
// sprintf(label, "%s - %s [%s] [%s]", partition->ContentName(),
// size, partition->ContentType(), path.Path());
// sprintf(menuLabel, "%s - %s [%s]", partition->ContentName(), size,
// partition->ContentType());
if (showContentType) {
const char* type = partition->ContentType();
if (type == NULL)
type = "Unknown Type";
sprintf(label, "%s - %s [%s] (%s)", partition->ContentName(), size,
path.Path(), type);
} else {
sprintf(label, "%s - %s [%s]", partition->ContentName(), size,
path.Path());
}
sprintf(label, "%s - %s - %s", partition->ContentName(), size,
path.Path());
sprintf(menuLabel, "%s - %s", partition->ContentName(), size);
}