Changeset View
Changeset View
Standalone View
Standalone View
plugins/mprisremote/mprisremoteplayer.cpp
- This file was added.
1 | /** | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Nicolas Fella <nicolas.fella@gmx.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <networkpacket.h> | ||||
22 | #include <QDateTime> | ||||
23 | | ||||
24 | #include "mprisremoteplayer.h" | ||||
25 | | ||||
26 | MprisRemotePlayer::MprisRemotePlayer() : | ||||
27 | m_playing(false) | ||||
28 | , m_nowPlaying() | ||||
29 | , m_volume(50) | ||||
30 | , m_length(0) | ||||
31 | , m_lastPosition(0) | ||||
32 | , m_lastPositionTime() | ||||
33 | , m_title() | ||||
34 | , m_artist() | ||||
35 | , m_album() | ||||
36 | { | ||||
37 | } | ||||
38 | | ||||
39 | MprisRemotePlayer::~MprisRemotePlayer() | ||||
40 | { | ||||
41 | } | ||||
42 | | ||||
43 | void MprisRemotePlayer::parseNetworkPacket(const NetworkPacket& np) | ||||
44 | { | ||||
45 | m_nowPlaying = np.get<QString>(QStringLiteral("nowPlaying"), m_nowPlaying); | ||||
46 | m_title = np.get<QString>(QStringLiteral("title"), m_title); | ||||
47 | m_artist = np.get<QString>(QStringLiteral("artist"), m_artist); | ||||
48 | m_album = np.get<QString>(QStringLiteral("album"), m_album); | ||||
49 | m_volume = np.get<int>(QStringLiteral("volume"), m_volume); | ||||
50 | m_length = np.get<int>(QStringLiteral("length"), m_length); | ||||
51 | if(np.has(QStringLiteral("pos"))){ | ||||
52 | m_lastPosition = np.get<int>(QStringLiteral("pos"), m_lastPosition); | ||||
53 | m_lastPositionTime = QDateTime::currentMSecsSinceEpoch(); | ||||
54 | } | ||||
55 | m_playing = np.get<bool>(QStringLiteral("isPlaying"), m_playing); | ||||
56 | } | ||||
57 | | ||||
58 | long MprisRemotePlayer::position() const | ||||
59 | { | ||||
60 | if(m_playing) { | ||||
61 | return m_lastPosition + (QDateTime::currentMSecsSinceEpoch() - m_lastPositionTime); | ||||
62 | } else { | ||||
63 | return m_lastPosition; | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
67 | void MprisRemotePlayer::setPosition(long position) | ||||
68 | { | ||||
69 | m_lastPosition = position; | ||||
70 | m_lastPositionTime = QDateTime::currentMSecsSinceEpoch(); | ||||
71 | } | ||||
72 | | ||||
73 | int MprisRemotePlayer::volume() const | ||||
74 | { | ||||
75 | return m_volume; | ||||
76 | } | ||||
77 | | ||||
78 | long int MprisRemotePlayer::length() const | ||||
79 | { | ||||
80 | return m_length; | ||||
81 | } | ||||
82 | | ||||
83 | bool MprisRemotePlayer::playing() const | ||||
84 | { | ||||
85 | return m_playing; | ||||
86 | } | ||||
87 | | ||||
88 | QString MprisRemotePlayer::nowPlaying() const | ||||
89 | { | ||||
90 | return m_nowPlaying; | ||||
91 | } | ||||
92 | | ||||
93 | QString MprisRemotePlayer::title() const | ||||
94 | { | ||||
95 | return m_title; | ||||
96 | } | ||||
97 | | ||||
98 | QString MprisRemotePlayer::artist() const | ||||
99 | { | ||||
100 | return m_artist; | ||||
101 | } | ||||
102 | | ||||
103 | QString MprisRemotePlayer::album() const | ||||
104 | { | ||||
105 | return m_album; | ||||
106 | } |