xref: /haiku/headers/os/locale/CatalogData.h (revision 71452e98334eaac603bf542d159e24788a46bebb)
1 /*
2  * Copyright 2003-2012, Haiku, Inc.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _CATALOG_DATA_H_
6 #define _CATALOG_DATA_H_
7 
8 
9 #include <SupportDefs.h>
10 #include <String.h>
11 
12 
13 class BCatalog;
14 class BMessage;
15 struct entry_ref;
16 
17 
18 /**
19  * Base class for the catalog-data provided by every catalog add-on. An instance
20  * of this class represents (the data of) a single catalog. Several of these
21  * catalog data objects may be chained together in order to represent
22  * variations of a specific language. If for instance the catalog data 'en_uk'
23  * is chained to the data for 'en', a BCatalog using this catalog data chain
24  * will prefer any entries in the 'en_uk' catalog, but fallback onto 'en' for
25  * entries missing in the former.
26  */
27 class BCatalogData {
28 public:
29 								BCatalogData(const char* signature,
30 									const char* language,
31 									uint32 fingerprint);
32 	virtual						~BCatalogData();
33 
34 	virtual	const char*			GetString(const char* string,
35 									const char* context = NULL,
36 									const char* comment = NULL) = 0;
37 	virtual	const char*			GetString(uint32 id) = 0;
38 
39 			status_t			InitCheck() const;
40 			BCatalogData*		Next();
41 
42 	// the following could be used to localize non-textual data (e.g.
43 	// icons), but these will only be implemented if there's demand for such
44 	// a feature:
45 	virtual	bool				CanHaveData() const;
46 	virtual	status_t			GetData(const char* name, BMessage* msg);
47 	virtual	status_t			GetData(uint32 id, BMessage* msg);
48 
49 	// interface for catalog-editor-app and testing apps:
50 	virtual	status_t			SetString(const char* string,
51 									const char* translated,
52 									const char* context = NULL,
53 									const char* comment = NULL);
54 	virtual	status_t			SetString(int32 id, const char* translated);
55 
56 	virtual	bool				CanWriteData() const;
57 	virtual	status_t			SetData(const char* name, BMessage* msg);
58 	virtual	status_t			SetData(uint32 id, BMessage* msg);
59 
60 	virtual	status_t			ReadFromFile(const char* path = NULL);
61 	virtual	status_t			ReadFromAttribute(
62 									const entry_ref& appOrAddOnRef);
63 	virtual	status_t			ReadFromResource(
64 									const entry_ref& appOrAddOnRef);
65 	virtual	status_t			WriteToFile(const char* path = NULL);
66 	virtual	status_t			WriteToAttribute(
67 									const entry_ref& appOrAddOnRef);
68 	virtual	status_t			WriteToResource(
69 									const entry_ref& appOrAddOnRef);
70 
71 	virtual	void				MakeEmpty();
72 	virtual	int32				CountItems() const;
73 
74 			void				SetNext(BCatalogData* next);
75 
76 protected:
77 	virtual	void				UpdateFingerprint();
78 
79 protected:
80 	friend	class BCatalog;
81 	friend	status_t 			get_add_on_catalog(BCatalog*, const char*);
82 
83 			status_t 			fInitCheck;
84 			BString 			fSignature;
85 			BString 			fLanguageName;
86 			uint32				fFingerprint;
87 			BCatalogData*		fNext;
88 };
89 
90 
91 inline BCatalogData*
92 BCatalogData::Next()
93 {
94 	return fNext;
95 }
96 
97 
98 // every catalog-add-on should export the following three symbols:
99 //
100 // 1. the function that instantiates a catalog for this add-on-type
101 extern "C"
102 BCatalogData* instantiate_catalog(const entry_ref& signature,
103 	const char* language, uint32 fingerprint);
104 
105 // 2. the function that creates an empty catalog for this add-on-type
106 extern "C"
107 BCatalogData* create_catalog(const char* signature, const char* language);
108 
109 // 3. the priority which will be used to order the catalog add-ons
110 extern uint8 gCatalogAddOnPriority;
111 
112 
113 #endif /* _CATALOG_DATA_H_ */
114