add more spacing
[personal-kdebase.git] / workspace / plasma / dataengines / nowplaying / playerinterface / xmms.cpp
blob325877893b58a0756a266c84194e62a99e2ebc8a
1 /*
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.
22 #include "xmms.h"
23 #include "xmms_p.h"
25 #include <kdebug.h>
27 #include <xmmsctrl.h>
29 XmmsFactory::XmmsFactory(QObject* parent)
30 : PollingPlayerFactory(parent)
32 setObjectName("XmmsFactory");
35 Player::Ptr XmmsFactory::create(const QVariantList& args)
37 int session = 0;
38 if (!args.isEmpty() && args.first().canConvert<int>()) {
39 session = args.first().toInt();
40 if (session < 0) {
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)
54 int session = 0;
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)
66 : Player(factory),
67 m_session(session)
69 if (m_session == 0) {
70 setName("XMMS");
71 } else {
72 setName("XMMS" + QString::number(m_session));
76 Xmms::~Xmms()
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)) {
88 return Paused;
89 } else if (xmms_remote_is_playing(m_session)) {
90 return Playing;
92 return Stopped;
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()
104 return QString();
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"
117 return 0;
120 QString Xmms::comment()
122 return QString();
125 QString Xmms::genre()
127 return QString();
130 int Xmms::length()
132 return xmms_remote_get_playlist_time(m_session, xmms_remote_get_playlist_pos(0));
135 int Xmms::position()
137 return xmms_remote_get_output_time(m_session);
140 float Xmms::volume()
142 return xmms_remote_get_main_volume(m_session);
145 void Xmms::play()
147 xmms_remote_play(m_session);
150 void Xmms::pause()
152 xmms_remote_pause(m_session);
155 void Xmms::stop()
157 xmms_remote_stop(m_session);
160 void Xmms::previous()
162 xmms_remote_playlist_prev(m_session);
165 void Xmms::next()
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);
181 #include "xmms.moc"