Tracker: expand use of mime sniffer

* Add Model::SniffMimeIfNeeded as a faster alternative to
  Model::Mimeset, useful for ensuring that Model::fMimeType is
  initialized regardless of whether the filesystem supports MIME.
* Use SniffMimeIfNeeded when the user interacts with a file.
* Change the return value of Model::Mimeset to match the comment in
  Model.h, although currently no client functions pay attention to the
  return value.
* Fixes #19284.

The SniffMimeIfNeeded calls provide the following behavior:
* AddOneRefSignatures - Populate Open With
* SearchForSignatureEntryList::Relation - Populate Open With
* SearchForSignatureEntryList::RelationDescription - Populate Open
  With descriptions (e.g. "Preferred for Text file").
* TTracker::OpenInfoWindows - Set up Get Info window

Change-Id: Icd0aa98781e191d3f804235b0ab8acfdbe47582d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9683
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Jim906
2026-01-02 16:32:15 +00:00
committed by Adrien Destugues
parent 0681754858
commit be9bccd08f
4 changed files with 25 additions and 1 deletions
+18 -1
View File
@@ -1281,7 +1281,24 @@ Model::Mimeset(bool force)
opener.OpenNode();
AttrChanged(NULL);
return !oldType.ICompare(MimeType());
return oldType.ICompare(MimeType()) != 0;
}
void
Model::SniffMimeIfNeeded()
{
if (fMimeType != B_FILE_MIMETYPE)
return;
BVolume volume(fStatBuf.st_dev);
if (volume.InitCheck() == B_OK && !volume.KnowsMime()) {
BMimeType mimeType;
if (BMimeType::GuessMimeType(&fEntryRef, &mimeType) == B_OK)
fMimeType = mimeType.Type();
}
return;
}
+3
View File
@@ -208,6 +208,9 @@ public:
bool Mimeset(bool force);
// returns true if mime type changed
void SniffMimeIfNeeded();
// if the filesystem does not support MIME, sets fMimeType using the MIME sniffer;
// makes no attempt to write the file's MIME attribute
bool HasLocalizedName() const;
+3
View File
@@ -617,6 +617,7 @@ AddOneRefSignatures(const entry_ref* ref, void* castToIterator)
Model model(ref, true, true);
if (model.InitCheck() != B_OK)
return NULL;
model.SniffMimeIfNeeded();
BString mimeType(model.MimeType());
@@ -1586,6 +1587,7 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen,
Model model(&ref, true, true);
if (model.InitCheck())
continue;
model.SniffMimeIfNeeded();
int32 result = Relation(&model, applicationModel);
if (result != kNoRelation) {
@@ -1626,6 +1628,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
Model model(&ref, true, true);
if (model.InitCheck())
continue;
model.SniffMimeIfNeeded();
BMimeType mimeType;
int32 result = Relation(&model, applicationModel);
+1
View File
@@ -1171,6 +1171,7 @@ TTracker::OpenInfoWindows(BMessage* message)
wind->Activate();
delete model;
} else {
model->SniffMimeIfNeeded();
wind = new BInfoWindow(model, index, &fWindowList);
wind->PostMessage(kRestoreState);
}