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