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 9*541ff51aSOliver 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 { 1716e50923SOliver Tappe EditableCatalog::EditableCatalog(const char* type, const char* signature, 1816e50923SOliver Tappe const char* language) 1916e50923SOliver Tappe { 20*541ff51aSOliver Tappe fCatalogData = MutableLocaleRoster::Default()->CreateCatalog(type, 21*541ff51aSOliver Tappe signature, language); 2216e50923SOliver Tappe } 2316e50923SOliver Tappe 2416e50923SOliver Tappe 2516e50923SOliver Tappe EditableCatalog::~EditableCatalog() 2616e50923SOliver Tappe { 2716e50923SOliver Tappe } 2816e50923SOliver Tappe 2916e50923SOliver Tappe 3016e50923SOliver Tappe status_t 3116e50923SOliver Tappe EditableCatalog::SetString(const char* string, const char* translated, 3216e50923SOliver Tappe const char* context, const char* comment) 3316e50923SOliver Tappe { 34*541ff51aSOliver Tappe if (fCatalogData == NULL) 3516e50923SOliver Tappe return B_NO_INIT; 3616e50923SOliver Tappe 37*541ff51aSOliver Tappe return fCatalogData->SetString(string, translated, context, comment); 3816e50923SOliver Tappe } 3916e50923SOliver Tappe 4016e50923SOliver Tappe 4116e50923SOliver Tappe status_t 4216e50923SOliver Tappe EditableCatalog::SetString(int32 id, const char* translated) 4316e50923SOliver Tappe { 44*541ff51aSOliver Tappe if (fCatalogData == NULL) 4516e50923SOliver Tappe return B_NO_INIT; 4616e50923SOliver Tappe 47*541ff51aSOliver Tappe return fCatalogData->SetString(id, translated); 4816e50923SOliver Tappe } 4916e50923SOliver Tappe 5016e50923SOliver Tappe 5116e50923SOliver Tappe bool 5216e50923SOliver Tappe EditableCatalog::CanWriteData() const 5316e50923SOliver Tappe { 54*541ff51aSOliver Tappe if (fCatalogData == NULL) 5516e50923SOliver Tappe return false; 5616e50923SOliver Tappe 57*541ff51aSOliver Tappe return fCatalogData->CanWriteData(); 5816e50923SOliver Tappe } 5916e50923SOliver Tappe 6016e50923SOliver Tappe 6116e50923SOliver Tappe status_t 6216e50923SOliver Tappe EditableCatalog::SetData(const char* name, BMessage* msg) 6316e50923SOliver Tappe { 64*541ff51aSOliver Tappe if (fCatalogData == NULL) 6516e50923SOliver Tappe return B_NO_INIT; 6616e50923SOliver Tappe 67*541ff51aSOliver Tappe return fCatalogData->SetData(name, msg); 6816e50923SOliver Tappe } 6916e50923SOliver Tappe 7016e50923SOliver Tappe 7116e50923SOliver Tappe status_t 7216e50923SOliver Tappe EditableCatalog::SetData(uint32 id, BMessage* msg) 7316e50923SOliver Tappe { 74*541ff51aSOliver Tappe if (fCatalogData == NULL) 7516e50923SOliver Tappe return B_NO_INIT; 7616e50923SOliver Tappe 77*541ff51aSOliver Tappe return fCatalogData->SetData(id, msg); 7816e50923SOliver Tappe } 7916e50923SOliver Tappe 8016e50923SOliver Tappe 8116e50923SOliver Tappe status_t 8216e50923SOliver Tappe EditableCatalog::ReadFromFile(const char* path) 8316e50923SOliver Tappe { 84*541ff51aSOliver Tappe if (fCatalogData == NULL) 8516e50923SOliver Tappe return B_NO_INIT; 8616e50923SOliver Tappe 87*541ff51aSOliver Tappe return fCatalogData->ReadFromFile(path); 8816e50923SOliver Tappe } 8916e50923SOliver Tappe 9016e50923SOliver Tappe 9116e50923SOliver Tappe status_t 9216e50923SOliver Tappe EditableCatalog::ReadFromAttribute(const entry_ref& appOrAddOnRef) 9316e50923SOliver Tappe { 94*541ff51aSOliver Tappe if (fCatalogData == NULL) 9516e50923SOliver Tappe return B_NO_INIT; 9616e50923SOliver Tappe 97*541ff51aSOliver Tappe return fCatalogData->ReadFromAttribute(appOrAddOnRef); 9816e50923SOliver Tappe } 9916e50923SOliver Tappe 10016e50923SOliver Tappe 10116e50923SOliver Tappe status_t 10216e50923SOliver Tappe EditableCatalog::ReadFromResource(const entry_ref& appOrAddOnRef) 10316e50923SOliver Tappe { 104*541ff51aSOliver Tappe if (fCatalogData == NULL) 10516e50923SOliver Tappe return B_NO_INIT; 10616e50923SOliver Tappe 107*541ff51aSOliver Tappe return fCatalogData->ReadFromResource(appOrAddOnRef); 10816e50923SOliver Tappe } 10916e50923SOliver Tappe 11016e50923SOliver Tappe 11116e50923SOliver Tappe status_t 11216e50923SOliver Tappe EditableCatalog::WriteToFile(const char* path) 11316e50923SOliver Tappe { 114*541ff51aSOliver Tappe if (fCatalogData == NULL) 11516e50923SOliver Tappe return B_NO_INIT; 11616e50923SOliver Tappe 117*541ff51aSOliver Tappe return fCatalogData->WriteToFile(path); 11816e50923SOliver Tappe } 11916e50923SOliver Tappe 12016e50923SOliver Tappe 12116e50923SOliver Tappe status_t 12216e50923SOliver Tappe EditableCatalog::WriteToAttribute(const entry_ref& appOrAddOnRef) 12316e50923SOliver Tappe { 124*541ff51aSOliver Tappe if (fCatalogData == NULL) 12516e50923SOliver Tappe return B_NO_INIT; 12616e50923SOliver Tappe 127*541ff51aSOliver Tappe return fCatalogData->WriteToAttribute(appOrAddOnRef); 12816e50923SOliver Tappe } 12916e50923SOliver Tappe 13016e50923SOliver Tappe 13116e50923SOliver Tappe status_t 13216e50923SOliver Tappe EditableCatalog::WriteToResource(const entry_ref& appOrAddOnRef) 13316e50923SOliver Tappe { 134*541ff51aSOliver Tappe if (fCatalogData == NULL) 13516e50923SOliver Tappe return B_NO_INIT; 13616e50923SOliver Tappe 137*541ff51aSOliver Tappe return fCatalogData->WriteToResource(appOrAddOnRef); 13816e50923SOliver Tappe } 13916e50923SOliver Tappe 14016e50923SOliver Tappe 14116e50923SOliver Tappe void EditableCatalog::MakeEmpty() 14216e50923SOliver Tappe { 143*541ff51aSOliver Tappe if (fCatalogData == NULL) 144*541ff51aSOliver Tappe fCatalogData->MakeEmpty(); 14516e50923SOliver Tappe } 14616e50923SOliver Tappe 14716e50923SOliver Tappe 148*541ff51aSOliver Tappe BCatalogData* 149*541ff51aSOliver Tappe EditableCatalog::CatalogData() 15016e50923SOliver Tappe { 151*541ff51aSOliver Tappe return fCatalogData; 15216e50923SOliver Tappe } 15316e50923SOliver Tappe 15416e50923SOliver Tappe 15516e50923SOliver Tappe } // namespace BPrivate 156