Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "core_resource.hxx"
22 : :
23 : : #include <tools/resmgr.hxx>
24 : :
25 : : // ---- needed as long as we have no contexts for components ---
26 : : #include <vcl/svapp.hxx>
27 : : //---------------------------------------------------
28 : : #include <rtl/instance.hxx>
29 : : #include <svl/solar.hrc>
30 : :
31 : : //.........................................................................
32 : : namespace dbaccess
33 : : {
34 : :
35 : : //==================================================================
36 : : //= ResourceManager
37 : : //==================================================================
38 : : namespace
39 : : {
40 : : // access safety
41 : : struct theResourceManagerMutex : public rtl::Static< osl::Mutex, theResourceManagerMutex > {};
42 : : }
43 : :
44 : : sal_Int32 ResourceManager::s_nClients = 0;
45 : : ResMgr* ResourceManager::m_pImpl = NULL;
46 : :
47 : : //------------------------------------------------------------------
48 : 34 : void ResourceManager::ensureImplExists()
49 : : {
50 [ + + ]: 34 : if (m_pImpl)
51 : 34 : return;
52 : :
53 [ + - ][ + - ]: 4 : ::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
54 : :
55 [ + - ]: 34 : m_pImpl = ResMgr::CreateResMgr("dba", aLocale);
56 : : }
57 : :
58 : : //------------------------------------------------------------------
59 : 34 : ::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
60 : : {
61 : 34 : ::rtl::OUString sReturn;
62 : :
63 [ + - ]: 34 : ensureImplExists();
64 [ + - ]: 34 : if (m_pImpl)
65 [ + - ][ + - ]: 34 : sReturn = String(ResId(_nResId,*m_pImpl));
[ + - ]
66 : :
67 : 34 : return sReturn;
68 : : }
69 : :
70 : : //------------------------------------------------------------------
71 : 0 : ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const ::rtl::OUString& _rReplace )
72 : : {
73 [ # # ][ # # ]: 0 : String sString( loadString( _nResId ) );
74 [ # # ][ # # ]: 0 : sString.SearchAndReplaceAscii( _pPlaceholderAscii, _rReplace );
[ # # ]
75 [ # # ][ # # ]: 0 : return sString;
76 : : }
77 : :
78 : : //------------------------------------------------------------------
79 : 0 : ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii1, const ::rtl::OUString& _rReplace1,
80 : : const sal_Char* _pPlaceholderAscii2, const ::rtl::OUString& _rReplace2 )
81 : : {
82 [ # # ][ # # ]: 0 : String sString( loadString( _nResId ) );
83 [ # # ][ # # ]: 0 : sString.SearchAndReplaceAscii( _pPlaceholderAscii1, _rReplace1 );
[ # # ]
84 [ # # ][ # # ]: 0 : sString.SearchAndReplaceAscii( _pPlaceholderAscii2, _rReplace2 );
[ # # ]
85 [ # # ][ # # ]: 0 : return sString;
86 : : }
87 : :
88 : : //-------------------------------------------------------------------------
89 : 498 : void ResourceManager::registerClient()
90 : : {
91 [ + - ][ + - ]: 498 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
92 [ + - ]: 498 : ++s_nClients;
93 : 498 : }
94 : :
95 : : //-------------------------------------------------------------------------
96 : 491 : void ResourceManager::revokeClient()
97 : : {
98 [ + - ][ + - ]: 491 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
99 [ + + ][ + + ]: 491 : if (!--s_nClients && m_pImpl)
[ + + ]
100 : : {
101 [ + - ][ + - ]: 4 : delete m_pImpl;
102 : 4 : m_pImpl = NULL;
103 [ + - ]: 491 : }
104 : 491 : }
105 : : //.........................................................................
106 : : }
107 : : //.........................................................................
108 : :
109 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|