sbBooleanPropertyInfo.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 
27 #include "sbBooleanPropertyInfo.h"
28 #include "sbStandardOperators.h"
29 #include <nsAutoPtr.h>
30 #include <nsITreeView.h>
31 
37 
39 {
40  MOZ_COUNT_CTOR(sbBooleanPropertyInfo);
41  mType = NS_LITERAL_STRING("boolean");
42  mSuppressSelect = PR_TRUE;
43 }
44 
46 {
47  MOZ_COUNT_DTOR(sbBooleanPropertyInfo);
48 }
49 
50 nsresult
52 {
53  nsresult rv;
54 
55  rv = sbPropertyInfo::Init();
56  NS_ENSURE_SUCCESS(rv, rv);
57 
58  rv = InitializeOperators();
59  NS_ENSURE_SUCCESS(rv, rv);
60 
61  return NS_OK;
62 }
63 
64 nsresult
66 {
67  nsAutoString op;
68  nsRefPtr<sbPropertyOperator> propOp;
69  nsresult rv;
70 
71  rv = sbPropertyInfo::GetOPERATOR_EQUALS(op);
72  NS_ENSURE_SUCCESS(rv, rv);
73  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.int.equal"));
74  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
75  rv = mOperators.AppendObject(propOp);
76  NS_ENSURE_SUCCESS(rv, rv);
77 
78  rv = sbPropertyInfo::GetOPERATOR_NOTEQUALS(op);
79  NS_ENSURE_SUCCESS(rv, rv);
80  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.int.notequal"));
81  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
82  rv = mOperators.AppendObject(propOp);
83  NS_ENSURE_SUCCESS(rv, rv);
84 
85  rv = GetOPERATOR_ISTRUE(op);
86  NS_ENSURE_SUCCESS(rv, rv);
87  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.bool.istrue"));
88  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
89  rv = mOperators.AppendObject(propOp);
90  NS_ENSURE_SUCCESS(rv, rv);
91 
92  rv = GetOPERATOR_ISFALSE(op);
93  NS_ENSURE_SUCCESS(rv, rv);
94  propOp = new sbPropertyOperator(op, NS_LITERAL_STRING("&smart.bool.isfalse"));
95  NS_ENSURE_TRUE(propOp, NS_ERROR_OUT_OF_MEMORY);
96  rv = mOperators.AppendObject(propOp);
97  NS_ENSURE_SUCCESS(rv, rv);
98 
99  return NS_OK;
100 }
101 
102 NS_IMETHODIMP
103 sbBooleanPropertyInfo::Validate(const nsAString & aValue, PRBool *_retval)
104 {
105  NS_ENSURE_ARG_POINTER(_retval);
106 
107  if (aValue.IsVoid() ||
108  aValue.IsEmpty() ||
109  aValue.EqualsLiteral("0") ||
110  aValue.EqualsLiteral("1")) {
111  *_retval = PR_TRUE;
112  }
113  else {
114  *_retval = PR_FALSE;
115  }
116 
117  return NS_OK;
118 }
119 
120 NS_IMETHODIMP
121 sbBooleanPropertyInfo::Sanitize(const nsAString & aValue, nsAString & _retval)
122 {
123  return NS_ERROR_NOT_IMPLEMENTED;
124 }
125 
126 NS_IMETHODIMP
127 sbBooleanPropertyInfo::Format(const nsAString & aValue, nsAString & _retval)
128 {
129  _retval.Truncate();
130  return NS_OK;
131 }
132 
133 NS_IMETHODIMP
134 sbBooleanPropertyInfo::MakeSearchable(const nsAString & aValue, nsAString & _retval)
135 {
136  nsresult rv;
137  PRBool valid = PR_FALSE;
138 
139  _retval = aValue;
140 
141  rv = Validate(_retval, &valid);
142  NS_ENSURE_SUCCESS(rv, rv);
143 
144  if(!valid) {
145  _retval.Truncate();
146  rv = NS_ERROR_INVALID_ARG;
147  }
148 
149  return rv;
150 }
151 
152 NS_IMETHODIMP
153 sbBooleanPropertyInfo::GetOPERATOR_ISTRUE(nsAString & aOPERATOR_ISTRUE)
154 {
155  aOPERATOR_ISTRUE = NS_LITERAL_STRING(SB_OPERATOR_ISTRUE);
156  return NS_OK;
157 }
158 
159 NS_IMETHODIMP
160 sbBooleanPropertyInfo::GetOPERATOR_ISFALSE(nsAString & aOPERATOR_ISFALSE)
161 {
162  aOPERATOR_ISFALSE = NS_LITERAL_STRING(SB_OPERATOR_ISFALSE);
163  return NS_OK;
164 }
165 
166 // sbITreeViewPropertyInfo
167 
168 NS_IMETHODIMP
169 sbBooleanPropertyInfo::GetImageSrc(const nsAString& aValue,
170  nsAString& _retval)
171 {
172  _retval.Truncate();
173  return NS_OK;
174 }
175 
176 NS_IMETHODIMP
177 sbBooleanPropertyInfo::GetProgressMode(const nsAString& aValue,
178  PRInt32* _retval)
179 {
180  NS_ENSURE_ARG_POINTER(_retval);
181  *_retval = nsITreeView::PROGRESS_NONE;
182  return NS_OK;
183 }
184 
185 NS_IMETHODIMP
186 sbBooleanPropertyInfo::GetCellValue(const nsAString& aValue,
187  nsAString& _retval)
188 {
189  nsresult rv;
190  PRBool valid = PR_FALSE;
191 
192  _retval = aValue;
193 
194  rv = Validate(_retval, &valid);
195  NS_ENSURE_SUCCESS(rv, rv);
196 
197  if(!valid) {
198  _retval.Truncate();
199  rv = NS_ERROR_INVALID_ARG;
200  }
201 
202  // Force empty or nulls to be false.
203  if (aValue.IsVoid() || aValue.IsEmpty()) {
204  _retval.AssignLiteral("0");
205  }
206 
207  return rv;
208 }
209 
210 NS_IMETHODIMP
211 sbBooleanPropertyInfo::GetRowProperties(const nsAString& aValue,
212  nsAString& _retval)
213 {
214  _retval.Truncate();
215  return NS_OK;
216 }
217 
218 NS_IMETHODIMP
219 sbBooleanPropertyInfo::GetCellProperties(const nsAString& aValue,
220  nsAString& _retval)
221 {
222  _retval.AssignLiteral("checkbox");
223 
224  if (aValue.EqualsLiteral("1")) {
225  _retval.AppendLiteral(" checked");
226  } else {
227  _retval.AppendLiteral(" unchecked");
228  }
229 
230  return NS_OK;
231 }
232 
233 NS_IMETHODIMP
234 sbBooleanPropertyInfo::GetColumnType(nsAString& _retval)
235 {
236  _retval.AssignLiteral("text");
237  return NS_OK;
238 }
239 
240 // sbIClickablePropertyInfo
241 
242 NS_IMETHODIMP
243 sbBooleanPropertyInfo::GetSuppressSelect(PRBool* aSuppressSelect)
244 {
245  NS_ENSURE_ARG_POINTER(aSuppressSelect);
246  *aSuppressSelect = mSuppressSelect;
247  return NS_OK;
248 }
249 
250 NS_IMETHODIMP
251 sbBooleanPropertyInfo::SetSuppressSelect(PRBool aSuppressSelect)
252 {
253  mSuppressSelect = aSuppressSelect;
254  return NS_OK;
255 }
256 
257 NS_IMETHODIMP
258 sbBooleanPropertyInfo::IsDisabled(const nsAString& aCurrentValue,
259  PRBool* _retval)
260 {
261  NS_ENSURE_ARG_POINTER(_retval);
262  *_retval = PR_FALSE;
263  return NS_OK;
264 }
265 
266 NS_IMETHODIMP
267 sbBooleanPropertyInfo::HitTest(const nsAString& aCurrentValue,
268  const nsAString& aPart,
269  PRUint32 aBoxWidth,
270  PRUint32 aBoxHeight,
271  PRUint32 aMouseX,
272  PRUint32 aMouseY,
273  PRBool* _retval)
274 {
275  NS_ENSURE_ARG_POINTER(_retval);
276  *_retval = PR_TRUE;
277  return NS_OK;
278 }
279 
280 NS_IMETHODIMP
281 sbBooleanPropertyInfo::GetValueForClick(const nsAString& aCurrentValue,
282  PRUint32 aBoxWidth,
283  PRUint32 aBoxHeight,
284  PRUint32 aMouseX,
285  PRUint32 aMouseY,
286  nsAString& _retval)
287 {
288  if (aCurrentValue.EqualsLiteral("1")) {
289  _retval.AssignLiteral("0");
290  } else {
291  _retval.AssignLiteral("1");
292  }
293 
294  return NS_OK;
295 }
296 
297 /* boolean onClick (in sbIMediaItem aItem,
298  [optional] in nsISupports aEvent,
299  [optional] in nsISupports aContext); */
300 NS_IMETHODIMP
301 sbBooleanPropertyInfo::OnClick(sbIMediaItem *aItem,
302  nsISupports *aEvent,
303  nsISupports *aContext,
304  PRBool *_retval NS_OUTPARAM)
305 {
306  NS_ENSURE_ARG_POINTER(_retval);
307  *_retval = PR_FALSE;
308  return NS_OK;
309 }
return NS_OK
onPageChanged aValue
Definition: FeedWriter.js:1395
The property information specific to clickable properties.
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
NS_IMETHOD Validate(const nsAString &aValue, PRBool *_retval)
NS_IMPL_ISUPPORTS_INHERITED3(sbBooleanPropertyInfo, sbPropertyInfo, sbIBooleanPropertyInfo, sbIClickablePropertyInfo, sbITreeViewPropertyInfo) sbBooleanPropertyInfo
#define SB_OPERATOR_ISTRUE
nsCOMArray< sbIPropertyOperator > mOperators
NS_IMETHOD Sanitize(const nsAString &aValue, nsAString &_retval)
The property information specific to boolean properties.
#define SB_OPERATOR_ISFALSE
Interface that defines a single item of media in the system.
NS_IMETHOD MakeSearchable(const nsAString &aValue, nsAString &_retval)