1 /* 2 * Copyright 2002-2006, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Tyler Dauwalder 7 */ 8 #ifndef _MIME_DATABASE_H 9 #define _MIME_DATABASE_H 10 11 12 #include <Mime.h> 13 #include <mime/AssociatedTypes.h> 14 #include <mime/InstalledTypes.h> 15 #include <mime/SnifferRules.h> 16 #include <mime/SupportingApps.h> 17 #include <mime/database_access.h> 18 #include <Messenger.h> 19 #include <StorageDefs.h> 20 21 #include <string> 22 #include <map> 23 #include <set> 24 25 class BNode; 26 class BBitmap; 27 class BMessage; 28 class BString; 29 30 struct entry_ref; 31 32 namespace BPrivate { 33 namespace Storage { 34 namespace Mime { 35 36 // types of mime update functions that may be run asynchronously 37 typedef enum { 38 B_REG_UPDATE_MIME_INFO, 39 B_REG_CREATE_APP_META_MIME, 40 } mime_update_function; 41 42 class Database { 43 public: 44 Database(); 45 ~Database(); 46 47 status_t InitCheck() const; 48 49 // Type management 50 status_t Install(const char *type); 51 status_t Delete(const char *type); 52 53 // Set() 54 status_t SetAppHint(const char *type, const entry_ref *ref); 55 status_t SetAttrInfo(const char *type, const BMessage *info); 56 status_t SetShortDescription(const char *type, const char *description); 57 status_t SetLongDescription(const char *type, const char *description); 58 status_t SetFileExtensions(const char *type, const BMessage *extensions); 59 status_t SetIcon(const char *type, const void *data, size_t dataSize, 60 icon_size which); 61 status_t SetIcon(const char *type, const void *data, size_t dataSize); 62 status_t SetIconForType(const char *type, const char *fileType, 63 const void *data, size_t dataSize, icon_size which); 64 status_t SetIconForType(const char *type, const char *fileType, 65 const void *data, size_t dataSize); 66 status_t SetPreferredApp(const char *type, const char *signature, 67 app_verb verb = B_OPEN); 68 status_t SetSnifferRule(const char *type, const char *rule); 69 status_t SetSupportedTypes(const char *type, const BMessage *types, bool fullSync); 70 71 // Non-atomic Get() 72 status_t GetInstalledSupertypes(BMessage *super_types); 73 status_t GetInstalledTypes(BMessage *types); 74 status_t GetInstalledTypes(const char *super_type, 75 BMessage *subtypes); 76 status_t GetSupportingApps(const char *type, BMessage *signatures); 77 status_t GetAssociatedTypes(const char *extension, BMessage *types); 78 79 // Sniffer 80 status_t GuessMimeType(const entry_ref *file, BString *result); 81 status_t GuessMimeType(const void *buffer, int32 length, BString *result); 82 status_t GuessMimeType(const char *filename, BString *result); 83 84 // Monitor 85 status_t StartWatching(BMessenger target); 86 status_t StopWatching(BMessenger target); 87 88 // Delete() 89 status_t DeleteAppHint(const char *type); 90 status_t DeleteAttrInfo(const char *type); 91 status_t DeleteShortDescription(const char *type); 92 status_t DeleteLongDescription(const char *type); 93 status_t DeleteFileExtensions(const char *type); 94 status_t DeleteIcon(const char *type, icon_size size); 95 status_t DeleteIcon(const char *type); 96 status_t DeleteIconForType(const char *type, const char *fileType, 97 icon_size which); 98 status_t DeleteIconForType(const char *type, const char *fileType); 99 status_t DeletePreferredApp(const char *type, app_verb verb = B_OPEN); 100 status_t DeleteSnifferRule(const char *type); 101 status_t DeleteSupportedTypes(const char *type, bool fullSync); 102 103 private: 104 status_t _SetStringValue(const char *type, int32 what, 105 const char* attribute, type_code attributeType, 106 size_t maxLength, const char *value); 107 108 // Functions to send monitor notifications 109 status_t _SendInstallNotification(const char *type); 110 status_t _SendDeleteNotification(const char *type); 111 status_t _SendMonitorUpdate(int32 which, const char *type, 112 const char *extraType, bool largeIcon, int32 action); 113 status_t _SendMonitorUpdate(int32 which, const char *type, 114 const char *extraType, int32 action); 115 status_t _SendMonitorUpdate(int32 which, const char *type, 116 bool largeIcon, int32 action); 117 status_t _SendMonitorUpdate(int32 which, const char *type, 118 int32 action); 119 status_t _SendMonitorUpdate(BMessage &msg); 120 121 private: 122 status_t fStatus; 123 std::set<BMessenger> fMonitorMessengers; 124 AssociatedTypes fAssociatedTypes; 125 InstalledTypes fInstalledTypes; 126 SnifferRules fSnifferRules; 127 SupportingApps fSupportingApps; 128 }; 129 130 } // namespace Mime 131 } // namespace Storage 132 } // namespace BPrivate 133 134 #endif // _MIME_DATABASE_H 135