source: smplayer/trunk/src/mpris2/mediaplayer2player.cpp@ 176

Last change on this file since 176 was 175, checked in by Silvan Scherrer, 9 years ago

smplayer: update vendor to version 16.4

File size: 7.6 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2015 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19
20/***********************************************************************
21 * Copyright 2012 Eike Hein <hein@kde.org>
22 * Copyright 2012 Bernd Buschinski <b.buschinski@googlemail.com>
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU General Public License as
26 * published by the Free Software Foundation; either version 2 of
27 * the License or (at your option) version 3 or any later version
28 * accepted by the membership of KDE e.V. (or its successor approved
29 * by the membership of KDE e.V.), which shall act as a proxy
30 * defined in Section 14 of version 3 of the license.
31 *
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
36 *
37 * You should have received a copy of the GNU General Public License
38 * along with this program. If not, see <http://www.gnu.org/licenses/>.
39 ***********************************************************************/
40
41#include "mediaplayer2player.h"
42#include "mpris2.h"
43#include "basegui.h"
44#include "core.h"
45#include "playlist.h"
46
47#include <QCryptographicHash>
48
49static QByteArray makeTrackId(const QString& source)
50{
51 return QByteArray("/org/smplayer/") + "smplayer" + "/tid_" +
52 QCryptographicHash::hash(source.toLocal8Bit(), QCryptographicHash::Sha1)
53 .toHex();
54}
55
56MediaPlayer2Player::MediaPlayer2Player(BaseGui * gui, QObject* parent)
57 : QDBusAbstractAdaptor(parent),
58 m_core(gui->getCore()),
59 m_playlist(gui->getPlaylist())
60{
61// connect(m_core, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
62// connect(m_core, SIGNAL(seekableChanged(bool)), this, SLOT(seekableChanged(bool)));
63 connect(m_core, SIGNAL(mediaPlaying(QString,QString)), this, SLOT(currentSourceChanged()));
64 connect(m_core, SIGNAL(stateChanged(Core::State)), this, SLOT(stateUpdated()));
65 connect(m_core, SIGNAL(mediaInfoChanged()), this, SLOT(emitMetadataChange()));
66 connect(m_core, SIGNAL(volumeChanged(int)), this, SLOT(volumeChanged()));
67}
68
69MediaPlayer2Player::~MediaPlayer2Player()
70{
71}
72
73bool MediaPlayer2Player::CanGoNext() const
74{
75 return true;
76}
77
78void MediaPlayer2Player::Next() const
79{
80 m_playlist->playNext();
81}
82
83bool MediaPlayer2Player::CanGoPrevious() const
84{
85 return true;
86}
87
88void MediaPlayer2Player::Previous() const
89{
90 m_playlist->playPrev();
91}
92
93bool MediaPlayer2Player::CanPause() const
94{
95 return true;
96}
97
98void MediaPlayer2Player::Pause() const
99{
100 m_core->pause();
101}
102
103void MediaPlayer2Player::PlayPause() const
104{
105 m_core->play_or_pause();
106}
107
108void MediaPlayer2Player::Stop() const
109{
110 m_core->stop();
111}
112
113bool MediaPlayer2Player::CanPlay() const
114{
115 return true;
116}
117
118void MediaPlayer2Player::Play() const
119{
120 m_core->play();
121}
122
123void MediaPlayer2Player::SetPosition(const QDBusObjectPath& TrackId, qlonglong Position) const
124{
125 if (TrackId.path().toLocal8Bit() == makeTrackId(m_core->mdat.filename))
126 m_core->seek(static_cast<int>(Position / 1000000));
127}
128
129void MediaPlayer2Player::OpenUri(QString uri) const
130{
131 m_core->open(uri);
132}
133
134QString MediaPlayer2Player::PlaybackStatus() const
135{
136 return m_core->stateToString();
137}
138
139QString MediaPlayer2Player::LoopStatus() const
140{
141 return "None";
142}
143
144void MediaPlayer2Player::setLoopStatus(const QString& loopStatus) const
145{
146 Q_UNUSED(loopStatus)
147}
148
149double MediaPlayer2Player::Rate() const
150{
151 return m_core->mset.speed;
152}
153
154void MediaPlayer2Player::setRate(double rate) const
155{
156 m_core->setSpeed(rate);
157}
158
159bool MediaPlayer2Player::Shuffle() const
160{
161 return false;
162}
163
164void MediaPlayer2Player::setShuffle(bool shuffle) const
165{
166 Q_UNUSED(shuffle)
167}
168
169QVariantMap MediaPlayer2Player::Metadata() const
170{
171 QVariantMap metaData;
172
173 if (!m_core->mdat.initialized)
174 return metaData;
175
176 metaData["mpris:trackid"] = QVariant::fromValue<QDBusObjectPath>(QDBusObjectPath(makeTrackId(m_core->mdat.filename).constData()));
177 metaData["mpris:length"] = m_core->mdat.duration * 1000000;
178
179 if (m_core->mdat.type == TYPE_STREAM)
180 metaData["xesam:url"] = m_core->mdat.stream_url;
181 else
182 metaData["xesam:url"] = m_core->mdat.filename;
183
184 if (!m_core->mdat.clip_album.isEmpty())
185 metaData["xesam:album"] = m_core->mdat.clip_album;
186 if (!m_core->mdat.clip_name.isEmpty())
187 metaData["xesam:title"] = m_core->mdat.clip_name;
188 else if (!m_core->mdat.filename.isEmpty()) {
189 QFileInfo fileInfo(m_core->mdat.filename);
190 metaData["xesam:title"] = fileInfo.fileName();
191 }
192 if (!m_core->mdat.clip_artist.isEmpty())
193 metaData["xesam:artist"] = m_core->mdat.clip_artist;
194 if (!m_core->mdat.clip_genre.isEmpty())
195 metaData["xesam:genre"] = m_core->mdat.clip_genre;
196
197 return metaData;
198}
199
200double MediaPlayer2Player::Volume() const
201{
202 return static_cast<double>(m_core->mset.volume / 100.0);
203}
204
205void MediaPlayer2Player::setVolume(double volume) const
206{
207 m_core->setVolume(static_cast<int>(volume*100));
208}
209
210qlonglong MediaPlayer2Player::Position() const
211{
212 return static_cast<qlonglong>(m_core->mset.current_sec * 1000000);
213}
214
215double MediaPlayer2Player::MinimumRate() const
216{
217 return 0.01;
218}
219
220double MediaPlayer2Player::MaximumRate() const
221{
222 return 100.0;
223}
224
225bool MediaPlayer2Player::CanSeek() const
226{
227 return true;
228}
229
230void MediaPlayer2Player::Seek(qlonglong Offset) const
231{
232 m_core->seek(static_cast<int>(Offset/1000000));
233}
234
235bool MediaPlayer2Player::CanControl() const
236{
237 return true;
238}
239
240void MediaPlayer2Player::tick(qint64 newPos)
241{
242// if (newPos - oldPos > tickInterval + 250 || newPos < oldPos)
243// emit Seeked(newPos * 1000);
244
245 oldPos = newPos;
246}
247
248void MediaPlayer2Player::emitMetadataChange() const
249{
250 QVariantMap properties;
251 properties["Metadata"] = Metadata();
252 Mpris2::signalPropertiesChange(this, properties);
253}
254
255void MediaPlayer2Player::currentSourceChanged() const
256{
257 QVariantMap properties;
258 properties["Metadata"] = Metadata();
259 properties["CanSeek"] = CanSeek();
260 Mpris2::signalPropertiesChange(this, properties);
261}
262
263void MediaPlayer2Player::stateUpdated() const
264{
265 QVariantMap properties;
266 properties["PlaybackStatus"] = PlaybackStatus();
267 properties["CanPause"] = CanPause();
268 Mpris2::signalPropertiesChange(this, properties);
269}
270
271void MediaPlayer2Player::totalTimeChanged() const
272{
273 QVariantMap properties;
274 properties["Metadata"] = Metadata();
275 Mpris2::signalPropertiesChange(this, properties);
276}
277
278void MediaPlayer2Player::seekableChanged(bool seekable) const
279{
280 QVariantMap properties;
281 properties["CanSeek"] = seekable;
282 Mpris2::signalPropertiesChange(this, properties);
283}
284
285void MediaPlayer2Player::volumeChanged() const
286{
287 QVariantMap properties;
288 properties["Volume"] = Volume();
289 Mpris2::signalPropertiesChange(this, properties);
290}
291
292#include "moc_mediaplayer2player.cpp"
Note: See TracBrowser for help on using the repository browser.