1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright 2012 Canonical Ltd.
5
* This program is free software: you can redistribute it and/or modify it
6
* under the terms of the GNU Lesser General Public License version 3, as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranties of
11
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12
* PURPOSE. See the applicable version of the GNU Lesser General Public
13
* License for more details.
15
* You should have received a copy of both the GNU Lesser General Public
16
* License version 3 along with this program. If not, see
17
* <http://www.gnu.org/licenses/>
19
* Authored by: Nick Dedekind <nick.dedekind@canonical.com>
24
#include <NuxCore/Logger.h>
25
#include <Nux/VLayout.h>
26
#include "unity-shared/IntrospectableWrappers.h"
27
#include "unity-shared/PlacesVScrollBar.h"
28
#include "unity-shared/PreviewStyle.h"
29
#include <UnityCore/Track.h>
39
class TrackLayout : public nux::VLayout
44
int ItemCount() const { return _layout_element_list.size(); }
46
void RemoveViewAt(unsigned int index)
48
unsigned int idx = index;
49
std::list<Area *>::iterator pos = _layout_element_list.begin();
51
while (pos != _layout_element_list.end() && idx > 0)
56
if (pos != _layout_element_list.end())
58
ViewRemoved.emit(this, *pos);
59
(*pos)->UnParentObject();
60
_layout_element_list.erase(pos);
68
nux::logging::Logger logger("unity.dash.previews.tracks");
71
NUX_IMPLEMENT_OBJECT_TYPE(Tracks);
73
Tracks::Tracks(dash::Tracks::Ptr tracks, NUX_FILE_LINE_DECL)
74
: ScrollView(NUX_FILE_LINE_PARAM)
81
tracks_->track_added.connect(sigc::mem_fun(this, &Tracks::OnTrackAdded));
82
tracks_->track_changed.connect(sigc::mem_fun(this, &Tracks::OnTrackUpdated));
83
tracks_->track_removed.connect(sigc::mem_fun(this, &Tracks::OnTrackRemoved));
85
// Add what we've got.
86
for (std::size_t i = 0; i < tracks_->count.Get(); i++)
88
OnTrackAdded(tracks_->RowAtIndex(i));
97
std::string Tracks::GetName() const
102
void Tracks::AddProperties(GVariantBuilder* builder)
106
void Tracks::SetupViews()
108
SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
109
layout_ = new TrackLayout();
110
layout_->SetPadding(0, previews::Style::Instance().GetDetailsRightMargin(), 0, 0);
111
layout_->SetSpaceBetweenChildren(1);
115
void Tracks::OnTrackUpdated(dash::Track const& track_row)
117
auto pos = m_tracks.find(track_row.uri.Get());
118
if (pos == m_tracks.end())
121
pos->second->Update(track_row);
124
void Tracks::OnTrackAdded(dash::Track const& track_row)
126
LOG_TRACE(logger) << "OnTrackAdded for " << track_row.title.Get();
128
std::string track_uri = track_row.uri.Get();
129
if (m_tracks.find(track_uri) != m_tracks.end())
132
previews::Style& style = dash::previews::Style::Instance();
134
previews::Track::Ptr track_view(new previews::Track(NUX_TRACKER_LOCATION));
135
track_view->play.connect([&](std::string const& uri) { play.emit(uri); });
136
track_view->pause.connect([&](std::string const& uri) { pause.emit(uri); });
138
track_view->Update(track_row);
139
track_view->SetMinimumHeight(style.GetTrackHeight());
140
track_view->SetMaximumHeight(style.GetTrackHeight());
141
layout_->AddView(track_view.GetPointer(), 0);
143
m_tracks[track_uri] = track_view;
146
void Tracks::OnTrackRemoved(dash::Track const& track_row)
148
LOG_TRACE(logger) << "OnTrackRemoved for " << track_row.title.Get();
150
auto pos = m_tracks.find(track_row.uri.Get());
151
if (pos == m_tracks.end())
154
layout_->RemoveChildObject(pos->second.GetPointer());
157
void Tracks::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
159
nux::Geometry const& base = GetGeometry();
161
gfx_engine.PushClippingRectangle(base);
162
nux::GetPainter().PaintBackground(gfx_engine, base);
164
gfx_engine.PopClippingRectangle();
167
void Tracks::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
169
nux::Geometry const& base = GetGeometry();
170
gfx_engine.PushClippingRectangle(base);
172
if (GetCompositionLayout())
173
GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
175
gfx_engine.PopClippingRectangle();
178
} // namespace previews
b'\\ No newline at end of file'