sbMetadataJobItem.cpp
Go to the documentation of this file.
1 /* vim: set sw=2 :miv */
2 /*
3 //
4 // BEGIN SONGBIRD GPL
5 //
6 // This file is part of the Songbird web player.
7 //
8 // Copyright(c) 2005-2008 POTI, Inc.
9 // http://songbirdnest.com
10 //
11 // This file may be licensed under the terms of of the
12 // GNU General Public License Version 2 (the "GPL").
13 //
14 // Software distributed under the License is distributed
15 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
16 // express or implied. See the GPL for the specific language
17 // governing rights and limitations.
18 //
19 // You should have received a copy of the GPL along with this
20 // program. If not, go to http://www.gnu.org/licenses/gpl.html
21 // or write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 //
24 // END SONGBIRD GPL
25 //
26 */
27 
33 // INCLUDES ===================================================================
34 #include <nspr.h>
35 #include <nscore.h>
36 #include <nsComponentManagerUtils.h>
37 #include "prlog.h"
38 #include "sbMetadataJobItem.h"
39 
40 // DEFINES ====================================================================
41 #ifdef PR_LOGGING
42 extern PRLogModuleInfo* gMetadataLog;
43 #define TRACE(args) PR_LOG(gMetadataLog, PR_LOG_DEBUG, args)
44 #define LOG(args) PR_LOG(gMetadataLog, PR_LOG_WARN, args)
45 #else
46 #define TRACE(args) /* nothing */
47 #define LOG(args) /* nothing */
48 #endif
49 
50 #define SB_MUTABLEPROPERTYARRAY_CONTRACTID "@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"
51 
52 // CLASSES ====================================================================
53 
55 
57  sbIMediaItem* aMediaItem,
58  nsStringArray* aRequiredProperties,
59  sbMetadataJob* aOwningJob) :
60  mJobType(aJobType),
61  mMediaItem(aMediaItem),
62  mHandler(nsnull),
63  mOwningJob(aOwningJob),
64  mPropertyList(aRequiredProperties),
65  mProcessingStarted(PR_FALSE),
66  mProcessingComplete(PR_FALSE)
67 {
68  MOZ_COUNT_CTOR(sbMetadataJobItem);
69  TRACE(("sbMetadataJobItem[0x%.8x] - ctor", this));
70 }
71 
73 {
74  MOZ_COUNT_DTOR(sbMetadataJobItem);
75  TRACE(("sbMetadataJobItem[0x%.8x] - dtor", this));
76 }
77 
79 {
80  NS_ENSURE_ARG_POINTER(aHandler);
81  if (!mHandler) {
82  return NS_ERROR_NOT_AVAILABLE;
83  }
84  NS_ADDREF(*aHandler = mHandler);
85  return NS_OK;
86 }
87 
89 {
90  mHandler = aHandler;
91  return NS_OK;
92 }
93 
95 {
96  NS_ENSURE_ARG_POINTER(aMediaItem);
97  NS_ENSURE_STATE(mMediaItem);
98  NS_ADDREF(*aMediaItem = mMediaItem);
99  return NS_OK;
100 }
101 
103 {
104  NS_ENSURE_ARG_POINTER(aJob);
105  NS_ENSURE_STATE(mOwningJob);
106  NS_ADDREF(*aJob = mOwningJob);
107  return NS_OK;
108 }
109 
111 {
112  NS_ENSURE_ARG_POINTER(aJobType);
113  *aJobType = mJobType;
114  return NS_OK;
115 }
116 
117 nsresult sbMetadataJobItem::GetProcessingStarted(PRBool* aProcessingStarted)
118 {
119  NS_ENSURE_ARG_POINTER(aProcessingStarted);
120  *aProcessingStarted = mProcessingStarted;
121  return NS_OK;
122 }
123 
124 nsresult sbMetadataJobItem::SetProcessingStarted(PRBool aProcessingStarted)
125 {
126  mProcessingStarted = aProcessingStarted;
127  return NS_OK;
128 }
129 
130 nsresult sbMetadataJobItem::GetProcessed(PRBool* aProcessed)
131 {
132  NS_ENSURE_ARG_POINTER(aProcessed);
133  *aProcessed = mProcessingComplete;
134  return NS_OK;
135 }
136 
137 nsresult sbMetadataJobItem::SetProcessed(PRBool aProcessed)
138 {
139  mProcessingComplete = aProcessed;
140  return NS_OK;
141 }
142 
143 nsresult sbMetadataJobItem::GetURL(nsACString& aURL)
144 {
145  aURL.Assign(mURL);
146  return NS_OK;
147 }
148 nsresult sbMetadataJobItem::SetURL(const nsACString& aURL)
149 {
150  mURL.Assign(aURL);
151  return NS_OK;
152 }
153 
155 {
156  NS_ENSURE_ARG_POINTER(aPropertyArray);
157  NS_ENSURE_STATE(mMediaItem);
158  nsresult rv;
159 
160  // Create a property array we can put the properties we want into.
161  nsCOMPtr<sbIMutablePropertyArray> writeProps =
162  do_CreateInstance(SB_MUTABLEPROPERTYARRAY_CONTRACTID, &rv);
163  NS_ENSURE_SUCCESS(rv, rv);
164 
165  // Now grab all the properties from the item.
166  nsCOMPtr<sbIPropertyArray> propArray;
167  rv = mMediaItem->GetProperties(nsnull, getter_AddRefs(propArray));
168  NS_ENSURE_SUCCESS(rv, rv);
169 
170  // We have to make sure that any properties we wanted that are missing from
171  // propArray get added with empty strings to ensure we can erase values.
172  nsCOMPtr<sbIProperty> property;
173  nsString propertyId;
174  nsString propertyValue;
175  for (PRInt32 current = 0; current < mPropertyList->Count(); ++current) {
176  // Get the wanted property
177  mPropertyList->StringAt(current, propertyId);
178 
179  // Get the value for this property and if null make an empty string
180  rv = propArray->GetPropertyValue(propertyId, propertyValue);
181  if (rv == NS_ERROR_NOT_AVAILABLE) {
182  // This is a null value or does not exist so we should write out an
183  // empty string
184  propertyValue = EmptyString();
185  propertyValue.SetIsVoid(PR_TRUE);
186  } else {
187  NS_ENSURE_SUCCESS(rv, rv);
188  }
189 
190  rv = writeProps->AppendProperty(propertyId, propertyValue);
191  NS_ENSURE_SUCCESS(rv, rv);
192  }
193 
194  NS_ADDREF(*aPropertyArray = writeProps);
195  return NS_OK;
196 }
nsresult SetProcessingStarted(PRBool aProcessingStarted)
sbMetadataJob::JobType mJobType
nsresult SetURL(const nsACString &aURL)
NS_IMPL_THREADSAFE_ISUPPORTS0(sbMetadataJobItem)
return NS_OK
nsCOMPtr< sbIMediaItem > mMediaItem
#define SB_MUTABLEPROPERTYARRAY_CONTRACTID
nsresult GetJobType(sbMetadataJob::JobType *aJobType)
nsresult GetURL(nsACString &aURL)
NS_DECL_ISUPPORTS sbMetadataJobItem(sbMetadataJob::JobType aJobType, sbIMediaItem *aMediaItem, nsStringArray *aRequiredProperties, sbMetadataJob *aOwningJob)
An interface to carry around arrays of nsIProperty instances Note that implementations of the interfa...
nsresult GetProcessingStarted(PRBool *aProcessingStarted)
nsresult GetProcessed(PRBool *aProcessed)
nsresult GetMediaItem(sbIMediaItem **aMediaItem)
nsStringArray * mPropertyList
An object capable of manipulating the metadata tags for a media file.
#define TRACE(args)
nsresult GetOwningJob(sbMetadataJob **aJob)
nsresult SetHandler(sbIMetadataHandler *aHandler)
Interface that defines a single item of media in the system.
nsresult SetProcessed(PRBool aProcessed)
A metadata job task.
nsresult GetProperties(sbIMutablePropertyArray **aPropertyArray)
nsCOMPtr< sbIMetadataHandler > mHandler
nsRefPtr< sbMetadataJob > mOwningJob
nsresult GetHandler(sbIMetadataHandler **aHandler)