2 * Copyright 2002-2006, Haiku.
3 * Distributed under the terms of the MIT License.
8 #ifndef _MIME_DATABASE_H
9 #define _MIME_DATABASE_H
18 #include <Messenger.h>
19 #include <StorageDefs.h>
21 #include <mime/AssociatedTypes.h>
22 #include <mime/InstalledTypes.h>
23 #include <mime/SnifferRules.h>
24 #include <mime/SupportingApps.h>
39 class DatabaseLocation
;
43 // types of mime update functions that may be run asynchronously
45 B_REG_UPDATE_MIME_INFO
,
46 B_REG_CREATE_APP_META_MIME
,
47 } mime_update_function
;
51 class NotificationListener
;
54 Database(DatabaseLocation
* databaseLocation
, MimeSniffer
* mimeSniffer
,
55 NotificationListener
* notificationListener
);
58 status_t
InitCheck() const;
60 DatabaseLocation
* Location() const { return fLocation
; }
63 status_t
Install(const char *type
);
64 status_t
Delete(const char *type
);
67 status_t
SetAppHint(const char *type
, const entry_ref
*ref
);
68 status_t
SetAttrInfo(const char *type
, const BMessage
*info
);
69 status_t
SetShortDescription(const char *type
, const char *description
);
70 status_t
SetLongDescription(const char *type
, const char *description
);
71 status_t
SetFileExtensions(const char *type
, const BMessage
*extensions
);
72 status_t
SetIcon(const char* type
, const BBitmap
* icon
,
74 status_t
SetIcon(const char *type
, const void *data
, size_t dataSize
,
76 status_t
SetIcon(const char *type
, const void *data
, size_t dataSize
);
77 status_t
SetIconForType(const char* type
, const char* fileType
,
78 const BBitmap
* icon
, icon_size which
);
79 status_t
SetIconForType(const char *type
, const char *fileType
,
80 const void *data
, size_t dataSize
, icon_size which
);
81 status_t
SetIconForType(const char *type
, const char *fileType
,
82 const void *data
, size_t dataSize
);
83 status_t
SetPreferredApp(const char *type
, const char *signature
,
84 app_verb verb
= B_OPEN
);
85 status_t
SetSnifferRule(const char *type
, const char *rule
);
86 status_t
SetSupportedTypes(const char *type
, const BMessage
*types
, bool fullSync
);
89 status_t
GetInstalledSupertypes(BMessage
*super_types
);
90 status_t
GetInstalledTypes(BMessage
*types
);
91 status_t
GetInstalledTypes(const char *super_type
,
93 status_t
GetSupportingApps(const char *type
, BMessage
*signatures
);
94 status_t
GetAssociatedTypes(const char *extension
, BMessage
*types
);
97 status_t
GuessMimeType(const entry_ref
*file
, BString
*result
);
98 status_t
GuessMimeType(const void *buffer
, int32 length
, BString
*result
);
99 status_t
GuessMimeType(const char *filename
, BString
*result
);
102 status_t
StartWatching(BMessenger target
);
103 status_t
StopWatching(BMessenger target
);
106 status_t
DeleteAppHint(const char *type
);
107 status_t
DeleteAttrInfo(const char *type
);
108 status_t
DeleteShortDescription(const char *type
);
109 status_t
DeleteLongDescription(const char *type
);
110 status_t
DeleteFileExtensions(const char *type
);
111 status_t
DeleteIcon(const char *type
, icon_size size
);
112 status_t
DeleteIcon(const char *type
);
113 status_t
DeleteIconForType(const char *type
, const char *fileType
,
115 status_t
DeleteIconForType(const char *type
, const char *fileType
);
116 status_t
DeletePreferredApp(const char *type
, app_verb verb
= B_OPEN
);
117 status_t
DeleteSnifferRule(const char *type
);
118 status_t
DeleteSupportedTypes(const char *type
, bool fullSync
);
120 // deferred notifications
121 void DeferInstallNotification(const char* type
);
122 void UndeferInstallNotification(const char* type
);
125 struct DeferredInstallNotification
{
126 char type
[B_MIME_TYPE_LENGTH
];
130 status_t
_SetStringValue(const char *type
, int32 what
,
131 const char* attribute
, type_code attributeType
,
132 size_t maxLength
, const char *value
);
134 // Functions to send monitor notifications
135 status_t
_SendInstallNotification(const char *type
);
136 status_t
_SendDeleteNotification(const char *type
);
137 status_t
_SendMonitorUpdate(int32 which
, const char *type
,
138 const char *extraType
, bool largeIcon
, int32 action
);
139 status_t
_SendMonitorUpdate(int32 which
, const char *type
,
140 const char *extraType
, int32 action
);
141 status_t
_SendMonitorUpdate(int32 which
, const char *type
,
142 bool largeIcon
, int32 action
);
143 status_t
_SendMonitorUpdate(int32 which
, const char *type
,
145 status_t
_SendMonitorUpdate(BMessage
&msg
);
147 DeferredInstallNotification
* _FindDeferredInstallNotification(
148 const char* type
, bool remove
= false);
149 bool _CheckDeferredInstallNotification(int32 which
, const char* type
);
153 DatabaseLocation
* fLocation
;
154 NotificationListener
* fNotificationListener
;
155 std::set
<BMessenger
> fMonitorMessengers
;
156 AssociatedTypes fAssociatedTypes
;
157 InstalledTypes fInstalledTypes
;
158 SnifferRules fSnifferRules
;
159 SupportingApps fSupportingApps
;
161 BLocker fDeferredInstallNotificationsLocker
;
162 BList fDeferredInstallNotifications
;
165 class InstallNotificationDeferrer
{
167 InstallNotificationDeferrer(Database
* database
, const char* type
)
172 if (fDatabase
!= NULL
&& fType
!= NULL
)
173 fDatabase
->DeferInstallNotification(fType
);
176 ~InstallNotificationDeferrer()
178 if (fDatabase
!= NULL
&& fType
!= NULL
)
179 fDatabase
->UndeferInstallNotification(fType
);
188 class Database::NotificationListener
{
190 virtual ~NotificationListener();
192 virtual status_t
Notify(BMessage
* message
,
193 const BMessenger
& target
) = 0;
198 } // namespace Storage
199 } // namespace BPrivate
201 #endif // _MIME_DATABASE_H