sbDeviceImages.h
Go to the documentation of this file.
1 /*
2  *=BEGIN SONGBIRD GPL
3  *
4  * This file is part of the Songbird web player.
5  *
6  * Copyright(c) 2005-2010 POTI, Inc.
7  * http://www.songbirdnest.com
8  *
9  * This file may be licensed under the terms of of the
10  * GNU General Public License Version 2 (the ``GPL'').
11  *
12  * Software distributed under the License is distributed
13  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
14  * express or implied. See the GPL for the specific language
15  * governing rights and limitations.
16  *
17  * You should have received a copy of the GPL along with this
18  * program. If not, go to http://www.gnu.org/licenses/gpl.html
19  * or write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  *=END SONGBIRD GPL
23  */
24 
25 #ifndef SBDEVICEIMAGES_H_
26 #define SBDEVICEIMAGES_H_
27 
28 // Standard includes
29 #include <set>
30 
31 // Mozilla includes
32 #include <nsIArray.h>
33 
34 // Songbird local includes
35 #include "sbBaseDevice.h"
36 #include "sbIDeviceImage.h"
37 
38 class sbIFileScanQuery;
39 
41 {
42 public:
43  friend class sbBaseDevice;
44 
45  // Compute the difference between the images present locally and
46  // those provided in the device image array. You must provide a list
47  // of supported extensions. The copy array will be filled with images
48  // which the device implementation should act upon.
49  nsresult ComputeImageSyncArray(sbIDeviceLibrary *aLibrary,
50  nsIArray *aDeviceImageArray,
51  const nsTArray<nsString> &aFileExtensionList,
52  nsIArray **retCopyArray);
53 
54  // This may be called by devices whose underlying storage lies on the
55  // filesystem to build an array of sbIDeviceImage items. aScanPath is the
56  // directory that is to be scanned. aBasePath is the base of the image
57  // directory on that filesystem. You must also provide a list of supported
58  // extensions.
59  nsresult ScanImages(nsIFile *aScanDir,
60  nsIFile *aBaseDir,
61  const nsTArray<nsString> &aFileExtensionList,
62  PRBool recursive,
63  nsIArray **retImageArray);
64 
65  // Create and return in aMediaItem a temporary media item for the local file
66  // represented by aImage and device library aLibrary.
68  sbIDeviceLibrary* aLibrary,
69  sbIMediaItem** aMediaItem);
70 
71  // Create an nsIFile for an sbIDeviceImage item given the base image sync
72  // directory. The function can automatically create the needed subdirectories
73  // in which the file will reside, or to create a file object pointing at the
74  // file's parent directory rather than at the file itself.
75  nsresult MakeFile(sbIDeviceImage* aImage,
76  nsIFile* aBaseDir,
77  PRBool aWithFilename,
78  PRBool aCreateDirectories,
79  nsIFile** retFile);
80 
81  static nsresult GetImagesRootFolder(sbIDeviceLibrary * aDevLib,
82  nsIFile ** aFile);
83 private:
84  // ctor
85  sbDeviceImages(sbBaseDevice * aBaseDevice);
86 
87  // add local images to an existing array, this is used to sequentially
88  // build the list of all local files that should be synced.
89  nsresult
90  AddLocalImages(nsIFile *baseDir,
91  nsIFile *subDir,
92  const nsTArray<nsString> aFileExtensionList,
93  PRBool recursive,
94  nsIMutableArray *localImageArray);
95 
96  // search for each item that is in searchItem in the searchableImageArray.
97  // if an item does not exist, it is inserted in the diffResultsArray
98  nsresult DiffImages(nsIMutableArray *diffResultsArray,
99  nsTArray< sbIDeviceImage* > &searchableImageArray,
100  nsIArray *searchItems);
101 
102  // perform the actual image scanning of a directory using a filescan object
103  nsresult ScanForImageFiles(nsIURI *aImageFilesPath,
104  const nsTArray<nsString> &aFileExtensionList,
105  PRBool recursive,
106  sbIFileScanQuery** aFileScanQuery);
107 
108  // A pointer to our parent base device
109  sbBaseDevice *mBaseDevice;
110 };
111 
112 // sbIDeviceImage implementation
114 public:
116  NS_DECL_SBIDEVICEIMAGE
117 
118  sbDeviceImage();
119  virtual ~sbDeviceImage() {}
120 
121 private:
122  PRUint64 mSize;
123  nsString mFilename;
124  nsString mSubdirectory;
125 };
126 
127 // a comparator class for sbIDeviceImages so that we can efficiently search
128 // through a sorted list.
130 public:
131  // Defined for the Sort function on nsTArray
132  PRBool LessThan(const sbIDeviceImage *a, const sbIDeviceImage *b) const;
133  // This has to be defined for Sort as well, but is used for Searching.
134  PRBool Equals(const sbIDeviceImage *a, const sbIDeviceImage *b) const;
135 };
136 
137 #endif
static nsresult GetImagesRootFolder(sbIDeviceLibrary *aDevLib, nsIFile **aFile)
friend class sbDeviceImages
Definition: sbBaseDevice.h:105
virtual ~sbDeviceImage()
PRBool Equals(const sbIDeviceImage *a, const sbIDeviceImage *b) const
nsresult ComputeImageSyncArray(sbIDeviceLibrary *aLibrary, nsIArray *aDeviceImageArray, const nsTArray< nsString > &aFileExtensionList, nsIArray **retCopyArray)
nsresult ScanImages(nsIFile *aScanDir, nsIFile *aBaseDir, const nsTArray< nsString > &aFileExtensionList, PRBool recursive, nsIArray **retImageArray)
NS_DECL_ISUPPORTS NS_DECL_SBIDEVICEIMAGE sbDeviceImage()
nsresult CreateTemporaryLocalMediaItem(sbIDeviceImage *aImage, sbIDeviceLibrary *aLibrary, sbIMediaItem **aMediaItem)
PRBool LessThan(const sbIDeviceImage *a, const sbIDeviceImage *b) const
Interface that defines a single item of media in the system.
nsresult MakeFile(sbIDeviceImage *aImage, nsIFile *aBaseDir, PRBool aWithFilename, PRBool aCreateDirectories, nsIFile **retFile)
An object to scan through the files of a folder (and optionally subfolders)