diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index 298fcf3018..da1defca8c 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -65,6 +65,8 @@ public: // Get the catalog for the calling image // (that needs to link with liblocalestub.a) + bool IsFilesystemTranslationPreferred() const; + static const char* kCatLangAttr; static const char* kCatSigAttr; static const char* kCatFingerprintAttr; diff --git a/headers/private/locale/MutableLocaleRoster.h b/headers/private/locale/MutableLocaleRoster.h index 52b74d793f..f9101c0e3b 100644 --- a/headers/private/locale/MutableLocaleRoster.h +++ b/headers/private/locale/MutableLocaleRoster.h @@ -44,6 +44,7 @@ public: // the message contains one or more // 'language'-string-fields which // contain the language-name(s) + status_t SetFilesystemTranslationPreferred(bool preferred); status_t GetSystemCatalog(BCatalogAddOn** catalog) const; @@ -110,6 +111,8 @@ struct RosterData { BLocale fDefaultLocale; BTimeZone fDefaultTimeZone; + + bool fIsFilesystemTranslationPreferred; bool fAreResourcesLoaded; BResources fResources; @@ -133,6 +136,8 @@ struct RosterData { const BFormattingConventions& convetions); status_t SetDefaultTimeZone(const BTimeZone& zone); status_t SetPreferredLanguages(const BMessage* msg); + status_t SetFilesystemTranslationPreferred( + bool preferred); private: status_t _Initialize(); @@ -156,6 +161,8 @@ private: BMessage* message) const; status_t _AddPreferredLanguagesToMessage( BMessage* message) const; + status_t _AddFilesystemTranslationPreferenceToMessage( + BMessage* message) const; }; diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 68be733d2d..5e5c7788bb 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -610,10 +610,11 @@ TBarApp::AddTeam(team_id team, uint32 flags, const char* sig, entry_ref* ref) BFile file(ref, B_READ_ONLY); BAppFileInfo appMime(&file); - BString name; - if (GetLocalizedFileName(*ref, name) != B_OK) + BString name; + if (!BLocaleRoster::Default()->IsFilesystemTranslationPreferred() + || GetLocalizedFileName(*ref, name) != B_OK) name = ref->name; - + BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig), new BBitmap(kIconRect, kIconFormat), strdup(name.String())); diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 22b4178650..3b7b0a655b 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -366,3 +366,15 @@ BLocaleRoster::_GetCatalog(BCatalog* catalog, vint32* catalogInitStatus) return catalog; } + + +bool +BLocaleRoster::IsFilesystemTranslationPreferred() const +{ + RosterData* rosterData = RosterData::Default(); + BAutolock lock(rosterData->fLock); + if (!lock.IsLocked()) + return B_ERROR; + + return rosterData->fIsFilesystemTranslationPreferred; +} diff --git a/src/kits/locale/MutableLocaleRoster.cpp b/src/kits/locale/MutableLocaleRoster.cpp index 491301c844..86656eac60 100644 --- a/src/kits/locale/MutableLocaleRoster.cpp +++ b/src/kits/locale/MutableLocaleRoster.cpp @@ -133,14 +133,15 @@ namespace { static const char* kPriorityAttr = "ADDON:priority"; static const char* kLanguageField = "language"; - static const char* kTimezoneField = "timezone"; static const char* kOffsetField = "offset"; +static const char* kTranslateFilesystemField = "filesys"; static RosterData* sRosterData = NULL; static pthread_once_t sRosterDataInitOnce = PTHREAD_ONCE_INIT; + static struct RosterDataReaper { ~RosterDataReaper() { @@ -167,6 +168,7 @@ RosterData::RosterData(const BLanguage& language, : fLock("LocaleRosterData"), fDefaultLocale(&language, &conventions), + fIsFilesystemTranslationPreferred(false), fAreResourcesLoaded(false) { fInitStatus = _Initialize(); @@ -297,6 +299,28 @@ RosterData::SetPreferredLanguages(const BMessage* languages) } +status_t +RosterData::SetFilesystemTranslationPreferred(bool preferred) +{ + BAutolock lock(fLock); + if (!lock.IsLocked()) + return B_ERROR; + + fIsFilesystemTranslationPreferred = preferred; + + status_t status = _SaveLocaleSettings(); + + if (status == B_OK) { + BMessage updateMessage(B_LOCALE_CHANGED); + status = _AddFilesystemTranslationPreferenceToMessage(&updateMessage); + if (status == B_OK) + status = be_roster->Broadcast(&updateMessage); + } + + return status; +} + + status_t RosterData::_Initialize() { @@ -483,6 +507,10 @@ RosterData::_LoadLocaleSettings() fDefaultLocale.SetFormattingConventions(conventions); _SetPreferredLanguages(&settings); + + bool preferred; + if (settings.FindBool(kTranslateFilesystemField, &preferred) == B_OK) + SetFilesystemTranslationPreferred(preferred); return B_OK; } @@ -540,6 +568,8 @@ RosterData::_SaveLocaleSettings() status_t status = _AddDefaultFormattingConventionsToMessage(&settings); if (status == B_OK) _AddPreferredLanguagesToMessage(&settings); + if (status == B_OK) + _AddFilesystemTranslationPreferenceToMessage(&settings); BPath path; if (status == B_OK) @@ -685,6 +715,15 @@ RosterData::_AddPreferredLanguagesToMessage(BMessage* message) const } +status_t +RosterData::_AddFilesystemTranslationPreferenceToMessage(BMessage* message) + const +{ + return message->AddBool(kTranslateFilesystemField, + fIsFilesystemTranslationPreferred); +} + + // #pragma mark - MutableLocaleRoster @@ -736,6 +775,13 @@ MutableLocaleRoster::SetPreferredLanguages(const BMessage* languages) } +status_t +MutableLocaleRoster::SetFilesystemTranslationPreferred(bool preferred) +{ + return RosterData::Default()->SetFilesystemTranslationPreferred(preferred); +} + + status_t MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const { diff --git a/src/preferences/locale/LocalePreflet.cpp b/src/preferences/locale/LocalePreflet.cpp index 752ae5ca6d..69897f9267 100644 --- a/src/preferences/locale/LocalePreflet.cpp +++ b/src/preferences/locale/LocalePreflet.cpp @@ -5,15 +5,13 @@ */ -#include -#include - #include -#include #include +#include #include -#include #include +#include +#include #include "LocalePreflet.h" #include "LocaleWindow.h" @@ -32,8 +30,11 @@ class LocalePreflet : public BApplication { virtual ~LocalePreflet(); virtual void AboutRequested(); + virtual void MessageReceived(BMessage* message); private: + status_t _RestartApp(const char* signature) const; + LocaleWindow* fLocaleWindow; }; @@ -63,13 +64,51 @@ LocalePreflet::AboutRequested() "Axel Dörfler", "Adrien Destugues", "Oliver Tappe", - NULL + NULL }; BAboutWindow about(B_TRANSLATE("Locale"), 2005, authors); about.Show(); } +void +LocalePreflet::MessageReceived(BMessage* message) +{ + switch (message->what) { + case kMsgRestartTrackerAndDeskbar: + if (message->FindInt32("which") == 1) { + _RestartApp("application/x-vnd.Be-TRAK"); + _RestartApp("application/x-vnd.Be-TSKB"); + } + break; + + default: + BApplication::MessageReceived(message); + break; + } +} + + +status_t +LocalePreflet::_RestartApp(const char* signature) const +{ + app_info info; + status_t status = be_roster->GetAppInfo(signature, &info); + if (status != B_OK) + return status; + + BMessenger application(signature); + status = application.SendMessage(B_QUIT_REQUESTED); + if (status != B_OK) + return status; + + status_t exit; + wait_for_thread(info.thread, &exit); + + return be_roster->Launch(signature); +} + + // #pragma mark - diff --git a/src/preferences/locale/LocalePreflet.h b/src/preferences/locale/LocalePreflet.h index db7c5cc900..428a5207d9 100644 --- a/src/preferences/locale/LocalePreflet.h +++ b/src/preferences/locale/LocalePreflet.h @@ -11,6 +11,7 @@ extern const char* kSignature; +static const uint32 kMsgRestartTrackerAndDeskbar = 'Rstr'; static const uint32 kMsgSettingsChanged = 'SeCh'; diff --git a/src/preferences/locale/LocaleWindow.cpp b/src/preferences/locale/LocaleWindow.cpp index 58864514c4..9a1793f6af 100644 --- a/src/preferences/locale/LocaleWindow.cpp +++ b/src/preferences/locale/LocaleWindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ static const uint32 kMsgConventionsSelection = 'csel'; static const uint32 kMsgDefaults = 'dflt'; static const uint32 kMsgPreferredLanguagesChanged = 'lang'; +static const uint32 kMsgFilesystemTranslationChanged = 'fsys'; static int @@ -68,7 +70,8 @@ LocaleWindow::LocaleWindow() B_QUIT_ON_WINDOW_CLOSE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fInitialConventionsItem(NULL), - fDefaultConventionsItem(NULL) + fDefaultConventionsItem(NULL), + fFilesystemTranslationCheckbox(NULL) { SetLayout(new BGroupLayout(B_HORIZONTAL)); @@ -232,8 +235,24 @@ LocaleWindow::LocaleWindow() .Add(fFormatView) .SetInsets(spacing, spacing, spacing, spacing)); + BView* systemTab = new BView(B_TRANSLATE("System"), B_WILL_DRAW); + systemTab->SetLayout(new BGroupLayout(B_VERTICAL, 0)); + + fFilesystemTranslationCheckbox = new BCheckBox("filesystemTranslation", + B_TRANSLATE("Translate application and folder names in Deskbar and Tracker."), + new BMessage(kMsgFilesystemTranslationChanged)); + + fFilesystemTranslationCheckbox->SetValue( + BLocaleRoster::Default()->IsFilesystemTranslationPreferred()); + + systemTab->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, spacing) + .Add(fFilesystemTranslationCheckbox) + .AddGlue() + .SetInsets(spacing, spacing, spacing, spacing)); + tabView->AddTab(languageTab); tabView->AddTab(countryTab); + tabView->AddTab(systemTab); BButton* button = new BButton(B_TRANSLATE("Defaults"), new BMessage(kMsgDefaults)); @@ -396,6 +415,21 @@ LocaleWindow::MessageReceived(BMessage* message) break; } + case kMsgFilesystemTranslationChanged: + { + MutableLocaleRoster::Default()->SetFilesystemTranslationPreferred( + fFilesystemTranslationCheckbox->Value()); + + BAlert* alert = new BAlert(B_TRANSLATE("Locale"), + B_TRANSLATE("Deskbar and Tracker need to be restarted for this " + "change to take effect. Would you like to restart them now?"), + B_TRANSLATE("Cancel"), B_TRANSLATE("Restart"), NULL, + B_WIDTH_FROM_WIDEST, B_IDEA_ALERT); + alert->Go(new BInvoker(new BMessage(kMsgRestartTrackerAndDeskbar), + NULL, be_app)); + break; + } + default: BWindow::MessageReceived(message); break; @@ -594,4 +628,3 @@ LocaleWindow::_Defaults() fConventionsListView->ScrollToSelection(); } } - diff --git a/src/preferences/locale/LocaleWindow.h b/src/preferences/locale/LocaleWindow.h index d43281c5a3..45f42a39c9 100644 --- a/src/preferences/locale/LocaleWindow.h +++ b/src/preferences/locale/LocaleWindow.h @@ -14,6 +14,7 @@ static const uint32 kMsgRevert = 'revt'; class BButton; +class BCheckBox; class BListView; class FormatSettingsView; class LanguageListItem; @@ -54,6 +55,7 @@ private: LanguageListItem* fInitialConventionsItem; LanguageListItem* fDefaultConventionsItem; BMessage fInitialPreferredLanguages; + BCheckBox* fFilesystemTranslationCheckbox; };