Music Hub  ..
A session-wide music playback service
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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::types::ObjectPath& op)
47  : impl(impl),
48  parent(parent),
49  object(impl->access_service()->object_for_path(op)),
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<void> 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 };
67 
69  const std::shared_ptr<media::Player>& parent,
70  const core::dbus::types::ObjectPath& op)
71  : dbus::Stub<media::TrackList>(the_session_bus()),
72  d(new Private(this, parent, op))
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
93  = d->object->invoke_method_synchronously<
94  mpris::TrackList::GetTracksMetadata,
95  std::map<std::string, std::string>>(id);
96 
97  if (op.is_error())
98  throw std::runtime_error("Problem querying meta data for track: " + op.error());
99 
100  media::Track::MetaData md;
101  for(auto pair : op.value())
102  {
103  md.set(pair.first, pair.second);
104  }
105  return md;
106 }
107 
109  const media::Track::UriType& uri,
110  const media::Track::Id& id,
111  bool make_current)
112 {
113  auto op = d->object->invoke_method_synchronously<mpris::TrackList::AddTrack, void>(
114  uri,
115  id,
116  make_current);
117 
118  if (op.is_error())
119  throw std::runtime_error("Problem adding track: " + op.error());
120 }
121 
123 {
124  auto op = d->object->invoke_method_synchronously<mpris::TrackList::RemoveTrack, void>(
125  track);
126 
127  if (op.is_error())
128  throw std::runtime_error("Problem removing track: " + op.error());
129 }
130 
132 {
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 
140 const core::Signal<void>& media::TrackListStub::on_track_list_replaced() const
141 {
142  return d->on_track_list_replaced;
143 }
144 
145 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_added() const
146 {
147  return d->on_track_added;
148 }
149 
150 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_removed() const
151 {
152  return d->on_track_removed;
153 }
154 
155 const core::Signal<media::Track::Id>& media::TrackListStub::on_track_changed() const
156 {
157  return d->on_track_changed;
158 }
core::Signal< Track::Id > on_track_removed
core::Signal< void > on_track_list_replaced
std::shared_ptr< core::dbus::Property< mpris::TrackList::Properties::CanEditTracks > > can_edit_tracks
void go_to(const Track::Id &track)
core::Signal< Track::Id > on_track_changed
core::dbus::Bus::Ptr the_session_bus()
const core::Signal< void > & on_track_list_replaced() const
Definition: player.h:40
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)
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
std::shared_ptr< media::Player > parent
const core::Property< Container > & tracks() const
const core::Signal< Track::Id > & on_track_removed() const
core::Signal< Track::Id > on_track_added
Private(TrackListStub *impl, const std::shared_ptr< media::Player > &parent, const dbus::types::ObjectPath &op)
std::shared_ptr< core::dbus::Property< mpris::TrackList::Properties::Tracks > > tracks
std::string UriType
Definition: track.h:40
TrackListStub(const std::shared_ptr< Player > &parent, const core::dbus::types::ObjectPath &op)