Adjusted the resolving algorithm such that when the preferred handler of the

super type is among the handlers with direct support for the sub-type, that this
handler is at the beginning of the list of fall-back handlers.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36507 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2010-04-27 17:51:11 +00:00
parent 47a07cbf03
commit 6e1c9c648a
+29 -8
View File
@@ -2614,6 +2614,7 @@ BRoster::_TranslateType(const char* mimeType, BMimeType* appMeta,
// applications for the sub and the super type respectively. // applications for the sub and the super type respectively.
const char* kSigField = "applications"; const char* kSigField = "applications";
BMessage signatures; BMessage signatures;
bool addedSecondarySignature = false;
if (error == B_OK) { if (error == B_OK) {
if (primarySignature[0] != '\0') if (primarySignature[0] != '\0')
error = signatures.AddString(kSigField, primarySignature); error = signatures.AddString(kSigField, primarySignature);
@@ -2624,8 +2625,10 @@ BRoster::_TranslateType(const char* mimeType, BMimeType* appMeta,
// we fall-back to non-preferred but supporting apps only in the // we fall-back to non-preferred but supporting apps only in the
// case when there is a preferred handler for the sub-type but // case when there is a preferred handler for the sub-type but
// it cannot be resolved (misconfiguration). // it cannot be resolved (misconfiguration).
if (secondarySignature[0] != '\0') if (secondarySignature[0] != '\0') {
error = signatures.AddString(kSigField, secondarySignature); error = signatures.AddString(kSigField, secondarySignature);
addedSecondarySignature = true;
}
} }
} }
@@ -2635,30 +2638,48 @@ BRoster::_TranslateType(const char* mimeType, BMimeType* appMeta,
int32 subCount; int32 subCount;
if (supportingSignatures.FindInt32("be:sub", &subCount) != B_OK) if (supportingSignatures.FindInt32("be:sub", &subCount) != B_OK)
subCount = 0; subCount = 0;
// Add all signatures with direct support for the sub-type // Add all signatures with direct support for the sub-type.
const char* supportingType; const char* supportingType;
if (!addedSecondarySignature) {
// Try to add the secondarySignature in front of all other
// supporting apps, if we find it among those.
for (int32 i = 0; error == B_OK && i < subCount
&& supportingSignatures.FindString(kSigField, i,
&supportingType) == B_OK; i++) {
if (strcmp(primarySignature, supportingType) != 0
&& strcmp(secondarySignature, supportingType) == 0) {
error = signatures.AddString(kSigField, supportingType);
addedSecondarySignature = true;
break;
}
}
}
for (int32 i = 0; error == B_OK && i < subCount for (int32 i = 0; error == B_OK && i < subCount
&& supportingSignatures.FindString(kSigField, i, && supportingSignatures.FindString(kSigField, i,
&supportingType) == B_OK; i++) { &supportingType) == B_OK; i++) {
// don't add the signature if it's the preferred app already. if (strcmp(primarySignature, supportingType) != 0
if (strcmp(primarySignature, supportingType) != 0) && strcmp(secondarySignature, supportingType) != 0) {
error = signatures.AddString(kSigField, supportingType); error = signatures.AddString(kSigField, supportingType);
}
} }
// Add the preferred type of the super type here before adding // Add the preferred type of the super type here before adding
// the other types supporting the super type, but only if we have // the other types supporting the super type, but only if we have
// not already added it in case there was no preferred app for the // not already added it in case there was no preferred app for the
// sub-type configured. // sub-type configured.
if (error == B_OK && primarySignature[0] != '\0' if (error == B_OK && !addedSecondarySignature
&& secondarySignature[0] != '\0') { && secondarySignature[0] != '\0') {
error = signatures.AddString(kSigField, secondarySignature); error = signatures.AddString(kSigField, secondarySignature);
} }
// Add all signatures with support for the super-type // Add all signatures with support for the super-type.
for (int32 i = subCount; error == B_OK for (int32 i = subCount; error == B_OK
&& supportingSignatures.FindString(kSigField, i, && supportingSignatures.FindString(kSigField, i,
&supportingType) == B_OK; i++) { &supportingType) == B_OK; i++) {
// don't add the signature if it's the preferred app already. // Don't add the signature if it's one of the preferred apps
if (strcmp(secondarySignature, supportingType) != 0) // already.
if (strcmp(primarySignature, supportingType) != 0
&& strcmp(secondarySignature, supportingType) != 0) {
error = signatures.AddString(kSigField, supportingType); error = signatures.AddString(kSigField, supportingType);
}
} }
} else { } else {
// Failed to get supporting apps, just add the preferred apps. // Failed to get supporting apps, just add the preferred apps.