sbStringBundleService.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4 //
5 // BEGIN SONGBIRD GPL
6 //
7 // This file is part of the Songbird web player.
8 //
9 // Copyright(c) 2005-2008 POTI, Inc.
10 // http://songbirdnest.com
11 //
12 // This file may be licensed under the terms of of the
13 // GNU General Public License Version 2 (the "GPL").
14 //
15 // Software distributed under the License is distributed
16 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
17 // express or implied. See the GPL for the specific language
18 // governing rights and limitations.
19 //
20 // You should have received a copy of the GPL along with this
21 // program. If not, go to http://www.gnu.org/licenses/gpl.html
22 // or write to the Free Software Foundation, Inc.,
23 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 // END SONGBIRD GPL
26 //
27 */
28 
29 #ifndef __SB_STRINGBUNDLESERVICE_H__
30 #define __SB_STRINGBUNDLESERVICE_H__
31 
32 //------------------------------------------------------------------------------
33 //------------------------------------------------------------------------------
34 //
35 // Songbird string bundle service.
36 //
37 //------------------------------------------------------------------------------
38 //------------------------------------------------------------------------------
39 
45 //------------------------------------------------------------------------------
46 //
47 // Songbird string bundle service imported services.
48 //
49 //------------------------------------------------------------------------------
50 
51 // Songbird imports.
52 #include <sbIStringBundleService.h>
53 
54 // Mozilla imports.
55 #include <nsCOMArray.h>
56 #include <nsCOMPtr.h>
57 #include <nsIObserver.h>
58 #include <nsIStringBundle.h>
59 
60 
61 //------------------------------------------------------------------------------
62 //
63 // Songbird string bundle service defs.
64 //
65 //------------------------------------------------------------------------------
66 
67 //
68 // Songbird string bundle service component defs.
69 //
70 
71 #define SB_STRINGBUNDLESERVICE_CLASSNAME "sbStringBundleService"
72 #define SB_STRINGBUNDLESERVICE_CID \
73  /* {04134658-9CF9-4FEA-90C0-BC159C016037} */ \
74  { \
75  0x04134658, \
76  0x9CF9, \
77  0x4FEA, \
78  { 0x90, 0xC0, 0xBC, 0x15, 0x9C, 0x01, 0x60, 0x37 } \
79  }
80 
81 
82 //------------------------------------------------------------------------------
83 //
84 // Songbird string bundle service classes.
85 //
86 //------------------------------------------------------------------------------
87 
93 class sbStringBundleService : public nsIStringBundleService,
94  public nsIObserver,
96 {
97  //----------------------------------------------------------------------------
98  //
99  // Public interface.
100  //
101  //----------------------------------------------------------------------------
102 
103 public:
104 
105  //
106  // Inherited interfaces.
107  //
108 
110  NS_DECL_NSISTRINGBUNDLESERVICE
111  NS_DECL_NSIOBSERVER
112  NS_DECL_SBISTRINGBUNDLESERVICE
113 
114 
115  //
116  // Public services.
117  //
118 
120 
121  virtual ~sbStringBundleService();
122 
123  nsresult Initialize();
124  nsresult ReloadBundles();
125 
126 
127  //----------------------------------------------------------------------------
128  //
129  // Private interface.
130  //
131  //----------------------------------------------------------------------------
132 
133 private:
134 
135  //
136  // mBaseStringBundleService Base string bundle service.
137  // mBundle Main Songbird string bundle.
138  // mBrandBundle Main Songbird brand string bundle.
139  //
140 
141  nsCOMPtr<nsIStringBundleService>
142  mBaseStringBundleService;
143  nsCOMPtr<nsIStringBundle> mBundle;
144  nsCOMPtr<nsIStringBundle> mBrandBundle;
145 };
146 
147 
175 class sbStringBundle: public nsIStringBundle
176 {
177  //----------------------------------------------------------------------------
178  //
179  // Public interface.
180  //
181  //----------------------------------------------------------------------------
182 
183 public:
184 
185  //
186  // Inherited interfaces.
187  //
188 
190  NS_DECL_NSISTRINGBUNDLE
191 
192 
193  //
194  // Public services.
195  //
196 
197  static nsresult New(nsIStringBundle* aBaseStringBundle,
198  sbStringBundle** aStringBundle);
199 
200  virtual ~sbStringBundle();
201 
202 
203  //----------------------------------------------------------------------------
204  //
205  // Private interface.
206  //
207  //----------------------------------------------------------------------------
208 
209 private:
210 
211  //
212  // mBaseStringBundleService Base string bundle service.
213  // mBaseStringBundle Base string bundle.
214  // mStringBundleList List of loaded string bundles.
215  //
216 
217  nsCOMPtr<nsIStringBundleService>
218  mBaseStringBundleService;
219  nsCOMPtr<nsIStringBundle> mBaseStringBundle;
220  nsCOMArray<nsIStringBundle> mStringBundleList;
221 
222 
223  //
224  // Private services.
225  //
226 
227  sbStringBundle(nsIStringBundle* aBaseStringBundle);
228 
229  nsresult Initialize();
230 
231  nsresult LoadBundle(nsAString& aBundleURLSpec);
232 
233  nsresult LoadBundle(nsIStringBundle* aBundle);
234 
235  nsresult ApplySubstitutions(nsAString& aString);
236 };
237 
238 
239 #endif // __SB_STRINGBUNDLESERVICE_H__
240 
NS_DECL_ISUPPORTS NS_DECL_NSISTRINGBUNDLESERVICE NS_DECL_NSIOBSERVER NS_DECL_SBISTRINGBUNDLESERVICE sbStringBundleService()
NS_DECL_ISUPPORTS static NS_DECL_NSISTRINGBUNDLE nsresult New(nsIStringBundle *aBaseStringBundle, sbStringBundle **aStringBundle)
Interface for the Songbird string bundle service. Instantiate as a component service.