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(-)
@@ -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())) {
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();
}
}
@@ -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;
@@ -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;
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) {
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();
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();
}
@@ -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*);
@@ -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();
if (IsVolumesRoot())
CreateTrashPose();
@@ -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 @@
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()) {
BVolume volume(device);
if (volume.InitCheck() != B_OK)
break;
ASSERT(targetModel != NULL);
if (targetModel->IsRoot()
|| ((IsVolumesRoot() && settings.MountVolumesOntoDesktop())
&& ((!volume.IsShared() || settings.MountSharedVolumesOntoDesktop())))) {
CreateVolumePose(&volume);
} else if (targetModel->IsTrash()) {
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) {
DisableSaveLocation();
Window()->Close();
} else if (targetModel != NULL) {
EachPoseAndModel(fPoseList, &PoseHandleDeviceUnmounted,
this, device);
ASSERT(targetModel != NULL);
if (targetModel->NodeRef()->device == device) {
if (IsFilePanel()) {
BMessage message(kSwitchToHome);
Window()->PostMessage(&message, this);
} else {
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));
}