Parent: [82cbd0] (diff)

Child: [1cc5a7] (diff)

Download this file

playlistohrd.cpp    135 lines (117 with data), 4.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <QDebug>
#include "playlistohrd.h"
#include "libupnpp/log.hxx"
using namespace UPnPP;
// We take ownership of the OHRad and OhInf objects. The latter can be NULL
PlaylistOHRD::PlaylistOHRD(OHRad *ohrd, OHInf *ohif, QObject * parent)
: Playlist(parent), m_ohrdo(ohrd), m_ohifo(ohif)
{
// Connections from OpenHome renderer to local playlist
connect(m_ohrdo, SIGNAL(metadataArrayChanged(const MetaDataList&)),
this, SLOT(onRemoteMetaArray(const MetaDataList&)));
connect(m_ohrdo, SIGNAL(currentTrackId(int)),
this, SLOT(onRemoteCurrentTrackid(int)));
connect(m_ohrdo, SIGNAL(audioStateChanged(int, const char *)),
this, SLOT(onRemoteTpState(int, const char *)));
connect(m_ohrdo, SIGNAL(connectionLost()), this, SIGNAL(connectionLost()));
if (m_ohifo) {
connect(m_ohifo, SIGNAL(metatextChanged(const MetaData&)),
this, SIGNAL(sig_track_metadata(const MetaData&)));
}
// Connections from local playlist to openhome
connect(this, SIGNAL(sig_pause()), m_ohrdo, SLOT(pause()));
connect(this, SIGNAL(sig_stop()), m_ohrdo, SLOT(stop()));
connect(this, SIGNAL(sig_resume_play()), m_ohrdo, SLOT(play()));
}
static bool samelist(const MetaDataList& mdv1, const MetaDataList& mdv2)
{
if (mdv1.size() != mdv2.size())
return false;
for (unsigned int i = 0; i < mdv1.size(); i++) {
if (mdv1[i].filepath.compare(mdv2[i].filepath))
return false;
}
return true;
}
void PlaylistOHRD::onRemoteMetaArray(const MetaDataList& mdv)
{
qDebug() << "PlaylistOHRD::psl_new_ohrd: " << mdv.size() << " entries";
if (!samelist(mdv, m_meta)) {
m_meta = mdv;
emit sig_playlist_updated(m_meta, m_play_idx, 0);
}
}
void PlaylistOHRD::onRemoteCurrentTrackid(int id)
{
qDebug() << "PlaylistOHRD::onRemoteCurrentTrackid: " << id;
if (id <= 0) {
return;
}
for (vector<MetaData>::iterator it = m_meta.begin();
it != m_meta.end(); it++) {
if (it->id == id) {
m_play_idx = it - m_meta.begin();
// Emit the current index in any case to let the playlist
// UI scroll to show the currently playing track (some
// time after a user interaction scrolled it off)
emit sig_playing_track_changed(m_play_idx);
// If the track id change was caused by the currently
// playing track having been removed, the play index did
// not change but the metadata did, so emit metadata in
// all cases.
MetaData md;
if (m_ohifo && m_ohifo->metatext(md)) {
emit sig_track_metadata(md);
} else {
emit sig_track_metadata(*it);
}
return;
}
}
LOGINF("PlaylistOHRD::onRemoteCurrentTrackid: track not found in array" << endl);
}
void PlaylistOHRD::update_state()
{
m_ohrdo->fetchState();
if (m_ohifo) {
MetaData md;
if (m_ohifo->metatext(md)) {
emit sig_track_metadata(md);
}
}
}
void PlaylistOHRD::psl_change_track_impl(int idx) {
m_ohrdo->setIdx(idx);
m_ohrdo->play();
}
void PlaylistOHRD::psl_play()
{
if (m_tpstate == AUDIO_STOPPED && valid_row(m_selection_min_row)) {
m_ohrdo->setIdx(m_selection_min_row);
}
emit sig_resume_play();
}
void PlaylistOHRD::psl_pause()
{
emit sig_pause();
}
void PlaylistOHRD::psl_stop()
{
emit sig_stop();
}