From febccfbfc6ec9b227689dbf2e2531f9a19ca0cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 11 Feb 2005 04:37:01 +0000 Subject: [PATCH] If update_mime_info() could not determine the MIME type, it now just set the information it has from the translator itself. Maybe this functionality should be done in the Translation Kit as well if the output stream is a file. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11336 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bin/translate.cpp | 49 +++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/apps/bin/translate.cpp b/src/apps/bin/translate.cpp index 9a5df8e559..705996998c 100644 --- a/src/apps/bin/translate.cpp +++ b/src/apps/bin/translate.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,7 @@ class Translator { status_t Indirectly(BFile &input, BFile &output); status_t FindPath(const translation_format *info, BPositionIO &stream, TypeList &typesSeen, TypeList &path, double &pathQuality); + status_t GetMimeTypeFromCode(uint32 type, char *mimeType); private: BTranslatorRoster *fRoster; @@ -257,6 +259,17 @@ Translator::Translate() // add filetype attribute update_mime_info(fOutputPath.Path(), false, true, false); + + char mimeType[B_ATTR_NAME_LENGTH]; + BNode node(fOutputPath.Path()); + BNodeInfo info(&node); + if (info.GetType(mimeType) != B_OK || !strcasecmp(mimeType, B_FILE_MIME_TYPE)) { + // the Registrar couldn't find a type for this file + // so let's use the information we have from the + // translator + if (GetMimeTypeFromCode(fOutputFormat, mimeType) == B_OK) + info.SetType(mimeType); + } } else { fprintf(stderr, "%s: translating failed: %s\n", gProgramName, strerror(status)); @@ -437,6 +450,36 @@ Translator::FindPath(const translation_format *format, BPositionIO &stream, } +status_t +Translator::GetMimeTypeFromCode(uint32 type, char *mimeType) +{ + translator_id *ids = NULL; + int32 count; + status_t status = fRoster->GetAllTranslators(&ids, &count); + if (status != B_OK) + return status; + + status = B_NO_TRANSLATOR; + + for (int32 i = 0; i < count; i++) { + const translation_format *format = NULL; + int32 formatCount = 0; + fRoster->GetOutputFormats(ids[i], &format, &formatCount); + + for (int32 j = 0; j < formatCount; j++) { + if (type == format[j].type) { + strcpy(mimeType, format[j].MIME); + status = B_OK; + break; + } + } + } + + delete[] ids; + return status; +} + + // #pragma mark - @@ -596,9 +639,9 @@ TranslateApp::GetTypeCodeForOutputMime(const char *mime) int32 count = 0; fTranslatorRoster->GetOutputFormats(fTranslatorArray[i], &format, &count); - for (int32 ii = 0; ii < count; ii++) { - if (!strcmp(mime, format[ii].MIME)) - return format[ii].type; + for (int32 j = 0; j < count; j++) { + if (!strcmp(mime, format[j].MIME)) + return format[j].type; } }