Adding the AutoDetect charset menu items. r=erik

This commit is contained in:
cata%netscape.com 2000-02-16 01:17:25 +00:00
parent ddb0159abd
commit d8ae72ac77
3 changed files with 208 additions and 25 deletions

View File

@ -26,25 +26,25 @@
## charset_name.title = a_title - specifies the human readable title for
## this charset
iso-8859-1.title = Western (ISO-8859-1)
iso-8859-2.title = Central European (ISO-8859-2)
iso-8859-3.title = South European (ISO-8859-3)
iso-8859-4.title = Baltic (ISO-8859-4)
iso-8859-9.title = Turkish (ISO-8859-9)
iso-8859-10.title = Nordic (ISO-8859-10)
iso-8859-13.title = Baltic (ISO-8859-13)
iso-8859-14.title = Celtic (ISO-8859-14)
iso-8859-15.title = Western (ISO-8859-15)
windows-1250.title = Central European (Windows-1250)
windows-1252.title = Western (Windows-1252)
windows-1254.title = Turkish (Windows-1254)
windows-1257.title = Baltic (Windows-1257)
x-mac-roman.title = Western (MacRoman)
x-mac-ce.title = Central European (MacCE)
x-mac-turkish.title = Turkish (MacTurkish)
x-mac-croatian.title = Croatian (MacCroatian)
x-mac-romanian.title = Romanian (MacRomanian)
x-mac-icelandic.title = Icelandic (MacIcelandic)
iso-8859-1.title = Western (ISO-8859-1)
iso-8859-2.title = Central European (ISO-8859-2)
iso-8859-3.title = South European (ISO-8859-3)
iso-8859-4.title = Baltic (ISO-8859-4)
iso-8859-9.title = Turkish (ISO-8859-9)
iso-8859-10.title = Nordic (ISO-8859-10)
iso-8859-13.title = Baltic (ISO-8859-13)
iso-8859-14.title = Celtic (ISO-8859-14)
iso-8859-15.title = Western (ISO-8859-15)
windows-1250.title = Central European (Windows-1250)
windows-1252.title = Western (Windows-1252)
windows-1254.title = Turkish (Windows-1254)
windows-1257.title = Baltic (Windows-1257)
x-mac-roman.title = Western (MacRoman)
x-mac-ce.title = Central European (MacCE)
x-mac-turkish.title = Turkish (MacTurkish)
x-mac-croatian.title = Croatian (MacCroatian)
x-mac-romanian.title = Romanian (MacRomanian)
x-mac-icelandic.title = Icelandic (MacIcelandic)
iso-2022-jp.title = Japanese (ISO-2022-JP)
shift_jis.title = Japanese (Shift_JIS)
euc-jp.title = Japanese (EUC-JP)
@ -86,3 +86,13 @@ ibm855.title = Cyrillic (IBM-855)
ibm857.title = Turkish (IBM-857)
ibm862.title = Hebrew (IBM-862)
ibm864.title = Arabic (IBM-864)
charsetDetector.off.title = Auto-Detect Off
charsetDetector.japsm.title = Auto-Detect (Japanese)
charsetDetector.kopsm.title = Auto-Detect (Korean)
charsetDetector.zhtwpsm.title = Auto-Detect (Traditional Chinese)
charsetDetector.zhcnpsm.title = Auto-Detect (Simplified Chinese)
charsetDetector.zhpsm.title = Auto-Detect (Chinese)
charsetDetector.cjkpsm.title = Auto-Detect (East Asian)
charsetDetector.ruprob.title = Auto-Detect (Russian)
charsetDetector.ukprob.title = Auto-Detect (Ukrainian)

View File

@ -28,6 +28,7 @@
#include "nsIServiceManager.h"
#include "nsICharsetConverterManager.h"
#include "nsIStringBundle.h"
#include "nsICharsetDetector.h"
#include "nsILocaleService.h"
#include "nsUConvDll.h"
#include "nsObjectArray.h"
@ -84,7 +85,7 @@ private:
nsresult GetConverterList(nsObjectArray * aArray, nsString *** aResult,
PRInt32 * aCount);
nsresult LoadExtensibleBundle(const char* aRegistryKey,
nsresult LoadExtensibleBundle(const char * aRegistryKey,
nsIStringBundle ** aResult);
static nsresult RegisterConverterTitles(nsIRegistry * aRegistry,
@ -99,6 +100,8 @@ private:
nsresult GetBundleValue(nsIStringBundle * aBundle, nsString * aName,
nsString * aProp, nsIAtom ** aResult);
nsresult GetRegistryEnumeration(char * aRegistryKey, nsStringArray * aArray);
public:
nsCharsetConverterManager();
@ -116,6 +119,7 @@ public:
NS_IMETHOD GetDecoderList(nsString *** aResult, PRInt32 * aCount);
NS_IMETHOD GetEncoderList(nsString *** aResult, PRInt32 * aCount);
NS_IMETHOD GetCharsetDetectorList(nsStringArray * aArray);
NS_IMETHOD GetCharsetData(nsString * aCharset, nsString * aProp,
nsString ** aResult);
@ -439,6 +443,82 @@ nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle,
return res;
}
nsresult nsCharsetConverterManager::GetRegistryEnumeration(
char * aRegistryKey,
nsStringArray * aArray)
{
nsresult res = NS_OK;
nsIEnumerator * components = NULL;
nsIRegistry * registry = NULL;
nsRegistryKey key;
PRBool regOpen = PR_FALSE;
// get the registry
res = nsServiceManager::GetService(NS_REGISTRY_PROGID,
NS_GET_IID(nsIRegistry), (nsISupports**)&registry);
if (NS_FAILED(res)) goto done;
// open registry if necessary
registry->IsOpen(&regOpen);
if (!regOpen) {
res = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry);
if (NS_FAILED(res)) goto done;
}
// get subtree
res = registry->GetSubtree(nsIRegistry::Common, aRegistryKey, &key);
if (NS_FAILED(res)) goto done;
// enumerate subtrees
res = registry->EnumerateSubtrees(key, &components);
if (NS_FAILED(res)) goto done;
res = components->First();
if (NS_FAILED(res)) goto done;
while (NS_OK != components->IsDone()) {
nsISupports * base = NULL;
nsIRegistryNode * node = NULL;
char * name = NULL;
nsString * s = NULL;
res = components->CurrentItem(&base);
if (NS_FAILED(res)) goto done1;
res = base->QueryInterface(kRegistryNodeIID, (void**)&node);
if (NS_FAILED(res)) goto done1;
res = node->GetName(&name);
if (NS_FAILED(res)) goto done1;
s = new nsString("charsetDetector.");
if (s == NULL) {
res = NS_ERROR_OUT_OF_MEMORY;
goto done1;
}
s->Append(name);
aArray->AppendString(*s);
done1:
NS_IF_RELEASE(base);
NS_IF_RELEASE(node);
if (name != NULL) nsCRT::free(name);
if (s != NULL) delete s;
res = components->Next();
if (NS_FAILED(res)) break; // this is NOT supposed to fail!
}
// finish and clean up
done:
if (registry != NULL) {
nsServiceManager::ReleaseService(NS_REGISTRY_PROGID, registry);
}
NS_IF_RELEASE(components);
return res;
}
//----------------------------------------------------------------------------
// Interface nsICharsetConverterManager [implementation]
@ -496,6 +576,12 @@ NS_IMETHODIMP nsCharsetConverterManager::GetEncoderList(nsString *** aResult,
return GetConverterList(&mEncoderArray, aResult, aCount);
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetDetectorList(
nsStringArray * aArray)
{
return GetRegistryEnumeration(NS_CHARSET_DETECTOR_REG_BASE, aArray);
}
NS_IMETHODIMP nsCharsetConverterManager::GetCharsetData(nsString * aCharset,
nsString * aProp,
nsString ** aResult)

View File

@ -66,6 +66,9 @@ static const char * kURINC_BrowserMore5CharsetMenuRoot = "NC:BrowserMore5Charset
static const char * kURINC_BrowserMore6CharsetMenuRoot = "NC:BrowserMore6CharsetMenuRoot";
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Checked);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, BookmarkSeparator);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, CharsetDetector);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, NC, type);
//----------------------------------------------------------------------------
// Class nsMenuItem [declaration]
@ -106,6 +109,9 @@ private:
static nsIRDFResource * kNC_BrowserMore6CharsetMenuRoot;
static nsIRDFResource * kNC_Name;
static nsIRDFResource * kNC_Checked;
static nsIRDFResource * kNC_CharsetDetector;
static nsIRDFResource * kNC_BookmarkSeparator;
static nsIRDFResource * kRDF_type;
static nsIRDFDataSource * mInner;
@ -126,15 +132,20 @@ private:
nsICharsetConverterManager * aCCMan, nsString ** aDecs, PRInt32 aCount);
nsresult InitBrowserMoreMenu(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan, nsString ** aDecs, PRInt32 aCount);
nsresult InitBrowserAutodetectMenu(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan, nsIRDFContainer * aContainer);
nsresult AddItemToMenu(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan, nsObjectArray * aObjectArray,
nsIRDFContainer * aContainer, nsString * aCharset);
nsIRDFContainer * aContainer, nsString * aCharset,
nsIRDFResource * aType = NULL);
nsresult AddItemToArray(nsICharsetConverterManager * aCCMan,
nsObjectArray * aObjectArray, nsString * aCharset,
nsMenuItem ** aResult, PRInt32 aPosition = -1);
nsresult AddItemToContainer(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan, nsIRDFContainer * aContainer,
nsMenuItem * aItem);
nsMenuItem * aItem, nsIRDFResource * aType = NULL);
nsresult AddSeparatorToContainer(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan, nsIRDFContainer * aContainer);
nsresult AddFromStringToMenu(char * aCharsetList,
nsIRDFService * aRDFServ, nsICharsetConverterManager * aCCMan,
nsObjectArray * aObjectArray, nsIRDFContainer * aContainer,
@ -278,6 +289,9 @@ nsIRDFResource * nsCharsetMenu::kNC_BrowserMore5CharsetMenuRoot = NULL;
nsIRDFResource * nsCharsetMenu::kNC_BrowserMore6CharsetMenuRoot = NULL;
nsIRDFResource * nsCharsetMenu::kNC_Name = NULL;
nsIRDFResource * nsCharsetMenu::kNC_Checked = NULL;
nsIRDFResource * nsCharsetMenu::kNC_CharsetDetector = NULL;
nsIRDFResource * nsCharsetMenu::kNC_BookmarkSeparator = NULL;
nsIRDFResource * nsCharsetMenu::kRDF_type = NULL;
nsCharsetMenu::nsCharsetMenu()
:mStaticCount(0), mCurrentCharset(-1)
@ -316,6 +330,9 @@ nsresult nsCharsetMenu::Init()
rdfServ->GetResource(kURINC_BrowserMore6CharsetMenuRoot, &kNC_BrowserMore6CharsetMenuRoot);
rdfServ->GetResource(kURINC_Name, &kNC_Name);
rdfServ->GetResource(kURINC_Checked, &kNC_Checked);
rdfServ->GetResource(kURINC_CharsetDetector, &kNC_CharsetDetector);
rdfServ->GetResource(kURINC_BookmarkSeparator, &kNC_BookmarkSeparator);
rdfServ->GetResource(kURINC_type, &kRDF_type);
res = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID, nsnull,
kIRDFDataSourceIID, (void**) &mInner);
@ -377,6 +394,9 @@ done:
NS_IF_RELEASE(kNC_BrowserMore6CharsetMenuRoot);
NS_IF_RELEASE(kNC_Name);
NS_IF_RELEASE(kNC_Checked);
NS_IF_RELEASE(kNC_CharsetDetector);
NS_IF_RELEASE(kNC_BookmarkSeparator);
NS_IF_RELEASE(kRDF_type);
NS_IF_RELEASE(mInner);
return res;
@ -450,6 +470,13 @@ nsresult nsCharsetMenu::InitBrowserStaticMenu(nsIRDFService * aRDFServ,
NS_WITH_SERVICE(nsIPref, pref, NS_PREF_PROGID, &res);
if (NS_FAILED(res)) return res;
// XXX work around bug that causes the submenus to be first instead of last
AddSeparatorToContainer(aRDFServ, aCCMan, container);
InitBrowserAutodetectMenu(aRDFServ, aCCMan, container);
AddSeparatorToContainer(aRDFServ, aCCMan, container);
AddFromPrefsToMenu(pref, aRDFServ, aCCMan, &mBrowserMenu, container,
"intl.charset_menu.static", aDecs, aCount);
mStaticCount = mBrowserMenu.GetUsage();
@ -554,11 +581,34 @@ nsresult nsCharsetMenu::InitBrowserMoreMenu(nsIRDFService * aRDFServ,
return res;
}
nsresult nsCharsetMenu::InitBrowserAutodetectMenu(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan,
nsIRDFContainer * aContainer)
{
nsresult res = NS_OK;
nsObjectArray mBrowserAutodetectMenu;
nsStringArray array;
res = aCCMan->GetCharsetDetectorList(&array);
if (NS_FAILED(res)) return res;
for (PRInt32 i = 0; i < array.Count(); i++) {
res = AddItemToMenu(aRDFServ, aCCMan, &mBrowserAutodetectMenu, aContainer,
array.StringAt(i), kNC_CharsetDetector);
if (NS_FAILED(res)) return res;
}
// XXX at some point add reordering here
return res;
}
nsresult nsCharsetMenu::AddItemToMenu(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan,
nsObjectArray * aObjectArray,
nsIRDFContainer * aContainer,
nsString * aCharset)
nsString * aCharset,
nsIRDFResource * aType)
{
nsresult res = NS_OK;
nsMenuItem * item = NULL;
@ -566,7 +616,7 @@ nsresult nsCharsetMenu::AddItemToMenu(nsIRDFService * aRDFServ,
res = AddItemToArray(aCCMan, aObjectArray, aCharset, &item);
if (NS_FAILED(res)) goto done;
res = AddItemToContainer(aRDFServ, aCCMan, aContainer, item);
res = AddItemToContainer(aRDFServ, aCCMan, aContainer, item, aType);
if (NS_FAILED(res)) goto done;
item = NULL;
@ -622,7 +672,8 @@ done:
nsresult nsCharsetMenu::AddItemToContainer(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan,
nsIRDFContainer * aContainer,
nsMenuItem * aItem)
nsMenuItem * aItem,
nsIRDFResource * aType)
{
nsresult res = NS_OK;
nsCOMPtr<nsIRDFResource> node;
@ -642,6 +693,42 @@ nsresult nsCharsetMenu::AddItemToContainer(nsIRDFService * aRDFServ,
res = aRDFServ->GetLiteral(title, getter_AddRefs(titleLiteral));
if (NS_FAILED(res)) return res;
res = Assert(node, kNC_Name, titleLiteral, PR_TRUE);
if (NS_FAILED(res)) return res;
if (aType != NULL) {
res = Assert(node, kRDF_type, aType, PR_TRUE);
if (NS_FAILED(res)) return res;
}
// Add the element to the container
res = aContainer->AppendElement(node);
if (NS_FAILED(res)) return res;
return res;
}
// XXX unify with AddItemToContainer
nsresult nsCharsetMenu::AddSeparatorToContainer(nsIRDFService * aRDFServ,
nsICharsetConverterManager * aCCMan,
nsIRDFContainer * aContainer)
{
nsresult res = NS_OK;
nsCOMPtr<nsIRDFResource> node;
// Make up a unique ID and create the RDF NODE
char csID[] = "-----";
res = aRDFServ->GetResource(csID, getter_AddRefs(node));
if (NS_FAILED(res)) return res;
nsAutoString str(csID);
// set node's title
nsCOMPtr<nsIRDFLiteral> titleLiteral;
res = aRDFServ->GetLiteral(str.GetUnicode(), getter_AddRefs(titleLiteral));
if (NS_FAILED(res)) return res;
res = Assert(node, kNC_Name, titleLiteral, PR_TRUE);
if (NS_FAILED(res)) return res;
res = Assert(node, kRDF_type, kNC_BookmarkSeparator, PR_TRUE);
if (NS_FAILED(res)) return res;
// Add the element to the container