1/*
2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Ingo Weinhold <ingo_weinhold@gmx.de>
7 */
8#ifndef _MIME_DATABASE_LOCATION_H
9#define _MIME_DATABASE_LOCATION_H
10
11
12#include <Mime.h>
13#include <StringList.h>
14
15
16namespace BPrivate {
17namespace Storage {
18namespace Mime {
19
20
21class DatabaseLocation {
22public:
23								DatabaseLocation();
24								~DatabaseLocation();
25
26			bool				AddDirectory(const BString& directory);
27
28			// paths
29
30			const BStringList&	Directories() const
31									{ return fDirectories; }
32			BString				WritableDirectory() const
33									{ return fDirectories.StringAt(0); }
34
35			BString				WritablePathForType(const char* type) const
36									{ return _TypeToFilename(type, 0); }
37
38			// opening type nodes
39
40			status_t			OpenType(const char* type, BNode& _node) const;
41			status_t			OpenWritableType(const char* type,
42									BNode& _node, bool create,
43									bool* _didCreate = NULL) const;
44
45			// generic type attributes access
46
47			ssize_t				ReadAttribute(const char* type,
48									const char* attribute, void* data,
49									size_t length, type_code datatype) const;
50			status_t			ReadMessageAttribute(const char* type,
51									const char* attribute, BMessage& _message)
52									const;
53			status_t			ReadStringAttribute(const char* type,
54									const char* attribute, BString& _string)
55									const;
56
57			status_t			WriteAttribute(const char* type,
58									const char* attribute, const void* data,
59									size_t length, type_code datatype,
60									bool* _didCreate) const;
61			status_t			WriteMessageAttribute(const char* type,
62									const char* attribute,
63									const BMessage& message, bool* _didCreate)
64									const;
65
66			status_t			DeleteAttribute(const char* type,
67									const char* attribute) const;
68
69			// type attribute convenience getters
70
71			status_t			GetAppHint(const char* type, entry_ref& _ref);
72			status_t			GetAttributesInfo(const char* type,
73									BMessage& _info);
74			status_t			GetShortDescription(const char* type,
75									char* description);
76			status_t			GetLongDescription(const char* type,
77									char* description);
78			status_t			GetFileExtensions(const char* type,
79									BMessage& _extensions);
80			status_t			GetIcon(const char* type, BBitmap& _icon,
81									icon_size size);
82			status_t			GetIcon(const char* type, uint8*& _data,
83									size_t& _size);
84			status_t			GetIconForType(const char* type,
85									const char* fileType, BBitmap& _icon,
86									icon_size which);
87			status_t			GetIconForType(const char* type,
88									const char* fileType, uint8*& _data,
89									size_t& _size);
90			status_t			GetPreferredApp(const char* type,
91									char* signature, app_verb verb);
92			status_t			GetSnifferRule(const char* type,
93									BString& _result);
94			status_t			GetSupportedTypes(const char* type,
95									BMessage& _types);
96
97			bool				IsInstalled(const char* type);
98
99private:
100			BString				_TypeToFilename(const char* type, int32 index)
101									const;
102			status_t			_OpenType(const char* type, BNode& _node,
103									int32& _index) const;
104			status_t			_CreateTypeNode(const char* type, BNode& _node)
105									const;
106			status_t			_CopyTypeNode(BNode& source, const char* type,
107									BNode& _target) const;
108
109private:
110			BStringList			fDirectories;
111};
112
113
114} // namespace Mime
115} // namespace Storage
116} // namespace BPrivate
117
118
119#endif	// _MIME_DATABASE_LOCATION_H
120