Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
nsCharsetMenu Class Reference

The Charset Converter menu. More...

Inheritance diagram for nsCharsetMenu:
Inheritance graph
[legend]
Collaboration diagram for nsCharsetMenu:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsCharsetMenu ()
virtual ~nsCharsetMenu ()
nsresult Init ()
nsresult InitBrowserMenu ()
nsresult InitMaileditMenu ()
nsresult InitMailviewMenu ()
nsresult InitComposerMenu ()
nsresult InitOthers ()
nsresult InitSecondaryTiers ()
 Inits the secondary tiers of the charset menu.
nsresult InitAutodetMenu ()
nsresult RefreshBrowserMenu ()
nsresult RefreshMailviewMenu ()
nsresult RefreshMaileditMenu ()
nsresult RefreshComposerMenu ()
NS_IMETHOD SetCurrentCharset (const PRUnichar *aCharset)
NS_IMETHOD SetCurrentMailCharset (const PRUnichar *aCharset)
NS_IMETHOD SetCurrentComposerCharset (const PRUnichar *aCharset)
void SetCurrentCharset (in wstring charset)
void SetCurrentMailCharset (in wstring charset)
void SetCurrentComposerCharset (in wstring charset)

Private Member Functions

nsresult Done ()
nsresult SetCharsetCheckmark (nsString *aCharset, PRBool aValue)
nsresult FreeResources ()
 Free the resources no longer needed by the component.
nsresult InitStaticMenu (nsCStringArray &aDecs, nsIRDFResource *aResource, const char *aKey, nsVoidArray *aArray)
nsresult InitCacheMenu (nsCStringArray &aDecs, nsIRDFResource *aResource, const char *aKey, nsVoidArray *aArray)
nsresult InitMoreMenu (nsCStringArray &aDecs, nsIRDFResource *aResource, const char *aFlag)
nsresult InitMoreSubmenus (nsCStringArray &aDecs)
nsresult AddCharsetToItemArray (nsVoidArray *aArray, const nsAFlatCString &aCharset, nsMenuEntry **aResult, PRInt32 aPlace)
nsresult AddCharsetArrayToItemArray (nsVoidArray &aArray, const nsCStringArray &aCharsets)
nsresult AddMenuItemToContainer (nsIRDFContainer *aContainer, nsMenuEntry *aItem, nsIRDFResource *aType, const char *aIDPrefix, PRInt32 aPlace)
nsresult AddMenuItemArrayToContainer (nsIRDFContainer *aContainer, nsVoidArray *aArray, nsIRDFResource *aType)
nsresult AddCharsetToContainer (nsVoidArray *aArray, nsIRDFContainer *aContainer, const nsAFlatCString &aCharset, const char *aIDPrefix, PRInt32 aPlace, PRInt32 aRDFPlace)
nsresult AddFromPrefsToMenu (nsVoidArray *aArray, nsIRDFContainer *aContainer, const char *aKey, nsCStringArray &aDecs, const char *aIDPrefix)
nsresult AddFromNolocPrefsToMenu (nsVoidArray *aArray, nsIRDFContainer *aContainer, const char *aKey, nsCStringArray &aDecs, const char *aIDPrefix)
nsresult AddFromStringToMenu (char *aCharsetList, nsVoidArray *aArray, nsIRDFContainer *aContainer, nsCStringArray &aDecs, const char *aIDPrefix)
nsresult AddSeparatorToContainer (nsIRDFContainer *aContainer)
nsresult AddCharsetToCache (const nsAFlatCString &aCharset, nsVoidArray *aArray, nsIRDFResource *aRDFResource, PRInt32 aCacheStart, PRInt32 aCacheSize, PRInt32 aRDFPlace)
nsresult WriteCacheToPrefs (nsVoidArray *aArray, PRInt32 aCacheStart, const char *aKey)
nsresult UpdateCachePrefs (const char *aCacheKey, const char *aCacheSizeKey, const char *aStaticKey, const PRUnichar *aCharset)
nsresult ClearMenu (nsIRDFContainer *aContainer, nsVoidArray *aArray)
nsresult RemoveLastMenuItem (nsIRDFContainer *aContainer, nsVoidArray *aArray)
nsresult RemoveFlaggedCharsets (nsCStringArray &aList, const nsString &aProp)
nsresult NewRDFContainer (nsIRDFDataSource *aDataSource, nsIRDFResource *aResource, nsIRDFContainer **aResult)
void FreeMenuItemArray (nsVoidArray *aArray)
PRInt32 FindMenuItemInArray (const nsVoidArray *aArray, const nsAFlatCString &aCharset, nsMenuEntry **aResult)
nsresult ReorderMenuItemArray (nsVoidArray *aArray)
nsresult GetCollation (nsICollation **aCollation)

Static Private Member Functions

static nsresult SetArrayFromEnumerator (nsIUTF8StringEnumerator *aEnumerator, nsCStringArray &aArray)

Private Attributes

PRPackedBool mInitialized
PRPackedBool mBrowserMenuInitialized
PRPackedBool mMailviewMenuInitialized
PRPackedBool mComposerMenuInitialized
PRPackedBool mMaileditMenuInitialized
PRPackedBool mSecondaryTiersInitialized
PRPackedBool mAutoDetectInitialized
PRPackedBool mOthersInitialized
nsVoidArray mBrowserMenu
PRInt32 mBrowserCacheStart
PRInt32 mBrowserCacheSize
PRInt32 mBrowserMenuRDFPosition
nsVoidArray mMailviewMenu
PRInt32 mMailviewCacheStart
PRInt32 mMailviewCacheSize
PRInt32 mMailviewMenuRDFPosition
nsVoidArray mComposerMenu
PRInt32 mComposerCacheStart
PRInt32 mComposerCacheSize
PRInt32 mComposerMenuRDFPosition
nsCOMPtr< nsIRDFServicemRDFService
nsCOMPtr
< nsICharsetConverterManager
mCCManager
nsCOMPtr< nsIPrefBranchmPrefs
nsCOMPtr< nsIObservermCharsetMenuObserver
nsCStringArray mDecoderList

Static Private Attributes

static nsIRDFResourcekNC_BrowserAutodetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserCharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMoreCharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMore1CharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMore2CharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMore3CharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMore4CharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserMore5CharsetMenuRoot = NULL
static nsIRDFResourcekNC_BrowserUnicodeCharsetMenuRoot = NULL
static nsIRDFResourcekNC_MaileditCharsetMenuRoot = NULL
static nsIRDFResourcekNC_MailviewCharsetMenuRoot = NULL
static nsIRDFResourcekNC_ComposerCharsetMenuRoot = NULL
static nsIRDFResourcekNC_DecodersRoot = NULL
static nsIRDFResourcekNC_EncodersRoot = NULL
static nsIRDFResourcekNC_Name = NULL
static nsIRDFResourcekNC_Checked = NULL
static nsIRDFResourcekNC_CharsetDetector = NULL
static nsIRDFResourcekNC_BookmarkSeparator = NULL
static nsIRDFResourcekRDF_type = NULL
static nsIRDFDataSourcemInner = NULL

Detailed Description

The Charset Converter menu.

God, our GUI programming disgusts me.

23/Nov/1999

Author:
Catalin Rotaru [CATA]

Definition at line 158 of file nsCharsetMenu.cpp.


Constructor & Destructor Documentation

Definition at line 495 of file nsCharsetMenu.cpp.

: mInitialized(PR_FALSE), 
  mBrowserMenuInitialized(PR_FALSE),
  mMailviewMenuInitialized(PR_FALSE),
  mComposerMenuInitialized(PR_FALSE),
  mMaileditMenuInitialized(PR_FALSE),
  mSecondaryTiersInitialized(PR_FALSE),
  mAutoDetectInitialized(PR_FALSE),
  mOthersInitialized(PR_FALSE)
{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::nsCharsetMenu");
  nsresult res = NS_OK;

  //get charset manager
  mCCManager = do_GetService(kCharsetConverterManagerCID, &res);

  //initialize skeleton RDF source
  mRDFService = do_GetService(kRDFServiceCID, &res);

  if (NS_SUCCEEDED(res))  {
    mRDFService->RegisterDataSource(this, PR_FALSE);
  
    CallCreateInstance(kRDFInMemoryDataSourceCID, &mInner);

    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserCharsetMenuRoot),
                             &kNC_BrowserCharsetMenuRoot);
  }

  //get pref service
  nsCOMPtr<nsIPrefService> PrefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &res);
  if (NS_SUCCEEDED(res))
    res = PrefService->GetBranch(nsnull, getter_AddRefs(mPrefs));

  //register event listener
  mCharsetMenuObserver = new nsCharsetMenuObserver(this);

  if (mCharsetMenuObserver)  {
    nsCOMPtr<nsIObserverService> observerService = 
             do_GetService("@mozilla.org/observer-service;1", &res);

    if (NS_SUCCEEDED(res))
      res = observerService->AddObserver(mCharsetMenuObserver, 
                                         "charsetmenu-selected", 
                                         PR_FALSE);
  }

  NS_ASSERTION(NS_SUCCEEDED(res), "Failed to initialize nsCharsetMenu");
  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::nsCharsetMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::nsCharsetMenu");
}

Here is the call graph for this function:

Definition at line 546 of file nsCharsetMenu.cpp.

Here is the call graph for this function:


Member Function Documentation

nsresult nsCharsetMenu::AddCharsetArrayToItemArray ( nsVoidArray aArray,
const nsCStringArray &  aCharsets 
) [private]

Definition at line 1340 of file nsCharsetMenu.cpp.

{
  PRUint32 count = aCharsets.Count();

  for (PRUint32 i = 0; i < count; i++) {

    nsCString* str = aCharsets.CStringAt(i);
    if (str) {
      nsresult res = AddCharsetToItemArray(&aArray, *str, NULL, -1);
    
      if (NS_FAILED(res)) return res;
    }
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddCharsetToCache ( const nsAFlatCString aCharset,
nsVoidArray aArray,
nsIRDFResource aRDFResource,
PRInt32  aCacheStart,
PRInt32  aCacheSize,
PRInt32  aRDFPlace 
) [private]

Definition at line 1566 of file nsCharsetMenu.cpp.

{
  PRInt32 i;
  nsresult res = NS_OK;

  i = FindMenuItemInArray(aArray, aCharset, NULL);
  if (i >= 0) return res;

  nsCOMPtr<nsIRDFContainer> container;
  res = NewRDFContainer(mInner, aRDFResource, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // iff too many items, remove last one
  if (aArray->Count() - aCacheStart >= aCacheSize){
    res = RemoveLastMenuItem(container, aArray);
    if (NS_FAILED(res)) return res;
  }

  res = AddCharsetToContainer(aArray, container, aCharset, "charset.", 
                              aCacheStart, aRDFPlace);

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddCharsetToContainer ( nsVoidArray aArray,
nsIRDFContainer aContainer,
const nsAFlatCString aCharset,
const char *  aIDPrefix,
PRInt32  aPlace,
PRInt32  aRDFPlace 
) [private]

Definition at line 1437 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsMenuEntry * item = NULL; 
  
  res = AddCharsetToItemArray(aArray, aCharset, &item, aPlace);
  if (NS_FAILED(res)) goto done;

  res = AddMenuItemToContainer(aContainer, item, NULL, aIDPrefix, 
    aPlace + aRDFPlace);
  if (NS_FAILED(res)) goto done;

  // if we have made another reference to "item", do not delete it 
  if (aArray != NULL) item = NULL; 

done:
  if (item != NULL) delete item;

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddCharsetToItemArray ( nsVoidArray aArray,
const nsAFlatCString aCharset,
nsMenuEntry **  aResult,
PRInt32  aPlace 
) [private]

Definition at line 1295 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsMenuEntry * item = NULL; 

  if (aResult != NULL) *aResult = NULL;
  
  item = new nsMenuEntry();
  if (item == NULL) {
    res = NS_ERROR_OUT_OF_MEMORY;
    goto done;
  }

  item->mCharset = aCharset;

  res = mCCManager->GetCharsetTitle(aCharset.get(), item->mTitle);
  if (NS_FAILED(res)) {
    item->mTitle.AssignWithConversion(aCharset.get());
  }

  if (aArray != NULL) {
    if (aPlace < 0) {
      res = aArray->AppendElement(item);
      if (NS_FAILED(res)) goto done;
    } else {
      res = aArray->InsertElementAt(item, aPlace);
      if (NS_FAILED(res)) goto done;
    }
  }

  if (aResult != NULL) *aResult = item;

  // if we have made another reference to "item", do not delete it 
  if ((aArray != NULL) || (aResult != NULL)) item = NULL; 

done:
  if (item != NULL) delete item;

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddFromNolocPrefsToMenu ( nsVoidArray aArray,
nsIRDFContainer aContainer,
const char *  aKey,
nsCStringArray &  aDecs,
const char *  aIDPrefix 
) [private]

Definition at line 1489 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  char * value = NULL;
  res = mPrefs->GetCharPref(aKey, &value);
  if (NS_FAILED(res)) return res;

  if (value != NULL) {
    res = AddFromStringToMenu(value, aArray, aContainer, aDecs, aIDPrefix);
    nsMemory::Free(value);
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddFromPrefsToMenu ( nsVoidArray aArray,
nsIRDFContainer aContainer,
const char *  aKey,
nsCStringArray &  aDecs,
const char *  aIDPrefix 
) [private]

Definition at line 1463 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  nsCOMPtr<nsIPrefLocalizedString> pls;
  res = mPrefs->GetComplexValue(aKey, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(pls));
  if (NS_FAILED(res)) return res;

  if (pls) {
    nsXPIDLString ucsval;
    pls->ToString(getter_Copies(ucsval));
    NS_ConvertUCS2toUTF8 utf8val(ucsval);
    if (ucsval)
      res = AddFromStringToMenu(utf8val.BeginWriting(), aArray,
                                aContainer, aDecs, aIDPrefix);
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddFromStringToMenu ( char *  aCharsetList,
nsVoidArray aArray,
nsIRDFContainer aContainer,
nsCStringArray &  aDecs,
const char *  aIDPrefix 
) [private]

Definition at line 1509 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  char * p = aCharsetList;
  char * q = p;
  while (*p != 0) {
         for (; (*q != ',') && (*q != ' ') && (*q != 0); q++) {;}
    char temp = *q;
    *q = 0;

    // if this charset is not on the accepted list of charsets, ignore it
    PRInt32 index;
    index = aDecs.IndexOfIgnoreCase(nsCAutoString(p));
    if (index >= 0) {

      // else, add it to the menu
      res = AddCharsetToContainer(aArray, aContainer, nsDependentCString(p),
                                  aIDPrefix, -1, 0);
      NS_ASSERTION(NS_SUCCEEDED(res), "cannot add charset to menu");
      if (NS_FAILED(res)) break;

      res = aDecs.RemoveCStringAt(index);
      NS_ASSERTION(NS_SUCCEEDED(res), "cannot remove atom from array");
    }

    *q = temp;
    for (; (*q == ',') || (*q == ' '); q++) {;}
    p=q;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddMenuItemArrayToContainer ( nsIRDFContainer aContainer,
nsVoidArray aArray,
nsIRDFResource aType 
) [private]

Definition at line 1418 of file nsCharsetMenu.cpp.

{
  PRUint32 count = aArray->Count();
  nsresult res = NS_OK;

  for (PRUint32 i = 0; i < count; i++) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(i);
    if (item == NULL) return NS_ERROR_UNEXPECTED;

    res = AddMenuItemToContainer(aContainer, item, aType, NULL, -1);
    if (NS_FAILED(res)) return res;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::AddMenuItemToContainer ( nsIRDFContainer aContainer,
nsMenuEntry aItem,
nsIRDFResource aType,
const char *  aIDPrefix,
PRInt32  aPlace 
) [private]

Definition at line 1360 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsCOMPtr<nsIRDFResource> node;

  nsCAutoString id;
  if (aIDPrefix != NULL) id.Assign(aIDPrefix);
  id.Append(aItem->mCharset);

  // Make up a unique ID and create the RDF NODE
  res = mRDFService->GetResource(id, getter_AddRefs(node));
  if (NS_FAILED(res)) return res;

  const PRUnichar * title = aItem->mTitle.get();

  // set node's title
  nsCOMPtr<nsIRDFLiteral> titleLiteral;
  res = mRDFService->GetLiteral(title, getter_AddRefs(titleLiteral));
  if (NS_FAILED(res)) return res;

  if (aPlace < -1) {
    res = Unassert(node, kNC_Name, titleLiteral);
    if (NS_FAILED(res)) return res;
  } else {
    res = Assert(node, kNC_Name, titleLiteral, PR_TRUE);
    if (NS_FAILED(res)) return res;
  }

  if (aType != NULL) {
    if (aPlace < -1) {
      res = Unassert(node, kRDF_type, aType);
      if (NS_FAILED(res)) return res;
    } else {
      res = Assert(node, kRDF_type, aType, PR_TRUE);
      if (NS_FAILED(res)) return res;
    }
  }

  // Add the element to the container
  if (aPlace < -1) {
    res = aContainer->RemoveElement(node, PR_TRUE);
    if (NS_FAILED(res)) return res;
  } else if (aPlace < 0) {
    res = aContainer->AppendElement(node);
    if (NS_FAILED(res)) return res;
  } else {
    res = aContainer->InsertElementAt(node, aPlace, PR_TRUE);
    if (NS_FAILED(res)) return res;
  } 

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1547 of file nsCharsetMenu.cpp.

{
  nsCAutoString str;
  str.AssignLiteral("----");

  // hack to generate unique id's for separators
  static PRInt32 u = 0;
  u++;
  str.AppendInt(u);

  nsMenuEntry item;
  item.mCharset = str;
  item.mTitle.AssignWithConversion(str.get());

  return AddMenuItemToContainer(aContainer, &item, kNC_BookmarkSeparator, 
    NULL, -1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::ClearMenu ( nsIRDFContainer aContainer,
nsVoidArray aArray 
) [private]

Definition at line 1656 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  // clean the RDF data source
  PRInt32 count = aArray->Count();
  for (PRInt32 i = 0; i < count; i++) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(i);
    if (item != NULL) {    
      res = AddMenuItemToContainer(aContainer, item, NULL, "charset.", -2);
      if (NS_FAILED(res)) return res;
    }
  }

  // clean the internal data structures
  FreeMenuItemArray(aArray);

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRInt32 nsCharsetMenu::FindMenuItemInArray ( const nsVoidArray aArray,
const nsAFlatCString aCharset,
nsMenuEntry **  aResult 
) [private]

Definition at line 1750 of file nsCharsetMenu.cpp.

{
  PRUint32 count = aArray->Count();

  for (PRUint32 i=0; i < count; i++) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(i);
    if (item->mCharset == aCharset) {
      if (aResult != NULL) *aResult = item;
      return i;
    }
  }

  if (aResult != NULL) *aResult = NULL;
  return -1;
}

Here is the caller graph for this function:

Definition at line 1738 of file nsCharsetMenu.cpp.

{
  PRUint32 count = aArray->Count();
  for (PRUint32 i = 0; i < count; i++) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(i);
    if (item != NULL) {
      delete item;
    }
  }
  aArray->Clear();
}

Here is the caller graph for this function:

Free the resources no longer needed by the component.

Definition at line 849 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  if (mCharsetMenuObserver) {
    nsCOMPtr<nsIPrefBranch2> pbi = do_QueryInterface(mPrefs);
    if (pbi) {
      pbi->RemoveObserver(kBrowserStaticPrefKey, mCharsetMenuObserver);
      pbi->RemoveObserver(kMaileditPrefKey, mCharsetMenuObserver);
    }
    /* nsIObserverService has to have released nsCharsetMenu already */
  }

  mRDFService = NULL;
  mCCManager  = NULL;
  mPrefs      = NULL;

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::GetCollation ( nsICollation **  aCollation) [private]

Definition at line 1811 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsCOMPtr<nsILocale> locale = nsnull;
  nsICollationFactory * collationFactory = nsnull;
  
  nsCOMPtr<nsILocaleService> localeServ = 
           do_GetService(kLocaleServiceCID, &res);
  if (NS_FAILED(res)) return res;

  res = localeServ->GetApplicationLocale(getter_AddRefs(locale));
  if (NS_FAILED(res)) return res;

  res = CallCreateInstance(kCollationFactoryCID, &collationFactory);
  if (NS_FAILED(res)) return res;

  res = collationFactory->CreateCollation(locale, aCollation);
  NS_RELEASE(collationFactory);
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 701 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  if (!mInitialized)  {

    //enumerate decoders
    nsCOMPtr<nsIUTF8StringEnumerator> decoders;
    res = mCCManager->GetDecoderList(getter_AddRefs(decoders));
    if (NS_FAILED(res)) return res;

    SetArrayFromEnumerator(decoders, mDecoderList);

    //initialize all remaining RDF template nodes
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserAutodetMenuRoot),
                             &kNC_BrowserAutodetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMoreCharsetMenuRoot),
                             &kNC_BrowserMoreCharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMore1CharsetMenuRoot),
                             &kNC_BrowserMore1CharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMore2CharsetMenuRoot),
                             &kNC_BrowserMore2CharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMore3CharsetMenuRoot),
                             &kNC_BrowserMore3CharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMore4CharsetMenuRoot),
                             &kNC_BrowserMore4CharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserMore5CharsetMenuRoot),
                             &kNC_BrowserMore5CharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BrowserUnicodeCharsetMenuRoot),
                             &kNC_BrowserUnicodeCharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_MaileditCharsetMenuRoot),
                             &kNC_MaileditCharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_MailviewCharsetMenuRoot),
                             &kNC_MailviewCharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_ComposerCharsetMenuRoot),
                             &kNC_ComposerCharsetMenuRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_DecodersRoot),
                             &kNC_DecodersRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_EncodersRoot),
                             &kNC_EncodersRoot);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_Name),
                             &kNC_Name);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_Checked),
                             &kNC_Checked);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_CharsetDetector),
                             &kNC_CharsetDetector);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_BookmarkSeparator),
                             &kNC_BookmarkSeparator);
    mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_type), &kRDF_type);

    nsIRDFContainerUtils * rdfUtil = NULL;
    res = CallGetService(kRDFContainerUtilsCID, &rdfUtil);
    if (NS_FAILED(res)) goto done;

    res = rdfUtil->MakeSeq(mInner, kNC_BrowserAutodetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMoreCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMore1CharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMore2CharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMore3CharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMore4CharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserMore5CharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_BrowserUnicodeCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_MaileditCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_MailviewCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_ComposerCharsetMenuRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_DecodersRoot, NULL);
    if (NS_FAILED(res)) goto done;
    res = rdfUtil->MakeSeq(mInner, kNC_EncodersRoot, NULL);
    if (NS_FAILED(res)) goto done;

  done:
    NS_IF_RELEASE(rdfUtil);
    if (NS_FAILED(res)) return res;
  }
  mInitialized = NS_SUCCEEDED(res);
  return res;
}

Here is the call graph for this function:

Definition at line 1157 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitAutodetMenu");

  nsresult res = NS_OK;

  if (!mAutoDetectInitialized) {
    nsVoidArray chardetArray;
    nsCOMPtr<nsIRDFContainer> container;
    nsCStringArray detectorArray;

    res = NewRDFContainer(mInner, kNC_BrowserAutodetMenuRoot, getter_AddRefs(container));
    if (NS_FAILED(res)) return res;

    nsCOMPtr<nsIUTF8StringEnumerator> detectors;
    res = mCCManager->GetCharsetDetectorList(getter_AddRefs(detectors));
    if (NS_FAILED(res)) goto done;

    res = SetArrayFromEnumerator(detectors, detectorArray);
    if (NS_FAILED(res)) goto done;
    
    res = AddCharsetArrayToItemArray(chardetArray, detectorArray);
    if (NS_FAILED(res)) goto done;

    // reorder the array
    res = ReorderMenuItemArray(&chardetArray);
    if (NS_FAILED(res)) goto done;

    res = AddMenuItemArrayToContainer(container, &chardetArray, 
      kNC_CharsetDetector);
    if (NS_FAILED(res)) goto done;

  done:
    // free the elements in the VoidArray
    FreeMenuItemArray(&chardetArray);
  }

  mAutoDetectInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitAutodetMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitAutodetMenu");

  return res;
}

Here is the call graph for this function:

Definition at line 869 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitBrowserMenu");

  nsresult res = NS_OK;

  if (!mBrowserMenuInitialized)  {
    nsCOMPtr<nsIRDFContainer> container;
    res = NewRDFContainer(mInner, kNC_BrowserCharsetMenuRoot, getter_AddRefs(container));
    if (NS_FAILED(res)) return res;


    // how to clone mDecoderList??
    nsCStringArray browserDecoderList;
    CloneCStringArray(mDecoderList, browserDecoderList);

    res = InitStaticMenu(browserDecoderList, kNC_BrowserCharsetMenuRoot, 
                         kBrowserStaticPrefKey, &mBrowserMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing browser static charset menu");

    // mark the end of the static area, the rest is cache
    mBrowserCacheStart = mBrowserMenu.Count();
    mPrefs->GetIntPref(kBrowserCacheSizePrefKey, &mBrowserCacheSize);

    // compute the position of the menu in the RDF container
    res = container->GetCount(&mBrowserMenuRDFPosition);
    if (NS_FAILED(res)) return res;
    // this "1" here is a correction necessary because the RDF container 
    // elements are numbered from 1 (why god, WHY?!?!?!)
    mBrowserMenuRDFPosition -= mBrowserCacheStart - 1;

    // Remove "notForBrowser" entries before populating cache menu
    res = RemoveFlaggedCharsets(browserDecoderList, NS_LITERAL_STRING(".notForBrowser"));
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");

    res = InitCacheMenu(browserDecoderList, kNC_BrowserCharsetMenuRoot, kBrowserCachePrefKey, 
      &mBrowserMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing browser cache charset menu");

    // register prefs callback
    nsCOMPtr<nsIPrefBranch2> pbi = do_QueryInterface(mPrefs);
    if (pbi)
      res = pbi->AddObserver(kBrowserStaticPrefKey, mCharsetMenuObserver, PR_FALSE);
  }

  mBrowserMenuInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitBrowserMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitBrowserMenu");

  return res;
}

Here is the call graph for this function:

nsresult nsCharsetMenu::InitCacheMenu ( nsCStringArray &  aDecs,
nsIRDFResource aResource,
const char *  aKey,
nsVoidArray aArray 
) [private]

Definition at line 1134 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitCacheMenu");

  nsresult res = NS_OK;
  nsCOMPtr<nsIRDFContainer> container;

  res = NewRDFContainer(mInner, aResource, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  res = AddFromNolocPrefsToMenu(aArray, container, aKey, aDecs, "charset.");
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing cache charset menu from prefs");

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitCacheMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitCacheMenu");

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1004 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitComposerMenu");
 
  nsresult res = NS_OK;

  if (!mComposerMenuInitialized)  {
    nsCOMPtr<nsIRDFContainer> container;
    res = NewRDFContainer(mInner, kNC_ComposerCharsetMenuRoot, getter_AddRefs(container));
    if (NS_FAILED(res)) return res;

    nsCStringArray composerDecoderList;
    CloneCStringArray(mDecoderList, composerDecoderList);

    // even if we fail, the show must go on
    res = InitStaticMenu(composerDecoderList, kNC_ComposerCharsetMenuRoot, 
      kComposerStaticPrefKey, &mComposerMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing composer static charset menu");

    // mark the end of the static area, the rest is cache
    mComposerCacheStart = mComposerMenu.Count();
    mPrefs->GetIntPref(kComposerCacheSizePrefKey, &mComposerCacheSize);

    // compute the position of the menu in the RDF container
    res = container->GetCount(&mComposerMenuRDFPosition);
    if (NS_FAILED(res)) return res;
    // this "1" here is a correction necessary because the RDF container 
    // elements are numbered from 1 (why god, WHY?!?!?!)
    mComposerMenuRDFPosition -= mComposerCacheStart - 1;

    res = InitCacheMenu(composerDecoderList, kNC_ComposerCharsetMenuRoot, 
      kComposerCachePrefKey, &mComposerMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing composer cache charset menu");
  }

  mComposerMenuInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitComposerMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitComposerMenu");
  
  return res;
}

Here is the call graph for this function:

Definition at line 922 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitMaileditMenu");

  nsresult res = NS_OK;

  if (!mMaileditMenuInitialized)  {
    nsCOMPtr<nsIRDFContainer> container;
    res = NewRDFContainer(mInner, kNC_MaileditCharsetMenuRoot, getter_AddRefs(container));
    if (NS_FAILED(res)) return res;

    //enumerate encoders
    // this would bring in a whole bunch of 'font encoders' as well as genuine 
    // charset encoders, but it's safe because we rely on prefs to filter
    // them out. Moreover, 'customize' menu lists only genuine charset 
    // encoders further guarding  against  'font encoders' sneaking in. 
    nsCOMPtr<nsIUTF8StringEnumerator> encoders;
    res = mCCManager->GetEncoderList(getter_AddRefs(encoders));
    if (NS_FAILED(res))  return res;

    nsCStringArray maileditEncoderList;
    SetArrayFromEnumerator(encoders, maileditEncoderList);
  
    res = AddFromPrefsToMenu(NULL, container, kMaileditPrefKey, maileditEncoderList, NULL);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing mailedit charset menu from prefs");

    // register prefs callback
    nsCOMPtr<nsIPrefBranch2> pbi = do_QueryInterface(mPrefs);
    if (pbi)
      res = pbi->AddObserver(kMaileditPrefKey, mCharsetMenuObserver, PR_FALSE);
  }

  mMaileditMenuInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitMaileditMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitMaileditMenu");

  return res;
}

Here is the call graph for this function:

Definition at line 962 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitMailviewMenu");
  
  nsresult res = NS_OK;

  if (!mMailviewMenuInitialized)  {
    nsCOMPtr<nsIRDFContainer> container;
    res = NewRDFContainer(mInner, kNC_MailviewCharsetMenuRoot, getter_AddRefs(container));
    if (NS_FAILED(res)) return res;

    nsCStringArray mailviewDecoderList;
    CloneCStringArray(mDecoderList, mailviewDecoderList);

    res = InitStaticMenu(mailviewDecoderList, kNC_MailviewCharsetMenuRoot, 
                         kMailviewStaticPrefKey, &mMailviewMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing mailview static charset menu");

    // mark the end of the static area, the rest is cache
    mMailviewCacheStart = mMailviewMenu.Count();
    mPrefs->GetIntPref(kMailviewCacheSizePrefKey, &mMailviewCacheSize);

    // compute the position of the menu in the RDF container
    res = container->GetCount(&mMailviewMenuRDFPosition);
    if (NS_FAILED(res)) return res;
    // this "1" here is a correction necessary because the RDF container 
    // elements are numbered from 1 (why god, WHY?!?!?!)
    mMailviewMenuRDFPosition -= mMailviewCacheStart - 1;

    res = InitCacheMenu(mailviewDecoderList, kNC_MailviewCharsetMenuRoot, 
      kMailviewCachePrefKey, &mMailviewMenu);
    NS_ASSERTION(NS_SUCCEEDED(res), "error initializing mailview cache charset menu");
  }

  mMailviewMenuInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitMailviewMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitMailviewMenu");

  return res;
}

Here is the call graph for this function:

nsresult nsCharsetMenu::InitMoreMenu ( nsCStringArray &  aDecs,
nsIRDFResource aResource,
const char *  aFlag 
) [private]

Definition at line 1202 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitMoreMenu");

  nsresult res = NS_OK;
  nsCOMPtr<nsIRDFContainer> container;
  nsVoidArray moreMenu;

  res = NewRDFContainer(mInner, aResource, getter_AddRefs(container));
  if (NS_FAILED(res)) goto done;

  // remove charsets "not for browser"
  res = RemoveFlaggedCharsets(aDecs, NS_ConvertASCIItoUTF16(aFlag));
  if (NS_FAILED(res)) goto done;

  res = AddCharsetArrayToItemArray(moreMenu, aDecs);
  if (NS_FAILED(res)) goto done;

  // reorder the array
  res = ReorderMenuItemArray(&moreMenu);
  if (NS_FAILED(res)) goto done;

  res = AddMenuItemArrayToContainer(container, &moreMenu, NULL);
  if (NS_FAILED(res)) goto done;

done:
  // free the elements in the VoidArray
  FreeMenuItemArray(&moreMenu);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitMoreMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitMoreMenu");

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::InitMoreSubmenus ( nsCStringArray &  aDecs) [private]

Definition at line 1240 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitMoreSubmenus");

  nsresult res = NS_OK;

  nsCOMPtr<nsIRDFContainer> container1;
  nsCOMPtr<nsIRDFContainer> container2;
  nsCOMPtr<nsIRDFContainer> container3;
  nsCOMPtr<nsIRDFContainer> container4;
  nsCOMPtr<nsIRDFContainer> container5;
  nsCOMPtr<nsIRDFContainer> containerU;
  const char key1[] = "intl.charsetmenu.browser.more1";
  const char key2[] = "intl.charsetmenu.browser.more2";
  const char key3[] = "intl.charsetmenu.browser.more3";
  const char key4[] = "intl.charsetmenu.browser.more4";
  const char key5[] = "intl.charsetmenu.browser.more5";
  const char keyU[] = "intl.charsetmenu.browser.unicode";

  res = NewRDFContainer(mInner, kNC_BrowserMore1CharsetMenuRoot, 
    getter_AddRefs(container1));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, container1, key1, aDecs, NULL);

  res = NewRDFContainer(mInner, kNC_BrowserMore2CharsetMenuRoot, 
    getter_AddRefs(container2));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, container2, key2, aDecs, NULL);

  res = NewRDFContainer(mInner, kNC_BrowserMore3CharsetMenuRoot, 
    getter_AddRefs(container3));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, container3, key3, aDecs, NULL);

  res = NewRDFContainer(mInner, kNC_BrowserMore4CharsetMenuRoot, 
    getter_AddRefs(container4));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, container4, key4, aDecs, NULL);

  res = NewRDFContainer(mInner, kNC_BrowserMore5CharsetMenuRoot, 
    getter_AddRefs(container5));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, container5, key5, aDecs, NULL);

  res = NewRDFContainer(mInner, kNC_BrowserUnicodeCharsetMenuRoot, 
    getter_AddRefs(containerU));
  if (NS_FAILED(res)) return res;
  AddFromPrefsToMenu(NULL, containerU, keyU, aDecs, NULL);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitMoreSubmenus");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitMoreSubmenus");

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1047 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitOthers");

  nsresult res = NS_OK;

  if (!mOthersInitialized) {
    nsCStringArray othersDecoderList;
    CloneCStringArray(mDecoderList, othersDecoderList);

    res = InitMoreMenu(othersDecoderList, kNC_DecodersRoot, ".notForBrowser");                 
    if (NS_FAILED(res))  return res;

    // Using mDecoderList instead of GetEncoderList(), we can avoid having to
    // tag a whole bunch of 'font encoders' with '.notForOutgoing' in 
    // charsetData.properties file. 
    nsCStringArray othersEncoderList;
    CloneCStringArray(mDecoderList, othersEncoderList);

    res = InitMoreMenu(othersEncoderList, kNC_EncodersRoot, ".notForOutgoing");                 
    if (NS_FAILED(res)) return res;
  }

  mOthersInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitOthers");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitOthers");

  return res;
}

Here is the call graph for this function:

Inits the secondary tiers of the charset menu.

Because currently all the CS menus are sharing the secondary tiers, one should call this method only once for all of them.

Definition at line 1083 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitSecondaryTiers");

  nsresult res = NS_OK;

  if (!mSecondaryTiersInitialized)  {
    nsCStringArray secondaryTiersDecoderList;
    CloneCStringArray(mDecoderList, secondaryTiersDecoderList);

    res = InitMoreSubmenus(secondaryTiersDecoderList);
    NS_ASSERTION(NS_SUCCEEDED(res), "err init browser charset more submenus");

    res = InitMoreMenu(secondaryTiersDecoderList, kNC_BrowserMoreCharsetMenuRoot, ".notForBrowser");
    NS_ASSERTION(NS_SUCCEEDED(res), "err init browser charset more menu");
  }

  mSecondaryTiersInitialized = NS_SUCCEEDED(res);

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitSecondaryTiers");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitSecondaryTiers");

  return res;
}

Here is the call graph for this function:

nsresult nsCharsetMenu::InitStaticMenu ( nsCStringArray &  aDecs,
nsIRDFResource aResource,
const char *  aKey,
nsVoidArray aArray 
) [private]

Definition at line 1108 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu::InitStaticMenu");

  nsresult res = NS_OK;
  nsCOMPtr<nsIRDFContainer> container;

  res = NewRDFContainer(mInner, aResource, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // XXX work around bug that causes the submenus to be first instead of last
  res = AddSeparatorToContainer(container);
  NS_ASSERTION(NS_SUCCEEDED(res), "error adding separator to container");

  res = AddFromPrefsToMenu(aArray, container, aKey, aDecs, "charset.");
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");

  NS_TIMELINE_STOP_TIMER("nsCharsetMenu::InitStaticMenu");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu::InitStaticMenu");

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::NewRDFContainer ( nsIRDFDataSource aDataSource,
nsIRDFResource aResource,
nsIRDFContainer **  aResult 
) [private]

Definition at line 1725 of file nsCharsetMenu.cpp.

{
  nsresult res = CallCreateInstance(kRDFContainerCID, aResult);
  if (NS_FAILED(res)) return res;

  res = (*aResult)->Init(aDataSource, aResource);
  if (NS_FAILED(res)) NS_RELEASE(*aResult);

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 559 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  nsCOMPtr<nsIRDFContainer> container;
  res = NewRDFContainer(mInner, kNC_BrowserCharsetMenuRoot, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // clean the menu
  res = ClearMenu(container, &mBrowserMenu);
  if (NS_FAILED(res)) return res;

  // rebuild the menu
  nsCOMPtr<nsIUTF8StringEnumerator> decoders;
  res = mCCManager->GetDecoderList(getter_AddRefs(decoders));
  if (NS_FAILED(res)) return res;

  nsCStringArray decs;
  SetArrayFromEnumerator(decoders, decs);
  
  res = AddFromPrefsToMenu(&mBrowserMenu, container, kBrowserStaticPrefKey, 
                           decs, "charset.");
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");

  // mark the end of the static area, the rest is cache
  mBrowserCacheStart = mBrowserMenu.Count();

  // Remove "notForBrowser" entries before populating cache menu
  res = RemoveFlaggedCharsets(decs, NS_LITERAL_STRING(".notForBrowser"));
  NS_ASSERTION(NS_SUCCEEDED(res), "error removing flagged charsets");

  res = InitCacheMenu(decs, kNC_BrowserCharsetMenuRoot, kBrowserCachePrefKey, 
                      &mBrowserMenu);
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing browser cache charset menu");

  return res;
}

Here is the call graph for this function:

Definition at line 668 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  nsCOMPtr<nsIRDFContainer> container;
  res = NewRDFContainer(mInner, kNC_ComposerCharsetMenuRoot, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // clean the menu
  res = ClearMenu(container, &mComposerMenu);
  if (NS_FAILED(res)) return res;

  nsCOMPtr<nsIUTF8StringEnumerator> decoders;
  res = mCCManager->GetDecoderList(getter_AddRefs(decoders));
  if (NS_FAILED(res)) return res;

  nsCStringArray decs;
  SetArrayFromEnumerator(decoders, decs);
  
  res = AddFromPrefsToMenu(&mComposerMenu, container, kComposerStaticPrefKey, 
                           decs, "charset.");
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");

  // mark the end of the static area, the rest is cache
  mComposerCacheStart = mComposerMenu.Count();

  res = InitCacheMenu(decs, kNC_ComposerCharsetMenuRoot, 
    kComposerCachePrefKey, &mComposerMenu);
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing composer cache charset menu");

  return res;
}

Here is the call graph for this function:

Definition at line 630 of file nsCharsetMenu.cpp.

{
  nsresult res;

  nsCOMPtr<nsIRDFContainer> container;
  res = NewRDFContainer(mInner, kNC_MaileditCharsetMenuRoot, getter_AddRefs(container));
  NS_ENSURE_SUCCESS(res, res);

  nsCOMPtr<nsISimpleEnumerator> enumerator;
  res = container->GetElements(getter_AddRefs(enumerator));
  NS_ENSURE_SUCCESS(res, res);

  // clear the menu
  nsCOMPtr<nsIRDFNode> node;
  while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(node)))) {

    res = mInner->Unassert(kNC_MaileditCharsetMenuRoot, kNC_Name, node);
    NS_ENSURE_SUCCESS(res, res);

    res = container->RemoveElement(node, PR_FALSE);
    NS_ENSURE_SUCCESS(res, res);
  }

  // get a list of available encoders
  nsCOMPtr<nsIUTF8StringEnumerator> encoders;
  res = mCCManager->GetEncoderList(getter_AddRefs(encoders));
  NS_ENSURE_SUCCESS(res, res);

  nsCStringArray encs;
  SetArrayFromEnumerator(encoders, encs);
  
  // add menu items from pref
  res = AddFromPrefsToMenu(NULL, container, kMaileditPrefKey, encs, NULL);
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing mailedit charset menu from prefs");

  return res;
}

Here is the call graph for this function:

Definition at line 597 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  nsCOMPtr<nsIRDFContainer> container;
  res = NewRDFContainer(mInner, kNC_MailviewCharsetMenuRoot, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // clean the menu
  res = ClearMenu(container, &mMailviewMenu);
  if (NS_FAILED(res)) return res;

  nsCOMPtr<nsIUTF8StringEnumerator> decoders;
  res = mCCManager->GetDecoderList(getter_AddRefs(decoders));
  if (NS_FAILED(res)) return res;

  nsCStringArray decs;
  SetArrayFromEnumerator(decoders, decs);
  
  res = AddFromPrefsToMenu(&mMailviewMenu, container, kMailviewStaticPrefKey, 
                           decs, "charset.");
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing static charset menu from prefs");

  // mark the end of the static area, the rest is cache
  mMailviewCacheStart = mMailviewMenu.Count();

  res = InitCacheMenu(decs, kNC_MailviewCharsetMenuRoot, 
    kMailviewCachePrefKey, &mMailviewMenu);
  NS_ASSERTION(NS_SUCCEEDED(res), "error initializing mailview cache charset menu");

  return res;
}

Here is the call graph for this function:

nsresult nsCharsetMenu::RemoveFlaggedCharsets ( nsCStringArray &  aList,
const nsString aProp 
) [private]

Definition at line 1697 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  PRUint32 count;

  count = aList.Count();
  if (NS_FAILED(res)) return res;

  nsCString* charset;
  nsAutoString str;
  for (PRUint32 i = 0; i < count; i++) {

    charset = aList.CStringAt(i);
    if (!charset) continue;

    res = mCCManager->GetCharsetData(charset->get(), aProp.get(), str);
    if (NS_FAILED(res)) continue;

    aList.RemoveCStringAt(i);

    i--; 
    count--;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::RemoveLastMenuItem ( nsIRDFContainer aContainer,
nsVoidArray aArray 
) [private]

Definition at line 1677 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  PRInt32 last = aArray->Count() - 1;
  if (last >= 0) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(last);
    if (item != NULL) {    
      res = AddMenuItemToContainer(aContainer, item, NULL, "charset.", -2);
      if (NS_FAILED(res)) return res;

      res = aArray->RemoveElementAt(last);
      if (NS_FAILED(res)) return res;
    }
  }

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1768 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsCOMPtr<nsICollation> collation;
  PRUint32 count = aArray->Count();
  PRUint32 i;

  // we need to use a temporary array
  charsetMenuSortRecord *array = new charsetMenuSortRecord [count];
  NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
  for (i = 0; i < count; i++)
    array[i].key = nsnull;

  res = GetCollation(getter_AddRefs(collation));
  if (NS_FAILED(res))
    goto done;

  for (i = 0; i < count && NS_SUCCEEDED(res); i++) {
    array[i].item = (nsMenuEntry *)aArray->ElementAt(i);

    res = collation->AllocateRawSortKey(nsICollation::kCollationCaseInSensitive, 
                                       (array[i].item)->mTitle, &array[i].key, &array[i].len);
  }

  // reorder the array
  if (NS_SUCCEEDED(res)) {
    NS_QuickSort(array, count, sizeof(*array), CompareMenuItems, collation);

    // move the elements from the temporary array into the the real one
    aArray->Clear();
    for (i = 0; i < count; i++) {
      aArray->AppendElement(array[i].item);
    }
  }

done:
  for (i = 0; i < count; i++) {
    PR_FREEIF(array[i].key);
  }
  delete [] array;
  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::SetArrayFromEnumerator ( nsIUTF8StringEnumerator aEnumerator,
nsCStringArray &  aArray 
) [static, private]

Definition at line 373 of file nsCharsetMenu.cpp.

{
  nsresult rv;
  
  PRBool hasMore;
  rv = aEnumerator->HasMore(&hasMore);
  
  nsCAutoString value;
  while (NS_SUCCEEDED(rv) && hasMore) {
    rv = aEnumerator->GetNext(value);
    if (NS_SUCCEEDED(rv))
      aArray.AppendCString(value);

    rv = aEnumerator->HasMore(&hasMore);
  }

  return rv;
}

Here is the caller graph for this function:

nsresult nsCharsetMenu::SetCharsetCheckmark ( nsString aCharset,
PRBool  aValue 
) [private]

Definition at line 821 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;
  nsCOMPtr<nsIRDFContainer> container;
  nsCOMPtr<nsIRDFResource> node;

  res = NewRDFContainer(mInner, kNC_BrowserCharsetMenuRoot, getter_AddRefs(container));
  if (NS_FAILED(res)) return res;

  // find RDF node for given charset
  res = mRDFService->GetUnicodeResource(*aCharset, getter_AddRefs(node));
  if (NS_FAILED(res)) return res;

  // set checkmark value
  nsCOMPtr<nsIRDFLiteral> checkedLiteral;
  nsAutoString checked; checked.AssignWithConversion((aValue == PR_TRUE) ? "true" : "false");
  res = mRDFService->GetLiteral(checked.get(), getter_AddRefs(checkedLiteral));
  if (NS_FAILED(res)) return res;
  res = Assert(node, kNC_Checked, checkedLiteral, PR_TRUE);
  if (NS_FAILED(res)) return res;

  return res;
}

Here is the call graph for this function:

void nsICurrentCharsetListener::SetCurrentCharset ( in wstring  charset) [inherited]

Definition at line 1835 of file nsCharsetMenu.cpp.

{
  NS_TIMELINE_START_TIMER("nsCharsetMenu:SetCurrentCharset");
  nsresult res = NS_OK;

  if (mBrowserMenuInitialized) {
    // Don't add item to the cache if it's marked "notForBrowser"
    nsAutoString str;
    res = mCCManager->GetCharsetData(NS_LossyConvertUTF16toASCII(aCharset).get(),
                                     NS_LITERAL_STRING(".notForBrowser").get(), str);
    if (NS_SUCCEEDED(res)) // succeeded means attribute exists
      return res; // don't throw

    res = AddCharsetToCache(NS_LossyConvertUCS2toASCII(aCharset),
                            &mBrowserMenu, kNC_BrowserCharsetMenuRoot, 
                            mBrowserCacheStart, mBrowserCacheSize,
                            mBrowserMenuRDFPosition);
    if (NS_FAILED(res)) {
        NS_TIMELINE_LEAVE("nsCharsetMenu:SetCurrentCharset");
        return res;
    }

    res = WriteCacheToPrefs(&mBrowserMenu, mBrowserCacheStart, 
      kBrowserCachePrefKey);
  } else {
    res = UpdateCachePrefs(kBrowserCachePrefKey, kBrowserCacheSizePrefKey, 
                           kBrowserStaticPrefKey, aCharset);
  }
  NS_TIMELINE_STOP_TIMER("nsCharsetMenu:SetCurrentCharset");
  NS_TIMELINE_MARK_TIMER("nsCharsetMenu:SetCurrentCharset");
  return res;
}

Here is the call graph for this function:

Definition at line 1891 of file nsCharsetMenu.cpp.

Here is the call graph for this function:

void nsICurrentCharsetListener::SetCurrentMailCharset ( in wstring  charset) [inherited]

Definition at line 1868 of file nsCharsetMenu.cpp.

Here is the call graph for this function:

nsresult nsCharsetMenu::UpdateCachePrefs ( const char *  aCacheKey,
const char *  aCacheSizeKey,
const char *  aStaticKey,
const PRUnichar aCharset 
) [private]

Definition at line 1622 of file nsCharsetMenu.cpp.

{
  nsresult rv = NS_OK;
  nsXPIDLCString cachePrefValue;
  nsXPIDLCString staticPrefValue;
  NS_LossyConvertUTF16toASCII currentCharset(aCharset);
  PRInt32 cacheSize = 0;

  mPrefs->GetCharPref(aCacheKey, getter_Copies(cachePrefValue));
  mPrefs->GetCharPref(aStaticKey, getter_Copies(staticPrefValue));
  rv = mPrefs->GetIntPref(aCacheSizeKey, &cacheSize);

  if (NS_FAILED(rv) || cacheSize <= 0)
    return NS_ERROR_UNEXPECTED;

  if ((cachePrefValue.Find(currentCharset) == kNotFound) && 
      (staticPrefValue.Find(currentCharset) == kNotFound)) {

    if (!cachePrefValue.IsEmpty())
      cachePrefValue.Insert(", ", 0);

    cachePrefValue.Insert(currentCharset, 0);
    if (cacheSize < (PRInt32) cachePrefValue.CountChar(',') + 1)
      cachePrefValue.Truncate(cachePrefValue.RFindChar(','));

    rv = mPrefs->SetCharPref(aCacheKey, cachePrefValue);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsCharsetMenu::WriteCacheToPrefs ( nsVoidArray aArray,
PRInt32  aCacheStart,
const char *  aKey 
) [private]

Definition at line 1595 of file nsCharsetMenu.cpp.

{
  nsresult res = NS_OK;

  // create together the cache string
  nsCAutoString cache;
  nsCAutoString sep(NS_LITERAL_CSTRING(", "));
  PRInt32 count = aArray->Count();

  for (PRInt32 i = aCacheStart; i < count; i++) {
    nsMenuEntry * item = (nsMenuEntry *) aArray->ElementAt(i);
    if (item != NULL) {    
      cache.Append(item->mCharset);
      if (i < count - 1) {
        cache.Append(sep);
      }
    }
  }

  // write the pref
  res = mPrefs->SetCharPref(aKey, cache.get());

  return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 180 of file nsCharsetMenu.cpp.

Definition at line 163 of file nsCharsetMenu.cpp.

Definition at line 164 of file nsCharsetMenu.cpp.

Definition at line 166 of file nsCharsetMenu.cpp.

Definition at line 167 of file nsCharsetMenu.cpp.

Definition at line 168 of file nsCharsetMenu.cpp.

Definition at line 169 of file nsCharsetMenu.cpp.

Definition at line 170 of file nsCharsetMenu.cpp.

Definition at line 165 of file nsCharsetMenu.cpp.

Definition at line 171 of file nsCharsetMenu.cpp.

Definition at line 179 of file nsCharsetMenu.cpp.

Definition at line 178 of file nsCharsetMenu.cpp.

Definition at line 174 of file nsCharsetMenu.cpp.

Definition at line 175 of file nsCharsetMenu.cpp.

Definition at line 176 of file nsCharsetMenu.cpp.

Definition at line 172 of file nsCharsetMenu.cpp.

Definition at line 173 of file nsCharsetMenu.cpp.

Definition at line 177 of file nsCharsetMenu.cpp.

Definition at line 181 of file nsCharsetMenu.cpp.

Definition at line 191 of file nsCharsetMenu.cpp.

Definition at line 196 of file nsCharsetMenu.cpp.

Definition at line 195 of file nsCharsetMenu.cpp.

Definition at line 194 of file nsCharsetMenu.cpp.

Definition at line 186 of file nsCharsetMenu.cpp.

Definition at line 197 of file nsCharsetMenu.cpp.

Definition at line 210 of file nsCharsetMenu.cpp.

Definition at line 212 of file nsCharsetMenu.cpp.

Definition at line 206 of file nsCharsetMenu.cpp.

Definition at line 205 of file nsCharsetMenu.cpp.

Definition at line 204 of file nsCharsetMenu.cpp.

Definition at line 188 of file nsCharsetMenu.cpp.

Definition at line 207 of file nsCharsetMenu.cpp.

nsCStringArray nsCharsetMenu::mDecoderList [private]

Definition at line 213 of file nsCharsetMenu.cpp.

Definition at line 185 of file nsCharsetMenu.cpp.

Definition at line 183 of file nsCharsetMenu.cpp.

Definition at line 189 of file nsCharsetMenu.cpp.

Definition at line 201 of file nsCharsetMenu.cpp.

Definition at line 200 of file nsCharsetMenu.cpp.

Definition at line 199 of file nsCharsetMenu.cpp.

Definition at line 187 of file nsCharsetMenu.cpp.

Definition at line 202 of file nsCharsetMenu.cpp.

Definition at line 192 of file nsCharsetMenu.cpp.

Definition at line 211 of file nsCharsetMenu.cpp.

Definition at line 209 of file nsCharsetMenu.cpp.

Definition at line 190 of file nsCharsetMenu.cpp.


The documentation for this class was generated from the following file: