Plasma
xmms.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "xmms.h"
00023 #include "xmms_p.h"
00024
00025 #include <kdebug.h>
00026
00027 #include <xmmsctrl.h>
00028
00029 XmmsFactory::XmmsFactory(QObject* parent)
00030 : PollingPlayerFactory(parent)
00031 {
00032 }
00033
00034 Player::Ptr XmmsFactory::create(const QVariantList& args)
00035 {
00036 int session = 0;
00037 if (!args.isEmpty() && args.first().canConvert<int>()) {
00038 session = args.first().toInt();
00039 if (session < 0) {
00040 return Player::Ptr(0);
00041 }
00042 }
00043 if (xmms_remote_is_running(session)) {
00044 Xmms* player = new Xmms(session, this);
00045 kDebug() << "Creating a player for XMMS session" << session;
00046 return Player::Ptr(player);
00047 }
00048 return Player::Ptr(0);
00049 }
00050
00051 bool XmmsFactory::exists(const QVariantList& args)
00052 {
00053 int session = 0;
00054 if (!args.isEmpty() && args.first().canConvert<int>()) {
00055 session = args.first().toInt();
00056 }
00057 return (session >= 0) && xmms_remote_is_running(session);
00058 }
00059
00060
00061
00062
00063
00064 Xmms::Xmms(int session, PlayerFactory* factory)
00065 : Player(factory),
00066 m_session(session)
00067 {
00068 if (m_session == 0) {
00069 setName("XMMS");
00070 } else {
00071 setName("XMMS" + QString::number(m_session));
00072 }
00073 }
00074
00075 Xmms::~Xmms()
00076 {
00077 }
00078
00079 bool Xmms::isRunning()
00080 {
00081 return xmms_remote_is_running(m_session);
00082 }
00083
00084 Player::State Xmms::state()
00085 {
00086 if (xmms_remote_is_paused(m_session)) {
00087 return Paused;
00088 } else if (xmms_remote_is_playing(m_session)) {
00089 return Playing;
00090 }
00091 return Stopped;
00092 }
00093
00094 QString Xmms::artist()
00095 {
00096
00097 QString track = xmms_remote_get_playlist_title(m_session, xmms_remote_get_playlist_pos(0));
00098 return track.section(" - ", 0, 0);
00099 }
00100
00101 QString Xmms::album()
00102 {
00103 return QString();
00104 }
00105
00106 QString Xmms::title()
00107 {
00108
00109 QString track = xmms_remote_get_playlist_title(m_session, xmms_remote_get_playlist_pos(0));
00110 return track.section(" - ", -1, -1);
00111 }
00112
00113 int Xmms::trackNumber()
00114 {
00115
00116 return 0;
00117 }
00118
00119 QString Xmms::comment()
00120 {
00121 return QString();
00122 }
00123
00124 QString Xmms::genre()
00125 {
00126 return QString();
00127 }
00128
00129 int Xmms::length()
00130 {
00131 return xmms_remote_get_playlist_time(m_session, xmms_remote_get_playlist_pos(0));
00132 }
00133
00134 int Xmms::position()
00135 {
00136 return xmms_remote_get_output_time(m_session);
00137 }
00138
00139 float Xmms::volume()
00140 {
00141 return xmms_remote_get_main_volume(m_session);
00142 }
00143
00144 void Xmms::play()
00145 {
00146 xmms_remote_play(m_session);
00147 }
00148
00149 void Xmms::pause()
00150 {
00151 xmms_remote_pause(m_session);
00152 }
00153
00154 void Xmms::stop()
00155 {
00156 xmms_remote_stop(m_session);
00157 }
00158
00159 void Xmms::previous()
00160 {
00161 xmms_remote_playlist_prev(m_session);
00162 }
00163
00164 void Xmms::next()
00165 {
00166 xmms_remote_playlist_next(m_session);
00167 }
00168
00169 void Xmms::setVolume(float volume)
00170 {
00171 xmms_remote_set_main_volume(m_session, volume);
00172 }
00173
00174 void Xmms::seek(int time)
00175 {
00176 xmms_remote_jump_to_time(m_session, time);
00177 }
00178
00179
00180 #include "xmms.moc"