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:
@@ -1281,7 +1281,24 @@ Model::Mimeset(bool force)
|
|||||||
opener.OpenNode();
|
opener.OpenNode();
|
||||||
AttrChanged(NULL);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -208,6 +208,9 @@ public:
|
|||||||
|
|
||||||
bool Mimeset(bool force);
|
bool Mimeset(bool force);
|
||||||
// returns true if mime type changed
|
// 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;
|
bool HasLocalizedName() const;
|
||||||
|
|
||||||
|
|||||||
@@ -617,6 +617,7 @@ AddOneRefSignatures(const entry_ref* ref, void* castToIterator)
|
|||||||
Model model(ref, true, true);
|
Model model(ref, true, true);
|
||||||
if (model.InitCheck() != B_OK)
|
if (model.InitCheck() != B_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
model.SniffMimeIfNeeded();
|
||||||
|
|
||||||
BString mimeType(model.MimeType());
|
BString mimeType(model.MimeType());
|
||||||
|
|
||||||
@@ -1586,6 +1587,7 @@ SearchForSignatureEntryList::Relation(const BMessage* entriesToOpen,
|
|||||||
Model model(&ref, true, true);
|
Model model(&ref, true, true);
|
||||||
if (model.InitCheck())
|
if (model.InitCheck())
|
||||||
continue;
|
continue;
|
||||||
|
model.SniffMimeIfNeeded();
|
||||||
|
|
||||||
int32 result = Relation(&model, applicationModel);
|
int32 result = Relation(&model, applicationModel);
|
||||||
if (result != kNoRelation) {
|
if (result != kNoRelation) {
|
||||||
@@ -1626,6 +1628,7 @@ SearchForSignatureEntryList::RelationDescription(const BMessage* entriesToOpen,
|
|||||||
Model model(&ref, true, true);
|
Model model(&ref, true, true);
|
||||||
if (model.InitCheck())
|
if (model.InitCheck())
|
||||||
continue;
|
continue;
|
||||||
|
model.SniffMimeIfNeeded();
|
||||||
|
|
||||||
BMimeType mimeType;
|
BMimeType mimeType;
|
||||||
int32 result = Relation(&model, applicationModel);
|
int32 result = Relation(&model, applicationModel);
|
||||||
|
|||||||
@@ -1171,6 +1171,7 @@ TTracker::OpenInfoWindows(BMessage* message)
|
|||||||
wind->Activate();
|
wind->Activate();
|
||||||
delete model;
|
delete model;
|
||||||
} else {
|
} else {
|
||||||
|
model->SniffMimeIfNeeded();
|
||||||
wind = new BInfoWindow(model, index, &fWindowList);
|
wind = new BInfoWindow(model, index, &fWindowList);
|
||||||
wind->PostMessage(kRestoreState);
|
wind->PostMessage(kRestoreState);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user