sbDownloadButtonPropertyBuilder.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 
29 
30 #include <nsAutoPtr.h>
31 
32 #include <sbIPropertyArray.h>
33 #include <sbIPropertyManager.h>
34 #include <nsIStringBundle.h>
35 
36 #include "sbStandardProperties.h"
37 
42 
43 nsresult
45 {
46  nsresult rv;
48  NS_ENSURE_SUCCESS(rv, rv);
49 
50  rv = SetPropertyID(NS_LITERAL_STRING(SB_PROPERTY_DOWNLOADBUTTON));
51  NS_ENSURE_SUCCESS(rv, rv);
52 
53  rv = SetDisplayNameKey(NS_LITERAL_STRING("property.download_button"));
54  NS_ENSURE_SUCCESS(rv, rv);
55 
56  rv = SetLabelKey(NS_LITERAL_STRING("property.download_button"));
57  NS_ENSURE_SUCCESS(rv, rv);
58 
59  rv = SetRetryLabelKey(NS_LITERAL_STRING("property.download_button_retry"));
60  NS_ENSURE_SUCCESS(rv, rv);
61 
62  return NS_OK;
63 }
64 
65 NS_IMETHODIMP
67 {
68  NS_ENSURE_ARG_POINTER(_retval);
69  NS_ENSURE_STATE(!mPropertyID.IsEmpty());
70 
71  nsString displayName;
72  nsresult rv = GetFinalDisplayName(displayName);
73  NS_ENSURE_SUCCESS(rv, rv);
74 
75  nsString label;
76  if (!mLabelKey.IsEmpty()) {
77  rv = GetStringFromName(mBundle, mLabelKey, label);
78  NS_ENSURE_SUCCESS(rv, rv);
79  }
80  else {
81  label = mLabel;
82  }
83 
84  nsString retryLabel;
85  if (!mRetryLabelKey.IsEmpty()) {
86  rv = GetStringFromName(mBundle, mRetryLabelKey, retryLabel);
87  NS_ENSURE_SUCCESS(rv, rv);
88  }
89  else {
90  retryLabel = mRetryLabel;
91  }
92 
93  nsRefPtr<sbDownloadButtonPropertyInfo> pi =
95  displayName,
97  label,
98  retryLabel,
102  mUserEditable);
103  NS_ENSURE_TRUE(pi, NS_ERROR_OUT_OF_MEMORY);
104 
105  rv = pi->Init();
106  NS_ENSURE_SUCCESS(rv, rv);
107 
108  NS_ADDREF(*_retval = pi);
109  return NS_OK;
110 }
111 
112 NS_IMETHODIMP
113 sbDownloadButtonPropertyBuilder::GetLabel(nsAString& aLabel)
114 {
115  aLabel = mLabel;
116  return NS_OK;
117 }
118 NS_IMETHODIMP
119 sbDownloadButtonPropertyBuilder::SetLabel(const nsAString& aLabel)
120 {
121  mLabel = aLabel;
122  return NS_OK;
123 }
124 
125 NS_IMETHODIMP
126 sbDownloadButtonPropertyBuilder::GetRetryLabel(nsAString& aRetryLabel)
127 {
128  aRetryLabel = mRetryLabel;
129  return NS_OK;
130 }
131 NS_IMETHODIMP
132 sbDownloadButtonPropertyBuilder::SetRetryLabel(const nsAString& aRetryLabel)
133 {
134  mRetryLabel = aRetryLabel;
135  return NS_OK;
136 }
137 
138 NS_IMETHODIMP
139 sbDownloadButtonPropertyBuilder::GetLabelKey(nsAString& aLabelKey)
140 {
141  aLabelKey = mLabelKey;
142  return NS_OK;
143 }
144 NS_IMETHODIMP
145 sbDownloadButtonPropertyBuilder::SetLabelKey(const nsAString& aLabelKey)
146 {
147  mLabelKey = aLabelKey;
148  return NS_OK;
149 }
150 
151 NS_IMETHODIMP
152 sbDownloadButtonPropertyBuilder::GetRetryLabelKey(nsAString& aRetryLabelKey)
153 {
154  aRetryLabelKey = mRetryLabelKey;
155  return NS_OK;
156 }
157 NS_IMETHODIMP
158 sbDownloadButtonPropertyBuilder::SetRetryLabelKey(const nsAString& aRetryLabelKey)
159 {
160  mRetryLabelKey = aRetryLabelKey;
161  return NS_OK;
162 }
attribute AString displayName
return NS_OK
NS_IMETHOD Get(sbIPropertyInfo **_retval)
nsresult GetFinalDisplayName(nsAString &aDisplayName)
nsCOMPtr< nsIStringBundle > mBundle
NS_IMPL_ISUPPORTS_INHERITED2(sbDownloadButtonPropertyBuilder, sbAbstractPropertyBuilder, sbISimpleButtonPropertyBuilder, sbIDownloadButtonPropertyBuilder) nsresult sbDownloadButtonPropertyBuilder
function Init()
An interface used to describe a metadata property for use by the UI and other sbILibrary interfaces (...
#define SB_PROPERTY_DOWNLOADBUTTON
static nsresult GetStringFromName(nsIStringBundle *aBundle, const nsAString &aName, nsAString &_retval)