* 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:
Adrien Destugues
2010-07-21 10:12:59 +00:00
parent 8f6bf75670
commit 2aeaae9988
3 changed files with 70 additions and 34 deletions
+32 -16
View File
@@ -191,8 +191,9 @@ struct RosterData {
BLocker fLock;
BList fCatalogAddOnInfos;
BMessage fPreferredLanguages;
BString fCountryCodeName;
BString fCountryDateFormat;
// BString fCountryCodeName;
// BString fCountryDateFormat;
BCountry* fDefaultCountry;
RosterData();
~RosterData();
@@ -246,8 +247,21 @@ RosterData::RosterData()
} else
fPreferredLanguages.AddString("language", "en");
if (settingsMessage.FindString("country", &fCountryCodeName) != B_OK)
fCountryCodeName = "en_US";
BString codeName;
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;
}
}
@@ -255,7 +269,7 @@ RosterData::RosterData()
// Something went wrong (no settings file or invalid BMessage
// set everything to default values
fPreferredLanguages.AddString("language", "en");
fCountryCodeName = "en_US";
fDefaultCountry = new BCountry("en_US");
log_team(LOG_ERR, "*** No language preference found!\n");
}
@@ -264,6 +278,7 @@ RosterData::~RosterData()
{
BAutolock lock(fLock);
assert(lock.IsLocked());
delete fDefaultCountry;
CleanupCatalogAddOns();
closelog();
}
@@ -278,8 +293,8 @@ RosterData::CompareInfos(const void *left, const void *right)
/*
* iterate over add-on-folders and collect information about each
* catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
iterate over add-on-folders and collect information about each
catalog-add-ons (types of catalogs) into fCatalogAddOnInfos.
*/
void
RosterData::InitializeCatalogAddOns()
@@ -452,15 +467,16 @@ BLocaleRoster::GetCatalog(BCatalog* catalog, vint32* catalogInitStatus)
bool found = false;
while (get_next_image_info(0, &cookie, &info) == B_OK) {
if ((char*)info.data < (char*)catalog && (char*)info.data+info.data_size
> (char*)catalog) {
if ((char*)info.data < (char*)catalog && (char*)info.data
+ info.data_size > (char*)catalog) {
found = true;
break;
}
}
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;
}
// figure out mimetype from image
@@ -532,10 +548,7 @@ BLocaleRoster::GetDefaultCountry(BCountry **country) const
BAutolock lock(gRosterData.fLock);
assert(lock.IsLocked());
*country = new(std::nothrow) BCountry(
gRosterData.fCountryCodeName.String());
if (gRosterData.fCountryDateFormat.Length() > 0)
(*country)->SetDateFormat(gRosterData.fCountryDateFormat.String());
*country = gRosterData.fDefaultCountry;
return B_OK;
}
@@ -559,8 +572,11 @@ BLocaleRoster::GetLanguage(const char* languageCode,
void
BLocaleRoster::SetDefaultCountry(BCountry* newDefault) const
{
gRosterData.fCountryCodeName = newDefault->Code();
newDefault->DateFormat(gRosterData.fCountryDateFormat, true);
BAutolock lock(gRosterData.fLock);
assert(lock.IsLocked());
delete gRosterData.fDefaultCountry;
gRosterData.fDefaultCountry = newDefault;
}
+22 -9
View File
@@ -73,21 +73,34 @@ LocaleSettings::_Open(BFile* file, int32 mode)
void
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");
for (int i = 0;; i++) {
if (message->FindString("language", i, &langName) != B_OK)
if (message->FindString("language", i, &messageContent) != B_OK)
break;
fMessage.AddString("language", langName);
fMessage.AddString("language", messageContent);
}
}
if (message->FindString("country", &langName) == B_OK)
fMessage.ReplaceString("country", langName);
fSaved = false;
}
if (message->FindString("country", &messageContent) == B_OK) {
fMessage.ReplaceString("country", messageContent);
fMessage.RemoveName("shortTimeFormat");
fMessage.RemoveName("longTimeFormat");
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 "Locale.h"
#include <Alert.h>
#include <Application.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
@@ -441,6 +443,8 @@ FormatView::MessageReceived(BMessage* message)
case kClockFormatChange:
{
BMessage newMessage(kMsgSettingsChanged);
BString timeFormat;
timeFormat = fOriginalTimeFormat;
if (f24HrRadioButton->Value() == 1) {
@@ -458,6 +462,7 @@ FormatView::MessageReceived(BMessage* message)
}
}
fCountry->SetTimeFormat(timeFormat.String(), false);
newMessage.AddString("shortTimeFormat", timeFormat);
timeFormat = fOriginalLongTimeFormat;
if (f24HrRadioButton->Value() == 1) {
@@ -475,8 +480,10 @@ FormatView::MessageReceived(BMessage* message)
}
}
fCountry->SetTimeFormat(timeFormat.String(), true);
newMessage.AddString("longTimeFormat", timeFormat);
_UpdateExamples();
Window()->PostMessage(kSettingsContentsModified);
be_app_messenger.SendMessage(&newMessage);
break;
}