}
File *file;
+ static List<const FileTypeResolver *> fileTypeResolvers;
};
+List<const FileRef::FileTypeResolver *> FileRef::FileRefPrivate::fileTypeResolvers;
+
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
return d->file->save();
}
+void FileRef::addFileTypeResolver(const FileTypeResolver *resolver) // static
+{
+ FileRefPrivate::fileTypeResolvers.prepend(resolver);
+}
+
bool FileRef::isNull() const
{
return !d->file || !d->file->isValid();
* across file types.
*
* Also note that it is probably a good idea to plug this into your mime
- * type system rather than using the constructor that accepts a file name.
+ * type system rather than using the constructor that accepts a file name using
+ * the FileTypeResolver.
*
- * For example in KDE this could be done with:
+ * \see FileTypeResolver
+ * \see addFileTypeResolver()
+ */
+
+ class FileRef
+ {
+ public:
+
+ //! A class for pluggable file type resolution.
+
+ /*!
+ * This class is used to add extend TagLib's very basic file name based file
+ * type resolution.
+ *
+ * This can be accomplished with:
*
* \code
*
- * TagLib::FileRef createFileRef( const QString &fileName )
+ * class MyFileTypeResolver : FileTypeResolver
* {
- * KMimeType::Ptr result = KMimeType::findByPath( fileName, 0, true );
- *
- * if( result->name() == "audio/x-mp3" )
- * return FileRef( new MPEG::File( QFile::encodeName( fileName ).data() ) );
- *
- * if( result->name() == "application/ogg" )
- * return FileRef( new Vorbis::File( QFile::encodeName( fileName ).data() ) );
- *
- * return FileRef( 0 );
+ * TagLib::File *createFile(const char *fileName)
+ * {
+ * if(someCheckForAnMP3File(fileName))
+ * return new TagLib::MPEG::File(fileName);
+ * return 0;
+ * }
* }
*
+ * FileRef::addFileTypeResolver(new MyFileTypeResolver);
+ *
* \endcode
+ *
+ * Naturally a less contrived example would be slightly more complex. This
+ * can be used to plug in mime-type detection systems or to add new file types
+ * to TagLib.
*/
- class FileRef
- {
- public:
+ class FileTypeResolver
+ {
+ public:
+ /*!
+ * This method must be overriden to provide an additional file type
+ * resolver. If the resolver is able to determine the file type it should
+ * return a valid File object; if not it should return 0.
+ *
+ * \note The created file is then owned by the FileRef and should not be
+ * deleted. Deletion will happen automatically when the FileRef passes
+ * out of scope.
+ */
+ virtual File *createFile(const char *fileName) = 0;
+ };
FileRef();
*/
bool save();
+ /*!
+ * Adds a FileTypeResolver to the list of those used by TagLib. Each
+ * additional FileTypeResolver is added to the front of a list of resolvers
+ * that are tried. If the FileTypeResolver returns zero the next resolver
+ * is tried.
+ */
+ static void addFileTypeResolver(const FileTypeResolver *resolver);
+
/*!
* Returns true if the file (and as such other pointers) are null.
*/