[haiku-commits] r41126 - in haiku/trunk: headers/os/locale src/apps/deskbar src/bin src/kits/locale src/kits/tracker

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 27 Mar 2011 20:38:06 +0200 (CEST)

Author: kirilla
Date: 2011-03-27 20:38:05 +0200 (Sun, 27 Mar 2011)
New Revision: 41126
Changeset: https://dev.haiku-os.org/changeset/41126

Modified:
   haiku/trunk/headers/os/locale/LocaleRoster.h
   haiku/trunk/src/apps/deskbar/BarApp.cpp
   haiku/trunk/src/bin/query.cpp
   haiku/trunk/src/kits/locale/LocaleRoster.cpp
   haiku/trunk/src/kits/tracker/FilePanelPriv.cpp
   haiku/trunk/src/kits/tracker/InfoWindow.cpp
   haiku/trunk/src/kits/tracker/Model.cpp
   haiku/trunk/src/kits/tracker/Model.h
Log:
* Extend the Model class with a method bool HasLocalizedName().
* Disallow renaming of entries with localized names for now - this is meant to 
be temporary - and so far only in Tracker's Info window. Renames do not result 
in a change, visually, as the localized name hides the real name, and results 
in a bad user experience. One could possibly allow renames of the localized 
name, writing it back to the catalog. I've experimented with using 
BCatalogAddOn::SetString() but haven't been able to make it stick yet.
* Disallow renaming Trash in Tracker's Info window via Command-E.
* Adjust the argument order of BLocaleRoster::GetLocalizedFileName().
* Add a BLocaleRoster::GetLocalizedFileName() variant to look up another app's 
name given its signature and unlocalized, canonical name.

Modified: haiku/trunk/headers/os/locale/LocaleRoster.h
===================================================================
--- haiku/trunk/headers/os/locale/LocaleRoster.h        2011-03-27 15:21:15 UTC 
(rev 41125)
+++ haiku/trunk/headers/os/locale/LocaleRoster.h        2011-03-27 18:38:05 UTC 
(rev 41126)
@@ -68,10 +68,14 @@
 
                        bool                            
IsFilesystemTranslationPreferred() const;
 
-                       status_t                        
GetLocalizedFileName(const entry_ref& ref,
-                                                                       
BString& localizedFileName,
+                       status_t                        
GetLocalizedFileName(BString& localizedFileName,
+                                                                       const 
entry_ref& ref,
                                                                        bool 
traverse = false);
 
+                       status_t                        
GetLocalizedFileName(BString& localizedFileName,
+                                                                       const 
char* signature, const char* context,
+                                                                       const 
char* string);
+
        static  const char*                     kCatLangAttr;
        static  const char*                     kCatSigAttr;
        static  const char*                     kCatFingerprintAttr;
@@ -82,6 +86,10 @@
 private:
        static  BCatalog*                       _GetCatalog(BCatalog* catalog,
                                                                        vint32* 
catalogInitStatus);
+
+                       status_t                        
_PrepareCatalogEntry(const entry_ref& ref,
+                                                                       
BString& signature, BString& context,
+                                                                       
BString& string, bool traverse);
 };
 
 

Modified: haiku/trunk/src/apps/deskbar/BarApp.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-27 15:21:15 UTC (rev 
41125)
+++ haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-27 18:38:05 UTC (rev 
41126)
@@ -620,7 +620,7 @@
 
        BString name;
        if (!gLocalizedNamePreferred
-               || BLocaleRoster::Default()->GetLocalizedFileName(*ref, name) 
!= B_OK)
+               || BLocaleRoster::Default()->GetLocalizedFileName(name, *ref) 
!= B_OK)
                name = ref->name;
 
        BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),

Modified: haiku/trunk/src/bin/query.cpp
===================================================================
--- haiku/trunk/src/bin/query.cpp       2011-03-27 15:21:15 UTC (rev 41125)
+++ haiku/trunk/src/bin/query.cpp       2011-03-27 18:38:05 UTC (rev 41126)
@@ -94,7 +94,7 @@
                        entry_ref ref;
 
                        if (entry.GetRef(&ref) != B_OK || 
BLocaleRoster::Default()
-                               ->GetLocalizedFileName(ref, string) != B_OK)
+                               ->GetLocalizedFileName(string, ref) != B_OK)
                                continue;
 
                        if (string.IFindFirst(predicate) < 0)

Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2011-03-27 15:21:15 UTC 
(rev 41125)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2011-03-27 18:38:05 UTC 
(rev 41126)
@@ -381,11 +381,10 @@
 }
 
 
-/*!    \brief Looks up a localized filename in a catalog, using attribute data
-               on the entry.
-       \param ref An entry_ref with an attribute holding data for catalog 
lookup.
+/*!    \brief Looks up a localized filename from a catalog.
        \param localizedFileName A pre-allocated BString object for the result
                of the lookup.
+       \param ref An entry_ref with an attribute holding data for catalog 
lookup.
        \param traverse A boolean to decide if symlinks are to be traversed.
        \return
        - \c B_OK: success
@@ -400,9 +399,57 @@
        Lookup fails if a comment is present in the catalog entry.
 */
 status_t
-BLocaleRoster::GetLocalizedFileName(const entry_ref& ref,
-       BString& localizedFileName, bool traverse)
+BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
+       const entry_ref& ref, bool traverse)
 {
+       BString signature;
+       BString context;
+       BString string;
+       
+       status_t status = _PrepareCatalogEntry(ref, signature, context, string,
+               traverse);
+
+       if (status != B_OK)
+               return status;
+
+       return GetLocalizedFileName(localizedFileName, signature, context, 
string);
+}
+
+
+/*!    \brief Looks up a localized filename from a catalog.
+       \param localizedFileName A pre-allocated BString object for the result
+               of the lookup.
+       \param signature The "x-vnd..." part of an application signature.
+       \param context A catalog context. Likely 
B_TRANSLATE_SYSTEM_NAME_CONTEXT.
+       \param string A catalog string entry. Likely the unlocalized app name.
+       \return
+       - \c B_OK: success
+       - \c B_ENTRY_NOT_FOUND: failure. Catalog entry not found in catalog, etc
+       - other error codes: failure
+
+       Lookup is done for the top preferred language, only.
+       Lookup fails if a comment is present in the catalog entry.
+*/
+status_t
+BLocaleRoster::GetLocalizedFileName(BString& localizedFileName,
+       const char* signature, const char* context, const char* string)
+{
+       BCatalog catalog(signature);
+
+       const char* temp = catalog.GetString(string, context);
+
+       if (temp == NULL)
+               return B_ENTRY_NOT_FOUND;
+
+       localizedFileName = temp;
+       return B_OK;
+}
+
+
+status_t
+BLocaleRoster::_PrepareCatalogEntry(const entry_ref& ref, BString& signature,
+       BString& context, BString& string, bool traverse)
+{
        BEntry entry(&ref, traverse);
        if (!entry.Exists())
                return B_ENTRY_NOT_FOUND;
@@ -412,44 +459,26 @@
        if (status != B_OK)
                return status;
 
-       attr_info attr;
-       status = node.GetAttrInfo("SYS:NAME", &attr);
+       status = node.ReadAttrString("SYS:NAME", &signature);
        if (status != B_OK)
                return status;
 
-       char attribute[attr.size + 1];
-       ssize_t bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute,
-               attr.size);
-
-       if (bytes < 0)
-               return bytes;
-       
-       if (bytes == 0 || bytes != attr.size)
+       int32 first = signature.FindFirst(':');
+       int32 last = signature.FindLast(':');
+       if (first == last)
                return B_ENTRY_NOT_FOUND;
 
-       attribute[bytes] = '\0';
+       context = signature;
+       string = signature;
 
-       char* signature = attribute;
-       char* context = strchr(signature, ':');
-       if (context == NULL)
-               return B_ENTRY_NOT_FOUND;
+       signature.Truncate(first);
+       context.Truncate(last);
+       context.Remove(0, first + 1);
+       string.Remove(0, last + 1);
 
-       context[0] = '\0';
-       context++;
-
-       char* string = strchr(context, ':');
-       if (string == NULL)
+       if (signature.Length() == 0 || context.Length() == 0
+               || string.Length() == 0)
                return B_ENTRY_NOT_FOUND;
 
-       string[0] = '\0';
-       string++;
-
-       BCatalog catalog(signature);
-
-       const char* temp = catalog.GetString(string, context);
-       if (temp == NULL)
-               return B_ENTRY_NOT_FOUND;
-
-       localizedFileName = temp;
        return B_OK;
 }

Modified: haiku/trunk/src/kits/tracker/FilePanelPriv.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/FilePanelPriv.cpp      2011-03-27 15:21:15 UTC 
(rev 41125)
+++ haiku/trunk/src/kits/tracker/FilePanelPriv.cpp      2011-03-27 18:38:05 UTC 
(rev 41126)
@@ -782,7 +782,7 @@
        if (be_app->GetAppInfo(&info) == B_OK) {
                if (!gLocalizedNamePreferred
                        || BLocaleRoster::Default()->GetLocalizedFileName(
-                               info.ref, title, false) != B_OK)
+                               title, info.ref, false) != B_OK)
                        title = info.ref.name;
                title << ": ";
        }

Modified: haiku/trunk/src/kits/tracker/InfoWindow.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/InfoWindow.cpp 2011-03-27 15:21:15 UTC (rev 
41125)
+++ haiku/trunk/src/kits/tracker/InfoWindow.cpp 2011-03-27 18:38:05 UTC (rev 
41126)
@@ -299,7 +299,9 @@
        if (list)
                list->AddItem(this);
 
-       AddShortcut('E', 0, new BMessage(kEditItem));
+       if (!model->IsTrash() && !model->HasLocalizedName())
+               AddShortcut('E', 0, new BMessage(kEditItem));
+
        AddShortcut('O', 0, new BMessage(kOpenSelection));
        AddShortcut('U', 0, new BMessage(kUnmountVolume));
        AddShortcut('P', 0, new BMessage(kPermissionsSelected));
@@ -1222,6 +1224,7 @@
        } else if (fTitleRect.Contains(point)) {
                // You can't change the name of the trash
                if (!fModel->IsTrash()
+                       && !fModel->HasLocalizedName()
                        && ConfirmChangeIfWellKnownDirectory(&entry,
                                B_TRANSLATE_COMMENT("rename", "As in 'If you 
rename ...'"),
                                B_TRANSLATE_COMMENT("rename", "As in 'To rename 
...'"), true)
@@ -2037,9 +2040,11 @@
                new BMessage(kOpenSelection), 'O'));
 
        if (!model.IsTrash()) {
-               parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
-                       new BMessage(kEditItem), 'E'));
-               parent->AddSeparatorItem();
+               if (!fModel->HasLocalizedName()) {
+                       parent->AddItem(new BMenuItem(B_TRANSLATE("Edit name"),
+                               new BMessage(kEditItem), 'E'));
+                       parent->AddSeparatorItem();
+               }
                if (fModel->IsVolume()) {
                        BMenuItem* item = new BMenuItem(B_TRANSLATE("Unmount"),
                                new BMessage(kUnmountVolume), 'U');

Modified: haiku/trunk/src/kits/tracker/Model.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/Model.cpp      2011-03-27 15:21:15 UTC (rev 
41125)
+++ haiku/trunk/src/kits/tracker/Model.cpp      2011-03-27 18:38:05 UTC (rev 
41126)
@@ -568,7 +568,7 @@
 Model::CacheLocalizedName()
 {
        if (BLocaleRoster::Default()->GetLocalizedFileName(
-                       fEntryRef, fLocalizedName, true) == B_OK)
+                       fLocalizedName, fEntryRef, true) == B_OK)
                fHasLocalizedName = true;
        else
                fHasLocalizedName = false;

Modified: haiku/trunk/src/kits/tracker/Model.h
===================================================================
--- haiku/trunk/src/kits/tracker/Model.h        2011-03-27 15:21:15 UTC (rev 
41125)
+++ haiku/trunk/src/kits/tracker/Model.h        2011-03-27 18:38:05 UTC (rev 
41126)
@@ -204,6 +204,9 @@
 
                bool Mimeset(bool force);
                        // returns true if mime type changed
+
+               bool HasLocalizedName() const;
+
        private:
                status_t OpenNodeCommon(bool writable);
                void SetupBaseType();
@@ -451,6 +454,13 @@
 }
 
 
+inline bool
+Model::HasLocalizedName() const
+{
+       return fHasLocalizedName;
+}
+
+
 inline
 ModelNodeLazyOpener::ModelNodeLazyOpener(Model *model, bool writable, bool 
openLater)
        :       fModel(model),


Other related posts:

  • » [haiku-commits] r41126 - in haiku/trunk: headers/os/locale src/apps/deskbar src/bin src/kits/locale src/kits/tracker - jonas