~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to plasma/generic/dataengines/nowplaying/playerinterface/xmms.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright 2007 Alex Merry <alex.merry@kdemail.net>
 
3
 *
 
4
 *   Based on Xmms support in the Kopete Now Listening plugin
 
5
 *   Copyright 2002 by Will Stephenson <will@stevello.free-online.co.uk>
 
6
 *
 
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
 
10
 *
 
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
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include "xmms.h"
 
23
#include "xmms_p.h"
 
24
 
 
25
#include <kdebug.h>
 
26
 
 
27
#include <xmmsctrl.h>
 
28
 
 
29
XmmsFactory::XmmsFactory(QObject* parent)
 
30
    : PollingPlayerFactory(parent)
 
31
{
 
32
    setObjectName( QLatin1String("XmmsFactory" ));
 
33
}
 
34
 
 
35
Player::Ptr XmmsFactory::create(const QVariantList& args)
 
36
{
 
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);
 
42
        }
 
43
    }
 
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);
 
48
    }
 
49
    return Player::Ptr(0);
 
50
}
 
51
 
 
52
bool XmmsFactory::exists(const QVariantList& args)
 
53
{
 
54
    int session = 0;
 
55
    if (!args.isEmpty() && args.first().canConvert<int>()) {
 
56
        session = args.first().toInt();
 
57
    }
 
58
    return (session >= 0) && xmms_remote_is_running(session);
 
59
}
 
60
 
 
61
 
 
62
 
 
63
 
 
64
 
 
65
Xmms::Xmms(int session, PlayerFactory* factory)
 
66
    : Player(factory),
 
67
      m_session(session)
 
68
{
 
69
    if (m_session == 0) {
 
70
        setName("XMMS");
 
71
    } else {
 
72
        setName("XMMS" + QString::number(m_session));
 
73
    }
 
74
}
 
75
 
 
76
Xmms::~Xmms()
 
77
{
 
78
}
 
79
 
 
80
bool Xmms::isRunning()
 
81
{
 
82
    return xmms_remote_is_running(m_session);
 
83
}
 
84
 
 
85
Player::State Xmms::state()
 
86
{
 
87
    if (xmms_remote_is_paused(m_session)) {
 
88
        return Paused;
 
89
    } else if (xmms_remote_is_playing(m_session)) {
 
90
        return Playing;
 
91
    }
 
92
    return Stopped;
 
93
}
 
94
 
 
95
QString Xmms::artist()
 
96
{
 
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);
 
100
}
 
101
 
 
102
QString Xmms::album()
 
103
{
 
104
    return QString();
 
105
}
 
106
 
 
107
QString Xmms::title()
 
108
{
 
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);
 
112
}
 
113
 
 
114
int Xmms::trackNumber()
 
115
{
 
116
    // we can get the playlist pos, but that's not what we mean by "trackNumber"
 
117
    return 0;
 
118
}
 
119
 
 
120
QString Xmms::comment()
 
121
{
 
122
    return QString();
 
123
}
 
124
 
 
125
QString Xmms::genre()
 
126
{
 
127
    return QString();
 
128
}
 
129
 
 
130
int Xmms::length()
 
131
{
 
132
    return xmms_remote_get_playlist_time(m_session, xmms_remote_get_playlist_pos(0));
 
133
}
 
134
 
 
135
int Xmms::position()
 
136
{
 
137
    return xmms_remote_get_output_time(m_session);
 
138
}
 
139
 
 
140
float Xmms::volume()
 
141
{
 
142
    return xmms_remote_get_main_volume(m_session);
 
143
}
 
144
 
 
145
void Xmms::play()
 
146
{
 
147
    xmms_remote_play(m_session);
 
148
}
 
149
 
 
150
void Xmms::pause()
 
151
{
 
152
    xmms_remote_pause(m_session);
 
153
}
 
154
 
 
155
void Xmms::stop()
 
156
{
 
157
    xmms_remote_stop(m_session);
 
158
}
 
159
 
 
160
void Xmms::previous()
 
161
{
 
162
    xmms_remote_playlist_prev(m_session);
 
163
}
 
164
 
 
165
void Xmms::next()
 
166
{
 
167
    xmms_remote_playlist_next(m_session);
 
168
}
 
169
 
 
170
void Xmms::setVolume(qreal volume)
 
171
{
 
172
    xmms_remote_set_main_volume(m_session, volume);
 
173
}
 
174
 
 
175
void Xmms::seek(int time)
 
176
{
 
177
    xmms_remote_jump_to_time(m_session, time);
 
178
}
 
179
 
 
180
 
 
181
#include "xmms.moc"