1 /***************************************************************************
2 copyright : (C) 2002 - 2008 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
21 * Alternatively, this file is available under the Mozilla Public *
22 * License Version 1.1. You may obtain a copy of the License at *
23 * http://www.mozilla.org/MPL/ *
24 ***************************************************************************/
26 #ifndef TAGLIB_FILEREF_H
27 #define TAGLIB_FILEREF_H
30 #include "tstringlist.h"
32 #include "taglib_export.h"
33 #include "audioproperties.h"
39 //! This class provides a simple abstraction for creating and handling files
42 * FileRef exists to provide a minimal, generic and value-based wrapper around
43 * a File. It is lightweight and implicitly shared, and as such suitable for
44 * pass-by-value use. This hides some of the uglier details of TagLib::File
45 * and the non-generic portions of the concrete file implementations.
47 * This class is useful in a "simple usage" situation where it is desirable
48 * to be able to get and set some of the tag information that is similar
51 * Also note that it is probably a good idea to plug this into your mime
52 * type system rather than using the constructor that accepts a file name using
53 * the FileTypeResolver.
55 * \see FileTypeResolver
56 * \see addFileTypeResolver()
59 class TAGLIB_EXPORT FileRef
63 //! A class for pluggable file type resolution.
66 * This class is used to add extend TagLib's very basic file name based file
69 * This can be accomplished with:
73 * class MyFileTypeResolver : FileTypeResolver
75 * TagLib::File *createFile(TagLib::FileName *fileName, bool, AudioProperties::ReadStyle)
77 * if(someCheckForAnMP3File(fileName))
78 * return new TagLib::MPEG::File(fileName);
83 * FileRef::addFileTypeResolver(new MyFileTypeResolver);
87 * Naturally a less contrived example would be slightly more complex. This
88 * can be used to plug in mime-type detection systems or to add new file types
92 class TAGLIB_EXPORT FileTypeResolver
94 TAGLIB_IGNORE_MISSING_DESTRUCTOR
97 * This method must be overridden to provide an additional file type
98 * resolver. If the resolver is able to determine the file type it should
99 * return a valid File object; if not it should return 0.
101 * \note The created file is then owned by the FileRef and should not be
102 * deleted. Deletion will happen automatically when the FileRef passes
105 virtual File *createFile(FileName fileName,
106 bool readAudioProperties = true,
107 AudioProperties::ReadStyle
108 audioPropertiesStyle = AudioProperties::Average) const = 0;
112 * Creates a null FileRef.
117 * Create a FileRef from \a fileName. If \a readAudioProperties is true then
118 * the audio properties will be read using \a audioPropertiesStyle. If
119 * \a readAudioProperties is false then \a audioPropertiesStyle will be
122 * Also see the note in the class documentation about why you may not want to
123 * use this method in your application.
125 explicit FileRef(FileName fileName,
126 bool readAudioProperties = true,
127 AudioProperties::ReadStyle
128 audioPropertiesStyle = AudioProperties::Average);
131 * Contruct a FileRef using \a file. The FileRef now takes ownership of the
132 * pointer and will delete the File when it passes out of scope.
134 explicit FileRef(File *file);
137 * Make a copy of \a ref.
139 FileRef(const FileRef &ref);
142 * Destroys this FileRef instance.
147 * Returns a pointer to represented file's tag.
149 * \warning This pointer will become invalid when this FileRef and all
150 * copies pass out of scope.
157 * Returns the audio properties for this FileRef. If no audio properties
158 * were read then this will returns a null pointer.
160 AudioProperties *audioProperties() const;
163 * Returns a pointer to the file represented by this handler class.
165 * As a general rule this call should be avoided since if you need to work
166 * with file objects directly, you are probably better served instantiating
167 * the File subclasses (i.e. MPEG::File) manually and working with their APIs.
169 * This <i>handle</i> exists to provide a minimal, generic and value-based
170 * wrapper around a File. Accessing the file directly generally indicates
171 * a moving away from this simplicity (and into things beyond the scope of
174 * \warning This pointer will become invalid when this FileRef and all
175 * copies pass out of scope.
180 * Saves the file. Returns true on success.
185 * Adds a FileTypeResolver to the list of those used by TagLib. Each
186 * additional FileTypeResolver is added to the front of a list of resolvers
187 * that are tried. If the FileTypeResolver returns zero the next resolver
190 * Returns a pointer to the added resolver (the same one that's passed in --
191 * this is mostly so that static inialializers have something to use for
194 * \see FileTypeResolver
196 static const FileTypeResolver *addFileTypeResolver(const FileTypeResolver *resolver);
199 * As is mentioned elsewhere in this class's documentation, the default file
200 * type resolution code provided by TagLib only works by comparing file
203 * This method returns the list of file extensions that are used by default.
205 * The extensions are all returned in lowercase, though the comparison used
206 * by TagLib for resolution is case-insensitive.
208 * \note This does not account for any additional file type resolvers that
209 * are plugged in. Also note that this is not intended to replace a propper
210 * mime-type resolution system, but is just here for reference.
212 * \see FileTypeResolver
214 static StringList defaultFileExtensions();
217 * Returns true if the file (and as such other pointers) are null.
222 * Assign the file pointed to by \a ref to this FileRef.
224 FileRef &operator=(const FileRef &ref);
227 * Returns true if this FileRef and \a ref point to the same File object.
229 bool operator==(const FileRef &ref) const;
232 * Returns true if this FileRef and \a ref do not point to the same File
235 bool operator!=(const FileRef &ref) const;
238 * A simple implementation of file type guessing. If \a readAudioProperties
239 * is true then the audio properties will be read using
240 * \a audioPropertiesStyle. If \a readAudioProperties is false then
241 * \a audioPropertiesStyle will be ignored.
243 * \note You generally shouldn't use this method, but instead the constructor
248 static File *create(FileName fileName,
249 bool readAudioProperties = true,
250 AudioProperties::ReadStyle audioPropertiesStyle = AudioProperties::Average);
254 class FileRefPrivate;
258 } // namespace TagLib