MimeType.h revision b6f76ebe
1//----------------------------------------------------------------------
2//  This software is part of the OpenBeOS distribution and is covered
3//  by the MIT License.
4//---------------------------------------------------------------------
5/*!
6	\file MimeType.h
7	BMimeType interface declarations.
8*/
9#ifndef _MIME_TYPE_H
10#define _MIME_TYPE_H
11
12#include <SupportDefs.h>
13#include <StorageDefs.h>
14
15#include <Messenger.h>
16#include <Mime.h>
17#include <File.h>
18#include <Entry.h>
19
20class BBitmap;
21class BResources;
22class BAppFileInfo;
23class BMessenger;
24
25namespace BPrivate {
26	class MimeDatabase;
27}
28
29enum app_verb {
30	B_OPEN
31};
32
33extern const char *B_APP_MIME_TYPE;		// platform dependent
34extern const char *B_PEF_APP_MIME_TYPE;	// "application/x-be-executable"
35extern const char *B_PE_APP_MIME_TYPE;	// "application/x-vnd.be-peexecutable"
36extern const char *B_ELF_APP_MIME_TYPE;	// "application/x-vnd.be-elfexecutable"
37extern const char *B_RESOURCE_MIME_TYPE;// "application/x-be-resource"
38extern const char *B_FILE_MIME_TYPE;	// "application/octet-stream"
39
40/* ------------------------------------------------------------- */
41
42// MIME Monitor BMessage::what value
43enum {
44	B_META_MIME_CHANGED = 'MMCH'
45};
46
47// MIME Monitor "be:which" values
48enum {
49	B_ICON_CHANGED					= 0x00000001,
50	B_PREFERRED_APP_CHANGED			= 0x00000002,
51	B_ATTR_INFO_CHANGED				= 0x00000004,
52	B_FILE_EXTENSIONS_CHANGED		= 0x00000008,
53	B_SHORT_DESCRIPTION_CHANGED		= 0x00000010,
54	B_LONG_DESCRIPTION_CHANGED		= 0x00000020,
55	B_ICON_FOR_TYPE_CHANGED			= 0x00000040,
56	B_APP_HINT_CHANGED				= 0x00000080,
57	B_MIME_TYPE_CREATED				= 0x00000100,
58	B_MIME_TYPE_DELETED				= 0x00000200,
59	B_SNIFFER_RULE_CHANGED			= 0x00000400,
60	B_SUPPORTED_TYPES_CHANGED		= 0x00000800,
61
62	B_EVERYTHING_CHANGED			= (int)0xFFFFFFFF
63};
64
65// MIME Monitor "be:action" values
66enum {
67	B_META_MIME_MODIFIED	= 'MMMD',
68	B_META_MIME_DELETED 	= 'MMDL',
69};
70
71/* ------------------------------------------------------------- */
72
73//!		File typing functionality.
74/*! 	The BMimeType class provides access to the file typing system, which
75		provides the following functionality:
76			- Basic MIME string manipulation
77			- Access to file type information in the MIME database
78			- Ways to receive notifications when parts of the MIME database are updated
79			- Methods to determine/help determine the types of untyped files
80
81		\author <a href='mailto:tylerdauwalder@users.sf.net'>Tyler Dauwalder</a>
82		\author <a href='bonefish@users.sf.net'>Ingo Weinhold</a>
83		\version 0.0.0
84*/
85class BMimeType	{
86public:
87	BMimeType();
88	BMimeType(const char *mimeType);
89	virtual ~BMimeType();
90
91	status_t SetTo(const char *mimeType);
92	void Unset();
93	status_t InitCheck() const;
94
95	/* these functions simply perform string manipulations*/
96	const char *Type() const;
97	bool IsValid() const;
98	bool IsSupertypeOnly() const;
99	status_t GetSupertype(BMimeType *superType) const;
100
101	bool operator==(const BMimeType &type) const;
102	bool operator==(const char *type) const;
103
104	bool Contains(const BMimeType *type) const;
105
106	/* These functions are for managing data in the meta mime file*/
107 	static bool IsValid(const char *mimeType);
108
109	/* Deprecated  Use SetTo instead. */
110	status_t SetType(const char *mimeType);
111
112	static status_t GuessMimeType(const entry_ref *file, BMimeType *type);
113	static status_t GuessMimeType(const void *buffer, int32 length,
114								  BMimeType *type);
115	static status_t GuessMimeType(const char *filename, BMimeType *type);
116
117private:
118	BMimeType(const char *mimeType, const char *mimePath);
119		// if mimePath is NULL, defaults to "/boot/home/config/settings/beos_mime/"
120
121	friend class MimeTypeTest;
122
123// Uncomment, when needed...
124
125	friend class BAppFileInfo;
126//	friend class BRoster;
127//	friend class TRosterApp;
128//	friend class TMimeWorker;
129
130//	friend status_t _update_mime_info_(const char *, int32);
131//	friend status_t _real_update_app_(BAppFileInfo *, const char *, bool);
132
133//	static void _set_local_dispatch_target_(BMessenger *, void (*)(BMessage *));
134//	void _touch_();
135
136	virtual void _ReservedMimeType1();
137	virtual void _ReservedMimeType2();
138	virtual void _ReservedMimeType3();
139
140	BMimeType &operator=(const BMimeType &);
141	BMimeType(const BMimeType &);
142
143
144//	void InitData(const char *type);
145//	void InitData(const char *type);
146//	status_t OpenFile(bool create_file = false, dev_t dev = -1) const;
147//	status_t CloseFile() const;
148	status_t GetSupportedTypes(BMessage *types);
149	status_t SetSupportedTypes(const BMessage *types, bool fullSync = true);
150
151	static status_t GetAssociatedTypes(const char *extension, BMessage *types);
152
153//	void MimeChanged(int32 w, const char *type = NULL,
154//					 bool large = true) const;
155
156
157	char		*fType;
158	BFile		*fMeta;
159	void		*_unused;
160	entry_ref	fRef;
161	int			fWhere;
162	status_t	fCStatus;
163	uint32		_reserved[3];
164};
165
166
167#endif	// _MIME_TYPE_H
168
169
170