Merge lp:~ken-vandine/unity/trunk_with_social_preview into lp:unity

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: no longer in the source branch.
Merged at revision: 2704
Proposed branch: lp:~ken-vandine/unity/trunk_with_social_preview
Merge into: lp:unity
Diff against target: 1884 lines (+1716/-0)
17 files modified
UnityCore/CMakeLists.txt (+2/-0)
UnityCore/Preview.cpp (+5/-0)
UnityCore/SocialPreview.cpp (+105/-0)
UnityCore/SocialPreview.h (+77/-0)
dash/previews/CMakeLists.txt (+10/-0)
dash/previews/Preview.cpp (+5/-0)
dash/previews/SocialPreview.cpp (+309/-0)
dash/previews/SocialPreview.h (+93/-0)
dash/previews/SocialPreviewComments.cpp (+193/-0)
dash/previews/SocialPreviewComments.h (+78/-0)
dash/previews/SocialPreviewContent.cpp (+325/-0)
dash/previews/SocialPreviewContent.h (+86/-0)
dash/previews/StandaloneSocialPreview.cpp (+287/-0)
tests/CMakeLists.txt (+4/-0)
tests/test_previews_social.cpp (+110/-0)
unity-shared/PreviewStyle.cpp (+15/-0)
unity-shared/PreviewStyle.h (+12/-0)
To merge this branch: bzr merge lp:~ken-vandine/unity/trunk_with_social_preview
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+124516@code.launchpad.net

Commit message

Added SocialPreview

Description of the change

Added SocialPreview

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Looks good and works well, approved.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No commit message specified.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1312/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1319/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1321/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1322/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Hmm odd it isn't grabbing the new libunity...
Unpacking libunity9:amd64 (from .../libunity9_5.96.0+bzr173ubuntu0+140_amd64.deb) ..

Al the libunitys are grabbing the rev 173...which your fix is inserted at 176. :(

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1324/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Unity Merger (unity-merger) wrote :

The Jenkins job https://jenkins.qa.ubuntu.com/job/automerge-unity/1325/console reported an error when processing this lp:~ken-vandine/unity/trunk_with_social_preview branch.
Not merging it.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

@Ken

The problem is being looking at. When a solution comes up this will get merged :)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/CMakeLists.txt'
2--- UnityCore/CMakeLists.txt 2012-08-30 13:15:09 +0000
3+++ UnityCore/CMakeLists.txt 2012-09-17 14:17:20 +0000
4@@ -46,6 +46,7 @@
5 ResultIterator.h
6 Results.h
7 SeriesPreview.h
8+ SocialPreview.h
9 Track.h
10 Tracks.h
11 Variant.h
12@@ -84,6 +85,7 @@
13 ResultIterator.cpp
14 Results.cpp
15 SeriesPreview.cpp
16+ SocialPreview.cpp
17 Track.cpp
18 Tracks.cpp
19 Variant.cpp
20
21=== modified file 'UnityCore/Preview.cpp'
22--- UnityCore/Preview.cpp 2012-09-13 10:56:42 +0000
23+++ UnityCore/Preview.cpp 2012-09-17 14:17:20 +0000
24@@ -28,6 +28,7 @@
25 #include "GenericPreview.h"
26 #include "MusicPreview.h"
27 #include "MoviePreview.h"
28+#include "SocialPreview.h"
29 #include "SeriesPreview.h"
30
31 namespace unity
32@@ -68,6 +69,10 @@
33 {
34 return Preview::Ptr(new MoviePreview(proto_obj));
35 }
36+ else if (renderer_name == "preview-social")
37+ {
38+ return Preview::Ptr(new SocialPreview(proto_obj));
39+ }
40 else if (renderer_name == "preview-series")
41 {
42 return Preview::Ptr(new SeriesPreview(proto_obj));
43
44=== added file 'UnityCore/SocialPreview.cpp'
45--- UnityCore/SocialPreview.cpp 1970-01-01 00:00:00 +0000
46+++ UnityCore/SocialPreview.cpp 2012-09-17 14:17:20 +0000
47@@ -0,0 +1,105 @@
48+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
49+/*
50+ * Copyright (C) 2011-2012 Canonical Ltd
51+ *
52+ * This program is free software: you can redistribute it and/or modify
53+ * it under the terms of the GNU General Public License version 3 as
54+ * published by the Free Software Foundation.
55+ *
56+ * This program is distributed in the hope that it will be useful,
57+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
58+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59+ * GNU General Public License for more details.
60+ *
61+ * You should have received a copy of the GNU General Public License
62+ * along with this program. If not, see <http://www.gnu.org/contents/>.
63+ *
64+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
65+ *
66+ */
67+
68+#include <unity-protocol.h>
69+
70+#include "SocialPreview.h"
71+
72+namespace unity
73+{
74+namespace dash
75+{
76+
77+class SocialPreview::Impl
78+{
79+public:
80+ Impl(SocialPreview* owner, glib::Object<GObject> const& proto_obj);
81+
82+
83+ void SetupGetters();
84+ std::string get_sender() { return sender_; };
85+ std::string get_content() { return content_; };
86+ glib::Object<GIcon> get_avatar() { return avatar_; };
87+ CommentPtrList get_comments() const { return comments_list_; };
88+
89+ SocialPreview* owner_;
90+
91+ std::string sender_;
92+ std::string content_;
93+ glib::Object<GIcon> avatar_;
94+ CommentPtrList comments_list_;
95+};
96+
97+SocialPreview::Impl::Impl(SocialPreview* owner, glib::Object<GObject> const& proto_obj)
98+ : owner_(owner)
99+{
100+ const gchar* s;
101+ auto preview = glib::object_cast<UnityProtocolSocialPreview>(proto_obj);
102+
103+ s = unity_protocol_social_preview_get_sender(preview);
104+ if (s) sender_ = s;
105+ s = unity_protocol_social_preview_get_content(preview);
106+ if (s) content_ = s;
107+
108+ glib::Object<GIcon> icon(unity_protocol_social_preview_get_avatar(preview),
109+ glib::AddRef());
110+ avatar_ = icon;
111+
112+ int comments_len;
113+ auto comments = unity_protocol_social_preview_get_comments(preview, &comments_len);
114+ for (int i = 0; i < comments_len; i++)
115+ {
116+ UnityProtocolSocialPreviewCommentRaw *raw_comment = &comments[i];
117+ comments_list_.push_back(std::make_shared<Comment>(
118+ raw_comment->id, raw_comment->display_name, raw_comment->content,
119+ raw_comment->time));
120+ }
121+
122+ SetupGetters();
123+}
124+
125+void SocialPreview::Impl::SetupGetters()
126+{
127+ owner_->sender.SetGetterFunction(
128+ sigc::mem_fun(this, &SocialPreview::Impl::get_sender));
129+ owner_->content.SetGetterFunction(
130+ sigc::mem_fun(this, &SocialPreview::Impl::get_content));
131+ owner_->avatar.SetGetterFunction(
132+ sigc::mem_fun(this, &SocialPreview::Impl::get_avatar));
133+}
134+
135+SocialPreview::SocialPreview(unity::glib::Object<GObject> const& proto_obj)
136+ : Preview(proto_obj)
137+ , pimpl(new Impl(this, proto_obj))
138+{
139+}
140+
141+SocialPreview::CommentPtrList SocialPreview::GetComments() const
142+{
143+ return pimpl->get_comments();
144+}
145+
146+
147+SocialPreview::~SocialPreview()
148+{
149+}
150+
151+}
152+}
153
154=== added file 'UnityCore/SocialPreview.h'
155--- UnityCore/SocialPreview.h 1970-01-01 00:00:00 +0000
156+++ UnityCore/SocialPreview.h 2012-09-17 14:17:20 +0000
157@@ -0,0 +1,77 @@
158+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
159+/*
160+ * Copyright (C) 2011-2012 Canonical Ltd
161+ *
162+ * This program is free software: you can redistribute it and/or modify
163+ * it under the terms of the GNU General Public License version 3 as
164+ * published by the Free Software Foundation.
165+ *
166+ * This program is distributed in the hope that it will be useful,
167+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
168+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
169+ * GNU General Public License for more details.
170+ *
171+ * You should have received a copy of the GNU General Public License
172+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
173+ *
174+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
175+ *
176+ */
177+
178+#ifndef UNITY_SOCIAL_PREVIEW_H
179+#define UNITY_SOCIAL_PREVIEW_H
180+
181+#include <memory>
182+
183+#include <sigc++/trackable.h>
184+
185+#include "Preview.h"
186+
187+namespace unity
188+{
189+namespace dash
190+{
191+
192+class SocialPreview : public Preview
193+{
194+public:
195+ struct Comment
196+ {
197+ std::string id;
198+ std::string display_name;
199+ std::string content;
200+ std::string time;
201+
202+ Comment() {};
203+ Comment(const gchar* id_, const gchar* display_name_,
204+ const gchar* content_, const gchar* time_)
205+ : id(id_ != NULL ? id_ : "")
206+ , display_name(display_name_ != NULL ? display_name_ : "")
207+ , content(content_ != NULL ? content_ : "")
208+ , time(time_ != NULL ? time_ : "") {};
209+ };
210+
211+ typedef std::shared_ptr<SocialPreview> Ptr;
212+ typedef std::shared_ptr<Comment> CommentPtr;
213+ typedef std::vector<CommentPtr> CommentPtrList;
214+
215+ SocialPreview(unity::glib::Object<GObject> const& proto_obj);
216+ ~SocialPreview();
217+
218+ nux::RWProperty<std::string> sender;
219+ nux::RWProperty<std::string> title;
220+ nux::RWProperty<std::string> content;
221+ nux::RWProperty<glib::Object<GIcon>> avatar;
222+
223+ CommentPtrList GetComments() const;
224+
225+
226+private:
227+ class Impl;
228+ std::unique_ptr<Impl> pimpl;
229+};
230+
231+}
232+}
233+
234+#endif
235
236=== modified file 'dash/previews/CMakeLists.txt'
237--- dash/previews/CMakeLists.txt 2012-09-03 17:24:11 +0000
238+++ dash/previews/CMakeLists.txt 2012-09-17 14:17:20 +0000
239@@ -38,6 +38,9 @@
240 PreviewInfoHintWidget.cpp
241 PreviewNavigator.cpp
242 PreviewRatingsWidget.cpp
243+ SocialPreview.cpp
244+ SocialPreviewContent.cpp
245+ SocialPreviewComments.cpp
246 Track.cpp
247 Tracks.cpp
248 )
249@@ -61,6 +64,13 @@
250 target_link_libraries (music_previews previews-lib unity-shared)
251
252 #
253+# Social Standalone variant
254+#
255+add_executable (social_previews StandaloneSocialPreview.cpp)
256+add_dependencies (social_previews previews-lib)
257+target_link_libraries (social_previews previews-lib unity-shared)
258+
259+#
260 # Music Standalone variant
261 #
262 add_executable (movie_previews StandaloneMoviePreview.cpp)
263
264=== modified file 'dash/previews/Preview.cpp'
265--- dash/previews/Preview.cpp 2012-09-13 16:11:54 +0000
266+++ dash/previews/Preview.cpp 2012-09-17 14:17:20 +0000
267@@ -32,6 +32,7 @@
268 #include "ApplicationPreview.h"
269 #include "MusicPreview.h"
270 #include "MoviePreview.h"
271+#include "SocialPreview.h"
272
273 namespace unity
274 {
275@@ -69,6 +70,10 @@
276 {
277 return Preview::Ptr(new MoviePreview(model));
278 }
279+ else if (model->renderer_name == "preview-social")
280+ {
281+ return Preview::Ptr(new SocialPreview(model));
282+ }
283 // else if (renderer_name == "preview-series")
284 // {
285 // return Preview::Ptr(new SeriesPreview(model));
286
287=== added file 'dash/previews/SocialPreview.cpp'
288--- dash/previews/SocialPreview.cpp 1970-01-01 00:00:00 +0000
289+++ dash/previews/SocialPreview.cpp 2012-09-17 14:17:20 +0000
290@@ -0,0 +1,309 @@
291+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
292+/*
293+ * Copyright 2012 Canonical Ltd.
294+ *
295+ * This program is free software: you can redistribute it and/or modify it
296+ * under the terms of the GNU Lesser General Public License version 3, as
297+ * published by the Free Software Foundation.
298+ *
299+ * This program is distributed in the hope that it will be useful, but
300+ * WITHOUT ANY WARRANTY; without even the implied warranties of
301+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
302+ * PURPOSE. See the applicable version of the GNU Lesser General Public
303+ * License for more details.
304+ *
305+ * You should have received a copy of both the GNU Lesser General Public
306+ * License version 3 along with this program. If not, see
307+ * <http://www.gnu.org/licenses/>
308+ *
309+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
310+ *
311+ */
312+
313+#include "unity-shared/IntrospectableWrappers.h"
314+#include "unity-shared/PreviewStyle.h"
315+#include "unity-shared/CoverArt.h"
316+#include "unity-shared/IconTexture.h"
317+#include "unity-shared/StaticCairoText.h"
318+#include "unity-shared/PlacesVScrollBar.h"
319+#include <UnityCore/SocialPreview.h>
320+#include <NuxCore/Logger.h>
321+#include <Nux/HLayout.h>
322+#include <Nux/VLayout.h>
323+#include <Nux/GridHLayout.h>
324+#include <Nux/Button.h>
325+#include <glib/gi18n-lib.h>
326+
327+#include "SocialPreview.h"
328+#include "SocialPreviewContent.h"
329+#include "SocialPreviewComments.h"
330+#include "ActionButton.h"
331+#include "PreviewInfoHintWidget.h"
332+
333+namespace unity
334+{
335+namespace dash
336+{
337+namespace previews
338+{
339+
340+namespace
341+{
342+nux::logging::Logger logger("unity.dash.previews.socialpreview");
343+
344+}
345+
346+class DetailsScrollView : public nux::ScrollView
347+{
348+public:
349+ DetailsScrollView(NUX_FILE_LINE_PROTO)
350+ : ScrollView(NUX_FILE_LINE_PARAM)
351+ {
352+ SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
353+ }
354+
355+};
356+
357+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreview);
358+
359+SocialPreview::SocialPreview(dash::Preview::Ptr preview_model)
360+: Preview(preview_model)
361+, full_data_layout_(nullptr)
362+{
363+ SetupBackground();
364+ SetupViews();
365+}
366+
367+SocialPreview::~SocialPreview()
368+{
369+}
370+
371+void SocialPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
372+{
373+ nux::Geometry const& base = GetGeometry();
374+
375+ bool enable_bg_shadows = dash::previews::Style::Instance().GetShadowBackgroundEnabled();
376+
377+ gfx_engine.PushClippingRectangle(base);
378+ nux::GetPainter().PaintBackground(gfx_engine, base);
379+
380+ if (enable_bg_shadows && full_data_layout_)
381+ {
382+ unsigned int alpha, src, dest = 0;
383+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
384+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
385+
386+ details_bg_layer_->SetGeometry(full_data_layout_->GetGeometry());
387+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, full_data_layout_->GetGeometry(), details_bg_layer_.get());
388+
389+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
390+ }
391+
392+ gfx_engine.PopClippingRectangle();
393+}
394+
395+void SocialPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
396+{
397+ nux::Geometry const& base = GetGeometry();
398+ gfx_engine.PushClippingRectangle(base);
399+
400+ bool enable_bg_shadows = dash::previews::Style::Instance().GetShadowBackgroundEnabled();
401+
402+ if (enable_bg_shadows && !IsFullRedraw())
403+ nux::GetPainter().PushLayer(gfx_engine, details_bg_layer_->GetGeometry(), details_bg_layer_.get());
404+
405+ unsigned int alpha, src, dest = 0;
406+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
407+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
408+
409+ if (GetCompositionLayout())
410+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
411+
412+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
413+
414+ if (enable_bg_shadows && !IsFullRedraw())
415+ nux::GetPainter().PopBackground();
416+
417+ gfx_engine.PopClippingRectangle();
418+}
419+
420+std::string SocialPreview::GetName() const
421+{
422+ return "SocialPreview";
423+}
424+
425+void SocialPreview::AddProperties(GVariantBuilder* builder)
426+{
427+ Preview::AddProperties(builder);
428+}
429+
430+void SocialPreview::SetupBackground()
431+{
432+ details_bg_layer_.reset(dash::previews::Style::Instance().GetBackgroundLayer());
433+}
434+
435+void SocialPreview::SetupViews()
436+{
437+ dash::SocialPreview* social_preview_model = dynamic_cast<dash::SocialPreview*>(preview_model_.get());
438+ if (!social_preview_model)
439+ {
440+ LOG_ERROR(logger) << "Could not derive social preview model from given parameter.";
441+ return;
442+ }
443+
444+ previews::Style& style = dash::previews::Style::Instance();
445+
446+ nux::HLayout* image_data_layout = new nux::HLayout();
447+ image_data_layout->SetSpaceBetweenChildren(style.GetPanelSplitWidth());
448+
449+ nux::VLayout* social_content_layout = new nux::VLayout();
450+ social_content_layout->SetSpaceBetweenChildren(16);
451+
452+
453+ if (social_preview_model->description.Get().length() > 0)
454+ {
455+ content_ = new SocialPreviewContent(social_preview_model->description, NUX_TRACKER_LOCATION);
456+ social_content_layout->AddView(content_.GetPointer(), 1);
457+ } else {
458+ image_ = new CoverArt();
459+ AddChild(image_.GetPointer());
460+ UpdateCoverArtImage(image_.GetPointer());
461+ social_content_layout->AddView(image_.GetPointer(), 1);
462+ }
463+
464+ /////////////////////
465+
466+ /////////////////////
467+ // Social Data Panel
468+ full_data_layout_ = new nux::VLayout();
469+ full_data_layout_->SetPadding(style.GetDetailsTopMargin(), 0, style.GetDetailsBottomMargin(), style.GetDetailsLeftMargin());
470+ full_data_layout_->SetSpaceBetweenChildren(16);
471+
472+ /////////////////////
473+ // Main Social Info
474+ nux::HLayout* main_social_info = new nux::HLayout();
475+ main_social_info->SetSpaceBetweenChildren(style.GetSpaceBetweenIconAndDetails());
476+
477+ /////////////////////
478+ // Icon Layout
479+ nux::VLayout* icon_layout = new nux::VLayout();
480+ icon_layout->SetSpaceBetweenChildren(3);
481+ avatar_ = new IconTexture(social_preview_model->avatar.Get().RawPtr() ? g_icon_to_string(social_preview_model->avatar.Get().RawPtr()) : "", MIN(style.GetAvatarAreaWidth(), style.GetAvatarAreaHeight()));
482+ avatar_->SetMinMaxSize(style.GetAvatarAreaWidth(), style.GetAvatarAreaHeight());
483+ icon_layout->AddView(avatar_.GetPointer(), 0);
484+
485+ /////////////////////
486+
487+ /////////////////////
488+ // Data
489+ nux::VLayout* social_data_layout = new nux::VLayout();
490+ social_data_layout->SetSpaceBetweenChildren(style.GetSpaceBetweenTitleAndSubtitle());
491+
492+ title_ = new nux::StaticCairoText(preview_model_->title, true, NUX_TRACKER_LOCATION);
493+ title_->SetLines(-1);
494+ title_->SetFont(style.title_font().c_str());
495+
496+ subtitle_ = new nux::StaticCairoText(preview_model_->subtitle, true, NUX_TRACKER_LOCATION);
497+ subtitle_->SetFont(style.content_font().c_str());
498+ subtitle_->SetLines(-1);
499+
500+ social_data_layout->AddView(title_.GetPointer(), 0);
501+ social_data_layout->AddView(subtitle_.GetPointer(), 0);
502+ social_data_layout->AddSpace(0, 1);
503+
504+ // buffer space
505+ /////////////////////
506+
507+ main_social_info->AddLayout(icon_layout, 0);
508+ main_social_info->AddLayout(social_data_layout, 1);
509+ /////////////////////
510+
511+ /////////////////////
512+ // Details
513+ nux::ScrollView* social_info = new DetailsScrollView(NUX_TRACKER_LOCATION);
514+ social_info->EnableHorizontalScrollBar(false);
515+
516+ nux::VLayout* social_info_layout = new nux::VLayout();
517+ social_info_layout->SetSpaceBetweenChildren(12);
518+ social_info->SetLayout(social_info_layout);
519+
520+ if (!preview_model_->GetInfoHints().empty())
521+ {
522+ preview_info_hints_ = new PreviewInfoHintWidget(preview_model_, style.GetAvatarAreaWidth());
523+ AddChild(preview_info_hints_.GetPointer());
524+ social_info_layout->AddView(preview_info_hints_.GetPointer());
525+ }
526+ /////////////////////
527+ // Comments/Replies
528+ if (!social_preview_model->GetComments().empty())
529+ {
530+ nux::HLayout* comments_layout = new nux::HLayout();
531+ comments_layout->SetSpaceBetweenChildren(12);
532+ std::string tmp_comments_hint = _("Comments");
533+ tmp_comments_hint += ":";
534+
535+ comments_hint_ = new nux::StaticCairoText(tmp_comments_hint, true, NUX_TRACKER_LOCATION);
536+ comments_hint_->SetLines(-1);
537+ comments_hint_->SetFont(style.info_hint_bold_font().c_str());
538+ comments_hint_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT);
539+ comments_layout->AddView(comments_hint_.GetPointer(), 0, nux::MINOR_POSITION_TOP);
540+
541+ comments_ = new SocialPreviewComments(preview_model_, NUX_TRACKER_LOCATION);
542+ AddChild(comments_.GetPointer());
543+ comments_layout->AddView(comments_.GetPointer());
544+ social_info_layout->AddView(comments_layout, 0);
545+ }
546+
547+ /////////////////////
548+ // Actions
549+ action_buttons_.clear();
550+ nux::Layout* actions_layout = BuildGridActionsLayout(preview_model_->GetActions(), action_buttons_);
551+ actions_layout->SetLeftAndRightPadding(0, style.GetDetailsRightMargin());
552+ ///////////////////
553+
554+ full_data_layout_->AddLayout(main_social_info, 0, nux::MINOR_POSITION_TOP);
555+ full_data_layout_->AddView(social_info, 1, nux::MINOR_POSITION_TOP);
556+ //full_data_layout_->AddView(comments_.GetPointer(), 1, nux::MINOR_POSITION_TOP);
557+
558+ full_data_layout_->AddLayout(actions_layout, 0);
559+ /////////////////////
560+
561+ image_data_layout->AddView(social_content_layout, 0);
562+ image_data_layout->AddLayout(full_data_layout_, 1);
563+
564+
565+ SetLayout(image_data_layout);
566+}
567+
568+void SocialPreview::PreLayoutManagement()
569+{
570+ nux::Geometry geo = GetGeometry();
571+
572+ previews::Style& style = dash::previews::Style::Instance();
573+
574+ nux::Geometry geo_content(geo.x, geo.y, style.GetAppImageAspectRatio() * geo.height, geo.height);
575+
576+ if (geo.width - geo_content.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() < style.GetDetailsPanelMinimumWidth())
577+ geo_content.width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() - style.GetDetailsPanelMinimumWidth());
578+ if (content_) { content_->SetMinMaxSize(geo_content.width, geo_content.height); }
579+ if (image_) { image_->SetMinMaxSize(geo_content.width, geo_content.height); }
580+
581+ int details_width = MAX(0, geo.width - geo_content.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
582+ int top_social_info_max_width = details_width - style.GetAppIconAreaWidth() - style.GetSpaceBetweenIconAndDetails();
583+
584+ if (title_) { title_->SetMaximumWidth(top_social_info_max_width); }
585+ if (subtitle_) { subtitle_->SetMaximumWidth(top_social_info_max_width); }
586+ if (comments_) { comments_->SetMaximumWidth(top_social_info_max_width); }
587+ if (comments_hint_) { comments_hint_->SetMinimumWidth(style.GetInfoHintNameMinimumWidth()); }
588+
589+ for (nux::AbstractButton* button : action_buttons_)
590+ {
591+ button->SetMinMaxSize(CLAMP((details_width - style.GetSpaceBetweenActions()) / 2, 0, style.GetActionButtonMaximumWidth()), style.GetActionButtonHeight());
592+ }
593+
594+ Preview::PreLayoutManagement();
595+}
596+
597+} // namespace previews
598+} // namespace dash
599+} // namepsace unity
600
601=== added file 'dash/previews/SocialPreview.h'
602--- dash/previews/SocialPreview.h 1970-01-01 00:00:00 +0000
603+++ dash/previews/SocialPreview.h 2012-09-17 14:17:20 +0000
604@@ -0,0 +1,93 @@
605+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
606+/*
607+ * Copyright 2012 Canonical Ltd.
608+ *
609+ * This program is free software: you can redistribute it and/or modify it
610+ * under the terms of the GNU Lesser General Public License version 3, as
611+ * published by the Free Software Foundation.
612+ *
613+ * This program is distributed in the hope that it will be useful, but
614+ * WITHOUT ANY WARRANTY; without even the implied warranties of
615+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
616+ * PURPOSE. See the applicable version of the GNU Lesser General Public
617+ * License for more details.
618+ *
619+ * You should have received a copy of both the GNU Lesser General Public
620+ * License version 3 along with this program. If not, see
621+ * <http://www.gnu.org/licenses/>
622+ *
623+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
624+ *
625+ */
626+
627+#ifndef SOCIALPREVIEW_H
628+#define SOCIALPREVIEW_H
629+
630+#include "Preview.h"
631+#include <Nux/Nux.h>
632+
633+namespace nux
634+{
635+class AbstractPaintLayer;
636+class VLayout;
637+class StaticCairoText;
638+}
639+
640+namespace unity
641+{
642+class IconTexture;
643+
644+namespace dash
645+{
646+namespace previews
647+{
648+class CoverArt;
649+class PreviewLikesWidget;
650+class PreviewInfoHintWidget;
651+class SocialPreviewContent;
652+class SocialPreviewComments;
653+
654+class SocialPreview : public Preview
655+{
656+public:
657+ typedef nux::ObjectPtr<SocialPreview> Ptr;
658+ NUX_DECLARE_OBJECT_TYPE(SocialPreview, Preview);
659+
660+ SocialPreview(dash::Preview::Ptr social_preview_model);
661+ ~SocialPreview();
662+
663+ // From debug::Introspectable
664+ std::string GetName() const;
665+ void AddProperties(GVariantBuilder* builder);
666+
667+protected:
668+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
669+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
670+ virtual void PreLayoutManagement();
671+
672+ void SetupBackground();
673+ void SetupViews();
674+
675+protected:
676+ nux::VLayout* full_data_layout_;
677+ nux::VLayout* sender_layout_;
678+ nux::VLayout* title_layout_;
679+
680+ nux::ObjectPtr<IconTexture> avatar_;
681+ nux::ObjectPtr<CoverArt> image_;
682+ nux::ObjectPtr<SocialPreviewContent> content_;
683+ nux::ObjectPtr<SocialPreviewComments> comments_;
684+ nux::ObjectPtr<nux::StaticCairoText> title_;
685+ nux::ObjectPtr<nux::StaticCairoText> subtitle_;
686+ nux::ObjectPtr<nux::StaticCairoText> comments_hint_;
687+ nux::ObjectPtr<PreviewInfoHintWidget> preview_info_hints_;
688+
689+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
690+ LayerPtr details_bg_layer_;
691+};
692+
693+}
694+}
695+}
696+
697+#endif //SOCIALPREVIEW_H
698
699=== added file 'dash/previews/SocialPreviewComments.cpp'
700--- dash/previews/SocialPreviewComments.cpp 1970-01-01 00:00:00 +0000
701+++ dash/previews/SocialPreviewComments.cpp 2012-09-17 14:17:20 +0000
702@@ -0,0 +1,193 @@
703+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
704+/*
705+ * Copyright 2011 Canonical Ltd.
706+ *
707+ * This program is free software: you can redistribute it and/or modify it
708+ * under the terms of the GNU Lesser General Public License version 3, as
709+ * published by the Free Software Foundation.
710+ *
711+ * This program is distributed in the hope that it will be useful, but
712+ * WITHOUT ANY WARRANTY; without even the implied warranties of
713+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
714+ * PURPOSE. See the applicable version of the GNU Lesser General Public
715+ * License for more details.
716+ *
717+ * You should have received a copy of both the GNU Lesser General Public
718+ * License version 3 along with this program. If not, see
719+ * <http://www.gnu.org/licenses/>
720+ *
721+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
722+ *
723+ */
724+
725+#include "unity-shared/DashStyle.h"
726+#include "unity-shared/PreviewStyle.h"
727+#include <UnityCore/SocialPreview.h>
728+#include <NuxCore/Logger.h>
729+#include <Nux/Layout.h>
730+#include <Nux/VLayout.h>
731+#include <Nux/HLayout.h>
732+
733+#include "SocialPreviewComments.h"
734+
735+namespace unity
736+{
737+namespace dash
738+{
739+namespace previews
740+{
741+
742+namespace
743+{
744+nux::logging::Logger logger("unity.dash.previews.socialpreviewcomments");
745+
746+const int layout_spacing = 12;
747+}
748+
749+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewComments);
750+
751+SocialPreviewComments::SocialPreviewComments(dash::Preview::Ptr preview_model, NUX_FILE_LINE_DECL)
752+: View(NUX_FILE_LINE_PARAM)
753+, preview_model_(preview_model)
754+{
755+ SetupViews();
756+}
757+
758+SocialPreviewComments::~SocialPreviewComments()
759+{
760+}
761+
762+void SocialPreviewComments::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
763+{
764+}
765+
766+void SocialPreviewComments::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
767+{
768+ nux::Geometry base = GetGeometry();
769+ gfx_engine.PushClippingRectangle(base);
770+
771+ if (GetCompositionLayout())
772+ {
773+ unsigned int alpha, src, dest = 0;
774+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
775+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
776+
777+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
778+
779+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
780+ }
781+
782+ gfx_engine.PopClippingRectangle();
783+}
784+
785+void SocialPreviewComments::PreLayoutManagement()
786+{
787+ previews::Style& style = previews::Style::Instance();
788+ nux::Geometry const& geo = GetGeometry();
789+
790+ int comment_width = 0;
791+ for (Comment const& comment : comments_)
792+ {
793+ int width = style.GetDetailsPanelMinimumWidth();
794+ if (comment.first)
795+ {
796+ width = comment.first->GetTextExtents().width;
797+
798+ if (width < style.GetDetailsPanelMinimumWidth())
799+ width = style.GetDetailsPanelMinimumWidth();
800+ }
801+
802+ if (comment_width < width)
803+ {
804+ comment_width = width;
805+ }
806+ }
807+
808+ int comment_value_width = MAX(0, geo.width - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
809+
810+ for (Comment const& comment : comments_)
811+ {
812+ if (comment.first)
813+ {
814+ comment.first->SetMaximumWidth(comment_value_width);
815+ }
816+ if (comment.second)
817+ {
818+ comment.second->SetMaximumWidth(comment_value_width);
819+ }
820+ }
821+ View::PreLayoutManagement();
822+}
823+
824+void SocialPreviewComments::SetupViews()
825+{
826+ dash::SocialPreview* social_preview_model = dynamic_cast<dash::SocialPreview*>(preview_model_.get());
827+
828+
829+ RemoveLayout();
830+ comments_.clear();
831+
832+ previews::Style& style = previews::Style::Instance();
833+
834+ nux::VLayout* layout = new nux::VLayout();
835+ layout->SetSpaceBetweenChildren(6);
836+
837+ for (dash::SocialPreview::CommentPtr comment : social_preview_model->GetComments())
838+ {
839+
840+ nux::HLayout* name_layout = new nux::HLayout();
841+ name_layout->SetSpaceBetweenChildren(layout_spacing);
842+
843+ StaticCairoTextPtr comment_name;
844+ if (!comment->display_name.empty())
845+ {
846+ comment_name = new nux::StaticCairoText(comment->display_name, true, NUX_TRACKER_LOCATION);
847+ comment_name->SetFont(style.info_hint_bold_font());
848+ comment_name->SetLines(-1);
849+ comment_name->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
850+ name_layout->AddView(comment_name.GetPointer(), 0, nux::MINOR_POSITION_TOP);
851+ }
852+
853+ StaticCairoTextPtr comment_time;
854+ if (!comment->time.empty())
855+ {
856+ comment_time = new nux::StaticCairoText(comment->time, true, NUX_TRACKER_LOCATION);
857+ comment_time->SetFont(style.info_hint_font());
858+ comment_time->SetLines(-1);
859+ comment_time->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT);
860+ name_layout->AddView(comment_time.GetPointer(), 0, nux::MINOR_POSITION_TOP);
861+ }
862+
863+
864+ nux::HLayout* comment_layout = new nux::HLayout();
865+ comment_layout->SetSpaceBetweenChildren(layout_spacing);
866+
867+ StaticCairoTextPtr comment_value(new nux::StaticCairoText(comment->content, false, NUX_TRACKER_LOCATION));
868+
869+ comment_value->SetFont(style.info_hint_font());
870+ comment_value->SetLines(-7);
871+ comment_value->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
872+ comment_layout->AddView(comment_value.GetPointer(), 1, nux::MINOR_POSITION_TOP);
873+
874+ Comment comment_views(comment_name, comment_value);
875+ comments_.push_back(comment_views);
876+
877+ layout->AddLayout(name_layout, 0);
878+ layout->AddLayout(comment_layout, 1);
879+ }
880+ SetLayout(layout);
881+
882+}
883+
884+std::string SocialPreviewComments::GetName() const
885+{
886+ return "SocialPreviewComments";
887+}
888+
889+void SocialPreviewComments::AddProperties(GVariantBuilder* builder)
890+{
891+}
892+
893+}
894+}
895+}
896
897=== added file 'dash/previews/SocialPreviewComments.h'
898--- dash/previews/SocialPreviewComments.h 1970-01-01 00:00:00 +0000
899+++ dash/previews/SocialPreviewComments.h 2012-09-17 14:17:20 +0000
900@@ -0,0 +1,78 @@
901+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
902+/*
903+ * Copyright 2011 Canonical Ltd.
904+ *
905+ * This program is free software: you can redistribute it and/or modify it
906+ * under the terms of the GNU Lesser General Public License version 3, as
907+ * published by the Free Software Foundation.
908+ *
909+ * This program is distributed in the hope that it will be useful, but
910+ * WITHOUT ANY WARRANTY; without even the implied warranties of
911+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
912+ * PURPOSE. See the applicable version of the GNU Lesser General Public
913+ * License for more details.
914+ *
915+ * You should have received a copy of both the GNU Lesser General Public
916+ * License version 3 along with this program. If not, see
917+ * <http://www.gnu.org/licenses/>
918+ *
919+ * Authored by: Ken VanDine <ken.vandine@canonical.com>
920+ *
921+ */
922+
923+#ifndef SOCIAL_PREVIEW_COMMENTS_H
924+#define SOCIAL_PREVIEW_COMMENTS_H
925+
926+#include <Nux/Nux.h>
927+#include <Nux/CairoWrapper.h>
928+#include <NuxCore/ObjectPtr.h>
929+#include "unity-shared/StaticCairoText.h"
930+#include "unity-shared/Introspectable.h"
931+#include <UnityCore/SocialPreview.h>
932+
933+namespace unity
934+{
935+namespace dash
936+{
937+namespace previews
938+{
939+
940+class SocialPreviewComments : public nux::View, public unity::debug::Introspectable
941+{
942+public:
943+ typedef nux::ObjectPtr<SocialPreviewComments> Ptr;
944+ NUX_DECLARE_OBJECT_TYPE(SocialPreviewComments, nux::View);
945+
946+ SocialPreviewComments(dash::Preview::Ptr preview_model, NUX_FILE_LINE_PROTO);
947+
948+ virtual ~SocialPreviewComments();
949+
950+protected:
951+
952+ typedef nux::ObjectPtr<nux::StaticCairoText> StaticCairoTextPtr;
953+ typedef std::pair<StaticCairoTextPtr, StaticCairoTextPtr> Comment;
954+ std::list<Comment> comments_;
955+
956+ dash::Preview::Ptr preview_model_;
957+
958+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
959+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
960+ virtual void PreLayoutManagement();
961+
962+ virtual bool AcceptKeyNavFocus() { return false; }
963+
964+ void SetupViews();
965+
966+ virtual std::string GetName() const;
967+ virtual void AddProperties(GVariantBuilder* builder);
968+
969+private:
970+
971+ typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
972+};
973+
974+}
975+}
976+}
977+
978+#endif // SOCIAL_PREVIEW_COMMENTS_H
979
980=== added file 'dash/previews/SocialPreviewContent.cpp'
981--- dash/previews/SocialPreviewContent.cpp 1970-01-01 00:00:00 +0000
982+++ dash/previews/SocialPreviewContent.cpp 2012-09-17 14:17:20 +0000
983@@ -0,0 +1,325 @@
984+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
985+/*
986+ * Copyright 2011 Canonical Ltd.
987+ *
988+ * This program is free software: you can redistribute it and/or modify it
989+ * under the terms of the GNU Lesser General Public License version 3, as
990+ * published by the Free Software Foundation.
991+ *
992+ * This program is distributed in the hope that it will be useful, but
993+ * WITHOUT ANY WARRANTY; without even the implied warranties of
994+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
995+ * PURPOSE. See the applicable version of the GNU Lesser General Public
996+ * License for more details.
997+ *
998+ * You should have received a copy of both the GNU Lesser General Public
999+ * License version 3 along with this program. If not, see
1000+ * <http://www.gnu.org/licenses/>
1001+ *
1002+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
1003+ * Ken VanDine <ken.vandine@canonical.com>
1004+ *
1005+ */
1006+
1007+#include "unity-shared/DashStyle.h"
1008+#include "unity-shared/PreviewStyle.h"
1009+#include <NuxCore/Logger.h>
1010+#include <Nux/Layout.h>
1011+
1012+#include "SocialPreviewContent.h"
1013+
1014+namespace unity
1015+{
1016+namespace dash
1017+{
1018+namespace previews
1019+{
1020+
1021+namespace
1022+{
1023+nux::logging::Logger logger("unity.dash.previews.socialpreviewcontent");
1024+}
1025+
1026+inline nux::Geometry GetBubbleGeometry(nux::Geometry const& geo)
1027+{
1028+ return nux::Geometry(geo.x + geo.width*0.1,
1029+ geo.y + geo.height*0.1,
1030+ geo.width - 2*(geo.width*0.1),
1031+ geo.height - 2*(geo.height*0.1));
1032+}
1033+
1034+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewContent);
1035+
1036+SocialPreviewContent::SocialPreviewContent(std::string const& text, NUX_FILE_LINE_DECL)
1037+: View(NUX_FILE_LINE_PARAM)
1038+{
1039+ SetupViews();
1040+ if (text.length() > 0)
1041+ SetText(text);
1042+}
1043+
1044+SocialPreviewContent::~SocialPreviewContent()
1045+{
1046+}
1047+
1048+void SocialPreviewContent::SetText(std::string const& text)
1049+{
1050+ std::stringstream ss;
1051+ ss << "<b>&#x201C;</b> ";
1052+ ss << text;
1053+ ss << " <b>&#x201E;</b>";
1054+ text_->SetText(ss.str());
1055+ UpdateBaloonTexture();
1056+}
1057+
1058+void SocialPreviewContent::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
1059+{
1060+
1061+ nux::Geometry const& geo = GetGeometry();
1062+
1063+ gPainter.PaintBackground(gfx_engine, geo);
1064+ // set up our texture mode
1065+ nux::TexCoordXForm texxform;
1066+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
1067+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
1068+
1069+ // clear what is behind us
1070+ unsigned int alpha = 0, src = 0, dest = 0;
1071+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
1072+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1073+
1074+ nux::ObjectPtr<nux::IOpenGLBaseTexture> tex = cr_bubble_->GetTexture()->GetDeviceTexture();
1075+
1076+ nux::Geometry geo_bubble(GetBubbleGeometry(geo));
1077+
1078+ gfx_engine.QRP_1Tex(geo_bubble.x,
1079+ geo_bubble.y,
1080+ tex->GetWidth(),
1081+ tex->GetHeight(),
1082+ tex,
1083+ texxform,
1084+ nux::Color(0.2f, 0.2f, 0.2f, 0.2f));
1085+
1086+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
1087+
1088+ if (GetCompositionLayout())
1089+ {
1090+ gPainter.PushPaintLayerStack();
1091+ {
1092+ nux::Geometry clip_geo = geo;
1093+
1094+ gfx_engine.PushClippingRectangle(clip_geo);
1095+ gPainter.PushPaintLayerStack();
1096+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
1097+ gPainter.PopPaintLayerStack();
1098+ gfx_engine.PopClippingRectangle();
1099+ }
1100+ gPainter.PopPaintLayerStack();
1101+ }
1102+}
1103+
1104+void SocialPreviewContent::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
1105+{
1106+}
1107+
1108+void SocialPreviewContent::SetupViews()
1109+{
1110+ dash::previews::Style const& style = dash::previews::Style::Instance();
1111+
1112+ text_ = new nux::StaticCairoText("", false, NUX_TRACKER_LOCATION);
1113+ text_->SetLines(-8);
1114+ text_->SetFont(style.content_font());
1115+ text_->SetLineSpacing(5);
1116+ text_->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_MIDDLE);
1117+
1118+ nux::Layout* layout = new nux::Layout();
1119+ layout->AddView(text_.GetPointer(), 1);
1120+ SetLayout(layout);
1121+
1122+ cr_bubble_.reset(new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &SocialPreviewContent::RedrawBubble), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
1123+}
1124+
1125+void SocialPreviewContent::UpdateBaloonTexture()
1126+{
1127+ nux::Geometry const& geo = GetGeometry();
1128+
1129+ nux::Geometry geo_cr(GetBubbleGeometry(geo));
1130+
1131+ double tail_width = MAX(0, MIN(geo_cr.width - 2*15.0, MIN(geo_cr.width*0.125, geo_cr.height*0.125)));
1132+
1133+ int max_width = geo_cr.width - 2*(geo_cr.width*0.1);
1134+ int max_height = geo_cr.height - 2*(geo_cr.height*0.1) - tail_width;
1135+
1136+ // this will update the texture with the actual size of the text.
1137+ text_->SetMaximumHeight(max_height);
1138+ text_->SetMaximumWidth(max_width);
1139+ nux::Geometry const& geo_text = text_->GetGeometry();
1140+
1141+ // center text
1142+ text_->SetBaseX(geo.x + geo.width/2 - geo_text.width/2);
1143+ text_->SetBaseY(geo.y + geo.height/2 - geo_text.height/2 - tail_width/2);
1144+
1145+ if (geo_cr.width > 0 && geo_cr.height > 0)
1146+ {
1147+ cr_bubble_->Invalidate(geo_cr);
1148+ }
1149+}
1150+
1151+void SocialPreviewContent::RedrawBubble(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
1152+{
1153+ double blur = 4.0;
1154+
1155+ double line_width = 1.0;
1156+ double radius = 20.0;
1157+ double tailWidthPercentage = 0.125;
1158+ double tailPositionPercentage = 0.7;
1159+ double x = 0.0 + blur;
1160+ double y = 0.0 + blur;
1161+ double width = cairo_image_surface_get_width(cairo_get_target(cr)) - 2*blur;
1162+ double height = cairo_image_surface_get_height(cairo_get_target(cr)) - 2*blur;
1163+
1164+ if (width > 0 && height > 0)
1165+ {
1166+ DrawBubble(cr, line_width, radius, x, y, width, height, tailPositionPercentage, tailWidthPercentage);
1167+ dash::Style::Instance().Blur(cr, blur);
1168+ }
1169+}
1170+
1171+inline double _align(double val, bool odd=true)
1172+{
1173+ double fract = val - (int) val;
1174+
1175+ if (odd)
1176+ {
1177+ // for strokes with an odd line-width
1178+ if (fract != 0.5f)
1179+ return (double) ((int) val + 0.5f);
1180+ else
1181+ return val;
1182+ }
1183+ else
1184+ {
1185+ // for strokes with an even line-width
1186+ if (fract != 0.0f)
1187+ return (double) ((int) val);
1188+ else
1189+ return val;
1190+ }
1191+}
1192+
1193+void SocialPreviewContent::DrawBubble(cairo_t* cr,
1194+ double line_width,
1195+ double radius,
1196+ double x,
1197+ double y,
1198+ double width,
1199+ double height,
1200+ double tailPositionPercentage,
1201+ double tailWidthPercentage)
1202+{
1203+ // sanity check
1204+ if (cairo_status(cr) != CAIRO_STATUS_SUCCESS &&
1205+ cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE)
1206+ return;
1207+
1208+ cairo_set_line_width(cr, line_width);
1209+
1210+ double tailWidth = MAX(0, MIN(width - 2*radius, MIN(width*tailWidthPercentage, height*tailWidthPercentage)));
1211+ double tail_start_pos = x + tailPositionPercentage*width - tailWidth/2;
1212+
1213+ // recitfications for outer draw.
1214+ x += line_width/2;
1215+ y += line_width/2;
1216+ height -= line_width;
1217+ height -= tailWidth;
1218+ width -= line_width;
1219+
1220+ bool odd = true;
1221+ odd = line_width != double((int)line_width);
1222+
1223+ // top-left, right of the corner
1224+ cairo_move_to(cr, _align (x + radius, odd), _align (y, odd));
1225+
1226+ // top-right, left of the corner
1227+ cairo_line_to(cr, _align(x + width - radius, odd), _align(y, odd));
1228+
1229+ // top-right, below the corner
1230+ cairo_arc(cr,
1231+ _align(x + width - radius, odd),
1232+ _align(y + radius, odd),
1233+ radius,
1234+ -90.0f * G_PI / 180.0f,
1235+ 0.0f * G_PI / 180.0f);
1236+
1237+ // bottom-right, above the corner
1238+ cairo_line_to(cr, _align(x + width, odd), _align(y + height - radius, odd));
1239+
1240+ // bottom-right, left of the corner
1241+ cairo_arc(cr,
1242+ _align(x + width - radius, odd),
1243+ _align(y + height - radius, odd),
1244+ radius,
1245+ 0.0f * G_PI / 180.0f,
1246+ 90.0f * G_PI / 180.0f);
1247+
1248+ if (tailWidth > 0.0)
1249+ {
1250+ // tail-right, tail top
1251+ cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height, odd));
1252+
1253+ // tail-right, tail bottom
1254+ cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height + tailWidth, odd));
1255+
1256+ // tail-right, tail bottom
1257+ cairo_line_to(cr, _align(tail_start_pos, odd), _align(y + height, odd));
1258+ }
1259+
1260+ // bottom-left, right of the corner
1261+ cairo_line_to(cr, _align(x + radius, odd), _align(y + height, odd));
1262+
1263+ // bottom-left, above the corner
1264+ cairo_arc(cr,
1265+ _align(x + radius, odd),
1266+ _align(y + height - radius, odd),
1267+ radius,
1268+ 90.0f * G_PI / 180.0f,
1269+ 180.0f * G_PI / 180.0f);
1270+
1271+ // top-left, right of the corner
1272+ cairo_arc(cr,
1273+ _align(x + radius, odd),
1274+ _align(y + radius, odd),
1275+ radius,
1276+ 180.0f * G_PI / 180.0f,
1277+ 270.0f * G_PI / 180.0f);
1278+
1279+
1280+ nux::Color color(0.53, 1.0, 0.66, 0.5);
1281+ if (color.alpha != 0.0)
1282+ {
1283+ cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
1284+ cairo_fill_preserve(cr);
1285+ }
1286+ cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
1287+ cairo_stroke(cr);
1288+}
1289+
1290+void SocialPreviewContent::PreLayoutManagement()
1291+{
1292+ UpdateBaloonTexture();
1293+
1294+ View::PreLayoutManagement();
1295+}
1296+
1297+std::string SocialPreviewContent::GetName() const
1298+{
1299+ return "SocialPreviewContent";
1300+}
1301+
1302+void SocialPreviewContent::AddProperties(GVariantBuilder* builder)
1303+{
1304+}
1305+
1306+}
1307+}
1308+}
1309
1310=== added file 'dash/previews/SocialPreviewContent.h'
1311--- dash/previews/SocialPreviewContent.h 1970-01-01 00:00:00 +0000
1312+++ dash/previews/SocialPreviewContent.h 2012-09-17 14:17:20 +0000
1313@@ -0,0 +1,86 @@
1314+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1315+/*
1316+ * Copyright 2011 Canonical Ltd.
1317+ *
1318+ * This program is free software: you can redistribute it and/or modify it
1319+ * under the terms of the GNU Lesser General Public License version 3, as
1320+ * published by the Free Software Foundation.
1321+ *
1322+ * This program is distributed in the hope that it will be useful, but
1323+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1324+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1325+ * PURPOSE. See the applicable version of the GNU Lesser General Public
1326+ * License for more details.
1327+ *
1328+ * You should have received a copy of both the GNU Lesser General Public
1329+ * License version 3 along with this program. If not, see
1330+ * <http://www.gnu.org/licenses/>
1331+ *
1332+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
1333+ * Ken VanDine <ken.vandine@canonical.com>
1334+ *
1335+ */
1336+
1337+#ifndef SOCIAL_PREVIEW_CONTENT_H
1338+#define SOCIAL_PREVIEW_CONTENT_H
1339+
1340+#include <Nux/Nux.h>
1341+#include <Nux/View.h>
1342+#include <Nux/CairoWrapper.h>
1343+#include <NuxCore/ObjectPtr.h>
1344+#include "unity-shared/StaticCairoText.h"
1345+#include "unity-shared/Introspectable.h"
1346+
1347+namespace unity
1348+{
1349+namespace dash
1350+{
1351+namespace previews
1352+{
1353+
1354+class SocialPreviewContent : public nux::View, public unity::debug::Introspectable
1355+{
1356+public:
1357+ typedef nux::ObjectPtr<SocialPreviewContent> Ptr;
1358+ NUX_DECLARE_OBJECT_TYPE(SocialPreviewContent, nux::View);
1359+
1360+ SocialPreviewContent(std::string const& text, NUX_FILE_LINE_PROTO);
1361+ virtual ~SocialPreviewContent();
1362+
1363+ void SetText(std::string const& text);
1364+
1365+protected:
1366+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
1367+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
1368+ virtual void PreLayoutManagement();
1369+
1370+ virtual bool AcceptKeyNavFocus() { return false; }
1371+
1372+ void SetupViews();
1373+ void UpdateBaloonTexture();
1374+ void RedrawBubble(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
1375+ void DrawBubble(cairo_t* cr,
1376+ double line_width,
1377+ double radius,
1378+ double x,
1379+ double y,
1380+ double width,
1381+ double height,
1382+ double tailPositionPercentage,
1383+ double tailWidthPercentage);
1384+
1385+ virtual std::string GetName() const;
1386+ virtual void AddProperties(GVariantBuilder* builder);
1387+
1388+private:
1389+ nux::ObjectPtr<nux::StaticCairoText> text_;
1390+
1391+ typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr;
1392+ NuxCairoPtr cr_bubble_;
1393+};
1394+
1395+}
1396+}
1397+}
1398+
1399+#endif // SOCIAL_PREVIEW_CONTENT_H
1400
1401=== added file 'dash/previews/StandaloneSocialPreview.cpp'
1402--- dash/previews/StandaloneSocialPreview.cpp 1970-01-01 00:00:00 +0000
1403+++ dash/previews/StandaloneSocialPreview.cpp 2012-09-17 14:17:20 +0000
1404@@ -0,0 +1,287 @@
1405+/*
1406+ * Copyright 2012 Canonical Ltd.
1407+ *
1408+ * This program is free software: you can redistribute it and/or modify it
1409+ * under the terms of the GNU General Public License version 3, as published
1410+ * by the Free Software Foundation.
1411+ *
1412+ * This program is distributed in the hope that it will be useful, but
1413+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1414+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1415+ * PURPOSE. See the GNU General Public License for more details.
1416+ *
1417+ * You should have received a copy of the GNU General Public License
1418+ * version 3 along with this program. If not, see
1419+ * <http://www.gnu.org/licenses/>
1420+ *
1421+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
1422+ *
1423+ */
1424+#include <gtk/gtk.h>
1425+
1426+#include "Nux/Nux.h"
1427+#include "Nux/VLayout.h"
1428+#include "Nux/WindowThread.h"
1429+#include "NuxGraphics/GraphicsEngine.h"
1430+#include <Nux/Layout.h>
1431+#include <NuxCore/Logger.h>
1432+#include <UnityCore/Variant.h>
1433+#include <UnityCore/SocialPreview.h>
1434+#include <unity-protocol.h>
1435+
1436+#include "unity-shared/FontSettings.h"
1437+#include "unity-shared/UnitySettings.h"
1438+#include "unity-shared/PreviewStyle.h"
1439+#include "unity-shared/DashStyle.h"
1440+#include "unity-shared/ThumbnailGenerator.h"
1441+
1442+#include "Preview.h"
1443+#include "PreviewContainer.h"
1444+
1445+
1446+#define WIDTH 910
1447+#define HEIGHT 400
1448+
1449+using namespace unity;
1450+using namespace unity::dash;
1451+
1452+class DummyView : public nux::View
1453+{
1454+public:
1455+ DummyView(nux::View* view)
1456+ : View(NUX_TRACKER_LOCATION)
1457+ {
1458+ SetAcceptKeyNavFocusOnMouseDown(false);
1459+ SetAcceptKeyNavFocusOnMouseEnter(false);
1460+
1461+ nux::ROPConfig rop;
1462+ rop.Blend = true;
1463+ rop.SrcBlend = GL_ONE;
1464+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
1465+ bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
1466+
1467+ nux::Layout* layout = new nux::VLayout();
1468+ layout->SetPadding(16);
1469+ layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
1470+ SetLayout(layout);
1471+ }
1472+
1473+ // Keyboard navigation
1474+ bool AcceptKeyNavFocus()
1475+ {
1476+ return false;
1477+ }
1478+
1479+protected:
1480+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
1481+ {
1482+ nux::Geometry const& base = GetGeometry();
1483+
1484+ gfx_engine.PushClippingRectangle(base);
1485+ nux::GetPainter().PaintBackground(gfx_engine, base);
1486+
1487+ unsigned int alpha, src, dest = 0;
1488+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
1489+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1490+
1491+ bg_layer_->SetGeometry(GetGeometry());
1492+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
1493+
1494+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
1495+
1496+ gfx_engine.PopClippingRectangle();
1497+ }
1498+
1499+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
1500+ {
1501+ nux::Geometry const& base = GetGeometry();
1502+ gfx_engine.PushClippingRectangle(base);
1503+
1504+ if (!IsFullRedraw())
1505+ nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
1506+
1507+ if (GetCompositionLayout())
1508+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
1509+
1510+ if (!IsFullRedraw())
1511+ nux::GetPainter().PopBackground();
1512+
1513+ gfx_engine.PopClippingRectangle();
1514+ }
1515+
1516+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
1517+ LayerPtr bg_layer_;
1518+};
1519+
1520+class TestRunner
1521+{
1522+public:
1523+ TestRunner ();
1524+ ~TestRunner ();
1525+
1526+ static void InitWindowThread (nux::NThread* thread, void* InitData);
1527+ void Init ();
1528+ void NavRight();
1529+ void NavLeft();
1530+
1531+ previews::PreviewContainer::Ptr container_;
1532+ nux::Layout *layout_;
1533+ int nav_iter;
1534+ glib::Source::UniquePtr preview_wait_timer_;
1535+};
1536+
1537+TestRunner::TestRunner ()
1538+{
1539+ nav_iter = 0;
1540+}
1541+
1542+TestRunner::~TestRunner ()
1543+{
1544+}
1545+
1546+void TestRunner::Init ()
1547+{
1548+ container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
1549+ container_->navigate_right.connect(sigc::mem_fun(this, &TestRunner::NavRight));
1550+ container_->navigate_left.connect(sigc::mem_fun(this, &TestRunner::NavLeft));
1551+ container_->request_close.connect([&]() { exit(0); });
1552+
1553+ DummyView* dummyView = new DummyView(container_.GetPointer());
1554+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
1555+ layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
1556+ nux::GetWindowThread()->SetLayout (layout_);
1557+
1558+ const char* title = "Candace Flynn";
1559+ const char* subtitle = "@candacejeremyxo, 10 Aug 2012 05:01";
1560+ const char* description = "Lorem ipsum dolor sit amet, id eruditi referrentur cum, et est enim persequeris. Munere docendi intellegebat pro id, nam no delenit facilisis similique, ut usu eros aliquando. Electram postulant accusamus ut ius, cum ad impedit facilis mediocrem. At cum tamquam.";
1561+
1562+ glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/sunflower.jpg", NULL));
1563+ glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
1564+
1565+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
1566+
1567+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
1568+
1569+ unity_protocol_social_preview_set_content(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), description);
1570+
1571+ unity_protocol_preview_set_title(proto_obj, title);
1572+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
1573+ unity_protocol_preview_set_description(proto_obj, description);
1574+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
1575+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
1576+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Stacy", "Lorem ipsum dolor sit amet, id eruditi referrentur cum, et est enim persequeris. Munere docendi intellegebat pro id, nam no delenit facilisis similique, ut usu eros aliquando. Electram postulant accusamus ut ius, cum ad impedit facilis mediocrem. At cum tamquam.", "13 minutes ago");
1577+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Jeremy", "This is a comment", "4 hours ago");
1578+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Stacy", "This is a comment", "4 hours ago");
1579+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
1580+
1581+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
1582+ glib::StealRef());
1583+
1584+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
1585+ container_->Preview(preview_model, previews::Navigation::RIGHT);
1586+
1587+}
1588+
1589+void TestRunner::NavRight()
1590+{
1591+ const char* title = "Phineas Flynn";
1592+ const char* subtitle = "@phineasflynn12, 10 Aug 2012 05:01";
1593+ const char* description = "I know what we are going to do today!";
1594+
1595+ // creates a generic preview object
1596+ glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/astronaut.jpg", NULL));
1597+ glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
1598+
1599+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
1600+
1601+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
1602+
1603+ unity_protocol_preview_set_title(proto_obj, title);
1604+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
1605+ unity_protocol_preview_set_description(proto_obj, description);
1606+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
1607+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
1608+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
1609+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Ferb", "This is a comment, yes it really is, i think so anyway... maybe it isn't? hard to really tell. This is a comment, yes it really is, i think so anyway... maybe it isn't? hard to really tell. This is a comment, yes it really is, i think so anyway... maybe it isn't? hard to really tell.", "4 hours ago...");
1610+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Baljeet", "This is a comment", "4 hours ago");
1611+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Buford", "This is a comment", "4 hours ago");
1612+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "Where's Perry?", "4 hours ago");
1613+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Pery the Platypus", "Over here", "4 hours ago");
1614+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Buford", "This is a comment", "4 hours ago");
1615+ unity_protocol_preview_add_info_hint(proto_obj, "likes", "Favorites", nullptr, g_variant_new("i", 1210));
1616+ unity_protocol_preview_add_info_hint(proto_obj, "retweets", "Retweets", nullptr, g_variant_new("i", 21));
1617+
1618+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
1619+ glib::StealRef());
1620+
1621+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
1622+ container_->Preview(preview_model, previews::Navigation::RIGHT);
1623+}
1624+
1625+void TestRunner::NavLeft()
1626+{
1627+ const char* title = "Ferb Fletcher";
1628+ const char* subtitle = "@ferbfletcher123, 10 Aug 2012 05:01";
1629+ const char* description = "Profile pictures are what people want them to think they look like. Tagged pictures are what they really look like.";
1630+
1631+ glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/soccerball.png", NULL));
1632+ glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
1633+
1634+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
1635+
1636+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
1637+
1638+ unity_protocol_preview_set_title(proto_obj, title);
1639+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
1640+ unity_protocol_preview_set_description(proto_obj, description);
1641+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
1642+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
1643+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Baljeet", "This is a comment", "4 hours ago");
1644+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
1645+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Candace", "This is a comment", "4 hours ago");
1646+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Vanessa", "This is a comment", "4 hours ago");
1647+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Major Monogram", "I'm a comment", "4 hours ago");
1648+ unity_protocol_preview_add_info_hint(proto_obj, "likes", "Favorites", nullptr, g_variant_new("i", 123));
1649+ unity_protocol_preview_add_info_hint(proto_obj, "retweets", "Retweets", nullptr, g_variant_new("i", 12));
1650+
1651+
1652+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
1653+ glib::StealRef());
1654+
1655+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
1656+ container_->Preview(preview_model, previews::Navigation::LEFT);
1657+}
1658+
1659+void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
1660+{
1661+ TestRunner *self = (TestRunner *) InitData;
1662+ self->Init ();
1663+}
1664+
1665+int main(int argc, char **argv)
1666+{
1667+ nux::WindowThread* wt = NULL;
1668+
1669+ gtk_init (&argc, &argv);
1670+
1671+ nux::NuxInitialize(0);
1672+ nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
1673+ // The instances for the pseudo-singletons.
1674+ unity::Settings settings;
1675+ unity::dash::previews::Style panel_style;
1676+ unity::dash::Style dash_style;
1677+ unity::ThumbnailGenerator thumbnail_generator;
1678+
1679+ TestRunner *test_runner = new TestRunner ();
1680+ wt = nux::CreateGUIThread(TEXT("Unity Preview"),
1681+ WIDTH, HEIGHT,
1682+ 0,
1683+ &TestRunner::InitWindowThread,
1684+ test_runner);
1685+
1686+ wt->Run (NULL);
1687+ delete wt;
1688+ return 0;
1689+}
1690+
1691+
1692
1693=== modified file 'tests/CMakeLists.txt'
1694--- tests/CMakeLists.txt 2012-09-11 10:38:31 +0000
1695+++ tests/CMakeLists.txt 2012-09-17 14:17:20 +0000
1696@@ -220,6 +220,7 @@
1697 test_previews_generic.cpp
1698 test_previews_movie.cpp
1699 test_previews_music.cpp
1700+ test_previews_social.cpp
1701 test_quicklist_menu_item.cpp
1702 test_quicklist_view.cpp
1703 test_resultviewgrid.cpp
1704@@ -248,6 +249,9 @@
1705 ${CMAKE_SOURCE_DIR}/dash/previews/Preview.cpp
1706 ${CMAKE_SOURCE_DIR}/dash/previews/PreviewInfoHintWidget.cpp
1707 ${CMAKE_SOURCE_DIR}/dash/previews/PreviewRatingsWidget.cpp
1708+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreview.cpp
1709+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreviewContent.cpp
1710+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreviewComments.cpp
1711 ${CMAKE_SOURCE_DIR}/dash/previews/Tracks.cpp
1712 ${CMAKE_SOURCE_DIR}/dash/previews/Track.cpp
1713 ${CMAKE_SOURCE_DIR}/hud/HudAbstractView.cpp
1714
1715=== added file 'tests/test_previews_social.cpp'
1716--- tests/test_previews_social.cpp 1970-01-01 00:00:00 +0000
1717+++ tests/test_previews_social.cpp 2012-09-17 14:17:20 +0000
1718@@ -0,0 +1,110 @@
1719+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1720+/*
1721+ * Copyright (C) 2012 Canonical Ltd
1722+ *
1723+ * This program is free software: you can redistribute it and/or modify
1724+ * it under the terms of the GNU General Public License version 3 as
1725+ * published by the Free Software Foundation.
1726+ *
1727+ * This program is distributed in the hope that it will be useful,
1728+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1729+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1730+ * GNU General Public License for more details.
1731+ *
1732+ * You should have received a copy of the GNU General Public License
1733+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1734+ *
1735+ * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
1736+ * Ken VanDine <ken.vandine@canonical.com>
1737+ */
1738+
1739+#include <list>
1740+#include <gmock/gmock.h>
1741+using namespace testing;
1742+
1743+#include <Nux/Nux.h>
1744+#include <Nux/BaseWindow.h>
1745+#include <unity-shared/StaticCairoText.h>
1746+#include <unity-shared/DashStyle.h>
1747+#include <unity-shared/PreviewStyle.h>
1748+#include <unity-shared/ThumbnailGenerator.h>
1749+#include "unity-shared/UnitySettings.h"
1750+
1751+#include <unity-protocol.h>
1752+#include "UnityCore/SocialPreview.h"
1753+#include "dash/previews/SocialPreview.h"
1754+#include "dash/previews/SocialPreviewContent.h"
1755+#include "dash/previews/SocialPreviewComments.h"
1756+#include "dash/previews/PreviewInfoHintWidget.h"
1757+#include "dash/previews/PreviewRatingsWidget.h"
1758+#include "test_utils.h"
1759+using namespace unity;
1760+using namespace unity::dash;
1761+
1762+namespace
1763+{
1764+
1765+class MockSocialPreview : public previews::SocialPreview
1766+{
1767+public:
1768+ typedef nux::ObjectPtr<MockSocialPreview> Ptr;
1769+
1770+ MockSocialPreview(dash::Preview::Ptr preview_model)
1771+ : SocialPreview(preview_model)
1772+ {}
1773+
1774+ using SocialPreview::title_;
1775+ using SocialPreview::subtitle_;
1776+ using SocialPreview::content_;
1777+ using SocialPreview::action_buttons_;
1778+ using SocialPreview::preview_info_hints_;
1779+};
1780+
1781+class TestPreviewSocial : public Test
1782+{
1783+public:
1784+ TestPreviewSocial()
1785+ : parent_window_(new nux::BaseWindow("TestPreviewSocial"))
1786+ {
1787+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
1788+
1789+ unity_protocol_preview_set_image_source_uri(proto_obj, "http://ia.media-imdb.com/images/M/MV5BMTM3NDM5MzY5Ml5BMl5BanBnXkFtZTcwNjExMDUwOA@@._V1._SY317_.jpg");
1790+ unity_protocol_preview_set_title(proto_obj, "Social Title & special char");
1791+ unity_protocol_preview_set_subtitle(proto_obj, "Social Subtitle > special char");
1792+ unity_protocol_preview_set_description(proto_obj, "Social Desctiption &lt; special char");
1793+ unity_protocol_preview_add_action(proto_obj, "action1", "Action 1", NULL, 0);
1794+ unity_protocol_preview_add_action(proto_obj, "action2", "Action 2", NULL, 0);
1795+ unity_protocol_preview_add_info_hint(proto_obj, "hint1", "Hint 1", NULL, g_variant_new("s", "string hint 1"));
1796+ unity_protocol_preview_add_info_hint(proto_obj, "hint2", "Hint 2", NULL, g_variant_new("s", "string hint 2"));
1797+ unity_protocol_preview_add_info_hint(proto_obj, "hint3", "Hint 3", NULL, g_variant_new("i", 12));
1798+
1799+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
1800+ preview_model_ = dash::Preview::PreviewForVariant(v);
1801+ }
1802+
1803+ nux::BaseWindow* parent_window_;
1804+ dash::Preview::Ptr preview_model_;
1805+
1806+ unity::Settings settings;
1807+ previews::Style panel_style;
1808+ dash::Style dash_style;
1809+ ThumbnailGenerator thumbnail_generator;
1810+};
1811+
1812+TEST_F(TestPreviewSocial, TestCreate)
1813+{
1814+ previews::Preview::Ptr preview_view = previews::Preview::PreviewForModel(preview_model_);
1815+
1816+ EXPECT_TRUE(dynamic_cast<previews::SocialPreview*>(preview_view.GetPointer()) != NULL);
1817+}
1818+
1819+TEST_F(TestPreviewSocial, TestUIValues)
1820+{
1821+ MockSocialPreview::Ptr preview_view(new MockSocialPreview(preview_model_));
1822+
1823+ EXPECT_EQ(preview_view->title_->GetText(), "Social Title &amp; special char");
1824+ EXPECT_EQ(preview_view->subtitle_->GetText(), "Social Subtitle &gt; special char");
1825+ EXPECT_EQ(preview_view->action_buttons_.size(), 2);
1826+}
1827+
1828+}
1829
1830=== modified file 'unity-shared/PreviewStyle.cpp'
1831--- unity-shared/PreviewStyle.cpp 2012-09-17 10:00:38 +0000
1832+++ unity-shared/PreviewStyle.cpp 2012-09-17 14:17:20 +0000
1833@@ -292,6 +292,21 @@
1834 return float(540)/380;
1835 }
1836
1837+int Style::GetAvatarAreaWidth() const
1838+{
1839+ return 100;
1840+}
1841+
1842+int Style::GetAvatarAreaHeight() const
1843+{
1844+ return 100;
1845+}
1846+
1847+std::string Style::content_font() const
1848+{
1849+ return "Ubuntu Light 12";
1850+}
1851+
1852 std::string Style::title_font() const
1853 {
1854 return "Ubuntu 22";
1855
1856=== modified file 'unity-shared/PreviewStyle.h'
1857--- unity-shared/PreviewStyle.h 2012-09-14 23:28:40 +0000
1858+++ unity-shared/PreviewStyle.h 2012-09-17 14:17:20 +0000
1859@@ -81,6 +81,9 @@
1860 int GetInfoHintNameMinimumWidth() const;
1861 int GetInfoHintNameMaximumWidth() const;
1862
1863+ int GetCommentNameMinimumWidth() const;
1864+ int GetCommentNameMaximumWidth() const;
1865+
1866 float GetDescriptionLineSpacing() const;
1867 int GetDescriptionLineCount() const;
1868
1869@@ -129,6 +132,15 @@
1870 int GetStatusIconSize() const;
1871 ////////////////////////////////
1872
1873+ ////////////////////////////////
1874+ // Social Preview
1875+ int GetAvatarAreaWidth() const;
1876+ int GetAvatarAreaHeight() const;
1877+
1878+ std::string content_font() const;
1879+
1880+ ////////////////////////////////
1881+
1882 nux::BaseTexture* GetNavLeftIcon();
1883 nux::BaseTexture* GetNavRightIcon();
1884 nux::BaseTexture* GetPlayIcon();