~thomas-voss/media-hub/fix-seek-does-not-send-reply

« back to all changes in this revision

Viewing changes to src/com/ubuntu/music/track_list_stub.cpp

  • Committer: thomas-voss
  • Date: 2013-10-07 11:07:11 UTC
  • Revision ID: thomas.voss@canonical.com-20131007110711-a6wc1pz09jatz1g0
More refactoring of local spike.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <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>
 
25
 
 
26
#include "property_stub.h"
 
27
#include "track_id.h"
 
28
#include "track_list_traits.h"
 
29
#include "the_session_bus.h"
 
30
 
 
31
#include "mpris/track_list.h"
 
32
 
 
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>
 
37
 
 
38
#include <limits>
 
39
 
 
40
namespace dbus = org::freedesktop::dbus;
 
41
namespace music = com::ubuntu::music;
 
42
 
 
43
struct music::TrackListStub::Private
 
44
{
 
45
    Private(
 
46
            TrackListStub* impl,
 
47
            const std::shared_ptr<music::Player>& parent,
 
48
            const dbus::types::ObjectPath& op)
 
49
        : impl(impl),
 
50
          parent(parent),
 
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>())
 
54
    {
 
55
    }
 
56
 
 
57
    TrackListStub* impl;
 
58
    std::shared_ptr<music::Player> parent;
 
59
    dbus::Object::Ptr object;
 
60
 
 
61
    PropertyStub<bool, mpris::TrackList::Properties::CanEditTracks> can_edit_tracks;
 
62
    PropertyStub<TrackList::Container, mpris::TrackList::Properties::Tracks> tracks;
 
63
 
 
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;
 
68
};
 
69
 
 
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))
 
75
{
 
76
}
 
77
 
 
78
music::TrackListStub::~TrackListStub()
 
79
{
 
80
}
 
81
 
 
82
const music::Property<bool>& music::TrackListStub::can_edit_tracks() const
 
83
{
 
84
    return d->can_edit_tracks;
 
85
}
 
86
 
 
87
const music::Property<music::TrackList::Container>& music::TrackListStub::tracks() const
 
88
{
 
89
    return d->tracks;
 
90
}
 
91
 
 
92
void music::TrackListStub::add_track_with_uri_at(
 
93
        const music::Track::UriType& uri,
 
94
        const music::Track::Id& id,
 
95
        bool make_current)
 
96
{
 
97
    auto op = d->object->invoke_method_synchronously<mpris::TrackList::AddTrack, void>(
 
98
                uri,
 
99
                id.object_path,
 
100
                make_current);
 
101
 
 
102
    if (op.is_error())
 
103
        throw std::runtime_error("Problem adding track: " + op.error());
 
104
}
 
105
 
 
106
void music::TrackListStub::remove_track(const music::Track::Id& track)
 
107
{
 
108
    auto op = d->object->invoke_method_synchronously<mpris::TrackList::RemoveTrack, void>(
 
109
                track.object_path);
 
110
 
 
111
    if (op.is_error())
 
112
        throw std::runtime_error("Problem removing track: " + op.error());
 
113
}
 
114
 
 
115
void music::TrackListStub::go_to(const music::Track::Id& track)
 
116
{
 
117
    auto op = d->object->invoke_method_synchronously<mpris::TrackList::GoTo, void>(
 
118
                track.object_path);
 
119
 
 
120
    if (op.is_error())
 
121
        throw std::runtime_error("Problem adding track: " + op.error());
 
122
}
 
123
 
 
124
const music::Signal<void>& music::TrackListStub::on_track_list_replaced() const
 
125
{
 
126
    return d->on_track_list_replaced;
 
127
}
 
128
 
 
129
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_added() const
 
130
{
 
131
    return d->on_track_added;
 
132
}
 
133
 
 
134
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_removed() const
 
135
{
 
136
    return d->on_track_removed;
 
137
}
 
138
 
 
139
const music::Signal<std::shared_ptr<music::Track>>& music::TrackListStub::on_track_changed() const
 
140
{
 
141
    return d->on_track_changed;
 
142
}