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.
This commit is contained in:
Adrien Destugues
2015-01-17 17:02:40 +01:00
parent 412f030b0f
commit 4bb4130ff2
3 changed files with 42 additions and 12 deletions
+2 -2
View File
@@ -99,8 +99,8 @@ BCatalogData::Next()
// //
// 1. the function that instantiates a catalog for this add-on-type // 1. the function that instantiates a catalog for this add-on-type
extern "C" extern "C"
BCatalogData* instantiate_catalog(const char* signature, const char* language, BCatalogData* instantiate_catalog(const entry_ref& signature,
uint32 fingerprint); const char* language, uint32 fingerprint);
// 2. the function that creates an empty catalog for this add-on-type // 2. the function that creates an empty catalog for this add-on-type
extern "C" extern "C"
+4 -4
View File
@@ -18,22 +18,22 @@ namespace BPrivate {
class PlainTextCatalog : public HashMapCatalog { class PlainTextCatalog : public HashMapCatalog {
public: public:
PlainTextCatalog(const char *signature, const char *language, PlainTextCatalog(const entry_ref& owner, const char *language,
uint32 fingerprint); uint32 fingerprint);
// constructor for normal use // constructor for normal use
PlainTextCatalog(entry_ref *appOrAddOnRef);
// constructor for embedded catalog
PlainTextCatalog(const char *path, const char *signature, PlainTextCatalog(const char *path, const char *signature,
const char *language); const char *language);
// constructor for editor-app // constructor for editor-app
~PlainTextCatalog(); ~PlainTextCatalog();
void SetSignature(const entry_ref &catalogOwner);
// implementation for editor-interface: // implementation for editor-interface:
status_t ReadFromFile(const char *path = NULL); status_t ReadFromFile(const char *path = NULL);
status_t WriteToFile(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); const char *language, uint32 fingerprint);
static const char *kCatMimeType; static const char *kCatMimeType;
@@ -14,6 +14,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <AppFileInfo.h>
#include <Application.h> #include <Application.h>
#include <Directory.h> #include <Directory.h>
#include <File.h> #include <File.h>
@@ -74,11 +75,14 @@ escapeQuotedChars(BString& stringToEscape)
* InitCheck() will be B_OK if catalog could be loaded successfully, it will * InitCheck() will be B_OK if catalog could be loaded successfully, it will
* give an appropriate error-code otherwise. * 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) 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: // give highest priority to catalog living in sub-folder of app's folder:
app_info appInfo; app_info appInfo;
be_app->GetAppInfo(&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 status_t
PlainTextCatalog::ReadFromFile(const char *path) PlainTextCatalog::ReadFromFile(const char *path)
{ {
@@ -353,11 +383,11 @@ PlainTextCatalog::UpdateAttributes(const char* path)
BCatalogData * BCatalogData *
PlainTextCatalog::Instantiate(const char *signature, const char *language, PlainTextCatalog::Instantiate(const entry_ref& owner, const char *language,
uint32 fingerprint) uint32 fingerprint)
{ {
PlainTextCatalog *catalog PlainTextCatalog *catalog
= new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint);
if (catalog && catalog->InitCheck() != B_OK) { if (catalog && catalog->InitCheck() != B_OK) {
delete catalog; delete catalog;
return NULL; return NULL;
@@ -367,11 +397,11 @@ PlainTextCatalog::Instantiate(const char *signature, const char *language,
extern "C" BCatalogData * extern "C" BCatalogData *
instantiate_catalog(const char *signature, const char *language, instantiate_catalog(const entry_ref& owner, const char *language,
uint32 fingerprint) uint32 fingerprint)
{ {
PlainTextCatalog *catalog PlainTextCatalog *catalog
= new(std::nothrow) PlainTextCatalog(signature, language, fingerprint); = new(std::nothrow) PlainTextCatalog(owner, language, fingerprint);
if (catalog && catalog->InitCheck() != B_OK) { if (catalog && catalog->InitCheck() != B_OK) {
delete catalog; delete catalog;
return NULL; return NULL;