[haiku-commits] r40918 - in haiku/trunk: headers/os/locale headers/private/locale src/apps/deskbar src/kits/locale src/preferences/locale

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 11 Mar 2011 20:52:27 +0100 (CET)

Author: kirilla
Date: 2011-03-11 20:52:15 +0100 (Fri, 11 Mar 2011)
New Revision: 40918
Changeset: http://dev.haiku-os.org/changeset/40918

Modified:
   haiku/trunk/headers/os/locale/LocaleRoster.h
   haiku/trunk/headers/private/locale/MutableLocaleRoster.h
   haiku/trunk/src/apps/deskbar/BarApp.cpp
   haiku/trunk/src/kits/locale/LocaleRoster.cpp
   haiku/trunk/src/kits/locale/MutableLocaleRoster.cpp
   haiku/trunk/src/preferences/locale/LocalePreflet.cpp
   haiku/trunk/src/preferences/locale/LocalePreflet.h
   haiku/trunk/src/preferences/locale/LocaleWindow.cpp
   haiku/trunk/src/preferences/locale/LocaleWindow.h
Log:
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.

Modified: haiku/trunk/headers/os/locale/LocaleRoster.h
===================================================================
--- haiku/trunk/headers/os/locale/LocaleRoster.h        2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/headers/os/locale/LocaleRoster.h        2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -65,6 +65,8 @@
                                                                        // 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;

Modified: haiku/trunk/headers/private/locale/MutableLocaleRoster.h
===================================================================
--- haiku/trunk/headers/private/locale/MutableLocaleRoster.h    2011-03-11 
18:20:57 UTC (rev 40917)
+++ haiku/trunk/headers/private/locale/MutableLocaleRoster.h    2011-03-11 
19:52:15 UTC (rev 40918)
@@ -44,6 +44,7 @@
                                                                        // 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 @@
 
                        BLocale                         fDefaultLocale;
                        BTimeZone                       fDefaultTimeZone;
+                       
+                       bool                            
fIsFilesystemTranslationPreferred;
 
                        bool                            fAreResourcesLoaded;
                        BResources                      fResources;
@@ -133,6 +136,8 @@
                                                                        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 @@
                                                                        
BMessage* message) const;
                        status_t                        
_AddPreferredLanguagesToMessage(
                                                                        
BMessage* message) const;
+                       status_t                        
_AddFilesystemTranslationPreferenceToMessage(
+                                                                       
BMessage* message) const;
 };
 
 

Modified: haiku/trunk/src/apps/deskbar/BarApp.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-11 18:20:57 UTC (rev 
40917)
+++ haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-11 19:52:15 UTC (rev 
40918)
@@ -610,10 +610,11 @@
        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()));
 

Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -366,3 +366,15 @@
 
        return catalog;
 }
+
+
+bool
+BLocaleRoster::IsFilesystemTranslationPreferred() const
+{
+       RosterData* rosterData = RosterData::Default();
+       BAutolock lock(rosterData->fLock);
+       if (!lock.IsLocked())
+               return B_ERROR;
+
+       return rosterData->fIsFilesystemTranslationPreferred;
+}

Modified: haiku/trunk/src/kits/locale/MutableLocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/MutableLocaleRoster.cpp 2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/src/kits/locale/MutableLocaleRoster.cpp 2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -133,14 +133,15 @@
 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 @@
        :
        fLock("LocaleRosterData"),
        fDefaultLocale(&language, &conventions),
+       fIsFilesystemTranslationPreferred(false),
        fAreResourcesLoaded(false)
 {
        fInitStatus = _Initialize();
@@ -298,6 +300,28 @@
 
 
 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()
 {
        openlog_team("liblocale.so", LOG_PID, LOG_USER);
@@ -483,6 +507,10 @@
                fDefaultLocale.SetFormattingConventions(conventions);
 
                _SetPreferredLanguages(&settings);
+               
+               bool preferred;
+               if (settings.FindBool(kTranslateFilesystemField, &preferred) == 
B_OK)
+                       SetFilesystemTranslationPreferred(preferred);
 
                return B_OK;
        }
@@ -540,6 +568,8 @@
        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 @@
 }
 
 
+status_t
+RosterData::_AddFilesystemTranslationPreferenceToMessage(BMessage* message)
+       const
+{
+       return message->AddBool(kTranslateFilesystemField,
+               fIsFilesystemTranslationPreferred);
+}
+
+
 // #pragma mark - MutableLocaleRoster
 
 
@@ -737,6 +776,13 @@
 
 
 status_t
+MutableLocaleRoster::SetFilesystemTranslationPreferred(bool preferred)
+{
+       return 
RosterData::Default()->SetFilesystemTranslationPreferred(preferred);
+}
+
+
+status_t
 MutableLocaleRoster::GetSystemCatalog(BCatalogAddOn** catalog) const
 {
        if (!catalog)

Modified: haiku/trunk/src/preferences/locale/LocalePreflet.cpp
===================================================================
--- haiku/trunk/src/preferences/locale/LocalePreflet.cpp        2011-03-11 
18:20:57 UTC (rev 40917)
+++ haiku/trunk/src/preferences/locale/LocalePreflet.cpp        2011-03-11 
19:52:15 UTC (rev 40918)
@@ -5,15 +5,13 @@
  */
 
 
-#include <stdio.h>
-#include <string.h>
-
 #include <AboutWindow.h>
+#include <Alert.h>
 #include <Application.h>
-#include <Alert.h>
 #include <Catalog.h>
+#include <Locale.h>
+#include <Roster.h>
 #include <TextView.h>
-#include <Locale.h>
 
 #include "LocalePreflet.h"
 #include "LocaleWindow.h"
@@ -32,8 +30,11 @@
                virtual                         ~LocalePreflet();
 
                virtual void            AboutRequested();
+               virtual void            MessageReceived(BMessage* message);
 
 private:
+               status_t                        _RestartApp(const char* 
signature) const;
+               
                LocaleWindow*           fLocaleWindow;
 };
 
@@ -63,13 +64,51 @@
                "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 -
 
 

Modified: haiku/trunk/src/preferences/locale/LocalePreflet.h
===================================================================
--- haiku/trunk/src/preferences/locale/LocalePreflet.h  2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/src/preferences/locale/LocalePreflet.h  2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -11,6 +11,7 @@
 
 extern const char* kSignature;
 
+static const uint32 kMsgRestartTrackerAndDeskbar = 'Rstr';
 static const uint32 kMsgSettingsChanged = 'SeCh';
 
 

Modified: haiku/trunk/src/preferences/locale/LocaleWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/locale/LocaleWindow.cpp 2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/src/preferences/locale/LocaleWindow.cpp 2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -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 kMsgDefaults = 'dflt';
 
 static const uint32 kMsgPreferredLanguagesChanged = 'lang';
+static const uint32 kMsgFilesystemTranslationChanged = 'fsys';
 
 
 static int
@@ -68,7 +70,8 @@
                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 @@
                .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 @@
                        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 @@
                fConventionsListView->ScrollToSelection();
        }
 }
-

Modified: haiku/trunk/src/preferences/locale/LocaleWindow.h
===================================================================
--- haiku/trunk/src/preferences/locale/LocaleWindow.h   2011-03-11 18:20:57 UTC 
(rev 40917)
+++ haiku/trunk/src/preferences/locale/LocaleWindow.h   2011-03-11 19:52:15 UTC 
(rev 40918)
@@ -14,6 +14,7 @@
 
 
 class BButton;
+class BCheckBox;
 class BListView;
 class FormatSettingsView;
 class LanguageListItem;
@@ -54,6 +55,7 @@
                        LanguageListItem*       fInitialConventionsItem;
                        LanguageListItem*       fDefaultConventionsItem;
                        BMessage                        
fInitialPreferredLanguages;
+                       BCheckBox*                      
fFilesystemTranslationCheckbox;
 };
 
 


Other related posts:

  • » [haiku-commits] r40918 - in haiku/trunk: headers/os/locale headers/private/locale src/apps/deskbar src/kits/locale src/preferences/locale - jonas