+ 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
+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,