diff options
Diffstat (limited to 'src/modules/mediaplayer')
| -rw-r--r-- | src/modules/mediaplayer/MpAmipInterface.cpp | 170 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpAmipInterface.h | 91 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpInterface.cpp | 61 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpInterface.h | 117 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpMp3.cpp | 371 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpMp3.h | 68 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpMprisInterface.cpp | 412 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpMprisInterface.h | 196 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpWinampInterface.cpp | 198 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpWinampInterface.h | 81 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpXmmsInterface.cpp | 189 | ||||
| -rw-r--r-- | src/modules/mediaplayer/MpXmmsInterface.h | 89 | ||||
| -rw-r--r-- | src/modules/mediaplayer/libkvimediaplayer.cpp | 447 | ||||
| -rw-r--r-- | src/modules/mediaplayer/winamp.cpp | 46 |
14 files changed, 1310 insertions, 1226 deletions
diff --git a/src/modules/mediaplayer/MpAmipInterface.cpp b/src/modules/mediaplayer/MpAmipInterface.cpp index 1e01aac05..ddea46685 100644 --- a/src/modules/mediaplayer/MpAmipInterface.cpp +++ b/src/modules/mediaplayer/MpAmipInterface.cpp @@ -53,15 +53,16 @@ enum ac_ErrorCode static HINSTANCE amip_dll = NULL; -#define MP_AC_DYNPTR(__rettype,__func,__args) \ - typedef __rettype (CALLBACK* lp_##__func)(__args); \ +#define MP_AC_DYNPTR(__rettype, __func, __args) \ + typedef __rettype(CALLBACK * lp_##__func)(__args); \ lp_##__func __func -#define MP_AC_FUNC(__func) \ - __func = (lp_##__func)GetProcAddress(amip_dll,#__func); \ - if(!__func) { \ - FreeLibrary(amip_dll); \ - return false; \ +#define MP_AC_FUNC(__func) \ + __func = (lp_##__func)GetProcAddress(amip_dll, #__func); \ + if(!__func) \ + { \ + FreeLibrary(amip_dll); \ + return false; \ } #define COMMA() , @@ -72,13 +73,13 @@ MP_AC_DYNPTR(void, ac_getDestHost, char * out); MP_AC_DYNPTR(int, ac_getDestPort, void); MP_AC_DYNPTR(bool, ac_pingServer, const char * host COMMA() int port COMMA() int timeout); MP_AC_DYNPTR(int, ac_exec, const char * cmd); -MP_AC_DYNPTR(int, ac_eval, const char * cmd COMMA() char *result); - +MP_AC_DYNPTR(int, ac_eval, const char * cmd COMMA() char * result); static bool loadAmipDll() { amip_dll = LoadLibrary("ac.dll"); - if (!amip_dll) return false; + if(!amip_dll) + return false; MP_AC_FUNC(ac_init); MP_AC_FUNC(ac_uninit); @@ -102,26 +103,23 @@ static QTextCodec * mediaplayer_get_codec() } MP_IMPLEMENT_DESCRIPTOR( - MpAmipInterface, - "amip", - __tr2qs_ctx( - "An interface for the AMIP plugin.\n" \ - "You can download it from http://amip.tools-for.net\n" \ - "To use this interface you must " \ - "install AMIP plugin for your player." - , - "mediaplayer" - ) -) - - + MpAmipInterface, + "amip", + __tr2qs_ctx( + "An interface for the AMIP plugin.\n" + "You can download it from http://amip.tools-for.net\n" + "To use this interface you must " + "install AMIP plugin for your player.", + "mediaplayer")) MpAmipInterface::MpAmipInterface() -: MpInterface() + : MpInterface() { - if(!amip_dll) { + if(!amip_dll) + { bool res = loadAmipDll(); - if(!res) { + if(!res) + { amip_dll = NULL; return; } @@ -131,52 +129,56 @@ MpAmipInterface::MpAmipInterface() MpAmipInterface::~MpAmipInterface() { - if(!amip_dll) return; + if(!amip_dll) + return; ac_uninit(); FreeLibrary(amip_dll); amip_dll = NULL; } - int MpAmipInterface::detect(bool bStart) { - if(!amip_dll) return 0; + if(!amip_dll) + return 0; char host[AC_BUFFER_SIZE]; ac_getDestHost(host); - if(ac_pingServer(host, ac_getDestPort(), 5000)) return 99; + if(ac_pingServer(host, ac_getDestPort(), 5000)) + return 99; return 1; } -#define MP_AMIP_COMMAND(__cmdname,__acmd) \ - bool MpAmipInterface::__cmdname() \ - { \ +#define MP_AMIP_COMMAND(__cmdname, __acmd) \ + bool MpAmipInterface::__cmdname() \ + { \ return (ac_exec(__acmd) == AC_ERR_NOERROR); \ } -MP_AMIP_COMMAND(play,"control play") -MP_AMIP_COMMAND(stop,"control stop") -MP_AMIP_COMMAND(next,"control >") -MP_AMIP_COMMAND(prev,"control <") -MP_AMIP_COMMAND(pause,"control pause") -MP_AMIP_COMMAND(quit,"control exit") +MP_AMIP_COMMAND(play, "control play") +MP_AMIP_COMMAND(stop, "control stop") +MP_AMIP_COMMAND(next, "control >") +MP_AMIP_COMMAND(prev, "control <") +MP_AMIP_COMMAND(pause, "control pause") +MP_AMIP_COMMAND(quit, "control exit") // helper function for evaluating variables returning integers -int eval_int(const char *var) +int eval_int(const char * var) { - if(!amip_dll) return -1; + if(!amip_dll) + return -1; char buff[AC_BUFFER_SIZE]; int res = -1; - if (AC_ERR_NOERROR == ac_eval(var, buff)) + if(AC_ERR_NOERROR == ac_eval(var, buff)) res = atoi(buff); return res; } -QString eval_str(const char *var) +QString eval_str(const char * var) { QString res; - if(!amip_dll) return res; + if(!amip_dll) + return res; char buff[AC_BUFFER_SIZE]; - if (AC_ERR_NOERROR == ac_eval(var, buff)) + if(AC_ERR_NOERROR == ac_eval(var, buff)) res.append(buff); return res; } @@ -218,16 +220,16 @@ MpInterface::PlayerStatus MpAmipInterface::status() { case 0: return MpInterface::Stopped; - break; + break; case 3: return MpInterface::Paused; - break; + break; case 1: return MpInterface::Playing; - break; + break; default: return MpInterface::Unknown; - break; + break; } return MpInterface::Unknown; } @@ -240,7 +242,9 @@ QString MpAmipInterface::mrl() if(pCodec) { szRet = pCodec->toUnicode(szFn.toUtf8()); - } else { + } + else + { szRet = szFn; } @@ -255,9 +259,12 @@ QString getAmipString(const char * var) QString szRet; QString szString = eval_str(var); QTextCodec * pCodec = mediaplayer_get_codec(); - if(pCodec) { + if(pCodec) + { szRet = pCodec->toUnicode(szString.toUtf8()); - } else { + } + else + { szRet = szString; } return szRet; @@ -298,9 +305,10 @@ QString MpAmipInterface::genre() return getAmipString("var_7"); } -bool MpAmipInterface::setVol(kvs_int_t &iVol) +bool MpAmipInterface::setVol(kvs_int_t & iVol) { - if(!amip_dll) return false; + if(!amip_dll) + return false; char volcmd[AC_BUFFER_SIZE]; sprintf(volcmd, "control vol %d", iVol); return (ac_exec(volcmd) == AC_ERR_NOERROR); @@ -311,11 +319,12 @@ int MpAmipInterface::getVol() return eval_int("var_vol"); } -bool MpAmipInterface::jumpTo(kvs_int_t &iPos) +bool MpAmipInterface::jumpTo(kvs_int_t & iPos) { - if(!amip_dll) return false; + if(!amip_dll) + return false; char jmpcmd[AC_BUFFER_SIZE]; - sprintf(jmpcmd, "jumptotime %d", iPos/1000); + sprintf(jmpcmd, "jumptotime %d", iPos / 1000); return (ac_exec(jmpcmd) == AC_ERR_NOERROR); } bool MpAmipInterface::hide() @@ -342,13 +351,15 @@ bool MpAmipInterface::show() bool MpAmipInterface::minimize() { - if(!amip_dll) return false; + if(!amip_dll) + return false; return (ac_exec("control mimimize") == AC_ERR_NOERROR); } -bool MpAmipInterface::setPlayListPos(kvs_int_t &iPos) +bool MpAmipInterface::setPlayListPos(kvs_int_t & iPos) { - if(!amip_dll) return false; + if(!amip_dll) + return false; char jmpcmd[AC_BUFFER_SIZE]; sprintf(jmpcmd, "setplpos %d", iPos + 1); return (ac_exec(jmpcmd) == AC_ERR_NOERROR); @@ -374,48 +385,55 @@ bool MpAmipInterface::getShuffle() return eval_str("var_shuffle").startsWith("on"); } -bool MpAmipInterface::setShuffle(bool &bVal) +bool MpAmipInterface::setShuffle(bool & bVal) { - if(!amip_dll) return false; + if(!amip_dll) + return false; bool res; - if (bVal) + if(bVal) res = (ac_exec("setshuffle on") == AC_ERR_NOERROR); else res = (ac_exec("setshuffle off") == AC_ERR_NOERROR); return res; } -bool MpAmipInterface::setRepeat(bool &bVal) +bool MpAmipInterface::setRepeat(bool & bVal) { - if(!amip_dll) return false; + if(!amip_dll) + return false; bool res; - if (bVal) + if(bVal) res = (ac_exec("setrepeat on") == AC_ERR_NOERROR); else res = (ac_exec("setrepeat off") == AC_ERR_NOERROR); return res; } -bool MpAmipInterface::amipExec(const QString &cmd) +bool MpAmipInterface::amipExec(const QString & cmd) { - if(!amip_dll) return false; - QTextCodec *c=mediaplayer_get_codec(); + if(!amip_dll) + return false; + QTextCodec * c = mediaplayer_get_codec(); KviCString szCmd = c ? c->fromUnicode(cmd) : cmd.toUtf8(); return (ac_exec(szCmd) == AC_ERR_NOERROR); } -QString MpAmipInterface::amipEval(const QString &cmd) +QString MpAmipInterface::amipEval(const QString & cmd) { QString ret; - if(!amip_dll) return ret; - QTextCodec *c=mediaplayer_get_codec(); + if(!amip_dll) + return ret; + QTextCodec * c = mediaplayer_get_codec(); KviCString szCmd = c ? c->fromUnicode(cmd) : cmd.toUtf8(); char buff[AC_BUFFER_SIZE]; - if((ac_eval(szCmd, buff) == AC_ERR_NOERROR)) { + if((ac_eval(szCmd, buff) == AC_ERR_NOERROR)) + { QString s = buff; - QTextCodec *c=mediaplayer_get_codec(); - if (c) ret = c->toUnicode(s.toLatin1()); - else ret=s; + QTextCodec * c = mediaplayer_get_codec(); + if(c) + ret = c->toUnicode(s.toLatin1()); + else + ret = s; } return ret; } diff --git a/src/modules/mediaplayer/MpAmipInterface.h b/src/modules/mediaplayer/MpAmipInterface.h index 57ec57138..8e39a5057 100644 --- a/src/modules/mediaplayer/MpAmipInterface.h +++ b/src/modules/mediaplayer/MpAmipInterface.h @@ -28,53 +28,54 @@ #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - #include "MpInterface.h" +#include "MpInterface.h" - class MpAmipInterface : public MpInterface - { - public: - MpAmipInterface(); - ~MpAmipInterface(); - public: - virtual int detect(bool bStart); - virtual bool prev(); - virtual bool next(); - virtual bool play(); - virtual bool stop(); - virtual bool pause(); - virtual bool quit(); - virtual QString nowPlaying(); - virtual QString artist(); - virtual QString title(); - virtual QString genre(); - virtual QString comment(); - virtual QString album(); - virtual QString year(); - virtual QString mrl(); - virtual int position(); - virtual int length(); - virtual bool setVol(kvs_int_t &iVol); - virtual int getVol(); - virtual bool jumpTo(kvs_int_t &iPos); - virtual int sampleRate(); - virtual int bitRate(); - virtual int channels(); - virtual bool hide(); - virtual bool show(); - virtual bool minimize(); - virtual int getPlayListPos(); - virtual bool setPlayListPos(kvs_int_t &iPos); - virtual int getListLength(); - virtual bool getRepeat(); - virtual bool getShuffle(); - virtual bool setRepeat(bool &bVal); - virtual bool setShuffle(bool &bVal); - virtual bool amipExec(const QString &cmd); - virtual QString amipEval(const QString &cmd); - virtual MpInterface::PlayerStatus status(); - }; +class MpAmipInterface : public MpInterface +{ +public: + MpAmipInterface(); + ~MpAmipInterface(); - MP_DECLARE_DESCRIPTOR(MpAmipInterface) +public: + virtual int detect(bool bStart); + virtual bool prev(); + virtual bool next(); + virtual bool play(); + virtual bool stop(); + virtual bool pause(); + virtual bool quit(); + virtual QString nowPlaying(); + virtual QString artist(); + virtual QString title(); + virtual QString genre(); + virtual QString comment(); + virtual QString album(); + virtual QString year(); + virtual QString mrl(); + virtual int position(); + virtual int length(); + virtual bool setVol(kvs_int_t & iVol); + virtual int getVol(); + virtual bool jumpTo(kvs_int_t & iPos); + virtual int sampleRate(); + virtual int bitRate(); + virtual int channels(); + virtual bool hide(); + virtual bool show(); + virtual bool minimize(); + virtual int getPlayListPos(); + virtual bool setPlayListPos(kvs_int_t & iPos); + virtual int getListLength(); + virtual bool getRepeat(); + virtual bool getShuffle(); + virtual bool setRepeat(bool & bVal); + virtual bool setShuffle(bool & bVal); + virtual bool amipExec(const QString & cmd); + virtual QString amipEval(const QString & cmd); + virtual MpInterface::PlayerStatus status(); +}; + +MP_DECLARE_DESCRIPTOR(MpAmipInterface) #endif //COMPILE_ON_WINDOWS diff --git a/src/modules/mediaplayer/MpInterface.cpp b/src/modules/mediaplayer/MpInterface.cpp index d646389a5..f0feb5861 100644 --- a/src/modules/mediaplayer/MpInterface.cpp +++ b/src/modules/mediaplayer/MpInterface.cpp @@ -32,15 +32,15 @@ static QTextCodec * mediaplayer_get_codec() { - QTextCodec * c= QTextCodec::codecForName(KVI_OPTION_STRING(KviOption_stringWinampTextEncoding).toUtf8().data()); - if(!c)c = QTextCodec::codecForLocale(); + QTextCodec * c = QTextCodec::codecForName(KVI_OPTION_STRING(KviOption_stringWinampTextEncoding).toUtf8().data()); + if(!c) + c = QTextCodec::codecForLocale(); return c; - } void MpInterface::notImplemented() { - setLastError(__tr2qs_ctx("Function not implemented","mediaplayer")); + setLastError(__tr2qs_ctx("Function not implemented", "mediaplayer")); } int MpInterface::position() @@ -82,10 +82,11 @@ bool MpInterface::minimize() QString MpInterface::getLocalFile() { QString ret = mrl(); - if(ret.isEmpty())return ret; - if(ret.startsWith("file://",Qt::CaseInsensitive)) + if(ret.isEmpty()) + return ret; + if(ret.startsWith("file://", Qt::CaseInsensitive)) { - ret.remove(0,7); + ret.remove(0, 7); return ret; } return QString(); @@ -96,20 +97,23 @@ QString MpInterface::amipEval(const QString &) return QString(); } -#define SCAN_MP3_FILE \ +#define SCAN_MP3_FILE \ QString f = getLocalFile(); \ - if(f.isEmpty())return QString(); \ - mp3info mp3; \ - if(!scan_mp3_file(f,&mp3))return QString(); \ - QTextCodec *pCodec; \ - pCodec=mediaplayer_get_codec(); + if(f.isEmpty()) \ + return QString(); \ + mp3info mp3; \ + if(!scan_mp3_file(f, &mp3)) \ + return QString(); \ + QTextCodec * pCodec; \ + pCodec = mediaplayer_get_codec(); -#define SCAN_MP3_FILE_RET_INT \ +#define SCAN_MP3_FILE_RET_INT \ QString f = getLocalFile(); \ - if(f.isEmpty())return -1; \ - mp3info mp3; \ - if(!scan_mp3_file(f,&mp3))return -1; - + if(f.isEmpty()) \ + return -1; \ + mp3info mp3; \ + if(!scan_mp3_file(f, &mp3)) \ + return -1; QString MpInterface::artist() { @@ -265,12 +269,19 @@ bool MpInterface::setShuffle(bool &) QString MpInterface::mediaType() { QString ret = mrl(); - if(ret.endsWith(".mp3",Qt::CaseInsensitive))ret = "MPEG Layer 3"; - else if(ret.endsWith(".ogg",Qt::CaseInsensitive))ret = "OGG Vorbis"; - else if(ret.endsWith(".avi",Qt::CaseInsensitive))ret = "Audio Video Interleave"; - else if(ret.endsWith(".mpeg",Qt::CaseInsensitive))ret = "MPEG Video"; - else if(ret.endsWith(".mpg",Qt::CaseInsensitive))ret = "MPEG Video"; - else if(ret.startsWith("http://",Qt::CaseInsensitive))ret = "HTTP Audio Stream"; - else ret = QString(); + if(ret.endsWith(".mp3", Qt::CaseInsensitive)) + ret = "MPEG Layer 3"; + else if(ret.endsWith(".ogg", Qt::CaseInsensitive)) + ret = "OGG Vorbis"; + else if(ret.endsWith(".avi", Qt::CaseInsensitive)) + ret = "Audio Video Interleave"; + else if(ret.endsWith(".mpeg", Qt::CaseInsensitive)) + ret = "MPEG Video"; + else if(ret.endsWith(".mpg", Qt::CaseInsensitive)) + ret = "MPEG Video"; + else if(ret.startsWith("http://", Qt::CaseInsensitive)) + ret = "HTTP Audio Stream"; + else + ret = QString(); return ret; } diff --git a/src/modules/mediaplayer/MpInterface.h b/src/modules/mediaplayer/MpInterface.h index 42c1374a4..aae380f5c 100644 --- a/src/modules/mediaplayer/MpInterface.h +++ b/src/modules/mediaplayer/MpInterface.h @@ -35,8 +35,10 @@ public: // implement lazy initialization in each function instead MpInterface(){}; virtual ~MpInterface(){}; + protected: QString m_szLastError; + public: const QString & lastError() const { return m_szLastError; }; @@ -90,16 +92,16 @@ public: // the mrl may be (or may be not) added to the player's playlist // the function should return false if the player doesn't support // this function or there is a communication error - virtual bool playMrl(const QString &mrl); + virtual bool playMrl(const QString & mrl); // what is this ? :D - virtual bool amipExec(const QString &cmd); - virtual QString amipEval(const QString &cmd); + virtual bool amipExec(const QString & cmd); + virtual QString amipEval(const QString & cmd); // this is functions to hide,show and minimize the player interface virtual bool hide(); virtual bool show(); virtual bool minimize(); // set the volume of mediaplayer (0-255) - virtual bool setVol(kvs_int_t &iVol); + virtual bool setVol(kvs_int_t & iVol); // get the pvolume value(0-255) virtual int getVol(); //mute the volume @@ -108,7 +110,13 @@ public: // return false only on communication failure virtual bool quit(); // return the current player status - enum PlayerStatus { Unknown, Stopped, Playing, Paused }; + enum PlayerStatus + { + Unknown, + Stopped, + Playing, + Paused + }; virtual MpInterface::PlayerStatus status(); // current position in the media (msecs) // 0 if the player isn't playing anything and -1 if unknown @@ -117,7 +125,7 @@ public: // 0 if the player isn't playing anyting and -1 if unknown (e.g. a stream) virtual int length(); // jump to position - virtual bool jumpTo(kvs_int_t &iPos); + virtual bool jumpTo(kvs_int_t & iPos); // interface with a default implementation for certain types of media (read for mp3) // reimplement only if the player knows better @@ -156,83 +164,86 @@ public: // get the position in the playlist virtual int getPlayListPos(); // set the position in the playlist - virtual bool setPlayListPos(kvs_int_t &iPos); + virtual bool setPlayListPos(kvs_int_t & iPos); // return the list's length virtual int getListLength(); // return the Eq(number) value - virtual int getEqData(kvs_int_t &i_val); + virtual int getEqData(kvs_int_t & i_val); // set the Eq(iPos) to Eq(iVal) value - virtual bool setEqData(kvs_int_t &iPos, kvs_int_t &iVal); + virtual bool setEqData(kvs_int_t & iPos, kvs_int_t & iVal); // get the Repeat bool value virtual bool getRepeat(); // get the shuffle bool value virtual bool getShuffle(); // set the Repeat bool value - virtual bool setRepeat(bool &bVal); + virtual bool setRepeat(bool & bVal); // set the shuffle bool value - virtual bool setShuffle(bool &bVal); - void setLastError(const QString &szLastError){ m_szLastError = szLastError; }; + virtual bool setShuffle(bool & bVal); + void setLastError(const QString & szLastError) { m_szLastError = szLastError; }; protected: void notImplemented(); QString getLocalFile(); }; - class MpInterfaceDescriptor { public: MpInterfaceDescriptor(){}; virtual ~MpInterfaceDescriptor(){}; + public: virtual const QString & name() = 0; virtual const QString & description() = 0; virtual MpInterface * instance() = 0; }; - -#define MP_DECLARE_DESCRIPTOR(_interfaceclass) \ - class _interfaceclass ## Descriptor : public MpInterfaceDescriptor \ - { \ - public: \ - _interfaceclass ## Descriptor(); \ - virtual ~_interfaceclass ## Descriptor(); \ - protected: \ - _interfaceclass * m_pInstance; \ - QString m_szName; \ - QString m_szDescription; \ - public: \ - virtual const QString & name(); \ - virtual const QString & description(); \ - virtual MpInterface * instance(); \ +#define MP_DECLARE_DESCRIPTOR(_interfaceclass) \ + class _interfaceclass##Descriptor : public MpInterfaceDescriptor \ + { \ + public: \ + _interfaceclass##Descriptor(); \ + virtual ~_interfaceclass##Descriptor(); \ + \ + protected: \ + _interfaceclass * m_pInstance; \ + QString m_szName; \ + QString m_szDescription; \ + \ + public: \ + virtual const QString & name(); \ + virtual const QString & description(); \ + virtual MpInterface * instance(); \ }; -#define MP_IMPLEMENT_DESCRIPTOR(_interfaceclass,_name,_description) \ - _interfaceclass ## Descriptor::_interfaceclass ## Descriptor() \ - : MpInterfaceDescriptor() \ - { \ - m_pInstance = 0; \ - m_szName = _name; \ - m_szDescription = _description; \ - } \ - _interfaceclass ## Descriptor::~_interfaceclass ## Descriptor() \ - { \ - if(m_pInstance)delete m_pInstance; \ - } \ - const QString & _interfaceclass ## Descriptor::name() \ - { \ - return m_szName; \ - } \ - const QString & _interfaceclass ## Descriptor::description() \ - { \ - return m_szDescription; \ - } \ - MpInterface * _interfaceclass ## Descriptor::instance() \ - { \ - if(!m_pInstance)m_pInstance = new _interfaceclass(); \ - return m_pInstance; \ +#define MP_IMPLEMENT_DESCRIPTOR(_interfaceclass, _name, _description) \ + _interfaceclass##Descriptor::_interfaceclass##Descriptor() \ + : MpInterfaceDescriptor() \ + { \ + m_pInstance = 0; \ + m_szName = _name; \ + m_szDescription = _description; \ + } \ + _interfaceclass##Descriptor::~_interfaceclass##Descriptor() \ + { \ + if(m_pInstance) \ + delete m_pInstance; \ + } \ + const QString & _interfaceclass##Descriptor::name() \ + { \ + return m_szName; \ + } \ + const QString & _interfaceclass##Descriptor::description() \ + { \ + return m_szDescription; \ + } \ + MpInterface * _interfaceclass##Descriptor::instance() \ + { \ + if(!m_pInstance) \ + m_pInstance = new _interfaceclass(); \ + return m_pInstance; \ } #define MP_CREATE_DESCRIPTOR(_interfaceclass) \ - new _interfaceclass ## Descriptor() + new _interfaceclass##Descriptor() #endif //!_MP_INTERFACE_H_ diff --git a/src/modules/mediaplayer/MpMp3.cpp b/src/modules/mediaplayer/MpMp3.cpp index 59aae7560..caf35b8e7 100644 --- a/src/modules/mediaplayer/MpMp3.cpp +++ b/src/modules/mediaplayer/MpMp3.cpp @@ -43,8 +43,8 @@ #include <QFileInfo> #include <QTextCodec> -#define MAXGENRE 147 -#define GENREROWS 50 +#define MAXGENRE 147 +#define GENREROWS 50 /* The Information is stored in the last 128 bytes of an MP3. The Tag @@ -88,264 +88,263 @@ starting from 0. See A.3. */ - -const char *typegenre [MAXGENRE+2] = -{ - "Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge", - "Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B", - "Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska", - "Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient", - "Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical", - "Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise", - "Alt. Rock","Bass","Soul","Punk","Space","Meditative", - "Instrumental Pop","Instrumental Rock","Ethnic","Gothic", - "Darkwave","Techno-Industrial","Electronic","Pop-Folk","Eurodance", - "Dream","Southern Rock","Comedy","Cult","Gangsta Rap","Top 40", - "Christian Rap","Pop/Funk","Jungle","Native American","Cabaret", - "New Wave","Psychedelic","Rave","Showtunes","Trailer","Lo-Fi", - "Tribal","Acid Punk","Acid Jazz","Polka","Retro","Musical", - "Rock & Roll","Hard Rock","Folk","Folk/Rock","National Folk", - "Swing","Fast-Fusion","Bebob","Latin","Revival","Celtic", - "Bluegrass","Avantgarde","Gothic Rock","Progressive Rock", - "Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band", - "Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson", - "Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus", - "Porn Groove","Satire","Slow Jam","Club","Tango","Samba", - "Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle", - "Duet","Punk Rock","Drum Solo","A Cappella","Euro-House", - "Dance Hall","Goa","Drum & Bass","Club-House","Hardcore","Terror", - "Indie","BritPop","Negerpunk","Polsk Punk","Beat", - "Christian Gangsta Rap","Heavy Metal","Black Metal","Crossover", - "Contemporary Christian","Christian Rock","Merengue","Salsa", - "Thrash Metal","Anime","JPop","Synthpop","" +const char * typegenre[MAXGENRE + 2] = { + "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", + "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B", + "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska", + "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient", + "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical", + "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise", + "Alt. Rock", "Bass", "Soul", "Punk", "Space", "Meditative", + "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", + "Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", + "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta Rap", "Top 40", + "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", + "New Wave", "Psychedelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", + "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", + "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", + "Swing", "Fast-Fusion", "Bebob", "Latin", "Revival", "Celtic", + "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock", + "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", + "Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", + "Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus", + "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", + "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle", + "Duet", "Punk Rock", "Drum Solo", "A Cappella", "Euro-House", + "Dance Hall", "Goa", "Drum & Bass", "Club-House", "Hardcore", "Terror", + "Indie", "BritPop", "Negerpunk", "Polsk Punk", "Beat", + "Christian Gangsta Rap", "Heavy Metal", "Black Metal", "Crossover", + "Contemporary Christian", "Christian Rock", "Merengue", "Salsa", + "Thrash Metal", "Anime", "JPop", "Synthpop", "" }; const char * get_typegenre(int idx) { - if(idx > MAXGENRE)return typegenre[12]; + if(idx > MAXGENRE) + return typegenre[12]; return typegenre[idx]; } -int galphagenreindex[MAXGENRE+2] = -{ - 148,123,74,73,34,99,40,20,26,145,90, - 116,41,135,85,96,138,89,0,107,132,65,88, - 104,102,97,136,61,141,1,32,128,112,57,140, - 2,139,58,125,3,50,22,4,55,127,122,120, - 98,52,48,124,25,54,84,81,115,80,119,5, - 30,36,59,126,38,91,49,6,79,129,137,7, - 35,100,131,19,46,47,33,146,29,8,63,86, - 71,45,142,9,77,82,64,133,10,66,39,11, - 103,12,75,134,53,62,13,109,117,23,108,92, - 93,67,121,43,14,15,68,16,76,87,118,78, - 17,143,114,110,69,21,111,95,105,42,37,24, - 56,44,101,83,94,106,147,113,51,18,130,144, - 60,70,31,72,27,28 +int galphagenreindex[MAXGENRE + 2] = { + 148, 123, 74, 73, 34, 99, 40, 20, 26, 145, 90, + 116, 41, 135, 85, 96, 138, 89, 0, 107, 132, 65, 88, + 104, 102, 97, 136, 61, 141, 1, 32, 128, 112, 57, 140, + 2, 139, 58, 125, 3, 50, 22, 4, 55, 127, 122, 120, + 98, 52, 48, 124, 25, 54, 84, 81, 115, 80, 119, 5, + 30, 36, 59, 126, 38, 91, 49, 6, 79, 129, 137, 7, + 35, 100, 131, 19, 46, 47, 33, 146, 29, 8, 63, 86, + 71, 45, 142, 9, 77, 82, 64, 133, 10, 66, 39, 11, + 103, 12, 75, 134, 53, 62, 13, 109, 117, 23, 108, 92, + 93, 67, 121, 43, 14, 15, 68, 16, 76, 87, 118, 78, + 17, 143, 114, 110, 69, 21, 111, 95, 105, 42, 37, 24, + 56, 44, 101, 83, 94, 106, 147, 113, 51, 18, 130, 144, + 60, 70, 31, 72, 27, 28 }; -int *alphagenreindex=&(galphagenreindex[1]); - +int * alphagenreindex = &(galphagenreindex[1]); -int layer_tab[4]= {0, 3, 2, 1}; +int layer_tab[4] = { 0, 3, 2, 1 }; -int frequencies[3][4] = -{ - {22050,24000,16000,50000}, /* MPEG 2.0 */ - {44100,48000,32000,50000}, /* MPEG 1.0 */ - {11025,12000,8000,50000} /* MPEG 2.5 */ +int frequencies[3][4] = { + { 22050, 24000, 16000, 50000 }, /* MPEG 2.0 */ + { 44100, 48000, 32000, 50000 }, /* MPEG 1.0 */ + { 11025, 12000, 8000, 50000 } /* MPEG 2.5 */ }; -int bitrate[2][3][14] = -{ - { /* MPEG 2.0 */ - {32,48,56,64,80,96,112,128,144,160,176,192,224,256}, /* layer 1 */ - {8,16,24,32,40,48,56,64,80,96,112,128,144,160}, /* layer 2 */ - {8,16,24,32,40,48,56,64,80,96,112,128,144,160} /* layer 3 */ +int bitrate[2][3][14] = { + { + /* MPEG 2.0 */ + { 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 }, /* layer 1 */ + { 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }, /* layer 2 */ + { 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 } /* layer 3 */ }, - { /* MPEG 1.0 */ - {32,64,96,128,160,192,224,256,288,320,352,384,416,448}, /* layer 1 */ - {32,48,56,64,80,96,112,128,160,192,224,256,320,384}, /* layer 2 */ - {32,40,48,56,64,80,96,112,128,160,192,224,256,320} /* layer 3 */ + { + /* MPEG 1.0 */ + { 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, /* layer 1 */ + { 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, /* layer 2 */ + { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } /* layer 3 */ } }; -int frame_size_index[] = {24000, 72000, 72000}; +int frame_size_index[] = { 24000, 72000, 72000 }; -const char *mode_text[] = -{ +const char * mode_text[] = { "Stereo", "Joint Stereo", "Dual Channel", "Mono" }; -const char *emphasis_text[] = -{ +const char * emphasis_text[] = { "None", "50/15 Microseconds", "Reserved", "CCITT J 17" }; -void resetmp3infoStruct(mp3info *i) +void resetmp3infoStruct(mp3info * i) { - i->file=0; - i->datasize=0; - i->header_isvalid=0; - memset(&i->header,0,sizeof(i->header)); - i->id3_isvalid=0; - memset(&i->id3,0,sizeof(i->id3)); - i->vbr=0; - i->vbr_average=0; - i->seconds=0; - i->frames=0; - i->badframes=0; + i->file = 0; + i->datasize = 0; + i->header_isvalid = 0; + memset(&i->header, 0, sizeof(i->header)); + i->id3_isvalid = 0; + memset(&i->id3, 0, sizeof(i->id3)); + i->vbr = 0; + i->vbr_average = 0; + i->seconds = 0; + i->frames = 0; + i->badframes = 0; } -int get_mp3_info(mp3info *mp3) +int get_mp3_info(mp3info * mp3) { -// mp3header header; + // mp3header header; QFile fi(mp3->filename); - mp3->datasize=fi.size();//filestat.st_size; + mp3->datasize = fi.size(); //filestat.st_size; get_id3(mp3); - if(get_first_header(mp3,0L)) + if(get_first_header(mp3, 0L)) { - int bitrate,counter=0; - int data_start=ftell(mp3->file); - int lastrate=15-mp3->header.bitrate; + int bitrate, counter = 0; + int data_start = ftell(mp3->file); + int lastrate = 15 - mp3->header.bitrate; while((counter < NUM_SAMPLES) && lastrate) { - int sample_pos=(counter*(mp3->datasize/NUM_SAMPLES+1))+data_start; - if(get_first_header(mp3,sample_pos)) + int sample_pos = (counter * (mp3->datasize / NUM_SAMPLES + 1)) + data_start; + if(get_first_header(mp3, sample_pos)) { - bitrate=15-mp3->header.bitrate; - } else { - bitrate=-1; + bitrate = 15 - mp3->header.bitrate; + } + else + { + bitrate = -1; } if(bitrate != lastrate) { - mp3->vbr=1; + mp3->vbr = 1; } - lastrate=bitrate; + lastrate = bitrate; counter++; - } - mp3->frames=(mp3->datasize-data_start)/(frame_length(&mp3->header)); - mp3->seconds = (int)((float)(frame_length(&mp3->header)*mp3->frames)/ - (float)(header_bitrate(&mp3->header)*125)+0.5); + mp3->frames = (mp3->datasize - data_start) / (frame_length(&mp3->header)); + mp3->seconds = (int)((float)(frame_length(&mp3->header) * mp3->frames) / (float)(header_bitrate(&mp3->header) * 125) + 0.5); mp3->vbr_average = (float)header_bitrate(&mp3->header); } return 0; } -int get_first_header(mp3info *mp3, long startpos) +int get_first_header(mp3info * mp3, long startpos) { - int k, l=0,c; + int k, l = 0, c; mp3header h, h2; - long valid_start=0; + long valid_start = 0; - fseek(mp3->file,startpos,SEEK_SET); + fseek(mp3->file, startpos, SEEK_SET); while(1) { - while((c=fgetc(mp3->file)) != 255 && (c != EOF)) {} + while((c = fgetc(mp3->file)) != 255 && (c != EOF)) + { + } if(c == 255) { - ungetc(c,mp3->file); - valid_start=ftell(mp3->file); - if((l=get_header(mp3->file,&h))) + ungetc(c, mp3->file); + valid_start = ftell(mp3->file); + if((l = get_header(mp3->file, &h))) { - fseek(mp3->file,l-FRAME_HEADER_SIZE,SEEK_CUR); - for(k=1; (k < MIN_CONSEC_GOOD_FRAMES) && (mp3->datasize-ftell(mp3->file) >= FRAME_HEADER_SIZE); k++) + fseek(mp3->file, l - FRAME_HEADER_SIZE, SEEK_CUR); + for(k = 1; (k < MIN_CONSEC_GOOD_FRAMES) && (mp3->datasize - ftell(mp3->file) >= FRAME_HEADER_SIZE); k++) { - if(!(l=get_header(mp3->file,&h2))) break; - if(!sameConstant(&h,&h2)) break; - fseek(mp3->file,l-FRAME_HEADER_SIZE,SEEK_CUR); + if(!(l = get_header(mp3->file, &h2))) + break; + if(!sameConstant(&h, &h2)) + break; + fseek(mp3->file, l - FRAME_HEADER_SIZE, SEEK_CUR); } if(k == MIN_CONSEC_GOOD_FRAMES) { - fseek(mp3->file,valid_start,SEEK_SET); + fseek(mp3->file, valid_start, SEEK_SET); memcpy(&(mp3->header), &h2, sizeof(mp3header)); mp3->header_isvalid = 1; return 1; } } - } else { + } + else + { return 0; } } return 0; } - // Get next MP3 frame header. // Return codes: // positive value = Frame Length of this header // 0 = No, we did not retrieve a valid frame header -int get_header(FILE *file,mp3header *header) +int get_header(FILE * file, mp3header * header) { unsigned char buffer[FRAME_HEADER_SIZE]; int fl; - if(fread(&buffer,FRAME_HEADER_SIZE,1,file)<1) + if(fread(&buffer, FRAME_HEADER_SIZE, 1, file) < 1) { - header->sync=0; + header->sync = 0; return 0; } - header->sync=(((int)buffer[0]<<4) | ((int)(buffer[1]&0xE0)>>4)); - if(buffer[1] & 0x10) header->version=(buffer[1] >> 3) & 1; - else header->version=2; - header->layer=(buffer[1] >> 1) & 3; + header->sync = (((int)buffer[0] << 4) | ((int)(buffer[1] & 0xE0) >> 4)); + if(buffer[1] & 0x10) + header->version = (buffer[1] >> 3) & 1; + else + header->version = 2; + header->layer = (buffer[1] >> 1) & 3; if((header->sync != 0xFFE) || (header->layer != 1)) { - header->sync=0; + header->sync = 0; return 0; } - header->crc=buffer[1] & 1; - header->bitrate=(buffer[2] >> 4) & 0x0F; - header->freq=(buffer[2] >> 2) & 0x3; - header->padding=(buffer[2] >>1) & 0x1; - header->extension=(buffer[2]) & 0x1; - header->mode=(buffer[3] >> 6) & 0x3; - header->mode_extension=(buffer[3] >> 4) & 0x3; - header->copyright=(buffer[3] >> 3) & 0x1; - header->original=(buffer[3] >> 2) & 0x1; - header->emphasis=(buffer[3]) & 0x3; + header->crc = buffer[1] & 1; + header->bitrate = (buffer[2] >> 4) & 0x0F; + header->freq = (buffer[2] >> 2) & 0x3; + header->padding = (buffer[2] >> 1) & 0x1; + header->extension = (buffer[2]) & 0x1; + header->mode = (buffer[3] >> 6) & 0x3; + header->mode_extension = (buffer[3] >> 4) & 0x3; + header->copyright = (buffer[3] >> 3) & 0x1; + header->original = (buffer[3] >> 2) & 0x1; + header->emphasis = (buffer[3]) & 0x3; - return ((fl=frame_length(header)) >= MIN_FRAME_SIZE ? fl : 0); + return ((fl = frame_length(header)) >= MIN_FRAME_SIZE ? fl : 0); } -int frame_length(mp3header *header) +int frame_length(mp3header * header) { - return header->sync == 0xFFE ? - (frame_size_index[3-header->layer]*((header->version&1)+1)* - header_bitrate(header)/header_frequency(header))+ - header->padding : 1; + return header->sync == 0xFFE ? (frame_size_index[3 - header->layer] * ((header->version & 1) + 1) * header_bitrate(header) / header_frequency(header)) + header->padding : 1; } -int header_layer(mp3header *h) +int header_layer(mp3header * h) { return layer_tab[h->layer]; } -int header_bitrate(mp3header *h) +int header_bitrate(mp3header * h) { if(h->bitrate > 0) - return bitrate[h->version & 1][3-h->layer][h->bitrate-1]; + return bitrate[h->version & 1][3 - h->layer][h->bitrate - 1]; else return -1; // unknown } -int header_frequency(mp3header *h) +int header_frequency(mp3header * h) { return frequencies[h->version][h->freq]; } -const char *header_emphasis(mp3header *h) +const char * header_emphasis(mp3header * h) { return emphasis_text[h->emphasis]; } -const char *header_mode(mp3header *h) +const char * header_mode(mp3header * h) { return mode_text[h->mode]; } @@ -355,58 +354,61 @@ int header_channels(mp3header * h) return h->mode == 3 ? 1 : 2; } -int header_crc(mp3header *h) +int header_crc(mp3header * h) { return (!h->crc); } -int sameConstant(mp3header *h1, mp3header *h2) +int sameConstant(mp3header * h1, mp3header * h2) { - if((*(uint*)h1) == (*(uint*)h2)) return 1; + if((*(uint *)h1) == (*(uint *)h2)) + return 1; - if((h1->version == h2->version ) && - (h1->layer == h2->layer ) && - (h1->crc == h2->crc ) && - (h1->freq == h2->freq ) && - (h1->mode == h2->mode ) && - (h1->copyright == h2->copyright ) && - (h1->original == h2->original ) && - (h1->emphasis == h2->emphasis )) + if((h1->version == h2->version) && (h1->layer == h2->layer) && (h1->crc == h2->crc) && (h1->freq == h2->freq) && (h1->mode == h2->mode) && (h1->copyright == h2->copyright) && (h1->original == h2->original) && (h1->emphasis == h2->emphasis)) return 1; - else return 0; + else + return 0; } -int get_id3(mp3info *mp3) +int get_id3(mp3info * mp3) { // this will read ID3v1 tags - int retcode=0; + int retcode = 0; char fbuf[4]; if(mp3->datasize >= 128) { - if(fseek(mp3->file, -128, SEEK_END )) + if(fseek(mp3->file, -128, SEEK_END)) { retcode |= 4; - } else { - size_t dummy = fread(fbuf,1,3,mp3->file); fbuf[3] = '\0'; + } + else + { + size_t dummy = fread(fbuf, 1, 3, mp3->file); + fbuf[3] = '\0'; Q_UNUSED(dummy); - mp3->id3.genre[0]=255; + mp3->id3.genre[0] = 255; - if(!strcmp((const char *)"TAG",(const char *)fbuf)) + if(!strcmp((const char *)"TAG", (const char *)fbuf)) { - mp3->id3_isvalid=1; + mp3->id3_isvalid = 1; mp3->datasize -= 128; fseek(mp3->file, -125, SEEK_END); - dummy = fread(mp3->id3.title,1,30,mp3->file); mp3->id3.title[30] = '\0'; - dummy = fread(mp3->id3.artist,1,30,mp3->file); mp3->id3.artist[30] = '\0'; - dummy = fread(mp3->id3.album,1,30,mp3->file); mp3->id3.album[30] = '\0'; - dummy = fread(mp3->id3.year,1,4,mp3->file); mp3->id3.year[4] = '\0'; - dummy = fread(mp3->id3.comment,1,30,mp3->file); mp3->id3.comment[30] = '\0'; + dummy = fread(mp3->id3.title, 1, 30, mp3->file); + mp3->id3.title[30] = '\0'; + dummy = fread(mp3->id3.artist, 1, 30, mp3->file); + mp3->id3.artist[30] = '\0'; + dummy = fread(mp3->id3.album, 1, 30, mp3->file); + mp3->id3.album[30] = '\0'; + dummy = fread(mp3->id3.year, 1, 4, mp3->file); + mp3->id3.year[4] = '\0'; + dummy = fread(mp3->id3.comment, 1, 30, mp3->file); + mp3->id3.comment[30] = '\0'; if(mp3->id3.comment[28] == '\0') { mp3->id3.track[0] = mp3->id3.comment[29]; } - dummy = fread(mp3->id3.genre,1,1,mp3->file); + dummy = fread(mp3->id3.genre, 1, 1, mp3->file); unpad(mp3->id3.title); unpad(mp3->id3.artist); unpad(mp3->id3.album); @@ -418,38 +420,39 @@ int get_id3(mp3info *mp3) return retcode; } -char *pad(char *string, int length) +char * pad(char * string, int length) { int l; - l=strlen(string); - while(l<length) + l = strlen(string); + while(l < length) { string[l] = ' '; l++; } - string[l]='\0'; + string[l] = '\0'; return string; } // Remove trailing whitespace from the end of a string -char *unpad(char *string) +char * unpad(char * string) { - char *pos=string+strlen(string)-1; - while(isspace(pos[0])) (pos--)[0]=0; + char * pos = string + strlen(string) - 1; + while(isspace(pos[0])) + (pos--)[0] = 0; return string; } -bool scan_mp3_file(QString&,mp3info * i) +bool scan_mp3_file(QString &, mp3info * i) { //memset(i,0,sizeof(mp3info)); resetmp3infoStruct(i); - i->filename = "text"; - i->file = fopen(QTextCodec::codecForLocale()->fromUnicode(i->filename).data(),"rb"); - if(!i->file)return false; + i->file = fopen(QTextCodec::codecForLocale()->fromUnicode(i->filename).data(), "rb"); + if(!i->file) + return false; get_mp3_info(i); diff --git a/src/modules/mediaplayer/MpMp3.h b/src/modules/mediaplayer/MpMp3.h index f9b88f0d6..6d534e625 100644 --- a/src/modules/mediaplayer/MpMp3.h +++ b/src/modules/mediaplayer/MpMp3.h @@ -43,9 +43,8 @@ #define FRAME_HEADER_SIZE 4 #define MIN_FRAME_SIZE 21 #define NUM_SAMPLES 4 -#define TEXT_FIELD_LEN 30 -#define INT_FIELD_LEN 4 - +#define TEXT_FIELD_LEN 30 +#define INT_FIELD_LEN 4 #include "kvi_settings.h" @@ -54,16 +53,21 @@ #include <QString> #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - #include <unistd.h> - #include <sys/stat.h> - #include <ctype.h> - #include <string.h> +#include <unistd.h> +#include <sys/stat.h> +#include <ctype.h> +#include <string.h> #endif +enum VBR_REPORT +{ + VBR_VARIABLE, + VBR_AVERAGE, + VBR_MEDIAN +}; -enum VBR_REPORT { VBR_VARIABLE, VBR_AVERAGE, VBR_MEDIAN }; - -typedef struct { +typedef struct +{ unsigned int sync; unsigned int version; unsigned int layer; @@ -79,7 +83,8 @@ typedef struct { unsigned int emphasis; } mp3header; -typedef struct { +typedef struct +{ char title[31]; char artist[31]; char album[31]; @@ -89,9 +94,10 @@ typedef struct { unsigned char genre[1]; } id3tag; -typedef struct { +typedef struct +{ QString filename; - FILE *file; + FILE * file; unsigned int datasize; int header_isvalid; mp3header header; @@ -110,25 +116,25 @@ typedef struct { // 10 - Dual channel (2 mono channels) // 11 - Single channel (Mono) -bool scan_mp3_file(QString& szFileName,mp3info * i); +bool scan_mp3_file(QString & szFileName, mp3info * i); -void resetmp3infoStruct(mp3info *i); +void resetmp3infoStruct(mp3info * i); -int header_channels(mp3header *h); -int header_frequency(mp3header *h); -const char *header_emphasis(mp3header *h); -const char *header_mode(mp3header *h); -int header_layer(mp3header *h); -int header_bitrate(mp3header *h); -double header_version(mp3header *h); -int header_crc(mp3header *h); -int get_header(FILE *file,mp3header *header); -int frame_length(mp3header *header); -int sameConstant(mp3header *h1, mp3header *h2); -int get_mp3_info(mp3info *mp3); -int get_id3(mp3info *mp3); -char *pad(char *string, int length); -char *unpad(char *string); -int get_first_header(mp3info *mp3,long startpos); +int header_channels(mp3header * h); +int header_frequency(mp3header * h); +const char * header_emphasis(mp3header * h); +const char * header_mode(mp3header * h); +int header_layer(mp3header * h); +int header_bitrate(mp3header * h); +double header_version(mp3header * h); +int header_crc(mp3header * h); +int get_header(FILE * file, mp3header * header); +int frame_length(mp3header * header); +int sameConstant(mp3header * h1, mp3header * h2); +int get_mp3_info(mp3info * mp3); +int get_id3(mp3info * mp3); +char * pad(char * string, int length); +char * unpad(char * string); +int get_first_header(mp3info * mp3, long startpos); //void tagedit_curs(char *filename, int filenum, int fileoutof, id3tag *tag); const char * get_typegenre(int idx); diff --git a/src/modules/mediaplayer/MpMprisInterface.cpp b/src/modules/mediaplayer/MpMprisInterface.cpp index 6c40d47ec..30367487f 100644 --- a/src/modules/mediaplayer/MpMprisInterface.cpp +++ b/src/modules/mediaplayer/MpMprisInterface.cpp @@ -23,7 +23,7 @@ //============================================================================= #include "MpMprisInterface.h" -#if (defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) +#if(defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) #include "KviLocale.h" /* @@ -42,9 +42,9 @@ struct MPRISPlayerStatus int RepeatCurrent; int RepeatPlaylist; }; -Q_DECLARE_METATYPE( MPRISPlayerStatus ) +Q_DECLARE_METATYPE(MPRISPlayerStatus) -QDBusArgument &operator<<(QDBusArgument &argument, const MPRISPlayerStatus &status) +QDBusArgument & operator<<(QDBusArgument & argument, const MPRISPlayerStatus & status) { argument.beginStructure(); argument << status.Play << status.Random << status.RepeatCurrent << status.RepeatPlaylist; @@ -52,7 +52,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const MPRISPlayerStatus &stat return argument; } -const QDBusArgument &operator>>(const QDBusArgument &argument, MPRISPlayerStatus &status) +const QDBusArgument & operator>>(const QDBusArgument & argument, MPRISPlayerStatus & status) { argument.beginStructure(); argument >> status.Play >> status.Random >> status.RepeatCurrent >> status.RepeatPlaylist; @@ -61,7 +61,7 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, MPRISPlayerStatus } MpMprisInterface::MpMprisInterface() -: MpInterface() + : MpInterface() { qDBusRegisterMetaType<MPRISPlayerStatus>(); } @@ -73,25 +73,26 @@ MpMprisInterface::~MpMprisInterface() int MpMprisInterface::detect(bool) { QDBusReply<QStringList> reply = QDBusConnection::sessionBus().interface()->registeredServiceNames(); - if (!reply.isValid()) /* something fishy with dbus, it won't work */ + if(!reply.isValid()) /* something fishy with dbus, it won't work */ return 0; - foreach (QString name, reply.value()) - if (name == m_szServiceName) /* player is running */ + foreach(QString name, reply.value()) + if(name == m_szServiceName) /* player is running */ return 100; - return 1; /* dbus works, player may be closed */ + return 1; /* dbus works, player may be closed */ } -#define MPRIS_SIMPLE_CALL(__path, __action) \ - QDBusInterface dbus_iface(m_szServiceName, __path, \ - "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ - QDBusMessage reply = dbus_iface.call(QDBus::Block, __action); \ - if (reply.type() == QDBusMessage::ErrorMessage) { \ - QDBusError err = reply; \ +#define MPRIS_SIMPLE_CALL(__path, __action) \ + QDBusInterface dbus_iface(m_szServiceName, __path, \ + "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ + QDBusMessage reply = dbus_iface.call(QDBus::Block, __action); \ + if(reply.type() == QDBusMessage::ErrorMessage) \ + { \ + QDBusError err = reply; \ qDebug("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); \ - return false; \ - } \ + return false; \ + } \ return true; bool MpMprisInterface::prev() @@ -124,42 +125,47 @@ bool MpMprisInterface::quit() MPRIS_SIMPLE_CALL("/", "Quit") } -#define MPRIS_CALL_METHOD(__method, __return_if_fail) \ - QDBusInterface dbus_iface(m_szServiceName, "/Player", \ - "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ - QDBusMessage reply = dbus_iface.call(QDBus::Block, __method); \ - if (reply.type() == QDBusMessage::ErrorMessage) { \ - QDBusError err = reply; \ +#define MPRIS_CALL_METHOD(__method, __return_if_fail) \ + QDBusInterface dbus_iface(m_szServiceName, "/Player", \ + "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ + QDBusMessage reply = dbus_iface.call(QDBus::Block, __method); \ + if(reply.type() == QDBusMessage::ErrorMessage) \ + { \ + QDBusError err = reply; \ qDebug("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); \ - return __return_if_fail; \ + return __return_if_fail; \ } #define MPRIS_GET_METADATA_FIELD(__field, __return_type, __return_if_fail) \ - if (this->status() != MpInterface::Playing) \ - return __return_if_fail; \ - MPRIS_CALL_METHOD("GetMetadata", __return_if_fail) \ - foreach (QVariant w, reply.arguments()) { \ - QDBusArgument arg = qvariant_cast<QDBusArgument>(w); \ - QVariant v = qdbus_cast<QVariantMap>(arg); \ - if (v.userType() == QVariant::Map) { \ - const QVariantMap map = v.toMap(); \ - QVariantMap::ConstIterator it = map.find(__field); \ - if (it != map.end() && it.key() == __field) { \ - return it.value().value< __return_type >(); \ - } \ - } \ - } \ + if(this->status() != MpInterface::Playing) \ + return __return_if_fail; \ + MPRIS_CALL_METHOD("GetMetadata", __return_if_fail) \ + foreach(QVariant w, reply.arguments()) \ + { \ + QDBusArgument arg = qvariant_cast<QDBusArgument>(w); \ + QVariant v = qdbus_cast<QVariantMap>(arg); \ + if(v.userType() == QVariant::Map) \ + { \ + const QVariantMap map = v.toMap(); \ + QVariantMap::ConstIterator it = map.find(__field); \ + if(it != map.end() && it.key() == __field) \ + { \ + return it.value().value<__return_type>(); \ + } \ + } \ + } \ return __return_if_fail; -#define MPRIS_CALL_METHOD_WITH_ARG(__method, __arg, __return_if_fail) \ - QDBusInterface dbus_iface(m_szServiceName, "/Player", \ - "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ - QDBusMessage reply = dbus_iface.call(QDBus::Block, __method, __arg); \ - if (reply.type() == QDBusMessage::ErrorMessage) { \ - QDBusError err = reply; \ - qDebug("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); \ - return __return_if_fail; \ - } +#define MPRIS_CALL_METHOD_WITH_ARG(__method, __arg, __return_if_fail) \ + QDBusInterface dbus_iface(m_szServiceName, "/Player", \ + "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); \ + QDBusMessage reply = dbus_iface.call(QDBus::Block, __method, __arg); \ + if(reply.type() == QDBusMessage::ErrorMessage) \ + { \ + QDBusError err = reply; \ + qDebug("Error: %s\n%s\n", qPrintable(err.name()), qPrintable(err.message())); \ + return __return_if_fail; \ + } MpInterface::PlayerStatus MpMprisInterface::status() { @@ -172,38 +178,46 @@ MpInterface::PlayerStatus MpMprisInterface::status() status = qdbus_cast<MPRISPlayerStatus>(reply.arguments().first()); - switch (status.Play) { - case 0: return MpInterface::Playing; - case 1: return MpInterface::Paused; - case 2: return MpInterface::Stopped; - default: return MpInterface::Unknown; + switch(status.Play) + { + case 0: + return MpInterface::Playing; + case 1: + return MpInterface::Paused; + case 2: + return MpInterface::Stopped; + default: + return MpInterface::Unknown; } } QString MpMprisInterface::nowPlaying() { - if (this->status() != MpInterface::Playing) + if(this->status() != MpInterface::Playing) return ""; MPRIS_CALL_METHOD("GetMetadata", "") QString artist; QString title; - foreach (QVariant w, reply.arguments()) { + foreach(QVariant w, reply.arguments()) + { QDBusArgument arg = qvariant_cast<QDBusArgument>(w); QVariant v = qdbus_cast<QVariantMap>(arg); - if (v.userType() == QVariant::Map) { - const QVariantMap map = v.toMap(); - QVariantMap::ConstIterator it = map.constBegin(); - for ( ; it != map.constEnd(); ++it) { /* maybe do some configurable formatting */ - if (it.key() == "artist") + if(v.userType() == QVariant::Map) + { + const QVariantMap map = v.toMap(); + QVariantMap::ConstIterator it = map.constBegin(); + for(; it != map.constEnd(); ++it) + { /* maybe do some configurable formatting */ + if(it.key() == "artist") artist = it.value().toString(); - else if (it.key() == "title") + else if(it.key() == "title") title = it.value().toString(); } } } - if (artist.length() && title.length()) + if(artist.length() && title.length()) return artist + " - " + title; else return ""; @@ -213,13 +227,16 @@ QString MpMprisInterface::mrl() { MPRIS_CALL_METHOD("GetMetadata", "") - foreach (QVariant w, reply.arguments()) { + foreach(QVariant w, reply.arguments()) + { QDBusArgument arg = qvariant_cast<QDBusArgument>(w); QVariant v = qdbus_cast<QVariantMap>(arg); - if (v.userType() == QVariant::Map) { - const QVariantMap map = v.toMap(); - QVariantMap::ConstIterator it = map.find("location"); - if (it != map.end() && it.key() == "location") { + if(v.userType() == QVariant::Map) + { + const QVariantMap map = v.toMap(); + QVariantMap::ConstIterator it = map.find("location"); + if(it != map.end() && it.key() == "location") + { return it.value().toString(); } } @@ -267,9 +284,9 @@ int MpMprisInterface::sampleRate() MPRIS_GET_METADATA_FIELD("audio-samplerate", int, -1) } -bool MpMprisInterface::setVol(kvs_int_t &iVol) +bool MpMprisInterface::setVol(kvs_int_t & iVol) { - MPRIS_CALL_METHOD_WITH_ARG("VolumeSet", QVariant((int)(100*iVol/255)), false); + MPRIS_CALL_METHOD_WITH_ARG("VolumeSet", QVariant((int)(100 * iVol / 255)), false); return true; } @@ -278,7 +295,7 @@ int MpMprisInterface::getVol() MPRIS_CALL_METHOD("VolumeGet", -1) int iVol = reply.arguments().first().toInt(); - return iVol * 255 /100; + return iVol * 255 / 100; } int MpMprisInterface::position() @@ -291,14 +308,17 @@ int MpMprisInterface::length() { MPRIS_CALL_METHOD("GetMetadata", -1) - foreach (QVariant w, reply.arguments()) { + foreach(QVariant w, reply.arguments()) + { QDBusArgument arg = qvariant_cast<QDBusArgument>(w); QVariant v = qdbus_cast<QVariantMap>(arg); - if (v.userType() == QVariant::Map) { - const QVariantMap map = v.toMap(); - QVariantMap::ConstIterator it = map.constBegin(); - for ( ; it != map.constEnd(); ++it) { - if (it.key() == "mtime") + if(v.userType() == QVariant::Map) + { + const QVariantMap map = v.toMap(); + QVariantMap::ConstIterator it = map.constBegin(); + for(; it != map.constEnd(); ++it) + { + if(it.key() == "mtime") return it.value().toInt(); } } @@ -306,7 +326,7 @@ int MpMprisInterface::length() return -1; } -bool MpMprisInterface::jumpTo(kvs_int_t &iPos) +bool MpMprisInterface::jumpTo(kvs_int_t & iPos) { MPRIS_CALL_METHOD_WITH_ARG("PositionSet", QVariant((int)iPos), false) return true; @@ -314,18 +334,15 @@ bool MpMprisInterface::jumpTo(kvs_int_t &iPos) /* audacious interface */ MP_IMPLEMENT_DESCRIPTOR( - MpAudaciousInterface, - "audacious", - __tr2qs_ctx( - "An interface for the Audacious media player.\n" \ - "Download it from http://audacious-media-player.org\n" - , - "mediaplayer" - ) -) + MpAudaciousInterface, + "audacious", + __tr2qs_ctx( + "An interface for the Audacious media player.\n" + "Download it from http://audacious-media-player.org\n", + "mediaplayer")) MpAudaciousInterface::MpAudaciousInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.audacious"; } @@ -333,15 +350,14 @@ MpAudaciousInterface::MpAudaciousInterface() int MpAudaciousInterface::getPlayListPos() { QDBusInterface dbus_iface("org.mpris.audacious", "/org/atheme/audacious", - "org.atheme.audacious", QDBusConnection::sessionBus()); + "org.atheme.audacious", QDBusConnection::sessionBus()); QDBusReply<uint> pos = dbus_iface.call(QDBus::Block, "Position"); return pos; } - bool MpAudaciousInterface::quit() { - if (MpMprisInterface::quit()) + if(MpMprisInterface::quit()) return true; /* compatibility with older versions */ @@ -352,20 +368,24 @@ QString MpAudaciousInterface::mrl() { MPRIS_CALL_METHOD("GetMetadata", "") - foreach (QVariant w, reply.arguments()) { + foreach(QVariant w, reply.arguments()) + { QDBusArgument arg = qvariant_cast<QDBusArgument>(w); QVariant v = qdbus_cast<QVariantMap>(arg); - if (v.userType() == QVariant::Map) { - const QVariantMap map = v.toMap(); - QVariantMap::ConstIterator it = map.find("location"); - if (it != map.end() && it.key() == "location") { + if(v.userType() == QVariant::Map) + { + const QVariantMap map = v.toMap(); + QVariantMap::ConstIterator it = map.find("location"); + if(it != map.end() && it.key() == "location") + { return it.value().toString(); } /* Some audacious versions send URI instead of location */ it = map.find("URI"); - if (it != map.end() && it.key() == "URI") { - return it.value().toString(); - } + if(it != map.end() && it.key() == "URI") + { + return it.value().toString(); + } } } return ""; @@ -375,42 +395,50 @@ MpInterface::PlayerStatus MpAudaciousInterface::status() { MpInterface::PlayerStatus status; status = MpMprisInterface::status(); - if (status != MpInterface::Unknown) + if(status != MpInterface::Unknown) return status; /* compatibility with older versions */ QDBusInterface dbus_iface(m_szServiceName, "/Player", - "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); - if (!dbus_iface.isValid()) + "org.freedesktop.MediaPlayer", QDBusConnection::sessionBus()); + if(!dbus_iface.isValid()) return MpInterface::Unknown; QDBusMessage reply = dbus_iface.call(QDBus::Block, "GetStatus"); - switch (reply.arguments().first().toInt()) { - case 0: return MpInterface::Playing; - case 1: return MpInterface::Paused; - case 2: return MpInterface::Stopped; - default: return MpInterface::Unknown; + switch(reply.arguments().first().toInt()) + { + case 0: + return MpInterface::Playing; + case 1: + return MpInterface::Paused; + case 2: + return MpInterface::Stopped; + default: + return MpInterface::Unknown; } } int MpAudaciousInterface::length() { int length = MpMprisInterface::length(); - if (length != -1) + if(length != -1) return length; /* compatibility with older versions */ MPRIS_CALL_METHOD("GetMetadata", -1) - foreach (QVariant w, reply.arguments()) { + foreach(QVariant w, reply.arguments()) + { QDBusArgument arg = qvariant_cast<QDBusArgument>(w); QVariant v = qdbus_cast<QVariantMap>(arg); - if (v.userType() == QVariant::Map) { - const QVariantMap map = v.toMap(); - QVariantMap::ConstIterator it = map.constBegin(); - for ( ; it != map.constEnd(); ++it) { - if (it.key() == "length") + if(v.userType() == QVariant::Map) + { + const QVariantMap map = v.toMap(); + QVariantMap::ConstIterator it = map.constBegin(); + for(; it != map.constEnd(); ++it) + { + if(it.key() == "length") return it.value().toInt(); } } @@ -418,15 +446,15 @@ int MpAudaciousInterface::length() return -1; } -#define AUDACIOUS_GET_TUPLE_FIELD(__field) \ - if (this->status() != MpInterface::Playing) \ - return ""; \ - QDBusInterface dbus_iface("org.mpris.audacious", "/org/atheme/audacious", \ - "org.atheme.audacious", QDBusConnection::sessionBus()); \ - QList<QVariant> args; \ - args << (uint)this->getPlayListPos() << QString(__field); \ +#define AUDACIOUS_GET_TUPLE_FIELD(__field) \ + if(this->status() != MpInterface::Playing) \ + return ""; \ + QDBusInterface dbus_iface("org.mpris.audacious", "/org/atheme/audacious", \ + "org.atheme.audacious", QDBusConnection::sessionBus()); \ + QList<QVariant> args; \ + args << (uint) this->getPlayListPos() << QString(__field); \ QDBusReply<QDBusVariant> reply = dbus_iface.callWithArgumentList(QDBus::Block, "SongTuple", args); \ - return reply.value().variant().toString(); \ + return reply.value().variant().toString(); QString MpAudaciousInterface::year() { @@ -440,18 +468,15 @@ QString MpAudaciousInterface::mediaType() /* BMPx interface */ MP_IMPLEMENT_DESCRIPTOR( - MpBmpxInterface, - "bmpx", - __tr2qs_ctx( - "An interface for BMPx.\n" \ - "Download it from http://sourceforge.net/projects/beepmp\n" - , - "mediaplayer" - ) -) + MpBmpxInterface, + "bmpx", + __tr2qs_ctx( + "An interface for BMPx.\n" + "Download it from http://sourceforge.net/projects/beepmp\n", + "mediaplayer")) MpBmpxInterface::MpBmpxInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.bmp"; } @@ -464,72 +489,62 @@ MpInterface::PlayerStatus MpBmpxInterface::status() /* Amarok2 interface */ MP_IMPLEMENT_DESCRIPTOR( - MpAmarok2Interface, - "amarok2", - __tr2qs_ctx( - "An interface for Amarok2.\n" \ - "Download it from http://amarok.kde.org\n" - , - "mediaplayer" - ) -) + MpAmarok2Interface, + "amarok2", + __tr2qs_ctx( + "An interface for Amarok2.\n" + "Download it from http://amarok.kde.org\n", + "mediaplayer")) MpAmarok2Interface::MpAmarok2Interface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.amarok"; } /* Qmmp interface */ MP_IMPLEMENT_DESCRIPTOR( - MpQmmpInterface, - "Qmmp", - __tr2qs_ctx( - "An interface for Qmmp.\n" \ - "Download it from http://qmmp.ylsoftware.com\n" - , - "mediaplayer" - ) -) + MpQmmpInterface, + "Qmmp", + __tr2qs_ctx( + "An interface for Qmmp.\n" + "Download it from http://qmmp.ylsoftware.com\n", + "mediaplayer")) MpQmmpInterface::MpQmmpInterface() -: MpMprisInterface() + : MpMprisInterface() { - m_szServiceName = "org.mpris.qmmp"; + m_szServiceName = "org.mpris.qmmp"; } /* xmms2 interface */ MP_IMPLEMENT_DESCRIPTOR( - MpXmms2Interface, - "xmms2", - __tr2qs_ctx( - "An interface for the XMMS2 media player.\n" \ - "Download it from http://xmms2.org\n", - "mediaplayer" - ) -) + MpXmms2Interface, + "xmms2", + __tr2qs_ctx( + "An interface for the XMMS2 media player.\n" + "Download it from http://xmms2.org\n", + "mediaplayer")) MpXmms2Interface::MpXmms2Interface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.xmms2"; } /* mozilla songbird interface */ MP_IMPLEMENT_DESCRIPTOR( - MpSongbirdInterface, - "songbird", - __tr2qs_ctx( - "An interface for the Mozilla Songbird media player.\n" \ - "Download it from http://www.getsongbird.com.\n" \ - "To use it you have to install also the MPRIS addon " \ - "available at http://addons.songbirdnest.com/addon/1626.\n", - "mediaplayer" - ) -) + MpSongbirdInterface, + "songbird", + __tr2qs_ctx( + "An interface for the Mozilla Songbird media player.\n" + "Download it from http://www.getsongbird.com.\n" + "To use it you have to install also the MPRIS addon " + "available at http://addons.songbirdnest.com/addon/1626.\n", + "mediaplayer")) MpSongbirdInterface::MpSongbirdInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.songbird"; } @@ -541,56 +556,47 @@ MpInterface::PlayerStatus MpSongbirdInterface::status() /* Totem interface */ MP_IMPLEMENT_DESCRIPTOR( - MpTotemInterface, - "totem", - __tr2qs_ctx( - "An interface for Totem.\n" \ - "Download it from http://projects.gnome.org/totem/\n" - , - "mediaplayer" - ) -) + MpTotemInterface, + "totem", + __tr2qs_ctx( + "An interface for Totem.\n" + "Download it from http://projects.gnome.org/totem/\n", + "mediaplayer")) MpTotemInterface::MpTotemInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.Totem"; } /* Vlc interface */ MP_IMPLEMENT_DESCRIPTOR( - MpVlcInterface, - "vlc", - __tr2qs_ctx( - "An interface for VLC.\n" \ - "Download it from http://www.videolan.org/\n" \ - "You need to manually enable the D-Bus control\n" \ - "interface in the VLC preferences\n" \ - , - "mediaplayer" - ) -) + MpVlcInterface, + "vlc", + __tr2qs_ctx( + "An interface for VLC.\n" + "Download it from http://www.videolan.org/\n" + "You need to manually enable the D-Bus control\n" + "interface in the VLC preferences\n", + "mediaplayer")) MpVlcInterface::MpVlcInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.vlc"; } /* Clementine interface */ MP_IMPLEMENT_DESCRIPTOR( - MpClementineInterface, - "clementine", - __tr2qs_ctx( - "An interface for Clementine.\n" \ - "Download it from http://www.clementine-player.org/\n" \ - , - "mediaplayer" - ) -) + MpClementineInterface, + "clementine", + __tr2qs_ctx( + "An interface for Clementine.\n" + "Download it from http://www.clementine-player.org/\n", + "mediaplayer")) MpClementineInterface::MpClementineInterface() -: MpMprisInterface() + : MpMprisInterface() { m_szServiceName = "org.mpris.clementine"; } diff --git a/src/modules/mediaplayer/MpMprisInterface.h b/src/modules/mediaplayer/MpMprisInterface.h index 480fd01e1..b73ccf37d 100644 --- a/src/modules/mediaplayer/MpMprisInterface.h +++ b/src/modules/mediaplayer/MpMprisInterface.h @@ -28,115 +28,117 @@ #include "kvi_settings.h" -#if (defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) - #include <QtDBus/QtDBus> +#if(defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) +#include <QtDBus/QtDBus> - class MpMprisInterface : public MpInterface - { - public: - MpMprisInterface(); - virtual ~MpMprisInterface(); - public: - QString m_szServiceName; - virtual int detect(bool bStart); - virtual bool prev(); - virtual bool next(); - virtual bool play(); - virtual bool stop(); - virtual bool pause(); - virtual bool quit(); - virtual MpInterface::PlayerStatus status(); - virtual QString nowPlaying(); - virtual QString mrl(); - virtual QString title(); - virtual QString artist(); - virtual QString genre(); - virtual QString comment(); - virtual QString year(); - virtual QString album(); - virtual int bitRate(); - virtual int sampleRate(); - virtual bool setVol(kvs_int_t &iVol); - virtual int getVol(); - virtual int position(); - virtual int length(); - virtual bool jumpTo(kvs_int_t &iPos); - }; +class MpMprisInterface : public MpInterface +{ +public: + MpMprisInterface(); + virtual ~MpMprisInterface(); - class MpAudaciousInterface : public MpMprisInterface - { - public: - MpAudaciousInterface(); - public: - virtual bool quit(); - virtual MpInterface::PlayerStatus status(); - virtual QString mrl(); - virtual int length(); +public: + QString m_szServiceName; + virtual int detect(bool bStart); + virtual bool prev(); + virtual bool next(); + virtual bool play(); + virtual bool stop(); + virtual bool pause(); + virtual bool quit(); + virtual MpInterface::PlayerStatus status(); + virtual QString nowPlaying(); + virtual QString mrl(); + virtual QString title(); + virtual QString artist(); + virtual QString genre(); + virtual QString comment(); + virtual QString year(); + virtual QString album(); + virtual int bitRate(); + virtual int sampleRate(); + virtual bool setVol(kvs_int_t & iVol); + virtual int getVol(); + virtual int position(); + virtual int length(); + virtual bool jumpTo(kvs_int_t & iPos); +}; - virtual int getPlayListPos(); - virtual QString year(); - virtual QString mediaType(); - }; +class MpAudaciousInterface : public MpMprisInterface +{ +public: + MpAudaciousInterface(); - class MpBmpxInterface : public MpMprisInterface - { - public: - MpBmpxInterface(); - virtual MpInterface::PlayerStatus status(); - }; +public: + virtual bool quit(); + virtual MpInterface::PlayerStatus status(); + virtual QString mrl(); + virtual int length(); - class MpAmarok2Interface : public MpMprisInterface - { - public: - MpAmarok2Interface(); - }; + virtual int getPlayListPos(); + virtual QString year(); + virtual QString mediaType(); +}; - class MpQmmpInterface : public MpMprisInterface - { - public: - MpQmmpInterface(); - }; +class MpBmpxInterface : public MpMprisInterface +{ +public: + MpBmpxInterface(); + virtual MpInterface::PlayerStatus status(); +}; - class MpXmms2Interface : public MpMprisInterface - { - public: - MpXmms2Interface(); - }; +class MpAmarok2Interface : public MpMprisInterface +{ +public: + MpAmarok2Interface(); +}; - class MpSongbirdInterface : public MpMprisInterface - { - public: - MpSongbirdInterface(); - virtual MpInterface::PlayerStatus status(); - }; +class MpQmmpInterface : public MpMprisInterface +{ +public: + MpQmmpInterface(); +}; - class MpTotemInterface : public MpMprisInterface - { - public: - MpTotemInterface(); - }; +class MpXmms2Interface : public MpMprisInterface +{ +public: + MpXmms2Interface(); +}; - class MpVlcInterface : public MpMprisInterface - { - public: - MpVlcInterface(); - }; +class MpSongbirdInterface : public MpMprisInterface +{ +public: + MpSongbirdInterface(); + virtual MpInterface::PlayerStatus status(); +}; - class MpClementineInterface : public MpMprisInterface - { - public: - MpClementineInterface(); - }; +class MpTotemInterface : public MpMprisInterface +{ +public: + MpTotemInterface(); +}; - MP_DECLARE_DESCRIPTOR(MpAudaciousInterface) - MP_DECLARE_DESCRIPTOR(MpBmpxInterface) - MP_DECLARE_DESCRIPTOR(MpAmarok2Interface) - MP_DECLARE_DESCRIPTOR(MpQmmpInterface) - MP_DECLARE_DESCRIPTOR(MpXmms2Interface) - MP_DECLARE_DESCRIPTOR(MpSongbirdInterface) - MP_DECLARE_DESCRIPTOR(MpTotemInterface) - MP_DECLARE_DESCRIPTOR(MpVlcInterface) - MP_DECLARE_DESCRIPTOR(MpClementineInterface) +class MpVlcInterface : public MpMprisInterface +{ +public: + MpVlcInterface(); +}; + +class MpClementineInterface : public MpMprisInterface +{ +public: + MpClementineInterface(); +}; + +MP_DECLARE_DESCRIPTOR(MpAudaciousInterface) +MP_DECLARE_DESCRIPTOR(MpBmpxInterface) +MP_DECLARE_DESCRIPTOR(MpAmarok2Interface) +MP_DECLARE_DESCRIPTOR(MpQmmpInterface) +MP_DECLARE_DESCRIPTOR(MpXmms2Interface) +MP_DECLARE_DESCRIPTOR(MpSongbirdInterface) +MP_DECLARE_DESCRIPTOR(MpTotemInterface) +MP_DECLARE_DESCRIPTOR(MpVlcInterface) +MP_DECLARE_DESCRIPTOR(MpClementineInterface) #endif //COMPILE_ON_WINDOWS #endif //_MP_AUDACIOUSINTERFACE_H_ diff --git a/src/modules/mediaplayer/MpWinampInterface.cpp b/src/modules/mediaplayer/MpWinampInterface.cpp index 08666c864..88846bf01 100644 --- a/src/modules/mediaplayer/MpWinampInterface.cpp +++ b/src/modules/mediaplayer/MpWinampInterface.cpp @@ -163,7 +163,6 @@ #define KVIRC_WM_USER_GETFILE 10000 #define KVIRC_WM_USER_TRANSFER 15000 - static QTextCodec * mediaplayer_get_codec() { QTextCodec * pCodec = 0; @@ -176,34 +175,29 @@ static QTextCodec * mediaplayer_get_codec() static HWND find_winamp(KviWinampInterface * i) { - HWND hWnd = FindWindow("Winamp v1.x",NULL); + HWND hWnd = FindWindow("Winamp v1.x", NULL); if(!hWnd) { // try to start the process ? - i->setLastError(__tr2qs_ctx("Can't find a running Winamp window","mediaplayer")); + i->setLastError(__tr2qs_ctx("Can't find a running Winamp window", "mediaplayer")); } return hWnd; } - MP_IMPLEMENT_DESCRIPTOR( - KviWinampInterface, - "winamp", - __tr2qs_ctx( - "An interface for the Winamp media player.\n" \ - "You can download it from http://www.winamp.com.\n" \ - "To use all the features of this interface you must " \ - "copy the gen_kvirc.dll plugin found in the KVIrc " \ - "distribution directory to the Winamp plugins folder " \ - "and restart winamp." - , - "mediaplayer" - ) -) - + KviWinampInterface, + "winamp", + __tr2qs_ctx( + "An interface for the Winamp media player.\n" + "You can download it from http://www.winamp.com.\n" + "To use all the features of this interface you must " + "copy the gen_kvirc.dll plugin found in the KVIrc " + "distribution directory to the Winamp plugins folder " + "and restart winamp.", + "mediaplayer")) KviWinampInterface::KviWinampInterface() -: MpInterface() + : MpInterface() { } @@ -211,39 +205,40 @@ KviWinampInterface::~KviWinampInterface() { } - int KviWinampInterface::detect(bool bStart) { - if(find_winamp(this))return 80; + if(find_winamp(this)) + return 80; // FIXME : check for Programs Folder\Winamp\Winamp.exe ? // FIXME : if bStart try to start winamp.exe ? return 50; } -#define MP_WINAMP_SENDMESSAGE(__cmdname,__wmmsg,__lparam,__wparam) \ - bool KviWinampInterface::__cmdname() \ - { \ - HWND hWinamp = find_winamp(this); \ - if(hWinamp)SendMessage(hWinamp,__wmmsg,__lparam,__wparam); \ - return hWinamp != 0; \ +#define MP_WINAMP_SENDMESSAGE(__cmdname, __wmmsg, __lparam, __wparam) \ + bool KviWinampInterface::__cmdname() \ + { \ + HWND hWinamp = find_winamp(this); \ + if(hWinamp) \ + SendMessage(hWinamp, __wmmsg, __lparam, __wparam); \ + return hWinamp != 0; \ } -#define MP_WINAMP_WM_USER(__cmdname,_ipcmsg) MP_WINAMP_SENDMESSAGE(__cmdname,WM_USER,0,_ipcmsg) -#define MP_WINAMP_WM_COMMAND(__cmdname,_cmdmsg) MP_WINAMP_SENDMESSAGE(__cmdname,WM_COMMAND,_cmdmsg,0) - -MP_WINAMP_WM_USER(play,IPC_STARTPLAY) -MP_WINAMP_WM_COMMAND(stop,WINAMP_CMD_STOP) -MP_WINAMP_WM_COMMAND(next,WINAMP_CMD_NEXT) -MP_WINAMP_WM_COMMAND(prev,WINAMP_CMD_PREV) -MP_WINAMP_WM_COMMAND(pause,WINAMP_CMD_PAUSE) -MP_WINAMP_WM_COMMAND(quit,WINAMP_CMD_QUIT) +#define MP_WINAMP_WM_USER(__cmdname, _ipcmsg) MP_WINAMP_SENDMESSAGE(__cmdname, WM_USER, 0, _ipcmsg) +#define MP_WINAMP_WM_COMMAND(__cmdname, _cmdmsg) MP_WINAMP_SENDMESSAGE(__cmdname, WM_COMMAND, _cmdmsg, 0) +MP_WINAMP_WM_USER(play, IPC_STARTPLAY) +MP_WINAMP_WM_COMMAND(stop, WINAMP_CMD_STOP) +MP_WINAMP_WM_COMMAND(next, WINAMP_CMD_NEXT) +MP_WINAMP_WM_COMMAND(prev, WINAMP_CMD_PREV) +MP_WINAMP_WM_COMMAND(pause, WINAMP_CMD_PAUSE) +MP_WINAMP_WM_COMMAND(quit, WINAMP_CMD_QUIT) int KviWinampInterface::length() { int leninsecs = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)leninsecs = SendMessage(hWinamp,WM_USER,1,IPC_GETOUTPUTTIME); + if(hWinamp) + leninsecs = SendMessage(hWinamp, WM_USER, 1, IPC_GETOUTPUTTIME); return leninsecs * 1000; } @@ -251,7 +246,8 @@ int KviWinampInterface::position() { int leninmsecs = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)leninmsecs = SendMessage(hWinamp,WM_USER,0,IPC_GETOUTPUTTIME); + if(hWinamp) + leninmsecs = SendMessage(hWinamp, WM_USER, 0, IPC_GETOUTPUTTIME); return leninmsecs; } @@ -259,7 +255,8 @@ int KviWinampInterface::bitRate() { int ret = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,1,IPC_GETINFO); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 1, IPC_GETINFO); return ret; } @@ -267,7 +264,8 @@ int KviWinampInterface::sampleRate() { int ret = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,0,IPC_GETINFO); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 0, IPC_GETINFO); return ret; } @@ -275,7 +273,8 @@ int KviWinampInterface::channels() { int ret = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,2,IPC_GETINFO); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 2, IPC_GETINFO); return ret; } @@ -283,21 +282,22 @@ MpInterface::PlayerStatus KviWinampInterface::status() { HWND hWinamp = find_winamp(this); int ret = 1000; - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,0,IPC_ISPLAYING); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 0, IPC_ISPLAYING); switch(ret) { case 0: return MpInterface::Stopped; - break; + break; case 3: return MpInterface::Paused; - break; + break; case 1: return MpInterface::Playing; - break; + break; default: return MpInterface::Unknown; - break; + break; } return MpInterface::Unknown; } @@ -308,29 +308,31 @@ QString KviWinampInterface::mrl() HWND hWinamp = find_winamp(this); if(hWinamp) { - int ret2 = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_CHECK); + int ret2 = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_CHECK); if(ret2 != KVIRC_WM_USER_CHECK_REPLY) { - setLastError(__tr2qs_ctx("The Winamp plugin has not been installed properly. Check /help mediaplayer.nowplaying","mediaplayer")); + setLastError(__tr2qs_ctx("The Winamp plugin has not been installed properly. Check /help mediaplayer.nowplaying", "mediaplayer")); return ret; } - int len = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_GETFILE); + int len = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_GETFILE); if(len < 4096) { char szBuffer[4096]; - for(int i = 0;i < len;i++) + for(int i = 0; i < len; i++) { - szBuffer[i] = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_TRANSFER + i); + szBuffer[i] = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_TRANSFER + i); } szBuffer[len] = '\0'; - QTextCodec *c=mediaplayer_get_codec(); - if (c) ret = c->toUnicode(szBuffer); - else ret=szBuffer; - if(!ret.startsWith("http://",Qt::CaseInsensitive)) + QTextCodec * c = mediaplayer_get_codec(); + if(c) + ret = c->toUnicode(szBuffer); + else + ret = szBuffer; + if(!ret.startsWith("http://", Qt::CaseInsensitive)) ret.prepend("file://"); } } @@ -343,56 +345,58 @@ QString KviWinampInterface::nowPlaying() HWND hWinamp = find_winamp(this); if(hWinamp) { - int retpippo = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_CHECK); + int retpippo = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_CHECK); if(retpippo != KVIRC_WM_USER_CHECK_REPLY) { - setLastError(__tr2qs_ctx("The Winamp plugin has not been installed properly. Check /help mediaplayer.nowplaying","mediaplayer") ); + setLastError(__tr2qs_ctx("The Winamp plugin has not been installed properly. Check /help mediaplayer.nowplaying", "mediaplayer")); return ret; } - int len = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_GETTITLE); + int len = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_GETTITLE); if(len < 4096) { char szBuffer[4096]; - for(int i = 0;i < len;i++) + for(int i = 0; i < len; i++) { - szBuffer[i] = SendMessage(hWinamp,WM_USER,KVIRC_WM_USER,KVIRC_WM_USER_TRANSFER + i); + szBuffer[i] = SendMessage(hWinamp, WM_USER, KVIRC_WM_USER, KVIRC_WM_USER_TRANSFER + i); } - szBuffer[ len ] = '\0'; + szBuffer[len] = '\0'; - QTextCodec *c=mediaplayer_get_codec(); - if (c) ret = c->toUnicode(szBuffer); - else ret=szBuffer; + QTextCodec * c = mediaplayer_get_codec(); + if(c) + ret = c->toUnicode(szBuffer); + else + ret = szBuffer; } } return ret; } -bool KviWinampInterface::playMrl(const QString &mrl) +bool KviWinampInterface::playMrl(const QString & mrl) { HWND hWinamp = find_winamp(this); if(hWinamp) { - QTextCodec *c=mediaplayer_get_codec(); + QTextCodec * c = mediaplayer_get_codec(); KviCString szMrl = c ? c->fromUnicode(mrl) : mrl.toUtf8(); COPYDATASTRUCT cds; cds.dwData = IPC_PLAYFILE; cds.lpData = (void *)szMrl.ptr(); cds.cbData = szMrl.len() + 1; // include space for null char - SendMessage(hWinamp,WM_COPYDATA,(WPARAM)NULL,(LPARAM) &cds); + SendMessage(hWinamp, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds); return true; } return false; } -bool KviWinampInterface::setVol(kvs_int_t &iVol) +bool KviWinampInterface::setVol(kvs_int_t & iVol) { HWND hWinamp = find_winamp(this); if(hWinamp) { - SendMessage(hWinamp,WM_USER,iVol,IPC_SETVOLUME); + SendMessage(hWinamp, WM_USER, iVol, IPC_SETVOLUME); return true; } return false; @@ -403,19 +407,21 @@ int KviWinampInterface::getVol() int ret = -1; HWND hWinamp = find_winamp(this); #if defined(COMPILE_ON_MINGW) - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,666,IPC_SETVOLUME); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 666, IPC_SETVOLUME); #else - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,-666,IPC_SETVOLUME); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, -666, IPC_SETVOLUME); #endif return ret; } -bool KviWinampInterface::jumpTo(kvs_int_t &iPos) +bool KviWinampInterface::jumpTo(kvs_int_t & iPos) { HWND hWinamp = find_winamp(this); if(hWinamp) { - SendMessage(hWinamp,WM_USER,iPos,IPC_JUMPTOTIME); + SendMessage(hWinamp, WM_USER, iPos, IPC_JUMPTOTIME); return true; } return false; @@ -423,15 +429,15 @@ bool KviWinampInterface::jumpTo(kvs_int_t &iPos) bool KviWinampInterface::hide() { HWND hWinamp = find_winamp(this); - HWND hWinampPE = FindWindow("Winamp PE",NULL); /*Playlist*/ - HWND hWinampEQ = FindWindow("Winamp EQ",NULL); /*Equalizer*/ - HWND hWinampMB = FindWindow("Winamp MB",NULL); /*MiniBrowser*/ - HWND hWinampGen = FindWindow("Winamp Gen",NULL); /*Library*/ - HWND hWinampVideo = FindWindow("Winamp Video",NULL); /*Video*/ + HWND hWinampPE = FindWindow("Winamp PE", NULL); /*Playlist*/ + HWND hWinampEQ = FindWindow("Winamp EQ", NULL); /*Equalizer*/ + HWND hWinampMB = FindWindow("Winamp MB", NULL); /*MiniBrowser*/ + HWND hWinampGen = FindWindow("Winamp Gen", NULL); /*Library*/ + HWND hWinampVideo = FindWindow("Winamp Video", NULL); /*Video*/ if(hWinamp) { ShowWindow(hWinamp, SW_HIDE); - if(hWinampPE || hWinampEQ || hWinampMB || hWinampGen || hWinampVideo ) + if(hWinampPE || hWinampEQ || hWinampMB || hWinampGen || hWinampVideo) { if(hWinampPE) ShowWindow(hWinampPE, SW_HIDE); @@ -445,7 +451,7 @@ bool KviWinampInterface::hide() ShowWindow(hWinampVideo, SW_HIDE); return true; } - return true; + return true; } return false; } @@ -472,12 +478,12 @@ bool KviWinampInterface::minimize() return false; } -bool KviWinampInterface::setPlayListPos(kvs_int_t &iPos) +bool KviWinampInterface::setPlayListPos(kvs_int_t & iPos) { HWND hWinamp = find_winamp(this); if(hWinamp) { - SendMessage(hWinamp,WM_USER,iPos,IPC_SETPLAYLISTPOS); + SendMessage(hWinamp, WM_USER, iPos, IPC_SETPLAYLISTPOS); return true; } return false; @@ -487,7 +493,8 @@ int KviWinampInterface::getPlayListPos() { int ret = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,2,IPC_GETLISTPOS); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 2, IPC_GETLISTPOS); return ret; } @@ -495,29 +502,30 @@ int KviWinampInterface::getListLength() { int ret = -1; HWND hWinamp = find_winamp(this); - if(hWinamp)ret = SendMessage(hWinamp,WM_USER,2,IPC_GETLISTLENGTH); + if(hWinamp) + ret = SendMessage(hWinamp, WM_USER, 2, IPC_GETLISTLENGTH); return ret; } -bool KviWinampInterface::setEqData(kvs_int_t &iPos, kvs_int_t &iVal) +bool KviWinampInterface::setEqData(kvs_int_t & iPos, kvs_int_t & iVal) { HWND hWinamp = find_winamp(this); if(hWinamp) { - SendMessage(hWinamp,WM_USER,iPos,IPC_GETEQDATA); - SendMessage(hWinamp,WM_USER,iVal,IPC_SETEQDATA); + SendMessage(hWinamp, WM_USER, iPos, IPC_GETEQDATA); + SendMessage(hWinamp, WM_USER, iVal, IPC_SETEQDATA); return true; } return false; } -int KviWinampInterface::getEqData(kvs_int_t &ival) +int KviWinampInterface::getEqData(kvs_int_t & ival) { HWND hWinamp = find_winamp(this); int ret = -1; if(hWinamp) { - ret = SendMessage(hWinamp,WM_USER,ival,IPC_GETEQDATA); + ret = SendMessage(hWinamp, WM_USER, ival, IPC_GETEQDATA); return ret; } return ret; @@ -528,7 +536,7 @@ bool KviWinampInterface::getRepeat() HWND hWinamp = find_winamp(this); if(hWinamp) { - bool bRepeat = SendMessage(hWinamp,WM_USER,0,IPC_GET_REPEAT); + bool bRepeat = SendMessage(hWinamp, WM_USER, 0, IPC_GET_REPEAT); return bRepeat; } return false; @@ -539,29 +547,29 @@ bool KviWinampInterface::getShuffle() HWND hWinamp = find_winamp(this); if(hWinamp) { - bool bShuffle = SendMessage(hWinamp,WM_USER,0,IPC_GET_SHUFFLE); + bool bShuffle = SendMessage(hWinamp, WM_USER, 0, IPC_GET_SHUFFLE); return bShuffle; } return false; } -bool KviWinampInterface::setShuffle(bool &bVal) +bool KviWinampInterface::setShuffle(bool & bVal) { HWND hWinamp = find_winamp(this); if(hWinamp) { - bool bRepeat = SendMessage(hWinamp,WM_USER,bVal,IPC_SET_SHUFFLE); + bool bRepeat = SendMessage(hWinamp, WM_USER, bVal, IPC_SET_SHUFFLE); return bRepeat; } return false; } -bool KviWinampInterface::setRepeat(bool &bVal) +bool KviWinampInterface::setRepeat(bool & bVal) { HWND hWinamp = find_winamp(this); if(hWinamp) { - bool bShuffle = SendMessage(hWinamp,WM_USER,bVal,IPC_SET_REPEAT); + bool bShuffle = SendMessage(hWinamp, WM_USER, bVal, IPC_SET_REPEAT); return bShuffle; } return false; diff --git a/src/modules/mediaplayer/MpWinampInterface.h b/src/modules/mediaplayer/MpWinampInterface.h index cb853a09a..3c94559c7 100644 --- a/src/modules/mediaplayer/MpWinampInterface.h +++ b/src/modules/mediaplayer/MpWinampInterface.h @@ -28,48 +28,49 @@ #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) - #include "MpInterface.h" +#include "MpInterface.h" - class KviWinampInterface : public MpInterface - { - public: - KviWinampInterface(); - ~KviWinampInterface(); - public: - virtual int detect(bool bStart); - virtual bool prev(); - virtual bool next(); - virtual bool play(); - virtual bool stop(); - virtual bool pause(); - virtual bool quit(); - virtual QString nowPlaying(); - virtual QString mrl(); - virtual int position(); - virtual int length(); - virtual bool playMrl(const QString &mrl); - virtual bool setVol(kvs_int_t &iVol); - virtual int getVol(); - virtual bool jumpTo(kvs_int_t &iPos); - virtual int sampleRate(); - virtual int bitRate(); - virtual int channels(); - virtual bool hide(); - virtual bool show(); - virtual bool minimize(); - virtual int getPlayListPos(); - virtual bool setPlayListPos(kvs_int_t &iPos); - virtual int getListLength(); - virtual int getEqData(kvs_int_t &ival); - virtual bool setEqData(kvs_int_t &iPos, kvs_int_t &iVal); - virtual bool getRepeat(); - virtual bool getShuffle(); - virtual bool setRepeat(bool &bVal); - virtual bool setShuffle(bool &bVal); - virtual MpInterface::PlayerStatus status(); - }; +class KviWinampInterface : public MpInterface +{ +public: + KviWinampInterface(); + ~KviWinampInterface(); - MP_DECLARE_DESCRIPTOR(KviWinampInterface) +public: + virtual int detect(bool bStart); + virtual bool prev(); + virtual bool next(); + virtual bool play(); + virtual bool stop(); + virtual bool pause(); + virtual bool quit(); + virtual QString nowPlaying(); + virtual QString mrl(); + virtual int position(); + virtual int length(); + virtual bool playMrl(const QString & mrl); + virtual bool setVol(kvs_int_t & iVol); + virtual int getVol(); + virtual bool jumpTo(kvs_int_t & iPos); + virtual int sampleRate(); + virtual int bitRate(); + virtual int channels(); + virtual bool hide(); + virtual bool show(); + virtual bool minimize(); + virtual int getPlayListPos(); + virtual bool setPlayListPos(kvs_int_t & iPos); + virtual int getListLength(); + virtual int getEqData(kvs_int_t & ival); + virtual bool setEqData(kvs_int_t & iPos, kvs_int_t & iVal); + virtual bool getRepeat(); + virtual bool getShuffle(); + virtual bool setRepeat(bool & bVal); + virtual bool setShuffle(bool & bVal); + virtual MpInterface::PlayerStatus status(); +}; + +MP_DECLARE_DESCRIPTOR(KviWinampInterface) #endif //COMPILE_ON_WINDOWS diff --git a/src/modules/mediaplayer/MpXmmsInterface.cpp b/src/modules/mediaplayer/MpXmmsInterface.cpp index 6af16b513..ef7c119c2 100644 --- a/src/modules/mediaplayer/MpXmmsInterface.cpp +++ b/src/modules/mediaplayer/MpXmmsInterface.cpp @@ -27,34 +27,27 @@ #include "MpXmmsInterface.h" -#if (!defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) +#if(!defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) #include "KviLocale.h" MP_IMPLEMENT_DESCRIPTOR( - KviXmmsInterface, - "xmms", - __tr2qs_ctx( - "An interface for the UNIX XMMS media player.\n" \ - "Download it from http://legacy.xmms2.org\n" - , - "mediaplayer" - ) -) + KviXmmsInterface, + "xmms", + __tr2qs_ctx( + "An interface for the UNIX XMMS media player.\n" + "Download it from http://legacy.xmms2.org\n", + "mediaplayer")) MP_IMPLEMENT_DESCRIPTOR( - KviAudaciousClassicInterface, - "audacious classic", - __tr2qs_ctx( - "An interface for the UNIX Audacious media player.\n" \ - "Download it from http://audacious-media-player.org\n" - , - "mediaplayer" - ) -) + KviAudaciousClassicInterface, + "audacious classic", + __tr2qs_ctx( + "An interface for the UNIX Audacious media player.\n" + "Download it from http://audacious-media-player.org\n", + "mediaplayer")) -static const char *xmms_lib_names[] = -{ +static const char * xmms_lib_names[] = { "libxmms.so", "libxmms.so.1", "/usr/lib/libxmms.so", @@ -64,8 +57,7 @@ static const char *xmms_lib_names[] = 0 }; -static const char *audacious_lib_names[] = -{ +static const char * audacious_lib_names[] = { "libaudacious.so", "libaudacious.so.4", "/usr/lib/libaudacious.so", @@ -75,10 +67,8 @@ static const char *audacious_lib_names[] = 0 }; - - KviXmmsInterface::KviXmmsInterface() -: MpInterface() + : MpInterface() { m_pPlayerLibrary = 0; m_szPlayerLibraryName = "libxmms.so"; @@ -96,7 +86,7 @@ KviXmmsInterface::~KviXmmsInterface() } KviAudaciousClassicInterface::KviAudaciousClassicInterface() -: KviXmmsInterface() + : KviXmmsInterface() { m_szPlayerLibraryName = "libaudacious.so"; m_pLibraryPaths = audacious_lib_names; @@ -108,9 +98,10 @@ KviAudaciousClassicInterface::~KviAudaciousClassicInterface() bool KviXmmsInterface::loadPlayerLibrary() { - if(m_pPlayerLibrary && m_pPlayerLibrary->isLoaded())return true; + if(m_pPlayerLibrary && m_pPlayerLibrary->isLoaded()) + return true; - const char **lib_name = m_pLibraryPaths; + const char ** lib_name = m_pLibraryPaths; while(*lib_name) { m_pPlayerLibrary = new QLibrary(*lib_name); @@ -132,7 +123,7 @@ void * KviXmmsInterface::lookupSymbol(const char * szSymbolName) { if(!loadPlayerLibrary()) { - QString szTmp = QString(__tr2qs_ctx("Can't load the player library (%1)","mediaplayer")).arg(m_szPlayerLibraryName); + QString szTmp = QString(__tr2qs_ctx("Can't load the player library (%1)", "mediaplayer")).arg(m_szPlayerLibraryName); setLastError(szTmp); return 0; } @@ -140,23 +131,23 @@ void * KviXmmsInterface::lookupSymbol(const char * szSymbolName) void * symptr = (void *)m_pPlayerLibrary->resolve(szSymbolName); if(!symptr) { - QString szTmp = QString(__tr2qs_ctx("Can't find symbol %1 in %2","mediaplayer")).arg(szSymbolName,m_szPlayerLibraryName); + QString szTmp = QString(__tr2qs_ctx("Can't find symbol %1 in %2", "mediaplayer")).arg(szSymbolName, m_szPlayerLibraryName); setLastError(szTmp); } return symptr; } - int KviXmmsInterface::detect(bool) { void * sym = lookupSymbol("xmms_remote_play"); return sym ? 80 : 0; } -#define XMMS_SIMPLE_CALL(__symname) \ +#define XMMS_SIMPLE_CALL(__symname) \ void (*sym)(int) = (void (*)(int))lookupSymbol(__symname); \ - if(!sym)return false; \ - sym(0); \ + if(!sym) \ + return false; \ + sym(0); \ return true; bool KviXmmsInterface::prev() @@ -189,47 +180,53 @@ bool KviXmmsInterface::quit() XMMS_SIMPLE_CALL("xmms_remote_quit") } -bool KviXmmsInterface::jumpTo(kvs_int_t &iPos) +bool KviXmmsInterface::jumpTo(kvs_int_t & iPos) { - void (*sym)(int,int) = (void (*)(int,int))lookupSymbol("xmms_remote_jump_to_time"); - if(!sym)return false; - sym(0,iPos); + void (*sym)(int, int) = (void (*)(int, int))lookupSymbol("xmms_remote_jump_to_time"); + if(!sym) + return false; + sym(0, iPos); return true; } -bool KviXmmsInterface::setVol(kvs_int_t &iVol) +bool KviXmmsInterface::setVol(kvs_int_t & iVol) { - void (*sym)(int,int) = (void (*)(int,int))lookupSymbol("xmms_remote_set_main_volume"); - if(!sym)return false; - sym(0,100*iVol/255); + void (*sym)(int, int) = (void (*)(int, int))lookupSymbol("xmms_remote_set_main_volume"); + if(!sym) + return false; + sym(0, 100 * iVol / 255); return true; } int KviXmmsInterface::getVol() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_main_volume"); - if(!sym)return -1; + if(!sym) + return -1; int iVol = sym(0); - return iVol * 255 /100; + return iVol * 255 / 100; } bool KviXmmsInterface::getRepeat() { bool (*sym)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_repeat"); - if(!sym)return false; + if(!sym) + return false; bool ret = sym(0); return ret; } -bool KviXmmsInterface::setRepeat(bool &bVal) +bool KviXmmsInterface::setRepeat(bool & bVal) { bool (*sym1)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_repeat"); - if(!sym1)return false; + if(!sym1) + return false; bool bNow = sym1(0); if(bNow != bVal) { void (*sym2)(int) = (void (*)(int))lookupSymbol("xmms_remote_toggle_repeat"); - if(!sym2)return false; + if(!sym2) + return false; sym2(0); } return true; @@ -238,20 +235,23 @@ bool KviXmmsInterface::setRepeat(bool &bVal) bool KviXmmsInterface::getShuffle() { bool (*sym)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_shuffle"); - if(!sym)return false; + if(!sym) + return false; bool ret = sym(0); return ret; } -bool KviXmmsInterface::setShuffle(bool &bVal) +bool KviXmmsInterface::setShuffle(bool & bVal) { bool (*sym1)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_shuffle"); - if(!sym1)return false; + if(!sym1) + return false; bool bNow = sym1(0); if(bNow != bVal) { void (*sym2)(int) = (void (*)(int))lookupSymbol("xmms_remote_toggle_shuffle"); - if(!sym2)return false; + if(!sym2) + return false; sym2(0); } return true; @@ -262,41 +262,52 @@ MpInterface::PlayerStatus KviXmmsInterface::status() bool (*sym1)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_paused"); if(sym1) { - if(sym1(0))return MpInterface::Paused; + if(sym1(0)) + return MpInterface::Paused; bool (*sym2)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_playing"); if(sym2) { - if(sym2(0))return MpInterface::Playing; - else return MpInterface::Stopped; + if(sym2(0)) + return MpInterface::Playing; + else + return MpInterface::Stopped; } } return MpInterface::Unknown; } -bool KviXmmsInterface::playMrl(const QString &mrl) +bool KviXmmsInterface::playMrl(const QString & mrl) { - void (*sym)(int,char *) = (void (*)(int,char *))lookupSymbol("xmms_remote_playlist_add_url_string"); + void (*sym)(int, char *) = (void (*)(int, char *))lookupSymbol("xmms_remote_playlist_add_url_string"); QByteArray tmp = mrl.toLocal8Bit(); if(!tmp.isEmpty()) { if(sym) { - sym(0,tmp.data()); + sym(0, tmp.data()); int (*sym1)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_length"); if(sym1) { int len = sym1(0); if(len > 0) { - void (*sym2)(int,int) = (void (*)(int,int))lookupSymbol("xmms_remote_set_playlist_pos"); + void (*sym2)(int, int) = (void (*)(int, int))lookupSymbol("xmms_remote_set_playlist_pos"); if(sym2) { - sym2(0,len - 1); - } else return false; - } else return false; - } else return false; - } else return false; + sym2(0, len - 1); + } + else + return false; + } + else + return false; + } + else + return false; + } + else + return false; } return true; } @@ -304,53 +315,61 @@ bool KviXmmsInterface::playMrl(const QString &mrl) QString KviXmmsInterface::nowPlaying() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos"); - if(!sym)return QString(); + if(!sym) + return QString(); int pos = sym(0); - char * (*sym2)(int,int) = (char * (*)(int,int))lookupSymbol("xmms_remote_get_playlist_title"); - if(!sym2)return QString(); - return QString::fromLocal8Bit(sym2(0,pos)); + char * (*sym2)(int, int) = (char * (*)(int, int))lookupSymbol("xmms_remote_get_playlist_title"); + if(!sym2) + return QString(); + return QString::fromLocal8Bit(sym2(0, pos)); } QString KviXmmsInterface::mrl() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos"); - if(!sym)return QString(); + if(!sym) + return QString(); int pos = sym(0); - char * (*sym2)(int,int) = (char * (*)(int,int))lookupSymbol("xmms_remote_get_playlist_file"); - if(!sym2)return QString(); - QString ret = QString::fromLocal8Bit(sym2(0,pos)); + char * (*sym2)(int, int) = (char * (*)(int, int))lookupSymbol("xmms_remote_get_playlist_file"); + if(!sym2) + return QString(); + QString ret = QString::fromLocal8Bit(sym2(0, pos)); if(ret.length() > 1) - if(ret[0] == '/')ret.prepend("file://"); + if(ret[0] == '/') + ret.prepend("file://"); return ret; } int KviXmmsInterface::position() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos"); - if(!sym)return -1; + if(!sym) + return -1; int pos = sym(0); - int (*sym2)(int,int) = (int (*)(int,int))lookupSymbol("xmms_remote_get_output_time"); - if(!sym2)return -1; - return sym2(0,pos); + int (*sym2)(int, int) = (int (*)(int, int))lookupSymbol("xmms_remote_get_output_time"); + if(!sym2) + return -1; + return sym2(0, pos); } int KviXmmsInterface::length() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos"); - if(!sym)return -1; + if(!sym) + return -1; int pos = sym(0); - int (*sym2)(int,int) = (int (*)(int,int))lookupSymbol("xmms_remote_get_playlist_time"); - if(!sym2)return -1; - return sym2(0,pos); + int (*sym2)(int, int) = (int (*)(int, int))lookupSymbol("xmms_remote_get_playlist_time"); + if(!sym2) + return -1; + return sym2(0, pos); } int KviXmmsInterface::getPlayListPos() { int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos"); - if(!sym)return -1; + if(!sym) + return -1; return sym(0); } - - #endif //!COMPILE_ON_WINDOWS diff --git a/src/modules/mediaplayer/MpXmmsInterface.h b/src/modules/mediaplayer/MpXmmsInterface.h index 3b89cd8a2..4271799d9 100644 --- a/src/modules/mediaplayer/MpXmmsInterface.h +++ b/src/modules/mediaplayer/MpXmmsInterface.h @@ -34,52 +34,55 @@ #include <QLibrary> #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - class KviXmmsInterface : public MpInterface - { - public: - KviXmmsInterface(); - virtual ~KviXmmsInterface(); - protected: - QLibrary* m_pPlayerLibrary; - QString m_szPlayerLibraryName; - const char ** m_pLibraryPaths; - public: - virtual int detect(bool bStart); - virtual bool prev(); - virtual bool next(); - virtual bool play(); - virtual bool stop(); - virtual bool pause(); - virtual bool quit(); - virtual bool jumpTo(kvs_int_t &iPos); - virtual bool setVol(kvs_int_t &iVol); - virtual int getVol(); - virtual MpInterface::PlayerStatus status(); - virtual QString nowPlaying(); - virtual bool playMrl(const QString &mrl); - virtual QString mrl(); - virtual int getPlayListPos(); - virtual int position(); - virtual int length(); - virtual bool getRepeat(); - virtual bool getShuffle(); - virtual bool setRepeat(bool &bVal); - virtual bool setShuffle(bool &bVal); - protected: - bool loadPlayerLibrary(); - void * lookupSymbol(const char * szSymbolName); - }; +class KviXmmsInterface : public MpInterface +{ +public: + KviXmmsInterface(); + virtual ~KviXmmsInterface(); - MP_DECLARE_DESCRIPTOR(KviXmmsInterface) +protected: + QLibrary * m_pPlayerLibrary; + QString m_szPlayerLibraryName; + const char ** m_pLibraryPaths; - class KviAudaciousClassicInterface : public KviXmmsInterface - { - public: - KviAudaciousClassicInterface(); - virtual ~KviAudaciousClassicInterface(); - }; +public: + virtual int detect(bool bStart); + virtual bool prev(); + virtual bool next(); + virtual bool play(); + virtual bool stop(); + virtual bool pause(); + virtual bool quit(); + virtual bool jumpTo(kvs_int_t & iPos); + virtual bool setVol(kvs_int_t & iVol); + virtual int getVol(); + virtual MpInterface::PlayerStatus status(); + virtual QString nowPlaying(); + virtual bool playMrl(const QString & mrl); + virtual QString mrl(); + virtual int getPlayListPos(); + virtual int position(); + virtual int length(); + virtual bool getRepeat(); + virtual bool getShuffle(); + virtual bool setRepeat(bool & bVal); + virtual bool setShuffle(bool & bVal); - MP_DECLARE_DESCRIPTOR(KviAudaciousClassicInterface) +protected: + bool loadPlayerLibrary(); + void * lookupSymbol(const char * szSymbolName); +}; + +MP_DECLARE_DESCRIPTOR(KviXmmsInterface) + +class KviAudaciousClassicInterface : public KviXmmsInterface +{ +public: + KviAudaciousClassicInterface(); + virtual ~KviAudaciousClassicInterface(); +}; + +MP_DECLARE_DESCRIPTOR(KviAudaciousClassicInterface) #endif //COMPILE_ON_WINDOWS diff --git a/src/modules/mediaplayer/libkvimediaplayer.cpp b/src/modules/mediaplayer/libkvimediaplayer.cpp index 53ac614c1..a1a15acea 100644 --- a/src/modules/mediaplayer/libkvimediaplayer.cpp +++ b/src/modules/mediaplayer/libkvimediaplayer.cpp @@ -46,7 +46,7 @@ static MpInterface * auto_detect_player(KviWindow * pOut = 0) MpInterface * pBest = 0; MpInterfaceDescriptor * d; MpInterfaceDescriptor * pDBest = 0; - for(d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + for(d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { MpInterface * i = d->instance(); if(i) @@ -62,17 +62,17 @@ static MpInterface * auto_detect_player(KviWindow * pOut = 0) { QString szOut; QString szNam = d->name(); - szOut = QString(__tr2qs_ctx("Trying media player interface \"%1\": score %2","mediaplayer")).arg(szNam).arg(iScore); - pOut->output(KVI_OUT_MULTIMEDIA,szOut); + szOut = QString(__tr2qs_ctx("Trying media player interface \"%1\": score %2", "mediaplayer")).arg(szNam).arg(iScore); + pOut->output(KVI_OUT_MULTIMEDIA, szOut); } } } if(iBest < 90) { if(pOut) - pOut->outputNoFmt(KVI_OUT_MULTIMEDIA,__tr2qs_ctx("Not sure about the results, trying a second, more aggressive detection pass","mediaplayer")); + pOut->outputNoFmt(KVI_OUT_MULTIMEDIA, __tr2qs_ctx("Not sure about the results, trying a second, more aggressive detection pass", "mediaplayer")); // no sure player found... try again with a destructive test - for(d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + for(d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { MpInterface * i = d->instance(); if(i) @@ -88,8 +88,8 @@ static MpInterface * auto_detect_player(KviWindow * pOut = 0) { QString szOut; QString szNam = d->name(); - szOut = QString(__tr2qs_ctx("Trying media player interface \"%1\": score %2","mediaplayer")).arg(szNam).arg(iScore); - pOut->output(KVI_OUT_MULTIMEDIA,szOut); + szOut = QString(__tr2qs_ctx("Trying media player interface \"%1\": score %2", "mediaplayer")).arg(szNam).arg(iScore); + pOut->output(KVI_OUT_MULTIMEDIA, szOut); } } } @@ -98,75 +98,74 @@ static MpInterface * auto_detect_player(KviWindow * pOut = 0) { KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer) = pDBest->name(); if(pOut) - pOut->output(KVI_OUT_MULTIMEDIA,__tr2qs_ctx("Choosing media player interface \"%Q\"","mediaplayer"),&(KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer))); - } else { + pOut->output(KVI_OUT_MULTIMEDIA, __tr2qs_ctx("Choosing media player interface \"%Q\"", "mediaplayer"), &(KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer))); + } + else + { if(pOut) - pOut->outputNoFmt(KVI_OUT_MULTIMEDIA,__tr2qs_ctx("Seems that there is no usable media player on this machine","mediaplayer")); + pOut->outputNoFmt(KVI_OUT_MULTIMEDIA, __tr2qs_ctx("Seems that there is no usable media player on this machine", "mediaplayer")); } return pBest; } +#define MP_KVS_FAIL_ON_NO_INTERFACE \ + if(!g_pMPInterface) \ + { \ + c->warning(__tr2qs_ctx("No mediaplayer interface selected. Try /mediaplayer.detect", "mediaplayer")); \ + return true; \ + } +#define MP_KVS_COMMAND(__name) static bool mediaplayer_kvs_cmd_##__name(KviKvsModuleCommandCall * c) +#define MP_KVS_FUNCTION(__name) static bool mediaplayer_kvs_fnc_##__name(KviKvsModuleFunctionCall * c) - #define MP_KVS_FAIL_ON_NO_INTERFACE \ - if(!g_pMPInterface) \ - { \ - c->warning(__tr2qs_ctx("No mediaplayer interface selected. Try /mediaplayer.detect","mediaplayer")); \ - return true; \ - } \ - - #define MP_KVS_COMMAND(__name) static bool mediaplayer_kvs_cmd_ ## __name (KviKvsModuleCommandCall * c) - #define MP_KVS_FUNCTION(__name) static bool mediaplayer_kvs_fnc_ ## __name (KviKvsModuleFunctionCall * c) - - #define MP_KVS_SIMPLE_COMMAND(__name,__ifacecommand) \ - MP_KVS_COMMAND(__name) \ - { \ - KVSM_PARAMETERS_BEGIN(c) \ - KVSM_PARAMETERS_END(c) \ - \ - MP_KVS_FAIL_ON_NO_INTERFACE \ - \ - if(!g_pMPInterface->__ifacecommand()) \ - { \ - if(!c->hasSwitch('q',"quiet")) \ - { \ - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); \ - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); \ - tmp += g_pMPInterface->lastError(); \ - c->warning(tmp); \ - } \ - }\ - return true; \ - } +#define MP_KVS_SIMPLE_COMMAND(__name, __ifacecommand) \ + MP_KVS_COMMAND(__name) \ + { \ + KVSM_PARAMETERS_BEGIN(c) \ + KVSM_PARAMETERS_END(c) \ + \ + MP_KVS_FAIL_ON_NO_INTERFACE \ + \ + if(!g_pMPInterface->__ifacecommand()) \ + { \ + if(!c->hasSwitch('q', "quiet")) \ + { \ + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); \ + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); \ + tmp += g_pMPInterface->lastError(); \ + c->warning(tmp); \ + } \ + } \ + return true; \ + } - #define MP_KVS_SIMPLE_STRING_FUNCTION(__name,__ifacecommand) \ - MP_KVS_FUNCTION(__name) \ - { \ - MP_KVS_FAIL_ON_NO_INTERFACE \ - QString szRet = g_pMPInterface->__ifacecommand(); \ - c->returnValue()->setString(szRet); \ - return true; \ +#define MP_KVS_SIMPLE_STRING_FUNCTION(__name, __ifacecommand) \ + MP_KVS_FUNCTION(__name) \ + { \ + MP_KVS_FAIL_ON_NO_INTERFACE \ + QString szRet = g_pMPInterface->__ifacecommand(); \ + c->returnValue()->setString(szRet); \ + return true; \ } - #define MP_KVS_SIMPLE_INT_FUNCTION(__name,__ifacecommand) \ - MP_KVS_FUNCTION(__name) \ - { \ - MP_KVS_FAIL_ON_NO_INTERFACE \ - int iRet = g_pMPInterface->__ifacecommand(); \ - c->returnValue()->setInteger(iRet); \ - return true; \ +#define MP_KVS_SIMPLE_INT_FUNCTION(__name, __ifacecommand) \ + MP_KVS_FUNCTION(__name) \ + { \ + MP_KVS_FAIL_ON_NO_INTERFACE \ + int iRet = g_pMPInterface->__ifacecommand(); \ + c->returnValue()->setInteger(iRet); \ + return true; \ } - // FINDME! - #define MP_KVS_SIMPLE_BOOL_FUNCTION(__name,__ifacecommand) \ - MP_KVS_FUNCTION(__name) \ - { \ - MP_KVS_FAIL_ON_NO_INTERFACE \ - bool bRet = g_pMPInterface->__ifacecommand(); \ - c->returnValue()->setBoolean(bRet); \ - return true; \ +// FINDME! +#define MP_KVS_SIMPLE_BOOL_FUNCTION(__name, __ifacecommand) \ + MP_KVS_FUNCTION(__name) \ + { \ + MP_KVS_FAIL_ON_NO_INTERFACE \ + bool bRet = g_pMPInterface->__ifacecommand(); \ + c->returnValue()->setBoolean(bRet); \ + return true; \ } - /* @doc: mediaplayer.play @type: @@ -191,7 +190,7 @@ static MpInterface * auto_detect_player(KviWindow * pOut = 0) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(play,play) +MP_KVS_SIMPLE_COMMAND(play, play) /* @doc: mediaplayer.hide @@ -214,7 +213,7 @@ MP_KVS_SIMPLE_COMMAND(play,play) [cmd]mediaplayer.minimize[/cmd] */ -MP_KVS_SIMPLE_COMMAND(hide,hide) +MP_KVS_SIMPLE_COMMAND(hide, hide) /* @doc: mediaplayer.show @@ -239,7 +238,7 @@ MP_KVS_SIMPLE_COMMAND(hide,hide) [cmd]mediaplayer.minimize[/cmd] */ -MP_KVS_SIMPLE_COMMAND(show,show) +MP_KVS_SIMPLE_COMMAND(show, show) /* @doc: mediaplayer.minimize @@ -262,7 +261,7 @@ MP_KVS_SIMPLE_COMMAND(show,show) [cmd]mediaplayer.show[/cmd] */ -MP_KVS_SIMPLE_COMMAND(minimize,minimize) +MP_KVS_SIMPLE_COMMAND(minimize, minimize) /* @doc: mediaplayer.stop @@ -288,7 +287,7 @@ MP_KVS_SIMPLE_COMMAND(minimize,minimize) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(stop,stop) +MP_KVS_SIMPLE_COMMAND(stop, stop) /* @doc: mediaplayer.next @@ -314,7 +313,7 @@ MP_KVS_SIMPLE_COMMAND(stop,stop) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(next,next) +MP_KVS_SIMPLE_COMMAND(next, next) /* @doc: mediaplayer.prev @@ -340,7 +339,7 @@ MP_KVS_SIMPLE_COMMAND(next,next) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(prev,prev) +MP_KVS_SIMPLE_COMMAND(prev, prev) /* @doc: mediaplayer.quit @@ -366,7 +365,7 @@ MP_KVS_SIMPLE_COMMAND(prev,prev) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(quit,quit) +MP_KVS_SIMPLE_COMMAND(quit, quit) /* @doc: mediaplayer.pause @@ -392,7 +391,7 @@ MP_KVS_SIMPLE_COMMAND(quit,quit) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(pause,pause) +MP_KVS_SIMPLE_COMMAND(pause, pause) /* @doc: mediaplayer.detect @@ -427,7 +426,7 @@ MP_KVS_SIMPLE_COMMAND(pause,pause) MP_KVS_COMMAND(detect) { - g_pMPInterface = auto_detect_player(c->hasSwitch('q',"quiet") ? 0 : c->window()); + g_pMPInterface = auto_detect_player(c->hasSwitch('q', "quiet") ? 0 : c->window()); return true; } @@ -457,10 +456,10 @@ MP_KVS_COMMAND(setPlayer) QString szPlayer; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("player",KVS_PT_STRING,0,szPlayer) + KVSM_PARAMETER("player", KVS_PT_STRING, 0, szPlayer) KVSM_PARAMETERS_END(c) - for(MpInterfaceDescriptor * d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + for(MpInterfaceDescriptor * d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { if(d->name() == szPlayer) { @@ -520,12 +519,12 @@ MP_KVS_FUNCTION(player) MP_KVS_FUNCTION(playerList) { - KviKvsArray* pArray = new KviKvsArray(); - int id=0; + KviKvsArray * pArray = new KviKvsArray(); + int id = 0; - for(MpInterfaceDescriptor * d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + for(MpInterfaceDescriptor * d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { - pArray->set(id++,new KviKvsVariant(d->name())); + pArray->set(id++, new KviKvsVariant(d->name())); } c->returnValue()->setArray(pArray); return true; @@ -564,16 +563,16 @@ MP_KVS_COMMAND(playMrl) QString szMrl; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("player",KVS_PT_STRING,0,szMrl) + KVSM_PARAMETER("player", KVS_PT_STRING, 0, szMrl) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->playMrl(szMrl)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -587,16 +586,16 @@ MP_KVS_COMMAND(amipExec) QString szMrl; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("player",KVS_PT_STRING,0,szMrl) + KVSM_PARAMETER("player", KVS_PT_STRING, 0, szMrl) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->amipExec(szMrl)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -628,16 +627,16 @@ MP_KVS_COMMAND(jumpTo) kvs_int_t iPos; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("position",KVS_PT_INT,0,iPos) + KVSM_PARAMETER("position", KVS_PT_INT, 0, iPos) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->jumpTo(iPos)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -667,16 +666,16 @@ MP_KVS_COMMAND(setVol) kvs_int_t iVol; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("volume",KVS_PT_INT,0,iVol) + KVSM_PARAMETER("volume", KVS_PT_INT, 0, iVol) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->setVol(iVol)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -703,7 +702,7 @@ MP_KVS_COMMAND(setVol) [cmd]mediaplayer.setVol[/cmd] */ -MP_KVS_SIMPLE_INT_FUNCTION(getVol,getVol) +MP_KVS_SIMPLE_INT_FUNCTION(getVol, getVol) /* @doc: mediaplayer.mute @@ -729,7 +728,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(getVol,getVol) [fnc]$mediaplayer.status[/fnc] */ -MP_KVS_SIMPLE_COMMAND(mute,mute) +MP_KVS_SIMPLE_COMMAND(mute, mute) /* @doc: mediaplayer.mrl @@ -763,7 +762,7 @@ MP_KVS_SIMPLE_COMMAND(mute,mute) [fnc]$mediaplayer.localFile[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(mrl,mrl) +MP_KVS_SIMPLE_STRING_FUNCTION(mrl, mrl) /* @doc: mediaplayer.nowPlaying @@ -799,7 +798,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(mrl,mrl) [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(nowPlaying,nowPlaying) +MP_KVS_SIMPLE_STRING_FUNCTION(nowPlaying, nowPlaying) /* @doc: mediaplayer.title @@ -828,7 +827,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(nowPlaying,nowPlaying) [fnc]$mediaplayer.mediaType[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(title,title) +MP_KVS_SIMPLE_STRING_FUNCTION(title, title) /* @doc: mediaplayer.artist @@ -860,7 +859,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(title,title) [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(artist,artist) +MP_KVS_SIMPLE_STRING_FUNCTION(artist, artist) /* @doc: mediaplayer.genre @@ -890,7 +889,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(artist,artist) [fnc]$mediaplayer.length[/fnc], [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(genre,genre) +MP_KVS_SIMPLE_STRING_FUNCTION(genre, genre) /* @doc: mediaplayer.year @@ -920,7 +919,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(genre,genre) [fnc]$mediaplayer.length[/fnc], [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(year,year) +MP_KVS_SIMPLE_STRING_FUNCTION(year, year) /* @doc: mediaplayer.comment @@ -950,7 +949,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(year,year) [fnc]$mediaplayer.length[/fnc], [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(comment,comment) +MP_KVS_SIMPLE_STRING_FUNCTION(comment, comment) /* @doc: mediaplayer.album @@ -983,7 +982,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(comment,comment) [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(album,album) +MP_KVS_SIMPLE_STRING_FUNCTION(album, album) /* @doc: mediaplayer.mediaType @@ -1010,7 +1009,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(album,album) [fnc]$mediaplayer.year[/fnc], [fnc]$mediaplayer.comment[/fnc] */ -MP_KVS_SIMPLE_STRING_FUNCTION(mediaType,mediaType) +MP_KVS_SIMPLE_STRING_FUNCTION(mediaType, mediaType) /* @doc: mediaplayer.bitRate @@ -1040,7 +1039,7 @@ MP_KVS_SIMPLE_STRING_FUNCTION(mediaType,mediaType) [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_INT_FUNCTION(bitRate,bitRate) +MP_KVS_SIMPLE_INT_FUNCTION(bitRate, bitRate) /* @doc: mediaplayer.sampleRate @@ -1069,7 +1068,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(bitRate,bitRate) [fnc]$mediaplayer.position[/fnc], [fnc]$mediaplayer.channels[/fnc] */ -MP_KVS_SIMPLE_INT_FUNCTION(sampleRate,sampleRate) +MP_KVS_SIMPLE_INT_FUNCTION(sampleRate, sampleRate) /* @doc: mediaplayer.length @@ -1098,7 +1097,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(sampleRate,sampleRate) [fnc]$mediaplayer.position[/fnc] */ -MP_KVS_SIMPLE_INT_FUNCTION(length,length) +MP_KVS_SIMPLE_INT_FUNCTION(length, length) /* @doc: mediaplayer.position @@ -1127,7 +1126,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(length,length) [fnc]$mediaplayer.bitRate[/fnc], [fnc]$mediaplayer.channels[/fnc] */ -MP_KVS_SIMPLE_INT_FUNCTION(position,position) +MP_KVS_SIMPLE_INT_FUNCTION(position, position) /* @doc: mediaplayer.channels @@ -1150,7 +1149,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(position,position) [module:mediaplayer]media player module documentation[/module] */ -MP_KVS_SIMPLE_INT_FUNCTION(channels,channels) +MP_KVS_SIMPLE_INT_FUNCTION(channels, channels) /* @doc: mediaplayer.setPlayListPos @@ -1176,16 +1175,16 @@ MP_KVS_COMMAND(setPlayListPos) kvs_int_t iPos; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("position",KVS_PT_INT,0,iPos) + KVSM_PARAMETER("position", KVS_PT_INT, 0, iPos) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->setPlayListPos(iPos)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -1212,7 +1211,7 @@ MP_KVS_COMMAND(setPlayListPos) [cmd]mediaplayer.getPlayListPos[/cmd] */ -MP_KVS_SIMPLE_INT_FUNCTION(getPlayListPos,getPlayListPos) +MP_KVS_SIMPLE_INT_FUNCTION(getPlayListPos, getPlayListPos) /* @doc: mediaplayer.getListLength @@ -1232,7 +1231,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(getPlayListPos,getPlayListPos) [module:mediaplayer]media player module documentation[/module], */ -MP_KVS_SIMPLE_INT_FUNCTION(getListLength,getListLength) +MP_KVS_SIMPLE_INT_FUNCTION(getListLength, getListLength) /* @doc: mediaplayer.getRepeat @@ -1254,7 +1253,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(getListLength,getListLength) [fnc]$mediaplayer.getShuffle[/fnc] */ -MP_KVS_SIMPLE_INT_FUNCTION(getRepeat,getRepeat) +MP_KVS_SIMPLE_INT_FUNCTION(getRepeat, getRepeat) /* @doc: mediaplayer.getShuffle @@ -1276,7 +1275,7 @@ MP_KVS_SIMPLE_INT_FUNCTION(getRepeat,getRepeat) [fnc]$mediaplayer.getRepeat[/fnc] */ -MP_KVS_SIMPLE_BOOL_FUNCTION(getShuffle,getShuffle) +MP_KVS_SIMPLE_BOOL_FUNCTION(getShuffle, getShuffle) /* @doc: mediaplayer.getEqData @@ -1306,20 +1305,20 @@ MP_KVS_FUNCTION(getEqData) QString szOptions; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("item",KVS_PT_INT,0,iValue) - KVSM_PARAMETER("options",KVS_PT_STRING,KVS_PF_OPTIONAL,szOptions) + KVSM_PARAMETER("item", KVS_PT_INT, 0, iValue) + KVSM_PARAMETER("options", KVS_PT_STRING, KVS_PF_OPTIONAL, szOptions) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE - bool bQuiet = szOptions.indexOf('q',Qt::CaseInsensitive) != -1; + bool bQuiet = szOptions.indexOf('q', Qt::CaseInsensitive) != -1; int ret = g_pMPInterface->getEqData(iValue); if(!ret && !bQuiet) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -1353,17 +1352,17 @@ MP_KVS_COMMAND(setEqData) kvs_int_t iValue; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("item",KVS_PT_INT,0,iPos) - KVSM_PARAMETER("value",KVS_PT_INT,0,iValue) + KVSM_PARAMETER("item", KVS_PT_INT, 0, iPos) + KVSM_PARAMETER("value", KVS_PT_INT, 0, iValue) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE - if(!g_pMPInterface->setEqData(iPos,iValue)) + if(!g_pMPInterface->setEqData(iPos, iValue)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -1402,8 +1401,9 @@ MP_KVS_FUNCTION(localFile) MP_KVS_FAIL_ON_NO_INTERFACE QString szRet = g_pMPInterface->mrl(); - if(szRet.isEmpty())return true; - if(szRet.startsWith("file://",Qt::CaseInsensitive)) + if(szRet.isEmpty()) + return true; + if(szRet.startsWith("file://", Qt::CaseInsensitive)) { #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW) c->returnValue()->setString(szRet.mid(7)); @@ -1420,12 +1420,13 @@ MP_KVS_FUNCTION(amipEval) QString szMrl; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("player",KVS_PT_STRING,0,szMrl) + KVSM_PARAMETER("player", KVS_PT_STRING, 0, szMrl) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE QString szRet = g_pMPInterface->amipEval(szMrl); - if(szRet.isEmpty())return true; + if(szRet.isEmpty()) + return true; c->returnValue()->setString(szRet); @@ -1455,8 +1456,8 @@ MP_KVS_FUNCTION(amipEval) MP_KVS_FUNCTION(status) { -// KVSM_PARAMETERS_BEGIN(c) -// KVSM_PARAMETERS_END(c) + // KVSM_PARAMETERS_BEGIN(c) + // KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE MpInterface::PlayerStatus eStat = g_pMPInterface->status(); @@ -1464,16 +1465,16 @@ MP_KVS_FUNCTION(status) { case MpInterface::Stopped: c->returnValue()->setString("stopped"); - break; + break; case MpInterface::Playing: c->returnValue()->setString("playing"); - break; + break; case MpInterface::Paused: c->returnValue()->setString("paused"); - break; + break; default: c->returnValue()->setString("unknown"); - break; + break; } return true; } @@ -1546,16 +1547,16 @@ MP_KVS_COMMAND(setRepeat) bool bVal; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("repeat",KVS_PT_BOOL,0,bVal) + KVSM_PARAMETER("repeat", KVS_PT_BOOL, 0, bVal) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->setRepeat(bVal)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -1588,16 +1589,16 @@ MP_KVS_COMMAND(setShuffle) bool bVal; KVSM_PARAMETERS_BEGIN(c) - KVSM_PARAMETER("shuffle",KVS_PT_BOOL,0,bVal) + KVSM_PARAMETER("shuffle", KVS_PT_BOOL, 0, bVal) KVSM_PARAMETERS_END(c) MP_KVS_FAIL_ON_NO_INTERFACE if(!g_pMPInterface->setShuffle(bVal)) { - if(!c->hasSwitch('q',"quiet")) + if(!c->hasSwitch('q', "quiet")) { - c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function","mediaplayer")); - QString tmp = __tr2qs_ctx("Last interface error: ","mediaplayer"); + c->warning(__tr2qs_ctx("The selected media player interface failed to execute the requested function", "mediaplayer")); + QString tmp = __tr2qs_ctx("Last interface error: ", "mediaplayer"); tmp += g_pMPInterface->lastError(); c->warning(tmp); } @@ -1605,12 +1606,12 @@ MP_KVS_COMMAND(setShuffle) return true; } -static bool mediaplayer_module_init( KviModule * m ) +static bool mediaplayer_module_init(KviModule * m) { g_pDescriptorList = new KviPointerList<MpInterfaceDescriptor>; g_pDescriptorList->setAutoDelete(true); -#if (defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) +#if(defined(COMPILE_DBUS_SUPPORT) && !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MAC) && !defined(COMPILE_ON_MINGW)) g_pDescriptorList->append(MP_CREATE_DESCRIPTOR(MpAudaciousInterface)); g_pDescriptorList->append(MP_CREATE_DESCRIPTOR(KviAudaciousClassicInterface)); g_pDescriptorList->append(MP_CREATE_DESCRIPTOR(KviXmmsInterface)); @@ -1633,8 +1634,10 @@ static bool mediaplayer_module_init( KviModule * m ) if(KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer) == "auto") { g_pMPInterface = auto_detect_player(); - } else { - for(MpInterfaceDescriptor * d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + } + else + { + for(MpInterfaceDescriptor * d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { if(d->name() == KVI_OPTION_STRING(KviOption_stringPreferredMediaPlayer)) { @@ -1643,59 +1646,58 @@ static bool mediaplayer_module_init( KviModule * m ) } } - // check for "auto" interface too! - +// check for "auto" interface too! - #define MP_KVS_REGCMD(__name,__stringname) KVSM_REGISTER_SIMPLE_COMMAND(m,__stringname,mediaplayer_kvs_cmd_ ## __name) - #define MP_KVS_REGFNC(__name,__stringname) KVSM_REGISTER_FUNCTION(m,__stringname,mediaplayer_kvs_fnc_ ## __name) +#define MP_KVS_REGCMD(__name, __stringname) KVSM_REGISTER_SIMPLE_COMMAND(m, __stringname, mediaplayer_kvs_cmd_##__name) +#define MP_KVS_REGFNC(__name, __stringname) KVSM_REGISTER_FUNCTION(m, __stringname, mediaplayer_kvs_fnc_##__name) - MP_KVS_REGCMD(play,"play"); - MP_KVS_REGCMD(stop,"stop"); - MP_KVS_REGCMD(next,"next"); - MP_KVS_REGCMD(prev,"prev"); - MP_KVS_REGCMD(quit,"quit"); - MP_KVS_REGCMD(pause,"pause"); - MP_KVS_REGCMD(detect,"detect"); - MP_KVS_REGCMD(playMrl,"playMrl"); - MP_KVS_REGCMD(amipExec,"amipExec"); - MP_KVS_REGCMD(hide,"hide"); - MP_KVS_REGCMD(show,"show"); - MP_KVS_REGCMD(minimize,"minimize"); - MP_KVS_REGCMD(jumpTo,"jumpTo"); - MP_KVS_REGCMD(setPlayer,"setPlayer"); - MP_KVS_REGCMD(setVol,"setVol"); - MP_KVS_REGCMD(mute,"mute"); - MP_KVS_REGCMD(setRepeat,"setRepeat"); - MP_KVS_REGCMD(setShuffle,"setShuffle"); - MP_KVS_REGCMD(setPlayListPos,"setPlayListPos"); - MP_KVS_REGCMD(setEqData,"setEqData"); + MP_KVS_REGCMD(play, "play"); + MP_KVS_REGCMD(stop, "stop"); + MP_KVS_REGCMD(next, "next"); + MP_KVS_REGCMD(prev, "prev"); + MP_KVS_REGCMD(quit, "quit"); + MP_KVS_REGCMD(pause, "pause"); + MP_KVS_REGCMD(detect, "detect"); + MP_KVS_REGCMD(playMrl, "playMrl"); + MP_KVS_REGCMD(amipExec, "amipExec"); + MP_KVS_REGCMD(hide, "hide"); + MP_KVS_REGCMD(show, "show"); + MP_KVS_REGCMD(minimize, "minimize"); + MP_KVS_REGCMD(jumpTo, "jumpTo"); + MP_KVS_REGCMD(setPlayer, "setPlayer"); + MP_KVS_REGCMD(setVol, "setVol"); + MP_KVS_REGCMD(mute, "mute"); + MP_KVS_REGCMD(setRepeat, "setRepeat"); + MP_KVS_REGCMD(setShuffle, "setShuffle"); + MP_KVS_REGCMD(setPlayListPos, "setPlayListPos"); + MP_KVS_REGCMD(setEqData, "setEqData"); - MP_KVS_REGFNC(nowPlaying,"nowPlaying"); - MP_KVS_REGFNC(mrl,"mrl"); - MP_KVS_REGFNC(title,"title"); - MP_KVS_REGFNC(artist,"artist"); - MP_KVS_REGFNC(genre,"genre"); - MP_KVS_REGFNC(year,"year"); - MP_KVS_REGFNC(comment,"comment"); - MP_KVS_REGFNC(album,"album"); - MP_KVS_REGFNC(mediaType,"mediaType"); - MP_KVS_REGFNC(bitRate,"bitRate"); - MP_KVS_REGFNC(sampleRate,"sampleRate"); - MP_KVS_REGFNC(length,"length"); - MP_KVS_REGFNC(position,"position"); - MP_KVS_REGFNC(status,"status"); - MP_KVS_REGFNC(player,"player"); - MP_KVS_REGFNC(playerList,"playerList"); - MP_KVS_REGFNC(localFile,"localFile"); - MP_KVS_REGFNC(amipEval,"amipEval"); - MP_KVS_REGFNC(channels,"channels"); - MP_KVS_REGFNC(getListLength,"getListLength"); - MP_KVS_REGFNC(getPlayListPos,"getPlayListPos"); - MP_KVS_REGFNC(getEqData,"getEqData"); - MP_KVS_REGFNC(getRepeat,"getRepeat"); - MP_KVS_REGFNC(getShuffle,"getShuffle"); - MP_KVS_REGFNC(getVol,"getVol"); -/* + MP_KVS_REGFNC(nowPlaying, "nowPlaying"); + MP_KVS_REGFNC(mrl, "mrl"); + MP_KVS_REGFNC(title, "title"); + MP_KVS_REGFNC(artist, "artist"); + MP_KVS_REGFNC(genre, "genre"); + MP_KVS_REGFNC(year, "year"); + MP_KVS_REGFNC(comment, "comment"); + MP_KVS_REGFNC(album, "album"); + MP_KVS_REGFNC(mediaType, "mediaType"); + MP_KVS_REGFNC(bitRate, "bitRate"); + MP_KVS_REGFNC(sampleRate, "sampleRate"); + MP_KVS_REGFNC(length, "length"); + MP_KVS_REGFNC(position, "position"); + MP_KVS_REGFNC(status, "status"); + MP_KVS_REGFNC(player, "player"); + MP_KVS_REGFNC(playerList, "playerList"); + MP_KVS_REGFNC(localFile, "localFile"); + MP_KVS_REGFNC(amipEval, "amipEval"); + MP_KVS_REGFNC(channels, "channels"); + MP_KVS_REGFNC(getListLength, "getListLength"); + MP_KVS_REGFNC(getPlayListPos, "getPlayListPos"); + MP_KVS_REGFNC(getEqData, "getEqData"); + MP_KVS_REGFNC(getRepeat, "getRepeat"); + MP_KVS_REGFNC(getShuffle, "getShuffle"); + MP_KVS_REGFNC(getVol, "getVol"); + /* // Crissi m->registerFunction( "getmp3tag_date", mediaplayer_fnc_getmp3tag_date ); m->registerFunction( "getmp3tag_version", mediaplayer_fnc_getmp3tag_version ); @@ -1709,30 +1711,30 @@ static bool mediaplayer_module_init( KviModule * m ) return true; } -static bool mediaplayer_module_cleanup( KviModule * ) +static bool mediaplayer_module_cleanup(KviModule *) { delete g_pDescriptorList; return true; } -static bool mediaplayer_module_can_unload( KviModule * ) +static bool mediaplayer_module_can_unload(KviModule *) { return true; } -static bool mediaplayer_module_ctrl(KviModule *,const char * operation,void * param) +static bool mediaplayer_module_ctrl(KviModule *, const char * operation, void * param) { - if(kvi_strEqualCI(operation,"getAvailableMediaPlayers")) + if(kvi_strEqualCI(operation, "getAvailableMediaPlayers")) { // we expect param to be a pointer to QStringList QStringList * l = (QStringList *)param; - for(MpInterfaceDescriptor * d = g_pDescriptorList->first();d;d = g_pDescriptorList->next()) + for(MpInterfaceDescriptor * d = g_pDescriptorList->first(); d; d = g_pDescriptorList->next()) { l->append(d->name()); } return true; } - if(kvi_strEqualCI(operation,"detectMediaPlayer")) + if(kvi_strEqualCI(operation, "detectMediaPlayer")) { auto_detect_player(0); return true; @@ -1741,18 +1743,17 @@ static bool mediaplayer_module_ctrl(KviModule *,const char * operation,void * pa } KVIRC_MODULE( - "mediaplayer", - "4.0.0", - "Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)," \ - "Christoph Thielecke (crissi99 at gmx dot de)," \ - "Tonino Imbesi (grifisx at barmes dot org)," \ - "Alessandro Carbone (elfonol at gmail dot com)," \ - "Alexey Uzhva (wizard at opendoor dot ru)," \ - "Serge Baranov (sbaranov at gmail dot com)", - "Interface to various media players", - mediaplayer_module_init, - mediaplayer_module_can_unload, - mediaplayer_module_ctrl, - mediaplayer_module_cleanup, - "mediaplayer" -) + "mediaplayer", + "4.0.0", + "Copyright (C) 2001-2010 Szymon Stefanek (pragma at kvirc dot net)," + "Christoph Thielecke (crissi99 at gmx dot de)," + "Tonino Imbesi (grifisx at barmes dot org)," + "Alessandro Carbone (elfonol at gmail dot com)," + "Alexey Uzhva (wizard at opendoor dot ru)," + "Serge Baranov (sbaranov at gmail dot com)", + "Interface to various media players", + mediaplayer_module_init, + mediaplayer_module_can_unload, + mediaplayer_module_ctrl, + mediaplayer_module_cleanup, + "mediaplayer") diff --git a/src/modules/mediaplayer/winamp.cpp b/src/modules/mediaplayer/winamp.cpp index a1ee7003d..f43952557 100644 --- a/src/modules/mediaplayer/winamp.cpp +++ b/src/modules/mediaplayer/winamp.cpp @@ -25,18 +25,16 @@ #include <windows.h> #include <process.h> - // // This is a winamp-kvirc interface plugin // // This stuff is compiled only on windows, as a separate dll module - typedef struct { int version; - char *description; + char * description; int (*init)(); void (*config)(); void (*quit)(); @@ -46,16 +44,14 @@ typedef struct #define GPPHDR_VER 0x10 -extern winampGeneralPurposePlugin *gen_plugins[256]; +extern winampGeneralPurposePlugin * gen_plugins[256]; typedef winampGeneralPurposePlugin * (*winampGeneralPurposePluginGetter)(); int init(); void quit(); void config(); - -winampGeneralPurposePlugin plugin = -{ +winampGeneralPurposePlugin plugin = { GPPHDR_VER, "KVIrc interface plugin 1.0", init, @@ -83,11 +79,11 @@ BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lp #define KVIRC_WM_USER_CHECK 13123 #define KVIRC_WM_USER_CHECK_REPLY 13124 -void *lpWndProcOld = 0; +void * lpWndProcOld = 0; char szBuffer[4096]; -LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) +LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if(message == WM_USER) { @@ -99,35 +95,37 @@ LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) } if(lParam == KVIRC_WM_USER_GETTITLE) { - int idx = (int)SendMessage(hwnd,WM_USER,0,IPC_GETLISTPOS); + int idx = (int)SendMessage(hwnd, WM_USER, 0, IPC_GETLISTPOS); if(idx != -1) { - char * szTitle = (char *)SendMessage(hwnd,WM_USER,idx,IPC_GETPLAYLISTTITLE); - strcpy(szBuffer,szTitle); + char * szTitle = (char *)SendMessage(hwnd, WM_USER, idx, IPC_GETPLAYLISTTITLE); + strcpy(szBuffer, szTitle); return strlen(szBuffer); } - } else if(lParam == KVIRC_WM_USER_GETFILE) + } + else if(lParam == KVIRC_WM_USER_GETFILE) { - int idx = (int)SendMessage(hwnd,WM_USER,0,IPC_GETLISTPOS); + int idx = (int)SendMessage(hwnd, WM_USER, 0, IPC_GETLISTPOS); if(idx != -1) { - char * szTitle = (char *)SendMessage(hwnd,WM_USER,idx,IPC_GETPLAYLISTFILE); - strcpy(szBuffer,szTitle); + char * szTitle = (char *)SendMessage(hwnd, WM_USER, idx, IPC_GETPLAYLISTFILE); + strcpy(szBuffer, szTitle); return strlen(szBuffer); } - } else if((lParam >= KVIRC_WM_USER_TRANSFER) && (lParam < (KVIRC_WM_USER_TRANSFER + 4096))) + } + else if((lParam >= KVIRC_WM_USER_TRANSFER) && (lParam < (KVIRC_WM_USER_TRANSFER + 4096))) { - return (LRESULT) szBuffer[lParam - KVIRC_WM_USER_TRANSFER]; + return (LRESULT)szBuffer[lParam - KVIRC_WM_USER_TRANSFER]; } } } - return CallWindowProc((WNDPROC)lpWndProcOld,hwnd,message,wParam,lParam); + return CallWindowProc((WNDPROC)lpWndProcOld, hwnd, message, wParam, lParam); } int init() { - lpWndProcOld = (void *) GetWindowLong(plugin.hwndParent,GWLP_WNDPROC); - SetWindowLongPtr(plugin.hwndParent,GWLP_WNDPROC,(intptr_t)WndProc); + lpWndProcOld = (void *)GetWindowLong(plugin.hwndParent, GWLP_WNDPROC); + SetWindowLongPtr(plugin.hwndParent, GWLP_WNDPROC, (intptr_t)WndProc); return 0; } @@ -139,11 +137,7 @@ void config() { } - - - - -extern "C" __declspec( dllexport ) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() +extern "C" __declspec(dllexport) winampGeneralPurposePlugin * winampGetGeneralPurposePlugin() { return &plugin; } |
