sbDownloadButtonPropertyInfo.h
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 #ifndef __SBDOWNLOADBUTTONPROPERTYINFO_H__
28 #define __SBDOWNLOADBUTTONPROPERTYINFO_H__
29 
31 
32 #include <sbIPropertyManager.h>
33 #include <sbITreeViewPropertyInfo.h>
34 #include <sbIClickablePropertyInfo.h>
35 
36 #include <sbStringUtils.h>
37 
38 #include <nsCOMPtr.h>
39 #include <nsStringGlue.h>
40 
41 #include <stdio.h>
42 
46 {
47 public:
48 
49  NS_DECL_ISUPPORTS_INHERITED
50  NS_DECL_SBICLICKABLEPROPERTYINFO
51  NS_DECL_SBITREEVIEWPROPERTYINFO
52 
53  sbDownloadButtonPropertyInfo(const nsAString& aPropertyID,
54  const nsAString& aDisplayName,
55  const nsAString& aLocalizationKey,
56  const nsAString& aLabel,
57  const nsAString& aRetryLabel,
58  const PRBool aRemoteReadable,
59  const PRBool aRemoteWritable,
60  const PRBool aUserViewable,
61  const PRBool aUserEditable);
63 
64  NS_IMETHOD Format(const nsAString& aValue, nsAString& _retval);
65 
66  nsresult Init();
67 
68 private:
69 
70  nsString mLabel;
71  nsString mRetryLabel;
72  PRBool mSuppressSelect;
73 };
74 
76 {
77 public:
78  enum Mode {
79  eNone = 0,
80  eNew = 1,
81  eStarting = 2,
83  ePaused = 4,
84  eComplete = 5,
85  eFailed = 6
86  };
87 
89  mMode(eNone),
90  mTotal(0),
91  mCurrent(0),
92  mIsDirty(PR_FALSE),
93  mIsModeSet(PR_FALSE),
94  mIsTotalSet(PR_FALSE),
95  mIsCurrentSet(PR_FALSE)
96  {
97  mFirstPipe = aValue.FindChar('|');
98  mSecondPipe = aValue.FindChar('|', mFirstPipe + 1);
99 
100  if (mFirstPipe >= 1 && mSecondPipe >= 2) {
101  mValue = aValue;
102  }
103  else {
104  mValue.SetIsVoid(PR_TRUE);
105  mIsModeSet = PR_TRUE;
106  mIsTotalSet = PR_TRUE;
107  mIsCurrentSet = PR_TRUE;
108  }
109  }
110 
112  {
113  if (!mIsModeSet) {
114  nsresult rv;
115  PRInt32 mode = Substring(mValue, 0, mFirstPipe).ToInteger(&rv);
116  if (NS_SUCCEEDED(rv) && mode >= eNone && mode <= eFailed) {
117  mMode = Mode(mode);
118  }
119  mIsModeSet = PR_TRUE;
120  }
121  return mMode;
122  }
123 
124  void SetMode(Mode aMode)
125  {
126  mMode = aMode;
127  mIsDirty = PR_TRUE;
128  mIsModeSet = PR_TRUE;
129  }
130 
131  PRUint64 GetTotal()
132  {
133  if (!mIsTotalSet) {
134  nsresult rv;
135  PRInt32 total =
136  Substring(mValue, mFirstPipe + 1, mSecondPipe - mFirstPipe).ToInteger(&rv);
137  if (NS_SUCCEEDED(rv) && total >= 0) {
138  mTotal = total;
139  }
140  mIsTotalSet = PR_TRUE;
141  }
142  return mTotal;
143  }
144 
145  void SetTotal(PRUint64 aTotal)
146  {
147  mTotal = aTotal;
148  mIsTotalSet = PR_TRUE;
149  mIsDirty = PR_TRUE;
150  }
151 
152  PRUint64 GetCurrent()
153  {
154  if (!mIsCurrentSet) {
155  nsresult rv;
156  PRInt32 current = Substring(mValue, mSecondPipe + 1).ToInteger(&rv);
157  if (NS_SUCCEEDED(rv) && current >= 0) {
158  mCurrent = current;
159  }
160  mIsCurrentSet = PR_TRUE;
161  }
162  return mCurrent;
163  }
164 
165  void SetCurrent(PRUint64 aCurrent)
166  {
167  mCurrent = aCurrent;
168  mIsCurrentSet = PR_TRUE;
169  mIsDirty = PR_TRUE;
170  }
171 
172  void GetValue(nsAString& aValue)
173  {
174  if (mIsDirty) {
175  aValue.Truncate();
176  aValue.AppendInt(GetMode());
177  aValue.AppendLiteral("|");
178  AppendInt(aValue, GetTotal());
179  aValue.AppendLiteral("|");
180  AppendInt(aValue, GetCurrent());
181  }
182  else {
183  aValue = mValue;
184  }
185  }
186 
187 private:
188  PRInt32 mFirstPipe;
189  PRInt32 mSecondPipe;
190  nsString mValue;
191 
192  Mode mMode;
193  PRUint64 mTotal;
194  PRUint64 mCurrent;
195 
196  PRPackedBool mIsDirty;
197  PRPackedBool mIsModeSet;
198  PRPackedBool mIsTotalSet;
199  PRPackedBool mIsCurrentSet;
200 };
201 
202 #endif /* __SBDOWNLOADBUTTONPROPERTYINFO_H__ */
203 
NS_DECL_ISUPPORTS_INHERITED NS_DECL_SBICLICKABLEPROPERTYINFO NS_DECL_SBITREEVIEWPROPERTYINFO sbDownloadButtonPropertyInfo(const nsAString &aPropertyID, const nsAString &aDisplayName, const nsAString &aLocalizationKey, const nsAString &aLabel, const nsAString &aRetryLabel, const PRBool aRemoteReadable, const PRBool aRemoteWritable, const PRBool aUserViewable, const PRBool aUserEditable)
var total
onPageChanged aValue
Definition: FeedWriter.js:1395
The property information specific to clickable properties.
static void AppendInt(nsAString &str, PRInt64 val)
NS_IMETHOD Format(const nsAString &aValue, nsAString &_retval)
sbDownloadButtonPropertyValue(const nsAString &aValue)