[haiku-commits] r40796 - in haiku/trunk/src: apps/codycam apps/deskbar kits/tracker

  • From: jonas@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 3 Mar 2011 21:58:59 +0100 (CET)

Author: kirilla
Date: 2011-03-03 21:58:58 +0100 (Thu, 03 Mar 2011)
New Revision: 40796
Changeset: http://dev.haiku-os.org/changeset/40796

Modified:
   haiku/trunk/src/apps/codycam/Jamfile
   haiku/trunk/src/apps/deskbar/BarApp.cpp
   haiku/trunk/src/kits/tracker/Utilities.cpp
   haiku/trunk/src/kits/tracker/Utilities.h
Log:
Support for showing localized app entries in Deskbar. Just the app entries so 
far, and not yet the items in the leaf menu. Please review.

Modified: haiku/trunk/src/apps/codycam/Jamfile
===================================================================
--- haiku/trunk/src/apps/codycam/Jamfile        2011-03-03 20:10:40 UTC (rev 
40795)
+++ haiku/trunk/src/apps/codycam/Jamfile        2011-03-03 20:58:58 UTC (rev 
40796)
@@ -26,3 +26,8 @@
        SftpClient.cpp
        VideoConsumer.cpp
 ;
+
+AddCatalogEntryAttribute CodyCam
+       :
+       "x-vnd.Haiku.CodyCam:CodyCam:CodyCam"
+;

Modified: haiku/trunk/src/apps/deskbar/BarApp.cpp
===================================================================
--- haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-03 20:10:40 UTC (rev 
40795)
+++ haiku/trunk/src/apps/deskbar/BarApp.cpp     2011-03-03 20:58:58 UTC (rev 
40796)
@@ -635,8 +635,12 @@
        BFile file(ref, B_READ_ONLY);
        BAppFileInfo appMime(&file);
 
+       BString name;   
+       if (GetLocalizedFileName(*ref, name) != B_OK)
+               name = ref->name;
+               
        BarTeamInfo* barInfo = new BarTeamInfo(new BList(), flags, strdup(sig),
-               new BBitmap(kIconSize, kIconFormat), strdup(ref->name));
+               new BBitmap(kIconSize, kIconFormat), strdup(name.String()));
 
        barInfo->teams->AddItem((void*)team);
        if (appMime.GetIcon(barInfo->icon, B_MINI_ICON) != B_OK)

Modified: haiku/trunk/src/kits/tracker/Utilities.cpp
===================================================================
--- haiku/trunk/src/kits/tracker/Utilities.cpp  2011-03-03 20:10:40 UTC (rev 
40795)
+++ haiku/trunk/src/kits/tracker/Utilities.cpp  2011-03-03 20:58:58 UTC (rev 
40796)
@@ -44,6 +44,7 @@
 #endif
 
 #include <Bitmap.h>
+#include <Catalog.h>
 #include <Debug.h>
 #include <Directory.h>
 #include <fs_attr.h>
@@ -1469,6 +1470,80 @@
 }
 
 
+status_t
+GetLocalizedFileName(entry_ref& ref, BString& localizedFileName, bool traverse)
+{
+       // Looks up a localized filename, by reading a catalog signature,
+       // context and string to be translated, from an attribute on the 
+       // entry_ref, and using these to look up a translation in the catalog
+       // of the top preferred language.
+
+       // Attribute format:  "signature:context:string"
+       // (no colon in any of signature, context and string)
+
+       // It fails when a comment is present in the catalog.
+
+       status_t status;
+
+       BEntry entry(&ref, traverse);
+       if (!entry.Exists())
+               return B_ENTRY_NOT_FOUND;
+
+       BNode node(&entry);
+       status = node.InitCheck();
+       if (status != B_OK)
+               return status;
+
+       attr_info attr;
+       ssize_t bytes = 0;
+
+       status = node.GetAttrInfo("SYS:NAME", &attr);
+       if (status != B_OK)
+               return status;
+
+       char attribute[attr.size + 1];
+       bytes = node.ReadAttr("SYS:NAME", B_MIME_TYPE, 0, &attribute, 
attr.size);
+
+       if (bytes < 0)
+               return bytes;
+       
+       if (bytes == 0 || bytes != attr.size)
+               return B_ENTRY_NOT_FOUND;
+
+       attribute[bytes] = '\0';
+
+       char* signature = attribute;
+       char* context = NULL;
+       char* string = NULL;
+
+       ssize_t i = 0;
+       for (; i < bytes; i++) {
+               if (signature[i] == ':') {
+                       signature[i] = '\0';
+                       context = &signature[i + 1];
+                       break;
+               }
+       }
+
+       for (; i < bytes; i++) {
+               if (signature[i] == ':') {
+                       signature[i] = '\0';
+                       string = &signature[i + 1];
+                       break;
+               }
+       }
+
+       BCatalog catalog(signature);
+
+       const char* temp = catalog.GetString(string, context);
+       if (temp == NULL)
+               return B_ENTRY_NOT_FOUND;
+
+       localizedFileName = temp;
+       return B_OK;
+}
+
+
 void
 PrintToStream(rgb_color color)
 {

Modified: haiku/trunk/src/kits/tracker/Utilities.h
===================================================================
--- haiku/trunk/src/kits/tracker/Utilities.h    2011-03-03 20:10:40 UTC (rev 
40795)
+++ haiku/trunk/src/kits/tracker/Utilities.h    2011-03-03 20:58:58 UTC (rev 
40796)
@@ -523,6 +523,8 @@
 status_t GetAppIconFromAttr(BFile *, BBitmap *, icon_size);
 status_t GetFileIconFromAttr(BNode *, BBitmap *, icon_size);
 
+status_t GetLocalizedFileName(entry_ref& ref, BString& localizedFileName,
+       bool traverse = false);
 
 // debugging
 void HexDump(const void *buffer, int32 length);


Other related posts: