sbAbstractPropertyBuilder.cpp
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
28 
29 #include <nsAutoPtr.h>
30 
31 #include <nsServiceManagerUtils.h>
32 
33 #include <sbIPropertyArray.h>
34 #include <sbIPropertyManager.h>
35 #include <nsIStringBundle.h>
36 
37 #ifdef DEBUG
38 #include <prprf.h>
39 #endif
40 
43 
45  mUserViewable(PR_FALSE),
46  mUserEditable(PR_TRUE),
47  mRemoteReadable(PR_FALSE),
48  mRemoteWritable(PR_FALSE)
49 {
50 }
51 
52 nsresult
54 {
55  nsresult rv;
56  rv = CreateBundle("chrome://songbird/locale/songbird.properties",
57  getter_AddRefs(mBundle));
58  NS_ENSURE_SUCCESS(rv, rv);
59 
60  return NS_OK;
61 }
62 
63 nsresult
65 {
66  if (!mDisplayNameKey.IsEmpty()) {
67  nsresult rv = GetStringFromName(mBundle, mDisplayNameKey, aDisplayName);
68  NS_ENSURE_SUCCESS(rv, rv);
69  }
70  else {
71  aDisplayName = mDisplayName;
72  }
73 
74  return NS_OK;
75 }
76 
77 /* static */ nsresult
79  const nsAString& aName,
80  nsAString& _retval)
81 {
82  NS_ENSURE_ARG_POINTER(aBundle);
83 
84  nsString value;
85  nsresult rv = aBundle->GetStringFromName(aName.BeginReading(),
86  getter_Copies(value));
87  if (NS_SUCCEEDED(rv)) {
88  _retval = value;
89  }
90  else {
91 #ifdef DEBUG
92  char* message = PR_smprintf("sbPropertyManager: '%s' not found in bundle",
93  NS_LossyConvertUTF16toASCII(aName).get());
94  NS_WARNING(message);
95  PR_smprintf_free(message);
96 #endif
97  _retval = aName;
98  }
99 
100  return NS_OK;
101 }
102 
103 /* static */ nsresult
105  nsIStringBundle** _retval)
106 {
107  NS_ENSURE_ARG_POINTER(aURLSpec);
108  NS_ENSURE_ARG_POINTER(_retval);
109 
110  nsresult rv;
111  nsCOMPtr<nsIStringBundleService> stringBundleService =
112  do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
113  NS_ENSURE_SUCCESS(rv, rv);
114 
115  nsCOMPtr<nsIStringBundle> stringBundle;
116  rv = stringBundleService->CreateBundle(aURLSpec, _retval);
117  NS_ENSURE_SUCCESS(rv, rv);
118 
119  return NS_OK;
120 }
121 
122 NS_IMETHODIMP
123 sbAbstractPropertyBuilder::Get(sbIPropertyInfo** _retval)
124 {
125  return NS_ERROR_NOT_IMPLEMENTED;
126 }
127 
128 NS_IMETHODIMP
129 sbAbstractPropertyBuilder::GetPropertyID(nsAString& aPropertyID)
130 {
131  aPropertyID = mPropertyID;
132  return NS_OK;
133 }
134 NS_IMETHODIMP
135 sbAbstractPropertyBuilder::SetPropertyID(const nsAString& aPropertyID)
136 {
137  mPropertyID = aPropertyID;
138  return NS_OK;
139 }
140 
141 NS_IMETHODIMP
142 sbAbstractPropertyBuilder::GetDisplayName(nsAString& aDisplayName)
143 {
144  aDisplayName = mDisplayName;
145  return NS_OK;
146 }
147 NS_IMETHODIMP
148 sbAbstractPropertyBuilder::SetDisplayName(const nsAString& aDisplayName)
149 {
150  mDisplayName = aDisplayName;
151  return NS_OK;
152 }
153 
154 NS_IMETHODIMP
155 sbAbstractPropertyBuilder::GetDisplayNameKey(nsAString& aDisplayNameKey)
156 {
157  aDisplayNameKey = mDisplayNameKey;
158  return NS_OK;
159 }
160 NS_IMETHODIMP
161 sbAbstractPropertyBuilder::SetDisplayNameKey(const nsAString& aDisplayNameKey)
162 {
163  mDisplayNameKey = aDisplayNameKey;
164  return NS_OK;
165 }
166 
167 NS_IMETHODIMP
168 sbAbstractPropertyBuilder::GetUserViewable(PRBool* aUserViewable)
169 {
170  NS_ENSURE_ARG_POINTER(aUserViewable);
171  *aUserViewable = mUserViewable;
172  return NS_OK;
173 }
174 NS_IMETHODIMP
175 sbAbstractPropertyBuilder::SetUserViewable(PRBool aUserViewable)
176 {
177  mUserViewable = aUserViewable;
178  return NS_OK;
179 }
180 
181 NS_IMETHODIMP
182 sbAbstractPropertyBuilder::GetUserEditable(PRBool* aUserEditable)
183 {
184  NS_ENSURE_ARG_POINTER(aUserEditable);
185  *aUserEditable = mUserEditable;
186  return NS_OK;
187 }
188 NS_IMETHODIMP
189 sbAbstractPropertyBuilder::SetUserEditable(PRBool aUserEditable)
190 {
191  mUserEditable = aUserEditable;
192  return NS_OK;
193 }
194 
195 NS_IMETHODIMP
196 sbAbstractPropertyBuilder::GetRemoteReadable(PRBool* aRemoteReadable)
197 {
198  NS_ENSURE_ARG_POINTER(aRemoteReadable);
199  *aRemoteReadable = mRemoteReadable;
200  return NS_OK;
201 }
202 NS_IMETHODIMP
203 sbAbstractPropertyBuilder::SetRemoteReadable(PRBool aRemoteReadable)
204 {
205  mRemoteReadable = aRemoteReadable;
206  return NS_OK;
207 }
208 
209 NS_IMETHODIMP
210 sbAbstractPropertyBuilder::GetRemoteWritable(PRBool* aRemoteWritable)
211 {
212  NS_ENSURE_ARG_POINTER(aRemoteWritable);
213  *aRemoteWritable = mRemoteWritable;
214  return NS_OK;
215 }
216 NS_IMETHODIMP
217 sbAbstractPropertyBuilder::SetRemoteWritable(PRBool aRemoteWritable)
218 {
219  mRemoteWritable = aRemoteWritable;
220  return NS_OK;
221 }
222 
return NS_OK
nsresult GetFinalDisplayName(nsAString &aDisplayName)
nsCOMPtr< nsIStringBundle > mBundle
NS_IMPL_ISUPPORTS1(sbAbstractPropertyBuilder, sbIPropertyBuilder) sbAbstractPropertyBuilder
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
GstMessage * message
_updateCookies aName
countRef value
Definition: FeedWriter.js:1423
static nsresult CreateBundle(const char *aURLSpec, nsIStringBundle **_retval)
static nsresult GetStringFromName(nsIStringBundle *aBundle, const nsAString &aName, nsAString &_retval)