mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Added a callback to listen the pref change by UI, added a function to nsIDBFolderInfo to check if default charset is used, bug 50054, r=bienvenu.
This commit is contained in:
parent
a4e1bb6ae3
commit
df12b41dab
@ -463,7 +463,10 @@ nsresult nsMsgDBFolder::ReadDBFolderInfo(PRBool force)
|
||||
//folderInfo->GetImapTotalPendingMessages(&mNumPendingTotalMessages);
|
||||
//folderInfo->GetImapUnreadPendingMessages(&mNumPendingUnreadMessages);
|
||||
|
||||
folderInfo->GetCharacterSet(&mCharset);
|
||||
PRBool defaultUsed;
|
||||
folderInfo->GetCharacterSet2(&mCharset, &defaultUsed);
|
||||
if (defaultUsed)
|
||||
mCharset.AssignWithConversion("");
|
||||
|
||||
if (db) {
|
||||
PRBool hasnew;
|
||||
|
@ -63,6 +63,7 @@ interface nsIDBFolderInfo : nsISupports {
|
||||
void InitFromTransferInfo(in nsIDBFolderInfo transferInfo);
|
||||
|
||||
[noscript] void GetCharacterSet(in nsString result);
|
||||
[noscript] void GetCharacterSet2(in nsString result, out boolean usedDefault);
|
||||
[noscript] void SetCharacterSet(in nsString result);
|
||||
|
||||
void GetCharPtrCharacterSet(out string result);
|
||||
|
@ -51,8 +51,26 @@ static const char * kVersionColumnName = "version";
|
||||
static const char * kCharacterSetColumnName = "charSet";
|
||||
static const char * kLocaleColumnName = "locale";
|
||||
|
||||
static const char * MAILNEWS_VIEW_DEFAULT_CHARSET = "mailnews.view_default_charset";
|
||||
static nsString gDefaultCharacterSet; // default charset
|
||||
|
||||
static int PR_CALLBACK defaultCharacterSetChanged(const char *prefName, void *closure)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUnichar *prefCharset = nsnull;
|
||||
rv = prefs->GetLocalizedUnicharPref(prefName, &prefCharset);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
gDefaultCharacterSet.Assign(prefCharset);
|
||||
PR_Free(prefCharset);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDBFolderInfo)
|
||||
NS_IMPL_RELEASE(nsDBFolderInfo)
|
||||
|
||||
@ -106,14 +124,15 @@ nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb)
|
||||
m_mdbTokensInitialized = FALSE;
|
||||
|
||||
// Initialize a default charset to a pref default.
|
||||
if (gDefaultCharacterSet.IsEmpty())
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefs->RegisterCallback(MAILNEWS_VIEW_DEFAULT_CHARSET, defaultCharacterSetChanged, NULL);
|
||||
if (gDefaultCharacterSet.IsEmpty())
|
||||
{
|
||||
PRUnichar *prefCharset = nsnull;
|
||||
rv = prefs->GetLocalizedUnicharPref("mailnews.view_default_charset", &prefCharset);
|
||||
rv = prefs->GetLocalizedUnicharPref(MAILNEWS_VIEW_DEFAULT_CHARSET, &prefCharset);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
gDefaultCharacterSet.Assign(prefCharset);
|
||||
@ -144,6 +163,11 @@ nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb)
|
||||
|
||||
nsDBFolderInfo::~nsDBFolderInfo()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = prefs->UnregisterCallback(MAILNEWS_VIEW_DEFAULT_CHARSET, defaultCharacterSetChanged, NULL);
|
||||
|
||||
if (m_mdb)
|
||||
{
|
||||
if (m_mdbTable)
|
||||
@ -580,6 +604,22 @@ nsDBFolderInfo::GetCharacterSet(nsString *result)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDBFolderInfo::GetCharacterSet2(nsString *result, PRBool *usedDefault)
|
||||
{
|
||||
nsresult rv = GetProperty(kCharacterSetColumnName, result);
|
||||
|
||||
*usedDefault = FALSE;
|
||||
|
||||
if (NS_SUCCEEDED(rv) && result->IsEmpty())
|
||||
{
|
||||
result->Assign(gDefaultCharacterSet.GetUnicode());
|
||||
*usedDefault = TRUE;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDBFolderInfo::GetCharPtrCharacterSet(char **result)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user