After implementing the BMimeType::GetInstalled[Super]Types()

functionality, it became apparent that some restructuring was
needed if I wanted to keep things clean and managble.
storage/MimeDatabase.{h,cpp} have been broken into:

storage/mime/database_support.{h,cpp}
+ MIME database constants
+ high-level database access functions like open_type(),
  read_mime_attr(), etc.

storage/mime/database_access.{h,cpp}
+ atomic read functions
+ is_installed()
+ get_icon_data()

storage/mime/Database.{h,cpp}
+ Mime::Database class, which is responsible for all write,
  non-atomic read, and mime monitor functionality.

storage/mime/InstalledTypes.{h,cpp}
+ Helper class for Mime::Database::GetInstalled[Super]Types()

storage/mime/Supertype.{h,cpp}
+ Helper class for Mime::InstalledTypes

I haven't merged my intial, somewhat cludgy GetInstalled[Super]Types
implementation into the new setup yet. That comes next, and it ought
to be a more graceful implementation now.

I also implemented BMimeType::Get/SetSupportingTypes(), though
they haven't been tested yet (sorry).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@862 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-08-24 05:04:02 +00:00
parent 1c4b41005c
commit e20a514ae9
15 changed files with 2476 additions and 110 deletions
+100
View File
@@ -0,0 +1,100 @@
// mime/Database.h
#ifndef _MIME_DATABASE_H
#define _MIME_DATABASE_H
#include <mime/InstalledTypes.h>
#include <Mime.h>
#include <Messenger.h>
#include <StorageDefs.h>
#include <string>
#include <map>
#include <set>
class BNode;
class BBitmap;
class BMessage;
namespace BPrivate {
namespace Storage {
namespace Mime {
class Database {
public:
Database();
~Database();
status_t InitCheck() const;
// Type management
status_t Install(const char *type);
status_t Delete(const char *type);
// Set()
status_t SetAppHint(const char *type, const entry_ref *ref);
status_t SetAttrInfo(const char *type, const BMessage *info);
status_t SetShortDescription(const char *type, const char *description);
status_t SetLongDescription(const char *type, const char *description);
status_t SetFileExtensions(const char *type, const BMessage *extensions);
status_t SetIcon(const char *type, const void *data, size_t dataSize, icon_size which);
status_t SetIconForType(const char *type, const char *fileType, const void *data,
size_t dataSize, icon_size which);
status_t SetPreferredApp(const char *type, const char *signature, app_verb verb = B_OPEN);
// status_t SetSnifferRule(const char *);
status_t SetSupportedTypes(const char *type, const BMessage *types);
// Non-atomic Get()
status_t GetInstalledSupertypes(BMessage *super_types);
status_t GetInstalledTypes(BMessage *types);
status_t GetInstalledTypes(const char *super_type,
BMessage *subtypes);
status_t GetSupportingApps(const char *type, BMessage *signatures);
// 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);
// Monitor
status_t StartWatching(BMessenger target);
status_t StopWatching(BMessenger target);
// Delete()
status_t DeleteAppHint(const char *type);
status_t DeleteAttrInfo(const char *type);
status_t DeleteShortDescription(const char *type);
status_t DeleteLongDescription(const char *type);
status_t DeleteFileExtensions(const char *type);
status_t DeleteIcon(const char *type, icon_size size);
status_t DeleteIconForType(const char *type, const char *fileType, icon_size which);
status_t DeletePreferredApp(const char *type, app_verb verb = B_OPEN);
status_t DeleteSnifferRule(const char *type);
status_t DeleteSupportedTypes(const char *type);
private:
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,
int32 action);
status_t SendMonitorUpdate(int32 which, const char *type, bool largeIcon,
int32 action);
status_t SendMonitorUpdate(int32 which, const char *type,
int32 action);
status_t SendMonitorUpdate(BMessage &msg);
status_t fCStatus;
std::set<BMessenger> fMonitorSet;
InstalledTypes fInstalledTypes;
};
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_DATABASE_H
@@ -0,0 +1,42 @@
// mime/InstalledTypes.h
#ifndef _MIME_INSTALLED_TYPES_H
#define _MIME_INSTALLED_TYPES_H
#include <mime/Supertype.h>
#include <SupportDefs.h>
#include <string>
#include <map>
class BMessage;
namespace BPrivate {
namespace Storage {
namespace Mime {
class InstalledTypes {
public:
InstalledTypes();
~InstalledTypes();
status_t GetInstalledTypes(BMessage *types);
status_t GetInstalledTypes(const char *supertype, BMessage *types);
status_t GetInstalledSupertypes(BMessage *types);
void AddType(const char *type);
void AddSupertype(const char *type);
void AddSubtype(const char *super, const char *sub);
private:
void FillMessageWithTypes(BMessage *msg);
void FillMessageWithSupertypes(BMessage *msg);
std::map<std::string, Supertype> fSupertypes;
BMessage *fCachedMessage;
};
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_INSTALLED_TYPES_H
+34
View File
@@ -0,0 +1,34 @@
// mime/Supertype.h
#ifndef _MIME_SUPERTYPE_H
#define _MIME_SUPERTYPE_H
#include <SupportDefs.h>
#include <string>
#include <set>
class BMessage;
namespace BPrivate {
namespace Storage {
namespace Mime {
class Supertype {
public:
Supertype(const char *super);
~Supertype();
void AddSubtype(const char *sub);
void FillMessageWithTypes(BMessage *msg);
private:
std::set<std::string> fSubtypes;
BMessage *fCachedMessage;
std::string fType;
};
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_SUPERTYPE_H
@@ -0,0 +1,39 @@
// mime/database_access.h
#ifndef _MIME_DATABASE_ACCESS_H
#define _MIME_DATABASE_ACCESS_H
#include <Mime.h>
class BNode;
class BBitmap;
class BMessage;
namespace BPrivate {
namespace Storage {
namespace Mime {
// Get() functions
status_t get_app_hint(const char *type, entry_ref *ref);
status_t get_attr_info(const char *type, BMessage *info);
status_t get_short_description(const char *type, char *description);
status_t get_long_description(const char *type, char *description);
status_t get_file_extensions(const char *type, BMessage *extensions);
status_t get_icon(const char *type, BBitmap *icon, icon_size size);
status_t get_icon_for_type(const char *type, const char *fileType, BBitmap *icon,
icon_size which);
status_t get_preferred_app(const char *type, char *signature, app_verb verb);
status_t get_sniffer_rule(BString *result);
status_t get_supported_types(const char *type, BMessage *types);
bool is_installed(const char *type);
// Called by BMimeType to get properly formatted icon data ready
// 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);
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_DATABASE_H
@@ -0,0 +1,71 @@
// mime/database_support.h
#ifndef _MIME_DATABASE_SUPPORT_H
#define _MIME_DATABASE_SUPPORT_H
#include <StorageDefs.h>
#include <string>
class BNode;
class BMessage;
namespace BPrivate {
namespace Storage {
namespace Mime {
// Database directory
extern const std::string kDatabaseDir;
// Attribute Prefixes
extern const char *kMiniIconAttrPrefix;
extern const char *kLargeIconAttrPrefix;
// Attribute names
extern const char *kFileTypeAttr;
extern const char *kTypeAttr;
extern const char *kAttrInfoAttr;
extern const char *kAppHintAttr;
extern const char *kShortDescriptionAttr;
extern const char *kLongDescriptionAttr;
extern const char *kFileExtensionsAttr;
extern const char *kMiniIconAttr;
extern const char *kLargeIconAttr;
extern const char *kPreferredAppAttr;
extern const char *kSnifferRuleAttr;
extern const char *kSupportedTypesAttr;
// Attribute Datatypes
extern const int32 kFileTypeType;
extern const int32 kTypeType;
extern const int32 kAppHintType;
extern const int32 kAttrInfoType;
extern const int32 kShortDescriptionType;
extern const int32 kLongDescriptionType;
extern const int32 kFileExtensionsType;
extern const int32 kMiniIconType;
extern const int32 kLargeIconType;
extern const int32 kPreferredAppType;
extern const int32 kSnifferRuleType;
extern const int32 kSupportedTypesType;
std::string type_to_filename(const char *type);
status_t open_type(const char *type, BNode *result);
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 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,
const BMessage *msg, bool *didCreate);
status_t delete_attribute(const char *type, const char *attr);
} // namespace Mime
} // namespace Storage
} // namespace BPrivate
#endif // _MIME_DATABASE_SUPPORT_H