Introducing a Locale option to display localized filesystem entries (primarily apps and folders) in Deskbar, Tracker, etc. Making use of this in Deskbar's list of apps. The option currently defaults to off, to avoid exposing everyone to unfinished work.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40918 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström 2011-03-11 19:52:15 +00:00
parent a991d18159
commit 07cffb4786
9 changed files with 155 additions and 12 deletions

View File

@ -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;

View File

@ -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;
};

View File

@ -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()));

View File

@ -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;
}

View File

@ -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
{

View File

@ -5,15 +5,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <AboutWindow.h>
#include <Application.h>
#include <Alert.h>
#include <Application.h>
#include <Catalog.h>
#include <TextView.h>
#include <Locale.h>
#include <Roster.h>
#include <TextView.h>
#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 -

View File

@ -11,6 +11,7 @@
extern const char* kSignature;
static const uint32 kMsgRestartTrackerAndDeskbar = 'Rstr';
static const uint32 kMsgSettingsChanged = 'SeCh';

View File

@ -13,6 +13,7 @@
#include <Application.h>
#include <Button.h>
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <FormattingConventions.h>
#include <GroupLayout.h>
@ -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();
}
}

View File

@ -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;
};