=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2012-08-30 13:15:09 +0000
+++ UnityCore/CMakeLists.txt 2012-09-14 20:35:43 +0000
@@ -46,6 +46,7 @@
ResultIterator.h
Results.h
SeriesPreview.h
+ SocialPreview.h
Track.h
Tracks.h
Variant.h
@@ -84,6 +85,7 @@
ResultIterator.cpp
Results.cpp
SeriesPreview.cpp
+ SocialPreview.cpp
Track.cpp
Tracks.cpp
Variant.cpp
=== modified file 'UnityCore/Preview.cpp'
--- UnityCore/Preview.cpp 2012-09-11 09:15:29 +0000
+++ UnityCore/Preview.cpp 2012-09-14 20:35:43 +0000
@@ -28,6 +28,7 @@
#include "GenericPreview.h"
#include "MusicPreview.h"
#include "MoviePreview.h"
+#include "SocialPreview.h"
#include "SeriesPreview.h"
namespace unity
@@ -68,6 +69,10 @@
{
return Preview::Ptr(new MoviePreview(proto_obj));
}
+ else if (renderer_name == "preview-social")
+ {
+ return Preview::Ptr(new SocialPreview(proto_obj));
+ }
else if (renderer_name == "preview-series")
{
return Preview::Ptr(new SeriesPreview(proto_obj));
=== added file 'UnityCore/SocialPreview.cpp'
--- UnityCore/SocialPreview.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/SocialPreview.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,105 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2011-2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#include
+
+#include "SocialPreview.h"
+
+namespace unity
+{
+namespace dash
+{
+
+class SocialPreview::Impl
+{
+public:
+ Impl(SocialPreview* owner, glib::Object const& proto_obj);
+
+
+ void SetupGetters();
+ std::string get_sender() { return sender_; };
+ std::string get_content() { return content_; };
+ glib::Object get_avatar() { return avatar_; };
+ CommentPtrList get_comments() const { return comments_list_; };
+
+ SocialPreview* owner_;
+
+ std::string sender_;
+ std::string content_;
+ glib::Object avatar_;
+ CommentPtrList comments_list_;
+};
+
+SocialPreview::Impl::Impl(SocialPreview* owner, glib::Object const& proto_obj)
+ : owner_(owner)
+{
+ const gchar* s;
+ auto preview = glib::object_cast(proto_obj);
+
+ s = unity_protocol_social_preview_get_sender(preview);
+ if (s) sender_ = s;
+ s = unity_protocol_social_preview_get_content(preview);
+ if (s) content_ = s;
+
+ glib::Object icon(unity_protocol_social_preview_get_avatar(preview),
+ glib::AddRef());
+ avatar_ = icon;
+
+ int comments_len;
+ auto comments = unity_protocol_social_preview_get_comments(preview, &comments_len);
+ for (int i = 0; i < comments_len; i++)
+ {
+ UnityProtocolSocialPreviewCommentRaw *raw_comment = &comments[i];
+ comments_list_.push_back(std::make_shared(
+ raw_comment->id, raw_comment->display_name, raw_comment->content,
+ raw_comment->time));
+ }
+
+ SetupGetters();
+}
+
+void SocialPreview::Impl::SetupGetters()
+{
+ owner_->sender.SetGetterFunction(
+ sigc::mem_fun(this, &SocialPreview::Impl::get_sender));
+ owner_->content.SetGetterFunction(
+ sigc::mem_fun(this, &SocialPreview::Impl::get_content));
+ owner_->avatar.SetGetterFunction(
+ sigc::mem_fun(this, &SocialPreview::Impl::get_avatar));
+}
+
+SocialPreview::SocialPreview(unity::glib::Object const& proto_obj)
+ : Preview(proto_obj)
+ , pimpl(new Impl(this, proto_obj))
+{
+}
+
+SocialPreview::CommentPtrList SocialPreview::GetComments() const
+{
+ return pimpl->get_comments();
+}
+
+
+SocialPreview::~SocialPreview()
+{
+}
+
+}
+}
=== added file 'UnityCore/SocialPreview.h'
--- UnityCore/SocialPreview.h 1970-01-01 00:00:00 +0000
+++ UnityCore/SocialPreview.h 2012-09-14 20:35:43 +0000
@@ -0,0 +1,77 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2011-2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#ifndef UNITY_SOCIAL_PREVIEW_H
+#define UNITY_SOCIAL_PREVIEW_H
+
+#include
+
+#include
+
+#include "Preview.h"
+
+namespace unity
+{
+namespace dash
+{
+
+class SocialPreview : public Preview
+{
+public:
+ struct Comment
+ {
+ std::string id;
+ std::string display_name;
+ std::string content;
+ std::string time;
+
+ Comment() {};
+ Comment(const gchar* id_, const gchar* display_name_,
+ const gchar* content_, const gchar* time_)
+ : id(id_ != NULL ? id_ : "")
+ , display_name(display_name_ != NULL ? display_name_ : "")
+ , content(content_ != NULL ? content_ : "")
+ , time(time_ != NULL ? time_ : "") {};
+ };
+
+ typedef std::shared_ptr Ptr;
+ typedef std::shared_ptr CommentPtr;
+ typedef std::vector CommentPtrList;
+
+ SocialPreview(unity::glib::Object const& proto_obj);
+ ~SocialPreview();
+
+ nux::RWProperty sender;
+ nux::RWProperty title;
+ nux::RWProperty content;
+ nux::RWProperty> avatar;
+
+ CommentPtrList GetComments() const;
+
+
+private:
+ class Impl;
+ std::unique_ptr pimpl;
+};
+
+}
+}
+
+#endif
=== modified file 'dash/previews/CMakeLists.txt'
--- dash/previews/CMakeLists.txt 2012-09-03 17:24:11 +0000
+++ dash/previews/CMakeLists.txt 2012-09-14 20:35:43 +0000
@@ -38,6 +38,9 @@
PreviewInfoHintWidget.cpp
PreviewNavigator.cpp
PreviewRatingsWidget.cpp
+ SocialPreview.cpp
+ SocialPreviewContent.cpp
+ SocialPreviewComments.cpp
Track.cpp
Tracks.cpp
)
@@ -61,6 +64,13 @@
target_link_libraries (music_previews previews-lib unity-shared)
#
+# Social Standalone variant
+#
+add_executable (social_previews StandaloneSocialPreview.cpp)
+add_dependencies (social_previews previews-lib)
+target_link_libraries (social_previews previews-lib unity-shared)
+
+#
# Music Standalone variant
#
add_executable (movie_previews StandaloneMoviePreview.cpp)
=== modified file 'dash/previews/Preview.cpp'
--- dash/previews/Preview.cpp 2012-08-22 08:16:02 +0000
+++ dash/previews/Preview.cpp 2012-09-14 20:35:43 +0000
@@ -32,6 +32,7 @@
#include "ApplicationPreview.h"
#include "MusicPreview.h"
#include "MoviePreview.h"
+#include "SocialPreview.h"
namespace unity
{
@@ -69,6 +70,10 @@
{
return Preview::Ptr(new MoviePreview(model));
}
+ else if (model->renderer_name == "preview-social")
+ {
+ return Preview::Ptr(new SocialPreview(model));
+ }
// else if (renderer_name == "preview-series")
// {
// return Preview::Ptr(new SeriesPreview(model));
=== added file 'dash/previews/SocialPreview.cpp'
--- dash/previews/SocialPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreview.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,305 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#include "unity-shared/IntrospectableWrappers.h"
+#include "unity-shared/PreviewStyle.h"
+#include "unity-shared/CoverArt.h"
+#include "unity-shared/IconTexture.h"
+#include "unity-shared/StaticCairoText.h"
+#include "unity-shared/PlacesVScrollBar.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "SocialPreview.h"
+#include "SocialPreviewContent.h"
+#include "SocialPreviewComments.h"
+#include "ActionButton.h"
+#include "PreviewInfoHintWidget.h"
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+namespace
+{
+nux::logging::Logger logger("unity.dash.previews.socialpreview");
+
+}
+
+class DetailsScrollView : public nux::ScrollView
+{
+public:
+ DetailsScrollView(NUX_FILE_LINE_PROTO)
+ : ScrollView(NUX_FILE_LINE_PARAM)
+ {
+ SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
+ }
+
+};
+
+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreview);
+
+SocialPreview::SocialPreview(dash::Preview::Ptr preview_model)
+: Preview(preview_model)
+, full_data_layout_(nullptr)
+{
+ SetupBackground();
+ SetupViews();
+}
+
+SocialPreview::~SocialPreview()
+{
+}
+
+void SocialPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+ nux::Geometry const& base = GetGeometry();
+
+ gfx_engine.PushClippingRectangle(base);
+ nux::GetPainter().PaintBackground(gfx_engine, base);
+
+ if (full_data_layout_)
+ {
+ unsigned int alpha, src, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ details_bg_layer_->SetGeometry(full_data_layout_->GetGeometry());
+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, full_data_layout_->GetGeometry(), details_bg_layer_.get());
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+ }
+
+ gfx_engine.PopClippingRectangle();
+}
+
+void SocialPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+ nux::Geometry const& base = GetGeometry();
+ gfx_engine.PushClippingRectangle(base);
+
+ if (!IsFullRedraw())
+ nux::GetPainter().PushLayer(gfx_engine, details_bg_layer_->GetGeometry(), details_bg_layer_.get());
+
+ unsigned int alpha, src, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ if (GetCompositionLayout())
+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+
+ if (!IsFullRedraw())
+ nux::GetPainter().PopBackground();
+
+ gfx_engine.PopClippingRectangle();
+}
+
+std::string SocialPreview::GetName() const
+{
+ return "SocialPreview";
+}
+
+void SocialPreview::AddProperties(GVariantBuilder* builder)
+{
+ Preview::AddProperties(builder);
+}
+
+void SocialPreview::SetupBackground()
+{
+ details_bg_layer_.reset(dash::previews::Style::Instance().GetBackgroundLayer());
+}
+
+void SocialPreview::SetupViews()
+{
+ dash::SocialPreview* social_preview_model = dynamic_cast(preview_model_.get());
+ if (!social_preview_model)
+ {
+ LOG_ERROR(logger) << "Could not derive social preview model from given parameter.";
+ return;
+ }
+
+ previews::Style& style = dash::previews::Style::Instance();
+
+ nux::HLayout* image_data_layout = new nux::HLayout();
+ image_data_layout->SetSpaceBetweenChildren(style.GetPanelSplitWidth());
+
+ nux::VLayout* social_content_layout = new nux::VLayout();
+ social_content_layout->SetSpaceBetweenChildren(16);
+
+
+ if (social_preview_model->description.Get().length() > 0)
+ {
+ content_ = new SocialPreviewContent(social_preview_model->description, NUX_TRACKER_LOCATION);
+ social_content_layout->AddView(content_.GetPointer(), 1);
+ } else {
+ image_ = new CoverArt();
+ AddChild(image_.GetPointer());
+ UpdateCoverArtImage(image_.GetPointer());
+ social_content_layout->AddView(image_.GetPointer(), 1);
+ }
+
+ /////////////////////
+
+ /////////////////////
+ // Social Data Panel
+ full_data_layout_ = new nux::VLayout();
+ full_data_layout_->SetPadding(style.GetDetailsTopMargin(), 0, style.GetDetailsBottomMargin(), style.GetDetailsLeftMargin());
+ full_data_layout_->SetSpaceBetweenChildren(16);
+
+ /////////////////////
+ // Main Social Info
+ nux::HLayout* main_social_info = new nux::HLayout();
+ main_social_info->SetSpaceBetweenChildren(style.GetSpaceBetweenIconAndDetails());
+
+ /////////////////////
+ // Icon Layout
+ nux::VLayout* icon_layout = new nux::VLayout();
+ icon_layout->SetSpaceBetweenChildren(3);
+ avatar_ = new IconTexture(social_preview_model->avatar.Get().RawPtr() ? g_icon_to_string(social_preview_model->avatar.Get().RawPtr()) : "", MIN(style.GetAvatarAreaWidth(), style.GetAvatarAreaHeight()));
+ avatar_->SetMinMaxSize(style.GetAvatarAreaWidth(), style.GetAvatarAreaHeight());
+ icon_layout->AddView(avatar_.GetPointer(), 0);
+
+ /////////////////////
+
+ /////////////////////
+ // Data
+ nux::VLayout* social_data_layout = new nux::VLayout();
+ social_data_layout->SetSpaceBetweenChildren(style.GetSpaceBetweenTitleAndSubtitle());
+
+ title_ = new nux::StaticCairoText(preview_model_->title, true, NUX_TRACKER_LOCATION);
+ title_->SetLines(-1);
+ title_->SetFont(style.title_font().c_str());
+
+ subtitle_ = new nux::StaticCairoText(preview_model_->subtitle, true, NUX_TRACKER_LOCATION);
+ subtitle_->SetFont(style.content_font().c_str());
+ subtitle_->SetLines(-1);
+
+ social_data_layout->AddView(title_.GetPointer(), 0);
+ social_data_layout->AddView(subtitle_.GetPointer(), 0);
+ social_data_layout->AddSpace(0, 1);
+
+ // buffer space
+ /////////////////////
+
+ main_social_info->AddLayout(icon_layout, 0);
+ main_social_info->AddLayout(social_data_layout, 1);
+ /////////////////////
+
+ /////////////////////
+ // Details
+ nux::ScrollView* social_info = new DetailsScrollView(NUX_TRACKER_LOCATION);
+ social_info->EnableHorizontalScrollBar(false);
+
+ nux::VLayout* social_info_layout = new nux::VLayout();
+ social_info_layout->SetSpaceBetweenChildren(12);
+ social_info->SetLayout(social_info_layout);
+
+ if (!preview_model_->GetInfoHints().empty())
+ {
+ preview_info_hints_ = new PreviewInfoHintWidget(preview_model_, style.GetAvatarAreaWidth());
+ AddChild(preview_info_hints_.GetPointer());
+ social_info_layout->AddView(preview_info_hints_.GetPointer());
+ }
+ /////////////////////
+ // Comments/Replies
+ if (!social_preview_model->GetComments().empty())
+ {
+ nux::HLayout* comments_layout = new nux::HLayout();
+ comments_layout->SetSpaceBetweenChildren(12);
+ std::string tmp_comments_hint = _("Comments");
+ tmp_comments_hint += ":";
+
+ comments_hint_ = new nux::StaticCairoText(tmp_comments_hint, true, NUX_TRACKER_LOCATION);
+ comments_hint_->SetLines(-1);
+ comments_hint_->SetFont(style.info_hint_bold_font().c_str());
+ comments_hint_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT);
+ comments_layout->AddView(comments_hint_.GetPointer(), 0, nux::MINOR_POSITION_TOP);
+
+ comments_ = new SocialPreviewComments(preview_model_, NUX_TRACKER_LOCATION);
+ AddChild(comments_.GetPointer());
+ comments_layout->AddView(comments_.GetPointer());
+ social_info_layout->AddView(comments_layout, 0);
+ }
+
+ /////////////////////
+ // Actions
+ action_buttons_.clear();
+ nux::Layout* actions_layout = BuildGridActionsLayout(preview_model_->GetActions(), action_buttons_);
+ actions_layout->SetLeftAndRightPadding(0, style.GetDetailsRightMargin());
+ ///////////////////
+
+ full_data_layout_->AddLayout(main_social_info, 0, nux::MINOR_POSITION_TOP);
+ full_data_layout_->AddView(social_info, 1, nux::MINOR_POSITION_TOP);
+ //full_data_layout_->AddView(comments_.GetPointer(), 1, nux::MINOR_POSITION_TOP);
+
+ full_data_layout_->AddLayout(actions_layout, 0);
+ /////////////////////
+
+ image_data_layout->AddView(social_content_layout, 0);
+ image_data_layout->AddLayout(full_data_layout_, 1);
+
+
+ SetLayout(image_data_layout);
+}
+
+void SocialPreview::PreLayoutManagement()
+{
+ nux::Geometry geo = GetGeometry();
+
+ previews::Style& style = dash::previews::Style::Instance();
+
+ nux::Geometry geo_content(geo.x, geo.y, style.GetAppImageAspectRatio() * geo.height, geo.height);
+
+ if (geo.width - geo_content.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() < style.GetDetailsPanelMinimumWidth())
+ geo_content.width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin() - style.GetDetailsPanelMinimumWidth());
+ if (content_) { content_->SetMinMaxSize(geo_content.width, geo_content.height); }
+ if (image_) { image_->SetMinMaxSize(geo_content.width, geo_content.height); }
+
+ int details_width = MAX(0, geo.width - geo_content.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
+ int top_social_info_max_width = details_width - style.GetAppIconAreaWidth() - style.GetSpaceBetweenIconAndDetails();
+
+ if (title_) { title_->SetMaximumWidth(top_social_info_max_width); }
+ if (subtitle_) { subtitle_->SetMaximumWidth(top_social_info_max_width); }
+ if (comments_) { comments_->SetMaximumWidth(top_social_info_max_width); }
+ if (comments_hint_) { comments_hint_->SetMinimumWidth(style.GetInfoHintNameMinimumWidth()); }
+
+ for (nux::AbstractButton* button : action_buttons_)
+ {
+ button->SetMinMaxSize(CLAMP((details_width - style.GetSpaceBetweenActions()) / 2, 0, style.GetActionButtonMaximumWidth()), style.GetActionButtonHeight());
+ }
+
+ Preview::PreLayoutManagement();
+}
+
+} // namespace previews
+} // namespace dash
+} // namepsace unity
=== added file 'dash/previews/SocialPreview.h'
--- dash/previews/SocialPreview.h 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreview.h 2012-09-14 20:35:43 +0000
@@ -0,0 +1,93 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#ifndef SOCIALPREVIEW_H
+#define SOCIALPREVIEW_H
+
+#include "Preview.h"
+#include
+
+namespace nux
+{
+class AbstractPaintLayer;
+class VLayout;
+class StaticCairoText;
+}
+
+namespace unity
+{
+class IconTexture;
+
+namespace dash
+{
+namespace previews
+{
+class CoverArt;
+class PreviewLikesWidget;
+class PreviewInfoHintWidget;
+class SocialPreviewContent;
+class SocialPreviewComments;
+
+class SocialPreview : public Preview
+{
+public:
+ typedef nux::ObjectPtr Ptr;
+ NUX_DECLARE_OBJECT_TYPE(SocialPreview, Preview);
+
+ SocialPreview(dash::Preview::Ptr social_preview_model);
+ ~SocialPreview();
+
+ // From debug::Introspectable
+ std::string GetName() const;
+ void AddProperties(GVariantBuilder* builder);
+
+protected:
+ virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
+ virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
+ virtual void PreLayoutManagement();
+
+ void SetupBackground();
+ void SetupViews();
+
+protected:
+ nux::VLayout* full_data_layout_;
+ nux::VLayout* sender_layout_;
+ nux::VLayout* title_layout_;
+
+ nux::ObjectPtr avatar_;
+ nux::ObjectPtr image_;
+ nux::ObjectPtr content_;
+ nux::ObjectPtr comments_;
+ nux::ObjectPtr title_;
+ nux::ObjectPtr subtitle_;
+ nux::ObjectPtr comments_hint_;
+ nux::ObjectPtr preview_info_hints_;
+
+ typedef std::unique_ptr LayerPtr;
+ LayerPtr details_bg_layer_;
+};
+
+}
+}
+}
+
+#endif //SOCIALPREVIEW_H
=== added file 'dash/previews/SocialPreviewComments.cpp'
--- dash/previews/SocialPreviewComments.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreviewComments.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,193 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#include "unity-shared/DashStyle.h"
+#include "unity-shared/PreviewStyle.h"
+#include
+#include
+#include
+#include
+#include
+
+#include "SocialPreviewComments.h"
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+namespace
+{
+nux::logging::Logger logger("unity.dash.previews.socialpreviewcomments");
+
+const int layout_spacing = 12;
+}
+
+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewComments);
+
+SocialPreviewComments::SocialPreviewComments(dash::Preview::Ptr preview_model, NUX_FILE_LINE_DECL)
+: View(NUX_FILE_LINE_PARAM)
+, preview_model_(preview_model)
+{
+ SetupViews();
+}
+
+SocialPreviewComments::~SocialPreviewComments()
+{
+}
+
+void SocialPreviewComments::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+}
+
+void SocialPreviewComments::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+ nux::Geometry base = GetGeometry();
+ gfx_engine.PushClippingRectangle(base);
+
+ if (GetCompositionLayout())
+ {
+ unsigned int alpha, src, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+ }
+
+ gfx_engine.PopClippingRectangle();
+}
+
+void SocialPreviewComments::PreLayoutManagement()
+{
+ previews::Style& style = previews::Style::Instance();
+ nux::Geometry const& geo = GetGeometry();
+
+ int comment_width = 0;
+ for (Comment const& comment : comments_)
+ {
+ int width = style.GetDetailsPanelMinimumWidth();
+ if (comment.first)
+ {
+ width = comment.first->GetTextExtents().width;
+
+ if (width < style.GetDetailsPanelMinimumWidth())
+ width = style.GetDetailsPanelMinimumWidth();
+ }
+
+ if (comment_width < width)
+ {
+ comment_width = width;
+ }
+ }
+
+ int comment_value_width = MAX(0, geo.width - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
+
+ for (Comment const& comment : comments_)
+ {
+ if (comment.first)
+ {
+ comment.first->SetMaximumWidth(comment_value_width);
+ }
+ if (comment.second)
+ {
+ comment.second->SetMaximumWidth(comment_value_width);
+ }
+ }
+ View::PreLayoutManagement();
+}
+
+void SocialPreviewComments::SetupViews()
+{
+ dash::SocialPreview* social_preview_model = dynamic_cast(preview_model_.get());
+
+
+ RemoveLayout();
+ comments_.clear();
+
+ previews::Style& style = previews::Style::Instance();
+
+ nux::VLayout* layout = new nux::VLayout();
+ layout->SetSpaceBetweenChildren(6);
+
+ for (dash::SocialPreview::CommentPtr comment : social_preview_model->GetComments())
+ {
+
+ nux::HLayout* name_layout = new nux::HLayout();
+ name_layout->SetSpaceBetweenChildren(layout_spacing);
+
+ StaticCairoTextPtr comment_name;
+ if (!comment->display_name.empty())
+ {
+ comment_name = new nux::StaticCairoText(comment->display_name, true, NUX_TRACKER_LOCATION);
+ comment_name->SetFont(style.info_hint_bold_font());
+ comment_name->SetLines(-1);
+ comment_name->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
+ name_layout->AddView(comment_name.GetPointer(), 0, nux::MINOR_POSITION_TOP);
+ }
+
+ StaticCairoTextPtr comment_time;
+ if (!comment->time.empty())
+ {
+ comment_time = new nux::StaticCairoText(comment->time, true, NUX_TRACKER_LOCATION);
+ comment_time->SetFont(style.info_hint_font());
+ comment_time->SetLines(-1);
+ comment_time->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT);
+ name_layout->AddView(comment_time.GetPointer(), 0, nux::MINOR_POSITION_TOP);
+ }
+
+
+ nux::HLayout* comment_layout = new nux::HLayout();
+ comment_layout->SetSpaceBetweenChildren(layout_spacing);
+
+ StaticCairoTextPtr comment_value(new nux::StaticCairoText(comment->content, false, NUX_TRACKER_LOCATION));
+
+ comment_value->SetFont(style.info_hint_font());
+ comment_value->SetLines(-7);
+ comment_value->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT);
+ comment_layout->AddView(comment_value.GetPointer(), 1, nux::MINOR_POSITION_TOP);
+
+ Comment comment_views(comment_name, comment_value);
+ comments_.push_back(comment_views);
+
+ layout->AddLayout(name_layout, 0);
+ layout->AddLayout(comment_layout, 1);
+ }
+ SetLayout(layout);
+
+}
+
+std::string SocialPreviewComments::GetName() const
+{
+ return "SocialPreviewComments";
+}
+
+void SocialPreviewComments::AddProperties(GVariantBuilder* builder)
+{
+}
+
+}
+}
+}
=== added file 'dash/previews/SocialPreviewComments.h'
--- dash/previews/SocialPreviewComments.h 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreviewComments.h 2012-09-14 20:35:43 +0000
@@ -0,0 +1,78 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Ken VanDine
+ *
+ */
+
+#ifndef SOCIAL_PREVIEW_COMMENTS_H
+#define SOCIAL_PREVIEW_COMMENTS_H
+
+#include
+#include
+#include
+#include "unity-shared/StaticCairoText.h"
+#include "unity-shared/Introspectable.h"
+#include
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+class SocialPreviewComments : public nux::View, public unity::debug::Introspectable
+{
+public:
+ typedef nux::ObjectPtr Ptr;
+ NUX_DECLARE_OBJECT_TYPE(SocialPreviewComments, nux::View);
+
+ SocialPreviewComments(dash::Preview::Ptr preview_model, NUX_FILE_LINE_PROTO);
+
+ virtual ~SocialPreviewComments();
+
+protected:
+
+ typedef nux::ObjectPtr StaticCairoTextPtr;
+ typedef std::pair Comment;
+ std::list comments_;
+
+ dash::Preview::Ptr preview_model_;
+
+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ virtual void PreLayoutManagement();
+
+ virtual bool AcceptKeyNavFocus() { return false; }
+
+ void SetupViews();
+
+ virtual std::string GetName() const;
+ virtual void AddProperties(GVariantBuilder* builder);
+
+private:
+
+ typedef std::unique_ptr NuxCairoPtr;
+};
+
+}
+}
+}
+
+#endif // SOCIAL_PREVIEW_COMMENTS_H
=== added file 'dash/previews/SocialPreviewContent.cpp'
--- dash/previews/SocialPreviewContent.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreviewContent.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,325 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Nick Dedekind
+ * Ken VanDine
+ *
+ */
+
+#include "unity-shared/DashStyle.h"
+#include "unity-shared/PreviewStyle.h"
+#include
+#include
+
+#include "SocialPreviewContent.h"
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+namespace
+{
+nux::logging::Logger logger("unity.dash.previews.socialpreviewcontent");
+}
+
+inline nux::Geometry GetBubbleGeometry(nux::Geometry const& geo)
+{
+ return nux::Geometry(geo.x + geo.width*0.1,
+ geo.y + geo.height*0.1,
+ geo.width - 2*(geo.width*0.1),
+ geo.height - 2*(geo.height*0.1));
+}
+
+NUX_IMPLEMENT_OBJECT_TYPE(SocialPreviewContent);
+
+SocialPreviewContent::SocialPreviewContent(std::string const& text, NUX_FILE_LINE_DECL)
+: View(NUX_FILE_LINE_PARAM)
+{
+ SetupViews();
+ if (text.length() > 0)
+ SetText(text);
+}
+
+SocialPreviewContent::~SocialPreviewContent()
+{
+}
+
+void SocialPreviewContent::SetText(std::string const& text)
+{
+ std::stringstream ss;
+ ss << "“ ";
+ ss << text;
+ ss << " „";
+ text_->SetText(ss.str());
+ UpdateBaloonTexture();
+}
+
+void SocialPreviewContent::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+
+ nux::Geometry const& geo = GetGeometry();
+
+ gPainter.PaintBackground(gfx_engine, geo);
+ // set up our texture mode
+ nux::TexCoordXForm texxform;
+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
+
+ // clear what is behind us
+ unsigned int alpha = 0, src = 0, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ nux::ObjectPtr tex = cr_bubble_->GetTexture()->GetDeviceTexture();
+
+ nux::Geometry geo_bubble(GetBubbleGeometry(geo));
+
+ gfx_engine.QRP_1Tex(geo_bubble.x,
+ geo_bubble.y,
+ tex->GetWidth(),
+ tex->GetHeight(),
+ tex,
+ texxform,
+ nux::Color(0.2f, 0.2f, 0.2f, 0.2f));
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+
+ if (GetCompositionLayout())
+ {
+ gPainter.PushPaintLayerStack();
+ {
+ nux::Geometry clip_geo = geo;
+
+ gfx_engine.PushClippingRectangle(clip_geo);
+ gPainter.PushPaintLayerStack();
+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
+ gPainter.PopPaintLayerStack();
+ gfx_engine.PopClippingRectangle();
+ }
+ gPainter.PopPaintLayerStack();
+ }
+}
+
+void SocialPreviewContent::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
+{
+}
+
+void SocialPreviewContent::SetupViews()
+{
+ dash::previews::Style const& style = dash::previews::Style::Instance();
+
+ text_ = new nux::StaticCairoText("", false, NUX_TRACKER_LOCATION);
+ text_->SetLines(-8);
+ text_->SetFont(style.content_font());
+ text_->SetLineSpacing(5);
+ text_->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_MIDDLE);
+
+ nux::Layout* layout = new nux::Layout();
+ layout->AddView(text_.GetPointer(), 1);
+ SetLayout(layout);
+
+ cr_bubble_.reset(new nux::CairoWrapper(GetGeometry(), sigc::bind(sigc::mem_fun(this, &SocialPreviewContent::RedrawBubble), nux::ButtonVisualState::VISUAL_STATE_PRELIGHT)));
+}
+
+void SocialPreviewContent::UpdateBaloonTexture()
+{
+ nux::Geometry const& geo = GetGeometry();
+
+ nux::Geometry geo_cr(GetBubbleGeometry(geo));
+
+ double tail_width = MAX(0, MIN(geo_cr.width - 2*15.0, MIN(geo_cr.width*0.125, geo_cr.height*0.125)));
+
+ int max_width = geo_cr.width - 2*(geo_cr.width*0.1);
+ int max_height = geo_cr.height - 2*(geo_cr.height*0.1) - tail_width;
+
+ // this will update the texture with the actual size of the text.
+ text_->SetMaximumHeight(max_height);
+ text_->SetMaximumWidth(max_width);
+ nux::Geometry const& geo_text = text_->GetGeometry();
+
+ // center text
+ text_->SetBaseX(geo.x + geo.width/2 - geo_text.width/2);
+ text_->SetBaseY(geo.y + geo.height/2 - geo_text.height/2 - tail_width/2);
+
+ if (geo_cr.width > 0 && geo_cr.height > 0)
+ {
+ cr_bubble_->Invalidate(geo_cr);
+ }
+}
+
+void SocialPreviewContent::RedrawBubble(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state)
+{
+ double blur = 4.0;
+
+ double line_width = 1.0;
+ double radius = 20.0;
+ double tailWidthPercentage = 0.125;
+ double tailPositionPercentage = 0.7;
+ double x = 0.0 + blur;
+ double y = 0.0 + blur;
+ double width = cairo_image_surface_get_width(cairo_get_target(cr)) - 2*blur;
+ double height = cairo_image_surface_get_height(cairo_get_target(cr)) - 2*blur;
+
+ if (width > 0 && height > 0)
+ {
+ DrawBubble(cr, line_width, radius, x, y, width, height, tailPositionPercentage, tailWidthPercentage);
+ dash::Style::Instance().Blur(cr, blur);
+ }
+}
+
+inline double _align(double val, bool odd=true)
+{
+ double fract = val - (int) val;
+
+ if (odd)
+ {
+ // for strokes with an odd line-width
+ if (fract != 0.5f)
+ return (double) ((int) val + 0.5f);
+ else
+ return val;
+ }
+ else
+ {
+ // for strokes with an even line-width
+ if (fract != 0.0f)
+ return (double) ((int) val);
+ else
+ return val;
+ }
+}
+
+void SocialPreviewContent::DrawBubble(cairo_t* cr,
+ double line_width,
+ double radius,
+ double x,
+ double y,
+ double width,
+ double height,
+ double tailPositionPercentage,
+ double tailWidthPercentage)
+{
+ // sanity check
+ if (cairo_status(cr) != CAIRO_STATUS_SUCCESS &&
+ cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE)
+ return;
+
+ cairo_set_line_width(cr, line_width);
+
+ double tailWidth = MAX(0, MIN(width - 2*radius, MIN(width*tailWidthPercentage, height*tailWidthPercentage)));
+ double tail_start_pos = x + tailPositionPercentage*width - tailWidth/2;
+
+ // recitfications for outer draw.
+ x += line_width/2;
+ y += line_width/2;
+ height -= line_width;
+ height -= tailWidth;
+ width -= line_width;
+
+ bool odd = true;
+ odd = line_width != double((int)line_width);
+
+ // top-left, right of the corner
+ cairo_move_to(cr, _align (x + radius, odd), _align (y, odd));
+
+ // top-right, left of the corner
+ cairo_line_to(cr, _align(x + width - radius, odd), _align(y, odd));
+
+ // top-right, below the corner
+ cairo_arc(cr,
+ _align(x + width - radius, odd),
+ _align(y + radius, odd),
+ radius,
+ -90.0f * G_PI / 180.0f,
+ 0.0f * G_PI / 180.0f);
+
+ // bottom-right, above the corner
+ cairo_line_to(cr, _align(x + width, odd), _align(y + height - radius, odd));
+
+ // bottom-right, left of the corner
+ cairo_arc(cr,
+ _align(x + width - radius, odd),
+ _align(y + height - radius, odd),
+ radius,
+ 0.0f * G_PI / 180.0f,
+ 90.0f * G_PI / 180.0f);
+
+ if (tailWidth > 0.0)
+ {
+ // tail-right, tail top
+ cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height, odd));
+
+ // tail-right, tail bottom
+ cairo_line_to(cr, _align(tail_start_pos + tailWidth, odd), _align(y + height + tailWidth, odd));
+
+ // tail-right, tail bottom
+ cairo_line_to(cr, _align(tail_start_pos, odd), _align(y + height, odd));
+ }
+
+ // bottom-left, right of the corner
+ cairo_line_to(cr, _align(x + radius, odd), _align(y + height, odd));
+
+ // bottom-left, above the corner
+ cairo_arc(cr,
+ _align(x + radius, odd),
+ _align(y + height - radius, odd),
+ radius,
+ 90.0f * G_PI / 180.0f,
+ 180.0f * G_PI / 180.0f);
+
+ // top-left, right of the corner
+ cairo_arc(cr,
+ _align(x + radius, odd),
+ _align(y + radius, odd),
+ radius,
+ 180.0f * G_PI / 180.0f,
+ 270.0f * G_PI / 180.0f);
+
+
+ nux::Color color(0.53, 1.0, 0.66, 0.5);
+ if (color.alpha != 0.0)
+ {
+ cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
+ cairo_fill_preserve(cr);
+ }
+ cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
+ cairo_stroke(cr);
+}
+
+void SocialPreviewContent::PreLayoutManagement()
+{
+ UpdateBaloonTexture();
+
+ View::PreLayoutManagement();
+}
+
+std::string SocialPreviewContent::GetName() const
+{
+ return "SocialPreviewContent";
+}
+
+void SocialPreviewContent::AddProperties(GVariantBuilder* builder)
+{
+}
+
+}
+}
+}
=== added file 'dash/previews/SocialPreviewContent.h'
--- dash/previews/SocialPreviewContent.h 1970-01-01 00:00:00 +0000
+++ dash/previews/SocialPreviewContent.h 2012-09-14 20:35:43 +0000
@@ -0,0 +1,86 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright 2011 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3, as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the applicable version of the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of both the GNU Lesser General Public
+ * License version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Nick Dedekind
+ * Ken VanDine
+ *
+ */
+
+#ifndef SOCIAL_PREVIEW_CONTENT_H
+#define SOCIAL_PREVIEW_CONTENT_H
+
+#include
+#include
+#include
+#include
+#include "unity-shared/StaticCairoText.h"
+#include "unity-shared/Introspectable.h"
+
+namespace unity
+{
+namespace dash
+{
+namespace previews
+{
+
+class SocialPreviewContent : public nux::View, public unity::debug::Introspectable
+{
+public:
+ typedef nux::ObjectPtr Ptr;
+ NUX_DECLARE_OBJECT_TYPE(SocialPreviewContent, nux::View);
+
+ SocialPreviewContent(std::string const& text, NUX_FILE_LINE_PROTO);
+ virtual ~SocialPreviewContent();
+
+ void SetText(std::string const& text);
+
+protected:
+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw);
+ virtual void PreLayoutManagement();
+
+ virtual bool AcceptKeyNavFocus() { return false; }
+
+ void SetupViews();
+ void UpdateBaloonTexture();
+ void RedrawBubble(nux::Geometry const& geom, cairo_t* cr, nux::ButtonVisualState faked_state);
+ void DrawBubble(cairo_t* cr,
+ double line_width,
+ double radius,
+ double x,
+ double y,
+ double width,
+ double height,
+ double tailPositionPercentage,
+ double tailWidthPercentage);
+
+ virtual std::string GetName() const;
+ virtual void AddProperties(GVariantBuilder* builder);
+
+private:
+ nux::ObjectPtr text_;
+
+ typedef std::unique_ptr NuxCairoPtr;
+ NuxCairoPtr cr_bubble_;
+};
+
+}
+}
+}
+
+#endif // SOCIAL_PREVIEW_CONTENT_H
=== added file 'dash/previews/StandaloneSocialPreview.cpp'
--- dash/previews/StandaloneSocialPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/StandaloneSocialPreview.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,287 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ *
+ *
+ * Authored by: Nick Dedekind
+ *
+ */
+#include
+
+#include "Nux/Nux.h"
+#include "Nux/VLayout.h"
+#include "Nux/WindowThread.h"
+#include "NuxGraphics/GraphicsEngine.h"
+#include
+#include
+#include
+#include
+#include
+
+#include "unity-shared/FontSettings.h"
+#include "unity-shared/UnitySettings.h"
+#include "unity-shared/PreviewStyle.h"
+#include "unity-shared/DashStyle.h"
+#include "unity-shared/ThumbnailGenerator.h"
+
+#include "Preview.h"
+#include "PreviewContainer.h"
+
+
+#define WIDTH 910
+#define HEIGHT 400
+
+using namespace unity;
+using namespace unity::dash;
+
+class DummyView : public nux::View
+{
+public:
+ DummyView(nux::View* view)
+ : View(NUX_TRACKER_LOCATION)
+ {
+ SetAcceptKeyNavFocusOnMouseDown(false);
+ SetAcceptKeyNavFocusOnMouseEnter(false);
+
+ nux::ROPConfig rop;
+ rop.Blend = true;
+ rop.SrcBlend = GL_ONE;
+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
+ bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
+
+ nux::Layout* layout = new nux::VLayout();
+ layout->SetPadding(16);
+ layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
+ SetLayout(layout);
+ }
+
+ // Keyboard navigation
+ bool AcceptKeyNavFocus()
+ {
+ return false;
+ }
+
+protected:
+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
+ {
+ nux::Geometry const& base = GetGeometry();
+
+ gfx_engine.PushClippingRectangle(base);
+ nux::GetPainter().PaintBackground(gfx_engine, base);
+
+ unsigned int alpha, src, dest = 0;
+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ bg_layer_->SetGeometry(GetGeometry());
+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
+
+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
+
+ gfx_engine.PopClippingRectangle();
+ }
+
+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
+ {
+ nux::Geometry const& base = GetGeometry();
+ gfx_engine.PushClippingRectangle(base);
+
+ if (!IsFullRedraw())
+ nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
+
+ if (GetCompositionLayout())
+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
+
+ if (!IsFullRedraw())
+ nux::GetPainter().PopBackground();
+
+ gfx_engine.PopClippingRectangle();
+ }
+
+ typedef std::unique_ptr LayerPtr;
+ LayerPtr bg_layer_;
+};
+
+class TestRunner
+{
+public:
+ TestRunner ();
+ ~TestRunner ();
+
+ static void InitWindowThread (nux::NThread* thread, void* InitData);
+ void Init ();
+ void NavRight();
+ void NavLeft();
+
+ previews::PreviewContainer::Ptr container_;
+ nux::Layout *layout_;
+ int nav_iter;
+ glib::Source::UniquePtr preview_wait_timer_;
+};
+
+TestRunner::TestRunner ()
+{
+ nav_iter = 0;
+}
+
+TestRunner::~TestRunner ()
+{
+}
+
+void TestRunner::Init ()
+{
+ container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
+ container_->navigate_right.connect(sigc::mem_fun(this, &TestRunner::NavRight));
+ container_->navigate_left.connect(sigc::mem_fun(this, &TestRunner::NavLeft));
+ container_->request_close.connect([&]() { exit(0); });
+
+ DummyView* dummyView = new DummyView(container_.GetPointer());
+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
+ layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
+ nux::GetWindowThread()->SetLayout (layout_);
+
+ const char* title = "Candace Flynn";
+ const char* subtitle = "@candacejeremyxo, 10 Aug 2012 05:01";
+ 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.";
+
+ glib::Object iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/sunflower.jpg", NULL));
+ glib::Object iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
+
+ glib::Object proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
+
+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
+
+ unity_protocol_social_preview_set_content(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), description);
+
+ unity_protocol_preview_set_title(proto_obj, title);
+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
+ unity_protocol_preview_set_description(proto_obj, description);
+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
+ 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");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Jeremy", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Stacy", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
+
+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
+ glib::StealRef());
+
+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
+ container_->Preview(preview_model, previews::Navigation::RIGHT);
+
+}
+
+void TestRunner::NavRight()
+{
+ const char* title = "Phineas Flynn";
+ const char* subtitle = "@phineasflynn12, 10 Aug 2012 05:01";
+ const char* description = "I know what we are going to do today!";
+
+ // creates a generic preview object
+ glib::Object iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/astronaut.jpg", NULL));
+ glib::Object iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
+
+ glib::Object proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
+
+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
+
+ unity_protocol_preview_set_title(proto_obj, title);
+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
+ unity_protocol_preview_set_description(proto_obj, description);
+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
+ 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...");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Baljeet", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Buford", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "Where's Perry?", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Pery the Platypus", "Over here", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Buford", "This is a comment", "4 hours ago");
+ unity_protocol_preview_add_info_hint(proto_obj, "likes", "Favorites", nullptr, g_variant_new("i", 1210));
+ unity_protocol_preview_add_info_hint(proto_obj, "retweets", "Retweets", nullptr, g_variant_new("i", 21));
+
+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
+ glib::StealRef());
+
+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
+ container_->Preview(preview_model, previews::Navigation::RIGHT);
+}
+
+void TestRunner::NavLeft()
+{
+ const char* title = "Ferb Fletcher";
+ const char* subtitle = "@ferbfletcher123, 10 Aug 2012 05:01";
+ const char* description = "Profile pictures are what people want them to think they look like. Tagged pictures are what they really look like.";
+
+ glib::Object iconHint1(g_icon_new_for_string("/usr/share/pixmaps/faces/soccerball.png", NULL));
+ glib::Object iconHint2(g_icon_new_for_string("/usr/share/unity/6/lens-nav-home.svg", NULL));
+
+ glib::Object proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
+
+ unity_protocol_social_preview_set_avatar(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), iconHint1);
+
+ unity_protocol_preview_set_title(proto_obj, title);
+ unity_protocol_preview_set_subtitle(proto_obj, subtitle);
+ unity_protocol_preview_set_description(proto_obj, description);
+ unity_protocol_preview_add_action(proto_obj, "view", "View", iconHint2, 0);
+ unity_protocol_preview_add_action(proto_obj, "retweet", "Retweet", nullptr, 0);
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Baljeet", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Isabella", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Candace", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Vanessa", "This is a comment", "4 hours ago");
+ unity_protocol_social_preview_add_comment(UNITY_PROTOCOL_SOCIAL_PREVIEW(proto_obj.RawPtr()), "comment", "Major Monogram", "I'm a comment", "4 hours ago");
+ unity_protocol_preview_add_info_hint(proto_obj, "likes", "Favorites", nullptr, g_variant_new("i", 123));
+ unity_protocol_preview_add_info_hint(proto_obj, "retweets", "Retweets", nullptr, g_variant_new("i", 12));
+
+
+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
+ glib::StealRef());
+
+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
+ container_->Preview(preview_model, previews::Navigation::LEFT);
+}
+
+void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
+{
+ TestRunner *self = (TestRunner *) InitData;
+ self->Init ();
+}
+
+int main(int argc, char **argv)
+{
+ nux::WindowThread* wt = NULL;
+
+ gtk_init (&argc, &argv);
+
+ nux::NuxInitialize(0);
+ nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
+ // The instances for the pseudo-singletons.
+ unity::Settings settings;
+ unity::dash::previews::Style panel_style;
+ unity::dash::Style dash_style;
+ unity::ThumbnailGenerator thumbnail_generator;
+
+ TestRunner *test_runner = new TestRunner ();
+ wt = nux::CreateGUIThread(TEXT("Unity Preview"),
+ WIDTH, HEIGHT,
+ 0,
+ &TestRunner::InitWindowThread,
+ test_runner);
+
+ wt->Run (NULL);
+ delete wt;
+ return 0;
+}
+
+
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2012-08-31 21:32:38 +0000
+++ tests/CMakeLists.txt 2012-09-14 20:35:43 +0000
@@ -220,6 +220,7 @@
test_previews_generic.cpp
test_previews_movie.cpp
test_previews_music.cpp
+ test_previews_social.cpp
test_quicklist_menu_item.cpp
test_quicklist_view.cpp
test_resultviewgrid.cpp
@@ -247,6 +248,9 @@
${CMAKE_SOURCE_DIR}/dash/previews/Preview.cpp
${CMAKE_SOURCE_DIR}/dash/previews/PreviewInfoHintWidget.cpp
${CMAKE_SOURCE_DIR}/dash/previews/PreviewRatingsWidget.cpp
+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreview.cpp
+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreviewContent.cpp
+ ${CMAKE_SOURCE_DIR}/dash/previews/SocialPreviewComments.cpp
${CMAKE_SOURCE_DIR}/dash/previews/Tracks.cpp
${CMAKE_SOURCE_DIR}/dash/previews/Track.cpp
${CMAKE_SOURCE_DIR}/hud/HudAbstractView.cpp
=== added file 'tests/test_previews_social.cpp'
--- tests/test_previews_social.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_previews_social.cpp 2012-09-14 20:35:43 +0000
@@ -0,0 +1,110 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Andrea Azzarone
+ * Ken VanDine
+ */
+
+#include
+#include
+using namespace testing;
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include "unity-shared/UnitySettings.h"
+
+#include
+#include "UnityCore/SocialPreview.h"
+#include "dash/previews/SocialPreview.h"
+#include "dash/previews/SocialPreviewContent.h"
+#include "dash/previews/SocialPreviewComments.h"
+#include "dash/previews/PreviewInfoHintWidget.h"
+#include "dash/previews/PreviewRatingsWidget.h"
+#include "test_utils.h"
+using namespace unity;
+using namespace unity::dash;
+
+namespace
+{
+
+class MockSocialPreview : public previews::SocialPreview
+{
+public:
+ typedef nux::ObjectPtr Ptr;
+
+ MockSocialPreview(dash::Preview::Ptr preview_model)
+ : SocialPreview(preview_model)
+ {}
+
+ using SocialPreview::title_;
+ using SocialPreview::subtitle_;
+ using SocialPreview::content_;
+ using SocialPreview::action_buttons_;
+ using SocialPreview::preview_info_hints_;
+};
+
+class TestPreviewSocial : public Test
+{
+public:
+ TestPreviewSocial()
+ : parent_window_(new nux::BaseWindow("TestPreviewSocial"))
+ {
+ glib::Object proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_social_preview_new()));
+
+ unity_protocol_preview_set_image_source_uri(proto_obj, "http://ia.media-imdb.com/images/M/MV5BMTM3NDM5MzY5Ml5BMl5BanBnXkFtZTcwNjExMDUwOA@@._V1._SY317_.jpg");
+ unity_protocol_preview_set_title(proto_obj, "Social Title & special char");
+ unity_protocol_preview_set_subtitle(proto_obj, "Social Subtitle > special char");
+ unity_protocol_preview_set_description(proto_obj, "Social Desctiption < special char");
+ unity_protocol_preview_add_action(proto_obj, "action1", "Action 1", NULL, 0);
+ unity_protocol_preview_add_action(proto_obj, "action2", "Action 2", NULL, 0);
+ unity_protocol_preview_add_info_hint(proto_obj, "hint1", "Hint 1", NULL, g_variant_new("s", "string hint 1"));
+ unity_protocol_preview_add_info_hint(proto_obj, "hint2", "Hint 2", NULL, g_variant_new("s", "string hint 2"));
+ unity_protocol_preview_add_info_hint(proto_obj, "hint3", "Hint 3", NULL, g_variant_new("i", 12));
+
+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
+ preview_model_ = dash::Preview::PreviewForVariant(v);
+ }
+
+ nux::BaseWindow* parent_window_;
+ dash::Preview::Ptr preview_model_;
+
+ unity::Settings settings;
+ previews::Style panel_style;
+ dash::Style dash_style;
+ ThumbnailGenerator thumbnail_generator;
+};
+
+TEST_F(TestPreviewSocial, TestCreate)
+{
+ previews::Preview::Ptr preview_view = previews::Preview::PreviewForModel(preview_model_);
+
+ EXPECT_TRUE(dynamic_cast(preview_view.GetPointer()) != NULL);
+}
+
+TEST_F(TestPreviewSocial, TestUIValues)
+{
+ MockSocialPreview::Ptr preview_view(new MockSocialPreview(preview_model_));
+
+ EXPECT_EQ(preview_view->title_->GetText(), "Social Title & special char");
+ EXPECT_EQ(preview_view->subtitle_->GetText(), "Social Subtitle > special char");
+ EXPECT_EQ(preview_view->action_buttons_.size(), 2);
+}
+
+}
=== modified file 'unity-shared/PreviewStyle.cpp'
--- unity-shared/PreviewStyle.cpp 2012-09-10 15:43:52 +0000
+++ unity-shared/PreviewStyle.cpp 2012-09-14 20:35:43 +0000
@@ -292,6 +292,21 @@
return float(540)/380;
}
+int Style::GetAvatarAreaWidth() const
+{
+ return 100;
+}
+
+int Style::GetAvatarAreaHeight() const
+{
+ return 100;
+}
+
+std::string Style::content_font() const
+{
+ return "Ubuntu Light 12";
+}
+
std::string Style::title_font() const
{
return "Ubuntu 22";
=== modified file 'unity-shared/PreviewStyle.h'
--- unity-shared/PreviewStyle.h 2012-09-04 10:45:31 +0000
+++ unity-shared/PreviewStyle.h 2012-09-14 20:35:43 +0000
@@ -81,6 +81,9 @@
int GetInfoHintNameMinimumWidth() const;
int GetInfoHintNameMaximumWidth() const;
+ int GetCommentNameMinimumWidth() const;
+ int GetCommentNameMaximumWidth() const;
+
float GetDescriptionLineSpacing() const;
int GetDescriptionLineCount() const;
@@ -124,6 +127,15 @@
int GetStatusIconSize() const;
////////////////////////////////
+ ////////////////////////////////
+ // Social Preview
+ int GetAvatarAreaWidth() const;
+ int GetAvatarAreaHeight() const;
+
+ std::string content_font() const;
+
+ ////////////////////////////////
+
nux::BaseTexture* GetNavLeftIcon();
nux::BaseTexture* GetNavRightIcon();
nux::BaseTexture* GetPlayIcon();