mirror of
https://review.haiku-os.org/haiku
synced 2025-02-01 03:06:08 +01:00
* 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:
parent
9d6b4ad586
commit
bf5e11677b
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 <mime/SupportingApps.h>
|
||||
#include <mime/database_support.h>
|
||||
|
||||
#include <storage_support.h>
|
||||
|
||||
#include <Directory.h>
|
||||
#include <Message.h>
|
||||
#include <mime/database_support.h>
|
||||
#include <MimeType.h>
|
||||
#include <Path.h>
|
||||
#include <storage_support.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <new>
|
||||
#include <stdio.h>
|
||||
@ -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<std::string> oldTypes;
|
||||
std::set<std::string> &newTypes = fSupportedTypes[app];
|
||||
std::set<std::string> &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<std::string>::const_iterator i = newTypes.begin();
|
||||
i != newTypes.end();
|
||||
i++)
|
||||
{
|
||||
i != newTypes.end(); i++) {
|
||||
strandedTypes.erase(*i);
|
||||
}
|
||||
for (std::set<std::string>::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<std::string>::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<std::string> &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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user