* Use const references instead of pointers for the read from/write to
attribute/resource method in locale kit catalogs * Only load the embedded catalog if nothing else was found, so it can easily be overridden * Change the resource type to 'CADA' (CAtalog DAta) for embedded catalogs, and use a hash of the language code as the resource ID. This allows multiple languages to be stored in the same file and does not interfere with the user storing his own BMessages as resources. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43057 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -305,11 +305,15 @@ public:
|
||||
virtual status_t SetData(uint32 id, BMessage* msg);
|
||||
|
||||
virtual status_t ReadFromFile(const char* path = NULL);
|
||||
virtual status_t ReadFromAttribute(entry_ref* appOrAddOnRef);
|
||||
virtual status_t ReadFromResource(entry_ref* appOrAddOnRef);
|
||||
virtual status_t ReadFromAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
virtual status_t ReadFromResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
virtual status_t WriteToFile(const char* path = NULL);
|
||||
virtual status_t WriteToAttribute(entry_ref* appOrAddOnRef);
|
||||
virtual status_t WriteToResource(entry_ref* appOrAddOnRef);
|
||||
virtual status_t WriteToAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
virtual status_t WriteToResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
|
||||
virtual void MakeEmpty();
|
||||
virtual int32 CountItems() const;
|
||||
@@ -475,11 +479,15 @@ public:
|
||||
status_t SetData(uint32 id, BMessage* msg);
|
||||
|
||||
status_t ReadFromFile(const char* path = NULL);
|
||||
status_t ReadFromAttribute(entry_ref* appOrAddOnRef);
|
||||
status_t ReadFromResource(entry_ref* appOrAddOnRef);
|
||||
status_t ReadFromAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t ReadFromResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToFile(const char* path = NULL);
|
||||
status_t WriteToAttribute(entry_ref* appOrAddOnRef);
|
||||
status_t WriteToResource(entry_ref* appOrAddOnRef);
|
||||
status_t WriteToAttribute(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
status_t WriteToResource(
|
||||
const entry_ref& appOrAddOnRef);
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ class DefaultCatalog : public BHashMapCatalog {
|
||||
|
||||
// implementation for editor-interface:
|
||||
status_t ReadFromFile(const char *path = NULL);
|
||||
status_t ReadFromAttribute(entry_ref *appOrAddOnRef);
|
||||
status_t ReadFromResource(entry_ref *appOrAddOnRef);
|
||||
status_t ReadFromAttribute(const entry_ref &appOrAddOnRef);
|
||||
status_t ReadFromResource(const entry_ref &appOrAddOnRef);
|
||||
status_t WriteToFile(const char *path = NULL);
|
||||
status_t WriteToAttribute(entry_ref *appOrAddOnRef);
|
||||
status_t WriteToResource(entry_ref *appOrAddOnRef);
|
||||
status_t WriteToAttribute(const entry_ref &appOrAddOnRef);
|
||||
status_t WriteToResource(const entry_ref &appOrAddOnRef);
|
||||
|
||||
status_t SetRawString(const CatKey& key, const char *translated);
|
||||
void SetSignature(const entry_ref &catalogOwner);
|
||||
|
||||
@@ -90,15 +90,15 @@ class BHashMapCatalog: public BCatalogAddOn {
|
||||
// implementation for editor-interface
|
||||
virtual status_t ReadFromFile(const char *path = NULL)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
virtual status_t ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
virtual status_t ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
virtual status_t ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
virtual status_t ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
virtual status_t WriteToFile(const char *path = NULL)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
virtual status_t WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
virtual status_t WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
virtual status_t WriteToResource(entry_ref *appOrAddOnRef)
|
||||
virtual status_t WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{return B_NOT_SUPPORTED;}
|
||||
|
||||
void UpdateFingerprint();
|
||||
|
||||
@@ -139,7 +139,7 @@ main(int argc, char **argv)
|
||||
BEntry entry(outputFile.String());
|
||||
entry_ref eref;
|
||||
entry.GetRef(&eref);
|
||||
res = targetCatalog.WriteToAttribute(&eref);
|
||||
res = targetCatalog.WriteToAttribute(eref);
|
||||
if (res != B_OK) {
|
||||
fprintf(stderr,
|
||||
"couldn't write target-attribute to %s - error: %s\n",
|
||||
@@ -152,7 +152,7 @@ main(int argc, char **argv)
|
||||
BEntry entry(outputFile.String());
|
||||
entry_ref eref;
|
||||
entry.GetRef(&eref);
|
||||
res = targetCatalog.WriteToResource(&eref);
|
||||
res = targetCatalog.WriteToResource(eref);
|
||||
if (res != B_OK) {
|
||||
fprintf(stderr,
|
||||
"couldn't write target-resource to %s - error: %s\n",
|
||||
|
||||
@@ -211,14 +211,14 @@ BCatalogAddOn::ReadFromFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
@@ -232,14 +232,14 @@ BCatalogAddOn::WriteToFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
@@ -335,7 +335,7 @@ EditableCatalog::ReadFromFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
EditableCatalog::ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
if (!fCatalog)
|
||||
return B_NO_INIT;
|
||||
@@ -344,7 +344,7 @@ EditableCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
EditableCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
if (!fCatalog)
|
||||
return B_NO_INIT;
|
||||
@@ -362,7 +362,7 @@ EditableCatalog::WriteToFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
EditableCatalog::WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
if (!fCatalog)
|
||||
return B_NO_INIT;
|
||||
@@ -371,7 +371,7 @@ EditableCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
|
||||
|
||||
status_t
|
||||
EditableCatalog::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
EditableCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
if (!fCatalog)
|
||||
return B_NO_INIT;
|
||||
|
||||
@@ -70,27 +70,18 @@ DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *langua
|
||||
SetSignature(catalogOwner);
|
||||
status_t status;
|
||||
|
||||
app_info appInfo;
|
||||
be_app->GetAppInfo(&appInfo);
|
||||
|
||||
// give highest priority to catalog embedded as resource in application
|
||||
// executable:
|
||||
status = ReadFromResource(&appInfo.ref);
|
||||
|
||||
// search for catalog living in sub-folder of app's folder:
|
||||
if (status != B_OK) {
|
||||
node_ref nref;
|
||||
nref.device = appInfo.ref.device;
|
||||
nref.node = appInfo.ref.directory;
|
||||
BDirectory appDir(&nref);
|
||||
BString catalogName("locale/");
|
||||
catalogName << kCatFolder
|
||||
<< "/" << fSignature
|
||||
<< "/" << fLanguageName
|
||||
<< kCatExtension;
|
||||
BPath catalogPath(&appDir, catalogName.String());
|
||||
status = ReadFromFile(catalogPath.Path());
|
||||
}
|
||||
node_ref nref;
|
||||
nref.device = catalogOwner.device;
|
||||
nref.node = catalogOwner.directory;
|
||||
BDirectory appDir(&nref);
|
||||
BString catalogName("locale/");
|
||||
catalogName << kCatFolder
|
||||
<< "/" << fSignature
|
||||
<< "/" << fLanguageName
|
||||
<< kCatExtension;
|
||||
BPath catalogPath(&appDir, catalogName.String());
|
||||
status = ReadFromFile(catalogPath.Path());
|
||||
|
||||
if (status != B_OK) {
|
||||
// search in data folders
|
||||
@@ -116,6 +107,12 @@ DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *langua
|
||||
}
|
||||
}
|
||||
|
||||
if (status != B_OK) {
|
||||
// give lowest priority to catalog embedded as resource in application
|
||||
// executable, so they can be overridden easily.
|
||||
status = ReadFromResource(catalogOwner);
|
||||
}
|
||||
|
||||
fInitCheck = status;
|
||||
log_team(LOG_DEBUG,
|
||||
"trying to load default-catalog(sig=%s, lang=%s) results in %s",
|
||||
@@ -132,7 +129,7 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef)
|
||||
:
|
||||
BHashMapCatalog("", "", 0)
|
||||
{
|
||||
fInitCheck = ReadFromResource(appOrAddOnRef);
|
||||
fInitCheck = ReadFromResource(*appOrAddOnRef);
|
||||
log_team(LOG_DEBUG,
|
||||
"trying to load embedded catalog from resources results in %s",
|
||||
strerror(fInitCheck));
|
||||
@@ -255,22 +252,22 @@ DefaultCatalog::ReadFromFile(const char *path)
|
||||
* this method is not currently being used, but it may be useful in the future...
|
||||
*/
|
||||
status_t
|
||||
DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
BNode node;
|
||||
status_t res = node.SetTo(appOrAddOnRef);
|
||||
status_t res = node.SetTo(&appOrAddOnRef);
|
||||
if (res != B_OK) {
|
||||
log_team(LOG_ERR,
|
||||
"couldn't find app or add-on (dev=%lu, dir=%Lu, name=%s)",
|
||||
appOrAddOnRef->device, appOrAddOnRef->directory,
|
||||
appOrAddOnRef->name);
|
||||
appOrAddOnRef.device, appOrAddOnRef.directory,
|
||||
appOrAddOnRef.name);
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
log_team(LOG_DEBUG,
|
||||
"looking for embedded catalog-attribute in app/add-on"
|
||||
"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device,
|
||||
appOrAddOnRef->directory, appOrAddOnRef->name);
|
||||
"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef.device,
|
||||
appOrAddOnRef.directory, appOrAddOnRef.name);
|
||||
|
||||
attr_info attrInfo;
|
||||
res = node.GetAttrInfo(BLocaleRoster::kEmbeddedCatAttr, &attrInfo);
|
||||
@@ -305,22 +302,22 @@ DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
|
||||
|
||||
status_t
|
||||
DefaultCatalog::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
BFile file;
|
||||
status_t res = file.SetTo(appOrAddOnRef, B_READ_ONLY);
|
||||
status_t res = file.SetTo(&appOrAddOnRef, B_READ_ONLY);
|
||||
if (res != B_OK) {
|
||||
log_team(LOG_ERR,
|
||||
"couldn't find app or add-on (dev=%lu, dir=%Lu, name=%s)",
|
||||
appOrAddOnRef->device, appOrAddOnRef->directory,
|
||||
appOrAddOnRef->name);
|
||||
appOrAddOnRef.device, appOrAddOnRef.directory,
|
||||
appOrAddOnRef.name);
|
||||
return B_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
log_team(LOG_DEBUG,
|
||||
"looking for embedded catalog-resource in app/add-on"
|
||||
"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef->device,
|
||||
appOrAddOnRef->directory, appOrAddOnRef->name);
|
||||
"(dev=%lu, dir=%Lu, name=%s)", appOrAddOnRef.device,
|
||||
appOrAddOnRef.directory, appOrAddOnRef.name);
|
||||
|
||||
BResources rsrc;
|
||||
res = rsrc.SetTo(&file);
|
||||
@@ -329,9 +326,11 @@ DefaultCatalog::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
return res;
|
||||
}
|
||||
|
||||
int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);
|
||||
|
||||
size_t sz;
|
||||
const void *buf = rsrc.LoadResource(B_MESSAGE_TYPE,
|
||||
BLocaleRoster::kEmbeddedCatResId, &sz);
|
||||
const void *buf = rsrc.LoadResource('CADA',
|
||||
mangledLanguage, &sz);
|
||||
if (!buf) {
|
||||
log_team(LOG_DEBUG, "file has no catalog-resource");
|
||||
return B_NAME_NOT_FOUND;
|
||||
@@ -379,10 +378,10 @@ DefaultCatalog::WriteToFile(const char *path)
|
||||
* future...
|
||||
*/
|
||||
status_t
|
||||
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
BNode node;
|
||||
status_t res = node.SetTo(appOrAddOnRef);
|
||||
status_t res = node.SetTo(&appOrAddOnRef);
|
||||
if (res != B_OK)
|
||||
return res;
|
||||
|
||||
@@ -405,10 +404,10 @@ DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
|
||||
|
||||
status_t
|
||||
DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
BFile file;
|
||||
status_t res = file.SetTo(appOrAddOnRef, B_READ_WRITE);
|
||||
status_t res = file.SetTo(&appOrAddOnRef, B_READ_WRITE);
|
||||
if (res != B_OK)
|
||||
return res;
|
||||
|
||||
@@ -422,9 +421,12 @@ DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
// set a largish block-size in order to avoid reallocs
|
||||
res = Flatten(&mallocIO);
|
||||
|
||||
int mangledLanguage = CatKey::HashFun(fLanguageName.String(), 0);
|
||||
|
||||
if (res == B_OK) {
|
||||
res = rsrc.AddResource(B_MESSAGE_TYPE, BLocaleRoster::kEmbeddedCatResId,
|
||||
mallocIO.Buffer(), mallocIO.BufferLength(), "embedded catalog");
|
||||
res = rsrc.AddResource('CADA', mangledLanguage,
|
||||
mallocIO.Buffer(), mallocIO.BufferLength(),
|
||||
BString(fLanguageName) << " catalog");
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -206,14 +206,14 @@ BCatalogAddOn::ReadFromFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
@@ -227,14 +227,14 @@ BCatalogAddOn::WriteToFile(const char *path)
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BCatalogAddOn::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
BCatalogAddOn::WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return EOPNOTSUPP;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ DefaultCatalog::DefaultCatalog(entry_ref *appOrAddOnRef)
|
||||
:
|
||||
BHashMapCatalog("", "", 0)
|
||||
{
|
||||
fInitCheck = ReadFromResource(appOrAddOnRef);
|
||||
fInitCheck = ReadFromResource(*appOrAddOnRef);
|
||||
// fprintf(stderr,
|
||||
// "trying to load embedded catalog from resources results in %s",
|
||||
// strerror(fInitCheck));
|
||||
@@ -180,14 +180,14 @@ DefaultCatalog::ReadFromFile(const char *path)
|
||||
future...
|
||||
*/
|
||||
status_t
|
||||
DefaultCatalog::ReadFromAttribute(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::ReadFromAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DefaultCatalog::ReadFromResource(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
@@ -229,14 +229,14 @@ DefaultCatalog::WriteToFile(const char *path)
|
||||
future...
|
||||
*/
|
||||
status_t
|
||||
DefaultCatalog::WriteToAttribute(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::WriteToAttribute(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
DefaultCatalog::WriteToResource(entry_ref *appOrAddOnRef)
|
||||
DefaultCatalog::WriteToResource(const entry_ref &appOrAddOnRef)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ main(int argc, char **argv)
|
||||
BEntry entry(outputFile.String());
|
||||
entry_ref eref;
|
||||
entry.GetRef(&eref);
|
||||
res = targetCatImpl.WriteToAttribute(&eref);
|
||||
res = targetCatImpl.WriteToAttribute(eref);
|
||||
if (res != B_OK) {
|
||||
fprintf(stderr,
|
||||
"couldn't write target-attribute to %s - error: %s\n",
|
||||
@@ -136,7 +136,7 @@ main(int argc, char **argv)
|
||||
BEntry entry(outputFile.String());
|
||||
entry_ref eref;
|
||||
entry.GetRef(&eref);
|
||||
res = targetCatImpl.WriteToResource(&eref);
|
||||
res = targetCatImpl.WriteToResource(eref);
|
||||
if (res != B_OK) {
|
||||
fprintf(stderr,
|
||||
"couldn't write target-resource to %s - error: %s\n",
|
||||
|
||||
Reference in New Issue
Block a user