diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 638450dc05..6b902fe248 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -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(); diff --git a/src/apps/installer/PartitionMenuItem.cpp b/src/apps/installer/PartitionMenuItem.cpp index 662b2be6da..54d41f71ac 100644 --- a/src/apps/installer/PartitionMenuItem.cpp +++ b/src/apps/installer/PartitionMenuItem.cpp @@ -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; } diff --git a/src/apps/installer/PartitionMenuItem.h b/src/apps/installer/PartitionMenuItem.h index 6353093c05..abd3925a10 100644 --- a/src/apps/installer/PartitionMenuItem.h +++ b/src/apps/installer/PartitionMenuItem.h @@ -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_ diff --git a/src/apps/installer/WorkerThread.cpp b/src/apps/installer/WorkerThread.cpp index 74341f764a..015ed14ed2 100644 --- a/src/apps/installer/WorkerThread.cpp +++ b/src/apps/installer/WorkerThread.cpp @@ -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); }