* create_app_meta_mime() now preserves the case when installing the

MIME type.
* We now write the META:TYPE attribute that contains the type with
  preserved case (as in BeOS). We even currently check this whenever
  a type is opened, but that can be removed later, again.
* BMimeType::GetSupportingApps() was broken for applications that
  only support the super type.
* Also BMimeType::GetSupportingApps() preserves the case of the
  signatures.
* Why on earth would we want to preserve the case of case insensitive
  MIME types? Simple, this let's you query for those apps using case
  sensitive queries, as Tracker uses for its "open with" functionality.
  Strangely enough, that one still doesn't work, even though the query
  predicate is now correct.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17661 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-05-30 21:20:32 +00:00
parent 09d102ccb3
commit 373d946f22
3 changed files with 64 additions and 46 deletions
@@ -67,9 +67,6 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
if (status < B_OK)
return B_BAD_TYPE;
signature.ToLower();
// Signatures and MIME types are case insensitive
// Init our various objects
BMimeType mime;
@@ -80,6 +77,9 @@ CreateAppMetaMimeThread::DoMimeUpdate(const entry_ref* ref, bool* _entryIsDir)
if (!mime.IsInstalled())
mime.Install();
signature.ToLower();
// Signatures and MIME types are case insensitive
char metaMimePath[B_PATH_NAME_LENGTH];
sprintf(metaMimePath, "%s/%s", kDatabaseDir.c_str(), signature.String());
+37 -37
View File
@@ -101,7 +101,7 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps)
if (!err)
err = superMime.InitCheck();
if (!err) {
std::set<std::string> &superApps = fSupportingApps[type];
std::set<std::string> &superApps = fSupportingApps[superMime.Type()];
count = 0;
for (i = superApps.begin(); i != superApps.end() && !err; i++) {
if (subApps.find(*i) == subApps.end()) {
@@ -263,54 +263,54 @@ SupportingApps::BuildSupportingAppsTable()
fStrandedTypes.clear();
BDirectory dir;
status_t err = dir.SetTo(kApplicationDatabaseDir.c_str());
status_t status = dir.SetTo(kApplicationDatabaseDir.c_str());
// Build the supporting apps table based on the mime database
if (!err) {
if (status == B_OK) {
dir.Rewind();
// Handle each application type
while (true) {
entry_ref ref;
err = dir.GetNextRef(&ref);
if (err) {
status = dir.GetNextRef(&ref);
if (status < B_OK) {
// If we've come to the end of list, it's not an error
if (err == B_ENTRY_NOT_FOUND)
err = B_OK;
if (status == B_ENTRY_NOT_FOUND)
status = B_OK;
break;
} else {
BPath path;
BMessage msg;
char appSig[B_PATH_NAME_LENGTH];
err = path.SetTo(&ref);
if (!err) {
// Construct a mime type string
const char *appName = path.Leaf();
sprintf(appSig, "application/%s", appName);
// Read in the list of supported types
if (read_mime_attr_message(appSig, kSupportedTypesAttr, &msg) == B_OK) {
// Iterate through the supported types, adding them to the list of
// supported types for the application and adding the application's
// signature to the list of supporting apps for each type
BString type;
std::set<std::string> &supportedTypes = fSupportedTypes[appName];
for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) {
type.ToLower();
// MIME types are case insensitive, so we lowercase everything
supportedTypes.insert(type.String());
AddSupportingApp(type.String(), appSig);
}
}
}
}
}
// read application signature from file
BString appSignature;
BNode node(&ref);
if (node.InitCheck() == B_OK && node.ReadAttrString(kTypeAttr,
&appSignature) >= B_OK) {
// Read in the list of supported types
BMessage msg;
if (read_mime_attr_message(appSignature.String(), kSupportedTypesAttr,
&msg) == B_OK) {
// Iterate through the supported types, adding them to the list of
// supported types for the application and adding the application's
// signature to the list of supporting apps for each type
BString type;
std::set<std::string> &supportedTypes = fSupportedTypes[appSignature.String()];
for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) {
type.ToLower();
// MIME types are case insensitive, so we lowercase everything
supportedTypes.insert(type.String());
AddSupportingApp(type.String(), appSignature.String());
}
}
}
}
}
if (err)
DBG(OUT("Mime::SupportingApps::BuildSupportingAppsTable() failed, error code == 0x%lx\n", err));
else
if (status == B_OK)
fHaveDoneFullBuild = true;
return err;
else
DBG(OUT("SupportingApps::BuildSupportingAppsTable() failed: %s\n", strerror(status)));
return status;
}
} // namespace Mime
+24 -6
View File
@@ -136,10 +136,23 @@ type_to_filename(const char *type)
status_t
open_type(const char *type, BNode *result)
{
status_t err = (type && result ? B_OK : B_BAD_VALUE);
if (!err)
err = result->SetTo(type_to_filename(type).c_str());
return err;
if (type == NULL || result == NULL)
return B_BAD_VALUE;
status_t status = result->SetTo(type_to_filename(type).c_str());
// TODO: this can be removed again later - we just didn't write this
// attribute is before at all...
#if 1
if (status == B_OK) {
// check if the MIME:TYPE attribute exist, and create it if not
attr_info info;
if (result->GetAttrInfo(kTypeAttr, &info) != B_OK)
result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1);
}
#endif
return status;
}
// open_or_create_type
@@ -184,9 +197,14 @@ open_or_create_type(const char *type, BNode *result, bool *didCreate)
err = parent.CreateFile(sub.c_str(), NULL);
}
// Now try opening again
err = result->SetTo(filename.c_str());
if (!err && didCreate)
if (err == B_OK)
err = result->SetTo(filename.c_str());
if (err == B_OK && didCreate)
*didCreate = true;
if (err == B_OK) {
// write META:TYPE attribute
result->WriteAttr(kTypeAttr, B_STRING_TYPE, 0, type, strlen(type) + 1);
}
}
return err;
}