sbiTunesImporterAlbumArtListener.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-2009 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 
28 
29 #include <nsArrayUtils.h>
30 #include <nsCOMPtr.h>
31 #include <nsStringAPI.h>
32 #include <nsIArray.h>
33 #include <nsIURI.h>
34 
35 #include <sbIAlbumArtFetcher.h>
36 #include <sbIMediaItem.h>
37 #include <sbStandardProperties.h>
38 
41 
43 }
44 
45 sbiTunesImporterAlbumArtListener::~sbiTunesImporterAlbumArtListener() {
46 }
47 
50 }
51 
52 /* void onChangeFetcher (in sbIAlbumArtFetcher aFetcher); */
53 NS_IMETHODIMP
54 sbiTunesImporterAlbumArtListener::OnChangeFetcher(sbIAlbumArtFetcher *aFetcher)
55 {
56  // Nothing to do here, move along
57  return NS_OK;
58 }
59 
60 /* void onTrackResult (in nsIURI aImageLocation, in sbIMediaItem aMediaItem); */
61 NS_IMETHODIMP
62 sbiTunesImporterAlbumArtListener::OnTrackResult(nsIURI *aImageLocation,
63  sbIMediaItem *aMediaItem)
64 {
65  if (aImageLocation) {
66  nsCString spec;
67  nsresult rv = aImageLocation->GetSpec(spec);
68  NS_ENSURE_SUCCESS(rv, rv);
69 
70  rv = aMediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_PRIMARYIMAGEURL),
71  NS_ConvertUTF8toUTF16(spec));
72  NS_ENSURE_SUCCESS(rv, rv);
73  }
74  return NS_OK;
75 }
76 
77 /* void onAlbumResult (in nsIURI aImageLocation, in nsIArray aMediaItems); */
78 NS_IMETHODIMP
79 sbiTunesImporterAlbumArtListener::OnAlbumResult(nsIURI *aImageLocation,
80  nsIArray *aMediaItems)
81 {
82  if (aImageLocation) {
83  nsCString spec;
84  nsresult rv = aImageLocation->GetSpec(spec);
85  NS_ENSURE_SUCCESS(rv, rv);
86 
87  nsCOMPtr<sbIMediaItem> mediaItem;
88  PRUint32 length;
89  rv = aMediaItems->GetLength(&length);
90  NS_ENSURE_SUCCESS(rv, rv);
91 
92  for (PRUint32 index = 0; index < length; ++index) {
93  mediaItem = do_QueryElementAt(aMediaItems, index, &rv);
94  NS_ENSURE_SUCCESS(rv, rv);
95 
96  rv = mediaItem->SetProperty(NS_LITERAL_STRING(SB_PROPERTY_PRIMARYIMAGEURL),
97  NS_ConvertASCIItoUTF16(spec));
98  NS_ENSURE_SUCCESS(rv, rv);
99  }
100  }
101  return NS_OK;
102 }
103 
104 /* void onSearchComplete (in nsIArray aMediaItems); */
105 NS_IMETHODIMP
106 sbiTunesImporterAlbumArtListener::OnSearchComplete(nsIArray *aMediaItems)
107 {
108  // Nothing to do here, move along
109  return NS_OK;
110 }
return NS_OK
A component which is interested in the result of an album art fetch request.
NS_DECL_ISUPPORTS static NS_DECL_SBIALBUMARTLISTENER sbiTunesImporterAlbumArtListener * New()
NS_IMPL_THREADSAFE_ISUPPORTS1(sbiTunesImporterAlbumArtListener, sbIAlbumArtListener) sbiTunesImporterAlbumArtListener
Interface that defines a single item of media in the system.
Interface for an album art fetcher. Instantiate as a component instance.
#define SB_PROPERTY_PRIMARYIMAGEURL