2
* Copyright © 2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#ifndef MPRIS_PLAYLISTS_H_
20
#define MPRIS_PLAYLISTS_H_
22
#include <core/dbus/macros.h>
23
#include <core/dbus/object.h>
24
#include <core/dbus/property.h>
25
#include <core/dbus/interfaces/properties.h>
26
#include <core/dbus/types/struct.h>
27
#include <core/dbus/types/variant.h>
39
bool operator !=(const Struct<T>& lhs, const Struct<T>& rhs)
41
return lhs.value != rhs.value;
49
// Models interface org.mpris.MediaPlayer2.Playlists, see:
50
// http://specifications.freedesktop.org/mpris-spec/latest/Playlists_Interface.html
51
// for detailed documentation
54
static const std::string& name()
56
static const std::string s{"org.mpris.MediaPlayer2.Playlists"}; return s;
59
// All known orderings
62
// Alphabetical ordering by name, ascending.
63
static constexpr const char* alphabetical{"Alphabetical"};
64
// Ordering by creation date, oldest first.
65
static constexpr const char* creation_date{"CreationDate"};
66
// Ordering by last modified date, oldest first.
67
static constexpr const char* modified_date{"ModifiedDate"};
68
// Ordering by date of last playback, oldest first.
69
static constexpr const char* last_play_date{"LastPlayDate"};
70
// A user-defined ordering.
71
static constexpr const char* user_defined{"UserDefined"};
74
// A datastructure describing a playlist.
75
typedef core::dbus::types::Struct
79
// A unique identifier for the playlist.
80
// This should remain the same if the playlist is renamed.
81
core::dbus::types::ObjectPath,
82
// The name of the playlist, typically given by the user.
84
// The URI of an (optional) icon.
89
// A data structure describing a playlist, or nothing.
90
typedef core::dbus::types::Struct
94
// Whether this structure refers to a valid playlist.
96
// The playlist, providing Valid is true, otherwise undefined.
105
// Starts playing the given playlist.
106
// Note that this must be implemented. If the media player does not
107
// allow clients to change the playlist, it should not implement this
109
DBUS_CPP_METHOD_DEF(ActivatePlaylist, Playlists)
111
// Gets a set of playlists.
114
// The index of the first playlist to be fetched (according to the ordering).
116
// The maximum number of playlists to fetch.
117
// Order — s (Playlist_Ordering)
118
// The ordering that should be used.
120
// Whether the order should be reversed.
123
// Playlists — a(oss) (Playlist_List)
124
// A list of (at most MaxCount) playlists.
125
DBUS_CPP_METHOD_DEF(GetPlaylists, Playlists)
132
// Indicates that either the Name or Icon attribute of a playlist has changed.
133
// Client implementations should be aware that this signal may not be implemented.
134
DBUS_CPP_SIGNAL_DEF(PlaylistsChanged, Playlists, Playlist)
139
Properties() = delete;
141
// The number of playlists available.
142
DBUS_CPP_READABLE_PROPERTY_DEF(PlaylistCount, Playlists, std::uint32_t)
143
// The available orderings. At least one must be offered.
144
DBUS_CPP_READABLE_PROPERTY_DEF(Orderings, Playlists, std::vector<std::string>)
145
// The currently-active playlist.
146
DBUS_CPP_READABLE_PROPERTY_DEF(ActivePlaylist, Playlists, MaybePlaylist)
151
// Creation time properties go here.
154
// The bus connection that should be used
155
core::dbus::Bus::Ptr bus;
156
// The dbus object that should implement org.mpris.MediaPlayer2
157
core::dbus::Object::Ptr object;
158
// Default values assigned to properties on construction
161
Properties::PlaylistCount::ValueType playlist_count{0};
162
Properties::Orderings::ValueType orderings{{Orderings::alphabetical}};
163
Properties::ActivePlaylist::ValueType active_playlist
165
std::make_tuple(false, Playlist
168
core::dbus::types::ObjectPath{"/"},
176
Skeleton(const Configuration& configuration)
177
: configuration(configuration),
180
configuration.object->get_property<Properties::PlaylistCount>(),
181
configuration.object->get_property<Properties::Orderings>()
185
configuration.object->get_signal<Signals::PlaylistsChanged>()
188
properties.playlist_count->set(configuration.defaults.playlist_count);
189
properties.orderings->set(configuration.defaults.orderings);
192
std::map<std::string, core::dbus::types::Variant> get_all_properties()
194
std::map<std::string, core::dbus::types::Variant> dict;
195
dict[Properties::PlaylistCount::name()] = core::dbus::types::Variant::encode(properties.playlist_count->get());
196
dict[Properties::Orderings::name()] = core::dbus::types::Variant::encode(properties.orderings->get());
201
Configuration configuration;
205
std::shared_ptr<core::dbus::Property<Properties::PlaylistCount>> playlist_count;
206
std::shared_ptr<core::dbus::Property<Properties::Orderings>> orderings;
211
core::dbus::Signal<Signals::PlaylistsChanged, Signals::PlaylistsChanged::ArgumentType>::Ptr playlist_changed;
216
#endif // MPRIS_PLAYLISTS_H_