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