2
* Copyright © 2013 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
#include "track_list_stub.h"
21
#include <com/ubuntu/music/player.h>
22
#include <com/ubuntu/music/property.h>
23
#include <com/ubuntu/music/signal.h>
24
#include <com/ubuntu/music/track_list.h>
26
#include "property_stub.h"
28
#include "track_list_traits.h"
29
#include "the_session_bus.h"
31
#include "mpris/track_list.h"
33
#include <org/freedesktop/dbus/types/object_path.h>
34
#include <org/freedesktop/dbus/types/variant.h>
35
#include <org/freedesktop/dbus/types/stl/map.h>
36
#include <org/freedesktop/dbus/types/stl/vector.h>
40
namespace dbus = org::freedesktop::dbus;
41
namespace music = com::ubuntu::music;
43
struct music::TrackListStub::Private
47
const std::shared_ptr<music::Player>& parent,
48
const dbus::types::ObjectPath& op)
51
object(impl->access_service()->object_for_path(op)),
52
can_edit_tracks(object->get_property<mpris::TrackList::Properties::CanEditTracks>()),
53
tracks(object->get_property<mpris::TrackList::Properties::Tracks>())
58
std::shared_ptr<music::Player> parent;
59
dbus::Object::Ptr object;
61
PropertyStub<bool, mpris::TrackList::Properties::CanEditTracks> can_edit_tracks;
62
PropertyStub<TrackList::Container, mpris::TrackList::Properties::Tracks> tracks;
64
Signal<void> on_track_list_replaced;
65
Signal<std::shared_ptr<Track>> on_track_added;
66
Signal<std::shared_ptr<Track>> on_track_removed;
67
Signal<std::shared_ptr<Track>> on_track_changed;
70
music::TrackListStub::TrackListStub(
71
const std::shared_ptr<music::Player>& parent,
72
const org::freedesktop::dbus::types::ObjectPath& op)
73
: dbus::Stub<music::TrackList>(the_session_bus()),
74
d(new Private(this, parent, op))
78
music::TrackListStub::~TrackListStub()
82
const music::Property<bool>& music::TrackListStub::can_edit_tracks() const
84
return d->can_edit_tracks;
87
const music::Property<music::TrackList::Container>& music::TrackListStub::tracks() const
92
void music::TrackListStub::add_track_with_uri_at(
93
const music::Track::UriType& uri,
94
const music::Track::Id& id,
97
auto op = d->object->invoke_method_synchronously<mpris::TrackList::AddTrack, void>(
103
throw std::runtime_error("Problem adding track: " + op.error());
106
void music::TrackListStub::remove_track(const music::Track::Id& track)
108
auto op = d->object->invoke_method_synchronously<mpris::TrackList::RemoveTrack, void>(
112
throw std::runtime_error("Problem removing track: " + op.error());
115
void music::TrackListStub::go_to(const music::Track::Id& track)
117
auto op = d->object->invoke_method_synchronously<mpris::TrackList::GoTo, void>(
121
throw std::runtime_error("Problem adding track: " + op.error());
124
const music::Signal<void>& music::TrackListStub::on_track_list_replaced() const
126
return d->on_track_list_replaced;
129
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_added() const
131
return d->on_track_added;
134
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_removed() const
136
return d->on_track_removed;
139
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_changed() const
141
return d->on_track_changed;