File indexing completed on 2024-04-28 04:55:51

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2010-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005     SPDX-FileCopyrightText: 2010-2011 Ramin Gomari <ramin.gomari@gmail.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0008 */
0009 
0010 #ifndef MPRIS_H
0011 #define MPRIS_H
0012 
0013 #include <QString>
0014 #include <QStringList>
0015 #include <QVariantMap>
0016 
0017 /**
0018 implament of MPRIS
0019 see more details @ http://xmms2.org/wiki/MPRIS
0020 @author Ramin Gomari \<ramin.gomari@gmail.com\>
0021 */
0022 class MPRIS
0023 {
0024 public:
0025     struct MprisStatusStruct {
0026         MprisStatusStruct()
0027         {
0028             Status = hasShuffle = hasRepeat = hasPlaylistRepeat = -1;
0029         };
0030 
0031         int Status;            // 0 = Playing, 1 = Paused, 2 = Stopped.
0032         int hasShuffle;        // 0 = Playing linearly , 1 = Playing randomly.
0033         int hasRepeat;         // 0 = Go to the next element once the current has finished playing , 1 = Repeat the current element
0034         int hasPlaylistRepeat; // 0 = Stop playing once the last element has been played, 1 = Never give up playing
0035     };
0036     MPRIS(const QString  PlayerName);
0037     ~MPRIS();
0038 
0039     static QStringList getRunningPlayers();
0040 
0041     /**
0042 
0043     @return true if this query was a valid query
0044     */
0045     bool isValid()
0046     {
0047         return valid;
0048     }
0049 
0050     bool isPlaying()
0051     {
0052         return status.Status == 0;
0053     }
0054     bool isPaused()
0055     {
0056         return status.Status == 1;
0057     }
0058     bool isStopped()
0059     {
0060         return status.Status == 2;
0061     }
0062     bool hasRepeat()
0063     {
0064         return status.hasRepeat == 1;
0065     }
0066     bool hasPlaylistRepeat()
0067     {
0068         return status.hasPlaylistRepeat == 1;
0069     }
0070 
0071     const QString getLocation()       // Url to the media (local files are represented as a file:// url)
0072     {
0073         return trackInfo[QLatin1String("location")].toString();
0074     }
0075     const QString getTitle()          // Name
0076     {
0077         return trackInfo[QLatin1String("title")].toString();
0078     }
0079     const QString getArtist()          // Name of artist or band performing the work
0080     {
0081         return trackInfo[QLatin1String("artist")].toString();
0082     }
0083     const QString getAlbum()          // Name of compilation the work is part of
0084     {
0085         return trackInfo[QLatin1String("album")].toString();
0086     }
0087     const QString getTracknumber()      // The position if it's part of a larger set, it may have to be converted to an integer. This MAY be extended with a '/' character and a numeric string containing the total number of elements in the set. E.g. '69/1337'.
0088     {
0089         return trackInfo[QLatin1String("tracknumber")].toString();
0090     }
0091     uint getTime()          // The duration in seconds
0092     {
0093         return trackInfo[QLatin1String("time")].toUInt();
0094     }
0095     uint getMtime()          // The duration in milliseconds
0096     {
0097         return trackInfo[QLatin1String("mtime")].toUInt();
0098     }
0099     const QString getGenre()          // The genre. This MAY begin with a numerical value reflecting the genre in a previously known array of genres, such as ID3 genres. See http://www.linuxselfhelp.com/HOWTO/MP3-HOWTO-13.html#ss13.3
0100     {
0101         return trackInfo[QLatin1String("genre")].toString();
0102     }
0103     const QString getComment()      // A comment about the work
0104     {
0105         return trackInfo[QLatin1String("comment")].toString();
0106     }
0107     uint getRating()          // A 'taste' rate value, out of 5. 0-5 or 1-5?
0108     {
0109         return trackInfo[QLatin1String("rating")].toUInt();
0110     }
0111     uint getYear()          // The year when the performing was realized, i.e. 2007.
0112     {
0113         return trackInfo[QLatin1String("year")].toUInt();
0114     }
0115     uint getDate()          // When the performing was realized, for precise needs. It is represented as epoch, i.e. the number of seconds since « 00:00:00 1970-01-01 UTC »
0116     {
0117         return trackInfo[QLatin1String("date")].toUInt();
0118     }
0119     const QString getArturl()          // An URI to an image associated with the work
0120     {
0121         return trackInfo[QLatin1String("arturl")].toString();
0122     }
0123     const QVariantMap getTrackMetadata()
0124     {
0125         return trackInfo;
0126     }
0127     const QString getPlayerIdentification()
0128     {
0129         return Identity;
0130     }
0131 private:
0132     bool valid;
0133     MprisStatusStruct status;
0134     QVariantMap trackInfo;
0135     QString Identity;
0136 };
0137 
0138 #endif // MPRIS_H