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 SetIconForType(const char *type, const char *fileType, const void *data, 62 size_t dataSize, icon_size which); 63 status_t SetPreferredApp(const char *type, const char *signature, 64 app_verb verb = B_OPEN); 65 status_t SetSnifferRule(const char *type, const char *rule); 66 status_t SetSupportedTypes(const char *type, const BMessage *types, bool fullSync); 67 68 // Non-atomic Get() 69 status_t GetInstalledSupertypes(BMessage *super_types); 70 status_t GetInstalledTypes(BMessage *types); 71 status_t GetInstalledTypes(const char *super_type, 72 BMessage *subtypes); 73 status_t GetSupportingApps(const char *type, BMessage *signatures); 74 status_t GetAssociatedTypes(const char *extension, BMessage *types); 75 76 // Sniffer 77 status_t GuessMimeType(const entry_ref *file, BString *result); 78 status_t GuessMimeType(const void *buffer, int32 length, BString *result); 79 status_t GuessMimeType(const char *filename, BString *result); 80 81 // Monitor 82 status_t StartWatching(BMessenger target); 83 status_t StopWatching(BMessenger target); 84 85 // Delete() 86 status_t DeleteAppHint(const char *type); 87 status_t DeleteAttrInfo(const char *type); 88 status_t DeleteShortDescription(const char *type); 89 status_t DeleteLongDescription(const char *type); 90 status_t DeleteFileExtensions(const char *type); 91 status_t DeleteIcon(const char *type, icon_size size); 92 status_t DeleteIconForType(const char *type, const char *fileType, 93 icon_size which); 94 status_t DeletePreferredApp(const char *type, app_verb verb = B_OPEN); 95 status_t DeleteSnifferRule(const char *type); 96 status_t DeleteSupportedTypes(const char *type, bool fullSync); 97 98 private: 99 status_t _SetStringValue(const char *type, int32 what, 100 const char* attribute, type_code attributeType, 101 size_t maxLength, const char *value); 102 103 // Functions to send monitor notifications 104 status_t _SendInstallNotification(const char *type); 105 status_t _SendDeleteNotification(const char *type); 106 status_t _SendMonitorUpdate(int32 which, const char *type, 107 const char *extraType, bool largeIcon, int32 action); 108 status_t _SendMonitorUpdate(int32 which, const char *type, 109 const char *extraType, int32 action); 110 status_t _SendMonitorUpdate(int32 which, const char *type, 111 bool largeIcon, int32 action); 112 status_t _SendMonitorUpdate(int32 which, const char *type, 113 int32 action); 114 status_t _SendMonitorUpdate(BMessage &msg); 115 116 private: 117 status_t fStatus; 118 std::set<BMessenger> fMonitorMessengers; 119 AssociatedTypes fAssociatedTypes; 120 InstalledTypes fInstalledTypes; 121 SnifferRules fSnifferRules; 122 SupportingApps fSupportingApps; 123 }; 124 125 } // namespace Mime 126 } // namespace Storage 127 } // namespace BPrivate 128 129 #endif // _MIME_DATABASE_H 130