File indexing completed on 2025-01-19 04:24:29

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Alejandro Wainzinger <aikawarazuni@gmail.com>                     *
0003  * Copyright (c) 2011 Matěj Laitl <matej@laitl.cz>                                      *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef MEDIADEVICEHANDLER_READCAPABILITY_H
0019 #define MEDIADEVICEHANDLER_READCAPABILITY_H
0020 
0021 #include "core-impl/collections/mediadevicecollection/MediaDeviceMeta.h"
0022 #include "core-impl/collections/mediadevicecollection/handler/MediaDeviceHandlerCapability.h"
0023 #include "core-impl/collections/mediadevicecollection/support/mediadevicecollection_export.h"
0024 
0025 #include <QDateTime>
0026 
0027 namespace Handler
0028 {
0029 
0030 class MEDIADEVICECOLLECTION_EXPORT ReadCapability : public Handler::Capability
0031 {
0032     Q_OBJECT
0033 
0034     public:
0035         explicit ReadCapability( QObject *parent ) : Capability( parent ) {}
0036         ~ReadCapability() override;
0037 
0038         static Type capabilityInterfaceType() { return Handler::Capability::Readable; }
0039 
0040         /* Parsing of Tracks on Device */
0041 
0042         /**
0043          * Initializes iteration over some list of track structs
0044          * e.g. with libgpod, this initializes a GList to the beginning of
0045          * the list of tracks
0046          */
0047         virtual void prepareToParseTracks() = 0;
0048 
0049         /**
0050          * Runs a test to see if we have reached the end of
0051          * the list of tracks to be parsed on the device, e.g. in libgpod
0052          * this tests if cur != NULL, i.e. if(cur)
0053          */
0054         virtual bool isEndOfParseTracksList() = 0;
0055 
0056         /**
0057          * Moves the iterator to the next track on the list of
0058          *  track structs, e.g. with libgpod, cur = cur->next where cur
0059          *  is a GList*
0060          */
0061         virtual void prepareToParseNextTrack() = 0;
0062 
0063         /**
0064          * This method attempts to access the special struct of the
0065          * next track, so that information can then be parsed from it.
0066          * For libgpod, this is m_currtrack = (Itdb_Track*) cur->data
0067          */
0068         virtual void nextTrackToParse() = 0;
0069 
0070         /**
0071          * This method must create a two-way association of the current Meta::Track
0072          * to the special struct provided by the library to read/write information.
0073          * For example, for libgpod one would associate Itdb_Track*.  It makes
0074          * the most sense to use a QHash since it is fastest lookup and order
0075          * does not matter.
0076          * @param track The track to two-way associate with a library track struct
0077          */
0078         virtual void setAssociateTrack( const Meta::MediaDeviceTrackPtr track ) = 0;
0079 
0080         /*
0081          * Methods that wrap get/set of information using given library (e.g. libgpod)
0082          * Subclasses of MediaDeviceHandler must keep a pointer to the track struct
0083          * associated to the track parameter to get the information from the struct in libGet*,
0084          * and to set the struct's information to the passed metadata in libSet*
0085          */
0086 
0087         virtual QString libGetAlbum( const Meta::MediaDeviceTrackPtr &track ) = 0;
0088         virtual QString libGetArtist( const Meta::MediaDeviceTrackPtr &track ) = 0;
0089         virtual QString libGetAlbumArtist( const Meta::MediaDeviceTrackPtr &track ) = 0;
0090         virtual QString libGetComposer( const Meta::MediaDeviceTrackPtr &track ) = 0;
0091         virtual QString libGetGenre( const Meta::MediaDeviceTrackPtr &track ) = 0;
0092         virtual int     libGetYear( const Meta::MediaDeviceTrackPtr &track ) = 0;
0093 
0094         virtual QString libGetTitle( const Meta::MediaDeviceTrackPtr &track ) = 0;
0095         virtual qint64  libGetLength( const Meta::MediaDeviceTrackPtr &track ) = 0;
0096         virtual int     libGetTrackNumber( const Meta::MediaDeviceTrackPtr &track ) = 0;
0097         virtual QString libGetComment( const Meta::MediaDeviceTrackPtr &track ) = 0;
0098         virtual int     libGetDiscNumber( const Meta::MediaDeviceTrackPtr &track ) = 0;
0099         virtual int     libGetBitrate( const Meta::MediaDeviceTrackPtr &track ) = 0;
0100         virtual int     libGetSamplerate( const Meta::MediaDeviceTrackPtr &track ) = 0;
0101         virtual qreal   libGetBpm( const Meta::MediaDeviceTrackPtr &track ) = 0;
0102         virtual int     libGetFileSize( const Meta::MediaDeviceTrackPtr &track ) = 0;
0103         virtual int     libGetPlayCount( const Meta::MediaDeviceTrackPtr &track ) = 0;
0104         virtual QDateTime libGetLastPlayed( const Meta::MediaDeviceTrackPtr &track ) = 0;
0105         virtual int     libGetRating( const Meta::MediaDeviceTrackPtr &track )  = 0;
0106         virtual QString libGetType( const Meta::MediaDeviceTrackPtr &track ) = 0;
0107         virtual QUrl    libGetPlayableUrl( const Meta::MediaDeviceTrackPtr &track ) = 0;
0108         virtual bool    libIsCompilation( const Meta::MediaDeviceTrackPtr &track );
0109         virtual qreal   libGetReplayGain( const Meta::MediaDeviceTrackPtr &track );
0110 
0111         /**
0112          * Get used capacity on the device, in bytes. Returns 0.0 if capacity information
0113          * is not appropriate or not available.
0114          */
0115         virtual float usedCapacity() const { return 0.0; }
0116 
0117         /**
0118          * Get total (used + free) capacity on the device, in bytes. Returns 0.0 if
0119          * capacity information is not appropriate or not available.
0120          */
0121         virtual float totalCapacity() const { return 0.0; }
0122 
0123 };
0124 }
0125 
0126 #endif