* Implement a function to get all the available languages for a given application
* use it in readonlybootprompt instead of previous workaround code. This makes the readonlybootprompt faster and lighter as it doesn't open and parse all the catalogs anymore, but only checks for their existence. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36276 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -61,6 +61,10 @@ class DefaultCatalog : public BHashMapCatalog {
|
|||||||
mutable BString fPath;
|
mutable BString fPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
default_catalog_get_available_languages(BMessage* availableLanguages,
|
||||||
|
const char* sigPattern, const char* langPattern = NULL,
|
||||||
|
int32 fingerprint = 0);
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
|||||||
@@ -417,9 +417,8 @@ instantiate_catalog(const char *signature, const char *language,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C"
|
extern "C" BCatalogAddOn *
|
||||||
BCatalogAddOn *create_catalog(const char *signature,
|
create_catalog(const char *signature, const char *language)
|
||||||
const char *language)
|
|
||||||
{
|
{
|
||||||
PlainTextCatalog *catalog
|
PlainTextCatalog *catalog
|
||||||
= new(std::nothrow) PlainTextCatalog("emptycat", signature, language);
|
= new(std::nothrow) PlainTextCatalog("emptycat", signature, language);
|
||||||
@@ -427,5 +426,15 @@ BCatalogAddOn *create_catalog(const char *signature,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
get_available_languages(BMessage* availableLanguages,
|
||||||
|
const char* sigPattern = NULL, const char* langPattern = NULL,
|
||||||
|
int32 fingerprint = 0)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8 gCatalogAddOnPriority = 99;
|
uint8 gCatalogAddOnPriority = 99;
|
||||||
// give low priority to this add on, we don't want it to be actually used
|
// give low priority to this add on, we don't want it to be actually used
|
||||||
|
|||||||
@@ -266,36 +266,33 @@ BootPromptWindow::_PopulateLanguages()
|
|||||||
firstPreferredLanguage = "en";
|
firstPreferredLanguage = "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Use this API instead once it's ready.
|
BMessage installedCatalogs;
|
||||||
// BMessage installedCatalogs;
|
be_locale_roster->GetInstalledCatalogs(&installedCatalogs,
|
||||||
// be_locale_roster->GetInstalledCatalogs(&installedCatalogs);
|
"x-vnd.Haiku-ReadOnlyBootPrompt");
|
||||||
// installedCatalogs.PrintToStream();
|
|
||||||
|
|
||||||
// Try to instantiate a BCatalog for each language, it will only work
|
// Try to instantiate a BCatalog for each language, it will only work
|
||||||
// for translations of this application. So the list of languages will be
|
// for translations of this application. So the list of languages will be
|
||||||
// limited to catalogs written for this application, which is on purpose!
|
// limited to catalogs written for this application, which is on purpose!
|
||||||
|
|
||||||
const char* languageString;
|
const char* languageString;
|
||||||
for (int32 i = 0;
|
for (int32 i = 0;
|
||||||
fInstalledLanguages.FindString("langs", i, &languageString) == B_OK;
|
installedCatalogs.FindString("langs", i, &languageString) == B_OK;
|
||||||
i++) {
|
i++) {
|
||||||
BCatalog catalog("x-vnd.Haiku-ReadOnlyBootPrompt", languageString);
|
BLanguage* language;
|
||||||
if (catalog.InitCheck() == B_OK) {
|
if (be_locale_roster->GetLanguage(&language,
|
||||||
BLanguage* language;
|
BString(languageString)) == B_OK) {
|
||||||
if (be_locale_roster->GetLanguage(&language,
|
BString name;
|
||||||
BString(languageString)) == B_OK) {
|
language->GetName(&name);
|
||||||
BString name;
|
LanguageItem* item = new LanguageItem(name.String(),
|
||||||
language->GetName(&name);
|
languageString);
|
||||||
LanguageItem* item = new LanguageItem(name.String(),
|
fLanguagesListView->AddItem(item);
|
||||||
languageString);
|
// Select this item if it is the first preferred language
|
||||||
fLanguagesListView->AddItem(item);
|
if (strcmp(firstPreferredLanguage, languageString) == 0) {
|
||||||
// Select this item if it is the first preferred language
|
fLanguagesListView->Select(
|
||||||
if (strcmp(firstPreferredLanguage, languageString) == 0) {
|
fLanguagesListView->CountItems() - 1);
|
||||||
fLanguagesListView->Select(
|
}
|
||||||
fLanguagesListView->CountItems() - 1);
|
} else
|
||||||
}
|
printf("failed to get BLanguage for %s\n", languageString);
|
||||||
} else
|
|
||||||
printf("failed to get BLanguage for %s\n", languageString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-enable sending the selection message.
|
// Re-enable sending the selection message.
|
||||||
|
|||||||
@@ -575,3 +575,64 @@ DefaultCatalog::Create(const char *signature, const char *language)
|
|||||||
}
|
}
|
||||||
return catalog;
|
return catalog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" status_t
|
||||||
|
default_catalog_get_available_languages(BMessage* availableLanguages,
|
||||||
|
const char* sigPattern, const char* langPattern = NULL,
|
||||||
|
int32 fingerprint = 0)
|
||||||
|
{
|
||||||
|
if (availableLanguages == NULL || sigPattern == NULL)
|
||||||
|
return B_BAD_DATA;
|
||||||
|
|
||||||
|
app_info appInfo;
|
||||||
|
be_app->GetAppInfo(&appInfo);
|
||||||
|
node_ref nref;
|
||||||
|
nref.device = appInfo.ref.device;
|
||||||
|
nref.node = appInfo.ref.directory;
|
||||||
|
BDirectory appDir(&nref);
|
||||||
|
BString catalogName("locale/");
|
||||||
|
catalogName << kCatFolder
|
||||||
|
<< "/" << sigPattern ;
|
||||||
|
BPath catalogPath(&appDir, catalogName.String());
|
||||||
|
BEntry file(catalogPath.Path());
|
||||||
|
BDirectory dir(&file);
|
||||||
|
|
||||||
|
char fileName[B_FILE_NAME_LENGTH];
|
||||||
|
while(dir.GetNextEntry(&file) == B_OK) {
|
||||||
|
file.GetName(fileName);
|
||||||
|
BString langName(fileName);
|
||||||
|
langName.Replace(kCatExtension,"",1);
|
||||||
|
availableLanguages->AddString("langs",langName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// search in data folders
|
||||||
|
|
||||||
|
directory_which which[] = {
|
||||||
|
B_USER_DATA_DIRECTORY,
|
||||||
|
B_COMMON_DATA_DIRECTORY,
|
||||||
|
B_SYSTEM_DATA_DIRECTORY
|
||||||
|
};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sizeof(which) / sizeof(which[0]); i++) {
|
||||||
|
BPath path;
|
||||||
|
if (find_directory(which[i], &path) == B_OK) {
|
||||||
|
catalogName = BString("locale/")
|
||||||
|
<< kCatFolder
|
||||||
|
<< "/" << sigPattern;
|
||||||
|
|
||||||
|
BPath catalogPath(path.Path(), catalogName.String());
|
||||||
|
BEntry file(catalogPath.Path());
|
||||||
|
BDirectory dir(&file);
|
||||||
|
|
||||||
|
char fileName[B_FILE_NAME_LENGTH];
|
||||||
|
while(dir.GetNextEntry(&file) == B_OK) {
|
||||||
|
file.GetName(fileName);
|
||||||
|
BString langName(fileName);
|
||||||
|
langName.Replace(kCatExtension,"",1);
|
||||||
|
availableLanguages->AddString("langs",langName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ typedef BCatalogAddOn *(*CreateCatalogFunc)(const char *name,
|
|||||||
|
|
||||||
typedef BCatalogAddOn *(*InstantiateEmbeddedCatalogFunc)(
|
typedef BCatalogAddOn *(*InstantiateEmbeddedCatalogFunc)(
|
||||||
entry_ref *appOrAddOnRef);
|
entry_ref *appOrAddOnRef);
|
||||||
|
|
||||||
|
typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
|
||||||
|
const char*, int32);
|
||||||
|
|
||||||
static BLocaleRoster gLocaleRoster;
|
static BLocaleRoster gLocaleRoster;
|
||||||
BLocaleRoster *be_locale_roster = &gLocaleRoster;
|
BLocaleRoster *be_locale_roster = &gLocaleRoster;
|
||||||
@@ -62,6 +65,7 @@ struct BCatalogAddOnInfo {
|
|||||||
InstantiateCatalogFunc fInstantiateFunc;
|
InstantiateCatalogFunc fInstantiateFunc;
|
||||||
InstantiateEmbeddedCatalogFunc fInstantiateEmbeddedFunc;
|
InstantiateEmbeddedCatalogFunc fInstantiateEmbeddedFunc;
|
||||||
CreateCatalogFunc fCreateFunc;
|
CreateCatalogFunc fCreateFunc;
|
||||||
|
GetAvailableLanguagesFunc fLanguagesFunc;
|
||||||
uint8 fPriority;
|
uint8 fPriority;
|
||||||
BList fLoadedCatalogs;
|
BList fLoadedCatalogs;
|
||||||
bool fIsEmbedded;
|
bool fIsEmbedded;
|
||||||
@@ -84,6 +88,7 @@ BCatalogAddOnInfo::BCatalogAddOnInfo(const BString& name, const BString& path,
|
|||||||
fInstantiateFunc(NULL),
|
fInstantiateFunc(NULL),
|
||||||
fInstantiateEmbeddedFunc(NULL),
|
fInstantiateEmbeddedFunc(NULL),
|
||||||
fCreateFunc(NULL),
|
fCreateFunc(NULL),
|
||||||
|
fLanguagesFunc(NULL),
|
||||||
fPriority(priority),
|
fPriority(priority),
|
||||||
fIsEmbedded(path.Length()==0)
|
fIsEmbedded(path.Length()==0)
|
||||||
{
|
{
|
||||||
@@ -118,6 +123,8 @@ BCatalogAddOnInfo::MakeSureItsLoaded()
|
|||||||
B_SYMBOL_TYPE_TEXT, (void **)&fInstantiateEmbeddedFunc);
|
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",
|
||||||
|
B_SYMBOL_TYPE_TEXT, (void **)&fLanguagesFunc);
|
||||||
log_team(LOG_DEBUG, "catalog-add-on %s has been loaded",
|
log_team(LOG_DEBUG, "catalog-add-on %s has been loaded",
|
||||||
fName.String());
|
fName.String());
|
||||||
} else {
|
} else {
|
||||||
@@ -125,6 +132,9 @@ BCatalogAddOnInfo::MakeSureItsLoaded()
|
|||||||
fName.String(), strerror(fAddOnImage));
|
fName.String(), strerror(fAddOnImage));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (fIsEmbedded) {
|
||||||
|
// The built-in catalog still has to provide this function
|
||||||
|
fLanguagesFunc = default_catalog_get_available_languages;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -139,6 +149,7 @@ BCatalogAddOnInfo::UnloadIfPossible()
|
|||||||
fInstantiateFunc = NULL;
|
fInstantiateFunc = NULL;
|
||||||
fInstantiateEmbeddedFunc = NULL;
|
fInstantiateEmbeddedFunc = NULL;
|
||||||
fCreateFunc = NULL;
|
fCreateFunc = 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",
|
||||||
fName.String());
|
fName.String());
|
||||||
}
|
}
|
||||||
@@ -533,6 +544,29 @@ BLocaleRoster::GetInstalledLanguages(BMessage *languages) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
BLocaleRoster::GetInstalledCatalogs(BMessage * languageList, const char* sigPattern,
|
||||||
|
const char* langPattern, int32 fingerprint) const
|
||||||
|
{
|
||||||
|
if (languageList == NULL)
|
||||||
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
|
int32 count = gRosterData.fCatalogAddOnInfos.CountItems();
|
||||||
|
for (int32 i = 0; i < count; ++i) {
|
||||||
|
BCatalogAddOnInfo *info
|
||||||
|
= (BCatalogAddOnInfo*)gRosterData.fCatalogAddOnInfos.ItemAt(i);
|
||||||
|
|
||||||
|
if (!info->MakeSureItsLoaded() || !info->fInstantiateFunc)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
info->fLanguagesFunc(languageList, sigPattern, langPattern,
|
||||||
|
fingerprint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* creates a new (empty) catalog of the given type (the request is dispatched
|
* creates a new (empty) catalog of the given type (the request is dispatched
|
||||||
* to the appropriate add-on).
|
* to the appropriate add-on).
|
||||||
|
|||||||
Reference in New Issue
Block a user