1 /* 2 * Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _DEFAULT_CATALOG_H_ 6 #define _DEFAULT_CATALOG_H_ 7 8 9 #include <DataIO.h> 10 #include <HashMapCatalog.h> 11 #include <String.h> 12 13 14 class BFile; 15 16 namespace BPrivate { 17 18 19 /* 20 * The implementation of the Locale Kit's standard catalog-type. 21 * Currently it only maps CatKey to a BString (the translated string), 22 * but the value-type might change to add support for shortcuts and/or 23 * graphical data (button-images and the like). 24 */ 25 class DefaultCatalog : public BHashMapCatalog { 26 public: 27 DefaultCatalog(const entry_ref &catalogOwner, const char *language, 28 uint32 fingerprint); 29 // constructor for normal use 30 DefaultCatalog(entry_ref *appOrAddOnRef); 31 // constructor for embedded catalog 32 DefaultCatalog(const char *path, const char *signature, 33 const char *language); 34 // constructor for editor-app 35 36 ~DefaultCatalog(); 37 38 39 // implementation for editor-interface: 40 status_t ReadFromFile(const char *path = NULL); 41 status_t ReadFromAttribute(const entry_ref &appOrAddOnRef); 42 status_t ReadFromResource(const entry_ref &appOrAddOnRef); 43 status_t WriteToFile(const char *path = NULL); 44 status_t WriteToAttribute(const entry_ref &appOrAddOnRef); 45 status_t WriteToResource(const entry_ref &appOrAddOnRef); 46 47 status_t SetRawString(const CatKey& key, const char *translated); 48 void SetSignature(const entry_ref &catalogOwner); 49 50 static BCatalogAddOn *Instantiate(const entry_ref& catalogOwner, 51 const char *language, uint32 fingerprint); 52 static BCatalogAddOn *Create(const char *signature, 53 const char *language); 54 55 static const uint8 kDefaultCatalogAddOnPriority; 56 static const char *kCatMimeType; 57 58 private: 59 status_t Flatten(BDataIO *dataIO); 60 status_t Unflatten(BDataIO *dataIO); 61 void UpdateAttributes(BFile& catalogFile); 62 63 mutable BString fPath; 64 }; 65 66 extern "C" status_t 67 default_catalog_get_available_languages(BMessage* availableLanguages, 68 const char* sigPattern, const char* langPattern = NULL, 69 int32 fingerprint = 0); 70 71 } // namespace BPrivate 72 73 using namespace BPrivate; 74 75 #endif /* _DEFAULT_CATALOG_H_ */ 76