Author: axeld Date: 2011-07-10 18:21:09 +0200 (Sun, 10 Jul 2011) New Revision: 42403 Changeset: https://dev.haiku-os.org/changeset/42403 Ticket: https://dev.haiku-os.org/ticket/7614 Modified: haiku/trunk/src/kits/locale/Jamfile haiku/trunk/src/kits/locale/LanguageFlags.rdef haiku/trunk/src/kits/locale/LocaleRoster.cpp Log: * Moved the resource loading into a separate private function load_resources_if_needed(). * Renamed the Esperanto flag resource to "eo" since it is a language; language specific flags are now found by their two letter language code. * This closes ticket #7614, as the Esperanto flag is now found and displayed by ReadOnlyBootPrompt. * Rearranged code in BLocaleRoster::GetFlagIconForCountry() to make it more readable. Modified: haiku/trunk/src/kits/locale/Jamfile =================================================================== --- haiku/trunk/src/kits/locale/Jamfile 2011-07-10 15:18:52 UTC (rev 42402) +++ haiku/trunk/src/kits/locale/Jamfile 2011-07-10 16:21:09 UTC (rev 42403) @@ -52,7 +52,7 @@ # Dependency needed to trigger downloading/unzipping the package before # compiling the files. -AddResources liblocale.so : CountryFlags.rdef ; +AddResources liblocale.so : CountryFlags.rdef LanguageFlags.rdef ; SharedLibrary liblocale.so : $(sources) @@ -72,7 +72,7 @@ SEARCH on [ FGristFiles Menu.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; SEARCH on [ FGristFiles PrintJob.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; SEARCH on [ FGristFiles ZombieReplicantView.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; - + DoCatalogs liblocale.so : system : Modified: haiku/trunk/src/kits/locale/LanguageFlags.rdef =================================================================== --- haiku/trunk/src/kits/locale/LanguageFlags.rdef 2011-07-10 15:18:52 UTC (rev 42402) +++ haiku/trunk/src/kits/locale/LanguageFlags.rdef 2011-07-10 16:21:09 UTC (rev 42403) @@ -1,5 +1,5 @@ // Flag data for Esperanto -resource(0,"EO") #'VICN' array { +resource(5000, "eo") #'VICN' array { $"6E6369660305FF057E03009900020A0AC46BC0C0C35DC3FF50C1FEC8E2C3FFC7" $"D4C0C0CA97BEBFC72DBEBF50BB7FC512BEBFC1A8BEBF0A0421295F295F572157" $"040A02010102401084000000000000401642C01084C0C8590A000101023D18C6" Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp =================================================================== --- haiku/trunk/src/kits/locale/LocaleRoster.cpp 2011-07-10 15:18:52 UTC (rev 42402) +++ haiku/trunk/src/kits/locale/LocaleRoster.cpp 2011-07-10 16:21:09 UTC (rev 42403) @@ -66,6 +66,26 @@ // this may live in an app- or add-on-file +static status_t +load_resources_if_needed(RosterData* rosterData) +{ + if (rosterData->fAreResourcesLoaded) + return B_OK; + + status_t result = rosterData->fResources.SetToImage( + (const void*)&BLocaleRoster::Default); + if (result != B_OK) + return result; + + result = rosterData->fResources.PreloadResourceType(); + if (result != B_OK) + return result; + + rosterData->fAreResourcesLoaded = true; + return B_OK; +} + + static const char* country_code_for_language(const BLanguage& language) { @@ -302,31 +322,23 @@ if (!lock.IsLocked()) return B_ERROR; - if (!rosterData->fAreResourcesLoaded) { - status_t result = rosterData->fResources.SetToImage( - (const void*)&BLocaleRoster::Default); - if (result != B_OK) - return result; + status_t status = load_resources_if_needed(rosterData); + if (status != B_OK) + return status; - result = rosterData->fResources.PreloadResourceType(); - if (result != B_OK) - return result; + // Normalize the country code: 2 letters uppercase + // filter things out so that "pt_BR" gives the flag for brazil - rosterData->fAreResourcesLoaded = true; - } + int codeLength = strlen(countryCode); + if (codeLength < 2) + return B_BAD_VALUE; - size_t size; - - // normalize the country code : 2 letters uparcase - // filter things out so that "pt_BR" gived the flag for brazil char normalizedCode[3]; - normalizedCode[2] = '\0'; - - int codeLength = strlen(countryCode); - normalizedCode[0] = toupper(countryCode[codeLength - 2]); normalizedCode[1] = toupper(countryCode[codeLength - 1]); + normalizedCode[2] = '\0'; + size_t size; const void* buffer = rosterData->fResources.LoadResource( B_VECTOR_ICON_TYPE, normalizedCode, &size); if (buffer == NULL || size == 0) @@ -345,8 +357,33 @@ || languageCode[1] == '\0') return B_BAD_VALUE; - // TODO: Languages like Esperanto have a flag, but no country + RosterData* rosterData = RosterData::Default(); + BAutolock lock(rosterData->fLock); + if (!lock.IsLocked()) + return B_ERROR; + status_t status = load_resources_if_needed(rosterData); + if (status != B_OK) + return status; + + // Normalize the language code: first two letters, lowercase + + char normalizedCode[3]; + normalizedCode[0] = tolower(languageCode[0]); + normalizedCode[1] = tolower(languageCode[1]); + normalizedCode[2] = '\0'; + + size_t size; + const void* buffer = rosterData->fResources.LoadResource( + B_VECTOR_ICON_TYPE, normalizedCode, &size); + if (buffer != NULL && size != 0) { + return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer), + size, flagIcon); + } + + // There is no language flag, try to get the default country's flag for + // the language instead. + BLanguage language(languageCode); const char* countryCode = country_code_for_language(language); if (countryCode == NULL)