* Improved BMimeType::GetSupportingApps(): no longer uses the provided message to

send the request, and it now checks if the object is valid.
* Fixed building supporting apps table: now all types are converted to lower case,
  so that it works reliable now. This fixes bug #278.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16987 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-04-03 16:44:46 +00:00
parent 9d6b4ad586
commit bf5e11677b
2 changed files with 49 additions and 53 deletions
+9 -12
View File
@@ -669,27 +669,24 @@ BMimeType::GetLongDescription(char *description) const
status_t status_t
BMimeType::GetSupportingApps(BMessage *signatures) const BMimeType::GetSupportingApps(BMessage *signatures) const
{ {
status_t err = signatures ? B_OK : B_BAD_VALUE; if (signatures == NULL)
return B_BAD_VALUE;
BMessage &msg = *signatures; BMessage msg(B_REG_MIME_GET_SUPPORTING_APPS);
BMessage &reply = *signatures;
status_t result; status_t result;
// Build and send the message, read the reply status_t err = InitCheck();
if (!err)
msg.what = B_REG_MIME_GET_SUPPORTING_APPS;
if (!err) if (!err)
err = msg.AddString("type", Type()); err = msg.AddString("type", Type());
if (!err) if (!err)
err = BRoster::Private().SendTo(&msg, &reply, true); err = BRoster::Private().SendTo(&msg, signatures, true);
if (!err) if (!err)
err = reply.what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY; err = signatures->what == B_REG_RESULT ? (status_t)B_OK : (status_t)B_BAD_REPLY;
if (!err) if (!err)
err = reply.FindInt32("result", &result); err = signatures->FindInt32("result", &result);
if (!err) if (!err)
err = result; err = result;
// if (!err)
// err = reply.FindMessage("signatures", signatures);
return err; return err;
} }
+40 -41
View File
@@ -1,20 +1,24 @@
//---------------------------------------------------------------------- /*
// This software is part of the OpenBeOS distribution and is covered * Copyright 2002-2006, Haiku.
// by the OpenBeOS license. * Distributed under the terms of the MIT License.
//--------------------------------------------------------------------- *
/*! * Authors:
\file SupportingApps.cpp * Tyler Dauwalder
SupportingApps class implementation * Ingo Weinhold, [email protected]
*/ * Axel Dörfler, [email protected]
*/
#include "mime/SupportingApps.h"
#include <mime/SupportingApps.h>
#include <mime/database_support.h>
#include <storage_support.h>
#include <Directory.h> #include <Directory.h>
#include <Message.h> #include <Message.h>
#include <mime/database_support.h>
#include <MimeType.h> #include <MimeType.h>
#include <Path.h> #include <Path.h>
#include <storage_support.h> #include <String.h>
#include <new> #include <new>
#include <stdio.h> #include <stdio.h>
@@ -57,13 +61,13 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps)
{ {
status_t err = type && apps ? B_OK : B_BAD_VALUE; status_t err = type && apps ? B_OK : B_BAD_VALUE;
// See if we need to do our initial build still // See if we need to do our initial build still
if (!err && !fHaveDoneFullBuild) { if (!err && !fHaveDoneFullBuild)
err = BuildSupportingAppsTable(); err = BuildSupportingAppsTable();
}
if (!err) { if (!err) {
// Clear the message, as we're just going to add to it // Clear the message, as we're just going to add to it
apps->MakeEmpty(); apps->MakeEmpty();
BMimeType mime(type); BMimeType mime(type);
err = mime.InitCheck(); err = mime.InitCheck();
if (!err) { if (!err) {
@@ -89,7 +93,7 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps)
} }
if (!err) if (!err)
err = apps->AddInt32(kSupportingAppsSubCountField, count); err = apps->AddInt32(kSupportingAppsSubCountField, count);
// Now add any apps that support the supertype, but not the // Now add any apps that support the supertype, but not the
// subtype (plus their count). // subtype (plus their count).
BMimeType superMime; BMimeType superMime;
@@ -150,7 +154,7 @@ SupportingApps::SetSupportedTypes(const char *app, const BMessage *types, bool f
status_t err = app && types ? B_OK : B_BAD_VALUE; status_t err = app && types ? B_OK : B_BAD_VALUE;
if (!fHaveDoneFullBuild) if (!fHaveDoneFullBuild)
return err; return err;
std::set<std::string> oldTypes; std::set<std::string> oldTypes;
std::set<std::string> &newTypes = fSupportedTypes[app]; std::set<std::string> &newTypes = fSupportedTypes[app];
std::set<std::string> &strandedTypes = fStrandedTypes[app]; std::set<std::string> &strandedTypes = fStrandedTypes[app];
@@ -164,46 +168,39 @@ SupportingApps::SetSupportedTypes(const char *app, const BMessage *types, bool f
// each type. // each type.
newTypes.clear(); newTypes.clear();
const char *type; const char *type;
for (int32 i = 0; for (int32 i = 0; types->FindString(kTypesField, i, &type) == B_OK;
types->FindString(kTypesField, i, &type) == B_OK; i++) {
i++) {
newTypes.insert(type); newTypes.insert(type);
AddSupportingApp(type, app); AddSupportingApp(type, app);
} }
// Update the list of stranded types by removing any types that are newly // Update the list of stranded types by removing any types that are newly
// re-supported and adding any types that are newly un-supported // re-supported and adding any types that are newly un-supported
for (std::set<std::string>::const_iterator i = newTypes.begin(); for (std::set<std::string>::const_iterator i = newTypes.begin();
i != newTypes.end(); i != newTypes.end(); i++) {
i++)
{
strandedTypes.erase(*i); strandedTypes.erase(*i);
} }
for (std::set<std::string>::const_iterator i = oldTypes.begin(); for (std::set<std::string>::const_iterator i = oldTypes.begin();
i != oldTypes.end(); i != oldTypes.end(); i++) {
i++)
{
if (newTypes.find(*i) == newTypes.end()) if (newTypes.find(*i) == newTypes.end())
strandedTypes.insert(*i); strandedTypes.insert(*i);
} }
// Now, if we're doing a full sync, remove the app as a supporting // Now, if we're doing a full sync, remove the app as a supporting
// app for any of its stranded types and then clear said list of // app for any of its stranded types and then clear said list of
// stranded types. // stranded types.
if (fullSync) { if (fullSync) {
for (std::set<std::string>::const_iterator i = strandedTypes.begin(); for (std::set<std::string>::const_iterator i = strandedTypes.begin();
i != strandedTypes.end(); i != strandedTypes.end(); i++) {
i++)
{
RemoveSupportingApp((*i).c_str(), app); RemoveSupportingApp((*i).c_str(), app);
} }
strandedTypes.clear(); strandedTypes.clear();
} }
} }
return err; return err;
} }
// DeleteSupportedTypes
/*! \brief Clears the given application's supported types list and optionally /*! \brief Clears the given application's supported types list and optionally
removes the application from each of said types' supporting apps list. removes the application from each of said types' supporting apps list.
\param app The application whose supported types you are clearing \param app The application whose supported types you are clearing
@@ -264,14 +261,14 @@ SupportingApps::BuildSupportingAppsTable()
fSupportedTypes.clear(); fSupportedTypes.clear();
fSupportingApps.clear(); fSupportingApps.clear();
fStrandedTypes.clear(); fStrandedTypes.clear();
BDirectory dir; BDirectory dir;
status_t err = dir.SetTo(kApplicationDatabaseDir.c_str()); status_t err = dir.SetTo(kApplicationDatabaseDir.c_str());
// Build the supporting apps table based on the mime database // Build the supporting apps table based on the mime database
if (!err) { if (!err) {
dir.Rewind(); dir.Rewind();
// Handle each application type // Handle each application type
while (true) { while (true) {
entry_ref ref; entry_ref ref;
@@ -296,11 +293,13 @@ SupportingApps::BuildSupportingAppsTable()
// Iterate through the supported types, adding them to the list of // Iterate through the supported types, adding them to the list of
// supported types for the application and adding the application's // supported types for the application and adding the application's
// signature to the list of supporting apps for each type // signature to the list of supporting apps for each type
const char *type; BString type;
std::set<std::string> &supportedTypes = fSupportedTypes[appName]; std::set<std::string> &supportedTypes = fSupportedTypes[appName];
for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) { for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) {
supportedTypes.insert(type); type.ToLower();
AddSupportingApp(type, appSig); // MIME types are case insensitive, so we lowercase everything
supportedTypes.insert(type.String());
AddSupportingApp(type.String(), appSig);
} }
} }
} }