From f5c0a9970a3acbabb2289a20fdedcc9d1c7b6b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Sundstr=C3=B6m?= Date: Thu, 3 Mar 2011 20:58:58 +0000 Subject: [PATCH] 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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40796 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/codycam/Jamfile | 5 +++ src/apps/deskbar/BarApp.cpp | 6 ++- src/kits/tracker/Utilities.cpp | 75 ++++++++++++++++++++++++++++++++++ src/kits/tracker/Utilities.h | 2 + 4 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/apps/codycam/Jamfile b/src/apps/codycam/Jamfile index 0e2207a9b9..7f911b2d4e 100644 --- a/src/apps/codycam/Jamfile +++ b/src/apps/codycam/Jamfile @@ -26,3 +26,8 @@ DoCatalogs CodyCam : SftpClient.cpp VideoConsumer.cpp ; + +AddCatalogEntryAttribute CodyCam + : + "x-vnd.Haiku.CodyCam:CodyCam:CodyCam" +; diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 264706873d..5825f2a9d4 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -635,8 +635,12 @@ 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) + 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) diff --git a/src/kits/tracker/Utilities.cpp b/src/kits/tracker/Utilities.cpp index c02c4c1aa0..8949bbc45a 100644 --- a/src/kits/tracker/Utilities.cpp +++ b/src/kits/tracker/Utilities.cpp @@ -44,6 +44,7 @@ All rights reserved. #endif #include +#include #include #include #include @@ -1469,6 +1470,80 @@ GetFileIconFromAttr(BNode *file, BBitmap *result, icon_size size) } +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) { diff --git a/src/kits/tracker/Utilities.h b/src/kits/tracker/Utilities.h index d65edfccca..b71e52e26d 100644 --- a/src/kits/tracker/Utilities.h +++ b/src/kits/tracker/Utilities.h @@ -523,6 +523,8 @@ status_t GetAppSignatureFromAttr(BFile *, char *); 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);