From b7f609650b9864f5f93ee235c1a095970f9df525 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Mon, 30 Aug 2010 19:58:19 +0000 Subject: [PATCH] * removed all BLocale-related getters from BLocaleRoster - they're available in BLocale (which is accessible via be_locale) * adjusted all users accordingly git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38459 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/locale/LocaleRoster.h | 4 -- headers/private/locale/MutableLocaleRoster.h | 2 + src/apps/aboutsystem/AboutSystem.cpp | 6 +- src/apps/deskbar/CalendarMenuWindow.cpp | 5 +- src/apps/deskbar/TimeView.cpp | 7 +- src/bin/dstcheck.cpp | 6 +- src/kits/locale/LocaleRoster.cpp | 64 ------------------- src/kits/locale/MutableLocaleRoster.cpp | 25 ++++++++ src/kits/tracker/WidgetAttributeText.cpp | 14 ++-- src/preferences/locale/FormatSettingsView.cpp | 4 +- src/preferences/locale/LocaleSettings.cpp | 12 ++-- src/preferences/locale/LocaleWindow.cpp | 7 +- src/preferences/time/DateTimeEdit.cpp | 15 ++--- src/preferences/time/ZoneView.cpp | 16 ++--- 14 files changed, 57 insertions(+), 130 deletions(-) diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index a9c5ebf27a..c6657dce49 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -28,10 +28,6 @@ public: BLocaleRoster(); ~BLocaleRoster(); - status_t GetDefaultCollator(BCollator* collator) const; - status_t GetDefaultLanguage(BLanguage* language) const; - status_t GetDefaultCountry(BCountry* country) const; - status_t GetDefaultLocale(BLocale* locale) const; status_t GetDefaultTimeZone(BTimeZone* timezone) const; status_t GetLanguage(const char* languageCode, diff --git a/headers/private/locale/MutableLocaleRoster.h b/headers/private/locale/MutableLocaleRoster.h index 0d5e535d81..fbd46a8363 100644 --- a/headers/private/locale/MutableLocaleRoster.h +++ b/headers/private/locale/MutableLocaleRoster.h @@ -33,6 +33,8 @@ public: MutableLocaleRoster(); ~MutableLocaleRoster(); + status_t GetDefaultLocale(BLocale* locale) const; + status_t SetDefaultCountry(const BCountry& country); status_t SetDefaultLocale(const BLocale& locale); status_t SetDefaultTimeZone(const BTimeZone& zone); diff --git a/src/apps/aboutsystem/AboutSystem.cpp b/src/apps/aboutsystem/AboutSystem.cpp index b3ba59de93..d5adb526b4 100644 --- a/src/apps/aboutsystem/AboutSystem.cpp +++ b/src/apps/aboutsystem/AboutSystem.cpp @@ -196,7 +196,7 @@ TranslationComparator(const void* left, const void* right) rightName = rightTranslation->languageCode; BCollator collator; - be_locale_roster->GetDefaultCollator(&collator); + be_locale->GetCollator(&collator); return collator.Compare(leftName.String(), rightName.String()); } @@ -1114,9 +1114,7 @@ AboutView::_CreateCreditsView() fCreditsView->Insert(langName); fCreditsView->Insert("\n"); fCreditsView->SetFontAndColor(be_plain_font, B_FONT_ALL, &kDarkGrey); - fCreditsView->Insert( - translation.names - ); + fCreditsView->Insert(translation.names); } fCreditsView->SetFontAndColor(&font, B_FONT_ALL, &kHaikuOrange); diff --git a/src/apps/deskbar/CalendarMenuWindow.cpp b/src/apps/deskbar/CalendarMenuWindow.cpp index 83617be0d8..5d89a546a8 100644 --- a/src/apps/deskbar/CalendarMenuWindow.cpp +++ b/src/apps/deskbar/CalendarMenuWindow.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -89,10 +88,8 @@ CalendarMenuWindow::CalendarMenuWindow(BPoint where) fCalendarView(NULL), fSuppressFirstClose(true) { - BLocale locale; - be_locale_roster->GetDefaultLocale(&locale); BPrivate::week_start startOfWeek - = (BPrivate::week_start)locale.StartOfWeek(); + = (BPrivate::week_start)be_locale->StartOfWeek(); RemoveShortcut('H', B_COMMAND_KEY | B_CONTROL_KEY); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index 42c6711285..800cd5d15f 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -41,7 +41,6 @@ All rights reserved. #include #include #include -#include #include #include #include @@ -91,7 +90,7 @@ TTimeView::TTimeView(float maxWidth, float height, bool showSeconds, fLastDateStr[0] = 0; fNeedToUpdate = true; - be_locale_roster->GetDefaultLocale(&fLocale); + fLocale = *be_locale; } @@ -105,7 +104,7 @@ TTimeView::TTimeView(BMessage* data) data->FindBool("interval", &fInterval); fShowingDate = false; - be_locale_roster->GetDefaultCountry(&fLocale); + fLocale = *be_locale; } #endif @@ -461,7 +460,7 @@ TTimeView::AllowFullDate(bool allow) void TTimeView::Update() { - be_locale_roster->GetDefaultLocale(&fLocale); + fLocale = *be_locale; GetCurrentTime(); GetCurrentDate(); diff --git a/src/bin/dstcheck.cpp b/src/bin/dstcheck.cpp index 1d0acc005c..d2f0ead194 100644 --- a/src/bin/dstcheck.cpp +++ b/src/bin/dstcheck.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -84,10 +83,7 @@ TimedAlert::GetLabel(BString &string) time(&t); localtime_r(&t, &tm); - BLocale here; - be_locale_roster->GetDefaultLocale(&here); - - here.FormatTime(timestring, 15, t, false); + be_locale->FormatTime(timestring, 15, t, false); string += " "; string += timestring; diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index d5d73a97da..830bd9a866 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -78,70 +78,6 @@ BLocaleRoster::Refresh() } -status_t -BLocaleRoster::GetDefaultCollator(BCollator* collator) const -{ - if (!collator) - return B_BAD_VALUE; - - BAutolock lock(gRosterData.fLock); - if (!lock.IsLocked()) - return B_ERROR; - - gRosterData.fDefaultLocale.GetCollator(collator); - - return B_OK; -} - - -status_t -BLocaleRoster::GetDefaultLanguage(BLanguage* language) const -{ - if (!language) - return B_BAD_VALUE; - - BAutolock lock(gRosterData.fLock); - if (!lock.IsLocked()) - return B_ERROR; - - gRosterData.fDefaultLocale.GetLanguage(language); - - return B_OK; -} - - -status_t -BLocaleRoster::GetDefaultCountry(BCountry* country) const -{ - if (!country) - return B_BAD_VALUE; - - BAutolock lock(gRosterData.fLock); - if (!lock.IsLocked()) - return B_ERROR; - - gRosterData.fDefaultLocale.GetCountry(country); - - return B_OK; -} - - -status_t -BLocaleRoster::GetDefaultLocale(BLocale* locale) const -{ - if (!locale) - return B_BAD_VALUE; - - BAutolock lock(gRosterData.fLock); - if (!lock.IsLocked()) - return B_ERROR; - - *locale = gRosterData.fDefaultLocale; - - return B_OK; -} - - status_t BLocaleRoster::GetDefaultTimeZone(BTimeZone* timezone) const { diff --git a/src/kits/locale/MutableLocaleRoster.cpp b/src/kits/locale/MutableLocaleRoster.cpp index d827ff600f..d6629f47fa 100644 --- a/src/kits/locale/MutableLocaleRoster.cpp +++ b/src/kits/locale/MutableLocaleRoster.cpp @@ -555,6 +555,15 @@ RosterData::_SetDefaultCountry(const BCountry& newCountry) { fDefaultLocale.SetCountry(newCountry); + UErrorCode icuError = U_ZERO_ERROR; + Locale icuLocale = Locale::createCanonical(newCountry.Code()); + if (icuLocale.isBogus()) + return B_ERROR; + + Locale::setDefault(icuLocale, icuError); + if (!U_SUCCESS(icuError)) + return B_ERROR; + return B_OK; } @@ -709,6 +718,22 @@ MutableLocaleRoster::SetPreferredLanguages(const BMessage* languages) } +status_t +MutableLocaleRoster::GetDefaultLocale(BLocale* locale) const +{ + if (!locale) + return B_BAD_VALUE; + + BAutolock lock(gRosterData.fLock); + if (!lock.IsLocked()) + return B_ERROR; + + *locale = gRosterData.fDefaultLocale; + + return B_OK; +} + + status_t MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const { diff --git a/src/kits/tracker/WidgetAttributeText.cpp b/src/kits/tracker/WidgetAttributeText.cpp index b3b43da2f8..74e70f7e56 100644 --- a/src/kits/tracker/WidgetAttributeText.cpp +++ b/src/kits/tracker/WidgetAttributeText.cpp @@ -215,7 +215,7 @@ TruncFileSizeBase(BString *result, int64 value, const View *view, float width) // ToDo: // if slow, replace float divisions with shifts // if fast enough, try fitting more decimal places - + // TODO: reuse libshared's string_for_size // format file size value @@ -292,15 +292,11 @@ TruncTimeBase(BString *result, int64 value, const View *view, float width) time_t timeValue = (time_t)value; - BLocale here; - be_locale_roster->GetDefaultLocale(&here); - - if (here.FormatDateTime(buffer, 256, timeValue, true) == B_OK) { + if (be_locale->FormatDateTime(buffer, 256, timeValue, true) == B_OK) resultWidth = view->StringWidth(buffer); - } - - if (resultWidth > width && here.FormatDateTime(buffer, 256, timeValue, - false) == B_OK) { + + if (resultWidth > width + && be_locale->FormatDateTime(buffer, 256, timeValue, false) == B_OK) { resultWidth = view->StringWidth(buffer); } diff --git a/src/preferences/locale/FormatSettingsView.cpp b/src/preferences/locale/FormatSettingsView.cpp index dc85bbef91..0baa3ce30f 100644 --- a/src/preferences/locale/FormatSettingsView.cpp +++ b/src/preferences/locale/FormatSettingsView.cpp @@ -503,9 +503,7 @@ FormatView::SetDefaults() settings.SetClockTo24Hr(false); */ - BLocale defaultLocale; - be_locale_roster->GetDefaultLocale(&defaultLocale); - fLocale = defaultLocale; + fLocale = *be_locale; // We work on a copy of the default country and set the changes when // closing the preflet _UpdateExamples(); diff --git a/src/preferences/locale/LocaleSettings.cpp b/src/preferences/locale/LocaleSettings.cpp index c2d77fb13b..04e6a13a31 100644 --- a/src/preferences/locale/LocaleSettings.cpp +++ b/src/preferences/locale/LocaleSettings.cpp @@ -78,32 +78,30 @@ LocaleSettings::UpdateFrom(BMessage* message) gMutableLocaleRoster->SetPreferredLanguages(message); } - BLocale defaultLocale; - gMutableLocaleRoster->GetDefaultLocale(&defaultLocale); - + BLocale locale(*be_locale); bool countryChanged = false; if (message->FindString("country", &messageContent) == B_OK) { fMessage.ReplaceString("country", messageContent); fMessage.RemoveName("shortTimeFormat"); fMessage.RemoveName("longTimeFormat"); - defaultLocale = BLocale(messageContent.String()); + locale = BLocale(messageContent.String()); countryChanged = true; } if (message->FindString("shortTimeFormat", &messageContent) == B_OK) { fMessage.RemoveName("shortTimeFormat"); fMessage.AddString("shortTimeFormat", messageContent); - defaultLocale.SetTimeFormat(messageContent, false); + locale.SetTimeFormat(messageContent, false); countryChanged = true; } if (message->FindString("longTimeFormat", &messageContent) == B_OK) { fMessage.RemoveName("longTimeFormat"); fMessage.AddString("longTimeFormat", messageContent); - defaultLocale.SetTimeFormat(messageContent, true); + locale.SetTimeFormat(messageContent, true); countryChanged = true; } if (countryChanged) - gMutableLocaleRoster->SetDefaultLocale(defaultLocale); + gMutableLocaleRoster->SetDefaultLocale(locale); } diff --git a/src/preferences/locale/LocaleWindow.cpp b/src/preferences/locale/LocaleWindow.cpp index 6e9085167d..b9115507cc 100644 --- a/src/preferences/locale/LocaleWindow.cpp +++ b/src/preferences/locale/LocaleWindow.cpp @@ -76,9 +76,6 @@ LocaleWindow::LocaleWindow() BWindow(BRect(0, 0, 0, 0), "Locale", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { - BLocale defaultLocale; - be_locale_roster->GetDefaultLocale(&defaultLocale); - SetLayout(new BGroupLayout(B_HORIZONTAL)); float spacing = be_control_look->DefaultItemSpacing(); @@ -199,7 +196,7 @@ LocaleWindow::LocaleWindow() = new LanguageListItem(countryName, countryCode, NULL); listView->AddItem(item); - if (!strcmp(countryCode, defaultLocale.Code())) + if (!strcmp(countryCode, be_locale->Code())) currentItem = item; } @@ -211,7 +208,7 @@ LocaleWindow::LocaleWindow() listView->SetExplicitMinSize( BSize(25 * be_plain_font->Size(), B_SIZE_UNSET)); - fFormatView = new FormatView(defaultLocale); + fFormatView = new FormatView(*be_locale); countryTab->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing) .AddGroup(B_VERTICAL, 3) diff --git a/src/preferences/time/DateTimeEdit.cpp b/src/preferences/time/DateTimeEdit.cpp index 58ceedb154..7e46a651fd 100644 --- a/src/preferences/time/DateTimeEdit.cpp +++ b/src/preferences/time/DateTimeEdit.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include @@ -277,12 +276,9 @@ TTimeEdit::BuildDispatch(BMessage* message) void TTimeEdit::_UpdateFields() { - BLocale locale; - be_locale_roster->GetDefaultLocale(&locale); - time_t time = fTime.Time_t(); - locale.FormatTime(&fText, fFieldPositions, fFieldPosCount, time, true); - locale.GetTimeFields(fFields, fFieldCount, true); + be_locale->FormatTime(&fText, fFieldPositions, fFieldPosCount, time, true); + be_locale->GetTimeFields(fFields, fFieldCount, true); } @@ -678,12 +674,9 @@ TDateEdit::BuildDispatch(BMessage* message) void TDateEdit::_UpdateFields() { - BLocale locale; - be_locale_roster->GetDefaultLocale(&locale); - time_t time = BDateTime(fDate, BTime()).Time_t(); - locale.FormatDate(&fText, fFieldPositions, fFieldPosCount, time, false); - locale.GetDateFields(fFields, fFieldCount, false); + be_locale->FormatDate(&fText, fFieldPositions, fFieldPosCount, time, false); + be_locale->GetDateFields(fFields, fFieldCount, false); } diff --git a/src/preferences/time/ZoneView.cpp b/src/preferences/time/ZoneView.cpp index a8daeb3331..523bb59aaf 100644 --- a/src/preferences/time/ZoneView.cpp +++ b/src/preferences/time/ZoneView.cpp @@ -183,13 +183,11 @@ TimeZoneView::GetToolTipAt(BPoint point, BToolTip** _tip) return false; BString nowInTimeZone; - BLocale locale; - be_locale_roster->GetDefaultLocale(&locale); time_t now = time(NULL); - locale.FormatTime(&nowInTimeZone, now, false, &item->TimeZone()); + be_locale->FormatTime(&nowInTimeZone, now, false, &item->TimeZone()); BString dateInTimeZone; - locale.FormatDate(&dateInTimeZone, now, false, &item->TimeZone()); + be_locale->FormatDate(&dateInTimeZone, now, false, &item->TimeZone()); BString toolTip = item->Text(); toolTip << '\n' << item->TimeZone().ShortName() << " / " @@ -278,8 +276,8 @@ TimeZoneView::_BuildZoneMenu() BTimeZone defaultTimeZone; be_locale_roster->GetDefaultTimeZone(&defaultTimeZone); - BLanguage defaultLanguage; - be_locale_roster->GetDefaultLanguage(&defaultLanguage); + BLanguage language; + be_locale->GetLanguage(&language); BMessage countryList; be_locale_roster->GetAvailableCountries(&countryList); @@ -352,7 +350,7 @@ TimeZoneView::_BuildZoneMenu() zoneMap[region] = regionItem; } - BTimeZone* timeZone = new BTimeZone(zoneID, &defaultLanguage); + BTimeZone* timeZone = new BTimeZone(zoneID, &language); BString tzName = timeZone->Name(); if (tzName == "GMT+00:00") tzName = "GMT"; @@ -524,8 +522,6 @@ TimeZoneView::_FormatTime(const BTimeZone& timeZone) { BString result; - BLocale locale; - be_locale_roster->GetDefaultLocale(&locale); time_t now = time(NULL); bool rtcIsGMT; _kern_get_real_time_clock_is_gmt(&rtcIsGMT); @@ -536,7 +532,7 @@ TimeZoneView::_FormatTime(const BTimeZone& timeZone) : 0; now -= timeZone.OffsetFromGMT() - currentOffset; } - locale.FormatTime(&result, now, false, &timeZone); + be_locale->FormatTime(&result, now, false, &timeZone); return result; }