1999-10-18 23:58:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-10-18 23:58:07 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-10-18 23:58:07 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-10-18 23:58:07 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-10-18 23:58:07 +04:00
|
|
|
*/
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsOEStringBundle.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2000-06-24 04:03:10 +04:00
|
|
|
#include "nsIProxyObjectManager.h"
|
1999-10-18 23:58:07 +04:00
|
|
|
#include "nsIURI.h"
|
|
|
|
|
|
|
|
/* This is the next generation string retrieval call */
|
|
|
|
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
2000-12-05 07:30:55 +03:00
|
|
|
static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
|
1999-10-18 23:58:07 +04:00
|
|
|
|
|
|
|
#define OE_MSGS_URL "chrome://messenger/locale/oeImportMsgs.properties"
|
|
|
|
|
2000-03-12 00:30:17 +03:00
|
|
|
nsIStringBundle * nsOEStringBundle::m_pBundle = nsnull;
|
|
|
|
|
1999-10-18 23:58:07 +04:00
|
|
|
nsIStringBundle *nsOEStringBundle::GetStringBundle( void)
|
|
|
|
{
|
2000-03-12 00:30:17 +03:00
|
|
|
if (m_pBundle)
|
|
|
|
return( m_pBundle);
|
|
|
|
|
1999-10-18 23:58:07 +04:00
|
|
|
nsresult rv;
|
|
|
|
char* propertyURL = OE_MSGS_URL;
|
|
|
|
nsIStringBundle* sBundle = nsnull;
|
|
|
|
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != sBundleService)) {
|
2001-04-28 01:30:24 +04:00
|
|
|
rv = sBundleService->CreateBundle(propertyURL, &sBundle);
|
1999-10-18 23:58:07 +04:00
|
|
|
}
|
|
|
|
|
2000-03-12 00:30:17 +03:00
|
|
|
m_pBundle = sBundle;
|
|
|
|
|
1999-10-18 23:58:07 +04:00
|
|
|
return( sBundle);
|
|
|
|
}
|
|
|
|
|
2000-03-12 00:30:17 +03:00
|
|
|
nsIStringBundle *nsOEStringBundle::GetStringBundleProxy( void)
|
|
|
|
{
|
|
|
|
if (!m_pBundle)
|
|
|
|
return( nsnull);
|
|
|
|
|
|
|
|
nsIStringBundle *strProxy = nsnull;
|
|
|
|
nsresult rv;
|
|
|
|
// create a proxy object if we aren't on the same thread?
|
|
|
|
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2000-06-24 04:03:10 +04:00
|
|
|
rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
|
2000-03-12 00:30:17 +03:00
|
|
|
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
return( strProxy);
|
|
|
|
}
|
|
|
|
|
1999-10-18 23:58:07 +04:00
|
|
|
void nsOEStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
|
|
|
|
{
|
|
|
|
|
|
|
|
PRUnichar *ptrv = GetStringByID( stringID, pBundle);
|
|
|
|
result = ptrv;
|
|
|
|
FreeString( ptrv);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUnichar *nsOEStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle *pBundle)
|
|
|
|
{
|
|
|
|
if (!pBundle) {
|
|
|
|
pBundle = GetStringBundle();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pBundle) {
|
|
|
|
PRUnichar *ptrv = nsnull;
|
|
|
|
nsresult rv = pBundle->GetStringFromID(stringID, &ptrv);
|
2000-03-12 00:30:17 +03:00
|
|
|
|
1999-10-18 23:58:07 +04:00
|
|
|
if (NS_SUCCEEDED( rv) && ptrv)
|
|
|
|
return( ptrv);
|
|
|
|
}
|
|
|
|
|
2000-04-28 08:07:58 +04:00
|
|
|
nsString resultString;
|
|
|
|
resultString.AppendWithConversion("[StringID ");
|
|
|
|
resultString.AppendInt(stringID, 10);
|
|
|
|
resultString.AppendWithConversion("?]");
|
1999-10-18 23:58:07 +04:00
|
|
|
|
|
|
|
return( resultString.ToNewUnicode());
|
|
|
|
}
|
|
|
|
|
2000-03-12 00:30:17 +03:00
|
|
|
void nsOEStringBundle::Cleanup( void)
|
|
|
|
{
|
|
|
|
if (m_pBundle)
|
|
|
|
m_pBundle->Release();
|
|
|
|
m_pBundle = nsnull;
|
2000-04-02 11:17:25 +04:00
|
|
|
}
|