116e50923SOliver Tappe /*
216e50923SOliver Tappe * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de
316e50923SOliver Tappe * Copyright 2003-2004,2012, Oliver Tappe, zooey@hirschkaefer.de
416e50923SOliver Tappe * Distributed under the terms of the MIT License.
516e50923SOliver Tappe */
616e50923SOliver Tappe
716e50923SOliver Tappe #include <EditableCatalog.h>
816e50923SOliver Tappe
9541ff51aSOliver Tappe #include <CatalogData.h>
1016e50923SOliver Tappe #include <MutableLocaleRoster.h>
1116e50923SOliver Tappe
1216e50923SOliver Tappe
1316e50923SOliver Tappe using BPrivate::MutableLocaleRoster;
1416e50923SOliver Tappe
1516e50923SOliver Tappe
1616e50923SOliver Tappe namespace BPrivate {
EditableCatalog(const char * type,const char * signature,const char * language)1716e50923SOliver Tappe EditableCatalog::EditableCatalog(const char* type, const char* signature,
1816e50923SOliver Tappe const char* language)
1916e50923SOliver Tappe {
20541ff51aSOliver Tappe fCatalogData = MutableLocaleRoster::Default()->CreateCatalog(type,
21541ff51aSOliver Tappe signature, language);
2216e50923SOliver Tappe }
2316e50923SOliver Tappe
2416e50923SOliver Tappe
~EditableCatalog()2516e50923SOliver Tappe EditableCatalog::~EditableCatalog()
2616e50923SOliver Tappe {
2716e50923SOliver Tappe }
2816e50923SOliver Tappe
2916e50923SOliver Tappe
3016e50923SOliver Tappe status_t
SetString(const char * string,const char * translated,const char * context,const char * comment)3116e50923SOliver Tappe EditableCatalog::SetString(const char* string, const char* translated,
3216e50923SOliver Tappe const char* context, const char* comment)
3316e50923SOliver Tappe {
34541ff51aSOliver Tappe if (fCatalogData == NULL)
3516e50923SOliver Tappe return B_NO_INIT;
3616e50923SOliver Tappe
37541ff51aSOliver Tappe return fCatalogData->SetString(string, translated, context, comment);
3816e50923SOliver Tappe }
3916e50923SOliver Tappe
4016e50923SOliver Tappe
4116e50923SOliver Tappe status_t
SetString(int32 id,const char * translated)4216e50923SOliver Tappe EditableCatalog::SetString(int32 id, const char* translated)
4316e50923SOliver Tappe {
44541ff51aSOliver Tappe if (fCatalogData == NULL)
4516e50923SOliver Tappe return B_NO_INIT;
4616e50923SOliver Tappe
47541ff51aSOliver Tappe return fCatalogData->SetString(id, translated);
4816e50923SOliver Tappe }
4916e50923SOliver Tappe
5016e50923SOliver Tappe
5116e50923SOliver Tappe bool
CanWriteData() const5216e50923SOliver Tappe EditableCatalog::CanWriteData() const
5316e50923SOliver Tappe {
54541ff51aSOliver Tappe if (fCatalogData == NULL)
5516e50923SOliver Tappe return false;
5616e50923SOliver Tappe
57541ff51aSOliver Tappe return fCatalogData->CanWriteData();
5816e50923SOliver Tappe }
5916e50923SOliver Tappe
6016e50923SOliver Tappe
6116e50923SOliver Tappe status_t
SetData(const char * name,BMessage * msg)6216e50923SOliver Tappe EditableCatalog::SetData(const char* name, BMessage* msg)
6316e50923SOliver Tappe {
64541ff51aSOliver Tappe if (fCatalogData == NULL)
6516e50923SOliver Tappe return B_NO_INIT;
6616e50923SOliver Tappe
67541ff51aSOliver Tappe return fCatalogData->SetData(name, msg);
6816e50923SOliver Tappe }
6916e50923SOliver Tappe
7016e50923SOliver Tappe
7116e50923SOliver Tappe status_t
SetData(uint32 id,BMessage * msg)7216e50923SOliver Tappe EditableCatalog::SetData(uint32 id, BMessage* msg)
7316e50923SOliver Tappe {
74541ff51aSOliver Tappe if (fCatalogData == NULL)
7516e50923SOliver Tappe return B_NO_INIT;
7616e50923SOliver Tappe
77541ff51aSOliver Tappe return fCatalogData->SetData(id, msg);
7816e50923SOliver Tappe }
7916e50923SOliver Tappe
8016e50923SOliver Tappe
8116e50923SOliver Tappe status_t
ReadFromFile(const char * path)8216e50923SOliver Tappe EditableCatalog::ReadFromFile(const char* path)
8316e50923SOliver Tappe {
84541ff51aSOliver Tappe if (fCatalogData == NULL)
8516e50923SOliver Tappe return B_NO_INIT;
8616e50923SOliver Tappe
87541ff51aSOliver Tappe return fCatalogData->ReadFromFile(path);
8816e50923SOliver Tappe }
8916e50923SOliver Tappe
9016e50923SOliver Tappe
9116e50923SOliver Tappe status_t
ReadFromAttribute(const entry_ref & appOrAddOnRef)9216e50923SOliver Tappe EditableCatalog::ReadFromAttribute(const entry_ref& appOrAddOnRef)
9316e50923SOliver Tappe {
94541ff51aSOliver Tappe if (fCatalogData == NULL)
9516e50923SOliver Tappe return B_NO_INIT;
9616e50923SOliver Tappe
97541ff51aSOliver Tappe return fCatalogData->ReadFromAttribute(appOrAddOnRef);
9816e50923SOliver Tappe }
9916e50923SOliver Tappe
10016e50923SOliver Tappe
10116e50923SOliver Tappe status_t
ReadFromResource(const entry_ref & appOrAddOnRef)10216e50923SOliver Tappe EditableCatalog::ReadFromResource(const entry_ref& appOrAddOnRef)
10316e50923SOliver Tappe {
104541ff51aSOliver Tappe if (fCatalogData == NULL)
10516e50923SOliver Tappe return B_NO_INIT;
10616e50923SOliver Tappe
107541ff51aSOliver Tappe return fCatalogData->ReadFromResource(appOrAddOnRef);
10816e50923SOliver Tappe }
10916e50923SOliver Tappe
11016e50923SOliver Tappe
11116e50923SOliver Tappe status_t
WriteToFile(const char * path)11216e50923SOliver Tappe EditableCatalog::WriteToFile(const char* path)
11316e50923SOliver Tappe {
114541ff51aSOliver Tappe if (fCatalogData == NULL)
11516e50923SOliver Tappe return B_NO_INIT;
11616e50923SOliver Tappe
117541ff51aSOliver Tappe return fCatalogData->WriteToFile(path);
11816e50923SOliver Tappe }
11916e50923SOliver Tappe
12016e50923SOliver Tappe
12116e50923SOliver Tappe status_t
WriteToAttribute(const entry_ref & appOrAddOnRef)12216e50923SOliver Tappe EditableCatalog::WriteToAttribute(const entry_ref& appOrAddOnRef)
12316e50923SOliver Tappe {
124541ff51aSOliver Tappe if (fCatalogData == NULL)
12516e50923SOliver Tappe return B_NO_INIT;
12616e50923SOliver Tappe
127541ff51aSOliver Tappe return fCatalogData->WriteToAttribute(appOrAddOnRef);
12816e50923SOliver Tappe }
12916e50923SOliver Tappe
13016e50923SOliver Tappe
13116e50923SOliver Tappe status_t
WriteToResource(const entry_ref & appOrAddOnRef)13216e50923SOliver Tappe EditableCatalog::WriteToResource(const entry_ref& appOrAddOnRef)
13316e50923SOliver Tappe {
134541ff51aSOliver Tappe if (fCatalogData == NULL)
13516e50923SOliver Tappe return B_NO_INIT;
13616e50923SOliver Tappe
137541ff51aSOliver Tappe return fCatalogData->WriteToResource(appOrAddOnRef);
13816e50923SOliver Tappe }
13916e50923SOliver Tappe
14016e50923SOliver Tappe
MakeEmpty()14116e50923SOliver Tappe void EditableCatalog::MakeEmpty()
14216e50923SOliver Tappe {
143*e5ab37aeSMurai Takashi if (fCatalogData != NULL)
144541ff51aSOliver Tappe fCatalogData->MakeEmpty();
14516e50923SOliver Tappe }
14616e50923SOliver Tappe
14716e50923SOliver Tappe
148541ff51aSOliver Tappe BCatalogData*
CatalogData()149541ff51aSOliver Tappe EditableCatalog::CatalogData()
15016e50923SOliver Tappe {
151541ff51aSOliver Tappe return fCatalogData;
15216e50923SOliver Tappe }
15316e50923SOliver Tappe
15416e50923SOliver Tappe
15516e50923SOliver Tappe } // namespace BPrivate
156