зеркало из https://github.com/mozilla/pjs.git
Bug 369913 Remove Duplicated code in nsIImportService and nsMsgI18N.h/cpp. r/sr=bienvenu
This commit is contained in:
Родитель
881b2fc47a
Коммит
22bb78dd6e
|
@ -69,7 +69,6 @@ REQUIRES = xpcom \
|
|||
msgbaseutil \
|
||||
mime \
|
||||
intl \
|
||||
import \
|
||||
windowwatcher \
|
||||
uriloader \
|
||||
embed_base \
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
#include "nsIOutputStream.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "msgCore.h"
|
||||
#include "nsIImportService.h"
|
||||
#include "nsMsgI18N.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
#include "plstr.h"
|
||||
|
@ -507,9 +507,6 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const
|
|||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr <nsIImportService> importService = do_GetService(NS_IMPORTSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIOutputStream> outputStream;
|
||||
rv = NS_NewLocalFileOutputStream(getter_AddRefs(outputStream),
|
||||
aLocalFile,
|
||||
|
@ -542,7 +539,9 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const
|
|||
if (NS_FAILED(bundle->GetStringFromID(EXPORT_ATTRIBUTES_TABLE[i].plainTextStringID, getter_Copies(columnName))))
|
||||
columnName.AppendInt(EXPORT_ATTRIBUTES_TABLE[i].plainTextStringID);
|
||||
|
||||
importService->SystemStringFromUnicode(columnName.get(), revisedName);
|
||||
rv = nsMsgI18NConvertFromUnicode(nsMsgI18NFileSystemCharset(),
|
||||
columnName, revisedName);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = outputStream->Write(revisedName.get(),
|
||||
revisedName.Length(),
|
||||
|
@ -618,7 +617,9 @@ nsAddressBook::ExportDirectoryToDelimitedText(nsIAbDirectory *aDirectory, const
|
|||
newValue.AppendLiteral("\"");
|
||||
}
|
||||
|
||||
rv = importService->SystemStringFromUnicode(newValue.get(), valueCStr);
|
||||
rv = nsMsgI18NConvertFromUnicode(nsMsgI18NFileSystemCharset(),
|
||||
newValue, valueCStr);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION(0, "failed to convert string to system charset. use LDIF");
|
||||
|
|
|
@ -55,9 +55,8 @@ interface nsIImportGeneric;
|
|||
interface nsIImportFieldMap;
|
||||
|
||||
[ref] native nsStringRef(nsString);
|
||||
[ref] native nsCStringRef(nsCString);
|
||||
|
||||
[scriptable, uuid(50d7ea80-1726-11d3-a206-00a0cc26da63)]
|
||||
[scriptable, uuid(c035e4a5-6dcc-4c70-8ff7-5b740bd2ed2b)]
|
||||
interface nsIImportService : nsISupports
|
||||
{
|
||||
void DiscoverModules();
|
||||
|
@ -76,8 +75,6 @@ interface nsIImportService : nsISupports
|
|||
nsIImportGeneric CreateNewGenericAddressBooks();
|
||||
|
||||
[noscript] void SystemStringToUnicode( in string sysStr, in nsStringRef uniStr);
|
||||
[noscript] void SystemStringFromUnicode(in wstring uniStr, in nsCStringRef sysStr);
|
||||
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
|
|
@ -204,70 +204,6 @@ NS_IMETHODIMP nsImportService::SystemStringToUnicode(const char *sysStr, nsStrin
|
|||
return( rv);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::SystemStringFromUnicode(const PRUnichar *uniStr, nsCString & sysStr)
|
||||
{
|
||||
nsresult rv;
|
||||
if (m_sysCharset.IsEmpty()) {
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, m_sysCharset);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
m_sysCharset.AssignLiteral("ISO-8859-1");
|
||||
}
|
||||
|
||||
if (!uniStr) {
|
||||
sysStr.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (*uniStr == '\0') {
|
||||
sysStr.Truncate();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (m_sysCharset.IsEmpty() ||
|
||||
m_sysCharset.LowerCaseEqualsLiteral("us-ascii") ||
|
||||
m_sysCharset.LowerCaseEqualsLiteral("iso-8859-1")) {
|
||||
sysStr.AssignWithConversion(uniStr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (!m_pEncoder) {
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && (nsnull != ccm)) {
|
||||
// get an unicode converter
|
||||
rv = ccm->GetUnicodeEncoder(m_sysCharset.get(), &m_pEncoder);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = m_pEncoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nsnull, '?');
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pEncoder) {
|
||||
PRInt32 srcLen = nsCRT::strlen(uniStr);
|
||||
char * chars;
|
||||
PRInt32 charLength = 0;
|
||||
|
||||
rv = m_pEncoder->GetMaxLength( uniStr, srcLen, &charLength);
|
||||
// allocale an output buffer
|
||||
chars = NS_STATIC_CAST(char*, nsMemory::Alloc((charLength + 1) * sizeof(char)));
|
||||
if (chars != nsnull) {
|
||||
// convert to unicode
|
||||
rv = m_pEncoder->Convert( uniStr, &srcLen, chars, &charLength);
|
||||
sysStr.Assign(chars, charLength);
|
||||
nsMemory::Free(chars);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NS_FAILED( rv))
|
||||
sysStr.AssignWithConversion(uniStr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
extern nsresult NS_NewGenericMail(nsIImportGeneric** aImportGeneric);
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericMail(nsIImportGeneric **_retval)
|
||||
|
|
Загрузка…
Ссылка в новой задаче