diff --git a/data/system/boot/Bootscript b/data/system/boot/Bootscript index 9da752291d..0f6d7ebd24 100644 --- a/data/system/boot/Bootscript +++ b/data/system/boot/Bootscript @@ -114,10 +114,17 @@ fi if [ -e /etc/users ]; then + # TODO: system/Login needs to be fixed to launch the mount_server! launch system/Login # nothing more else cd /boot/home + + launch $SERVERS/mount_server + waitfor -m application/x-vnd.Haiku-mount_server + # delay the boot script until all previous volumes have been mounted + hey -s mount_server DO InitialScan + launch system/Tracker launch system/Deskbar diff --git a/src/apps/diskusage/Jamfile b/src/apps/diskusage/Jamfile index 22b5328b30..27e509b754 100644 --- a/src/apps/diskusage/Jamfile +++ b/src/apps/diskusage/Jamfile @@ -1,7 +1,6 @@ SubDir HAIKU_TOP src apps diskusage ; -UsePrivateHeaders shared ; -UsePrivateHeaders tracker ; +UsePrivateHeaders mount shared tracker ; SubDirHdrs $(HAIKU_TOP) src kits tracker ; Application DiskUsage : diff --git a/src/kits/tracker/AutoMounter.cpp b/src/kits/tracker/AutoMounter.cpp index e2881eeb9f..e69de29bb2 100644 --- a/src/kits/tracker/AutoMounter.cpp +++ b/src/kits/tracker/AutoMounter.cpp @@ -1,779 +0,0 @@ -/* -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. -*/ - -#include "AutoMounter.h" - -#include - -#include "AutoLock.h" -#include "AutoMounterSettings.h" -#include "Commands.h" -#include "FSUtils.h" -#include "Tracker.h" -#include "TrackerSettings.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - - -static const char *kAutoMounterSettings = "automounter_settings"; -static const uint32 kMsgInitialScan = 'insc'; -static const char* kMountFlagsKeyExtension = " mount flags"; - - -AutoMounter::AutoMounter() - : BLooper("AutoMounter", B_LOW_PRIORITY), - fNormalMode(kRestorePreviousVolumes), - fRemovableMode(kAllVolumes) -{ - if (!BootedInSafeMode()) { - _ReadSettings(); - } else { - // defeat automounter in safe mode, don't even care about the settings - fNormalMode = kNoVolumes; - fRemovableMode = kNoVolumes; - } - - BDiskDeviceRoster().StartWatching(this, - B_DEVICE_REQUEST_DEVICE | B_DEVICE_REQUEST_DEVICE_LIST); - PostMessage(kMsgInitialScan); -} - - -AutoMounter::~AutoMounter() -{ - BDiskDeviceRoster().StopWatching(this); -} - - -static bool -suggest_mount_flags(const BPartition* partition, uint32* _flags) -{ - uint32 mountFlags = 0; - - bool askReadOnly = true; - bool isBFS = false; - - if (partition->ContentType() != NULL - && strcmp(partition->ContentType(), kPartitionTypeBFS) == 0) { -#if 0 - askReadOnly = false; -#endif - isBFS = true; - } - - BDiskSystem diskSystem; - status_t status = partition->GetDiskSystem(&diskSystem); - if (status == B_OK && !diskSystem.SupportsWriting()) - askReadOnly = false; - - if (partition->IsReadOnly()) - askReadOnly = false; - - if (askReadOnly) { - // Suggest to the user to mount read-only until Haiku is more mature. - BString string; - string << "Mounting volume "; - if (partition->ContentName() != NULL) - string << "'" << partition->ContentName() << "'\n\n"; - else - string << "\n\n"; - // TODO: Use distro name instead of "Haiku"... - if (!isBFS) { - string << "The file system on this volume is not the Haiku file " - "system. It is strongly suggested to mount it in read-only " - "mode. "; - } else { - string << "It is suggested to mount all additional Haiku volumes " - "in read-only mode. "; - } - string << "This will prevent unintentional data loss because of " - "errors in Haiku."; - BAlert* alert = new BAlert("Mount Warning", string.String(), - "Mount Read/Write", "Cancel", "Mount Read-only", - B_WIDTH_FROM_WIDEST, B_WARNING_ALERT); - alert->SetShortcut(1, B_ESCAPE); - int32 choice = alert->Go(); - switch (choice) { - case 0: - break; - case 1: - return false; - case 2: - mountFlags |= B_MOUNT_READ_ONLY; - break; - } - } - - *_flags = mountFlags; - return true; -} - - -void -AutoMounter::_MountVolumes(mount_mode normal, mount_mode removable, - bool initialRescan, partition_id deviceID) -{ - if (normal == kNoVolumes && removable == kNoVolumes) - return; - - class InitialMountVisitor : public BDiskDeviceVisitor { - public: - InitialMountVisitor(mount_mode normalMode, mount_mode removableMode, - bool initialRescan, BMessage& previous, - partition_id deviceID) - : - fNormalMode(normalMode), - fRemovableMode(removableMode), - fInitialRescan(initialRescan), - fPrevious(previous), - fOnlyOnDeviceID(deviceID) - { - } - - virtual - ~InitialMountVisitor() - { - } - - virtual bool - Visit(BDiskDevice* device) - { - return Visit(device, 0); - } - - virtual bool - Visit(BPartition* partition, int32 level) - { - if (fOnlyOnDeviceID >= 0) { - // only mount partitions on the given device id - // or if the partition ID is already matched - BPartition* device = partition; - while (device->Parent() != NULL) { - if (device->ID() == fOnlyOnDeviceID) { - // we are happy - break; - } - device = device->Parent(); - } - if (device->ID() != fOnlyOnDeviceID) - return false; - } - - mount_mode mode = !fInitialRescan - && partition->Device()->IsRemovableMedia() - ? fRemovableMode : fNormalMode; - if (mode == kNoVolumes - || partition->IsMounted() - || !partition->ContainsFileSystem()) - return false; - - BPath path; - if (partition->GetPath(&path) != B_OK) - return false; - - if (mode == kRestorePreviousVolumes) { - // mount all volumes that were stored in the settings file - const char *volumeName = NULL; - if (partition->ContentName() == NULL - || fPrevious.FindString(path.Path(), &volumeName) - != B_OK - || strcmp(volumeName, partition->ContentName())) - return false; - } else if (mode == kOnlyBFSVolumes) { - if (partition->ContentType() == NULL - || strcmp(partition->ContentType(), kPartitionTypeBFS)) - return false; - } - - uint32 mountFlags; - if (!fInitialRescan) { - // Ask the user about mount flags if this is not the - // initial scan. - if (!suggest_mount_flags(partition, &mountFlags)) - return false; - } else { - BString mountFlagsKey(path.Path()); - mountFlagsKey << kMountFlagsKeyExtension; - if (fPrevious.FindInt32(mountFlagsKey.String(), - (int32*)&mountFlags) < B_OK) { - mountFlags = 0; - } - } - - if (partition->Mount(NULL, mountFlags) == B_OK - && partition->GetMountPoint(&path) == B_OK) { - // notify Tracker that a new volume has been started - BMessage note(kVolumeMounted); - note.AddString("path", path.Path()); - note.AddBool("initial rescan", fInitialRescan); - be_app->PostMessage(¬e); - } - return false; - } - - private: - mount_mode fNormalMode; - mount_mode fRemovableMode; - bool fInitialRescan; - BMessage& fPrevious; - partition_id fOnlyOnDeviceID; - } visitor(normal, removable, initialRescan, fSettings, deviceID); - - BDiskDeviceList devices; - status_t status = devices.Fetch(); - if (status == B_OK) - devices.VisitEachPartition(&visitor); -} - - -void -AutoMounter::_MountVolume(const BMessage* message) -{ - int32 id; - if (message->FindInt32("id", &id) != B_OK) - return; - - BDiskDeviceRoster roster; - BPartition *partition; - BDiskDevice device; - if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) - return; - - uint32 mountFlags; - if (!suggest_mount_flags(partition, &mountFlags)) - return; - - status_t status = partition->Mount(NULL, mountFlags); - if (status < B_OK) { - BString string; - string << "Error mounting volume. (" << strerror(status) << ")"; - (new BAlert("", string.String(), "Ok"))->Go(NULL); - } -} - - -bool -AutoMounter::_SuggestForceUnmount(const char* name, status_t error) -{ - BString text; - text << "Could not unmount disk \"" << name << "\":\n\t" << strerror(error); - text << "\n\nShould unmounting be forced?\n\n" - "Note: if an application is currently writing to the volume, unmounting" - " it now might result in loss of data.\n"; - - BAlert* alert = new BAlert("", text.String(), "Cancel", "Force Unmount", - NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); - alert->SetShortcut(0, B_ESCAPE); - int32 choice = alert->Go(); - - return choice == 1; -} - - -void -AutoMounter::_ReportUnmountError(const char* name, status_t error) -{ - BString text; - text << "Could not unmount disk \"" << name << "\":\n\t" << strerror(error); - - (new BAlert("", text.String(), "OK", NULL, NULL, B_WIDTH_AS_USUAL, - B_WARNING_ALERT))->Go(NULL); -} - - -void -AutoMounter::_UnmountAndEjectVolume(BPartition* partition, BPath& mountPoint, - const char* name) -{ - BDiskDevice device; - if (partition == NULL) { - // Try to retrieve partition - BDiskDeviceRoster().FindPartitionByMountPoint(mountPoint.Path(), - &device, &partition); - } - - status_t status; - if (partition != NULL) - status = partition->Unmount(); - else - status = fs_unmount_volume(mountPoint.Path(), 0); - - if (status < B_OK) { - if (!_SuggestForceUnmount(name, status)) - return; - - if (partition != NULL) - status = partition->Unmount(B_FORCE_UNMOUNT); - else - status = fs_unmount_volume(mountPoint.Path(), B_FORCE_UNMOUNT); - } - - if (status < B_OK) { - _ReportUnmountError(partition->ContentName(), status); - return; - } - - if (TrackerSettings().EjectWhenUnmounting() && partition != NULL) { - // eject device if it doesn't have any mounted partitions left - class IsMountedVisitor : public BDiskDeviceVisitor { - public: - IsMountedVisitor() - : - fHasMounted(false) - { - } - - virtual bool Visit(BDiskDevice* device) - { - return Visit(device, 0); - } - - virtual bool Visit(BPartition* partition, int32 level) - { - if (partition->IsMounted()) { - fHasMounted = true; - return true; - } - - return false; - } - - bool HasMountedPartitions() const - { - return fHasMounted; - } - - private: - bool fHasMounted; - } visitor; - - partition->Device()->VisitEachDescendant(&visitor); - - if (!visitor.HasMountedPartitions()) - partition->Device()->Eject(); - } - - // remove the directory if it's a directory in rootfs - if (dev_for_path(mountPoint.Path()) == dev_for_path("/")) - rmdir(mountPoint.Path()); -} - - -void -AutoMounter::_UnmountAndEjectVolume(BMessage* message) -{ - int32 id; - if (message->FindInt32("id", &id) == B_OK) { - BDiskDeviceRoster roster; - BPartition *partition; - BDiskDevice device; - if (roster.GetPartitionWithID(id, &device, &partition) != B_OK) - return; - - BPath path; - if (partition->GetMountPoint(&path) == B_OK) - _UnmountAndEjectVolume(partition, path, partition->ContentName()); - } else { - // see if we got a dev_t - - dev_t device; - if (message->FindInt32("device_id", &device) != B_OK) - return; - - BVolume volume(device); - status_t status = volume.InitCheck(); - - char name[B_FILE_NAME_LENGTH]; - if (status == B_OK) - status = volume.GetName(name); - if (status < B_OK) - snprintf(name, sizeof(name), "device:%ld", device); - - BPath path; - if (status == B_OK) { - BDirectory mountPoint; - status = volume.GetRootDirectory(&mountPoint); - if (status == B_OK) - status = path.SetTo(&mountPoint, "."); - } - - if (status == B_OK) - _UnmountAndEjectVolume(NULL, path, name); - } -} - - -void -AutoMounter::_FromMode(mount_mode mode, bool& all, bool& bfs, bool& restore) -{ - all = bfs = restore = false; - - switch (mode) { - case kAllVolumes: - all = true; - break; - case kOnlyBFSVolumes: - bfs = true; - break; - case kRestorePreviousVolumes: - restore = true; - break; - - default: - break; - } -} - - -AutoMounter::mount_mode -AutoMounter::_ToMode(bool all, bool bfs, bool restore) -{ - if (all) - return kAllVolumes; - if (bfs) - return kOnlyBFSVolumes; - if (restore) - return kRestorePreviousVolumes; - - return kNoVolumes; -} - - -void -AutoMounter::_ReadSettings() -{ - BPath directoryPath; - if (FSFindTrackerSettingsDir(&directoryPath) != B_OK) - return; - - BPath path(directoryPath); - path.Append(kAutoMounterSettings); - fPrefsFile.SetTo(path.Path(), O_RDWR); - - if (fPrefsFile.InitCheck() != B_OK) { - // no prefs file yet, create a new one - - BDirectory dir(directoryPath.Path()); - dir.CreateFile(kAutoMounterSettings, &fPrefsFile); - return; - } - - ssize_t settingsSize = (ssize_t)fPrefsFile.Seek(0, SEEK_END); - if (settingsSize == 0) - return; - - ASSERT(settingsSize != 0); - char *buffer = new char[settingsSize]; - - fPrefsFile.Seek(0, 0); - if (fPrefsFile.Read(buffer, (size_t)settingsSize) != settingsSize) { - PRINT(("error reading automounter settings\n")); - delete [] buffer; - return; - } - - BMessage message('stng'); - status_t result = message.Unflatten(buffer); - if (result != B_OK) { - PRINT(("error %s unflattening settings, size %d\n", strerror(result), - settingsSize)); - delete [] buffer; - return; - } - - delete [] buffer; - - // update flags and modes from the message - _UpdateSettingsFromMessage(&message); - // copy the previously mounted partitions - fSettings = message; -} - - -void -AutoMounter::_WriteSettings() -{ - if (fPrefsFile.InitCheck() != B_OK) - return; - - BMessage message('stng'); - GetSettings(&message); - - ssize_t settingsSize = message.FlattenedSize(); - - char *buffer = new char[settingsSize]; - status_t result = message.Flatten(buffer, settingsSize); - - fPrefsFile.Seek(0, 0); - result = fPrefsFile.Write(buffer, (size_t)settingsSize); - if (result != settingsSize) - PRINT(("error writing settings, %s\n", strerror(result))); - - delete [] buffer; -} - - -void -AutoMounter::_UpdateSettingsFromMessage(BMessage* message) -{ - // auto mounter settings - - bool all, bfs, restore; - if (message->FindBool("autoMountAll", &all) != B_OK) - all = true; - if (message->FindBool("autoMountAllBFS", &bfs) != B_OK) - bfs = false; - - fRemovableMode = _ToMode(all, bfs, false); - - // initial mount settings - - if (message->FindBool("initialMountAll", &all) != B_OK) - all = false; - if (message->FindBool("initialMountAllBFS", &bfs) != B_OK) - bfs = false; - if (message->FindBool("initialMountRestore", &restore) != B_OK) - restore = true; - - fNormalMode = _ToMode(all, bfs, restore); -} - - -void -AutoMounter::GetSettings(BMessage *message) -{ - message->MakeEmpty(); - - bool all, bfs, restore; - - _FromMode(fNormalMode, all, bfs, restore); - message->AddBool("initialMountAll", all); - message->AddBool("initialMountAllBFS", bfs); - message->AddBool("initialMountRestore", restore); - - _FromMode(fRemovableMode, all, bfs, restore); - message->AddBool("autoMountAll", all); - message->AddBool("autoMountAllBFS", bfs); - - // Save mounted volumes so we can optionally mount them on next - // startup - BVolumeRoster volumeRoster; - BVolume volume; - while (volumeRoster.GetNextVolume(&volume) == B_OK) { - fs_info info; - if (fs_stat_dev(volume.Device(), &info) == 0 - && (info.flags & (B_FS_IS_REMOVABLE | B_FS_IS_PERSISTENT)) != 0) { - message->AddString(info.device_name, info.volume_name); - - BString mountFlagsKey(info.device_name); - mountFlagsKey << kMountFlagsKeyExtension; - uint32 mountFlags = 0; - if (volume.IsReadOnly()) - mountFlags |= B_MOUNT_READ_ONLY; - message->AddInt32(mountFlagsKey.String(), mountFlags); - } - } -} - - -void -AutoMounter::MessageReceived(BMessage* message) -{ - switch (message->what) { - case kMsgInitialScan: - _MountVolumes(fNormalMode, fRemovableMode, true); - be_app->PostMessage(kOpenPreviouslyOpenWindows); - break; - - case kMountVolume: - _MountVolume(message); - break; - - case kUnmountVolume: - _UnmountAndEjectVolume(message); - break; - - case kSetAutomounterParams: - { - bool rescanNow = false; - message->FindBool("rescanNow", &rescanNow); - - _UpdateSettingsFromMessage(message); - GetSettings(&fSettings); - _WriteSettings(); - - if (rescanNow) - _MountVolumes(fNormalMode, fRemovableMode); - break; - } - - case kMountAllNow: - _MountVolumes(kAllVolumes, kAllVolumes); - break; - - case B_DEVICE_UPDATE: - int32 event; - if (message->FindInt32("event", &event) != B_OK - || (event != B_DEVICE_MEDIA_CHANGED - && event != B_DEVICE_ADDED)) - break; - - partition_id deviceID; - if (message->FindInt32("id", &deviceID) != B_OK) - break; - - _MountVolumes(kNoVolumes, fRemovableMode, false, deviceID); - break; - -#if 0 - case B_NODE_MONITOR: - { - int32 opcode; - if (message->FindInt32("opcode", &opcode) != B_OK) - break; - - switch (opcode) { - // The name of a mount point has changed - case B_ENTRY_MOVED: { - WRITELOG(("*** Received Mount Point Renamed Notification")); - - const char *newName; - if (message->FindString("name", &newName) != B_OK) { - WRITELOG(("ERROR: Couldn't find name field in update message")); - PRINT_OBJECT(*message); - break ; - } - - // - // When the node monitor reports a move, it gives the - // parent device and inode that moved. The problem is - // that the inode is the inode of root *in* the filesystem, - // which is generally always the same number for every - // filesystem of a type. - // - // What we'd really like is the device that the moved - // volume is mounted on. Find this by using the - // *new* name and directory, and then stat()ing that to - // find the device. - // - dev_t parentDevice; - if (message->FindInt32("device", &parentDevice) != B_OK) { - WRITELOG(("ERROR: Couldn't find 'device' field in update" - " message")); - PRINT_OBJECT(*message); - break; - } - - ino_t toDirectory; - if (message->FindInt64("to directory", &toDirectory)!=B_OK){ - WRITELOG(("ERROR: Couldn't find 'to directory' field in update" - "message")); - PRINT_OBJECT(*message); - break; - } - - entry_ref root_entry(parentDevice, toDirectory, newName); - - BNode entryNode(&root_entry); - if (entryNode.InitCheck() != B_OK) { - WRITELOG(("ERROR: Couldn't create mount point entry node: %s/n", - strerror(entryNode.InitCheck()))); - break; - } - - node_ref mountPointNode; - if (entryNode.GetNodeRef(&mountPointNode) != B_OK) { - WRITELOG(("ERROR: Couldn't get node ref for new mount point")); - break; - } - - WRITELOG(("Attempt to rename device %li to %s", mountPointNode.device, - newName)); - - Partition *partition = FindPartition(mountPointNode.device); - if (partition != NULL) { - WRITELOG(("Found device, changing name.")); - - BVolume mountVolume(partition->VolumeDeviceID()); - BDirectory mountDir; - mountVolume.GetRootDirectory(&mountDir); - BPath dirPath(&mountDir, 0); - - partition->SetMountedAt(dirPath.Path()); - partition->SetVolumeName(newName); - break; - } else { - WRITELOG(("ERROR: Device %li does not appear to be present", - mountPointNode.device)); - } - } - } - break; - } -#endif - - default: - BLooper::MessageReceived(message); - break; - } -} - - -bool -AutoMounter::QuitRequested() -{ - if (!BootedInSafeMode()) { - // don't write out settings in safe mode - this would overwrite the - // normal, non-safe mode settings - _WriteSettings(); - } - - return true; -} diff --git a/src/kits/tracker/AutoMounter.h b/src/kits/tracker/AutoMounter.h index b331892fa8..e69de29bb2 100644 --- a/src/kits/tracker/AutoMounter.h +++ b/src/kits/tracker/AutoMounter.h @@ -1,108 +0,0 @@ -/* -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. -*/ - -#ifndef _AUTO_MOUNTER_H -#define _AUTO_MOUNTER_H - -#include -#include -#include -#include - -class BPartition; -class BPath; - -namespace BPrivate { - -const uint32 kMountVolume = 'mntv'; -const uint32 kMountAllNow = 'mntn'; -const uint32 kSetAutomounterParams = 'pmst'; -const uint32 kVolumeMounted = 'vmtd'; - - -class AutoMounter : public BLooper { -public: - AutoMounter(); - virtual ~AutoMounter(); - - virtual bool QuitRequested(); - - void GetSettings(BMessage* message); - -private: - enum mount_mode { - kNoVolumes, - kOnlyBFSVolumes, - kAllVolumes, - kRestorePreviousVolumes - }; - - void _MountVolumes(mount_mode normal, - mount_mode removable, - bool initialRescan = false, - partition_id deviceID = -1); - void _MountVolume(const BMessage* message); - bool _SuggestForceUnmount(const char* name, - status_t error); - void _ReportUnmountError(const char* name, - status_t error); - void _UnmountAndEjectVolume(BPartition* partition, - BPath& mountPoint, const char* name); - void _UnmountAndEjectVolume(BMessage* message); - - void _FromMode(mount_mode mode, bool& all, - bool& bfs, bool& restore); - mount_mode _ToMode(bool all, bool bfs, - bool restore = false); - - void _UpdateSettingsFromMessage(BMessage* message); - void _ReadSettings(); - void _WriteSettings(); - - virtual void MessageReceived(BMessage* message); - -private: - mount_mode fNormalMode; - mount_mode fRemovableMode; - - BFile fPrefsFile; - BMessage fSettings; -}; - - -} // namespace BPrivate - -using namespace BPrivate; - -#endif // _AUTO_MOUNTER_H diff --git a/src/kits/tracker/AutoMounterSettings.cpp b/src/kits/tracker/AutoMounterSettings.cpp index fe72b8a19c..b28dbf206b 100644 --- a/src/kits/tracker/AutoMounterSettings.cpp +++ b/src/kits/tracker/AutoMounterSettings.cpp @@ -32,177 +32,182 @@ names are registered trademarks or trademarks of their respective holders. All rights reserved. */ - -#include "AutoMounter.h" #include "AutoMounterSettings.h" +#include #include #include +#include #include +#include +#include +#include +#include #include #include #include +#include + const uint32 kAutomountSettingsChanged = 'achg'; const uint32 kBootMountSettingsChanged = 'bchg'; -const uint32 kAutoAll = 'aall'; -const uint32 kAutoBFS = 'abfs'; -const uint32 kAutoHFS = 'ahfs'; -const uint32 kInitAll = 'iall'; -const uint32 kInitBFS = 'ibfs'; -const uint32 kInitHFS = 'ihfs'; +const uint32 kEjectWhenUnmountingChanged = 'ejct'; + class AutomountSettingsPanel : public BBox { - public: - AutomountSettingsPanel(BRect, BMessage *, AutoMounter *); - virtual ~AutomountSettingsPanel(); +public: + AutomountSettingsPanel(BMessage* settings, + const BMessenger& target); + virtual ~AutomountSettingsPanel(); - protected: - virtual void MessageReceived(BMessage *); - virtual void AttachedToWindow(); - virtual void GetPreferredSize(float* _width, float* _height); - - private: - void SendSettings(bool rescan); - - BRadioButton *fInitialDontMountCheck; - BRadioButton *fInitialMountAllBFSCheck; - BRadioButton *fInitialMountAllCheck; - BRadioButton *fInitialMountRestoreCheck; +protected: + virtual void MessageReceived(BMessage* message); + virtual void AttachedToWindow(); - BRadioButton *fScanningDisabledCheck; - BRadioButton *fAutoMountAllBFSCheck; - BRadioButton *fAutoMountAllCheck; +private: + void _SendSettings(bool rescan); - BButton *fDone; - BButton *fMountAllNow; + BRadioButton* fInitialDontMountCheck; + BRadioButton* fInitialMountAllBFSCheck; + BRadioButton* fInitialMountAllCheck; + BRadioButton* fInitialMountRestoreCheck; - AutoMounter *fTarget; + BRadioButton* fScanningDisabledCheck; + BRadioButton* fAutoMountAllBFSCheck; + BRadioButton* fAutoMountAllCheck; - typedef BBox _inherited; + BCheckBox* fEjectWhenUnmountingCheckBox; + + BButton* fDone; + BButton* fMountAllNow; + + BMessenger fTarget; + + typedef BBox _inherited; }; -AutomountSettingsDialog *AutomountSettingsDialog::sOneCopyOnly = NULL; + +AutomountSettingsDialog* AutomountSettingsDialog::sOneCopyOnly = NULL; -AutomountSettingsPanel::AutomountSettingsPanel(BRect frame, - BMessage *settings, AutoMounter *target) - : BBox(frame, "", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS - | B_NAVIGABLE_JUMP, B_NO_BORDER), - fTarget(target) +AutomountSettingsPanel::AutomountSettingsPanel(BMessage* settings, + const BMessenger& target) + : + BBox("", B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER), + fTarget(target) { + const float spacing = 8; + // "Automatic Disk Mounting" group - BRect boxRect(Bounds()); - boxRect.InsetBy(8.0f, 8.0f); - boxRect.bottom = boxRect.top + 85; - BBox *box = new BBox(boxRect, "autoMountBox", B_FOLLOW_LEFT_RIGHT, - B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); - box->SetLabel("Automatic Disk Mounting"); - AddChild(box); + BBox* autoMountBox = new BBox("autoMountBox", B_WILL_DRAW | B_FRAME_EVENTS + | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); + autoMountBox->SetLabel("Automatic Disk Mounting"); + BGroupLayout* autoMountLayout = new BGroupLayout(B_VERTICAL, spacing); + autoMountBox->SetLayout(autoMountLayout); + autoMountLayout->SetInsets(spacing, + autoMountBox->InnerFrame().top + spacing, spacing, spacing); - font_height fontHeight; - box->GetFontHeight(&fontHeight); + fScanningDisabledCheck = new BRadioButton("scanningOff", "Don't Automount", + new BMessage(kAutomountSettingsChanged)); - BRect checkBoxRect(box->Bounds()); - checkBoxRect.InsetBy(8.0f, 8.0f); - checkBoxRect.top += fontHeight.ascent + fontHeight.descent; + fAutoMountAllBFSCheck = new BRadioButton("autoBFS", "All BeOS Disks", + new BMessage(kAutomountSettingsChanged)); - fScanningDisabledCheck = new BRadioButton(checkBoxRect, "scanningOff", - "Don't Automount", new BMessage(kAutomountSettingsChanged)); - fScanningDisabledCheck->ResizeToPreferred(); - box->AddChild(fScanningDisabledCheck); - - checkBoxRect.OffsetBy(0, fScanningDisabledCheck->Bounds().Height()); - fAutoMountAllBFSCheck = new BRadioButton(checkBoxRect, "autoBFS", - "All BeOS Disks", new BMessage(kAutomountSettingsChanged)); - fAutoMountAllBFSCheck->ResizeToPreferred(); - box->AddChild(fAutoMountAllBFSCheck); - - checkBoxRect.OffsetBy(0, fScanningDisabledCheck->Bounds().Height()); - fAutoMountAllCheck = new BRadioButton(checkBoxRect, "autoAll", - "All Disks", new BMessage(kAutomountSettingsChanged)); - fAutoMountAllCheck->ResizeToPreferred(); - box->AddChild(fAutoMountAllCheck); - - box->ResizeTo(box->Bounds().Width(), fAutoMountAllCheck->Frame().bottom + 8.0f); + fAutoMountAllCheck = new BRadioButton("autoAll", "All Disks", + new BMessage(kAutomountSettingsChanged)); // "Disk Mounting During Boot" group - boxRect.top = box->Frame().bottom + 8.0f; - boxRect.bottom = boxRect.top + 105; - box = new BBox(boxRect, "", B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS - | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); - box->SetLabel("Disk Mounting During Boot"); - AddChild(box); + BBox* bootMountBox = new BBox("", B_WILL_DRAW | B_FRAME_EVENTS + | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); + bootMountBox->SetLabel("Disk Mounting During Boot"); + BGroupLayout* bootMountLayout = new BGroupLayout(B_VERTICAL, spacing); + bootMountBox->SetLayout(bootMountLayout); + bootMountLayout->SetInsets(spacing, + bootMountBox->InnerFrame().top + spacing, spacing, spacing); - checkBoxRect = box->Bounds(); - checkBoxRect.InsetBy(8.0f, 8.0f); - checkBoxRect.top += fontHeight.ascent + fontHeight.descent; - - checkBoxRect.bottom = checkBoxRect.top + 20; - fInitialDontMountCheck = new BRadioButton(checkBoxRect, "initialNone", + fInitialDontMountCheck = new BRadioButton("initialNone", "Only The Boot Disk", new BMessage(kBootMountSettingsChanged)); - fInitialDontMountCheck->ResizeToPreferred(); - box->AddChild(fInitialDontMountCheck); - checkBoxRect.OffsetBy(0, fInitialDontMountCheck->Bounds().Height()); - fInitialMountRestoreCheck = new BRadioButton(checkBoxRect, "initialRestore", + fInitialMountRestoreCheck = new BRadioButton("initialRestore", "Previously Mounted Disks", new BMessage(kBootMountSettingsChanged)); - fInitialMountRestoreCheck->ResizeToPreferred(); - box->AddChild(fInitialMountRestoreCheck); - checkBoxRect.OffsetBy(0, fInitialDontMountCheck->Bounds().Height()); - fInitialMountAllBFSCheck = new BRadioButton(checkBoxRect, "initialBFS", + fInitialMountAllBFSCheck = new BRadioButton("initialBFS", "All BeOS Disks", new BMessage(kBootMountSettingsChanged)); - fInitialMountAllBFSCheck->ResizeToPreferred(); - box->AddChild(fInitialMountAllBFSCheck); - checkBoxRect.OffsetBy(0, fInitialDontMountCheck->Bounds().Height()); - fInitialMountAllCheck = new BRadioButton(checkBoxRect, "initialAll", + fInitialMountAllCheck = new BRadioButton("initialAll", "All Disks", new BMessage(kBootMountSettingsChanged)); - fInitialMountAllCheck->ResizeToPreferred(); - box->AddChild(fInitialMountAllCheck); - box->ResizeTo(box->Bounds().Width(), fInitialMountAllCheck->Frame().bottom + 8.0f); + fEjectWhenUnmountingCheckBox = new BCheckBox("ejectWhenUnmounting", + "Eject When Unmounting", new BMessage(kEjectWhenUnmountingChanged)); // Buttons - fDone = new BButton(Bounds(), "done", "Done", new BMessage(B_QUIT_REQUESTED), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - fDone->ResizeToPreferred(); - fDone->MoveTo(Bounds().Width() - fDone->Bounds().Width() - 8.0f, - Bounds().bottom - fDone->Bounds().Height() - 8.0f); - AddChild(fDone); + fDone = new BButton("Done", new BMessage(B_QUIT_REQUESTED)); - fMountAllNow = new BButton(fDone->Frame(), "mountAll", "Mount all disks now", - new BMessage(kMountAllNow), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - fMountAllNow->ResizeToPreferred(); - fMountAllNow->MoveBy(-fMountAllNow->Bounds().Width() - 10.0f, 0.0f); - AddChild(fMountAllNow); + fMountAllNow = new BButton("mountAll", "Mount all disks now", + new BMessage(kMountAllNow)); fDone->MakeDefault(true); + // Layout the controls + AddChild(BGroupLayoutBuilder(B_VERTICAL, 0) + .Add(BGroupLayoutBuilder(B_VERTICAL, spacing) + .Add(BGroupLayoutBuilder(autoMountLayout) + .Add(fScanningDisabledCheck) + .Add(fAutoMountAllBFSCheck) + .Add(fAutoMountAllCheck) + ) + .Add(BGroupLayoutBuilder(bootMountLayout) + .Add(fInitialDontMountCheck) + .Add(fInitialMountRestoreCheck) + .Add(fInitialMountAllBFSCheck) + .Add(fInitialMountAllCheck) + ) + .Add(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(BSpaceLayoutItem::CreateHorizontalStrut(spacing - 1)) + .Add(fEjectWhenUnmountingCheckBox) + ) + .SetInsets(spacing, spacing, spacing, spacing) + ) + .Add(new BSeparatorView(B_HORIZONTAL/*, B_FANCY_BORDER*/)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing) + .AddGlue() + .Add(fMountAllNow) + .Add(fDone) + .SetInsets(spacing, spacing, spacing, spacing) + ) + ); + + + // Apply the settings + bool result; if (settings->FindBool("autoMountAll", &result) == B_OK && result) - fAutoMountAllCheck->SetValue(1); + fAutoMountAllCheck->SetValue(B_CONTROL_ON); else if (settings->FindBool("autoMountAllBFS", &result) == B_OK && result) - fAutoMountAllBFSCheck->SetValue(1); + fAutoMountAllBFSCheck->SetValue(B_CONTROL_ON); else - fScanningDisabledCheck->SetValue(1); + fScanningDisabledCheck->SetValue(B_CONTROL_ON); if (settings->FindBool("suspended", &result) == B_OK && result) - fScanningDisabledCheck->SetValue(1); + fScanningDisabledCheck->SetValue(B_CONTROL_ON); if (settings->FindBool("initialMountAll", &result) == B_OK && result) - fInitialMountAllCheck->SetValue(1); - else if (settings->FindBool("initialMountRestore", &result) == B_OK && result) - fInitialMountRestoreCheck->SetValue(1); - else if (settings->FindBool("initialMountAllBFS", &result) == B_OK && result) - fInitialMountAllBFSCheck->SetValue(1); - else - fInitialDontMountCheck->SetValue(1); + fInitialMountAllCheck->SetValue(B_CONTROL_ON); + else if (settings->FindBool("initialMountRestore", &result) == B_OK + && result) { + fInitialMountRestoreCheck->SetValue(B_CONTROL_ON); + } else if (settings->FindBool("initialMountAllBFS", &result) == B_OK + && result) { + fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON); + } else + fInitialDontMountCheck->SetValue(B_CONTROL_ON); + + if (settings->FindBool("ejectWhenUnmounting", &result) == B_OK && result) + fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON); } @@ -212,7 +217,49 @@ AutomountSettingsPanel::~AutomountSettingsPanel() void -AutomountSettingsPanel::SendSettings(bool rescan) +AutomountSettingsPanel::AttachedToWindow() +{ + fInitialMountAllCheck->SetTarget(this); + fInitialMountAllBFSCheck->SetTarget(this); + fInitialMountRestoreCheck->SetTarget(this); + fInitialDontMountCheck->SetTarget(this); + + fAutoMountAllCheck->SetTarget(this); + fAutoMountAllBFSCheck->SetTarget(this); + fScanningDisabledCheck->SetTarget(this); + fEjectWhenUnmountingCheckBox->SetTarget(this); + + fDone->SetTarget(this); + fMountAllNow->SetTarget(fTarget); +} + + +void +AutomountSettingsPanel::MessageReceived(BMessage* message) +{ + switch (message->what) { + case B_QUIT_REQUESTED: + Window()->Quit(); + break; + + case kAutomountSettingsChanged: + _SendSettings(true); + break; + + case kBootMountSettingsChanged: + case kEjectWhenUnmountingChanged: + _SendSettings(false); + break; + + default: + _inherited::MessageReceived(message); + break; + } +} + + +void +AutomountSettingsPanel::_SendSettings(bool rescan) { BMessage message(kSetAutomounterParams); @@ -225,91 +272,34 @@ AutomountSettingsPanel::SendSettings(bool rescan) message.AddBool("rescanNow", rescan); message.AddBool("initialMountAll", (bool)fInitialMountAllCheck->Value()); - message.AddBool("initialMountAllBFS", (bool)fInitialMountAllBFSCheck->Value()); - message.AddBool("initialMountRestore", (bool)fInitialMountRestoreCheck->Value()); - if (fInitialDontMountCheck->Value()) + message.AddBool("initialMountAllBFS", + (bool)fInitialMountAllBFSCheck->Value()); + message.AddBool("initialMountRestore", + (bool)fInitialMountRestoreCheck->Value()); + if (fInitialDontMountCheck->Value()) message.AddBool("initialMountAllHFS", false); - fTarget->PostMessage(&message, NULL); -} + message.AddBool("ejectWhenUnmounting", + (bool)fEjectWhenUnmountingCheckBox->Value()); - -void -AutomountSettingsPanel::GetPreferredSize(float* _width, float* _height) -{ - BBox* box = dynamic_cast(fInitialMountRestoreCheck->Parent()); - - if (_width) { - float a = fInitialMountRestoreCheck->Bounds().Width() + 32.0f; - float b = box != NULL ? box->StringWidth(box->Label()) + 24.0f : 0.0f; - float c = fMountAllNow->Bounds().Width() + fDone->Bounds().Width() + 26.0f; - - a = max_c(a, b); - *_width = max_c(a, c); - } - - if (_height) { - *_height = (box != NULL ? box->Frame().bottom : 0.0f) + 16.0f - + fMountAllNow->Bounds().Height(); - } -} - - -void -AutomountSettingsPanel::AttachedToWindow() -{ - fInitialMountAllCheck->SetTarget(this); - fInitialMountAllBFSCheck->SetTarget(this); - fInitialMountRestoreCheck->SetTarget(this); - fInitialDontMountCheck->SetTarget(this); - - fAutoMountAllCheck->SetTarget(this); - fAutoMountAllBFSCheck->SetTarget(this); - fScanningDisabledCheck->SetTarget(this); - - fDone->SetTarget(this); - fMountAllNow->SetTarget(fTarget); -} - - -void -AutomountSettingsPanel::MessageReceived(BMessage *message) -{ - switch (message->what) { - case B_QUIT_REQUESTED: - Window()->Quit(); - break; - - case kAutomountSettingsChanged: - SendSettings(true); - break; - - case kBootMountSettingsChanged: - SendSettings(false); - break; - - default: - _inherited::MessageReceived(message); - break; - } + fTarget.SendMessage(&message); } // #pragma mark - -AutomountSettingsDialog::AutomountSettingsDialog(BMessage *settings, - AutoMounter *target) - : BWindow(BRect(100, 100, 320, 370), "Disk Mount Settings", - B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) +AutomountSettingsDialog::AutomountSettingsDialog(BMessage* settings, + const BMessenger& target) + : + BWindow(BRect(100, 100, 320, 370), "Disk Mount Settings", + B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE + | B_AUTO_UPDATE_SIZE_LIMITS) { - BView* view = new AutomountSettingsPanel(Bounds(), settings, target); + SetLayout(new BGroupLayout(B_HORIZONTAL)); + BView* view = new AutomountSettingsPanel(settings, target); AddChild(view); - float width, height; - view->GetPreferredSize(&width, &height); - ResizeTo(width, height); - ASSERT(!sOneCopyOnly); sOneCopyOnly = this; } @@ -323,7 +313,7 @@ AutomountSettingsDialog::~AutomountSettingsDialog() void -AutomountSettingsDialog::RunAutomountSettings(AutoMounter *target) +AutomountSettingsDialog::RunAutomountSettings(const BMessenger& target) { // either activate an existing mount settings dialog or create a new one if (sOneCopyOnly) { @@ -331,8 +321,16 @@ AutomountSettingsDialog::RunAutomountSettings(AutoMounter *target) return; } - BMessage message; - target->GetSettings(&message); - (new AutomountSettingsDialog(&message, target))->Show(); + BMessage message(kGetAutomounterParams); + BMessage reply; + status_t ret = target.SendMessage(&message, &reply, 2500000); + if (ret != B_OK) { + (new BAlert("Mount Server Error", "The mount server could not be " + "contacted.", "Ok", NULL, NULL, B_WIDTH_AS_USUAL, + B_STOP_ALERT))->Go(); + return; + } + + (new AutomountSettingsDialog(&reply, target))->Show(); } diff --git a/src/kits/tracker/AutoMounterSettings.h b/src/kits/tracker/AutoMounterSettings.h index 4bb0d07bf1..88fa68de11 100644 --- a/src/kits/tracker/AutoMounterSettings.h +++ b/src/kits/tracker/AutoMounterSettings.h @@ -41,14 +41,12 @@ All rights reserved. namespace BPrivate { -class AutoMounter; - class AutomountSettingsDialog : public BWindow { public: - AutomountSettingsDialog(BMessage *settings, AutoMounter *); + AutomountSettingsDialog(BMessage *settings, const BMessenger &target); virtual ~AutomountSettingsDialog(); - static void RunAutomountSettings(AutoMounter *); + static void RunAutomountSettings(const BMessenger &target); private: static AutomountSettingsDialog *sOneCopyOnly; diff --git a/src/kits/tracker/Commands.h b/src/kits/tracker/Commands.h index 91aac36756..6f933afaca 100644 --- a/src/kits/tracker/Commands.h +++ b/src/kits/tracker/Commands.h @@ -37,6 +37,8 @@ All rights reserved. #include "PublicCommands.h" +#include + namespace BPrivate { // external app messages @@ -77,7 +79,6 @@ const uint32 kEmptyTrash = 'Tetr'; const uint32 kAddPrinter = 'Tadp'; const uint32 kMakeActivePrinter = 'Tmap'; -const uint32 kUnmountVolume = 'Tunm'; const uint32 kRunAutomounterSettings = 'Tram'; const uint32 kOpenParentDir = 'Topt'; diff --git a/src/kits/tracker/Jamfile b/src/kits/tracker/Jamfile index 039c7ac789..55344fd685 100644 --- a/src/kits/tracker/Jamfile +++ b/src/kits/tracker/Jamfile @@ -3,18 +3,18 @@ SubDir HAIKU_TOP src kits tracker ; SetSubDirSupportedPlatformsBeOSCompatible ; AddSubDirSupportedPlatforms libbe_test ; -UsePrivateHeaders interface shared storage tracker ; +UsePrivateHeaders interface mount shared storage tracker ; UseLibraryHeaders icon ; AddResources libtracker.so : TrackerIcons.rdef ; -SubDirC++Flags +SubDirC++Flags -D_BUILDING_tracker=1 -DOPEN_TRACKER=1 # -D_INCLUDES_CLASS_DEVICE_MAP=1 -D_SUPPORTS_RESOURCES=1 -D_SUPPORTS_FEATURE_SCRIPTING=1 -# -D_SILENTLY_CORRECT_FILE_NAMES=1 +# -D_SILENTLY_CORRECT_FILE_NAMES=1 ; local vector_icon_libs ; @@ -24,7 +24,6 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) && $(TARGET_PLATFORM) != libbe_test { SharedLibrary libtracker.so : AttributeStream.cpp - AutoMounter.cpp AutoMounterSettings.cpp BackgroundImage.cpp Bitmaps.cpp diff --git a/src/kits/tracker/MountMenu.cpp b/src/kits/tracker/MountMenu.cpp index 5c9171ee98..d729b24bc3 100644 --- a/src/kits/tracker/MountMenu.cpp +++ b/src/kits/tracker/MountMenu.cpp @@ -42,27 +42,18 @@ All rights reserved. #include #include -#include "AutoMounter.h" #include "Commands.h" #include "MountMenu.h" #include "IconMenuItem.h" #include "Tracker.h" #include "Bitmaps.h" -#ifdef __HAIKU__ -# include -# include -#else -# include "DeviceMap.h" -#endif +#include +#include #define SHOW_NETWORK_VOLUMES -#ifdef __HAIKU__ -// #pragma mark - Haiku Disk Device API - - class AddMenuItemVisitor : public BDiskDeviceVisitor { public: AddMenuItemVisitor(BMenu* menu); @@ -159,74 +150,6 @@ AddMenuItemVisitor::Visit(BPartition *partition, int32 level) return false; } -#else // !__HAIKU__ -// #pragma mark - R5 DeviceMap API - - -struct AddOneAsMenuItemParams { - BMenu *mountMenu; -}; - - -static Partition * -AddOnePartitionAsMenuItem(Partition *partition, void *castToParams) -{ - if (partition->Hidden()) - return NULL; - - AddOneAsMenuItemParams *params = (AddOneAsMenuItemParams *)castToParams; - BBitmap *icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), - B_CMAP8); - get_device_icon(partition->GetDevice()->Name(), icon->Bits(), B_MINI_ICON); - - - const char *name = partition->GetDevice()->DisplayName(); - - if (!partition->GetDevice()->IsFloppy() || - partition->Mounted() == kMounted) { - if (*partition->VolumeName()) - name = partition->VolumeName(); - else if (*partition->Type()) - name = partition->Type(); - } - - BMessage *message = new BMessage; - - if (partition->Mounted() == kMounted) { - message->what = kUnmountVolume; - message->AddInt32("device_id", partition->VolumeDeviceID()); - } else { - message->what = kMountVolume; - - // - // Floppies have an ID of -1, because they don't have - // partition (and hence no parititon ID). - // - if (partition->GetDevice()->IsFloppy()) - message->AddInt32("id", kFloppyID); - else - message->AddInt32("id", partition->UniqueID()); - } - - BMenuItem *item = new IconMenuItem(name, message, icon); - if (partition->Mounted() == kMounted) - item->SetMarked(true); - - if (partition->Mounted() == kMounted) { - BVolume partVolume(partition->VolumeDeviceID()); - - BVolume bootVolume; - BVolumeRoster().GetBootVolume(&bootVolume); - if (partVolume == bootVolume) - item->SetEnabled(false); - } - - params->mountMenu->AddItem(item); - - return NULL; -} -#endif // !__HAIKU__ - // #pragma mark - @@ -249,23 +172,12 @@ MountMenu::AddDynamicItem(add_state) delete item; } -#ifdef __HAIKU__ BDiskDeviceList devices; status_t status = devices.Fetch(); if (status == B_OK) { AddMenuItemVisitor visitor(this); devices.VisitEachPartition(&visitor); } -#else - AddOneAsMenuItemParams params; - params.mountMenu = this; - - AutoMounter *autoMounter = dynamic_cast(be_app)-> - AutoMounterLoop(); - - autoMounter->CheckVolumesNow(); - autoMounter->EachPartition(&AddOnePartitionAsMenuItem, ¶ms); -#endif #ifdef SHOW_NETWORK_VOLUMES // iterate the volume roster and look for volumes with the @@ -302,16 +214,8 @@ MountMenu::AddDynamicItem(add_state) AddSeparatorItem(); -#ifndef __HAIKU__ - // add an option to rescan the scsii bus, etc. - BMenuItem *rescanItem = NULL; - if (modifiers() & B_SHIFT_KEY) { - rescanItem = new BMenuItem("Rescan Devices", new BMessage(kAutomounterRescan)); - AddItem(rescanItem); - } -#endif - - BMenuItem *mountAll = new BMenuItem("Mount All", new BMessage(kMountAllNow)); + BMenuItem *mountAll = new BMenuItem("Mount All", + new BMessage(kMountAllNow)); AddItem(mountAll); BMenuItem *mountSettings = new BMenuItem("Settings" B_UTF8_ELLIPSIS, new BMessage(kRunAutomounterSettings)); @@ -319,10 +223,5 @@ MountMenu::AddDynamicItem(add_state) SetTargetForItems(be_app); -#ifndef __HAIKU__ - if (rescanItem) - rescanItem->SetTarget(autoMounter); -#endif - return false; } diff --git a/src/kits/tracker/SettingsViews.cpp b/src/kits/tracker/SettingsViews.cpp index a2263bbd88..f21b3e3ab4 100644 --- a/src/kits/tracker/SettingsViews.cpp +++ b/src/kits/tracker/SettingsViews.cpp @@ -61,7 +61,7 @@ static const rgb_color kDefaultUsedSpaceColor = {0, 203, 0, kSpaceBarAlpha}; static const rgb_color kDefaultFreeSpaceColor = {255, 255, 255, kSpaceBarAlpha}; static const rgb_color kDefaultWarningSpaceColor = {203, 0, 0, kSpaceBarAlpha}; - + static void send_bool_notices(uint32 what, const char *name, bool value) { @@ -153,7 +153,7 @@ SettingsView::ShowCurrentSettings() bool SettingsView::IsRevertable() const { - return true; + return true; } @@ -168,10 +168,10 @@ DesktopSettingsView::DesktopSettingsView(BRect rect) new BMessage(kShowDisksIconChanged)); fShowDisksIconRadioButton->ResizeToPreferred(); AddChild(fShowDisksIconRadioButton); - + const float itemSpacing = fShowDisksIconRadioButton->Bounds().Height() + kItemExtraSpacing; rect.OffsetBy(0, itemSpacing); - + fMountVolumesOntoDesktopRadioButton = new BRadioButton(rect, "", "Show Volumes on Desktop", new BMessage(kVolumesOnDesktopChanged)); AddChild(fMountVolumesOntoDesktopRadioButton); @@ -186,18 +186,13 @@ DesktopSettingsView::DesktopSettingsView(BRect rect) rect.OffsetBy(-20, itemSpacing); - fEjectWhenUnmountingCheckBox = new BCheckBox(rect, "", "Eject When Unmounting", - new BMessage(kEjectWhenUnmountingChanged)); - AddChild(fEjectWhenUnmountingCheckBox); - fEjectWhenUnmountingCheckBox->ResizeToPreferred(); - rect = Bounds(); rect.top = rect.bottom; fMountButton = new BButton(rect, "", "Mount Settings" B_UTF8_ELLIPSIS, new BMessage(kRunAutomounterSettings), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); fMountButton->ResizeToPreferred(); fMountButton->MoveBy(0, -fMountButton->Bounds().Height()); - AddChild(fMountButton); + AddChild(fMountButton); fMountButton->SetTarget(be_app); } @@ -211,7 +206,7 @@ DesktopSettingsView::GetPreferredSize(float *_width, float *_height) } if (_height != NULL) { - *_height = fEjectWhenUnmountingCheckBox->Frame().bottom + 8 + *_height = fMountSharedVolumesOntoDesktopCheckBox->Frame().bottom + 8 + fMountButton->Bounds().Height(); } } @@ -223,7 +218,6 @@ DesktopSettingsView::AttachedToWindow() fShowDisksIconRadioButton->SetTarget(this); fMountVolumesOntoDesktopRadioButton->SetTarget(this); fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this); - fEjectWhenUnmountingCheckBox->SetTarget(this); } @@ -236,7 +230,7 @@ DesktopSettingsView::MessageReceived(BMessage *message) TrackerSettings settings; - switch (message->what) { + switch (message->what) { case kShowDisksIconChanged: { // Turn on and off related settings: @@ -244,15 +238,15 @@ DesktopSettingsView::MessageReceived(BMessage *message) !fShowDisksIconRadioButton->Value() == 1); fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( fMountVolumesOntoDesktopRadioButton->Value() == 1); - + // Set the new settings in the tracker: settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1); settings.SetMountVolumesOntoDesktop( fMountVolumesOntoDesktopRadioButton->Value() == 1); settings.SetMountSharedVolumesOntoDesktop( fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); - - // Construct the notification message: + + // Construct the notification message: BMessage notificationMessage; notificationMessage.AddBool("ShowDisksIcon", fShowDisksIconRadioButton->Value() == 1); @@ -276,15 +270,15 @@ DesktopSettingsView::MessageReceived(BMessage *message) !fMountVolumesOntoDesktopRadioButton->Value() == 1); fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( fMountVolumesOntoDesktopRadioButton->Value() == 1); - + // Set the new settings in the tracker: settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1); settings.SetMountVolumesOntoDesktop( fMountVolumesOntoDesktopRadioButton->Value() == 1); settings.SetMountSharedVolumesOntoDesktop( fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); - - // Construct the notification message: + + // Construct the notification message: BMessage notificationMessage; notificationMessage.AddBool("ShowDisksIcon", fShowDisksIconRadioButton->Value() == 1); @@ -301,20 +295,6 @@ DesktopSettingsView::MessageReceived(BMessage *message) break; } - case kEjectWhenUnmountingChanged: - { - settings.SetEjectWhenUnmounting( - fEjectWhenUnmountingCheckBox->Value() == 1); - - // Send the notification message - send_bool_notices(kEjectWhenUnmountingChanged, - "EjectWhenUnmounting", fEjectWhenUnmountingCheckBox->Value() == 1); - - // Tell the settings window the contents have changed - Window()->PostMessage(kSettingsContentsModified); - break; - } - default: _inherited::MessageReceived(message); } @@ -374,7 +354,7 @@ DesktopSettingsView::_SendNotices() if (!tracker) return; - // Construct the notification message: + // Construct the notification message: BMessage notificationMessage; notificationMessage.AddBool("ShowDisksIcon", fShowDisksIconRadioButton->Value() == 1); @@ -382,8 +362,6 @@ DesktopSettingsView::_SendNotices() fMountVolumesOntoDesktopRadioButton->Value() == 1); notificationMessage.AddBool("MountSharedVolumesOntoDesktop", fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); - notificationMessage.AddBool("EjectWhenUnmounting", - fEjectWhenUnmountingCheckBox->Value() == 1); // Send notices to the tracker about the change: tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); @@ -401,8 +379,6 @@ DesktopSettingsView::ShowCurrentSettings() fMountSharedVolumesOntoDesktopCheckBox->SetValue(settings.MountSharedVolumesOntoDesktop()); fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(settings.MountVolumesOntoDesktop()); - - fEjectWhenUnmountingCheckBox->SetValue(settings.EjectWhenUnmounting()); } @@ -426,9 +402,7 @@ DesktopSettingsView::IsRevertable() const || fMountVolumesOntoDesktop != (fMountVolumesOntoDesktopRadioButton->Value() > 0) || fMountSharedVolumesOntoDesktop != - (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0) - || fEjectWhenUnmounting != - (fEjectWhenUnmountingCheckBox->Value() > 0); + (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0); } @@ -504,7 +478,7 @@ WindowsSettingsView::MessageReceived(BMessage *message) if (!tracker) return; TrackerSettings settings; - + switch (message->what) { case kWindowsShowFullPathChanged: settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBarCheckBox->Value() == 1); @@ -520,7 +494,7 @@ WindowsSettingsView::MessageReceived(BMessage *message) } else { fShowNavigatorCheckBox->SetEnabled(true); settings.SetShowNavigator(fShowNavigatorCheckBox->Value() != 0); - } + } tracker->SendNotices(kShowNavigatorChanged); tracker->SendNotices(kSingleWindowBrowseChanged); Window()->PostMessage(kSettingsContentsModified); @@ -563,7 +537,7 @@ WindowsSettingsView::MessageReceived(BMessage *message) } } - + void WindowsSettingsView::SetDefaults() { @@ -869,7 +843,7 @@ TimeFormatSettingsView::MessageReceived(BMessage *message) Window()->PostMessage(kSettingsContentsModified); break; } - + default: _inherited::MessageReceived(message); } @@ -1021,7 +995,7 @@ TimeFormatSettingsView::_UpdateExamples() separator = kSlashSeparator; } else separator = kSlashSeparator; - + DateOrder order = fYMDRadioButton->Value() ? kYMDFormat : (fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat); @@ -1036,7 +1010,7 @@ TimeFormatSettingsView::_UpdateExamples() TimeFormat(timeFormat, 4, separator, order, clockIs24hr); strftime(buffer, 256, timeFormat.String(), &timeData); - + fShortDateExampleView->SetText(buffer); fShortDateExampleView->ResizeToPreferred(); } @@ -1153,10 +1127,10 @@ SpaceBarSettingsView::MessageReceived(BMessage *message) case kSpaceBarColorChanged: { - rgb_color color = fColorControl->ValueAsColor(); + rgb_color color = fColorControl->ValueAsColor(); color.alpha = kSpaceBarAlpha; //alpha is ignored by BColorControl but is checked in equalities - + switch (fCurrentColor) { case 0: settings.SetUsedSpaceColor(color); @@ -1177,7 +1151,7 @@ SpaceBarSettingsView::MessageReceived(BMessage *message) default: _inherited::MessageReceived(message); break; - } + } } @@ -1345,7 +1319,7 @@ TrashSettingsView::MessageReceived(BMessage *message) if (!tracker) return; TrackerSettings settings; - + switch (message->what) { case kDontMoveFilesToTrashChanged: settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrashCheckBox->Value() == 1); @@ -1367,7 +1341,7 @@ TrashSettingsView::MessageReceived(BMessage *message) } } - + void TrashSettingsView::SetDefaults() { diff --git a/src/kits/tracker/SettingsViews.h b/src/kits/tracker/SettingsViews.h index 82355714e2..f427b68a22 100644 --- a/src/kits/tracker/SettingsViews.h +++ b/src/kits/tracker/SettingsViews.h @@ -89,7 +89,6 @@ class DesktopSettingsView : public SettingsView { BRadioButton *fMountVolumesOntoDesktopRadioButton; BCheckBox *fMountSharedVolumesOntoDesktopCheckBox; BCheckBox *fIntegrateNonBootBeOSDesktopsCheckBox; - BCheckBox *fEjectWhenUnmountingCheckBox; BButton *fMountButton; bool fShowDisksIcon; @@ -138,7 +137,7 @@ class TimeFormatSettingsView : public SettingsView { TimeFormatSettingsView(BRect frame); virtual void MessageReceived(BMessage *message); - virtual void AttachedToWindow(); + virtual void AttachedToWindow(); virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); diff --git a/src/kits/tracker/Tracker.cpp b/src/kits/tracker/Tracker.cpp index 55f227c3a3..c9cc9c00f9 100644 --- a/src/kits/tracker/Tracker.cpp +++ b/src/kits/tracker/Tracker.cpp @@ -56,7 +56,6 @@ All rights reserved. #include "Attributes.h" #include "AutoLock.h" -#include "AutoMounter.h" #include "AutoMounterSettings.h" #include "BackgroundImage.h" #include "Bitmaps.h" @@ -349,10 +348,6 @@ TTracker::Quit() { TrackerSettings().SaveSettings(false); - fAutoMounter->Lock(); - fAutoMounter->QuitRequested(); // automounter does some stuff in QuitRequested - fAutoMounter->Quit(); // but we really don't care if it is cooperating or not - fClipboardRefsWatcher->Lock(); fClipboardRefsWatcher->Quit(); @@ -376,11 +371,6 @@ TTracker::MessageReceived(BMessage *message) return; switch (message->what) { - case kOpenPreviouslyOpenWindows: - if (!BootedInSafeMode()) - _OpenPreviouslyOpenedWindows(); - break; - case kGetInfo: OpenInfoWindows(message); break; @@ -415,35 +405,6 @@ TTracker::MessageReceived(BMessage *message) EditQueries(message); break; - case kUnmountVolume: - // When the user attempts to unmount a volume from the mount - // context menu, this is where the message gets received. - // Save pose locations and forward this to the automounter - SaveAllPoseLocations(); - fAutoMounter->PostMessage(message); - break; - - case kRunAutomounterSettings: - AutomountSettingsDialog::RunAutomountSettings(fAutoMounter); - break; - - case kVolumeMounted: - { - // This is sent to us by the AutoMounter whenever it mounts - // a new volume - we use it to restore the previously opened - // windows from that volume in case it has been mounted - // during the AutoMounter's initial rescan - const char* path; - bool initial; - if (message->FindBool("initial rescan", &initial) != B_OK - || message->FindString("path", &path) != B_OK - || !initial) - break; - - _OpenPreviouslyOpenedWindows(path); - break; - } - case kShowSplash: run_be_about(); break; @@ -461,31 +422,40 @@ TTracker::MessageReceived(BMessage *message) #ifdef MOUNT_MENU_IN_DESKBAR case 'gmtv': - { - // Someone (probably the deskbar) has requested a list of - // mountable volumes. - BMessage reply; - AutoMounterLoop()->EachMountableItemAndFloppy(&AddMountableItemToMessage, - &reply); - message->SendReply(&reply); - break; - } + { + // Someone (probably the deskbar) has requested a list of + // mountable volumes. + BMessage reply; + AutoMounterLoop()->EachMountableItemAndFloppy(&AddMountableItemToMessage, + &reply); + message->SendReply(&reply); + break; + } #endif + case kUnmountVolume: + // When the user attempts to unmount a volume from the mount + // context menu, this is where the message gets received. + // Save pose locations and forward this to the automounter + SaveAllPoseLocations(); + // Fall through... case kMountVolume: case kMountAllNow: - AutoMounterLoop()->PostMessage(message); + MountServer().SendMessage(message); break; + case kRunAutomounterSettings: + AutomountSettingsDialog::RunAutomountSettings(MountServer()); + break; case kRestoreBackgroundImage: - { - BDeskWindow *desktop = GetDeskWindow(); - AutoLock lock(desktop); - desktop->UpdateDesktopBackgroundImages(); - } + { + BDeskWindow *desktop = GetDeskWindow(); + AutoLock lock(desktop); + desktop->UpdateDesktopBackgroundImages(); break; + } case kShowSettingsWindow: ShowSettingsWindow(); @@ -514,16 +484,13 @@ TTracker::MessageReceived(BMessage *message) } case kFSClipboardChanges: - { fClipboardRefsWatcher->UpdatePoseViews(message); break; - } case kShowVolumeSpaceBar: - case kSpaceBarColorChanged: { + case kSpaceBarColorChanged: gPeriodicUpdatePoses.DoPeriodicUpdate(true); break; - } default: _inherited::MessageReceived(message); @@ -1335,9 +1302,6 @@ TTracker::ReadyToRun() fClipboardRefsWatcher = new BClipboardRefsWatcher(); fClipboardRefsWatcher->Run(); - fAutoMounter = new AutoMounter(); - fAutoMounter->Run(); - fTaskLoop = new StandAloneTaskLoop(true); // open desktop window @@ -1383,6 +1347,8 @@ TTracker::ReadyToRun() if (!BootedInSafeMode()) { // kick of transient query killer DeleteTransientQueriesTask::StartUpTransientQueryCleaner(); + // the mount_server will have mounted the previous volumes already. + _OpenPreviouslyOpenedWindows(); } } @@ -1570,10 +1536,10 @@ TTracker::WatchNode(const node_ref *node, uint32 flags, } -AutoMounter * -TTracker::AutoMounterLoop() +BMessenger +TTracker::MountServer() const { - return fAutoMounter; + return BMessenger(kMountServerSignature); } diff --git a/src/kits/tracker/Tracker.h b/src/kits/tracker/Tracker.h index 2269fb1e6f..e3995767f7 100644 --- a/src/kits/tracker/Tracker.h +++ b/src/kits/tracker/Tracker.h @@ -47,7 +47,6 @@ All rights reserved. namespace BPrivate { -class AutoMounter; class BClipboardRefsWatcher; class BContainerWindow; class BDeskWindow; @@ -127,7 +126,7 @@ class TTracker : public BApplication { // again TaskLoop *MainTaskLoop() const; - AutoMounter *AutoMounterLoop(); + BMessenger MountServer() const; bool QueryActiveForDevice(dev_t); void CloseActiveQueryWindows(dev_t); @@ -212,11 +211,10 @@ class TTracker : public BApplication { const node_ref *nodeToSelect = NULL, OpenSelector selector = kOpen, const BMessage *messageToBundle = NULL); - MimeTypeList *fMimeTypeList; + MimeTypeList *fMimeTypeList; WindowList fWindowList; BClipboardRefsWatcher *fClipboardRefsWatcher; BTrashWatcher *fTrashWatcher; - AutoMounter *fAutoMounter; TaskLoop *fTaskLoop; int32 fNodeMonitorCount;