Music Hub  ..
A session-wide music playback service
track_list_stub.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
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.
7  *
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.
12  *
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/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #include "track_list_stub.h"
20 
21 #include <core/media/player.h>
22 #include <core/media/track_list.h>
23 
24 #include "property_stub.h"
25 #include "track_list_traits.h"
26 #include "the_session_bus.h"
27 
28 #include "mpris/track_list.h"
29 
30 #include <core/dbus/property.h>
31 #include <core/dbus/types/object_path.h>
32 #include <core/dbus/types/variant.h>
33 #include <core/dbus/types/stl/map.h>
34 #include <core/dbus/types/stl/vector.h>
35 
36 #include <limits>
37 
38 namespace dbus = core::dbus;
39 namespace media = core::ubuntu::media;
40 
42 {
45  const std::shared_ptr<media::Player>& parent,
46  const dbus::Object::Ptr& object)
47  : impl(impl),
48  parent(parent),
49  object(object),
50  can_edit_tracks(object->get_property<mpris::TrackList::Properties::CanEditTracks>()),
51  tracks(object->get_property<mpris::TrackList::Properties::Tracks>())
52  {
53  }
54 
56  std::shared_ptr<media::Player> parent;
57  dbus::Object::Ptr object;
58 
59  std::shared_ptr<core::dbus::Property<mpris::TrackList::Properties::CanEditTracks>> can_edit_tracks;
60  std::shared_ptr<core::dbus::Property<mpris::TrackList::Properties::Tracks>> tracks;
61 
62  core::Signal<media::TrackList::ContainerTrackIdTuple> on_track_list_replaced;
63  core::Signal<Track::Id> on_track_added;
64  core::Signal<Track::Id> on_track_removed;
65  core::Signal<Track::Id> on_track_changed;
66  core::Signal<std::pair<Track::Id, bool>> on_go_to_track;
67 };
68 
70  const std::shared_ptr<media::Player>& parent,
71  const core::dbus::Object::Ptr& object)
72  : d(new Private(this, parent, object))
73 {
74 }
75 
77 {
78 }
79 
80 const core::Property<bool>& media::TrackListStub::can_edit_tracks() const
81 {
82  return *d->can_edit_tracks;
83 }
84 
85 const core::Property<media::TrackList::Container>& media::TrackListStub::tracks() const
86 {
87  return *d->tracks;
88 }
89 
91 {
92  auto op = d->object->invoke_method_synchronously<
93  mpris::TrackList::GetTracksMetadata,
94  std::map<std::string, std::string>>(id);
95 
96  if (op.is_error())
97  throw std::runtime_error("Problem querying meta data for track: " + op.error());
98 
99  media::Track::MetaData md;
100  for(auto pair : op.value())
101  {
102  md.set(pair.first, pair.second);
103  }
104  return md;
105 }
106 
108  const media::Track::UriType& uri,
109  const media::Track::Id& id,
110  bool make_current)
111 {
112  auto op = d->object->invoke_method_synchronously<mpris::TrackList::AddTrack, void>(
113  uri,
114  id,
115  make_current);
116 
117  if (op.is_error())
118  throw std::runtime_error("Problem adding track: " + op.error());
119 }
120 
122 {
123  auto op = d->object->invoke_method_synchronously<mpris::TrackList::RemoveTrack, void>(
124  track);
125 
126  if (op.is_error())
127  throw std::runtime_error("Problem removing track: " + op.error());
128 }
129 
130 void media::TrackListStub::go_to(const media::Track::Id& track, bool toggle_player_state)
131 {
132  (void) toggle_player_state;
133  auto op = d->object->invoke_method_synchronously<mpris::TrackList::GoTo, void>(
134  track);
135 
136  if (op.is_error())
137  throw std::runtime_error("Problem adding track: " + op.error());
138 }
139 
141 {
142  // TODO: Add this to the dbus interface on the server and implement a proper dbus method call
143  return media::Track::Id{"/empty/track/id"};
144 }
145 
147 {
148  // TODO: Add this to the dbus interface on the server and implement a proper dbus method call
149  return media::Track::Id{"/empty/track/id"};
150 }
151 
153 {
154  std::cerr << "shuffle_tracks() does nothing from the client side" << std::endl;
155 }
156 
158 {
159  std::cerr << "unshuffle_tracks() does nothing from the client side" << std::endl;
160 }
161 
163 {
164  std::cerr << "reset() does nothing from the client side" << std::endl;
165 }
166 
167 const core::Signal<media::TrackList::ContainerTrackIdTuple>& media::TrackListStub::on_track_list_replaced() const
168 {
169  std::cout << "Signal on_track_list_replaced arrived via the bus" << std::endl;
170  return d->on_track_list_replaced;
171 }
172 
173 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_added() const
174 {
175  std::cout << "Signal on_track_added arrived via the bus" << std::endl;
176  return d->on_track_added;
177 }
178 
179 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_removed() const
180 {
181  std::cout << "Signal on_track_removed arrived via the bus" << std::endl;
182  return d->on_track_removed;
183 }
184 
185 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_changed() const
186 {
187  return d->on_track_changed;
188 }
189 
190 const core::Signal<std::pair<media::Track::Id, bool>>& media::TrackListStub::on_go_to_track() const
191 {
192  return d->on_go_to_track;
193 }
Private(TrackListStub *impl, const std::shared_ptr< media::Player > &parent, const dbus::Object::Ptr &object)
core::Signal< Track::Id > on_track_removed
std::shared_ptr< core::dbus::Property< mpris::TrackList::Properties::CanEditTracks > > can_edit_tracks
core::Signal< Track::Id > on_track_changed
const core::Property< bool > & can_edit_tracks() const
void add_track_with_uri_at(const Track::UriType &uri, const Track::Id &position, bool make_current)
core::Signal< media::TrackList::ContainerTrackIdTuple > on_track_list_replaced
Track::MetaData query_meta_data_for_track(const Track::Id &id)
void remove_track(const Track::Id &id)
void set(const typename Tag::ValueType &value)
Definition: track.h:63
const core::Signal< Track::Id > & on_track_changed() const
const core::Signal< Track::Id > & on_track_added() const
const core::Signal< std::pair< Track::Id, bool > > & on_go_to_track() const
std::shared_ptr< media::Player > parent
void go_to(const Track::Id &track, bool toggle_player_state)
TrackListStub(const std::shared_ptr< Player > &parent, const core::dbus::Object::Ptr &object)
const core::Property< Container > & tracks() const
const core::Signal< Track::Id > & on_track_removed() const
core::Signal< Track::Id > on_track_added
const core::Signal< ContainerTrackIdTuple > & on_track_list_replaced() const
std::shared_ptr< core::dbus::Property< mpris::TrackList::Properties::Tracks > > tracks
std::string UriType
Definition: track.h:40
core::Signal< std::pair< Track::Id, bool > > on_go_to_track