sbStatusPropertyValue.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2009 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef SBSTATUSPROPERTYVALUE_H_
26 #define SBSTATUSPROPERTYVALUE_H_
27 
28 // Mozilla includes
29 #include <nsStringAPI.h>
30 
31 // Songbird includes
32 #include <sbStringUtils.h>
33 
34 
39 {
40 public:
41  enum Mode {
42  eNone = 0,
43  eRipping = 1,
44  eComplete = 2,
45  eFailed = 3,
47  };
52  mMode(eNone),
53  mCurrent(0)
54  {
55  }
59  sbStatusPropertyValue(const nsAString& aValue) :
60  mMode(eNone),
61  mCurrent(0)
62  {
63  PRInt32 const pipe = aValue.FindChar('|');
64 
65  if (pipe >= 1) {
66  nsDependentSubstring const & modeString = Substring(aValue, 0, pipe);
67  nsresult rv;
68  PRInt32 const mode = modeString.ToInteger(&rv);
69  NS_ENSURE_SUCCESS(rv, /* void */);
70 
71  switch (mode) {
72  case 0:
73  mMode = eNone;
74  break;
75  case 1:
76  mMode = eRipping;
77  break;
78  case 2:
79  mMode = eComplete;
80  break;
81  case 3:
82  mMode = eFailed;
83  break;
84  case 4:
85  mMode = eAborted;
86  break;
87  default:
88  mMode = eNone;
89  NS_WARNING("Invalid mode value for status property");
90  break;
91  }
92 
93  PRInt32 const currentValue = Substring(aValue, pipe + 1).ToInteger(&rv);
94  if (NS_SUCCEEDED(rv)) {
95  mCurrent = currentValue;
96  }
97  }
98  }
102  Mode GetMode() const
103  {
104  return mMode;
105  }
109  void SetMode(Mode aMode)
110  {
111  mMode = aMode;
112  }
116  PRUint32 GetCurrent() const
117  {
118  return mCurrent;
119  }
123  void SetCurrent(PRUint32 aCurrent)
124  {
125  mCurrent = aCurrent;
126  }
130  nsString GetValue() const
131  {
132  nsString value;
133  value.AppendInt(GetMode());
134  switch (GetMode()) {
135  case eComplete:
136  case eFailed:
137  case eAborted:
138  value.AppendLiteral("|100");
139  break;
140  default:
141  value.AppendLiteral("|");
142  AppendInt(value, GetCurrent());
143  break;
144  }
145  return value;
146  }
147 
148 private:
149  Mode mMode;
150  PRUint32 mCurrent;
151 };
152 
153 
154 #endif /* SBSTATUSPROPERTYVALUE_H_ */
onPageChanged aValue
Definition: FeedWriter.js:1395
sbStatusPropertyValue(const nsAString &aValue)
countRef value
Definition: FeedWriter.js:1423
static void AppendInt(nsAString &str, PRInt64 val)
void SetCurrent(PRUint32 aCurrent)
PRUint32 GetCurrent() const