From bf5e11677b845b723aa92bd2029472e58978497f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 3 Apr 2006 16:44:46 +0000 Subject: [PATCH] * 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 --- src/kits/storage/MimeType.cpp | 21 +++--- src/kits/storage/mime/SupportingApps.cpp | 81 ++++++++++++------------ 2 files changed, 49 insertions(+), 53 deletions(-) diff --git a/src/kits/storage/MimeType.cpp b/src/kits/storage/MimeType.cpp index 3127dc8f18..1f21379ad1 100644 --- a/src/kits/storage/MimeType.cpp +++ b/src/kits/storage/MimeType.cpp @@ -669,27 +669,24 @@ BMimeType::GetLongDescription(char *description) const status_t 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 &reply = *signatures; + BMessage msg(B_REG_MIME_GET_SUPPORTING_APPS); status_t result; - - // Build and send the message, read the reply - if (!err) - msg.what = B_REG_MIME_GET_SUPPORTING_APPS; + + status_t err = InitCheck(); if (!err) err = msg.AddString("type", Type()); if (!err) - err = BRoster::Private().SendTo(&msg, &reply, true); + err = BRoster::Private().SendTo(&msg, signatures, true); 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) - err = reply.FindInt32("result", &result); + err = signatures->FindInt32("result", &result); if (!err) err = result; -// if (!err) -// err = reply.FindMessage("signatures", signatures); + return err; } diff --git a/src/kits/storage/mime/SupportingApps.cpp b/src/kits/storage/mime/SupportingApps.cpp index 174f6348c3..cce6a7f21d 100644 --- a/src/kits/storage/mime/SupportingApps.cpp +++ b/src/kits/storage/mime/SupportingApps.cpp @@ -1,20 +1,24 @@ -//---------------------------------------------------------------------- -// This software is part of the OpenBeOS distribution and is covered -// by the OpenBeOS license. -//--------------------------------------------------------------------- -/*! - \file SupportingApps.cpp - SupportingApps class implementation -*/ +/* + * Copyright 2002-2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Tyler Dauwalder + * Ingo Weinhold, bonefish@users.sf.net + * Axel Dörfler, axeld@pinc-software.de + */ -#include "mime/SupportingApps.h" + +#include +#include + +#include #include #include -#include #include #include -#include +#include #include #include @@ -57,13 +61,13 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps) { status_t err = type && apps ? B_OK : B_BAD_VALUE; // See if we need to do our initial build still - if (!err && !fHaveDoneFullBuild) { + if (!err && !fHaveDoneFullBuild) err = BuildSupportingAppsTable(); - } + if (!err) { // Clear the message, as we're just going to add to it apps->MakeEmpty(); - + BMimeType mime(type); err = mime.InitCheck(); if (!err) { @@ -89,7 +93,7 @@ SupportingApps::GetSupportingApps(const char *type, BMessage *apps) } if (!err) err = apps->AddInt32(kSupportingAppsSubCountField, count); - + // Now add any apps that support the supertype, but not the // subtype (plus their count). 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; if (!fHaveDoneFullBuild) return err; - + std::set oldTypes; std::set &newTypes = fSupportedTypes[app]; std::set &strandedTypes = fStrandedTypes[app]; @@ -164,46 +168,39 @@ SupportingApps::SetSupportedTypes(const char *app, const BMessage *types, bool f // each type. newTypes.clear(); const char *type; - for (int32 i = 0; - types->FindString(kTypesField, i, &type) == B_OK; - i++) { + for (int32 i = 0; types->FindString(kTypesField, i, &type) == B_OK; + i++) { newTypes.insert(type); AddSupportingApp(type, app); } - + // Update the list of stranded types by removing any types that are newly // re-supported and adding any types that are newly un-supported for (std::set::const_iterator i = newTypes.begin(); - i != newTypes.end(); - i++) - { + i != newTypes.end(); i++) { strandedTypes.erase(*i); } for (std::set::const_iterator i = oldTypes.begin(); - i != oldTypes.end(); - i++) - { + i != oldTypes.end(); i++) { if (newTypes.find(*i) == newTypes.end()) strandedTypes.insert(*i); - } - + } + // 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 // stranded types. - if (fullSync) { + if (fullSync) { for (std::set::const_iterator i = strandedTypes.begin(); - i != strandedTypes.end(); - i++) - { + i != strandedTypes.end(); i++) { RemoveSupportingApp((*i).c_str(), app); } strandedTypes.clear(); - } - } + } + } return err; } -// DeleteSupportedTypes + /*! \brief Clears the given application's supported types list and optionally removes the application from each of said types' supporting apps list. \param app The application whose supported types you are clearing @@ -264,14 +261,14 @@ SupportingApps::BuildSupportingAppsTable() fSupportedTypes.clear(); fSupportingApps.clear(); fStrandedTypes.clear(); - + BDirectory dir; status_t err = dir.SetTo(kApplicationDatabaseDir.c_str()); - + // Build the supporting apps table based on the mime database if (!err) { dir.Rewind(); - + // Handle each application type while (true) { entry_ref ref; @@ -296,11 +293,13 @@ SupportingApps::BuildSupportingAppsTable() // 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 - const char *type; + BString type; std::set &supportedTypes = fSupportedTypes[appName]; for (int i = 0; msg.FindString(kTypesField, i, &type) == B_OK; i++) { - supportedTypes.insert(type); - AddSupportingApp(type, appSig); + type.ToLower(); + // MIME types are case insensitive, so we lowercase everything + supportedTypes.insert(type.String()); + AddSupportingApp(type.String(), appSig); } } }