sbImmutablePropertyInfo.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-2011 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 #include "sbStandardOperators.h"
29 #include "sbPropertyOperator.h"
30 #include <nsAutoPtr.h>
31 
32 #include <nsIStringBundle.h>
33 
34 #include <nsArrayEnumerator.h>
35 #include <sbIPropertyManager.h>
36 #include <sbLockUtils.h>
37 
39 
41  mNullSort(sbIPropertyInfo::SORT_NULL_SMALL),
42  mUserViewable(PR_FALSE),
43  mUserEditable(PR_FALSE),
44  mRemoteReadable(PR_FALSE),
45  mRemoteWritable(PR_FALSE),
46  mUsedInIdentity(PR_FALSE),
47  mOperatorsLock(nsnull),
48  mUnitConverter(nsnull)
49 {
50  nsAutoString op;
51  nsRefPtr<sbPropertyOperator> propOp;
52 
53  mOperatorsLock = PR_NewLock();
54  NS_ASSERTION(mOperatorsLock,
55  "sbImmutablePropertyInfo::mOperatorsLock failed to create lock!");
56 }
57 
59  if(mOperatorsLock) {
60  PR_DestroyLock(mOperatorsLock);
61  }
62 }
63 
64 nsresult
66 {
67  nsresult rv;
68  nsAutoString op;
69  nsRefPtr<sbPropertyOperator> propOp;
70 
71  rv = sbImmutablePropertyInfo::GetOPERATOR_ISSET(op);
72  NS_ENSURE_SUCCESS(rv, rv);
73  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.isset"));
74  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
75  rv = mOperators.AppendObject(propOp);
76  NS_ENSURE_SUCCESS(rv, rv);
77 
78  rv = sbImmutablePropertyInfo::GetOPERATOR_ISNOTSET(op);
79  NS_ENSURE_SUCCESS(rv, rv);
80  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.isnotset"));
81  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
82  rv = mOperators.AppendObject(propOp);
83  NS_ENSURE_SUCCESS(rv, rv);
84 
85  return NS_OK;
86 }
87 
88 NS_IMETHODIMP
89 sbImmutablePropertyInfo::GetOPERATOR_EQUALS(nsAString& aOPERATOR_EQUALS)
90 {
91  aOPERATOR_EQUALS.AssignLiteral(SB_OPERATOR_EQUALS);
92  return NS_OK;
93 }
94 
95 NS_IMETHODIMP
96 sbImmutablePropertyInfo::GetOPERATOR_NOTEQUALS(nsAString& aOPERATOR_NOTEQUALS)
97 {
98  aOPERATOR_NOTEQUALS.AssignLiteral(SB_OPERATOR_NOTEQUALS);
99  return NS_OK;
100 }
101 
102 NS_IMETHODIMP
103 sbImmutablePropertyInfo::GetOPERATOR_GREATER(nsAString& aOPERATOR_GREATER)
104 {
105  aOPERATOR_GREATER.AssignLiteral(SB_OPERATOR_GREATER);
106  return NS_OK;
107 }
108 
109 NS_IMETHODIMP
110 sbImmutablePropertyInfo::GetOPERATOR_GREATEREQUAL(nsAString& aOPERATOR_GREATEREQUAL)
111 {
112  aOPERATOR_GREATEREQUAL.AssignLiteral(SB_OPERATOR_GREATEREQUAL);
113  return NS_OK;
114 }
115 
116 NS_IMETHODIMP
117 sbImmutablePropertyInfo::GetOPERATOR_LESS(nsAString& aOPERATOR_LESS)
118 {
119  aOPERATOR_LESS.AssignLiteral(SB_OPERATOR_LESS);
120  return NS_OK;
121 }
122 
123 NS_IMETHODIMP
124 sbImmutablePropertyInfo::GetOPERATOR_LESSEQUAL(nsAString& aOPERATOR_LESSEQUAL)
125 {
126  aOPERATOR_LESSEQUAL.AssignLiteral(SB_OPERATOR_LESSEQUAL);
127  return NS_OK;
128 }
129 
130 NS_IMETHODIMP
131 sbImmutablePropertyInfo::GetOPERATOR_CONTAINS(nsAString& aOPERATOR_CONTAINS)
132 {
133  aOPERATOR_CONTAINS.AssignLiteral(SB_OPERATOR_CONTAINS);
134  return NS_OK;
135 }
136 
137 NS_IMETHODIMP
138 sbImmutablePropertyInfo::GetOPERATOR_NOTCONTAINS(nsAString& aOPERATOR_NOTCONTAINS)
139 {
140  aOPERATOR_NOTCONTAINS.AssignLiteral(SB_OPERATOR_NOTCONTAINS);
141  return NS_OK;
142 }
143 
144 NS_IMETHODIMP
145 sbImmutablePropertyInfo::GetOPERATOR_BEGINSWITH(nsAString& aOPERATOR_BEGINSWITH)
146 {
147  aOPERATOR_BEGINSWITH.AssignLiteral(SB_OPERATOR_BEGINSWITH);
148  return NS_OK;
149 }
150 
151 NS_IMETHODIMP
152 sbImmutablePropertyInfo::GetOPERATOR_NOTBEGINSWITH(nsAString& aOPERATOR_NOTBEGINSWITH)
153 {
154  aOPERATOR_NOTBEGINSWITH.AssignLiteral(SB_OPERATOR_NOTBEGINSWITH);
155  return NS_OK;
156 }
157 
158 NS_IMETHODIMP
159 sbImmutablePropertyInfo::GetOPERATOR_ENDSWITH(nsAString& aOPERATOR_ENDSWITH)
160 {
161  aOPERATOR_ENDSWITH.AssignLiteral(SB_OPERATOR_ENDSWITH);
162  return NS_OK;
163 }
164 
165 NS_IMETHODIMP
166 sbImmutablePropertyInfo::GetOPERATOR_NOTENDSWITH(nsAString& aOPERATOR_NOTENDSWITH)
167 {
168  aOPERATOR_NOTENDSWITH.AssignLiteral(SB_OPERATOR_NOTENDSWITH);
169  return NS_OK;
170 }
171 
172 NS_IMETHODIMP
173 sbImmutablePropertyInfo::GetOPERATOR_BETWEEN(nsAString& aOPERATOR_BETWEEN)
174 {
175  aOPERATOR_BETWEEN.AssignLiteral(SB_OPERATOR_BETWEEN);
176  return NS_OK;
177 }
178 
179 NS_IMETHODIMP
180 sbImmutablePropertyInfo::GetOPERATOR_ISSET(nsAString & aOPERATOR_ISSET)
181 {
182  aOPERATOR_ISSET = NS_LITERAL_STRING(SB_OPERATOR_ISSET);
183  return NS_OK;
184 }
185 
186 NS_IMETHODIMP
187 sbImmutablePropertyInfo::GetOPERATOR_ISNOTSET(nsAString & aOPERATOR_ISNOTSET)
188 {
189  aOPERATOR_ISNOTSET = NS_LITERAL_STRING(SB_OPERATOR_ISNOTSET);
190  return NS_OK;
191 }
192 
193 
194 NS_IMETHODIMP
195 sbImmutablePropertyInfo::SetNullSort(PRUint32 aNullSort)
196 {
197  return NS_ERROR_NOT_IMPLEMENTED;
198 }
199 NS_IMETHODIMP
200 sbImmutablePropertyInfo::GetNullSort(PRUint32* aNullSort)
201 {
202  NS_ENSURE_ARG_POINTER(aNullSort);
203  *aNullSort = mNullSort;
204  return NS_OK;
205 }
206 
207 NS_IMETHODIMP
208 sbImmutablePropertyInfo::SetSecondarySort(sbIPropertyArray* aSecondarySort)
209 {
210  return NS_ERROR_NOT_IMPLEMENTED;
211 }
212 NS_IMETHODIMP
213 sbImmutablePropertyInfo::GetSecondarySort(sbIPropertyArray** aSecondarySort)
214 {
215  NS_ENSURE_ARG_POINTER(aSecondarySort);
216  NS_IF_ADDREF(*aSecondarySort = mSecondarySort);
217  return NS_OK;
218 }
219 
220 NS_IMETHODIMP
221 sbImmutablePropertyInfo::GetId(nsAString& aID)
222 {
223  aID = mID;
224  return NS_OK;
225 }
226 NS_IMETHODIMP
227 sbImmutablePropertyInfo::SetId(const nsAString& aID)
228 {
229  return NS_ERROR_NOT_IMPLEMENTED;
230 }
231 
232 NS_IMETHODIMP
233 sbImmutablePropertyInfo::GetType(nsAString& aType)
234 {
235  aType = mType;
236  return NS_OK;
237 }
238 NS_IMETHODIMP
239 sbImmutablePropertyInfo::SetType(const nsAString& aType)
240 {
241  return NS_ERROR_NOT_IMPLEMENTED;
242 }
243 
244 NS_IMETHODIMP
245 sbImmutablePropertyInfo::GetDisplayName(nsAString& aDisplayName)
246 {
247  aDisplayName = mDisplayName;
248  return NS_OK;
249 }
250 NS_IMETHODIMP
251 sbImmutablePropertyInfo::SetDisplayName(const nsAString& aDisplayName)
252 {
253  return NS_ERROR_NOT_IMPLEMENTED;
254 }
255 
256 /* attribute AString localizationKey; */
257 NS_IMETHODIMP
258 sbImmutablePropertyInfo::GetLocalizationKey(nsAString & aLocalizationKey)
259 {
260  aLocalizationKey = mLocalizationKey;
261  return NS_OK;
262 }
263 NS_IMETHODIMP
264 sbImmutablePropertyInfo::SetLocalizationKey(const nsAString & aLocalizationKey)
265 {
266  return NS_ERROR_NOT_IMPLEMENTED;
267 }
268 
269 NS_IMETHODIMP
270 sbImmutablePropertyInfo::GetUserViewable(PRBool *aUserViewable)
271 {
272  NS_ENSURE_ARG_POINTER(aUserViewable);
273  *aUserViewable = mUserViewable;
274  return NS_OK;
275 }
276 
277 NS_IMETHODIMP
278 sbImmutablePropertyInfo::SetUserViewable(PRBool aUserViewable)
279 {
280  return NS_ERROR_NOT_IMPLEMENTED;
281 }
282 
283 NS_IMETHODIMP
284 sbImmutablePropertyInfo::GetUserEditable(PRBool* aUserEditable)
285 {
286  NS_ENSURE_ARG_POINTER(aUserEditable);
287  *aUserEditable = mUserEditable;
288  return NS_OK;
289 }
290 
291 NS_IMETHODIMP
292 sbImmutablePropertyInfo::SetUserEditable(PRBool aUserEditable)
293 {
294  return NS_ERROR_NOT_IMPLEMENTED;
295 }
296 
297 NS_IMETHODIMP
298 sbImmutablePropertyInfo::GetRemoteReadable(PRBool* aRemoteReadable)
299 {
300  NS_ENSURE_ARG_POINTER(aRemoteReadable);
301  *aRemoteReadable = mRemoteReadable;
302  return NS_OK;
303 }
304 
305 NS_IMETHODIMP
306 sbImmutablePropertyInfo::SetRemoteReadable(PRBool aRemoteReadable)
307 {
308  return NS_ERROR_NOT_IMPLEMENTED;
309 }
310 
311 NS_IMETHODIMP
312 sbImmutablePropertyInfo::GetRemoteWritable(PRBool* aRemoteWritable)
313 {
314  NS_ENSURE_ARG_POINTER(aRemoteWritable);
315  *aRemoteWritable = mRemoteWritable;
316  return NS_OK;
317 }
318 
319 NS_IMETHODIMP
320 sbImmutablePropertyInfo::SetRemoteWritable(PRBool aRemoteWritable)
321 {
322  return NS_ERROR_NOT_IMPLEMENTED;
323 }
324 
325 NS_IMETHODIMP
326 sbImmutablePropertyInfo::GetOperators(nsISimpleEnumerator** aOperators)
327 {
328  NS_ENSURE_ARG_POINTER(aOperators);
329 
331  return NS_NewArrayEnumerator(aOperators, mOperators);
332 }
333 NS_IMETHODIMP
334 sbImmutablePropertyInfo::SetOperators(nsISimpleEnumerator* aOperators)
335 {
336  NS_ENSURE_ARG_POINTER(aOperators);
337 
339  mOperators.Clear();
340 
341  PRBool hasMore = PR_FALSE;
342  nsCOMPtr<nsISupports> object;
343 
344  while( NS_SUCCEEDED(aOperators->HasMoreElements(&hasMore)) &&
345  hasMore &&
346  NS_SUCCEEDED(aOperators->GetNext(getter_AddRefs(object)))) {
347  nsresult rv;
348  nsCOMPtr<sbIPropertyOperator> po = do_QueryInterface(object, &rv);
349  NS_ENSURE_SUCCESS(rv, rv);
350 
351  PRBool success = mOperators.AppendObject(po);
352  NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
353  }
354 
355  return NS_OK;
356 }
357 
358 NS_IMETHODIMP
359 sbImmutablePropertyInfo::GetOperator(const nsAString& aOperator,
360  sbIPropertyOperator** _retval)
361 {
362  NS_ENSURE_ARG_POINTER(_retval);
363 
365 
366  PRUint32 length = mOperators.Count();
367  for (PRUint32 i = 0; i < length; i++) {
368  nsAutoString op;
369  nsresult rv = mOperators[i]->GetOperator(op);
370  NS_ENSURE_SUCCESS(rv, rv);
371  if (op.Equals(aOperator)) {
372  NS_ADDREF(*_retval = mOperators[i]);
373  return NS_OK;
374  }
375  }
376 
377  *_retval = nsnull;
378  return NS_OK;
379 }
380 
381 NS_IMETHODIMP
382 sbImmutablePropertyInfo::Validate(const nsAString& aValue,
383  PRBool* _retval)
384 {
385  NS_ENSURE_ARG_POINTER(_retval);
386  *_retval = PR_TRUE;
387  return NS_OK;
388 }
389 
390 NS_IMETHODIMP
391 sbImmutablePropertyInfo::Sanitize(const nsAString& aValue,
392  nsAString& _retval)
393 {
394  _retval = aValue;
395  return NS_OK;
396 }
397 
398 NS_IMETHODIMP
399 sbImmutablePropertyInfo::Format(const nsAString& aValue,
400  nsAString& _retval)
401 {
402  _retval = aValue;
403  return NS_OK;
404 }
405 
406 NS_IMETHODIMP
407 sbImmutablePropertyInfo::MakeSortable(const nsAString& aValue,
408  nsAString& _retval)
409 {
410  // by default, the sortable value of a property is the same as the searchable
411  // value. this may be changed by specific properties, for instance by text
412  // properties which compute collation data for local-specific sort orders.
413  return MakeSearchable(aValue, _retval);
414 }
415 
416 NS_IMETHODIMP
417 sbImmutablePropertyInfo::MakeSearchable(const nsAString& aValue,
418  nsAString& _retval)
419 {
420  _retval = aValue;
421  return NS_OK;
422 }
423 
424 NS_IMETHODIMP
425 sbImmutablePropertyInfo::GetUnitConverter(sbIPropertyUnitConverter **retVal)
426 {
427  *retVal = mUnitConverter;
428  return NS_OK;
429 }
430 
431 NS_IMETHODIMP
433 {
434  mUnitConverter = aUnitConverter;
435  if (mUnitConverter)
436  mUnitConverter->SetPropertyInfo(this);
437  return NS_OK;
438 }
439 
440 NS_IMETHODIMP
441 sbImmutablePropertyInfo::GetUsedInIdentity(PRBool *aUsedInIdentity)
442 {
443  NS_ENSURE_ARG_POINTER(aUsedInIdentity);
444 
445  *aUsedInIdentity = mUsedInIdentity;
446  return NS_OK;
447 }
448 
449 NS_IMETHODIMP
450 sbImmutablePropertyInfo::SetUsedInIdentity(PRBool aUsedInIdentity)
451 {
452  return NS_ERROR_NOT_IMPLEMENTED;
453 }
nsCOMPtr< sbIPropertyUnitConverter > mUnitConverter
return NS_OK
onPageChanged aValue
Definition: FeedWriter.js:1395
#define SB_OPERATOR_NOTEQUALS
#define SB_OPERATOR_CONTAINS
#define SB_OPERATOR_NOTCONTAINS
#define SB_OPERATOR_ISNOTSET
NS_IMETHOD SetUnitConverter(sbIPropertyUnitConverter *aUnitConverter)
#define SB_OPERATOR_BEGINSWITH
#define SB_OPERATOR_GREATER
#define SB_OPERATOR_EQUALS
#define SB_OPERATOR_LESSEQUAL
nsCOMArray< sbIPropertyOperator > mOperators
An interface to represent an operator that may act upon a property.
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
nsCOMPtr< sbIPropertyArray > mSecondarySort
#define SB_OPERATOR_NOTENDSWITH
NS_IMPL_THREADSAFE_ISUPPORTS2(sbDeviceCapabilities, sbIDeviceCapabilities, nsIClassInfo) NS_IMPL_CI_INTERFACE_GETTER2(sbDeviceCapabilities
#define SB_OPERATOR_ISSET
#define SB_OPERATOR_NOTBEGINSWITH
StringArrayEnumerator prototype hasMore
Property unit converter interface This is an interface songbird property converter, used to convert a property value between its various units representations.
#define SB_OPERATOR_GREATEREQUAL
#define SB_OPERATOR_BETWEEN
#define SB_OPERATOR_LESS
#define SB_OPERATOR_ENDSWITH
An interface to carry around arrays of nsIProperty instances. Users of this interface should only QI ...
_getSelectedPageStyle s i