From 4bb4130ff2b8e2c9c93ef4ce2ee46d644a9bd5e9 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Sat, 17 Jan 2015 17:02:40 +0100 Subject: [PATCH] Fix instanciate_catalog prototype The prototype didn't match what the Locale Kit actually uses, making the plaintext catalog (and any other add-on) unusable. --- headers/os/locale/CatalogData.h | 4 +- headers/private/locale/PlainTextCatalog.h | 8 ++-- .../locale/catalogs/plaintext/Catalog.cpp | 42 ++++++++++++++++--- 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/headers/os/locale/CatalogData.h b/headers/os/locale/CatalogData.h index 5c6d91ba1d..f371f87b04 100644 --- a/headers/os/locale/CatalogData.h +++ b/headers/os/locale/CatalogData.h @@ -99,8 +99,8 @@ BCatalogData::Next() // // 1. the function that instantiates a catalog for this add-on-type extern "C" -BCatalogData* instantiate_catalog(const char* signature, const char* language, - uint32 fingerprint); +BCatalogData* instantiate_catalog(const entry_ref& signature, + const char* language, uint32 fingerprint); // 2. the function that creates an empty catalog for this add-on-type extern "C" diff --git a/headers/private/locale/PlainTextCatalog.h b/headers/private/locale/PlainTextCatalog.h index b31031b120..cbfcb8b582 100644 --- a/headers/private/locale/PlainTextCatalog.h +++ b/headers/private/locale/PlainTextCatalog.h @@ -18,22 +18,22 @@ namespace BPrivate { class PlainTextCatalog : public HashMapCatalog { public: - PlainTextCatalog(const char *signature, const char *language, + PlainTextCatalog(const entry_ref& owner, const char *language, uint32 fingerprint); // constructor for normal use - PlainTextCatalog(entry_ref *appOrAddOnRef); - // constructor for embedded catalog PlainTextCatalog(const char *path, const char *signature, const char *language); // constructor for editor-app ~PlainTextCatalog(); + void SetSignature(const entry_ref &catalogOwner); + // implementation for editor-interface: status_t ReadFromFile(const char *path = NULL); status_t WriteToFile(const char *path = NULL); - static BCatalogData *Instantiate(const char *signature, + static BCatalogData *Instantiate(const entry_ref &signature, const char *language, uint32 fingerprint); static const char *kCatMimeType; diff --git a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp index aefe570d1d..d79459597a 100644 --- a/src/add-ons/locale/catalogs/plaintext/Catalog.cpp +++ b/src/add-ons/locale/catalogs/plaintext/Catalog.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -74,11 +75,14 @@ escapeQuotedChars(BString& stringToEscape) * InitCheck() will be B_OK if catalog could be loaded successfully, it will * give an appropriate error-code otherwise. */ -PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language, +PlainTextCatalog::PlainTextCatalog(const entry_ref &owner, const char *language, uint32 fingerprint) : - HashMapCatalog(signature, language, fingerprint) + HashMapCatalog("", language, fingerprint) { + // We created the catalog with an invalid signature, but we fix that now. + SetSignature(owner); + // give highest priority to catalog living in sub-folder of app's folder: app_info appInfo; be_app->GetAppInfo(&appInfo); @@ -146,6 +150,32 @@ PlainTextCatalog::~PlainTextCatalog() } +void +PlainTextCatalog::SetSignature(const entry_ref &catalogOwner) +{ + // figure out mimetype from image + BFile objectFile(&catalogOwner, B_READ_ONLY); + BAppFileInfo objectInfo(&objectFile); + char objectSignature[B_MIME_TYPE_LENGTH]; + if (objectInfo.GetSignature(objectSignature) != B_OK) { + fSignature = ""; + return; + } + + // drop supertype from mimetype (should be "application/"): + char* stripSignature = objectSignature; + while (*stripSignature != '/' && *stripSignature != '\0') + stripSignature ++; + + if (*stripSignature == '\0') + stripSignature = objectSignature; + else + stripSignature ++; + + fSignature = stripSignature; +} + + status_t PlainTextCatalog::ReadFromFile(const char *path) { @@ -353,11 +383,11 @@ PlainTextCatalog::UpdateAttributes(const char* path) BCatalogData * -PlainTextCatalog::Instantiate(const char *signature, const char *language, +PlainTextCatalog::Instantiate(const entry_ref& owner, const char *language, uint32 fingerprint) { PlainTextCatalog *catalog - = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); + = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint); if (catalog && catalog->InitCheck() != B_OK) { delete catalog; return NULL; @@ -367,11 +397,11 @@ PlainTextCatalog::Instantiate(const char *signature, const char *language, extern "C" BCatalogData * -instantiate_catalog(const char *signature, const char *language, +instantiate_catalog(const entry_ref& owner, const char *language, uint32 fingerprint) { PlainTextCatalog *catalog - = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); + = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint); if (catalog && catalog->InitCheck() != B_OK) { delete catalog; return NULL;