Merge lp:~ken-vandine/unity/6_with_social_preview into lp:unity/6.0

Proposed by Ken VanDine
Status: Merged
Approved by: Ken VanDine
Approved revision: no longer in the source branch.
Merged at revision: 2688
Proposed branch: lp:~ken-vandine/unity/6_with_social_preview
Merge into: lp:unity/6.0
Diff against target: 1880 lines (+1712/-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 (+305/-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/6_with_social_preview
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+124513@code.launchpad.net

Commit message

Adds SocialPreview

Description of the change

Adds 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/1313/console reported an error when processing this lp:~ken-vandine/unity/6_with_social_preview branch.
Not merging it.

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

Subscribers

People subscribed via source and target branches