2 * Copyright 2007 Alex Merry <alex.merry@kdemail.net>
4 * Based on Xmms support in the Kopete Now Listening plugin
5 * Copyright 2002 by Will Stephenson <will@stevello.free-online.co.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License version 2 as
9 * published by the Free Software Foundation
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details
16 * You should have received a copy of the GNU Library General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 XmmsFactory::XmmsFactory(QObject
* parent
)
30 : PollingPlayerFactory(parent
)
32 setObjectName("XmmsFactory");
35 Player::Ptr
XmmsFactory::create(const QVariantList
& args
)
38 if (!args
.isEmpty() && args
.first().canConvert
<int>()) {
39 session
= args
.first().toInt();
41 return Player::Ptr(0);
44 if (xmms_remote_is_running(session
)) {
45 Xmms
* player
= new Xmms(session
, this);
46 kDebug() << "Creating a player for XMMS session" << session
;
47 return Player::Ptr(player
);
49 return Player::Ptr(0);
52 bool XmmsFactory::exists(const QVariantList
& args
)
55 if (!args
.isEmpty() && args
.first().canConvert
<int>()) {
56 session
= args
.first().toInt();
58 return (session
>= 0) && xmms_remote_is_running(session
);
65 Xmms::Xmms(int session
, PlayerFactory
* factory
)
72 setName("XMMS" + QString::number(m_session
));
80 bool Xmms::isRunning()
82 return xmms_remote_is_running(m_session
);
85 Player::State
Xmms::state()
87 if (xmms_remote_is_paused(m_session
)) {
89 } else if (xmms_remote_is_playing(m_session
)) {
95 QString
Xmms::artist()
97 // let's hope no-one changes the default title string
98 QString track
= xmms_remote_get_playlist_title(m_session
, xmms_remote_get_playlist_pos(0));
99 return track
.section(" - ", 0, 0);
102 QString
Xmms::album()
107 QString
Xmms::title()
109 // let's hope no-one changes the default title string
110 QString track
= xmms_remote_get_playlist_title(m_session
, xmms_remote_get_playlist_pos(0));
111 return track
.section(" - ", -1, -1);
114 int Xmms::trackNumber()
116 // we can get the playlist pos, but that's not what we mean by "trackNumber"
120 QString
Xmms::comment()
125 QString
Xmms::genre()
132 return xmms_remote_get_playlist_time(m_session
, xmms_remote_get_playlist_pos(0));
137 return xmms_remote_get_output_time(m_session
);
142 return xmms_remote_get_main_volume(m_session
);
147 xmms_remote_play(m_session
);
152 xmms_remote_pause(m_session
);
157 xmms_remote_stop(m_session
);
160 void Xmms::previous()
162 xmms_remote_playlist_prev(m_session
);
167 xmms_remote_playlist_next(m_session
);
170 void Xmms::setVolume(qreal volume
)
172 xmms_remote_set_main_volume(m_session
, volume
);
175 void Xmms::seek(int time
)
177 xmms_remote_jump_to_time(m_session
, time
);