* To get away with that empty mount menu, it now at least shows all mounted and

mountable volumes - there are no icons yet, and it will also not work at all,
  that is, you cannot mount/unmount any volumes yet.
* Got rid of _INCLUDES_CLASS_DEVICE_MAP in MountMenu.cpp.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-01-19 23:01:42 +00:00
parent dff7fdee70
commit 6486616423
2 changed files with 121 additions and 12 deletions

View File

@ -3,8 +3,7 @@ SubDir HAIKU_TOP src kits tracker ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
AddSubDirSupportedPlatforms libbe_test ; AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders shared ; UsePrivateHeaders shared storage tracker ;
UsePrivateHeaders tracker ;
UseLibraryHeaders icon ; UseLibraryHeaders icon ;

View File

@ -48,23 +48,111 @@ All rights reserved.
#include "Tracker.h" #include "Tracker.h"
#include "Bitmaps.h" #include "Bitmaps.h"
#if OPEN_TRACKER #ifdef __HAIKU__
# include "DeviceMap.h" # include <DiskDevice.h>
# include <DiskDeviceList.h>
#else #else
# include <private/storage/DeviceMap.h> # include "DeviceMap.h"
#endif #endif
#define SHOW_NETWORK_VOLUMES #define SHOW_NETWORK_VOLUMES
MountMenu::MountMenu(const char *name) #ifdef __HAIKU__
: BMenu(name) // #pragma mark - Haiku Disk Device API
class AddMenuItemVisitor : public BDiskDeviceVisitor {
public:
AddMenuItemVisitor(BMenu* menu);
virtual ~AddMenuItemVisitor();
virtual bool Visit(BDiskDevice *device);
virtual bool Visit(BPartition *partition, int32 level);
private:
BMenu* fMenu;
};
AddMenuItemVisitor::AddMenuItemVisitor(BMenu* menu)
:
fMenu(menu)
{ {
SetFont(be_plain_font);
} }
#if _INCLUDES_CLASS_DEVICE_MAP AddMenuItemVisitor::~AddMenuItemVisitor()
{
}
bool
AddMenuItemVisitor::Visit(BDiskDevice *device)
{
return Visit(device, 0);
}
bool
AddMenuItemVisitor::Visit(BPartition *partition, int32 level)
{
if (!partition->ContainsFileSystem())
return NULL;
// get name (and eventually the type)
BString name = partition->ContentName();
if (name.Length() == 0) {
name = partition->Name();
if (name.Length() == 0) {
const char *type = partition->ContentType();
if (type == NULL)
return NULL;
name = "(unnamed ";
name << type;
name << ")";
}
}
// get icon
BBitmap *icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1),
B_CMAP8);
if (partition->GetIcon(icon, B_MINI_ICON) != B_OK) {
delete icon;
icon = NULL;
}
BMessage *message = new BMessage(partition->IsMounted() ?
kUnmountVolume : kMountVolume);
message->AddInt32("id", partition->ID());
// TODO: for now, until we actually have disk device icons
BMenuItem *item;
if (icon != NULL)
item = new IconMenuItem(name.String(), message, icon);
else
item = new BMenuItem(name.String(), message);
if (partition->IsMounted()) {
item->SetMarked(true);
BVolume volume;
if (partition->GetVolume(&volume) == B_OK) {
BVolume bootVolume;
BVolumeRoster().GetBootVolume(&bootVolume);
if (volume == bootVolume)
item->SetEnabled(false);
}
}
fMenu->AddItem(item);
return false;
}
#else // !__HAIKU__
// #pragma mark - R5 DeviceMap API
struct AddOneAsMenuItemParams { struct AddOneAsMenuItemParams {
BMenu *mountMenu; BMenu *mountMenu;
}; };
@ -127,13 +215,23 @@ AddOnePartitionAsMenuItem(Partition *partition, void *castToParams)
return NULL; return NULL;
} }
#endif // _INCLUDES_CLASS_DEVICE_MAP #endif // !__HAIKU__
// #pragma mark -
MountMenu::MountMenu(const char *name)
: BMenu(name)
{
SetFont(be_plain_font);
}
bool bool
MountMenu::AddDynamicItem(add_state) MountMenu::AddDynamicItem(add_state)
{ {
#if _INCLUDES_CLASS_DEVICE_MAP // remove old items
for (;;) { for (;;) {
BMenuItem *item = RemoveItem(0L); BMenuItem *item = RemoveItem(0L);
if (item == NULL) if (item == NULL)
@ -141,6 +239,14 @@ MountMenu::AddDynamicItem(add_state)
delete item; delete item;
} }
#ifdef __HAIKU__
BDiskDeviceList devices;
status_t status = devices.Fetch();
if (status == B_OK) {
AddMenuItemVisitor visitor(this);
devices.VisitEachPartition(&visitor);
}
#else
AddOneAsMenuItemParams params; AddOneAsMenuItemParams params;
params.mountMenu = this; params.mountMenu = this;
@ -149,6 +255,7 @@ MountMenu::AddDynamicItem(add_state)
autoMounter->CheckVolumesNow(); autoMounter->CheckVolumesNow();
autoMounter->EachPartition(&AddOnePartitionAsMenuItem, &params); autoMounter->EachPartition(&AddOnePartitionAsMenuItem, &params);
#endif
#ifdef SHOW_NETWORK_VOLUMES #ifdef SHOW_NETWORK_VOLUMES
// iterate the volume roster and look for volumes with the // iterate the volume roster and look for volumes with the
@ -185,12 +292,14 @@ MountMenu::AddDynamicItem(add_state)
AddSeparatorItem(); AddSeparatorItem();
#ifndef __HAIKU__
// add an option to rescan the scsii bus, etc. // add an option to rescan the scsii bus, etc.
BMenuItem *rescanItem = NULL; BMenuItem *rescanItem = NULL;
if (modifiers() & B_SHIFT_KEY) { if (modifiers() & B_SHIFT_KEY) {
rescanItem = new BMenuItem("Rescan Devices", new BMessage(kAutomounterRescan)); rescanItem = new BMenuItem("Rescan Devices", new BMessage(kAutomounterRescan));
AddItem(rescanItem); AddItem(rescanItem);
} }
#endif
BMenuItem *mountAll = new BMenuItem("Mount All", new BMessage(kMountAllNow)); BMenuItem *mountAll = new BMenuItem("Mount All", new BMessage(kMountAllNow));
AddItem(mountAll); AddItem(mountAll);
@ -200,9 +309,10 @@ MountMenu::AddDynamicItem(add_state)
SetTargetForItems(be_app); SetTargetForItems(be_app);
#ifndef __HAIKU__
if (rescanItem) if (rescanItem)
rescanItem->SetTarget(autoMounter); rescanItem->SetTarget(autoMounter);
#endif // _INCLUDES_CLASS_DEVICE_MAP #endif
return false; return false;
} }