sbAlbumArtFetcherSet.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2010 POTI, Inc.
9  * http://www.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 #ifndef __SB_ALBUMARTFETCHERSET_H__
28 #define __SB_ALBUMARTFETCHERSET_H__
29 
30 //------------------------------------------------------------------------------
31 //------------------------------------------------------------------------------
32 //
33 // Songbird album art fetcher set.
34 //
35 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 
43 //------------------------------------------------------------------------------
44 //
45 // Songbird album art fetcher set imported services.
46 //
47 //------------------------------------------------------------------------------
48 
49 // Songbird imports.
50 #include <sbIAlbumArtFetcherSet.h>
51 #include <sbIAlbumArtService.h>
52 #include <sbIAlbumArtListener.h>
53 #include <sbIMediaItem.h>
54 
55 // Mozilla imports.
56 #include <nsCOMPtr.h>
57 #include <nsIConsoleService.h>
58 #include <nsIArray.h>
59 #include <nsIMutableArray.h>
60 #include <nsIThreadManager.h>
61 #include <nsITimer.h>
62 
63 
64 //------------------------------------------------------------------------------
65 //
66 // Songbird album art fetcher set defs.
67 //
68 //------------------------------------------------------------------------------
69 
70 //
71 // Songbird album art fetcher set component defs.
72 //
73 
74 #define SB_ALBUMARTFETCHERSET_CLASSNAME "sbAlbumArtFetcherSet"
75 #define SB_ALBUMARTFETCHERSET_CID \
76  /* {5da41a79-0ed6-4876-bbd7-348a447c784f} */ \
77  { \
78  0x5da41a79, \
79  0x0ed6, \
80  0x4876, \
81  { 0xbb, 0xd7, 0x34, 0x8a, 0x44, 0x7c, 0x78, 0x4f } \
82  }
83 
84 // Default values for the timers (milliseconds)
85 #define ALBUMART_SCANNER_TIMEOUT 10000
86 
87 // Preference keys
88 #define PREF_ALBUMART_SCANNER_BRANCH "songbird.albumart.scanner."
89 #define PREF_ALBUMART_SCANNER_TIMEOUT "timeout"
90 
91 //------------------------------------------------------------------------------
92 //
93 // Songbird album art fetcher set classes.
94 //
95 //------------------------------------------------------------------------------
96 
102  public nsITimerCallback,
103  public sbIAlbumArtListener
104 {
105  //----------------------------------------------------------------------------
106  //
107  // Public interface.
108  //
109  //----------------------------------------------------------------------------
110 
111 public:
112 
113  //
114  // Inherited interfaces.
115  //
116 
118  NS_DECL_SBIALBUMARTFETCHER
119  NS_DECL_SBIALBUMARTFETCHERSET
120  NS_DECL_NSITIMERCALLBACK
121  NS_DECL_SBIALBUMARTLISTENER
122 
123 
124  //
125  // Public services.
126  //
127 
129 
130  virtual ~sbAlbumArtFetcherSet();
131 
132  nsresult Initialize();
133 
134 
135  //----------------------------------------------------------------------------
136  //
137  // Private interface.
138  //
139  //----------------------------------------------------------------------------
140 
141 private:
142 
143  //
144  // mAlbumArtService Album art service.
145  // mThreadManager Thread manager.
146  // mConsoleService Console service for warning messages.
147  // mAlbumArtSourceList List of album art sources.
148  // mType sbIAlbumArtFetcherSet.TYPE_[LOCAL|REMOTE|ALL]
149  // mShutdown Flag to indicate if we should shutdown.
150  // mIsFetching True if currently fetching.
151  //
152 
153  nsCOMPtr<sbIAlbumArtService> mAlbumArtService;
154  nsCOMPtr<nsIThreadManager> mThreadManager;
155  nsCOMPtr<nsIConsoleService> mConsoleService;
156  nsCOMPtr<nsIArray> mAlbumArtSourceList;
157  PRUint32 mType;
158  PRBool mShutdown;
159  PRBool mIsFetching;
160 
161  //
162  // mListener Listener for the fetching.
163  //
164 
165  nsCOMPtr<sbIAlbumArtListener> mListener;
166 
167  //
168  // mFetcherList List of fetchers to check.
169  // mFetcherIndex Index of current fetcher we are checking.
170  // mFetcher Current Fetcher we are using.
171  // mMediaItems List of items we are scanning.
172  //
173 
174  nsCOMPtr<nsIArray> mFetcherList;
175  PRUint32 mFetcherIndex;
176  nsCOMPtr<sbIAlbumArtFetcher> mFetcher;
177  nsCOMPtr<nsIArray> mMediaItems;
178 
179  //
180  // mTimeoutTimer Time out timer for fetch opertaions
181  // mTimeoutTimerValue Max time a fetch operation is allowed.
182  //
183  nsCOMPtr<nsITimer> mTimeoutTimer;
184  PRInt32 mTimeoutTimerValue;
185 
186  //
187  // mFoundAllArtwork Flag to determine if we have found all artwork
188  // for the items requested.
189  //
190 
191  PRBool mFoundAllArtwork;
192 
193  //
194  // Internal services.
195  //
196 
197  nsresult CheckLocalImage(nsIURI* aImageLocation);
198 
199  nsresult TryNextFetcher();
200 
201  nsresult NextFetcher();
202 };
203 
204 
205 #endif // __SB_ALBUMARTFETCHERSET_H__
206 
NS_DECL_ISUPPORTS NS_DECL_SBIALBUMARTFETCHER NS_DECL_SBIALBUMARTFETCHERSET NS_DECL_NSITIMERCALLBACK NS_DECL_SBIALBUMARTLISTENER sbAlbumArtFetcherSet()
A component which is interested in the result of an album art fetch request.
Interface for an album art fetcher set. Instantiate as a component instance.
nsITimerCallback