Files
haiku-beta6/src/kits/tracker/MountMenu.cpp
T
Stephan Aßmus c1b274fd67 * Removed auto mounter code from Tracker.
* Tracker forwards auto mounter related messages to the mount_server.
* Rewrote AutoMounterSettings to not know AutoMounter and use
  the layout-management.
* Moved the "Eject When Unmounting" setting into the Mount Settings.
* Launch the mount_server during boot, but delay the script until all
  previously mounted volumes have been mounted. This solves some annoying
  timing bugs during boot. For example when you have desktop backgrounds
  on other volumes and some servers don't deal well with the situation
  of links to add-ons on other volumes becoming valid with a delay...
* src/kits/tracker/Commands.h includes the private headers/private/
  mount/MountServer.h header, which made adjustments to the DiskUsage
  Jamfile necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33555 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-10-12 14:52:17 +00:00

228 lines
5.8 KiB
C++

/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
// MountMenu implements a context menu used for mounting/unmounting volumes
#include <Debug.h>
#include <MenuItem.h>
#include <Mime.h>
#include <InterfaceDefs.h>
#include <VolumeRoster.h>
#include <Volume.h>
#include <fs_info.h>
#include "Commands.h"
#include "MountMenu.h"
#include "IconMenuItem.h"
#include "Tracker.h"
#include "Bitmaps.h"
#include <DiskDevice.h>
#include <DiskDeviceList.h>
#define SHOW_NETWORK_VOLUMES
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)
{
}
AddMenuItemVisitor::~AddMenuItemVisitor()
{
}
bool
AddMenuItemVisitor::Visit(BDiskDevice *device)
{
return Visit(device, 0);
}
bool
AddMenuItemVisitor::Visit(BPartition *partition, int32 level)
{
if (!partition->ContainsFileSystem())
return false;
// 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 false;
uint32 divisor = 1UL << 30;
char unit = 'G';
if (partition->Size() < divisor) {
divisor = 1UL << 20;
unit = 'M';
}
char* buffer = name.LockBuffer(256);
snprintf(buffer, 256, "(%.1f %cB %s)",
1.0 * partition->Size() / divisor, unit, type);
name.UnlockBuffer();
}
}
// get icon
BBitmap *icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1),
B_RGBA32);
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;
}
// #pragma mark -
MountMenu::MountMenu(const char *name)
: BMenu(name)
{
SetFont(be_plain_font);
}
bool
MountMenu::AddDynamicItem(add_state)
{
// remove old items
for (;;) {
BMenuItem *item = RemoveItem(0L);
if (item == NULL)
break;
delete item;
}
BDiskDeviceList devices;
status_t status = devices.Fetch();
if (status == B_OK) {
AddMenuItemVisitor visitor(this);
devices.VisitEachPartition(&visitor);
}
#ifdef SHOW_NETWORK_VOLUMES
// iterate the volume roster and look for volumes with the
// 'shared' attributes -- these same volumes will not be returned
// by the autoMounter because they do not show up in the /dev tree
BVolumeRoster volumeRoster;
BVolume volume;
bool needSeparator = false;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
if (volume.IsShared()) {
needSeparator = true;
BBitmap *icon = new BBitmap(BRect(0, 0, 15, 15), B_CMAP8);
fs_info info;
if (fs_stat_dev(volume.Device(), &info) != B_OK) {
PRINT(("Cannot get mount menu item icon; bad device ID\n"));
delete icon;
continue;
}
// Use the shared icon instead of the device icon
if (get_device_icon(info.device_name, icon->Bits(), B_MINI_ICON) != B_OK)
GetTrackerResources()->GetIconResource(kResShareIcon, B_MINI_ICON, icon);
BMessage *message = new BMessage(kUnmountVolume);
message->AddInt32("device_id", volume.Device());
char volumeName[B_FILE_NAME_LENGTH];
volume.GetName(volumeName);
BMenuItem *item = new IconMenuItem(volumeName, message, icon);
item->SetMarked(true);
AddItem(item);
}
}
#endif // SHOW_NETWORK_VOLUMES
AddSeparatorItem();
BMenuItem *mountAll = new BMenuItem("Mount All",
new BMessage(kMountAllNow));
AddItem(mountAll);
BMenuItem *mountSettings = new BMenuItem("Settings" B_UTF8_ELLIPSIS,
new BMessage(kRunAutomounterSettings));
AddItem(mountSettings);
SetTargetForItems(be_app);
return false;
}