~bilalakhtar/unity/fix-queuedraw-after-addlaunchericon

« back to all changes in this revision

Viewing changes to dash/previews/Tracks.cpp

  • Committer: Tarmac
  • Author(s): Nick Dedekind, Gord Allott
  • Date: 2012-08-15 15:17:58 UTC
  • mfrom: (2419.4.70 unity.Preview)
  • Revision ID: tarmac-20120815151758-7tf3zgnndg5gocou
Added Music, App, Movie (basic) & Generic dash preview UIs and preview standalones.. Fixes: . Approved by Neil J. Patel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
 
2
/*
 
3
 * Copyright 2012 Canonical Ltd.
 
4
 *
 
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.
 
8
 *
 
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.
 
14
 *
 
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/>
 
18
 *
 
19
 * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
 
20
 *
 
21
 */
 
22
 
 
23
#include "Tracks.h"
 
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>
 
30
 
 
31
 
 
32
namespace unity
 
33
{
 
34
namespace dash
 
35
{
 
36
namespace previews
 
37
{
 
38
 
 
39
class TrackLayout : public nux::VLayout
 
40
{
 
41
public:
 
42
  TrackLayout() {}
 
43
 
 
44
  int ItemCount() const { return _layout_element_list.size(); }
 
45
 
 
46
  void RemoveViewAt(unsigned int index)
 
47
  {
 
48
    unsigned int idx = index;
 
49
    std::list<Area *>::iterator pos = _layout_element_list.begin();
 
50
    
 
51
    while (pos != _layout_element_list.end() && idx > 0)
 
52
    {
 
53
      idx--;
 
54
      pos++;
 
55
    }
 
56
    if (pos != _layout_element_list.end())
 
57
    {
 
58
      ViewRemoved.emit(this, *pos);
 
59
      (*pos)->UnParentObject();
 
60
      _layout_element_list.erase(pos);
 
61
    }
 
62
  }
 
63
 
 
64
};
 
65
 
 
66
namespace
 
67
{
 
68
nux::logging::Logger logger("unity.dash.previews.tracks");
 
69
}
 
70
 
 
71
NUX_IMPLEMENT_OBJECT_TYPE(Tracks);
 
72
 
 
73
Tracks::Tracks(dash::Tracks::Ptr tracks, NUX_FILE_LINE_DECL)
 
74
  : ScrollView(NUX_FILE_LINE_PARAM)
 
75
  , tracks_(tracks)
 
76
{
 
77
  SetupViews();
 
78
 
 
79
  if (tracks_)
 
80
  {
 
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));
 
84
 
 
85
    // Add what we've got.
 
86
    for (std::size_t i = 0; i < tracks_->count.Get(); i++)
 
87
    {
 
88
      OnTrackAdded(tracks_->RowAtIndex(i));
 
89
    }
 
90
  }
 
91
}
 
92
 
 
93
Tracks::~Tracks()
 
94
{
 
95
}
 
96
 
 
97
std::string Tracks::GetName() const
 
98
{
 
99
  return "Tracks";
 
100
}
 
101
 
 
102
void Tracks::AddProperties(GVariantBuilder* builder)
 
103
{
 
104
}
 
105
 
 
106
void Tracks::SetupViews()
 
107
{
 
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);
 
112
  SetLayout(layout_);
 
113
}
 
114
 
 
115
void Tracks::OnTrackUpdated(dash::Track const& track_row)
 
116
{
 
117
  auto pos = m_tracks.find(track_row.uri.Get());
 
118
  if (pos == m_tracks.end())
 
119
    return;
 
120
 
 
121
  pos->second->Update(track_row);
 
122
}
 
123
 
 
124
void Tracks::OnTrackAdded(dash::Track const& track_row)
 
125
{
 
126
  LOG_TRACE(logger) << "OnTrackAdded for " << track_row.title.Get();
 
127
 
 
128
  std::string track_uri = track_row.uri.Get();
 
129
  if (m_tracks.find(track_uri) != m_tracks.end())
 
130
    return;
 
131
 
 
132
  previews::Style& style = dash::previews::Style::Instance();
 
133
 
 
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); });
 
137
 
 
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);
 
142
 
 
143
  m_tracks[track_uri] = track_view;
 
144
}
 
145
 
 
146
void Tracks::OnTrackRemoved(dash::Track const& track_row)
 
147
{
 
148
  LOG_TRACE(logger) << "OnTrackRemoved for " << track_row.title.Get();
 
149
  
 
150
  auto pos = m_tracks.find(track_row.uri.Get());
 
151
  if (pos == m_tracks.end())
 
152
    return;
 
153
 
 
154
  layout_->RemoveChildObject(pos->second.GetPointer());
 
155
}
 
156
 
 
157
void Tracks::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
 
158
{
 
159
  nux::Geometry const& base = GetGeometry();
 
160
 
 
161
  gfx_engine.PushClippingRectangle(base);
 
162
  nux::GetPainter().PaintBackground(gfx_engine, base);
 
163
 
 
164
  gfx_engine.PopClippingRectangle();
 
165
}
 
166
 
 
167
void Tracks::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
 
168
{
 
169
  nux::Geometry const& base = GetGeometry();
 
170
  gfx_engine.PushClippingRectangle(base);
 
171
 
 
172
  if (GetCompositionLayout())
 
173
    GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
 
174
 
 
175
  gfx_engine.PopClippingRectangle();
 
176
}
 
177
 
 
178
} // namespace previews
 
179
} // namespace dash
 
180
} // namespace unity
 
 
b'\\ No newline at end of file'