⛏️ index : haiku.git

author John Scipione <jscipione@gmail.com> 2025-11-16 14:19:39.0 -05:00:00
committer John Scipione <jscipione@gmail.com> 2025-11-30 19:05:25.0 +00:00:00
commit
d7022afd57b23949832639587704bd93c911f15d [patch]
tree
feec772f3c882d94f66384568b8116b141af415b
parent
1584b1ecaba938c2cc82f5de7b6dd79f0c9e23a5
download
d7022afd57b23949832639587704bd93c911f15d.tar.gz

Tracker: Simplify adding/removing poses when mounting/unmounting

... and sorting.

Change-Id: Ia72e85d12682d4f77200629f3f5f278a9a40c423
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9890
Reviewed-by: John Scipione <jscipione@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>

Diff

 src/kits/tracker/DesktopPoseView.cpp | 71 ++++++++++++++++-------------------------------------------------------
 src/kits/tracker/DesktopPoseView.h   |  3 ---
 src/kits/tracker/FilePanelPriv.cpp   | 64 +---------------------------------------------------------------
 src/kits/tracker/FilePanelPriv.h     |  3 ---
 src/kits/tracker/PoseView.cpp        | 59 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 5 files changed, 49 insertions(+), 151 deletions(-)

diff --git a/src/kits/tracker/DesktopPoseView.cpp b/src/kits/tracker/DesktopPoseView.cpp
index 54f84b1..5348a8b 100644
--- a/src/kits/tracker/DesktopPoseView.cpp
+++ b/src/kits/tracker/DesktopPoseView.cpp
@@ -187,58 +187,9 @@


bool
DesktopPoseView::FSNotification(const BMessage* message)
{
	switch (message->GetInt32("opcode", 0)) {
		case B_DEVICE_MOUNTED:
		{
			dev_t device;
			if (message->FindInt32("new device", &device) != B_OK)
				break;

			ASSERT(TargetModel());
			TrackerSettings settings;

			BVolume volume(device);
			if (volume.InitCheck() != B_OK)
				break;

			if (settings.MountVolumesOntoDesktop()
				&& (!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())) {
				// place an icon for the volume onto the desktop
				CreateVolumePose(&volume);
			}
		}
		break;
	}

	return _inherited::FSNotification(message);
}


bool
DesktopPoseView::AddPosesThreadValid(const entry_ref*) const
{
	return true;
}


void
DesktopPoseView::AddPosesCompleted()
{
	_inherited::AddPosesCompleted();

	CreateTrashPose();
	CheckAutoPlacedPoses();
}


void
DesktopPoseView::AddPoses(Model* model)
{
	AddVolumePoses();

	_inherited::AddPoses(model);
}


@@ -265,11 +216,12 @@
void
DesktopPoseView::StartSettingsWatch()
{
	if (be_app->LockLooper()) {
		be_app->StartWatching(this, kShowDisksIconChanged);
		be_app->StartWatching(this, kVolumesOnDesktopChanged);
		be_app->StartWatching(this, kDesktopIntegrationChanged);
		be_app->UnlockLooper();
	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
	if (tracker != NULL && tracker->LockLooper()) {
		tracker->StartWatching(this, kShowDisksIconChanged);
		tracker->StartWatching(this, kVolumesOnDesktopChanged);
		tracker->StartWatching(this, kDesktopIntegrationChanged);
		tracker->UnlockLooper();
	}
}

@@ -277,11 +229,12 @@
void
DesktopPoseView::StopSettingsWatch()
{
	if (be_app->LockLooper()) {
		be_app->StopWatching(this, kShowDisksIconChanged);
		be_app->StopWatching(this, kVolumesOnDesktopChanged);
		be_app->StopWatching(this, kDesktopIntegrationChanged);
		be_app->UnlockLooper();
	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
	if (tracker != NULL && tracker->LockLooper()) {
		tracker->StopWatching(this, kShowDisksIconChanged);
		tracker->StopWatching(this, kVolumesOnDesktopChanged);
		tracker->StopWatching(this, kDesktopIntegrationChanged);
		tracker->UnlockLooper();
	}
}

diff --git a/src/kits/tracker/DesktopPoseView.h b/src/kits/tracker/DesktopPoseView.h
index bef9ebb..eba9a16 100644
--- a/src/kits/tracker/DesktopPoseView.h
+++ b/src/kits/tracker/DesktopPoseView.h
@@ -62,11 +62,8 @@

protected:
	virtual EntryListBase* InitDirentIterator(const entry_ref*);
	virtual bool FSNotification(const BMessage*);

	virtual bool AddPosesThreadValid(const entry_ref*) const;
	virtual void AddPosesCompleted();
	virtual void AddPoses(Model* model = NULL);

	virtual bool IsDesktopView() const;

diff --git a/src/kits/tracker/FilePanelPriv.cpp b/src/kits/tracker/FilePanelPriv.cpp
index 0b96d73..4c158a2 100644
--- a/src/kits/tracker/FilePanelPriv.cpp
+++ b/src/kits/tracker/FilePanelPriv.cpp
@@ -1755,53 +1755,6 @@
}


bool
BFilePanelPoseView::FSNotification(const BMessage* message)
{
	switch (message->GetInt32("opcode", 0)) {
		case B_DEVICE_MOUNTED:
		{
			if (!IsDesktop() && !TargetModel()->IsRoot())
				break;

			dev_t device;
			if (message->FindInt32("new device", &device) != B_OK)
				break;

			ASSERT(TargetModel() != NULL);
			TrackerSettings settings;

			BVolume volume(device);
			if (volume.InitCheck() != B_OK)
				break;

			// place volume icon onto Desktop or Root
			if ((!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())
				&& ((IsVolumesRoot() && settings.MountVolumesOntoDesktop())
					|| TargetModel()->IsRoot())) {
				CreateVolumePose(&volume);
			}
			break;
		}

		case B_DEVICE_UNMOUNTED:
		{
			dev_t device;
			if (message->FindInt32("device", &device) == B_OK) {
				if (TargetModel() != NULL && TargetModel()->NodeRef()->device == device) {
					// Volume currently shown in this file panel
					// disappeared, reset location to home directory
					BMessage message(kSwitchToHome);
					MessageReceived(&message);
				}
			}
			break;
		}
	}
	return _inherited::FSNotification(message);
}


void
BFilePanelPoseView::RestoreState(AttributeStreamNode* node)
{
@@ -1836,26 +1789,11 @@
void
BFilePanelPoseView::AddPosesCompleted()
{
	_inherited::AddPosesCompleted();

	if (IsDesktop())
		CreateTrashPose();

	// the menu that adds these shortcuts may not exist initially
	Window()->AddShortcut('D', B_COMMAND_KEY, new BMessage(kSwitchToDesktop));
	Window()->AddShortcut('H', B_COMMAND_KEY, new BMessage(kSwitchToHome));

	UpdateScrollRange();
}


void
BFilePanelPoseView::AddPoses(Model* model)
{
	if (IsDesktop())
		AddVolumePoses();

	_inherited::AddPoses(model);
	_inherited::AddPosesCompleted();
}


diff --git a/src/kits/tracker/FilePanelPriv.h b/src/kits/tracker/FilePanelPriv.h
index 0a99f84..c189792 100644
--- a/src/kits/tracker/FilePanelPriv.h
+++ b/src/kits/tracker/FilePanelPriv.h
@@ -178,8 +178,6 @@
	BFilePanelPoseView(Model*);

	virtual bool IsFilePanel() const;
	virtual bool FSNotification(const BMessage*);

	virtual bool IsDesktop() const { return fIsDesktop; };
	void SetIsDesktop(bool on) { fIsDesktop = on; };

@@ -195,7 +193,6 @@

	virtual EntryListBase* InitDirentIterator(const entry_ref*);
	virtual void AddPosesCompleted();
	virtual void AddPoses(Model* model = NULL);
	virtual bool IsVolumesRoot() const { return fIsDesktop; };

	void AdaptToVolumeChange(BMessage*);
diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
index 519548e..160c90f 100644
--- a/src/kits/tracker/PoseView.cpp
+++ b/src/kits/tracker/PoseView.cpp
@@ -1285,7 +1285,8 @@
	if (TargetModel()->IsRoot()) {
		AddVolumePoses();
		return;
	}
	} else if (IsVolumesRoot())
		AddVolumePoses();

	ShowBarberPole();

@@ -1700,6 +1701,10 @@
	BContainerWindow* window = ContainerWindow();
	if (window != NULL && window->ShouldAddMenus())
		window->AddMimeTypesToMenu();

	// add Trash icon to Desktop
	if (IsVolumesRoot())
		CreateTrashPose();

	// if we're not in icon mode then we need to check for poses that
	// were "auto" placed to see if they overlap with other icons
@@ -1716,6 +1721,9 @@
		float lastItemTop = (CurrentPoseList()->CountItems() - 1) * fListElemHeight;
		if (bounds.top > lastItemTop)
			_inherited::ScrollTo(bounds.left, std::max(lastItemTop, 0.0f));

		SortPoses();
		Invalidate();
	}
}

@@ -5397,6 +5405,7 @@
	node_ref itemNode;
	dev_t device;
	Model* targetModel = TargetModel();
	TrackerSettings settings;

	switch (message->GetInt32("opcode", 0)) {
		case B_ENTRY_CREATED:
@@ -5414,7 +5423,6 @@
			// Query windows can get notices on different dirNodes
			// The Disks window can too
			// So can the Desktop, as long as the integrate flag is on
			TrackerSettings settings;
			if (targetModel != NULL && dirNode != *targetModel->NodeRef()
				&& !targetModel->IsQuery()
				&& !targetModel->IsVirtualDirectory()
@@ -5529,16 +5537,19 @@
			if (message->FindInt32("new device", &device) != B_OK)
				break;

			if (targetModel != NULL && targetModel->IsRoot()) {
				BVolume volume(device);
				if (volume.InitCheck() == B_OK)
					CreateVolumePose(&volume);
			} else if (TargetModel()->IsTrash()) {
				// add trash items from newly mounted volume
			BVolume volume(device);
			if (volume.InitCheck() != B_OK)
				break;

			ASSERT(targetModel != NULL);
			if (targetModel->IsRoot() // always create volume poses on root
				|| ((IsVolumesRoot() && settings.MountVolumesOntoDesktop())
					&& ((!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())))) {
				CreateVolumePose(&volume);
			} else if (targetModel->IsTrash()) {
				// add trash items from newly mounted volume
				BDirectory trashDir;
				BEntry entry;
				BVolume volume(device);
				if (FSGetTrashDir(&trashDir, volume.Device()) == B_OK
					&& trashDir.GetEntry(&entry) == B_OK) {
					Model model(&entry);
@@ -5560,14 +5571,19 @@

		case B_DEVICE_UNMOUNTED:
			if (message->FindInt32("device", &device) == B_OK) {
				if (targetModel != NULL
					&& targetModel->NodeRef()->device == device) {
					// close the window from a volume that is gone
					DisableSaveLocation();
					Window()->Close();
				} else if (targetModel != NULL) {
					EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted,
						this, device);
				ASSERT(targetModel != NULL);
				if (targetModel->NodeRef()->device == device) {
					if (IsFilePanel()) {
						// reset location to home directory
						BMessage message(kSwitchToHome);
						Window()->PostMessage(&message, this);
					} else {
						// close the window from a volume that is gone
						DisableSaveLocation();
						Window()->Close();
					}
				} else {
					EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted, this, device);
				}
			}
			break;
@@ -9608,12 +9624,9 @@
	PRINT(("===================\n"));
#endif

	BPose** poses = reinterpret_cast<BPose**>(fPoseList->AsBList()->Items());
	std::stable_sort(poses, &poses[fPoseList->CountItems()], PoseComparator(this));
	if (IsFiltering()) {
		poses = reinterpret_cast<BPose**>(fFilteredPoseList->AsBList()->Items());
		std::stable_sort(poses, &poses[fFilteredPoseList->CountItems()], PoseComparator(this));
	}
	PoseList* poseList = CurrentPoseList();
	BPose** poses = reinterpret_cast<BPose**>(poseList->AsBList()->Items());
	std::stable_sort(poses, &poses[poseList->CountItems()], PoseComparator(this));
}