Rework the handling of catalog loading in locale kit :
Instead of computing the mime signature and giving this to the catalog system, give an entry_ref instead. The default catalog add-on can thus look at the right place when searching local catalogs (embedded as resources, or stored as files next to the executable. * This allows different versions of the same app to each have their own catalog set, * And also make the embedded/local catalog searching work for add-ons and libs, instead it only worked for apps because of a getAppInfo call. Fix cpufrequency to make use of it properly (that wouldhave worked without the change, but nowit's mandatory, since loading a catlog by mimesignature is not possible anymore). Should fix #8037. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43021 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -20,7 +20,7 @@ struct entry_ref;
|
|||||||
class BCatalog {
|
class BCatalog {
|
||||||
public:
|
public:
|
||||||
BCatalog();
|
BCatalog();
|
||||||
BCatalog(const char* signature,
|
BCatalog(const entry_ref& catalogOwner,
|
||||||
const char* language = NULL,
|
const char* language = NULL,
|
||||||
uint32 fingerprint = 0);
|
uint32 fingerprint = 0);
|
||||||
virtual ~BCatalog();
|
virtual ~BCatalog();
|
||||||
@@ -42,7 +42,7 @@ public:
|
|||||||
status_t GetLanguage(BString* language);
|
status_t GetLanguage(BString* language);
|
||||||
status_t GetFingerprint(uint32* fingerprint);
|
status_t GetFingerprint(uint32* fingerprint);
|
||||||
|
|
||||||
status_t SetCatalog(const char* signature,
|
status_t SetCatalog(const entry_ref& catalogOwner,
|
||||||
uint32 fingerprint);
|
uint32 fingerprint);
|
||||||
|
|
||||||
status_t InitCheck() const;
|
status_t InitCheck() const;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace BPrivate {
|
|||||||
*/
|
*/
|
||||||
class DefaultCatalog : public BHashMapCatalog {
|
class DefaultCatalog : public BHashMapCatalog {
|
||||||
public:
|
public:
|
||||||
DefaultCatalog(const char *signature, const char *language,
|
DefaultCatalog(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint);
|
uint32 fingerprint);
|
||||||
// constructor for normal use
|
// constructor for normal use
|
||||||
DefaultCatalog(entry_ref *appOrAddOnRef);
|
DefaultCatalog(entry_ref *appOrAddOnRef);
|
||||||
@@ -45,10 +45,10 @@ class DefaultCatalog : public BHashMapCatalog {
|
|||||||
status_t WriteToResource(entry_ref *appOrAddOnRef);
|
status_t WriteToResource(entry_ref *appOrAddOnRef);
|
||||||
|
|
||||||
status_t SetRawString(const CatKey& key, const char *translated);
|
status_t SetRawString(const CatKey& key, const char *translated);
|
||||||
|
void SetSignature(const entry_ref &catalogOwner);
|
||||||
|
|
||||||
static BCatalogAddOn *Instantiate(const char *signature,
|
static BCatalogAddOn *Instantiate(const entry_ref& catalogOwner,
|
||||||
const char *language, uint32 fingerprint);
|
const char *language, uint32 fingerprint);
|
||||||
static BCatalogAddOn *InstantiateEmbedded(entry_ref *appOrAddOnRef);
|
|
||||||
static BCatalogAddOn *Create(const char *signature,
|
static BCatalogAddOn *Create(const char *signature,
|
||||||
const char *language);
|
const char *language);
|
||||||
|
|
||||||
|
|||||||
@@ -48,10 +48,9 @@ public:
|
|||||||
|
|
||||||
status_t GetSystemCatalog(BCatalogAddOn** catalog) const;
|
status_t GetSystemCatalog(BCatalogAddOn** catalog) const;
|
||||||
|
|
||||||
BCatalogAddOn* LoadCatalog(const char* signature,
|
BCatalogAddOn* LoadCatalog(const entry_ref& catalogOwner,
|
||||||
const char* language = NULL,
|
const char* language = NULL,
|
||||||
int32 fingerprint = 0) const;
|
int32 fingerprint = 0) const;
|
||||||
BCatalogAddOn* LoadEmbeddedCatalog(entry_ref* appOrAddOnRef);
|
|
||||||
status_t UnloadCatalog(BCatalogAddOn* addOn);
|
status_t UnloadCatalog(BCatalogAddOn* addOn);
|
||||||
|
|
||||||
BCatalogAddOn* CreateCatalog(const char* type,
|
BCatalogAddOn* CreateCatalog(const char* type,
|
||||||
@@ -60,7 +59,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const char* name,
|
typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const entry_ref& catalogOwner,
|
||||||
const char* language, uint32 fingerprint);
|
const char* language, uint32 fingerprint);
|
||||||
|
|
||||||
typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
|
typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
|
||||||
@@ -77,7 +76,6 @@ typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
|
|||||||
*/
|
*/
|
||||||
struct CatalogAddOnInfo {
|
struct CatalogAddOnInfo {
|
||||||
InstantiateCatalogFunc fInstantiateFunc;
|
InstantiateCatalogFunc fInstantiateFunc;
|
||||||
InstantiateEmbeddedCatalogFunc fInstantiateEmbeddedFunc;
|
|
||||||
CreateCatalogFunc fCreateFunc;
|
CreateCatalogFunc fCreateFunc;
|
||||||
GetAvailableLanguagesFunc fLanguagesFunc;
|
GetAvailableLanguagesFunc fLanguagesFunc;
|
||||||
|
|
||||||
|
|||||||
@@ -10,3 +10,5 @@ resource app_version {
|
|||||||
short_info = "Walter",
|
short_info = "Walter",
|
||||||
long_info = "©2001-2011 Haiku Inc."
|
long_info = "©2001-2011 Haiku Inc."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
resource app_signature "application/x-vnd.Haiku-libbe" ;
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ BCatalog::BCatalog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BCatalog::BCatalog(const char *signature, const char *language,
|
BCatalog::BCatalog(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
{
|
{
|
||||||
fCatalog = MutableLocaleRoster::Default()->LoadCatalog(signature, language,
|
fCatalog = MutableLocaleRoster::Default()->LoadCatalog(catalogOwner, language,
|
||||||
fingerprint);
|
fingerprint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +98,12 @@ BCatalog::GetData(uint32 id, BMessage *msg)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BCatalog::SetCatalog(const char* signature, uint32 fingerprint)
|
BCatalog::SetCatalog(const entry_ref &catalogOwner, uint32 fingerprint)
|
||||||
{
|
{
|
||||||
// This is not thread safe. It is used only in ReadOnlyBootPrompt and should
|
// This is not thread safe. It is used only in ReadOnlyBootPrompt and should
|
||||||
// not do harm there, but not sure what to do about it…
|
// not do harm there, but not sure what to do about it…
|
||||||
MutableLocaleRoster::Default()->UnloadCatalog(fCatalog);
|
MutableLocaleRoster::Default()->UnloadCatalog(fCatalog);
|
||||||
fCatalog = MutableLocaleRoster::Default()->LoadCatalog(signature, NULL,
|
fCatalog = MutableLocaleRoster::Default()->LoadCatalog(catalogOwner, NULL,
|
||||||
fingerprint);
|
fingerprint);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <AppFileInfo.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -55,16 +56,47 @@ const uint8 DefaultCatalog::kDefaultCatalogAddOnPriority = 1;
|
|||||||
// give highest priority to our embedded catalog-add-on
|
// give highest priority to our embedded catalog-add-on
|
||||||
|
|
||||||
|
|
||||||
|
void DefaultCatalog::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) {
|
||||||
|
log_team(LOG_ERR, "File %s has no mimesignature, so it can't use"
|
||||||
|
" localization.", catalogOwner.name);
|
||||||
|
fSignature = "";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop supertype from mimetype (should be "application/"):
|
||||||
|
char* stripSignature = objectSignature;
|
||||||
|
while (*stripSignature != '/' && *stripSignature != '\0')
|
||||||
|
stripSignature ++;
|
||||||
|
|
||||||
|
if (*stripSignature == '\0')
|
||||||
|
stripSignature = objectSignature;
|
||||||
|
else
|
||||||
|
stripSignature ++;
|
||||||
|
|
||||||
|
log_team(LOG_DEBUG, "Image %s requested catalog with mimetype %s",
|
||||||
|
catalogOwner.name, stripSignature);
|
||||||
|
fSignature = stripSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Constructs a DefaultCatalog with given signature and language and reads
|
/*! Constructs a DefaultCatalog with given signature and language and reads
|
||||||
the catalog from disk.
|
the catalog from disk.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
:
|
:
|
||||||
BHashMapCatalog(signature, language, fingerprint)
|
BHashMapCatalog("", language, fingerprint)
|
||||||
{
|
{
|
||||||
|
// We created the catalog with an invalid signature, but we fix that now.
|
||||||
|
SetSignature(catalogOwner);
|
||||||
status_t status;
|
status_t status;
|
||||||
|
|
||||||
app_info appInfo;
|
app_info appInfo;
|
||||||
@@ -116,7 +148,7 @@ DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
|||||||
fInitCheck = status;
|
fInitCheck = status;
|
||||||
log_team(LOG_DEBUG,
|
log_team(LOG_DEBUG,
|
||||||
"trying to load default-catalog(sig=%s, lang=%s) results in %s",
|
"trying to load default-catalog(sig=%s, lang=%s) results in %s",
|
||||||
signature, language, strerror(fInitCheck));
|
fSignature.String(), language, strerror(fInitCheck));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -555,23 +587,11 @@ DefaultCatalog::Unflatten(BDataIO *dataIO)
|
|||||||
|
|
||||||
|
|
||||||
BCatalogAddOn *
|
BCatalogAddOn *
|
||||||
DefaultCatalog::Instantiate(const char *signature, const char *language,
|
DefaultCatalog::Instantiate(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
{
|
{
|
||||||
DefaultCatalog *catalog
|
DefaultCatalog *catalog
|
||||||
= new(std::nothrow) DefaultCatalog(signature, language, fingerprint);
|
= new(std::nothrow) DefaultCatalog(catalogOwner, language, fingerprint);
|
||||||
if (catalog && catalog->InitCheck() != B_OK) {
|
|
||||||
delete catalog;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return catalog;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BCatalogAddOn *
|
|
||||||
DefaultCatalog::InstantiateEmbedded(entry_ref *appOrAddOnRef)
|
|
||||||
{
|
|
||||||
DefaultCatalog *catalog = new(std::nothrow) DefaultCatalog(appOrAddOnRef);
|
|
||||||
if (catalog && catalog->InitCheck() != B_OK) {
|
if (catalog && catalog->InitCheck() != B_OK) {
|
||||||
delete catalog;
|
delete catalog;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <AppFileInfo.h>
|
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <Collator.h>
|
#include <Collator.h>
|
||||||
@@ -465,7 +464,7 @@ BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
|
|||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
BCatalog catalog(signature);
|
BCatalog catalog(ref);
|
||||||
const char* temp = catalog.GetString(string, context);
|
const char* temp = catalog.GetString(string, context);
|
||||||
|
|
||||||
if (temp == NULL)
|
if (temp == NULL)
|
||||||
@@ -505,28 +504,11 @@ BLocaleRoster::_GetCatalog(BCatalog* catalog, vint32* catalogInitStatus)
|
|||||||
catalog);
|
catalog);
|
||||||
return catalog;
|
return catalog;
|
||||||
}
|
}
|
||||||
// figure out mimetype from image
|
|
||||||
BFile objectFile(info.name, B_READ_ONLY);
|
|
||||||
BAppFileInfo objectInfo(&objectFile);
|
|
||||||
char objectSignature[B_MIME_TYPE_LENGTH];
|
|
||||||
if (objectInfo.GetSignature(objectSignature) != B_OK) {
|
|
||||||
log_team(LOG_ERR, "File %s has no mimesignature, so it can't use"
|
|
||||||
" localization.", info.name);
|
|
||||||
return catalog;
|
|
||||||
}
|
|
||||||
|
|
||||||
// drop supertype from mimetype (should be "application/"):
|
|
||||||
char* stripSignature = objectSignature;
|
|
||||||
while (*stripSignature != '/')
|
|
||||||
stripSignature ++;
|
|
||||||
stripSignature ++;
|
|
||||||
|
|
||||||
log_team(LOG_DEBUG,
|
|
||||||
"Image %s (address %x) requested catalog with mimetype %s",
|
|
||||||
info.name, catalog, stripSignature);
|
|
||||||
|
|
||||||
// load the catalog for this mimetype and return it to the app
|
// load the catalog for this mimetype and return it to the app
|
||||||
catalog->SetCatalog(stripSignature, 0);
|
entry_ref ref;
|
||||||
|
BEntry(info.name).GetRef(&ref);
|
||||||
|
catalog->SetCatalog(ref, 0);
|
||||||
*catalogInitStatus = true;
|
*catalogInitStatus = true;
|
||||||
|
|
||||||
return catalog;
|
return catalog;
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ CatalogAddOnInfo::CatalogAddOnInfo(const BString& name, const BString& path,
|
|||||||
uint8 priority)
|
uint8 priority)
|
||||||
:
|
:
|
||||||
fInstantiateFunc(NULL),
|
fInstantiateFunc(NULL),
|
||||||
fInstantiateEmbeddedFunc(NULL),
|
|
||||||
fCreateFunc(NULL),
|
fCreateFunc(NULL),
|
||||||
fLanguagesFunc(NULL),
|
fLanguagesFunc(NULL),
|
||||||
fName(name),
|
fName(name),
|
||||||
@@ -87,8 +86,6 @@ CatalogAddOnInfo::MakeSureItsLoaded()
|
|||||||
if (fAddOnImage >= B_OK) {
|
if (fAddOnImage >= B_OK) {
|
||||||
get_image_symbol(fAddOnImage, "instantiate_catalog",
|
get_image_symbol(fAddOnImage, "instantiate_catalog",
|
||||||
B_SYMBOL_TYPE_TEXT, (void**)&fInstantiateFunc);
|
B_SYMBOL_TYPE_TEXT, (void**)&fInstantiateFunc);
|
||||||
get_image_symbol(fAddOnImage, "instantiate_embedded_catalog",
|
|
||||||
B_SYMBOL_TYPE_TEXT, (void**)&fInstantiateEmbeddedFunc);
|
|
||||||
get_image_symbol(fAddOnImage, "create_catalog",
|
get_image_symbol(fAddOnImage, "create_catalog",
|
||||||
B_SYMBOL_TYPE_TEXT, (void**)&fCreateFunc);
|
B_SYMBOL_TYPE_TEXT, (void**)&fCreateFunc);
|
||||||
get_image_symbol(fAddOnImage, "get_available_languages",
|
get_image_symbol(fAddOnImage, "get_available_languages",
|
||||||
@@ -115,7 +112,6 @@ CatalogAddOnInfo::UnloadIfPossible()
|
|||||||
unload_add_on(fAddOnImage);
|
unload_add_on(fAddOnImage);
|
||||||
fAddOnImage = B_NO_INIT;
|
fAddOnImage = B_NO_INIT;
|
||||||
fInstantiateFunc = NULL;
|
fInstantiateFunc = NULL;
|
||||||
fInstantiateEmbeddedFunc = NULL;
|
|
||||||
fCreateFunc = NULL;
|
fCreateFunc = NULL;
|
||||||
fLanguagesFunc = NULL;
|
fLanguagesFunc = NULL;
|
||||||
// log_team(LOG_DEBUG, "catalog-add-on %s has been unloaded",
|
// log_team(LOG_DEBUG, "catalog-add-on %s has been unloaded",
|
||||||
@@ -360,8 +356,6 @@ RosterData::_InitializeCatalogAddOns()
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
|
defaultCatalogAddOnInfo->fInstantiateFunc = DefaultCatalog::Instantiate;
|
||||||
defaultCatalogAddOnInfo->fInstantiateEmbeddedFunc
|
|
||||||
= DefaultCatalog::InstantiateEmbedded;
|
|
||||||
defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
|
defaultCatalogAddOnInfo->fCreateFunc = DefaultCatalog::Create;
|
||||||
fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);
|
fCatalogAddOnInfos.AddItem((void*)defaultCatalogAddOnInfo);
|
||||||
|
|
||||||
@@ -794,7 +788,10 @@ MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const
|
|||||||
{
|
{
|
||||||
if (!catalog)
|
if (!catalog)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
*catalog = LoadCatalog("system");
|
// get libbe entry_ref
|
||||||
|
entry_ref ref;
|
||||||
|
BEntry("/boot/system/lib/libbe.so").GetRef(&ref);
|
||||||
|
*catalog = LoadCatalog(ref);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -849,12 +846,9 @@ MutableLocaleRoster::CreateCatalog(const char* type, const char* signature,
|
|||||||
* NULL is returned if no matching catalog could be found.
|
* NULL is returned if no matching catalog could be found.
|
||||||
*/
|
*/
|
||||||
BCatalogAddOn*
|
BCatalogAddOn*
|
||||||
MutableLocaleRoster::LoadCatalog(const char* signature, const char* language,
|
MutableLocaleRoster::LoadCatalog(const entry_ref& catalogOwner, const char* language,
|
||||||
int32 fingerprint) const
|
int32 fingerprint) const
|
||||||
{
|
{
|
||||||
if (!signature)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BAutolock lock(RosterData::Default()->fLock);
|
BAutolock lock(RosterData::Default()->fLock);
|
||||||
if (!lock.IsLocked())
|
if (!lock.IsLocked())
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -877,7 +871,7 @@ MutableLocaleRoster::LoadCatalog(const char* signature, const char* language,
|
|||||||
BCatalogAddOn* catalog = NULL;
|
BCatalogAddOn* catalog = NULL;
|
||||||
const char* lang;
|
const char* lang;
|
||||||
for (int32 l=0; languages.FindString("language", l, &lang)==B_OK; ++l) {
|
for (int32 l=0; languages.FindString("language", l, &lang)==B_OK; ++l) {
|
||||||
catalog = info->fInstantiateFunc(signature, lang, fingerprint);
|
catalog = info->fInstantiateFunc(catalogOwner, lang, fingerprint);
|
||||||
if (catalog)
|
if (catalog)
|
||||||
info->fLoadedCatalogs.AddItem(catalog);
|
info->fLoadedCatalogs.AddItem(catalog);
|
||||||
// Chain-load catalogs for languages that depend on
|
// Chain-load catalogs for languages that depend on
|
||||||
@@ -889,12 +883,12 @@ MutableLocaleRoster::LoadCatalog(const char* signature, const char* language,
|
|||||||
int32 pos;
|
int32 pos;
|
||||||
BString langName(lang);
|
BString langName(lang);
|
||||||
BCatalogAddOn* currCatalog = catalog;
|
BCatalogAddOn* currCatalog = catalog;
|
||||||
BCatalogAddOn* nextCatalog;
|
BCatalogAddOn* nextCatalog = NULL;
|
||||||
while ((pos = langName.FindLast('_')) >= 0) {
|
while ((pos = langName.FindLast('_')) >= 0) {
|
||||||
// language is based on parent, so we load that, too:
|
// language is based on parent, so we load that, too:
|
||||||
// (even if the parent catalog was not found)
|
// (even if the parent catalog was not found)
|
||||||
langName.Truncate(pos);
|
langName.Truncate(pos);
|
||||||
nextCatalog = info->fInstantiateFunc(signature,
|
nextCatalog = info->fInstantiateFunc(catalogOwner,
|
||||||
langName.String(), fingerprint);
|
langName.String(), fingerprint);
|
||||||
if (nextCatalog) {
|
if (nextCatalog) {
|
||||||
info->fLoadedCatalogs.AddItem(nextCatalog);
|
info->fLoadedCatalogs.AddItem(nextCatalog);
|
||||||
@@ -915,43 +909,6 @@ MutableLocaleRoster::LoadCatalog(const char* signature, const char* language,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Loads an embedded catalog from the given entry-ref (which is usually an
|
|
||||||
* app- or add-on-file. The request to load the catalog is dispatched to all
|
|
||||||
* add-ons in turn, until an add-on reports success.
|
|
||||||
* NULL is returned if no embedded catalog could be found.
|
|
||||||
*/
|
|
||||||
BCatalogAddOn*
|
|
||||||
MutableLocaleRoster::LoadEmbeddedCatalog(entry_ref* appOrAddOnRef)
|
|
||||||
{
|
|
||||||
if (!appOrAddOnRef)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
BAutolock lock(RosterData::Default()->fLock);
|
|
||||||
if (!lock.IsLocked())
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
int32 count = RosterData::Default()->fCatalogAddOnInfos.CountItems();
|
|
||||||
for (int32 i = 0; i < count; ++i) {
|
|
||||||
CatalogAddOnInfo* info = (CatalogAddOnInfo*)
|
|
||||||
RosterData::Default()->fCatalogAddOnInfos.ItemAt(i);
|
|
||||||
|
|
||||||
if (!info->MakeSureItsLoaded() || !info->fInstantiateEmbeddedFunc)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
BCatalogAddOn* catalog = NULL;
|
|
||||||
catalog = info->fInstantiateEmbeddedFunc(appOrAddOnRef);
|
|
||||||
if (catalog) {
|
|
||||||
info->fLoadedCatalogs.AddItem(catalog);
|
|
||||||
return catalog;
|
|
||||||
}
|
|
||||||
info->UnloadIfPossible();
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* unloads the given catalog (or rather: catalog-chain).
|
* unloads the given catalog (or rather: catalog-chain).
|
||||||
* Every single catalog of the chain will be deleted automatically.
|
* Every single catalog of the chain will be deleted automatically.
|
||||||
|
|||||||
@@ -217,22 +217,20 @@ FrequencyMenu::FrequencyMenu(BMenu* menu, BHandler* target,
|
|||||||
fStorage(storage),
|
fStorage(storage),
|
||||||
fInterface(interface)
|
fInterface(interface)
|
||||||
{
|
{
|
||||||
BCatalog catalog("x-vnd.Haiku-CPUFrequencyPref");
|
|
||||||
fDynamicPerformance = new BMenuItem(
|
fDynamicPerformance = new BMenuItem(
|
||||||
catalog.GetString("Dynamic performance", B_TRANSLATE_CONTEXT),
|
B_TRANSLATE("Dynamic performance"),
|
||||||
new BMessage(kMsgPolicyDynamic));
|
new BMessage(kMsgPolicyDynamic));
|
||||||
fHighPerformance = new BMenuItem(
|
fHighPerformance = new BMenuItem(
|
||||||
catalog.GetString("High performance", B_TRANSLATE_CONTEXT),
|
B_TRANSLATE("High performance"),
|
||||||
new BMessage(kMsgPolicyPerformance));
|
new BMessage(kMsgPolicyPerformance));
|
||||||
fLowEnergie = new BMenuItem(catalog.GetString("Low energy",
|
fLowEnergie = new BMenuItem(B_TRANSLATE("Low energy"),
|
||||||
B_TRANSLATE_CONTEXT), new BMessage(kMsgPolicyLowEnergy));
|
new BMessage(kMsgPolicyLowEnergy));
|
||||||
|
|
||||||
menu->AddItem(fDynamicPerformance);
|
menu->AddItem(fDynamicPerformance);
|
||||||
menu->AddItem(fHighPerformance);
|
menu->AddItem(fHighPerformance);
|
||||||
menu->AddItem(fLowEnergie);
|
menu->AddItem(fLowEnergie);
|
||||||
|
|
||||||
fCustomStateMenu = new BMenu(catalog.GetString("Set state",
|
fCustomStateMenu = new BMenu(B_TRANSLATE("Set state"));
|
||||||
B_TRANSLATE_CONTEXT));
|
|
||||||
|
|
||||||
StateList* stateList = fInterface->GetCpuFrequencyStates();
|
StateList* stateList = fInterface->GetCpuFrequencyStates();
|
||||||
for (int i = 0; i < stateList->CountItems(); i++) {
|
for (int i = 0; i < stateList->CountItems(); i++) {
|
||||||
@@ -376,8 +374,7 @@ StatusView::StatusView(BRect frame, bool inDeskbar,
|
|||||||
B_WILL_DRAW | B_FRAME_EVENTS),
|
B_WILL_DRAW | B_FRAME_EVENTS),
|
||||||
fInDeskbar(inDeskbar),
|
fInDeskbar(inDeskbar),
|
||||||
fCurrentFrequency(NULL),
|
fCurrentFrequency(NULL),
|
||||||
fDragger(NULL),
|
fDragger(NULL)
|
||||||
fCatalog("x-vnd.Haiku-CPUFrequencyPref")
|
|
||||||
{
|
{
|
||||||
if (!inDeskbar) {
|
if (!inDeskbar) {
|
||||||
// we were obviously added to a standard window - let's add a dragger
|
// we were obviously added to a standard window - let's add a dragger
|
||||||
@@ -406,8 +403,7 @@ StatusView::StatusView(BMessage* archive)
|
|||||||
: BView(archive),
|
: BView(archive),
|
||||||
fInDeskbar(false),
|
fInDeskbar(false),
|
||||||
fCurrentFrequency(NULL),
|
fCurrentFrequency(NULL),
|
||||||
fDragger(NULL),
|
fDragger(NULL)
|
||||||
fCatalog("x-vnd.Haiku-CPUFrequencyPref")
|
|
||||||
{
|
{
|
||||||
app_info info;
|
app_info info;
|
||||||
if (be_app->GetAppInfo(&info) == B_OK
|
if (be_app->GetAppInfo(&info) == B_OK
|
||||||
@@ -431,10 +427,10 @@ StatusView::~StatusView()
|
|||||||
void
|
void
|
||||||
StatusView::_AboutRequested()
|
StatusView::_AboutRequested()
|
||||||
{
|
{
|
||||||
BAlert *alert = new BAlert("about", fCatalog.GetString("CPUFrequency\n"
|
BAlert *alert = new BAlert("about", B_TRANSLATE("CPUFrequency\n"
|
||||||
"\twritten by Clemens Zeidler\n"
|
"\twritten by Clemens Zeidler\n"
|
||||||
"\tCopyright 2009, Haiku, Inc.\n", B_TRANSLATE_CONTEXT),
|
"\tCopyright 2009, Haiku, Inc.\n"),
|
||||||
fCatalog.GetString("Ok", B_TRANSLATE_CONTEXT));
|
B_TRANSLATE("Ok"));
|
||||||
BTextView *view = alert->TextView();
|
BTextView *view = alert->TextView();
|
||||||
BFont font;
|
BFont font;
|
||||||
|
|
||||||
@@ -514,15 +510,15 @@ StatusView::AttachedToWindow()
|
|||||||
fPreferencesMenu->SetFont(be_plain_font);
|
fPreferencesMenu->SetFont(be_plain_font);
|
||||||
|
|
||||||
fPreferencesMenu->AddSeparatorItem();
|
fPreferencesMenu->AddSeparatorItem();
|
||||||
fOpenPrefItem = new BMenuItem(fCatalog.GetString(
|
fOpenPrefItem = new BMenuItem(B_TRANSLATE(
|
||||||
"Open Speedstep preferences" B_UTF8_ELLIPSIS, B_TRANSLATE_CONTEXT),
|
"Open Speedstep preferences" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(kMsgOpenSSPreferences));
|
new BMessage(kMsgOpenSSPreferences));
|
||||||
fPreferencesMenu->AddItem(fOpenPrefItem);
|
fPreferencesMenu->AddItem(fOpenPrefItem);
|
||||||
fOpenPrefItem->SetTarget(this);
|
fOpenPrefItem->SetTarget(this);
|
||||||
|
|
||||||
if (fInDeskbar) {
|
if (fInDeskbar) {
|
||||||
fQuitItem= new BMenuItem(fCatalog.GetString("Quit",
|
fQuitItem= new BMenuItem(B_TRANSLATE("Quit"),
|
||||||
B_TRANSLATE_CONTEXT), new BMessage(B_QUIT_REQUESTED));
|
new BMessage(B_QUIT_REQUESTED));
|
||||||
fPreferencesMenu->AddItem(fQuitItem);
|
fPreferencesMenu->AddItem(fQuitItem);
|
||||||
fQuitItem->SetTarget(this);
|
fQuitItem->SetTarget(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,8 +130,6 @@ private:
|
|||||||
|
|
||||||
BString fFreqString;
|
BString fFreqString;
|
||||||
BDragger* fDragger;
|
BDragger* fDragger;
|
||||||
|
|
||||||
BCatalog fCatalog;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // STATUS_VIEW_H
|
#endif // STATUS_VIEW_H
|
||||||
|
|||||||
@@ -31,10 +31,11 @@ BCatalog::BCatalog()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BCatalog::BCatalog(const char *signature, const char *language,
|
BCatalog::BCatalog(const entry_ref& catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
{
|
{
|
||||||
//fCatalog = be_locale_roster->LoadCatalog(signature, language, fingerprint);
|
// Unsupported - the build tools can't (and don't need to) load anything
|
||||||
|
// this way.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <AppFileInfo.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <DataIO.h>
|
#include <DataIO.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
@@ -55,20 +56,45 @@ static int16 kCatArchiveVersion = 1;
|
|||||||
// version of the catalog archive structure, bump this if you change it!
|
// version of the catalog archive structure, bump this if you change it!
|
||||||
|
|
||||||
|
|
||||||
|
const char* getCatalogSignature(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) {
|
||||||
|
log_team(LOG_ERR, "File %s has no mimesignature, so it can't use"
|
||||||
|
" localization.", catalogOwner.name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// drop supertype from mimetype (should be "application/"):
|
||||||
|
char* stripSignature = objectSignature;
|
||||||
|
while (*stripSignature != '/')
|
||||||
|
stripSignature ++;
|
||||||
|
stripSignature ++;
|
||||||
|
|
||||||
|
log_team(LOG_DEBUG, "Image %s requested catalog with mimetype %s",
|
||||||
|
catalogOwner.name, stripSignature);
|
||||||
|
|
||||||
|
return stripSignature;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! Constructs a DefaultCatalog with given signature and language and reads
|
/*! Constructs a DefaultCatalog with given signature and language and reads
|
||||||
the catalog from disk.
|
the catalog from disk.
|
||||||
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.
|
||||||
*/
|
*/
|
||||||
DefaultCatalog::DefaultCatalog(const char *signature, const char *language,
|
DefaultCatalog::DefaultCatalog(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
:
|
:
|
||||||
BHashMapCatalog(signature, language, fingerprint)
|
BHashMapCatalog(getCatalogSignature(catalogOwner), language, fingerprint)
|
||||||
{
|
{
|
||||||
fInitCheck = B_NOT_SUPPORTED;
|
fInitCheck = B_NOT_SUPPORTED;
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"trying to load default-catalog(sig=%s, lang=%s) results in %s",
|
"trying to load default-catalog(sig=%s, lang=%s) results in %s",
|
||||||
signature, language, strerror(fInitCheck));
|
getCatalogSignature(catalogOwner), language, strerror(fInitCheck));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -389,23 +415,11 @@ DefaultCatalog::Unflatten(BDataIO *dataIO)
|
|||||||
|
|
||||||
|
|
||||||
BCatalogAddOn *
|
BCatalogAddOn *
|
||||||
DefaultCatalog::Instantiate(const char *signature, const char *language,
|
DefaultCatalog::Instantiate(const entry_ref &catalogOwner, const char *language,
|
||||||
uint32 fingerprint)
|
uint32 fingerprint)
|
||||||
{
|
{
|
||||||
DefaultCatalog *catalog
|
DefaultCatalog *catalog
|
||||||
= new(std::nothrow) DefaultCatalog(signature, language, fingerprint);
|
= new(std::nothrow) DefaultCatalog(catalogOwner, language, fingerprint);
|
||||||
if (catalog && catalog->InitCheck() != B_OK) {
|
|
||||||
delete catalog;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return catalog;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BCatalogAddOn *
|
|
||||||
DefaultCatalog::InstantiateEmbedded(entry_ref *appOrAddOnRef)
|
|
||||||
{
|
|
||||||
DefaultCatalog *catalog = new(std::nothrow) DefaultCatalog(appOrAddOnRef);
|
|
||||||
if (catalog && catalog->InitCheck() != B_OK) {
|
if (catalog && catalog->InitCheck() != B_OK) {
|
||||||
delete catalog;
|
delete catalog;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user