+ Added file-extension based mime type guessing

+ Added sniffer rule based mime type guessing
+ Added get_device_icon()
+ Added complete (synchronous, asynchronous; recursive,
  non-recursive; forcing, non-forcing; you name it we got it :-)
  update_mime_info() implementation.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1152 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-09-24 05:36:03 +00:00
parent 743e936ee7
commit 1bd963b6c2
12 changed files with 891 additions and 101 deletions
+6 -3
View File
@@ -145,10 +145,10 @@ public:
/* calls to ask the sniffer to identify the MIME type of a file or data in
memory */
static status_t GuessMimeType(const entry_ref *file, BMimeType *result);
static status_t GuessMimeType(const entry_ref *file, BMimeType *type);
static status_t GuessMimeType(const void *buffer, int32 length,
BMimeType *result);
static status_t GuessMimeType(const char *filename, BMimeType *result);
BMimeType *type);
static status_t GuessMimeType(const char *filename, BMimeType *type);
static status_t StartWatching(BMessenger target);
static status_t StopWatching(BMessenger target);
@@ -201,6 +201,9 @@ private:
// status_t CloseFile() const;
status_t GetSupportedTypes(BMessage *types);
status_t SetSupportedTypes(const BMessage *types, bool fullSync = true);
static status_t GetAssociatedTypes(const char *extension, BMessage *types);
// void MimeChanged(int32 w, const char *type = NULL,
// bool large = true) const;
+28 -23
View File
@@ -39,32 +39,37 @@ extern const char *kRAppLooperPortName;
// message constants
enum {
// replies
B_REG_SUCCESS = 'rgsu',
B_REG_ERROR = 'rger',
B_REG_RESULT = 'rgrz',
B_REG_SUCCESS = 'rgsu',
B_REG_ERROR = 'rger',
B_REG_RESULT = 'rgrz',
// general requests
B_REG_GET_MIME_MESSENGER = 'rgmm',
B_REG_GET_CLIPBOARD_MESSENGER = 'rgcm',
B_REG_GET_MIME_MESSENGER = 'rgmm',
B_REG_GET_CLIPBOARD_MESSENGER = 'rgcm',
// roster requests
B_REG_ADD_APP = 'rgaa',
B_REG_COMPLETE_REGISTRATION = 'rgcr',
B_REG_IS_APP_PRE_REGISTERED = 'rgip',
B_REG_REMOVE_PRE_REGISTERED_APP = 'rgrp',
B_REG_REMOVE_APP = 'rgra',
B_REG_SET_THREAD_AND_TEAM = 'rgtt',
B_REG_GET_APP_INFO = 'rgai',
B_REG_GET_APP_LIST = 'rgal',
B_REG_ACTIVATE_APP = 'rgac',
B_REG_ADD_APP = 'rgaa',
B_REG_COMPLETE_REGISTRATION = 'rgcr',
B_REG_IS_APP_PRE_REGISTERED = 'rgip',
B_REG_REMOVE_PRE_REGISTERED_APP = 'rgrp',
B_REG_REMOVE_APP = 'rgra',
B_REG_SET_THREAD_AND_TEAM = 'rgtt',
B_REG_GET_APP_INFO = 'rgai',
B_REG_GET_APP_LIST = 'rgal',
B_REG_ACTIVATE_APP = 'rgac',
// MIME requests
B_REG_MIME_SET_PARAM = 'rgsp',
B_REG_MIME_DELETE_PARAM = 'rgdp',
B_REG_MIME_START_WATCHING = 'rgwb',
B_REG_MIME_STOP_WATCHING = 'rgwe',
B_REG_MIME_INSTALL = 'rgin',
B_REG_MIME_DELETE = 'rgdl',
B_REG_MIME_GET_INSTALLED_TYPES = 'rgit',
B_REG_MIME_GET_INSTALLED_SUPERTYPES = 'rgis',
B_REG_MIME_GET_SUPPORTING_APPS = 'rgsa',
B_REG_MIME_SET_PARAM = 'rgsp',
B_REG_MIME_DELETE_PARAM = 'rgdp',
B_REG_MIME_START_WATCHING = 'rgwb',
B_REG_MIME_STOP_WATCHING = 'rgwe',
B_REG_MIME_INSTALL = 'rgin',
B_REG_MIME_DELETE = 'rgdl',
B_REG_MIME_GET_INSTALLED_TYPES = 'rgit',
B_REG_MIME_GET_INSTALLED_SUPERTYPES = 'rgis',
B_REG_MIME_GET_SUPPORTING_APPS = 'rgsa',
B_REG_MIME_GET_ASSOCIATED_TYPES = 'rgat',
B_REG_MIME_SNIFF = 'rgsn',
B_REG_MIME_UPDATE_MIME_INFO_ASYNC = 'rgup',
B_REG_MIME_CREATE_APP_META_MIME_ASYNC = 'rgca',
B_REG_MIME_ASYNC_THREAD_FINISHED = 'rgtf',
};
// B_REG_MIME_SET_PARAM "which" constants
+23 -8
View File
@@ -10,9 +10,12 @@
#ifndef _MIME_DATABASE_H
#define _MIME_DATABASE_H
#include <mime/InstalledTypes.h>
#include <mime/SupportingApps.h>
#include <Mime.h>
#include <mime/AssociatedTypes.h>
#include <mime/InstalledTypes.h>
#include <mime/SnifferRules.h>
#include <mime/SupportingApps.h>
#include <mime/database_access.h>
#include <Messenger.h>
#include <StorageDefs.h>
@@ -23,6 +26,9 @@
class BNode;
class BBitmap;
class BMessage;
class BString;
struct entry_ref;
namespace BPrivate {
namespace Storage {
@@ -58,13 +64,12 @@ public:
status_t GetInstalledTypes(const char *super_type,
BMessage *subtypes);
status_t GetSupportingApps(const char *type, BMessage *signatures);
status_t GetAssociatedTypes(const char *extension, BMessage *types);
// Sniffer
// static status_t CheckSnifferRule(const char *rule, BString *parseError);
// static status_t GuessMimeType(const entry_ref *file, BMimeType *result);
// static status_t GuessMimeType(const void *buffer, int32 length,
// BMimeType *result);
// static status_t GuessMimeType(const char *filename, BMimeType *result);
status_t GuessMimeType(const entry_ref *file, BString *result);
status_t GuessMimeType(const void *buffer, int32 length, BString *result);
status_t GuessMimeType(const char *filename, BString *result);
// Monitor
status_t StartWatching(BMessenger target);
@@ -81,11 +86,15 @@ public:
status_t DeletePreferredApp(const char *type, app_verb verb = B_OPEN);
status_t DeleteSnifferRule(const char *type);
status_t DeleteSupportedTypes(const char *type, bool fullSync);
// Asynchronous C function calls
status_t UpdateMimeInfoAsync(const entry_ref *ref, bool recursive, bool force);
status_t CleanupAfterAsyncThread(thread_id id);
private:
// Functions to send monitor notifications
status_t SendInstallNotification(const char *type);
status_t SendDeleteNotification(const char *type);
status_t SendMonitorUpdate(int32 which, const char *type, const char *extraType,
bool largeIcon, int32 action);
status_t SendMonitorUpdate(int32 which, const char *type, const char *extraType,
@@ -96,10 +105,16 @@ private:
int32 action);
status_t SendMonitorUpdate(BMessage &msg);
// Entry point functions for asynchronous update threads
static int32 UpdateMimeInfoAsyncEntry(void *data);
status_t fCStatus;
std::set<BMessenger> fMonitorMessengers;
AssociatedTypes fAssociatedTypes;
InstalledTypes fInstalledTypes;
SnifferRules fSnifferRules;
SupportingApps fSupportingApps;
std::list<async_thread_data*> fAsyncThreads;
};
} // namespace Mime
+17 -1
View File
@@ -4,7 +4,7 @@
//---------------------------------------------------------------------
/*!
\file database_access.h
Mime database atomic read function declarations
Mime database atomic read functions and miscellany declarations
*/
#ifndef _MIME_DATABASE_ACCESS_H
@@ -39,6 +39,22 @@ bool is_installed(const char *type);
// to be shipped off to SetIcon*() and written to the database
status_t get_icon_data(const BBitmap *icon, icon_size size, void **data, int32 *dataSize);
// Common struct used to manage ansynchronous update threads
struct async_thread_data {
public:
async_thread_data(thread_id id = -1);
bool should_exit() const;
void post_exit_notification();
thread_id id;
private:
bool _should_exit;
};
// Called by directly (synchronous calls) and indirectly (asynchronous calls)
// by update_mime_info()
int update_mime_info(entry_ref *ref, bool recursive, bool force, async_thread_data *data = NULL);
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
@@ -59,11 +59,20 @@ extern const int32 kSupportedTypesType;
// Message fields
extern const char *kApplicationsField;
extern const char *kExtensionsField;
extern const char *kSupertypesField;
extern const char *kSupportingAppsSubCountField;
extern const char *kSupportingAppsSuperCountField;
extern const char *kTypesField;
// Mime types
extern const char *kGenericFileType;
extern const char *kDirectoryType;
extern const char *kSymlinkType;
// Error codes (to be used only by BPrivate::Storage::Mime members)
extern const status_t kMimeGuessFailureError;
std::string type_to_filename(const char *type);
status_t open_type(const char *type, BNode *result);
@@ -72,6 +81,7 @@ status_t open_or_create_type(const char *type, BNode *result, bool *didCreate);
ssize_t read_mime_attr(const char *type, const char *attr, void *data,
size_t len, type_code datatype);
status_t read_mime_attr_message(const char *type, const char *attr, BMessage *msg);
status_t read_mime_attr_string(const char *type, const char *attr, BString *str);
status_t write_mime_attr(const char *type, const char *attr, const void *data,
size_t len, type_code datatype, bool *didCreate);
status_t write_mime_attr_message(const char *type, const char *attr,