2 // C++ Implementation: playback
4 // Author: Oliver Groß <z.o.gross@gmx.de>, (C) 2008
6 // Copyright: See COPYING file that comes with this distribution
14 QPlayback::QPlayback(QClient
* parent
) : QObject(parent
), m_Connection(0) {
15 connect(parent
, SIGNAL(connectionChanged(xmmsc_connection_t
*)),
16 this, SLOT(setConnection(xmmsc_connection_t
*)));
17 if (parent
->isConnectedToServer())
18 setConnection(parent
->connection());
23 QPlayback::~QPlayback() {
26 void QPlayback::setVolumeChannel(const void * key
, xmmsc_result_value_type_t
, const void * value
, void * instance
) {
28 QPlayback
* playback
= static_cast<QPlayback
*>(instance
);
29 QString
hashKey((const char *)key
);
30 quint32 volume
= XPOINTER_TO_INT(value
);
31 if (playback
->m_Volume
.contains(hashKey
))
32 playback
->m_Volume
[hashKey
] = volume
;
34 playback
->m_Volume
.insert(hashKey
, volume
);
38 //callback for the "volume changed"-broadcast
39 void QPlayback::volumeCallback(xmmsc_result_t
* result
, void * instance
) {
40 if (xmmsc_result_iserror(result
)) {
41 qDebug() << "Error: (QPlayback::volumeCallback)" << xmmsc_result_get_error(result
);
46 QPlayback
* playback
= static_cast<QPlayback
*>(instance
);
47 xmmsc_result_dict_foreach(result
, setVolumeChannel
, instance
);
48 emit playback
->volumeChanged();
50 //xmmsc_result_unref(result);
53 //callback for the "status changed"-broadcast
54 void QPlayback::statusCallback(xmmsc_result_t
* result
, void * instance
) {
55 if (xmmsc_result_iserror(result
)) {
56 qDebug() << "Error: (QPlayback::statusCallback)" << xmmsc_result_get_error(result
);
61 QPlayback
* playback
= static_cast<QPlayback
*>(instance
);
63 xmmsc_result_get_uint(result
, &buffer
);
64 playback
->m_Status
= (xmms_playback_status_t
)buffer
;
65 emit playback
->statusChanged(playback
->m_Status
);
67 //xmmsc_result_unref(result);
70 //callback for the "id changed"-broadcast
71 void QPlayback::idCallback(xmmsc_result_t
* result
, void * instance
) {
72 if (xmmsc_result_iserror(result
)) {
73 qDebug() << "Error: (QPlayback::idCallback)" << xmmsc_result_get_error(result
);
78 QPlayback
* playback
= static_cast<QPlayback
*>(instance
);
79 xmmsc_result_get_uint(result
, &playback
->m_CurrentID
);
80 emit playback
->idChanged(playback
->m_CurrentID
);
82 //xmmsc_result_unref(result);
85 //callback for the "play time changed"-signal
86 void QPlayback::playTimeCallback(xmmsc_result_t
* result
, void * instance
) {
87 if (xmmsc_result_iserror(result
)) {
88 qDebug() << "Error: (QPlayback::playTimeCallback)" << xmmsc_result_get_error(result
);
93 QPlayback
* playback
= static_cast<QPlayback
*>(instance
);
95 xmmsc_result_get_uint(result
, &time
);
96 xmmsc_result_unref(xmmsc_result_restart(result
));
97 emit playback
->playTimeChanged(time
);
99 xmmsc_result_unref(result
);
102 void QPlayback::reset() {
104 connectNotifierUnref(xmmsc_playback_volume_get(m_Connection
), volumeCallback
, this);
105 connectNotifierUnref(xmmsc_playback_current_id(m_Connection
), idCallback
, this);
106 connectNotifierUnref(xmmsc_playback_status(m_Connection
), statusCallback
, this);
110 void QPlayback::setConnection(xmmsc_connection_t
* connection
) {
111 if (m_Connection
== connection
)
118 disconnectNotifierUnref(xmmsc_broadcast_playback_volume_changed(m_Connection
));
119 disconnectNotifierUnref(xmmsc_broadcast_playback_current_id(m_Connection
));
120 disconnectNotifierUnref(xmmsc_broadcast_playback_status(m_Connection
));
121 disconnectNotifierUnref(xmmsc_signal_playback_playtime(m_Connection
));
124 m_Connection
= connection
;
126 m_Status
= XMMS_PLAYBACK_STATUS_STOP
;
130 connectNotifierUnref(xmmsc_broadcast_playback_volume_changed(m_Connection
), volumeCallback
, this);
131 connectNotifierUnref(xmmsc_broadcast_playback_current_id(m_Connection
), idCallback
, this);
132 connectNotifierUnref(xmmsc_broadcast_playback_status(m_Connection
), statusCallback
, this);
133 connectNotifierUnref(xmmsc_signal_playback_playtime(m_Connection
), playTimeCallback
, this);
135 connectNotifierUnref(xmmsc_playback_volume_get(m_Connection
), volumeCallback
, this);
136 connectNotifierUnref(xmmsc_playback_current_id(m_Connection
), idCallback
, this);
137 connectNotifierUnref(xmmsc_playback_status(m_Connection
), statusCallback
, this);
141 emit
volumeChanged();
142 emit
statusChanged(XMMS_PLAYBACK_STATUS_STOP
);
146 void QPlayback::start() {
147 xmmsc_result_unref(xmmsc_playback_start(m_Connection
));
150 void QPlayback::pause() {
151 xmmsc_result_unref(xmmsc_playback_pause(m_Connection
));
154 void QPlayback::stop() {
155 xmmsc_result_unref(xmmsc_playback_stop(m_Connection
));
158 void QPlayback::tickle() {
159 xmmsc_result_unref(xmmsc_playback_tickle(m_Connection
));
162 void QPlayback::setVolume(int volume
, QString channel
) {
163 if (channel
.isEmpty()) {
164 foreach(QString i
, m_Volume
.keys())
165 xmmsc_result_unref(xmmsc_playback_volume_set(m_Connection
, i
.toAscii().data(), volume
));
168 xmmsc_result_unref(xmmsc_playback_volume_set(m_Connection
, channel
.toAscii().data(), volume
));
171 void QPlayback::setNext(quint32 position
) {
172 xmmsc_result_unref(xmmsc_playlist_set_next(m_Connection
, position
));
175 void QPlayback::setPlayTime(int time
) {
176 xmmsc_result_unref(xmmsc_playback_seek_ms(m_Connection
, time
));