From 83bf0add93ee5d4992570752bb1751691cbbdaff Mon Sep 17 00:00:00 2001 From: shatty Date: Thu, 11 Nov 2004 08:47:02 +0000 Subject: [PATCH] use textencodings git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9912 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/bemail/Header.cpp | 69 +++++++++++++++++++++-------- src/apps/bemail/Jamfile | 3 +- src/apps/bemail/Mail.cpp | 28 ++++++------ src/apps/bemail/Prefs.cpp | 90 ++++++++++++++++++-------------------- 4 files changed, 108 insertions(+), 82 deletions(-) diff --git a/src/apps/bemail/Header.cpp b/src/apps/bemail/Header.cpp index b67463d11d..98ff72dba4 100644 --- a/src/apps/bemail/Header.cpp +++ b/src/apps/bemail/Header.cpp @@ -56,6 +56,12 @@ All rights reserved. #include #include +#include +#include +#include + +using namespace BPrivate; + #include "Mail.h" #include "Header.h" #include "Utilities.h" @@ -154,27 +160,52 @@ THeaderView::THeaderView ( // (because the adjacent pop-up menu can't resize dynamically due to a BeOS // bug). - bool marked; - float widestCharacterSet; + float widestCharacterSet = 0; + bool marked_charset = false; + BMenuItem * item; fEncodingMenu = new BPopUpMenu (B_EMPTY_STRING); - marked = false; - widestCharacterSet = 0; - for (int32 i = 0; true; i++) { - if (kEncodings[i].flavor == B_MAIL_NULL_CONVERSION && (resending || !fIncoming)) - break; // Composing a new message, don't display last "Automatic" item. - msg = new BMessage(kMsgEncoding); - msg->AddInt32 ("charset", kEncodings[i].flavor); - BMenuItem *item = new BMenuItem (kEncodings[i].name, msg); - if (kEncodings[i].flavor == fCharacterSetUserSees && !marked) { - item->SetMarked (true); - marked = true; + + BCharacterSetRoster roster; + BCharacterSet charset; + while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { + BString name(charset.GetPrintName()); + const char * mime = charset.GetMIMEName(); + if (mime) { + name.Append(" ("); + name.Append(mime); + name.Append(")"); } - fEncodingMenu->AddItem (item); - if (font.StringWidth (kEncodings[i].name) > widestCharacterSet) - widestCharacterSet = font.StringWidth (kEncodings[i].name); - if (kEncodings[i].flavor == B_MAIL_NULL_CONVERSION) - break; // No more character set choices after this one, stop. + msg = new BMessage(kMsgEncoding); + if ((mime == 0) || (strcmp(mime, "UTF-8") != 0)) { + msg->AddInt32("charset", charset.GetConversionID()); + } else { + msg->AddInt32("charset", B_MAIL_UTF8_CONVERSION); + } + fEncodingMenu->AddItem(item = new BMenuItem(name.String(), msg)); + if (charset.GetConversionID() == fCharacterSetUserSees && !marked_charset) { + item->SetMarked(true); + marked_charset = true; + } + if (font.StringWidth(name.String()) > widestCharacterSet) + widestCharacterSet = font.StringWidth(name.String()); + } + + msg = new BMessage(kMsgEncoding); + msg->AddInt32("charset", B_MAIL_US_ASCII_CONVERSION); + fEncodingMenu->AddItem(item = new BMenuItem("US-ASCII", msg)); + if (fCharacterSetUserSees == B_MAIL_US_ASCII_CONVERSION && !marked_charset) { + item->SetMarked(true); + marked_charset = true; + } + + if (!resending && fIncoming) { + // reading a message, display the Automatic item + fEncodingMenu->AddSeparatorItem(); + msg = new BMessage(kMsgEncoding); + msg->AddInt32("charset", B_MAIL_NULL_CONVERSION); + fEncodingMenu->AddItem(item = new BMenuItem("Automatic", msg)); + item->SetMarked(true); } // First line of the header, From for reading e-mails (includes the @@ -254,7 +285,7 @@ THeaderView::THeaderView ( BList chains; if (GetOutboundMailChains(&chains) >= B_OK) { - marked = false; + bool marked = false; for (int32 i = 0;i < chains.CountItems();i++) { BMailChain *chain = (BMailChain *)chains.ItemAt(i); diff --git a/src/apps/bemail/Jamfile b/src/apps/bemail/Jamfile index 6917ed11de..bcd6b38c57 100644 --- a/src/apps/bemail/Jamfile +++ b/src/apps/bemail/Jamfile @@ -1,6 +1,7 @@ SubDir OBOS_TOP src apps bemail ; UsePrivateHeaders mail ; +UsePrivateHeaders textencoding ; AddResources BeMail : versioning.rdef pictures.rdef ; App BeMail : @@ -21,7 +22,7 @@ App BeMail : Words.cpp KUndoBuffer.cpp ; -LinkSharedOSLibs BeMail : be tracker stdc++.r4 libmail.so ; +LinkSharedOSLibs BeMail : be tracker stdc++.r4 libmail.so libtextencoding.so ; Package haiku-maildaemon-cvs : BeMail : diff --git a/src/apps/bemail/Mail.cpp b/src/apps/bemail/Mail.cpp index 71b1e87b56..8b887913a0 100644 --- a/src/apps/bemail/Mail.cpp +++ b/src/apps/bemail/Mail.cpp @@ -66,6 +66,10 @@ All rights reserved. #include #include +#include + +using namespace BPrivate ; + #ifndef BONE # include #endif @@ -241,7 +245,7 @@ TMailApp::AboutRequested() (new BAlert("", "BeMail\nBy Robert Polic\n\n" "Enhanced by Axel Dörfler and the Dr. Zoidberg crew\n\n" - "Mail.cpp $Revision: 1.3 $\n" + "Mail.cpp $Revision: 1.4 $\n" "Compiled on " __DATE__ " at " __TIME__ ".", "Close"))->Go(); } @@ -927,13 +931,10 @@ TMailApp::LoadSavePrefs(bool loadThem) } prefsFile.Read(&gMailCharacterSet, sizeof(int32)); - for (uint32 index = 0; true; index++) { - if (kEncodings[index].flavor == B_MAIL_NULL_CONVERSION) { - gMailCharacterSet = B_MS_WINDOWS_CONVERSION; - break; - } - if (kEncodings[index].flavor == gMailCharacterSet) - break; + if ((gMailCharacterSet != B_MAIL_UTF8_CONVERSION) && + (gMailCharacterSet != B_MAIL_US_ASCII_CONVERSION) && + (BCharacterSetRoster::GetCharacterSetByConversionID(gMailCharacterSet) == NULL)) { + gMailCharacterSet = B_MS_WINDOWS_CONVERSION; } if (prefsFile.Read(&len, sizeof(int32)) > 0) @@ -1072,13 +1073,10 @@ TMailApp::LoadSavePrefs(bool loadThem) if (loadThem) { if (settingsMsg.FindInt32(fieldName, &tempInt32) == B_OK) gMailCharacterSet = tempInt32; - for (uint32 index = 0; true; index++) { - if (kEncodings[index].flavor == B_MAIL_NULL_CONVERSION) { - gMailCharacterSet = B_MS_WINDOWS_CONVERSION; - break; // Don't use unknown character sets. - } - if (kEncodings[index].flavor == gMailCharacterSet) - break; + if ((gMailCharacterSet != B_MAIL_UTF8_CONVERSION) && + (gMailCharacterSet != B_MAIL_US_ASCII_CONVERSION) && + (BCharacterSetRoster::GetCharacterSetByConversionID(gMailCharacterSet) == NULL)) { + gMailCharacterSet = B_MS_WINDOWS_CONVERSION; } } else if (errorCode == B_OK) errorCode = settingsMsg.AddInt32(fieldName, gMailCharacterSet); diff --git a/src/apps/bemail/Prefs.cpp b/src/apps/bemail/Prefs.cpp index c24db6a13d..31c7e3ef03 100644 --- a/src/apps/bemail/Prefs.cpp +++ b/src/apps/bemail/Prefs.cpp @@ -50,6 +50,12 @@ All rights reserved. #include #include +#include +#include +#include + +using namespace BPrivate; + #include "Mail.h" #include "Prefs.h" @@ -98,41 +104,6 @@ enum P_MESSAGES {P_OK = 128, P_CANCEL, P_REVERT, P_FONT, extern BPoint prefs_window; -const EncodingItem kEncodings[] = -{ - // B_MS_WINDOWS is a superset of B_ISO1, MS mailers lie and send Windows - // chars as ISO-1 we still don't want to pretend we would use the Windows - // 1252 codetable; this should only be done at decoding stage, axeld. - // {"ISO-8859-1", B_MS_WINDOWS_CONVERSION}, - {"ISO-8859-1 (Latin-1)", B_ISO1_CONVERSION}, - {"ISO-8859-2", B_ISO2_CONVERSION}, - {"ISO-8859-3", B_ISO3_CONVERSION}, - {"ISO-8859-4", B_ISO4_CONVERSION}, - {"ISO-8859-5", B_ISO5_CONVERSION}, - {"ISO-8859-6", B_ISO6_CONVERSION}, - {"ISO-8859-7", B_ISO7_CONVERSION}, - {"ISO-8859-8", B_ISO8_CONVERSION}, - {"ISO-8859-9", B_ISO9_CONVERSION}, - {"ISO-8859-10", B_ISO10_CONVERSION}, - {"ISO-8859-13", B_ISO13_CONVERSION}, - {"ISO-8859-14", B_ISO14_CONVERSION}, - {"ISO-8859-15", B_ISO15_CONVERSION}, - {"SHIFT-JIS (obsolete)", B_SJIS_CONVERSION}, - {"ISO-2022-JP", B_JIS_CONVERSION}, - {"EUC-JP (obsolete)", B_EUC_CONVERSION}, - {"EUC-KR", B_EUC_KR_CONVERSION}, - {"KOI8-R", B_KOI8R_CONVERSION}, - {"Windows-1251",B_MS_WINDOWS_1251_CONVERSION}, - {"Windows-1252 (\"ANSI\")",B_MS_WINDOWS_CONVERSION}, - {"DOS-437 (common)", B_MS_DOS_CONVERSION}, - {"DOS-866 (rarer)", B_MS_DOS_866_CONVERSION}, - {"Macintosh Roman", B_MAC_ROMAN_CONVERSION}, - {"US-ASCII", B_MAIL_US_ASCII_CONVERSION}, - {"UTF-8 (BeOS)", B_MAIL_UTF8_CONVERSION}, - - {"Automatic", B_MAIL_NULL_CONVERSION /* marks end of list, only visible when decoding */} -}; - #define ATTRIBUTE_ON_TEXT MDR_DIALECT_CHOICE ("Include BeOS Attributes in Attachments", "BeOSの属性を付ける") #define ATTRIBUTE_OFF_TEXT MDR_DIALECT_CHOICE ("No BeOS Attributes, just Plain Data", "BeOSの属性を付けない(データのみ)") @@ -470,13 +441,16 @@ TPrefsWindow::MessageReceived(BMessage *msg) if (item) item->SetMarked(true); - for (uint32 index = 0; kEncodings[index].flavor != B_MAIL_NULL_CONVERSION; index++) - { - if (kEncodings[index].flavor == *fNewEncoding) - { - item = fEncodingMenu->FindItem(kEncodings[index].name); - if (item) - item->SetMarked(true); + uint32 index = 0; + while ((item = fEncodingMenu->ItemAt(index++)) != NULL) { + BMessage * message = item->Message(); + if (message == NULL) { + continue; + } + int32 encoding; + if ((message->FindInt32("encoding", &encoding) == B_OK) && + ((uint32)encoding == *fNewEncoding)) { + item->SetMarked(true); break; } } @@ -905,19 +879,41 @@ TPrefsWindow::BuildColoredQuotesMenu(bool quote) BPopUpMenu * TPrefsWindow::BuildEncodingMenu(uint32 encoding) { - uint32 loop; BMenuItem *item; BMessage *msg; BPopUpMenu *menu; menu = new BPopUpMenu(""); - for (loop = 0; kEncodings[loop].flavor != B_MAIL_NULL_CONVERSION; loop++) { + + BCharacterSetRoster roster; + BCharacterSet charset; + while (roster.GetNextCharacterSet(&charset) == B_NO_ERROR) { + BString name(charset.GetPrintName()); + const char * mime = charset.GetMIMEName(); + if (mime) { + name.Append(" ("); + name.Append(mime); + name.Append(")"); + } msg = new BMessage(P_ENC); - msg->AddInt32("encoding", kEncodings[loop].flavor); - menu->AddItem(item = new BMenuItem(kEncodings[loop].name, msg)); - if (encoding == kEncodings[loop].flavor) + if ((mime == 0) || (strcmp(mime, "UTF-8") != 0)) { + msg->AddInt32("encoding", charset.GetConversionID()); + } else { + msg->AddInt32("encoding", B_MAIL_UTF8_CONVERSION); + } + menu->AddItem(item = new BMenuItem(name.String(), msg)); + if (charset.GetConversionID() == encoding) { item->SetMarked(true); + } } + + msg = new BMessage(P_ENC); + msg->AddInt32("encoding", B_MAIL_US_ASCII_CONVERSION); + menu->AddItem(item = new BMenuItem("US-ASCII", msg)); + if (encoding == B_MAIL_US_ASCII_CONVERSION) { + item->SetMarked(true); + } + return menu; }