* Locale Roster : store an instance of BCountry instead of replicating all of its intrnals and creating instances on demand
* Locale preflet : save the time formats to the settings file if they are different from the defaut. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37642 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -191,8 +191,9 @@ struct RosterData {
|
|||||||
BLocker fLock;
|
BLocker fLock;
|
||||||
BList fCatalogAddOnInfos;
|
BList fCatalogAddOnInfos;
|
||||||
BMessage fPreferredLanguages;
|
BMessage fPreferredLanguages;
|
||||||
BString fCountryCodeName;
|
// BString fCountryCodeName;
|
||||||
BString fCountryDateFormat;
|
// BString fCountryDateFormat;
|
||||||
|
BCountry* fDefaultCountry;
|
||||||
|
|
||||||
RosterData();
|
RosterData();
|
||||||
~RosterData();
|
~RosterData();
|
||||||
@@ -236,7 +237,7 @@ RosterData::RosterData()
|
|||||||
icuLocale.getDisplayName(ustr);
|
icuLocale.getDisplayName(ustr);
|
||||||
ustr.toUTF8(bbs);
|
ustr.toUTF8(bbs);
|
||||||
|
|
||||||
Locale::setDefault(icuLocale,icuError);
|
Locale::setDefault(icuLocale, icuError);
|
||||||
assert(icuError == U_ZERO_ERROR);
|
assert(icuError == U_ZERO_ERROR);
|
||||||
fPreferredLanguages.RemoveName("language");
|
fPreferredLanguages.RemoveName("language");
|
||||||
for (int i = 0; settingsMessage.FindString("language", i,
|
for (int i = 0; settingsMessage.FindString("language", i,
|
||||||
@@ -246,8 +247,21 @@ RosterData::RosterData()
|
|||||||
} else
|
} else
|
||||||
fPreferredLanguages.AddString("language", "en");
|
fPreferredLanguages.AddString("language", "en");
|
||||||
|
|
||||||
if (settingsMessage.FindString("country", &fCountryCodeName) != B_OK)
|
BString codeName;
|
||||||
fCountryCodeName = "en_US";
|
if (settingsMessage.FindString("country", &codeName)
|
||||||
|
== B_OK)
|
||||||
|
fDefaultCountry = new BCountry(codeName);
|
||||||
|
else
|
||||||
|
fDefaultCountry = new BCountry("en_US");
|
||||||
|
|
||||||
|
BString timeFormat;
|
||||||
|
if (settingsMessage.FindString("shortTimeFormat", &timeFormat)
|
||||||
|
== B_OK)
|
||||||
|
fDefaultCountry->SetTimeFormat(timeFormat, false);
|
||||||
|
if (settingsMessage.FindString("longTimeFormat", &timeFormat)
|
||||||
|
== B_OK)
|
||||||
|
fDefaultCountry->SetTimeFormat(timeFormat, true);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,8 +269,8 @@ RosterData::RosterData()
|
|||||||
// Something went wrong (no settings file or invalid BMessage
|
// Something went wrong (no settings file or invalid BMessage
|
||||||
// set everything to default values
|
// set everything to default values
|
||||||
fPreferredLanguages.AddString("language", "en");
|
fPreferredLanguages.AddString("language", "en");
|
||||||
fCountryCodeName = "en_US";
|
fDefaultCountry = new BCountry("en_US");
|
||||||
log_team(LOG_ERR,"*** No language preference found!\n");
|
log_team(LOG_ERR, "*** No language preference found!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -264,6 +278,7 @@ RosterData::~RosterData()
|
|||||||
{
|
{
|
||||||
BAutolock lock(fLock);
|
BAutolock lock(fLock);
|
||||||
assert(lock.IsLocked());
|
assert(lock.IsLocked());
|
||||||
|
delete fDefaultCountry;
|
||||||
CleanupCatalogAddOns();
|
CleanupCatalogAddOns();
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
@@ -278,9 +293,9 @@ RosterData::CompareInfos(const void *left, const void *right)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iterate over add-on-folders and collect information about each
|
iterate over add-on-folders and collect information about each
|
||||||
* catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
|
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
RosterData::InitializeCatalogAddOns()
|
RosterData::InitializeCatalogAddOns()
|
||||||
{
|
{
|
||||||
@@ -397,7 +412,7 @@ RosterData::InitializeCatalogAddOns()
|
|||||||
}
|
}
|
||||||
fCatalogAddOnInfos.SortItems(CompareInfos);
|
fCatalogAddOnInfos.SortItems(CompareInfos);
|
||||||
|
|
||||||
for (int32 i=0; i<fCatalogAddOnInfos.CountItems(); ++i) {
|
for (int32 i = 0; i<fCatalogAddOnInfos.CountItems(); ++i) {
|
||||||
BCatalogAddOnInfo *info
|
BCatalogAddOnInfo *info
|
||||||
= static_cast<BCatalogAddOnInfo*>(fCatalogAddOnInfos.ItemAt(i));
|
= static_cast<BCatalogAddOnInfo*>(fCatalogAddOnInfos.ItemAt(i));
|
||||||
}
|
}
|
||||||
@@ -406,14 +421,14 @@ RosterData::InitializeCatalogAddOns()
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* unloads all catalog-add-ons (which will throw away all loaded catalogs, too)
|
* unloads all catalog-add-ons (which will throw away all loaded catalogs, too)
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
RosterData::CleanupCatalogAddOns()
|
RosterData::CleanupCatalogAddOns()
|
||||||
{
|
{
|
||||||
BAutolock lock(fLock);
|
BAutolock lock(fLock);
|
||||||
assert(lock.IsLocked());
|
assert(lock.IsLocked());
|
||||||
int32 count = fCatalogAddOnInfos.CountItems();
|
int32 count = fCatalogAddOnInfos.CountItems();
|
||||||
for (int32 i=0; i<count; ++i) {
|
for (int32 i = 0; i<count; ++i) {
|
||||||
BCatalogAddOnInfo *info
|
BCatalogAddOnInfo *info
|
||||||
= static_cast<BCatalogAddOnInfo*>(fCatalogAddOnInfos.ItemAt(i));
|
= static_cast<BCatalogAddOnInfo*>(fCatalogAddOnInfos.ItemAt(i));
|
||||||
delete info;
|
delete info;
|
||||||
@@ -440,7 +455,7 @@ BLocaleRoster::GetCatalog(BCatalog* catalog, vint32* catalogInitStatus)
|
|||||||
{
|
{
|
||||||
// This function is used in the translation macros, so it can't return a
|
// This function is used in the translation macros, so it can't return a
|
||||||
// status_t. Maybe it could throw exceptions ?
|
// status_t. Maybe it could throw exceptions ?
|
||||||
|
|
||||||
if (*catalogInitStatus == true) {
|
if (*catalogInitStatus == true) {
|
||||||
// Catalog already loaded - nothing else to do
|
// Catalog already loaded - nothing else to do
|
||||||
return catalog;
|
return catalog;
|
||||||
@@ -452,15 +467,16 @@ BLocaleRoster::GetCatalog(BCatalog* catalog, vint32* catalogInitStatus)
|
|||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
while (get_next_image_info(0, &cookie, &info) == B_OK) {
|
while (get_next_image_info(0, &cookie, &info) == B_OK) {
|
||||||
if ((char*)info.data < (char*)catalog && (char*)info.data+info.data_size
|
if ((char*)info.data < (char*)catalog && (char*)info.data
|
||||||
> (char*)catalog) {
|
+ info.data_size > (char*)catalog) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
log_team(LOG_DEBUG, "Catalog %x doesn't belong to any image !",catalog);
|
log_team(LOG_DEBUG, "Catalog %x doesn't belong to any image !",
|
||||||
|
catalog);
|
||||||
return catalog;
|
return catalog;
|
||||||
}
|
}
|
||||||
// figure out mimetype from image
|
// figure out mimetype from image
|
||||||
@@ -475,7 +491,7 @@ BLocaleRoster::GetCatalog(BCatalog* catalog, vint32* catalogInitStatus)
|
|||||||
|
|
||||||
// drop supertype from mimetype (should be "application/"):
|
// drop supertype from mimetype (should be "application/"):
|
||||||
char* stripSignature = objectSignature;
|
char* stripSignature = objectSignature;
|
||||||
while(*stripSignature != '/')
|
while (*stripSignature != '/')
|
||||||
stripSignature ++;
|
stripSignature ++;
|
||||||
stripSignature ++;
|
stripSignature ++;
|
||||||
|
|
||||||
@@ -532,10 +548,7 @@ BLocaleRoster::GetDefaultCountry(BCountry **country) const
|
|||||||
BAutolock lock(gRosterData.fLock);
|
BAutolock lock(gRosterData.fLock);
|
||||||
assert(lock.IsLocked());
|
assert(lock.IsLocked());
|
||||||
|
|
||||||
*country = new(std::nothrow) BCountry(
|
*country = gRosterData.fDefaultCountry;
|
||||||
gRosterData.fCountryCodeName.String());
|
|
||||||
if (gRosterData.fCountryDateFormat.Length() > 0)
|
|
||||||
(*country)->SetDateFormat(gRosterData.fCountryDateFormat.String());
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,8 +572,11 @@ BLocaleRoster::GetLanguage(const char* languageCode,
|
|||||||
void
|
void
|
||||||
BLocaleRoster::SetDefaultCountry(BCountry* newDefault) const
|
BLocaleRoster::SetDefaultCountry(BCountry* newDefault) const
|
||||||
{
|
{
|
||||||
gRosterData.fCountryCodeName = newDefault->Code();
|
BAutolock lock(gRosterData.fLock);
|
||||||
newDefault->DateFormat(gRosterData.fCountryDateFormat, true);
|
assert(lock.IsLocked());
|
||||||
|
|
||||||
|
delete gRosterData.fDefaultCountry;
|
||||||
|
gRosterData.fDefaultCountry = newDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ LocaleSettings::Load()
|
|||||||
BFile file;
|
BFile file;
|
||||||
status_t err;
|
status_t err;
|
||||||
err = _Open(&file, B_READ_ONLY);
|
err = _Open(&file, B_READ_ONLY);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
err = fMessage.Unflatten(&file);
|
err = fMessage.Unflatten(&file);
|
||||||
if (err == B_OK)
|
if (err == B_OK)
|
||||||
fSaved = true;
|
fSaved = true;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ LocaleSettings::Save()
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
err = fMessage.Flatten(&file);
|
err = fMessage.Flatten(&file);
|
||||||
if (err == B_OK)
|
if (err == B_OK)
|
||||||
fSaved = true;
|
fSaved = true;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -73,21 +73,34 @@ LocaleSettings::_Open(BFile* file, int32 mode)
|
|||||||
void
|
void
|
||||||
LocaleSettings::UpdateFrom(BMessage* message)
|
LocaleSettings::UpdateFrom(BMessage* message)
|
||||||
{
|
{
|
||||||
BString langName;
|
BString messageContent;
|
||||||
|
|
||||||
if (message->FindString("language", &langName) == B_OK) {
|
if (message->FindString("language", &messageContent) == B_OK) {
|
||||||
fMessage.RemoveName("language");
|
fMessage.RemoveName("language");
|
||||||
|
|
||||||
for (int i = 0;; i++) {
|
for (int i = 0;; i++) {
|
||||||
if (message->FindString("language", i, &langName) != B_OK)
|
if (message->FindString("language", i, &messageContent) != B_OK)
|
||||||
break;
|
break;
|
||||||
fMessage.AddString("language", langName);
|
fMessage.AddString("language", messageContent);
|
||||||
}
|
}
|
||||||
|
fSaved = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->FindString("country", &langName) == B_OK)
|
if (message->FindString("country", &messageContent) == B_OK) {
|
||||||
fMessage.ReplaceString("country", langName);
|
fMessage.ReplaceString("country", messageContent);
|
||||||
|
fMessage.RemoveName("shortTimeFormat");
|
||||||
|
fMessage.RemoveName("longTimeFormat");
|
||||||
|
fSaved = false;
|
||||||
|
}
|
||||||
|
|
||||||
fSaved = false;
|
if (message->FindString("shortTimeFormat", &messageContent) == B_OK) {
|
||||||
|
fMessage.ReplaceString("shortTimeFormat", messageContent);
|
||||||
|
fSaved = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message->FindString("longTimeFormat", &messageContent) == B_OK) {
|
||||||
|
fMessage.ReplaceString("longTimeFormat", messageContent);
|
||||||
|
fSaved = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "TimeFormatSettingsView.h"
|
#include "TimeFormatSettingsView.h"
|
||||||
|
#include "Locale.h"
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
|
#include <Application.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
#include <ControlLook.h>
|
#include <ControlLook.h>
|
||||||
@@ -441,6 +443,8 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case kClockFormatChange:
|
case kClockFormatChange:
|
||||||
{
|
{
|
||||||
|
BMessage newMessage(kMsgSettingsChanged);
|
||||||
|
|
||||||
BString timeFormat;
|
BString timeFormat;
|
||||||
timeFormat = fOriginalTimeFormat;
|
timeFormat = fOriginalTimeFormat;
|
||||||
if (f24HrRadioButton->Value() == 1) {
|
if (f24HrRadioButton->Value() == 1) {
|
||||||
@@ -458,6 +462,7 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fCountry->SetTimeFormat(timeFormat.String(), false);
|
fCountry->SetTimeFormat(timeFormat.String(), false);
|
||||||
|
newMessage.AddString("shortTimeFormat", timeFormat);
|
||||||
|
|
||||||
timeFormat = fOriginalLongTimeFormat;
|
timeFormat = fOriginalLongTimeFormat;
|
||||||
if (f24HrRadioButton->Value() == 1) {
|
if (f24HrRadioButton->Value() == 1) {
|
||||||
@@ -475,8 +480,10 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fCountry->SetTimeFormat(timeFormat.String(), true);
|
fCountry->SetTimeFormat(timeFormat.String(), true);
|
||||||
|
newMessage.AddString("longTimeFormat", timeFormat);
|
||||||
_UpdateExamples();
|
_UpdateExamples();
|
||||||
Window()->PostMessage(kSettingsContentsModified);
|
Window()->PostMessage(kSettingsContentsModified);
|
||||||
|
be_app_messenger.SendMessage(&newMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user