2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-10-18 23:58:07 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04: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
|
|
|
*
|
2001-09-29 00:14:13 +04: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.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-10-18 23:58:07 +04:00
|
|
|
#include "prprf.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-10-18 23:58:07 +04:00
|
|
|
#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"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> sBundleService =
|
2002-10-02 11:52:55 +04:00
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
1999-10-18 23:58:07 +04:00
|
|
|
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?
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIProxyObjectManager> proxyMgr =
|
|
|
|
do_GetService(kProxyObjectManagerCID, &rv);
|
2000-03-12 00:30:17 +03:00
|
|
|
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;
|
2001-12-16 14:58:03 +03:00
|
|
|
resultString.Append(NS_LITERAL_STRING("[StringID "));
|
2000-04-28 08:07:58 +04:00
|
|
|
resultString.AppendInt(stringID, 10);
|
2001-12-16 14:58:03 +03:00
|
|
|
resultString.Append(NS_LITERAL_STRING("?]"));
|
1999-10-18 23:58:07 +04:00
|
|
|
|
2001-09-29 12:28:41 +04:00
|
|
|
return( ToNewUnicode(resultString));
|
1999-10-18 23:58:07 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|