* Removed superfluous Delete*() methods.
* Invocations like SetShortDescription("") will now remove the description as
well, not only SetShortDescription(NULL).
* Cleanup.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16697 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -158,18 +158,6 @@ class BMimeType {
|
|||||||
/* Deprecated. Use SetTo() instead. */
|
/* Deprecated. Use SetTo() instead. */
|
||||||
status_t SetType(const char *mimeType);
|
status_t SetType(const char *mimeType);
|
||||||
|
|
||||||
/* Brand new Delete() methods */
|
|
||||||
status_t DeleteAppHint();
|
|
||||||
status_t DeleteAttrInfo();
|
|
||||||
status_t DeleteShortDescription();
|
|
||||||
status_t DeleteLongDescription();
|
|
||||||
status_t DeleteFileExtensions();
|
|
||||||
status_t DeleteIcon(icon_size size);
|
|
||||||
status_t DeleteIconForType(const char *type, icon_size which);
|
|
||||||
status_t DeletePreferredApp(app_verb verb = B_OPEN);
|
|
||||||
status_t DeleteSnifferRule();
|
|
||||||
status_t DeleteSupportedTypes(bool fullSync = true);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMimeType(const char *mimeType, const char *mimePath);
|
BMimeType(const char *mimeType, const char *mimePath);
|
||||||
// if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/"
|
// if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/"
|
||||||
|
|||||||
+79
-143
@@ -1,11 +1,14 @@
|
|||||||
//----------------------------------------------------------------------
|
/*
|
||||||
// This software is part of the OpenBeOS distribution and is covered
|
* Copyright 2002-2006, Haiku Inc.
|
||||||
// by the OpenBeOS license.
|
* Distributed under the terms of the MIT License.
|
||||||
//---------------------------------------------------------------------
|
*
|
||||||
/*!
|
* Authors:
|
||||||
\file MimeType.cpp
|
* Tyler Dauwalder
|
||||||
BMimeType implementation.
|
* Ingo Weinhold, [email protected]
|
||||||
*/
|
* Axel Dörfler, [email protected]
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MimeType.h"
|
#include "MimeType.h"
|
||||||
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
@@ -13,12 +16,14 @@
|
|||||||
#include <sniffer/Rule.h>
|
#include <sniffer/Rule.h>
|
||||||
#include <sniffer/Parser.h>
|
#include <sniffer/Parser.h>
|
||||||
|
|
||||||
#include <ctype.h> // For tolower()
|
|
||||||
#include <new> // For new(nothrow)
|
|
||||||
#include <stdio.h> // For printf()
|
|
||||||
#include <string.h> // For strncpy()
|
|
||||||
#include <RegistrarDefs.h>
|
#include <RegistrarDefs.h>
|
||||||
#include <RosterPrivate.h> // For SendTo()
|
#include <RosterPrivate.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <new>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate;
|
using namespace BPrivate;
|
||||||
|
|
||||||
@@ -26,10 +31,6 @@ using namespace BPrivate;
|
|||||||
bool isValidMimeChar(const char ch);
|
bool isValidMimeChar(const char ch);
|
||||||
status_t toLower(const char *str, char *result);
|
status_t toLower(const char *str, char *result);
|
||||||
|
|
||||||
enum {
|
|
||||||
NOT_IMPLEMENTED = B_ERROR,
|
|
||||||
};
|
|
||||||
|
|
||||||
using namespace BPrivate::Storage::Mime;
|
using namespace BPrivate::Storage::Mime;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -42,7 +43,54 @@ const char *B_FILE_MIME_TYPE = "application/octet-stream";
|
|||||||
// format for all platforms anyway.
|
// format for all platforms anyway.
|
||||||
const char *B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE;
|
const char *B_APP_MIME_TYPE = B_ELF_APP_MIME_TYPE;
|
||||||
|
|
||||||
// constructor
|
|
||||||
|
bool
|
||||||
|
isValidMimeChar(const char ch)
|
||||||
|
{
|
||||||
|
// Handles white space and most CTLs
|
||||||
|
return ch > 32
|
||||||
|
&& ch != '/'
|
||||||
|
&& ch != '<'
|
||||||
|
&& ch != '>'
|
||||||
|
&& ch != '@'
|
||||||
|
&& ch != ','
|
||||||
|
&& ch != ';'
|
||||||
|
&& ch != ':'
|
||||||
|
&& ch != '"'
|
||||||
|
&& ch != '('
|
||||||
|
&& ch != ')'
|
||||||
|
&& ch != '['
|
||||||
|
&& ch != ']'
|
||||||
|
&& ch != '?'
|
||||||
|
&& ch != '='
|
||||||
|
&& ch != '\\'
|
||||||
|
&& ch != 127; // DEL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a lowercase version of str in result. Result must
|
||||||
|
be preallocated and is assumed to be of adequate length.
|
||||||
|
*/
|
||||||
|
status_t
|
||||||
|
toLower(const char *str, char *result)
|
||||||
|
{
|
||||||
|
if (!str || !result)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
int len = strlen(str);
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
result[i] = tolower(str[i]);
|
||||||
|
}
|
||||||
|
result[i] = 0;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
/*! \brief Creates an uninitialized BMimeType object.
|
/*! \brief Creates an uninitialized BMimeType object.
|
||||||
*/
|
*/
|
||||||
BMimeType::BMimeType()
|
BMimeType::BMimeType()
|
||||||
@@ -52,7 +100,7 @@ BMimeType::BMimeType()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor
|
|
||||||
/*! \brief Creates a BMimeType object and initializes it to the supplied
|
/*! \brief Creates a BMimeType object and initializes it to the supplied
|
||||||
MIME type.
|
MIME type.
|
||||||
The supplied string must specify a valid MIME type or supertype.
|
The supplied string must specify a valid MIME type or supertype.
|
||||||
@@ -67,7 +115,7 @@ BMimeType::BMimeType(const char *mimeType)
|
|||||||
SetTo(mimeType);
|
SetTo(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
|
||||||
/*! \brief Frees all resources associated with this object.
|
/*! \brief Frees all resources associated with this object.
|
||||||
*/
|
*/
|
||||||
BMimeType::~BMimeType()
|
BMimeType::~BMimeType()
|
||||||
@@ -693,7 +741,8 @@ BMimeType::SetPreferredApp(const char *signature, app_verb verb)
|
|||||||
{
|
{
|
||||||
status_t err = InitCheck();
|
status_t err = InitCheck();
|
||||||
|
|
||||||
BMessage msg(signature ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
BMessage msg(signature && signature[0]
|
||||||
|
? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
@@ -868,7 +917,8 @@ BMimeType::SetShortDescription(const char *description)
|
|||||||
{
|
{
|
||||||
status_t err = InitCheck();
|
status_t err = InitCheck();
|
||||||
|
|
||||||
BMessage msg(description ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
BMessage msg(description && description [0]
|
||||||
|
? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
@@ -910,7 +960,8 @@ BMimeType::SetLongDescription(const char *description)
|
|||||||
{
|
{
|
||||||
status_t err = InitCheck();
|
status_t err = InitCheck();
|
||||||
|
|
||||||
BMessage msg(description ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
BMessage msg(description && description[0]
|
||||||
|
? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
@@ -1085,26 +1136,6 @@ BMimeType::IsValid(const char *string)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidMimeChar(const char ch)
|
|
||||||
{
|
|
||||||
return ch > 32 // Handles white space and most CTLs
|
|
||||||
&& ch != '/'
|
|
||||||
&& ch != '<'
|
|
||||||
&& ch != '>'
|
|
||||||
&& ch != '@'
|
|
||||||
&& ch != ','
|
|
||||||
&& ch != ';'
|
|
||||||
&& ch != ':'
|
|
||||||
&& ch != '"'
|
|
||||||
&& ch != '('
|
|
||||||
&& ch != ')'
|
|
||||||
&& ch != '['
|
|
||||||
&& ch != ']'
|
|
||||||
&& ch != '?'
|
|
||||||
&& ch != '='
|
|
||||||
&& ch != '\\'
|
|
||||||
&& ch != 127; // DEL
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAppHint
|
// GetAppHint
|
||||||
//! Fetches an \c entry_ref that serves as a hint as to where the MIME type's preferred application might live
|
//! Fetches an \c entry_ref that serves as a hint as to where the MIME type's preferred application might live
|
||||||
@@ -1334,16 +1365,17 @@ status_t
|
|||||||
BMimeType::SetSnifferRule(const char *rule)
|
BMimeType::SetSnifferRule(const char *rule)
|
||||||
{
|
{
|
||||||
status_t err = InitCheck();
|
status_t err = InitCheck();
|
||||||
if (!err && rule)
|
if (!err && rule && rule[0])
|
||||||
err = CheckSnifferRule(rule, NULL);
|
err = CheckSnifferRule(rule, NULL);
|
||||||
|
if (err != B_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
BMessage msg(rule ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
BMessage msg(rule && rule[0] ? B_REG_MIME_SET_PARAM : B_REG_MIME_DELETE_PARAM);
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
status_t result;
|
status_t result;
|
||||||
|
|
||||||
// Build and send the message, read the reply
|
// Build and send the message, read the reply
|
||||||
if (!err)
|
err = msg.AddString("type", Type());
|
||||||
err = msg.AddString("type", Type());
|
|
||||||
if (!err)
|
if (!err)
|
||||||
err = msg.AddInt32("which", B_REG_MIME_SNIFFER_RULE);
|
err = msg.AddInt32("which", B_REG_MIME_SNIFFER_RULE);
|
||||||
if (!err && rule)
|
if (!err && rule)
|
||||||
@@ -1641,85 +1673,6 @@ BMimeType::SetType(const char *mimeType)
|
|||||||
return SetTo(mimeType);
|
return SetTo(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteAppHint
|
|
||||||
//! Deletes the mime type's application hint
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteAppHint()
|
|
||||||
{
|
|
||||||
return SetAppHint(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteAttrInfo
|
|
||||||
//! Deletes the mime type's attribute info
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteAttrInfo()
|
|
||||||
{
|
|
||||||
return SetAttrInfo(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteShortDescription
|
|
||||||
//! Deletes the mime type's short description
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteShortDescription()
|
|
||||||
{
|
|
||||||
return SetShortDescription(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteLongDescription
|
|
||||||
//! Deletes the mime type's long description
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteLongDescription()
|
|
||||||
{
|
|
||||||
return SetLongDescription(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteFileExtensions
|
|
||||||
//! Deletes the mime type's associated file extensions
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteFileExtensions()
|
|
||||||
{
|
|
||||||
return SetFileExtensions(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteIcon
|
|
||||||
//! Deletes the mime type's icon of given size
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteIcon(icon_size which)
|
|
||||||
{
|
|
||||||
return SetIcon(NULL, which);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteIconForType
|
|
||||||
//! Deletes the mime type's custom icon of given size for the given file type
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteIconForType(const char *type, icon_size which)
|
|
||||||
{
|
|
||||||
return SetIconForType(type, NULL, which);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeletePreferredApp
|
|
||||||
//! Deletes the mime type's preferred app for the given verb
|
|
||||||
status_t
|
|
||||||
BMimeType::DeletePreferredApp(app_verb verb)
|
|
||||||
{
|
|
||||||
return SetPreferredApp(NULL, verb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteSnifferRule
|
|
||||||
//! Deletes the mime type's sniffer rule
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteSnifferRule()
|
|
||||||
{
|
|
||||||
return SetSnifferRule(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteSupportedTypes
|
|
||||||
//! Deletes the mime type's supported types
|
|
||||||
status_t
|
|
||||||
BMimeType::DeleteSupportedTypes(bool fullSync)
|
|
||||||
{
|
|
||||||
return SetSupportedTypes(NULL, fullSync);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BMimeType::_ReservedMimeType1() {}
|
void BMimeType::_ReservedMimeType1() {}
|
||||||
void BMimeType::_ReservedMimeType2() {}
|
void BMimeType::_ReservedMimeType2() {}
|
||||||
@@ -1848,20 +1801,3 @@ BMimeType::GetAssociatedTypes(const char *extension, BMessage *types)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns a lowercase version of str in result. Result must
|
|
||||||
// be preallocated and is assumed to be of adequate length.
|
|
||||||
status_t
|
|
||||||
toLower(const char *str, char *result) {
|
|
||||||
if (!str || !result)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
int len = strlen(str);
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
result[i] = tolower(str[i]);
|
|
||||||
result[i] = 0;
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user