From abef198c1ac3ade338630375b204dcaa453ca41d Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 31 Dec 2021 13:40:02 +0100 Subject: [PATCH] Tracker: fix logic to use custom icons. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Regression caused by refactorings in hrev55348. The logic for deciding when to use a built-in tracker icon was changed incorrectly to ignore attributes on directories, trash, etc (anything but executable applications). So the built-in icon was always used. This commit restores the previous logic. Shoud fix #17320 and #17371 Change-Id: I51ba22db59a8b6dd2bd1121b56c753ed47224c57 Reviewed-on: https://review.haiku-os.org/c/haiku/+/4841 Reviewed-by: Jérôme Duval Tested-by: Commit checker robot --- src/kits/tracker/Model.cpp | 40 +++++++++++++++++++++++++------------- src/kits/tracker/Model.h | 2 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/kits/tracker/Model.cpp b/src/kits/tracker/Model.cpp index e9226e547d..e14034db43 100644 --- a/src/kits/tracker/Model.cpp +++ b/src/kits/tracker/Model.cpp @@ -599,7 +599,7 @@ Model::FinishSettingUpType() // makes sense to look for a node-based icon. This serves as a hint to the // icon cache, allowing it to not hit the disk again for models that do not // have an icon defined by the node. - if (CheckNodeIconHint()) + if (fBaseType != kLinkNode && !CheckAppIconHint()) fIconFrom = kUnknownNotFromNode; if (fBaseType != kDirectoryNode @@ -623,7 +623,7 @@ Model::FinishSettingUpType() if (fPreferredAppName) DeletePreferredAppVolumeNameLinkTo(); - if (*type != '0') + if (*type != '\0') fPreferredAppName = strdup(type); } } @@ -720,11 +720,12 @@ Model::FinishSettingUpType() bool -Model::CheckNodeIconHint() const +Model::ShouldUseWellKnownIcon() const { - return (fBaseType == kDirectoryNode || fBaseType == kVolumeNode - || fBaseType == kTrashNode || fBaseType == kDesktopNode) - || (fBaseType == kExecutableNode && !CheckAppIconHint()); + if (fBaseType == kDirectoryNode || fBaseType == kVolumeNode + || fBaseType == kTrashNode || fBaseType == kDesktopNode) + return !CheckAppIconHint(); + return false; } @@ -732,13 +733,24 @@ bool Model::CheckAppIconHint() const { attr_info info; - return fNode != NULL - // node is open, and it - && (fNode->GetAttrInfo(kAttrIcon, &info) == B_OK - // has a vector icon, or - || (fNode->GetAttrInfo(kAttrMiniIcon, &info) == B_OK - && fNode->GetAttrInfo(kAttrLargeIcon, &info) == B_OK)); - // has a mini _and_ large icon + if (fNode == NULL) { + // Node is not open. + return false; + } + + if (fNode->GetAttrInfo(kAttrIcon, &info) == B_OK) { + // Node has a vector icon + return true; + } + + if (fNode->GetAttrInfo(kAttrMiniIcon, &info) == B_OK + && fNode->GetAttrInfo(kAttrLargeIcon, &info) == B_OK) { + // Node has a mini _and_ large icon + return true; + } + + // If there isn't either of these, we can't use the icon attribute from the node. + return false; } @@ -750,7 +762,7 @@ Model::ResetIconFrom() if (InitCheck() != B_OK) return; - if (CheckNodeIconHint()) { + if (ShouldUseWellKnownIcon()) { BDirectory* directory = dynamic_cast(fNode); if (WellKnowEntryList::Match(NodeRef()) > (directory_which)-1) { fIconFrom = kTrackerSupplied; diff --git a/src/kits/tracker/Model.h b/src/kits/tracker/Model.h index fe0f48ca4a..838c41f9af 100644 --- a/src/kits/tracker/Model.h +++ b/src/kits/tracker/Model.h @@ -212,7 +212,7 @@ private: status_t OpenNodeCommon(bool writable); void SetupBaseType(); void FinishSettingUpType(); - bool CheckNodeIconHint() const; + bool ShouldUseWellKnownIcon() const; bool CheckAppIconHint() const; void DeletePreferredAppVolumeNameLinkTo(); void CacheLocalizedName();