diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-07-17 16:28:47 +0100 |
|---|---|---|
| committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-07-17 16:28:47 +0100 |
| commit | d81520d95b182dcada788d6ee736a0f40964d0cd (patch) | |
| tree | ff7e7e277118cb428e7e6c1060b095ad9a27a713 | |
| parent | d9170c4708b5702936a95d200685f98f6666ec40 (diff) | |
Added music preview.
(bzr r2419.4.21)
31 files changed, 1910 insertions, 184 deletions
diff --git a/dash/previews/ApplicationPreview.cpp b/dash/previews/ApplicationPreview.cpp index 54f33558c..214fb6e9e 100644 --- a/dash/previews/ApplicationPreview.cpp +++ b/dash/previews/ApplicationPreview.cpp @@ -20,18 +20,20 @@ * */ -#include "ApplicationPreview.h" -#include "ActionButton.h" #include "unity-shared/IntrospectableWrappers.h" #include "unity-shared/PreviewStyle.h" -#include "unity-shared/ApplicationScreenshot.h" +#include "unity-shared/CoverArt.h" #include "unity-shared/IconTexture.h" +#include "unity-shared/StaticCairoText.h" #include <UnityCore/ApplicationPreview.h> #include <NuxCore/Logger.h> #include <Nux/HLayout.h> #include <Nux/VLayout.h> #include <Nux/Button.h> #include <PreviewFactory.h> + +#include "ApplicationPreview.h" +#include "ActionButton.h" #include "PreviewInfoHintWidget.h" #include "PreviewRatingsWidget.h" @@ -43,23 +45,6 @@ namespace dash namespace previews { -#define TMP_VIEW(name, colour) \ -class TmpView_##name : public nux::View \ -{ \ -public: \ - TmpView_##name():View(NUX_TRACKER_LOCATION) {} \ - ~TmpView_##name() {} \ - virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { \ - gPainter.Paint2DQuadColor(gfx_engine, GetGeometry(), colour); \ - } \ - virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) {} \ -}; - -TMP_VIEW(AppImage, nux::Color(0xAA, 0x00, 0x00, 0.1f)) -TMP_VIEW(AppIcon, nux::Color(0x00, 0x00, 0xAA, 0.1f)) -TMP_VIEW(UserRating, nux::Color(0x00, 0xAA, 0x00, 0.1f)) -TMP_VIEW(Actions, nux::Color(0x00, 0xAA, 0xAA, 0.1f)) - namespace { nux::logging::Logger logger("unity.dash.previews.applicationpreview"); @@ -155,9 +140,11 @@ void ApplicationPreview::SetupViews() nux::HLayout* image_data_layout = new nux::HLayout(); image_data_layout->SetSpaceBetweenChildren(12); - ApplicationScreenshot* app_image = new ApplicationScreenshot(); - app_image->SetImage(g_icon_to_string(preview_model_->image.Get().RawPtr())); + CoverArt* app_image = new CoverArt(); + app_image->SetImage(preview_model_->image.Get().RawPtr() ? g_icon_to_string(preview_model_->image.Get().RawPtr()) : ""); app_image->SetFont(style.no_preview_image_font()); + app_image->SetMinimumWidth(style.GetImageWidth()); + app_image->SetMaximumWidth(style.GetImageWidth()); ///////////////////// // App Data Panel @@ -173,7 +160,7 @@ void ApplicationPreview::SetupViews() ///////////////////// // Icon Layout nux::VLayout* icon_layout = new nux::VLayout(); - app_icon_ = new IconTexture(g_icon_to_string(app_preview_model->app_icon.Get().RawPtr()), 72); + app_icon_ = new IconTexture(app_preview_model->app_icon.Get().RawPtr() ? g_icon_to_string(app_preview_model->app_icon.Get().RawPtr()) : "", 72); app_icon_->SetMinimumSize(100,100); app_icon_->SetMaximumSize(100,100); icon_layout->AddView(app_icon_, 0); @@ -188,18 +175,18 @@ void ApplicationPreview::SetupViews() ///////////////////// ///////////////////// - // App Data + // Data nux::VLayout* app_data_layout = new nux::VLayout(); app_data_layout->SetSpaceBetweenChildren(14); - nux::VLayout* app_name_subtitle_layout = new nux::VLayout(); - app_name_subtitle_layout->SetSpaceBetweenChildren(8); + nux::VLayout* title_subtitle_layout = new nux::VLayout(); + title_subtitle_layout->SetSpaceBetweenChildren(8); - app_name_ = new nux::StaticCairoText(app_preview_model->title); - app_name_->SetFont(style.app_name_font().c_str()); + title_ = new nux::StaticCairoText(app_preview_model->title); + title_->SetFont(style.title_font().c_str()); subtitle_ = new nux::StaticCairoText(app_preview_model->subtitle); - subtitle_->SetFont(style.version_size_font().c_str()); + subtitle_->SetFont(style.subtitle_size_font().c_str()); nux::VLayout* app_updated_copywrite_layout = new nux::VLayout(); app_updated_copywrite_layout->SetSpaceBetweenChildren(8); @@ -213,14 +200,14 @@ void ApplicationPreview::SetupViews() copywrite_ = new nux::StaticCairoText(app_preview_model->copyright); copywrite_->SetFont(style.app_copywrite_font().c_str()); - app_name_subtitle_layout->AddView(app_name_, 1); - app_name_subtitle_layout->AddView(subtitle_, 1); + title_subtitle_layout->AddView(title_, 1); + title_subtitle_layout->AddView(subtitle_, 1); app_updated_copywrite_layout->AddView(license_, 1); app_updated_copywrite_layout->AddView(last_update_, 1); app_updated_copywrite_layout->AddView(copywrite_, 1); - app_data_layout->AddLayout(app_name_subtitle_layout); + app_data_layout->AddLayout(title_subtitle_layout); app_data_layout->AddLayout(app_updated_copywrite_layout); // buffer space @@ -231,7 +218,7 @@ void ApplicationPreview::SetupViews() ///////////////////// ///////////////////// - // App Description + // Description nux::ScrollView* app_info = new nux::ScrollView(NUX_TRACKER_LOCATION); app_info->EnableHorizontalScrollBar(false); @@ -247,14 +234,14 @@ void ApplicationPreview::SetupViews() app_description_->SetMaximumWidth(400); app_description_->SetText(app_preview_model->description); - PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_); + PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, 24); app_info_layout->AddView(app_description_); app_info_layout->AddView(preview_info_hints); ///////////////////// ///////////////////// - // App Actions + // Actions nux::HLayout* actions_layout = new nux::HLayout(); actions_layout->SetSpaceBetweenChildren(12); actions_layout->AddSpace(0, 1); @@ -273,18 +260,12 @@ void ApplicationPreview::SetupViews() full_data_layout_->AddLayout(actions_layout, 0); ///////////////////// - image_data_layout->AddView(app_image, 1); + image_data_layout->AddView(app_image, 0); image_data_layout->AddLayout(full_data_layout_, 1); SetLayout(image_data_layout); } -void ApplicationPreview::OnActionActivated(nux::Button*, std::string const& id) -{ - if (preview_model_) - preview_model_->PerformAction(id); -} - } // namespace previews } // namespace dash } // namepsace unity diff --git a/dash/previews/ApplicationPreview.h b/dash/previews/ApplicationPreview.h index e2de0eec1..a36767519 100644 --- a/dash/previews/ApplicationPreview.h +++ b/dash/previews/ApplicationPreview.h @@ -25,14 +25,12 @@ #include "Preview.h" #include <Nux/Nux.h> -#include "unity-shared/StaticCairoText.h" -#include <Nux/StaticText.h> namespace nux { class AbstractPaintLayer; class VLayout; -class Button; +class StaticCairoText; } namespace unity @@ -66,14 +64,13 @@ protected: void SetupBackground(); void SetupViews(); - void OnActionActivated(nux::Button* button, std::string const& id); protected: IconTexture* app_icon_; PreviewRatingsWidget* app_rating_; nux::VLayout* full_data_layout_; - nux::StaticCairoText* app_name_; + nux::StaticCairoText* title_; nux::StaticCairoText* subtitle_; nux::StaticCairoText* license_; nux::StaticCairoText* last_update_; diff --git a/dash/previews/CMakeLists.txt b/dash/previews/CMakeLists.txt index 97828b34b..71231c6d9 100644 --- a/dash/previews/CMakeLists.txt +++ b/dash/previews/CMakeLists.txt @@ -39,6 +39,8 @@ set (PREVIEWS_SOURCES PreviewInfoHintWidget.cpp PreviewNavigator.cpp PreviewRatingsWidget.cpp + Track.cpp + Tracks.cpp ) add_library (previews-lib STATIC ${PREVIEWS_SOURCES}) @@ -55,6 +57,13 @@ target_link_libraries (app_previews previews-lib unity-shared) # # Music Standalone variant # -#add_executable (music_previews StandaloneMusicPreview.cpp) -#add_dependencies (music_previews previews-lib) -#target_link_libraries (music_previews previews-lib unity-shared) \ No newline at end of file +add_executable (music_previews StandaloneMusicPreview.cpp) +add_dependencies (music_previews previews-lib) +target_link_libraries (music_previews previews-lib unity-shared) + +# +# Generic Standalone variant +# +add_executable (generic_previews StandaloneGenericPreview.cpp) +add_dependencies (generic_previews previews-lib) +target_link_libraries (generic_previews previews-lib unity-shared) \ No newline at end of file diff --git a/dash/previews/GenericPreview.cpp b/dash/previews/GenericPreview.cpp index dd15dc011..791b811b4 100644 --- a/dash/previews/GenericPreview.cpp +++ b/dash/previews/GenericPreview.cpp @@ -20,11 +20,19 @@ * */ -#include "GenericPreview.h" #include "unity-shared/IntrospectableWrappers.h" +#include "unity-shared/PreviewStyle.h" +#include "unity-shared/CoverArt.h" +#include "unity-shared/StaticCairoText.h" #include <NuxCore/Logger.h> -#include <Nux/Layout.h> -#include <PreviewFactory.h> +#include <Nux/HLayout.h> +#include <Nux/VLayout.h> +#include <Nux/Button.h> +#include <UnityCore/GenericPreview.h> + +#include "GenericPreview.h" +#include "ActionButton.h" +#include "PreviewInfoHintWidget.h" namespace unity { @@ -44,6 +52,8 @@ NUX_IMPLEMENT_OBJECT_TYPE(GenericPreview); GenericPreview::GenericPreview(dash::Preview::Ptr preview_model) : Preview(preview_model) { + SetupBackground(); + SetupViews(); } GenericPreview::~GenericPreview() @@ -52,16 +62,45 @@ GenericPreview::~GenericPreview() void GenericPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { - Preview::Draw(gfx_engine, 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 GenericPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) { - Preview::DrawContent(gfx_engine, force_draw); - - nux::Geometry base = GetGeometry(); + 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(); } @@ -76,6 +115,104 @@ void GenericPreview::AddProperties(GVariantBuilder* builder) Preview::AddProperties(builder); } +void GenericPreview::SetupBackground() +{ + nux::ROPConfig rop; + rop.Blend = true; + rop.SrcBlend = GL_ONE; + rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; + details_bg_layer_.reset(new nux::ColorLayer(nux::Color(0.03f, 0.03f, 0.03f, 0.0f), true, rop)); +} + +void GenericPreview::SetupViews() +{ + dash::GenericPreview* app_preview_model = dynamic_cast<dash::GenericPreview*>(preview_model_.get()); + if (!app_preview_model) + return; + + previews::Style& style = dash::previews::Style::Instance(); + + nux::HLayout* image_data_layout = new nux::HLayout(); + image_data_layout->SetSpaceBetweenChildren(12); + + CoverArt* app_image = new CoverArt(); + app_image->SetImage(preview_model_->image.Get().RawPtr() ? g_icon_to_string(preview_model_->image.Get().RawPtr()) : ""); + app_image->SetFont(style.no_preview_image_font()); + app_image->SetMinimumWidth(style.GetImageWidth()); + app_image->SetMaximumWidth(style.GetImageWidth()); + + ///////////////////// + // Data Panel + full_data_layout_ = new nux::VLayout(); + full_data_layout_->SetPadding(10); + full_data_layout_->SetSpaceBetweenChildren(16); + + ///////////////////// + // Data + nux::VLayout* app_data_layout = new nux::VLayout(); + app_data_layout->SetSpaceBetweenChildren(8); + + title_ = new nux::StaticCairoText(app_preview_model->title); + title_->SetFont(style.title_font().c_str()); + + subtitle_ = new nux::StaticCairoText(app_preview_model->subtitle); + subtitle_->SetFont(style.subtitle_size_font().c_str()); + + app_data_layout->AddView(title_, 1); + app_data_layout->AddView(subtitle_, 1); + ///////////////////// + + ///////////////////// + // Description + nux::ScrollView* app_info = new nux::ScrollView(NUX_TRACKER_LOCATION); + app_info->EnableHorizontalScrollBar(false); + + nux::VLayout* app_info_layout = new nux::VLayout(); + app_info_layout->SetSpaceBetweenChildren(16); + app_info->SetLayout(app_info_layout); + + app_description_ = new nux::StaticCairoText(""); + app_description_->SetFont(style.app_description_font().c_str()); + app_description_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_TOP); + app_description_->SetLines(-20); + app_description_->SetLineSpacing(1); + app_description_->SetMaximumWidth(400); + app_description_->SetText(app_preview_model->description); + + PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, 24); + + app_info_layout->AddView(app_description_); + app_info_layout->AddView(preview_info_hints); + ///////////////////// + + ///////////////////// + // Actions + nux::HLayout* actions_layout = new nux::HLayout(); + actions_layout->SetSpaceBetweenChildren(12); + actions_layout->AddSpace(0, 1); + + for (dash::Preview::ActionPtr action : preview_model_->GetActions()) + { + ActionButton* button = new ActionButton(action->display_name, NUX_TRACKER_LOCATION); + button->click.connect(sigc::bind(sigc::mem_fun(this, &GenericPreview::OnActionActivated), action->id)); + + actions_layout->AddView(button, 0); + } + ///////////////////// + + full_data_layout_->AddLayout(app_data_layout, 0); + full_data_layout_->AddView(app_info, 1); + full_data_layout_->AddLayout(actions_layout, 0); + ///////////////////// + + image_data_layout->AddView(app_image, 0); + image_data_layout->AddLayout(full_data_layout_, 1); + + SetLayout(image_data_layout); +} + + + } } } diff --git a/dash/previews/GenericPreview.h b/dash/previews/GenericPreview.h index 2d9397a17..58847a0e0 100644 --- a/dash/previews/GenericPreview.h +++ b/dash/previews/GenericPreview.h @@ -27,6 +27,13 @@ #include <Nux/Nux.h> #include <UnityCore/GenericPreview.h> +namespace nux +{ +class AbstractPaintLayer; +class StaticCairoText; +class VLayout; +} + namespace unity { namespace dash @@ -50,6 +57,19 @@ public: protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); + + void SetupBackground(); + void SetupViews(); + +protected: + nux::VLayout* full_data_layout_; + + nux::StaticCairoText* title_; + nux::StaticCairoText* subtitle_; + nux::StaticCairoText* app_description_; + + typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr; + LayerPtr details_bg_layer_; }; } diff --git a/dash/previews/MusicPreview.cpp b/dash/previews/MusicPreview.cpp index 972455608..75a0bc2ec 100644 --- a/dash/previews/MusicPreview.cpp +++ b/dash/previews/MusicPreview.cpp @@ -20,11 +20,22 @@ * */ -#include "MusicPreview.h" #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 <UnityCore/MusicPreview.h> #include <NuxCore/Logger.h> -#include <Nux/Layout.h> +#include <Nux/HLayout.h> +#include <Nux/VLayout.h> +#include <Nux/Button.h> #include <PreviewFactory.h> + +#include "MusicPreview.h" +#include "ActionButton.h" +#include "PreviewInfoHintWidget.h" +#include "Tracks.h" namespace unity { @@ -33,6 +44,21 @@ namespace dash namespace previews { + +#define TMP_VIEW(name, colour) \ +class TmpView_##name : public nux::View \ +{ \ +public: \ + TmpView_##name():View(NUX_TRACKER_LOCATION) {} \ + ~TmpView_##name() {} \ + virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { \ + gPainter.Paint2DQuadColor(gfx_engine, GetGeometry(), colour); \ + } \ + virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) {} \ +}; + +TMP_VIEW(Tracks, nux::Color(0xAA, 0x00, 0x00, 0.1f)) + namespace { nux::logging::Logger logger("unity.dash.previews.moviepreview"); @@ -44,6 +70,8 @@ NUX_IMPLEMENT_OBJECT_TYPE(MusicPreview); MusicPreview::MusicPreview(dash::Preview::Ptr preview_model) : Preview(preview_model) { + SetupBackground(); + SetupViews(); } MusicPreview::~MusicPreview() @@ -52,16 +80,45 @@ MusicPreview::~MusicPreview() void MusicPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { - Preview::Draw(gfx_engine, 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 MusicPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) { - Preview::DrawContent(gfx_engine, force_draw); - - nux::Geometry base = GetGeometry(); + 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(); } @@ -76,6 +133,120 @@ void MusicPreview::AddProperties(GVariantBuilder* builder) Preview::AddProperties(builder); } +void MusicPreview::SetupBackground() +{ + nux::ROPConfig rop; + rop.Blend = true; + rop.SrcBlend = GL_ONE; + rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA; + details_bg_layer_.reset(new nux::ColorLayer(nux::Color(0.03f, 0.03f, 0.03f, 0.0f), true, rop)); +} + +void MusicPreview::SetupViews() +{ + dash::MusicPreview* music_preview_model = dynamic_cast<dash::MusicPreview*>(preview_model_.get()); + if (!music_preview_model) + return; + + previews::Style& style = dash::previews::Style::Instance(); + + nux::HLayout* image_data_layout = new nux::HLayout(); + image_data_layout->SetSpaceBetweenChildren(12); + + CoverArt* album_cover = new CoverArt(); + album_cover->SetImage(preview_model_->image.Get().RawPtr() ? g_icon_to_string(preview_model_->image.Get().RawPtr()) : ""); + album_cover->SetFont(style.no_preview_image_font()); + album_cover->SetMinimumWidth(style.GetImageWidth()); + album_cover->SetMaximumWidth(style.GetImageWidth()); + + ///////////////////// + // App Data Panel + full_data_layout_ = new nux::VLayout(); + full_data_layout_->SetPadding(10); + full_data_layout_->SetSpaceBetweenChildren(16); + + ///////////////////// + // Music Info + nux::VLayout* album_data_layout = new nux::VLayout(); + album_data_layout->SetSpaceBetweenChildren(8); + + title_ = new nux::StaticCairoText(preview_model_->title); + title_->SetFont(style.title_font().c_str()); + + subtitle_ = new nux::StaticCairoText(preview_model_->subtitle); + subtitle_->SetFont(style.subtitle_size_font().c_str()); + + album_data_layout->AddView(title_, 1); + album_data_layout->AddView(subtitle_, 1); + + ///////////////////// + + + ///////////////////// + // Music Tracks + dash::Tracks::Ptr tracks_model = music_preview_model->GetTracksModel(); + if (tracks_model) + { + previews::Tracks* tracks = new previews::Tracks(tracks_model, NUX_TRACKER_LOCATION); + tracks->play.connect(sigc::mem_fun(this, &MusicPreview::OnPlayTrack)); + tracks->pause.connect(sigc::mem_fun(this, &MusicPreview::OnPauseTrack)); + tracks_ = tracks; + } + ///////////////////// + + nux::HLayout* hint_actions_layout = new nux::HLayout(); + + ///////////////////// + // Hints + nux::VLayout* hints_layout = new nux::VLayout(); + hints_layout->SetSpaceBetweenChildren(0); + hints_layout->AddSpace(0, 1); + PreviewInfoHintWidget* preview_info_hints = new PreviewInfoHintWidget(preview_model_, 24); + hints_layout->AddView(preview_info_hints, 0); + + ///////////////////// + // Actions + nux::VLayout* actions_container_layout = new nux::VLayout(); + actions_container_layout->SetSpaceBetweenChildren(0); + actions_container_layout->AddSpace(0, 1); + nux::VLayout* actions_layout = new nux::VLayout(); + actions_layout->SetSpaceBetweenChildren(10); + actions_container_layout->AddLayout(actions_layout, 0); + + for (dash::Preview::ActionPtr action : preview_model_->GetActions()) + { + ActionButton* button = new ActionButton(action->display_name, NUX_TRACKER_LOCATION); + button->click.connect(sigc::bind(sigc::mem_fun(this, &MusicPreview::OnActionActivated), action->id)); + + actions_layout->AddView(button, 0); + } + ///////////////////// + + hint_actions_layout->AddView(hints_layout, 1); + hint_actions_layout->AddView(actions_container_layout, 0); + + full_data_layout_->AddLayout(album_data_layout, 0); + if (tracks_) { full_data_layout_->AddView(tracks_, 1); } + full_data_layout_->AddLayout(hint_actions_layout, 0); + ///////////////////// + + image_data_layout->AddView(album_cover, 0); + image_data_layout->AddLayout(full_data_layout_, 1); + + SetLayout(image_data_layout); +} + +void MusicPreview::OnPlayTrack(std::string const& uri) +{ + LOG_ERROR(logger) << "Play not connected"; +} + +void MusicPreview::OnPauseTrack(std::string const& uri) +{ + LOG_ERROR(logger) << "Pause not connected"; +} + + } } } diff --git a/dash/previews/MusicPreview.h b/dash/previews/MusicPreview.h index a4aaee67e..730855809 100644 --- a/dash/previews/MusicPreview.h +++ b/dash/previews/MusicPreview.h @@ -25,7 +25,14 @@ #include "Preview.h" #include <Nux/Nux.h> -#include <UnityCore/MusicPreview.h> +#include <Nux/StaticText.h> + +namespace nux +{ +class AbstractPaintLayer; +class StaticCairoText; +class VLayout; +} namespace unity { @@ -33,6 +40,8 @@ namespace dash { namespace previews { +class Tracks; + class MusicPreview : public Preview { @@ -50,7 +59,22 @@ public: protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw); -}; + + void SetupBackground(); + void SetupViews(); + + void OnPlayTrack(std::string const& uri); + void OnPauseTrack(std::string const& uri); + +private: + nux::StaticCairoText* title_; + nux::StaticCairoText* subtitle_; + nux::VLayout* full_data_layout_; + nux::View* tracks_; + + typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr; + LayerPtr details_bg_layer_; + }; } } diff --git a/dash/previews/Preview.cpp b/dash/previews/Preview.cpp index 9c54aed77..cdc58f835 100644 --- a/dash/previews/Preview.cpp +++ b/dash/previews/Preview.cpp @@ -58,6 +58,12 @@ void Preview::AddProperties(GVariantBuilder* builder) { } +void Preview::OnActionActivated(nux::Button* button, std::string const& id) +{ + if (preview_model_) + preview_model_->PerformAction(id); +} + } } } diff --git a/dash/previews/Preview.h b/dash/previews/Preview.h index 291d422ac..36489e3fd 100644 --- a/dash/previews/Preview.h +++ b/dash/previews/Preview.h @@ -28,6 +28,11 @@ #include <UnityCore/Preview.h> #include "unity-shared/Introspectable.h" +namespace nux +{ +class Button; +} + namespace unity { namespace dash @@ -52,6 +57,8 @@ protected: virtual void Draw(nux::GraphicsEngine& GfxContext, bool force_draw) {} virtual void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) {} + virtual void OnActionActivated(nux::Button* button, std::string const& id); + protected: dash::Preview::Ptr preview_model_; diff --git a/dash/previews/PreviewContainer.cpp b/dash/previews/PreviewContainer.cpp index 9c6fb291f..01b8b3b47 100644 --- a/dash/previews/PreviewContainer.cpp +++ b/dash/previews/PreviewContainer.cpp @@ -65,8 +65,11 @@ public: void PushPreview(previews::Preview::Ptr preview, Navigation direction) { - AddView(preview.GetPointer()); - preview->SetVisible(false); + if (preview) + { + AddView(preview.GetPointer()); + preview->SetVisible(false); + } PreviewSwipe swipe; swipe.direction = direction; swipe.preview = preview; @@ -215,7 +218,7 @@ PreviewContainer::~PreviewContainer() { } -void PreviewContainer::preview(glib::Variant const& preview, Navigation direction) +void PreviewContainer::Preview(glib::Variant const& preview, Navigation direction) { PreviewFactoryOperator previewOperator(PreviewFactory::Instance().Item(preview)); @@ -230,6 +233,7 @@ void PreviewContainer::DisableNavButton(Navigation button) nav_disabled_ = button; nav_right_->SetEnabled(IsNavigationDisabled(Navigation::RIGHT) == false); nav_left_->SetEnabled(IsNavigationDisabled(Navigation::LEFT) == false); + QueueDraw(); } bool PreviewContainer::IsNavigationDisabled(Navigation button) const @@ -254,8 +258,8 @@ void PreviewContainer::SetupViews() SetLayout(layout_); nav_left_ = new PreviewNavigator(Orientation::LEFT, NUX_TRACKER_LOCATION); - nav_left_->SetMinimumWidth(stlye.NavigatorMinimumWidth()); - nav_left_->SetMaximumWidth(stlye.NavigatorMaximumWidth()); + nav_left_->SetMinimumWidth(stlye.GetNavigatorWidth()); + nav_left_->SetMaximumWidth(stlye.GetNavigatorWidth()); nav_left_->activated.connect([&]() { navigate_left.emit(); }); layout_->AddView(nav_left_, 0); @@ -263,8 +267,8 @@ void PreviewContainer::SetupViews() layout_->AddLayout(content_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); nav_right_ = new PreviewNavigator(Orientation::RIGHT, NUX_TRACKER_LOCATION); - nav_right_->SetMinimumWidth(stlye.NavigatorMinimumWidth()); - nav_right_->SetMaximumWidth(stlye.NavigatorMaximumWidth()); + nav_right_->SetMinimumWidth(stlye.GetNavigatorWidth()); + nav_right_->SetMaximumWidth(stlye.GetNavigatorWidth()); nav_right_->activated.connect([&]() { navigate_right.emit(); }); layout_->AddView(nav_right_, 0); diff --git a/dash/previews/PreviewContainer.h b/dash/previews/PreviewContainer.h index c002ebfc9..136c566dd 100644 --- a/dash/previews/PreviewContainer.h +++ b/dash/previews/PreviewContainer.h @@ -58,7 +58,7 @@ public: PreviewContainer(NUX_FILE_LINE_PROTO); virtual ~PreviewContainer(); - void preview(glib::Variant const& preview, Navigation direction); + void Preview(glib::Variant const& preview, Navigation direction); // calling this should disable the nav buttons to the left or the right of the preview void DisableNavButton(Navigation button); diff --git a/dash/previews/PreviewFactory.cpp b/dash/previews/PreviewFactory.cpp index 11dd6999f..02995a756 100644 --- a/dash/previews/PreviewFactory.cpp +++ b/dash/previews/PreviewFactory.cpp @@ -63,7 +63,7 @@ PreviewFactory::PreviewFactory() RegisterItem("preview-application", new PreviewFactoryItem<dash::ApplicationPreview, previews::ApplicationPreview>()); RegisterItem("preview-generic", new PreviewFactoryItem<dash::GenericPreview, previews::GenericPreview>()); RegisterItem("preview-movie", new PreviewFactoryItem<dash::MoviePreview, previews::MoviePreview>()); - RegisterItem("preview-movie", new PreviewFactoryItem<dash::MusicPreview, previews::MusicPreview>()); + RegisterItem("preview-music", new PreviewFactoryItem<dash::MusicPreview, previews::MusicPreview>()); } PreviewFactory::~PreviewFactory() @@ -134,6 +134,14 @@ PreviewFactoryOperator PreviewFactory::Item(glib::Object<GObject> const& proto_o auto iter = factory_items_.find(renderer_name); if (iter == factory_items_.end()) { + LOG_TRACE(logger) << "No preview factor item for '" << renderer_name << "'; using generic preview"; + + iter = factory_items_.find("preview-generic"); + if (iter != factory_items_.end()) + { + return PreviewFactoryOperator(proto_obj, (*iter).second); + } + LOG_WARN(logger) << "Factory item '" << renderer_name << " not registered."; return nullOperator; } diff --git a/dash/previews/PreviewInfoHintWidget.cpp b/dash/previews/PreviewInfoHintWidget.cpp index e371ffe41..016e5e12e 100644 --- a/dash/previews/PreviewInfoHintWidget.cpp +++ b/dash/previews/PreviewInfoHintWidget.cpp @@ -39,8 +39,9 @@ nux::logging::Logger logger("unity.dash.previews.previewinfohintwidget"); NUX_IMPLEMENT_OBJECT_TYPE(PreviewInfoHintWidget); -PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model) +PreviewInfoHintWidget::PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size) : View(NUX_TRACKER_LOCATION) + , icon_size_(icon_size) , preview_model_(preview_model) { SetupViews(); @@ -136,32 +137,36 @@ void PreviewInfoHintWidget::SetupViews() previews::Style& style = previews::Style::Instance(); nux::VLayout* layout = new nux::VLayout(); + layout->SetSpaceBetweenChildren(6); for (dash::Preview::InfoHintPtr info_hint : preview_model_->GetInfoHints()) { nux::HLayout* hint_layout = new nux::HLayout(); hint_layout->SetSpaceBetweenChildren(16); - int icon_width = 32; - - IconTexture* info_icon = new IconTexture(info_hint->icon_hint, icon_width); - info_icon->SetMinimumSize(icon_width, icon_width); + IconTexture* info_icon = new IconTexture(info_hint->icon_hint, icon_size_); + info_icon->SetMinimumSize(icon_size_, icon_size_); info_icon->SetVisible(true); hint_layout->AddView(info_icon, 0); - nux::StaticCairoText* info_name = new nux::StaticCairoText(info_hint->display_name, NUX_TRACKER_LOCATION); - info_name->SetFont(style.info_hint_font()); - nux::Layout* info_name_layout = new nux::HLayout(); - info_name_layout->AddView(info_name, 1, nux::MINOR_POSITION_CENTER); - info_name_layout->SetMaximumWidth(128 - (icon_width > 0 ? (icon_width + 16) : 0)); - + if (info_hint->display_name.size() > 0) + { + nux::StaticCairoText* info_name = new nux::StaticCairoText(info_hint->display_name, NUX_TRACKER_LOCATION); + info_name->SetFont(style.info_hint_font()); + + nux::Layout* info_name_layout = new nux::HLayout(); + info_name_layout->AddView(info_name, 1, nux::MINOR_POSITION_CENTER); + info_name_layout->SetMaximumWidth(128 - (icon_size_ > 0 ? (icon_size_ + 16) : 0)); + + hint_layout->AddView(info_name_layout, 1); + } + nux::StaticCairoText* info_value = new nux::StaticCairoText(StringFromVariant(info_hint->value), NUX_TRACKER_LOCATION); info_value->SetFont(style.info_hint_font()); nux::Layout* info_value_layout = new nux::HLayout(); info_value_layout->AddView(info_value, 1, nux::MINOR_POSITION_CENTER); - hint_layout->AddView(info_name_layout, 1); hint_layout->AddView(info_value_layout, 1); layout->AddLayout(hint_layout, 0); diff --git a/dash/previews/PreviewInfoHintWidget.h b/dash/previews/PreviewInfoHintWidget.h index db0f46a04..f624a7d40 100644 --- a/dash/previews/PreviewInfoHintWidget.h +++ b/dash/previews/PreviewInfoHintWidget.h @@ -42,7 +42,7 @@ public: typedef nux::ObjectPtr<PreviewInfoHintWidget> Ptr; NUX_DECLARE_OBJECT_TYPE(PreviewInfoHintWidget, nux::View); - PreviewInfoHintWidget(dash::Preview::Ptr preview_model); + PreviewInfoHintWidget(dash::Preview::Ptr preview_model, int icon_size); virtual ~PreviewInfoHintWidget(); // From debug::Introspectable @@ -62,6 +62,8 @@ protected: std::string icon_name); protected: + int icon_size_; + dash::Preview::Ptr preview_model_; typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; }; diff --git a/dash/previews/PreviewNavigator.cpp b/dash/previews/PreviewNavigator.cpp index d733a46e2..f65cf6a9b 100644 --- a/dash/previews/PreviewNavigator.cpp +++ b/dash/previews/PreviewNavigator.cpp @@ -25,6 +25,8 @@ #include <NuxCore/Logger.h> #include <Nux/HLayout.h> #include <Nux/VLayout.h> +#include <unity-shared/IconTexture.h> +#include <unity-shared/PreviewStyle.h> namespace unity { @@ -43,6 +45,7 @@ NUX_IMPLEMENT_OBJECT_TYPE(PreviewNavigator); PreviewNavigator::PreviewNavigator(Orientation orientation, NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM) , orientation_(orientation) + , texture_(nullptr) { SetupViews(); } @@ -54,8 +57,8 @@ std::string PreviewNavigator::GetName() const void PreviewNavigator::SetEnabled(bool enabled) { - button_->SetEnableView(enabled); - button_->SetVisible(enabled); + texture_->SetEnableView(enabled); + texture_->SetVisible(enabled); } void PreviewNavigator::AddProperties(GVariantBuilder* builder) @@ -72,9 +75,15 @@ void PreviewNavigator::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_d nux::Geometry base = GetGeometry(); gfx_engine.PushClippingRectangle(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); + if (GetCompositionLayout()) GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw); + gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); + gfx_engine.PopClippingRectangle(); } @@ -85,6 +94,11 @@ void PreviewNavigator::SetupViews() nux::VLayout* vlayout = new nux::VLayout(); vlayout->SetSpaceBetweenChildren(0); layout_ = vlayout; + + if (orientation_ == Orientation::LEFT) + texture_ = new IconTexture(Style::Instance().GetNavLeftIcon(), 32, 32); + else + texture_ = new IconTexture(Style::Instance().GetNavRightIcon(), 32, 32); } else if (orientation_ == Orientation::UP || orientation_ == Orientation::DOWN) { @@ -96,21 +110,19 @@ void PreviewNavigator::SetupViews() layout_->AddSpace(0, 1); - button_ = new nux::Button("nav", NUX_TRACKER_LOCATION); - button_->SetMinimumHeight(64); - button_->SetMaximumHeight(64); - button_->SetMinimumWidth(32); - button_->SetMaximumWidth(32); - button_->click.connect([&](nux::Button* const&) { OnClicked(); }); - layout_->AddView(button_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + if (texture_) + { + texture_->mouse_click.connect([&](int, int, unsigned long, unsigned long) { activated.emit(); }); + texture_->SetMinimumHeight(32); + texture_->SetMaximumHeight(32); + texture_->SetMinimumWidth(32); + texture_->SetMaximumWidth(32); + layout_->AddView(texture_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + } layout_->AddSpace(0, 1); } -void PreviewNavigator::OnClicked() -{ - activated.emit(); -} } // namespace previews } // namespace dash diff --git a/dash/previews/PreviewNavigator.h b/dash/previews/PreviewNavigator.h index 23c45e355..5a3cf040b 100644 --- a/dash/previews/PreviewNavigator.h +++ b/dash/previews/PreviewNavigator.h @@ -25,12 +25,14 @@ #include <Nux/Nux.h> #include <Nux/View.h> -#include <Nux/Button.h> #include "unity-shared/PreviewStyle.h" #include "unity-shared/Introspectable.h" + namespace unity { +class IconTexture; + namespace dash { namespace previews @@ -58,12 +60,10 @@ private: void SetupViews(); - void OnClicked(); - private: const Orientation orientation_; nux::Layout* layout_; - nux::Button* button_; + IconTexture* texture_; }; } // namespace previews diff --git a/dash/previews/PreviewRatingsWidget.cpp b/dash/previews/PreviewRatingsWidget.cpp index 5951abc38..2f1612c79 100644 --- a/dash/previews/PreviewRatingsWidget.cpp +++ b/dash/previews/PreviewRatingsWidget.cpp @@ -16,7 +16,7 @@ * License version 3 along with this program. If not, see * <http://www.gnu.org/licenses/> * - * Authored by: Gordon Allott <gord.allott@canonical.com> + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> * */ diff --git a/dash/previews/PreviewRatingsWidget.h b/dash/previews/PreviewRatingsWidget.h index 15abb00a2..bad8451ca 100644 --- a/dash/previews/PreviewRatingsWidget.h +++ b/dash/previews/PreviewRatingsWidget.h @@ -16,7 +16,7 @@ * License version 3 along with this program. If not, see * <http://www.gnu.org/licenses/> * - * Authored by: Gordon Allott <gord.allott@canonical.com> + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> * */ diff --git a/dash/previews/StandaloneApplicationPreview.cpp b/dash/previews/StandaloneApplicationPreview.cpp index 05aba8498..e2649b2c6 100644 --- a/dash/previews/StandaloneApplicationPreview.cpp +++ b/dash/previews/StandaloneApplicationPreview.cpp @@ -26,11 +26,7 @@ #include <Nux/Layout.h> #include <NuxCore/Logger.h> #include <UnityCore/Variant.h> -#include <UnityCore/Preview.h> #include <UnityCore/ApplicationPreview.h> -#include <UnityCore/MoviePreview.h> -#include <UnityCore/MusicPreview.h> -#include <UnityCore/SeriesPreview.h> #include <unity-protocol.h> #include "PreviewFactory.h" @@ -192,7 +188,7 @@ The service allows users to communicate with peers by voice, video, and instant glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef()); - container_->preview(v, previews::Navigation::RIGHT); + container_->Preview(v, previews::Navigation::RIGHT); } @@ -237,7 +233,7 @@ The service allows users to communicate with peers by voice, video, and instant glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef()); - container_->preview(v, previews::Navigation::RIGHT); + container_->Preview(v, previews::Navigation::RIGHT); } void TestRunner::NavLeft() @@ -279,7 +275,7 @@ The service allows users to communicate with peers by voice, video, and instant glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef()); - container_->preview(v, previews::Navigation::LEFT); + container_->Preview(v, previews::Navigation::LEFT); } void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData) diff --git a/dash/previews/StandaloneDBusTestRunner.h b/dash/previews/StandaloneDBusTestRunner.h new file mode 100644 index 000000000..9061b31a1 --- /dev/null +++ b/dash/previews/StandaloneDBusTestRunner.h @@ -0,0 +1,285 @@ +#include <UnityCore/GLibDBusProxy.h> + +#include <UnityCore/Preview.h> +#include <UnityCore/Lens.h> +#include <UnityCore/Results.h> +#include <NuxCore/Logger.h> + +namespace unity +{ +namespace dash +{ +namespace previews +{ +namespace +{ +nux::logging::Logger logger("unity.dash.StandaloneDBusTestRunner"); +} + + +class StandaloneDBusTestRunner +{ +public: + typedef std::map<std::string, unity::glib::Variant> Hints; + + StandaloneDBusTestRunner(std::string const& dbus_name, std::string const& dbus_path) + : proxy_(nullptr) + , results_(new Results(ModelType::REMOTE)) + , results_variant_(NULL) + , connected_(false) + , dbus_name_(dbus_name) + , dbus_path_(dbus_path) + { + proxy_ = new glib::DBusProxy(dbus_name, dbus_path, "com.canonical.Unity.Lens"); + proxy_->connected.connect(sigc::mem_fun(this, &StandaloneDBusTestRunner::OnProxyConnectionChanged)); + proxy_->disconnected.connect(sigc::mem_fun(this, &StandaloneDBusTestRunner::OnProxyDisconnected)); + proxy_->Connect("Changed", sigc::mem_fun(this, &StandaloneDBusTestRunner::OnChanged)); + + results_->end_transaction.connect(sigc::mem_fun(this, &StandaloneDBusTestRunner::ResultsModelUpdated)); + } + + void OnProxyConnectionChanged() + { + LOG_DEBUG(logger) << "Dbus connection changed. connected=" << (proxy_->IsConnected() ? "true" : "false"); + + if (proxy_->IsConnected()) + { + proxy_->Call("InfoRequest"); + proxy_->Call("SetViewType", g_variant_new("(u)", LENS_VIEW)); + } + } + + void OnProxyDisconnected() + { + LOG_DEBUG(logger) << "Dbus disconnected"; + + connected_ = false; + connected.emit(connected_); + } + + void OnChanged(GVariant* parameters) + { + glib::String dbus_path; + gboolean search_in_global = FALSE; + gboolean visible = FALSE; + glib::String search_hint; + glib::String private_connection_name; + glib::String results_model_name; + glib::String global_results_model_name; + glib::String categories_model_name; + glib::String filters_model_name; + GVariantIter* hints_iter = NULL; + + g_variant_get(parameters, "((sbbssssssa{sv}))", + &dbus_path, + &search_in_global, + &visible, + &search_hint, + &private_connection_name, + &results_model_name, + &global_results_model_name, + &categories_model_name, + &filters_model_name, + &hints_iter); + + LOG_DEBUG(logger) << "Lens info changed for " << dbus_name_ << "\n" + << " Path: " << dbus_path << "\n" + << " SearchInGlobal: " << search_in_global << "\n" + << " Visible: " << visible << "\n" + << " PrivateConnName: " << private_connection_name << "\n" + << " Results: " << results_model_name << "\n" + << " GlobalModel: " << global_results_model_name << "\n" + << " Categories: " << categories_model_name << "\n" + << " Filters: " << filters_model_name << "\n"; + if (dbus_path.Str() == dbus_path_) + { + results_->swarm_name = results_model_name; + LOG_DEBUG(logger) << "Received changes for " << dbus_path; + } + else + { + LOG_WARNING(logger) << "Paths do not match " << dbus_path_ << " != " << dbus_path; + } + + connected_ = true; + connected.emit(connected_); + + g_variant_iter_free(hints_iter); + } + + void Search(std::string const& search_string) + { + LOG_DEBUG(logger) << "Searching '" << dbus_name_ << "' for '" << search_string << "'"; + + if (proxy_ == NULL) + { + LOG_DEBUG(logger) << "Skipping search. Proxy not initialized. ('" << dbus_name_ << "')"; + return; + } + + GVariantBuilder b; + g_variant_builder_init(&b, G_VARIANT_TYPE("a{sv}")); + + if (search_cancellable_) g_cancellable_cancel (search_cancellable_); + search_cancellable_ = g_cancellable_new (); + + proxy_->Call("Search", + g_variant_new("(sa{sv})", + search_string.c_str(), + &b), + sigc::mem_fun(this, &StandaloneDBusTestRunner::OnSearchFinished), + search_cancellable_); + + g_variant_builder_clear(&b); + } + + void OnSearchFinished(GVariant* parameters) + { + Hints hints; + unsigned long long reply_seqnum; + reply_seqnum = ExtractModelSeqnum (parameters); + if (results_->seqnum < reply_seqnum) + { + // wait for the end-transaction signal + if (results_variant_) g_variant_unref (results_variant_); + results_variant_ = g_variant_ref (parameters); + + return; + } + + glib::Variant dict (parameters); + dict.ASVToHints(hints); + + search_finished.emit(hints); + } + + void ResultsModelUpdated(unsigned long long begin_seqnum, + unsigned long long end_seqnum) + { + if (results_variant_ != NULL && + end_seqnum >= ExtractModelSeqnum (results_variant_)) + { + glib::Variant dict(results_variant_, glib::StealRef()); + Hints hints; + + dict.ASVToHints(hints); + + search_finished.emit(hints); + + results_variant_ = NULL; + } + } + + + + void Preview(std::string const& uri) + { + LOG_DEBUG(logger) << "Previewing '" << uri << "' on '" << dbus_name_ << "'"; + + if (!proxy_->IsConnected()) + { + LOG_DEBUG(logger) << "Skipping preview. Proxy not connected. ('" << dbus_name_ << "')"; + return; + } + + if (preview_cancellable_) + { + g_cancellable_cancel(preview_cancellable_); + } + preview_cancellable_ = g_cancellable_new (); + + proxy_->Call("Activate", + g_variant_new("(su)", uri.c_str(), + UNITY_PROTOCOL_ACTION_TYPE_PREVIEW_RESULT), + sigc::mem_fun(this, &StandaloneDBusTestRunner::ActivationReply), + preview_cancellable_); + } + + void ActivationReply(GVariant* parameters) + { + glib::String uri; + guint32 handled; + GVariant* hints_variant; + Hints hints; + + g_variant_get(parameters, "((su@a{sv}))", &uri, &handled, &hints_variant); + + glib::Variant dict (hints_variant, glib::StealRef()); + dict.ASVToHints(hints); + + + LOG_WARNING(logger) << "ActivationReply type: " << handled; + + if (handled == UNITY_PROTOCOL_HANDLED_TYPE_SHOW_PREVIEW) + { + auto iter = hints.find("preview"); + if (iter != hints.end()) + { + glib::Object<UnityProtocolPreview> proto_object(unity_protocol_preview_parse(iter->second)); + if (!proto_object) + { + LOG_WARN(logger) << "Unable to create Preview object for variant type: " << g_variant_get_type_string(iter->second); + return; + } + else + { + // would be nice to make parent_lens a shared_ptr, + // but that's not really doable from here + preview_ready.emit(uri.Str(), proto_object); + return; + } + } + + LOG_WARNING(logger) << "Unable to deserialize Preview"; + } + else + { + } + } + + + sigc::signal<void, bool> connected; + sigc::signal<void, std::string const&, glib::Object<UnityProtocolPreview> const&> preview_ready; + sigc::signal<void, Hints const&> search_finished; + +protected: + unsigned long long ExtractModelSeqnum(GVariant *parameters) + { + GVariant *dict; + guint64 seqnum64; + unsigned long long seqnum = 0; + + dict = g_variant_get_child_value (parameters, 0); + if (dict) + { + if (g_variant_lookup (dict, "model-seqnum", "t", &seqnum64)) + { + seqnum = static_cast<unsigned long long> (seqnum64); + } + + g_variant_unref (dict); + } + + return seqnum; + } + + + glib::DBusProxy* proxy_; + glib::Object<GCancellable> preview_cancellable_; + glib::Object<GCancellable> search_cancellable_; + Results::Ptr results_; + GVariant *results_variant_; + + bool connected_; + std::string dbus_name_; + std::string dbus_path_; +}; + + + + + + +} // namespace previews +} // namespace dash +} // namespace unity \ No newline at end of file diff --git a/dash/previews/StandaloneGenericPreview.cpp b/dash/previews/StandaloneGenericPreview.cpp new file mode 100644 index 000000000..3684e535d --- /dev/null +++ b/dash/previews/StandaloneGenericPreview.cpp @@ -0,0 +1,255 @@ +/* + * Copyright 2010 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 + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ +#include <gtk/gtk.h> + +#include "Nux/Nux.h" +#include "Nux/VLayout.h" +#include "Nux/WindowThread.h" +#include "NuxGraphics/GraphicsEngine.h" +#include <Nux/Layout.h> +#include <NuxCore/Logger.h> +#include <UnityCore/Variant.h> +#include <UnityCore/Preview.h> +#include <unity-protocol.h> +#include "PreviewFactory.h" + +#include "unity-shared/FontSettings.h" +#include "unity-shared/UnitySettings.h" +#include "unity-shared/PreviewStyle.h" +#include "unity-shared/DashStyle.h" + +#include "Preview.h" +#include "PreviewContainer.h" +#include "StandaloneDBusTestRunner.h" + + +#define WIDTH 972 +#define HEIGHT 452 + +using namespace unity; +using namespace unity::dash; + +namespace +{ +nux::logging::Logger logger("unity.dash.StandaloneGenericPreview"); +} + +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<nux::AbstractPaintLayer> LayerPtr; + LayerPtr bg_layer_; +}; + +class TestRunner : public previews::StandaloneDBusTestRunner +{ +public: + TestRunner(); + ~TestRunner (); + + static void InitWindowThread (nux::NThread* thread, void* InitData); + void Init (); + void NavRight(); + void NavLeft(); + + previews::PreviewContainer::Ptr container_; + nux::Layout *layout_; + unsigned int nav_iter; + previews::Navigation nav_direction_; +}; + +TestRunner::TestRunner () +: StandaloneDBusTestRunner("com.canonical.Unity.Lens.Music","/com/canonical/unity/lens/music") +{ + nav_iter = 0; + nav_direction_ = previews::Navigation::RIGHT; + + connected.connect([&](bool connected) { + if (connected) + { + Search("Led"); + } + }); + + results_->result_added.connect([&](Result const& result) + { + previews::Navigation navDisabled = previews::Navigation::BOTH; + if (nav_iter < results_->count.Get()) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::RIGHT)); + if (results_->count.Get() > 0 && nav_iter > 0) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::LEFT)); + + container_->DisableNavButton(navDisabled); + }); +} + +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)); + + 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_); + + container_->DisableNavButton(previews::Navigation::BOTH); + + preview_ready.connect([&](std::string const& uri, glib::Object<UnityProtocolPreview> const& proto_obj) + { + glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + + container_->Preview(v, nav_direction_); + }); +} + +void TestRunner::NavRight() +{ + nav_direction_ = previews::Navigation::RIGHT; + Result result = results_->RowAtIndex(++nav_iter); + LOG_DEBUG(logger) << "Preview: " << result.uri.Get(); + Preview(result.uri); + + previews::Navigation navDisabled = previews::Navigation::BOTH; + if (nav_iter < results_->count.Get()) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::RIGHT)); + if (results_->count.Get() > 0 && nav_iter > 0) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::LEFT)); + + container_->DisableNavButton(navDisabled); +} + +void TestRunner::NavLeft() +{ + nav_direction_ = previews::Navigation::LEFT; + Result result = results_->RowAtIndex(--nav_iter); + LOG_DEBUG(logger) << "Preview: " << result.uri.Get(); + Preview(result.uri); + + previews::Navigation navDisabled = previews::Navigation::BOTH; + if (nav_iter < results_->count.Get()) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::RIGHT)); + if (results_->count.Get() > 0 && nav_iter > 0) + navDisabled = previews::Navigation( (unsigned int)results_ & ~((unsigned int)previews::Navigation::LEFT)); + + container_->DisableNavButton(navDisabled); +} + +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")); + nux::logging::Logger("unity").SetLogLevel(nux::logging::Trace); + // The instances for the pseudo-singletons. + unity::Settings settings; + unity::dash::previews::Style panel_style; + unity::dash::Style dash_style; + unity::dash::PreviewFactory preview_factory; + + 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; +} + + diff --git a/dash/previews/StandaloneMusicPreview.cpp b/dash/previews/StandaloneMusicPreview.cpp index 4163bf121..982d93be8 100644 --- a/dash/previews/StandaloneMusicPreview.cpp +++ b/dash/previews/StandaloneMusicPreview.cpp @@ -14,7 +14,7 @@ * version 3 along with this program. If not, see * <http://www.gnu.org/licenses/> * - * Authored by: Gordon Allott <gord.allott@canonical.com> + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> * */ #include <gtk/gtk.h> @@ -26,11 +26,7 @@ #include <Nux/Layout.h> #include <NuxCore/Logger.h> #include <UnityCore/Variant.h> -#include <UnityCore/Preview.h> -#include <UnityCore/ApplicationPreview.h> -#include <UnityCore/MoviePreview.h> #include <UnityCore/MusicPreview.h> -#include <UnityCore/SeriesPreview.h> #include <unity-protocol.h> #include "PreviewFactory.h" @@ -41,6 +37,7 @@ #include "Preview.h" #include "PreviewContainer.h" +#include "StandaloneDBusTestRunner.h" #define WIDTH 972 @@ -55,6 +52,9 @@ public: DummyView(nux::View* view) : View(NUX_TRACKER_LOCATION) { + SetAcceptKeyNavFocusOnMouseDown(false); + SetAcceptKeyNavFocusOnMouseEnter(false); + nux::ROPConfig rop; rop.Blend = true; rop.SrcBlend = GL_ONE; @@ -66,6 +66,12 @@ public: 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) @@ -108,10 +114,10 @@ protected: LayerPtr bg_layer_; }; -class TestRunner +class TestRunner : public previews::StandaloneDBusTestRunner { public: - TestRunner (); + TestRunner(); ~TestRunner (); static void InitWindowThread (nux::NThread* thread, void* InitData); @@ -119,14 +125,24 @@ public: void NavRight(); void NavLeft(); + + previews::PreviewContainer::Ptr container_; nux::Layout *layout_; int nav_iter; }; TestRunner::TestRunner () +: StandaloneDBusTestRunner("com.canonical.Unity.Lens.Music","/com/canonical/unity/lens/music") { nav_iter = 0; + preview_ready.connect([&](std::string const& uri, glib::Object<UnityProtocolPreview> const& proto_obj) + { + glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), + glib::StealRef()); + + container_->Preview(v, previews::Navigation::RIGHT); + }); } TestRunner::~TestRunner () @@ -143,36 +159,20 @@ void TestRunner::Init () layout_ = new nux::VLayout(NUX_TRACKER_LOCATION); layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); nux::GetWindowThread()->SetLayout (layout_); +} - - std::stringstream app_name; - app_name << "Title " << nav_iter; - - const char* subtitle = "The Beatles, 1986"; - const char* description = ""; - - // creates a generic preview object - glib::Object<GIcon> image(g_icon_new_for_string("./Beatles.png", NULL)); - glib::Object<GIcon> iconHint1(g_icon_new_for_string("/usr/share/unity/5/lens-nav-music.svg", NULL)); - glib::Object<GIcon> iconHint2(g_icon_new_for_string("/usr/share/unity/5/lens-nav-home.svg", NULL)); - - glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_music_preview_new())); - - unity_protocol_preview_set_title(proto_obj, app_name.str().c_str()); - unity_protocol_preview_set_subtitle(proto_obj, subtitle); - unity_protocol_preview_set_description(proto_obj, description); - unity_protocol_preview_set_thumbnail(proto_obj, image); - unity_protocol_preview_add_action(proto_obj, "play-album", "Play Album", NULL, 0); - unity_protocol_preview_add_info_hint(proto_obj, "run-time", "", iconHint1, g_variant_new("s", "10 Tracks, 37.50 min")); - unity_protocol_preview_add_info_hint(proto_obj, "genre", "Energy", iconHint2, g_variant_new("s", "60s, Rock 'n Roll, britpop")); - - glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), - glib::StealRef()); - - container_->preview(v, previews::RIGHT); - +void TestRunner::NavRight() +{ + std::string uri ="0x9dda078:album://Led Zeppelin/Houses of the Holy"; + Preview(uri); } +void TestRunner::NavLeft() +{ + std::string uri ="0x9dda078:album://Led Zeppelin/Houses of the Holy"; + Preview(uri); +} +/* void TestRunner::NavRight() { std::stringstream app_name; @@ -194,12 +194,12 @@ void TestRunner::NavRight() unity_protocol_preview_set_thumbnail(proto_obj, image); unity_protocol_preview_add_action(proto_obj, "play-album", "Play Album", NULL, 0); unity_protocol_preview_add_info_hint(proto_obj, "run-time", "", iconHint1, g_variant_new("s", "10 Tracks, 37.50 min")); - unity_protocol_preview_add_info_hint(proto_obj, "genre", "Energy", iconHint2, g_variant_new("s", "60s, Rock 'n Roll, britpop")); + unity_protocol_preview_add_info_hint(proto_obj, "genre", "", iconHint2, g_variant_new("s", "60s, Rock 'n Roll, britpop")); glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef()); - container_->preview(v, previews::RIGHT); + container_->preview(v, previews::Navigation::RIGHT); } void TestRunner::NavLeft() @@ -223,13 +223,14 @@ void TestRunner::NavLeft() unity_protocol_preview_set_thumbnail(proto_obj, image); unity_protocol_preview_add_action(proto_obj, "play-album", "Play Album", NULL, 0); unity_protocol_preview_add_info_hint(proto_obj, "run-time", "", iconHint1, g_variant_new("s", "10 Tracks, 37.50 min")); - unity_protocol_preview_add_info_hint(proto_obj, "genre", "Energy", iconHint2, g_variant_new("s", "60s, Rock 'n Roll, britpop")); + unity_protocol_preview_add_info_hint(proto_obj, "genre", "", iconHint2, g_variant_new("s", "60s, Rock 'n Roll, britpop")); glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef()); - container_->preview(v, previews::LEFT); + container_->preview(v, previews::Navigation::LEFT); } +*/ void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData) { @@ -245,7 +246,7 @@ int main(int argc, char **argv) nux::NuxInitialize(0); nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY")); - nux::logging::Logger("unity").SetLogLevel(nux::logging::Warning); + nux::logging::Logger("unity").SetLogLevel(nux::logging::Debug); // The instances for the pseudo-singletons. unity::Settings settings; unity::dash::previews::Style panel_style; diff --git a/dash/previews/Track.cpp b/dash/previews/Track.cpp new file mode 100644 index 000000000..5e4cdb37a --- /dev/null +++ b/dash/previews/Track.cpp @@ -0,0 +1,309 @@ +// -*- 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 + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ + +#include "Track.h" +#include "unity-shared/IntrospectableWrappers.h" +#include <NuxCore/Logger.h> +#include <Nux/HLayout.h> +#include <Nux/LayeredLayout.h> +#include <unity-shared/StaticCairoText.h> +#include <unity-shared/IconTexture.h> +#include <unity-shared/DashStyle.h> +#include <unity-shared/PreviewStyle.h> + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +namespace +{ +nux::logging::Logger logger("unity.dash.previews.track"); +} + +NUX_IMPLEMENT_OBJECT_TYPE(Track); + +Track::Track(NUX_FILE_LINE_DECL) + : View(NUX_FILE_LINE_PARAM) + , track_state(TrackState::STOPPED) +{ + SetupViews(); +} + +Track::~Track() +{ +} + +std::string Track::GetName() const +{ + return "Track"; +} + +void Track::AddProperties(GVariantBuilder* builder) +{ +} + +void Track::Update(dash::Track const& track) +{ + uri_ = track.uri; + progress_ = track.progress; + if (track.track_number == 5) { progress_ = 0.5; } + + title_->SetText(track.title); + + std::stringstream ss_track_number; + ss_track_number << track.track_number; + track_number_->SetText(ss_track_number.str()); + + gchar* duration = g_strdup_printf("%d:%.2d", track.length/60000, (track.length/1000) % 60); + duration_->SetText(duration); + g_free(duration); + + track_busy_ = track.is_playing.Get() || (progress_ > 0.0); + + if (track.is_playing) + { + track_status_layout_->SetActiveLayer(status_pause_layout_); + track_state = TrackState::PLAYING; + } + else if (progress_ > 0.0) + { + track_status_layout_->SetActiveLayer(status_play_layout_); + track_state = TrackState::PAUSED; + } + else + { + track_status_layout_->SetActiveLayer(track_number_layout_); + track_state = TrackState::STOPPED; + } + + QueueDraw(); +} + +void Track::SetupViews() +{ + previews::Style& style = previews::Style::Instance(); + nux::Layout* layout = new nux::HLayout(); + + nux::BaseTexture* tex_play = style.GetPlayIcon(); + IconTexture* status_play = new IconTexture(tex_play, tex_play ? tex_play->GetWidth() : 25, tex_play ? tex_play->GetHeight() : 25); + status_play->mouse_click.connect([&](int, int, unsigned long, unsigned long) { play.emit(uri_); }); + status_play->mouse_enter.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseEnter)); + status_play->mouse_leave.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseLeave)); + + nux::BaseTexture* tex_pause = style.GetPauseIcon(); + IconTexture* status_pause = new IconTexture(tex_pause, tex_pause ? tex_pause->GetWidth() : 25, tex_pause ? tex_pause->GetHeight() : 25); + status_pause->mouse_click.connect([&](int, int, unsigned long, unsigned long) { pause.emit(uri_); }); + status_pause->mouse_enter.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseEnter)); + status_pause->mouse_leave.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseLeave)); + + track_number_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION); + track_number_->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_NONE); + track_number_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); + track_number_->SetTextVerticalAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); + track_number_->SetLines(-1); + track_number_->SetFont(style.track_font()); + track_number_->mouse_enter.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseEnter)); + track_number_->mouse_leave.connect(sigc::mem_fun(this, &Track::OnTrackControlMouseLeave)); + + title_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION); + title_->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_NONE); + title_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_LEFT); + title_->SetTextVerticalAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); + title_->SetLines(-1); + title_->SetFont(style.track_font()); + + duration_ = new nux::StaticCairoText("", NUX_TRACKER_LOCATION); + duration_->SetTextEllipsize(nux::StaticCairoText::NUX_ELLIPSIZE_NONE); + duration_->SetTextAlignment(nux::StaticCairoText::NUX_ALIGN_RIGHT); + duration_->SetTextVerticalAlignment(nux::StaticCairoText::NUX_ALIGN_CENTRE); + duration_->SetLines(-1); + duration_->SetFont(style.track_font()); + + // Layouts + // stick text fields in a layout so they don't alter thier geometry. + status_play_layout_ = new nux::HLayout(); + status_play_layout_->AddSpace(0, 1); + status_play_layout_->AddView(status_play, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + status_play_layout_->AddSpace(0, 1); + + status_pause_layout_ = new nux::HLayout(); + status_pause_layout_->AddSpace(0, 1); + status_pause_layout_->AddView(status_pause, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + status_pause_layout_->AddSpace(0, 1); + + track_number_layout_ = new nux::HLayout(); + track_number_layout_->AddSpace(0, 1); + track_number_layout_->AddView(track_number_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + track_number_layout_->AddSpace(0, 1); + + track_status_layout_ = new nux::LayeredLayout(); + track_status_layout_->AddLayer(status_play_layout_, true); + track_status_layout_->AddLayer(status_pause_layout_, true); + track_status_layout_->AddLayer(track_number_layout_, true); + track_status_layout_->SetActiveLayer(track_number_layout_); + track_status_layout_->SetMinimumWidth(25); + track_status_layout_->SetMaximumWidth(25); + + title_layout_ = new nux::HLayout(); + title_layout_->SetLeftAndRightPadding(3); + title_layout_->AddView(title_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + title_layout_->AddSpace(0, 0); + + duration_layout_ = new nux::HLayout(); + duration_layout_->SetMinimumWidth(60); + duration_layout_->SetMaximumWidth(60); + duration_layout_->AddSpace(0, 1); + duration_layout_->AddView(duration_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + + layout->AddLayout(track_status_layout_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + layout->AddLayout(title_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + layout->AddLayout(duration_layout_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); + SetLayout(layout); + + persistant_status_ = track_status_layout_->GetActiveLayer(); +} + +void Track::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); + + if (HasStatusFocus()) + { + nux::Geometry geo_highlight(track_status_layout_->GetGeometry()); + + gfx_engine.QRP_Color(geo_highlight.x, + geo_highlight.y, + geo_highlight.width, + geo_highlight.height, + nux::Color(0.15f, 0.15f, 0.15f, 0.15f)); + } + + int progress_width = progress_ * (duration_layout_->GetGeometry().x + duration_layout_->GetGeometry().width - title_layout_->GetGeometry().x); + if (progress_width > 0.0) + { + + nux::Geometry geo_progress(title_layout_->GetGeometry().x, + base.y, + progress_width, + base.height); + + gfx_engine.QRP_Color(geo_progress.x, + geo_progress.y, + geo_progress.width, + geo_progress.height, + nux::Color(0.15f, 0.15f, 0.15f, 0.15f), + nux::Color(0.15f, 0.15f, 0.15f, 0.15f), + nux::Color(0.05, 0.05, 0.05, 0.15f), + nux::Color(0.05, 0.05, 0.05, 0.15f)); + + int current_progress_pos = progress_width > 2 ? (geo_progress.x+geo_progress.width) - 2 : geo_progress.x; + + + gfx_engine.QRP_Color(current_progress_pos, + geo_progress.y, + MIN(2, progress_width), + geo_progress.height, + nux::Color(0.7f, 0.7f, 0.7f, 0.15f)); + + } + + gfx_engine.GetRenderStates().SetBlend(alpha, src, dest); + + gfx_engine.PopClippingRectangle(); +} + +void Track::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + gfx_engine.PushClippingRectangle(base); + + if (IsFullRedraw()) + nux::GetPainter().PushPaintLayerStack(); + + 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().PopPaintLayerStack(); + + gfx_engine.PopClippingRectangle(); +} + +bool Track::HasStatusFocus() const +{ + return track_state == TrackState::PLAYING || track_state == TrackState::PAUSED; +} + +void Track::OnTrackControlMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) +{ + switch (track_state) + { + case TrackState::PLAYING: + track_status_layout_->SetActiveLayer(status_pause_layout_); + break; + case TrackState::PAUSED: + case TrackState::STOPPED: + default: + track_status_layout_->SetActiveLayer(status_play_layout_); + break; + } + QueueDraw(); +} + +void Track::OnTrackControlMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) +{ + switch (track_state) + { + case TrackState::PLAYING: + track_status_layout_->SetActiveLayer(status_pause_layout_); + break; + case TrackState::PAUSED: + track_status_layout_->SetActiveLayer(status_play_layout_); + break; + case TrackState::STOPPED: + default: + track_status_layout_->SetActiveLayer(track_number_layout_); + break; + } + QueueDraw(); +} + + +} +} +} diff --git a/dash/previews/Track.h b/dash/previews/Track.h new file mode 100644 index 000000000..29a47cb53 --- /dev/null +++ b/dash/previews/Track.h @@ -0,0 +1,105 @@ +// -*- 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 + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ + +#ifndef TRACK_H +#define TRACK_H + +#include <Nux/Nux.h> +#include <Nux/View.h> +#include <UnityCore/Tracks.h> +#include "unity-shared/Introspectable.h" + +namespace nux +{ + class StaticCairoText; + class LayeredLayout; +} + +namespace unity +{ +class IconTexture; + +namespace dash +{ +namespace previews +{ + +class Track : public nux::View, public debug::Introspectable +{ +public: + typedef nux::ObjectPtr<Track> Ptr; + NUX_DECLARE_OBJECT_TYPE(Track, nux::View); + + Track(NUX_FILE_LINE_PROTO); + virtual ~Track(); + + void Update(dash::Track const& track_row); + + // From debug::Introspectable + std::string GetName() const; + void AddProperties(GVariantBuilder* builder); + + sigc::signal<void, std::string const&> play; + sigc::signal<void, std::string const&> pause; + +protected: + virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw); + virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw); + + void SetupViews(); + + bool HasStatusFocus() const; + + void OnTrackControlMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags); + void OnTrackControlMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags); + +protected: + std::string uri_; + float progress_; + nux::StaticCairoText* track_number_; + nux::StaticCairoText* title_; + nux::StaticCairoText* duration_; + + nux::Layout* title_layout_; + nux::Layout* duration_layout_; + nux::Layout* status_play_layout_; + nux::Layout* status_pause_layout_; + nux::Layout* track_number_layout_; + nux::LayeredLayout* track_status_layout_; + nux::Area* persistant_status_; + + bool track_busy_; + + enum class TrackState { + STOPPED, + PAUSED, + PLAYING, + }; + TrackState track_state; + +}; + +} +} +} + +#endif // TRACK_H diff --git a/dash/previews/Tracks.cpp b/dash/previews/Tracks.cpp new file mode 100644 index 000000000..2c5393a81 --- /dev/null +++ b/dash/previews/Tracks.cpp @@ -0,0 +1,176 @@ +// -*- 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 + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ + +#include "Tracks.h" +#include "unity-shared/IntrospectableWrappers.h" +#include <NuxCore/Logger.h> +#include <Nux/VLayout.h> +#include <UnityCore/Track.h> + + +namespace unity +{ +namespace dash +{ +namespace previews +{ + +class TrackLayout : public nux::VLayout +{ +public: + TrackLayout() {} + + int ItemCount() const { return _layout_element_list.size(); } + + void RemoveViewAt(unsigned int index) + { + unsigned int idx = index; + std::list<Area *>::iterator pos = _layout_element_list.begin(); + + while (pos != _layout_element_list.end() && idx > 0) + { + idx--; + pos++; + } + if (pos != _layout_element_list.end()) + { + ViewRemoved.emit(this, *pos); + (*pos)->UnParentObject(); + _layout_element_list.erase(pos); + } + } + +}; + +namespace +{ +nux::logging::Logger logger("unity.dash.previews.tracks"); +} + +NUX_IMPLEMENT_OBJECT_TYPE(Tracks); + +Tracks::Tracks(dash::Tracks::Ptr tracks, NUX_FILE_LINE_DECL) + : ScrollView(NUX_FILE_LINE_PARAM) + , tracks_(tracks) +{ + SetupViews(); + + if (tracks_) + { + tracks_->track_added.connect(sigc::mem_fun(this, &Tracks::OnTrackAdded)); + tracks_->track_changed.connect(sigc::mem_fun(this, &Tracks::OnTrackUpdated)); + tracks_->track_removed.connect(sigc::mem_fun(this, &Tracks::OnTrackRemoved)); + + // Add what we've got. + for (std::size_t i = 0; i < tracks_->count.Get(); i++) + { + OnTrackAdded(tracks_->RowAtIndex(i)); + } + } +} + +Tracks::~Tracks() +{ +} + +std::string Tracks::GetName() const +{ + return "Tracks"; +} + +void Tracks::AddProperties(GVariantBuilder* builder) +{ +} + +void Tracks::SetupViews() +{ + layout_ = new TrackLayout(); + layout_->SetSpaceBetweenChildren(1); + SetLayout(layout_); +} + +void Tracks::OnTrackUpdated(dash::Track const& track_row) +{ + LOG_DEBUG(logger) << "OnTrackUpdated for " << track_row.title.Get(); + + auto pos = m_tracks.find(track_row.uri.Get()); + if (pos == m_tracks.end()) + return; + + pos->second->Update(track_row); +} + +void Tracks::OnTrackAdded(dash::Track const& track_row) +{ + LOG_DEBUG(logger) << "OnTrackAdded for " << track_row.title.Get(); + + std::string track_uri = track_row.uri.Get(); + if (m_tracks.find(track_uri) != m_tracks.end()) + return; + + previews::Track::Ptr track_view(new previews::Track(NUX_TRACKER_LOCATION)); + track_view->play.connect([&](std::string const& uri) { play.emit(uri); }); + track_view->pause.connect([&](std::string const& uri) { pause.emit(uri); }); + + track_view->Update(track_row); + track_view->SetMinimumHeight(25); + track_view->SetMaximumHeight(25); + layout_->AddView(track_view.GetPointer(), 0); + + m_tracks[track_uri] = track_view; +} + +void Tracks::OnTrackRemoved(dash::Track const& track_row) +{ + LOG_DEBUG(logger) << "OnTrackRemoved for " << track_row.title.Get(); + + auto pos = m_tracks.find(track_row.uri.Get()); + if (pos == m_tracks.end()) + return; + + layout_->RemoveChildObject(pos->second.GetPointer()); +} + +void Tracks::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + + gfx_engine.PushClippingRectangle(base); + nux::GetPainter().PaintBackground(gfx_engine, base); + + gfx_engine.PopClippingRectangle(); +} + +void Tracks::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +{ + nux::Geometry const& base = GetGeometry(); + gfx_engine.PushClippingRectangle(base); + + if (GetCompositionLayout()) + GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw); + + gfx_engine.PopClippingRectangle(); +} + +} // namespace previews +} // namespace dash +} // namespace unity \ No newline at end of file diff --git a/dash/previews/Tracks.h b/dash/previews/Tracks.h new file mode 100644 index 000000000..d5fa1833f --- /dev/null +++ b/dash/previews/Tracks.h @@ -0,0 +1,83 @@ +// -*- 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 + * <http://www.gnu.org/licenses/> + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + * + */ + +#ifndef TRACKS_H +#define TRACKS_H + +#include <Nux/Nux.h> +#include <Nux/ScrollView.h> +#include <UnityCore/Tracks.h> +#include "unity-shared/Introspectable.h" +#include "Track.h" + +namespace unity +{ +namespace dash +{ +class Track; + +namespace previews +{ +class TrackLayout; + +class Tracks : public nux::ScrollView, public debug::Introspectable +{ +public: + typedef nux::ObjectPtr<Tracks> Ptr; + NUX_DECLARE_OBJECT_TYPE(Tracks, nux::View); + + Tracks(dash::Tracks::Ptr tracks, NUX_FILE_LINE_PROTO); + virtual ~Tracks(); + + // From debug::Introspectable + std::string GetName() const; + void AddProperties(GVariantBuilder* builder); + + sigc::signal<void, std::string const&> play; + sigc::signal<void, std::string const&> pause; + +protected: + virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw); + virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw); + + void SetupViews(); + + void OnTrackUpdated(dash::Track const& track); + void OnTrackAdded(dash::Track const& track); + void OnTrackRemoved(dash::Track const&track); + + void onPlayTrack(std::string const& uri); + void onPauseTrack(std::string const& uri); + +protected: + dash::Tracks::Ptr tracks_; + + TrackLayout* layout_; + std::map<std::string, previews::Track::Ptr> m_tracks; + int track_count_; +}; + +} +} +} + +#endif // TRACKS_H diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 272bd3d25..cd4df5f15 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -31,8 +31,8 @@ include_directories (. .. ../services ../UnityCore ${UNITY_SRC} ${CMAKE_BINARY_D set (UNITY_SHARED_SOURCES AbstractSeparator.cpp Animator.cpp - ApplicationScreenshot.cpp BGHash.cpp + CoverArt.cpp BackgroundEffectHelper.cpp DashStyle.cpp FontSettings.cpp diff --git a/unity-shared/ApplicationScreenshot.cpp b/unity-shared/CoverArt.cpp index 67ed0bac3..0a9ac6419 100644 --- a/unity-shared/ApplicationScreenshot.cpp +++ b/unity-shared/CoverArt.cpp @@ -17,10 +17,11 @@ * <http://www.gnu.org/licenses/> * * Authored by: Andrea Cimitan <andrea.cimitan@canonical.com> + * Nick Dedekind <nick.dedekind@canonical.com> * */ -#include "ApplicationScreenshot.h" +#include "CoverArt.h" #include "unity-shared/IntrospectableWrappers.h" #include <NuxCore/Logger.h> #include <Nux/VLayout.h> @@ -34,25 +35,25 @@ namespace previews namespace { -nux::logging::Logger logger("unity.dash.previews.applicationscreenshot"); +nux::logging::Logger logger("unity.dash.previews.coverart"); } -NUX_IMPLEMENT_OBJECT_TYPE(ApplicationScreenshot); +NUX_IMPLEMENT_OBJECT_TYPE(CoverArt); -ApplicationScreenshot::ApplicationScreenshot() +CoverArt::CoverArt() : View(NUX_TRACKER_LOCATION) , overlay_text_(nullptr) { SetupViews(); } -ApplicationScreenshot::~ApplicationScreenshot() +CoverArt::~CoverArt() { if (overlay_text_) overlay_text_->UnReference(); } -void ApplicationScreenshot::SetImage(std::string const& image_hint) +void CoverArt::SetImage(std::string const& image_hint) { if (overlay_text_ && GetLayout()) GetLayout()->RemoveChildObject(overlay_text_); @@ -66,7 +67,7 @@ void ApplicationScreenshot::SetImage(std::string const& image_hint) QueueDraw(); } -void ApplicationScreenshot::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) +void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { nux::Geometry const& base = GetGeometry(); @@ -140,7 +141,7 @@ void ApplicationScreenshot::Draw(nux::GraphicsEngine& gfx_engine, bool force_dra gfx_engine.PopClippingRectangle(); } -void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) +void CoverArt::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw) { nux::Geometry const& base = GetGeometry(); gfx_engine.PushClippingRectangle(base); @@ -151,12 +152,12 @@ void ApplicationScreenshot::DrawContent(nux::GraphicsEngine& gfx_engine, bool fo gfx_engine.PopClippingRectangle(); } -std::string ApplicationScreenshot::GetName() const +std::string CoverArt::GetName() const { - return "ApplicationScreenshot"; + return "CoverArt"; } -void ApplicationScreenshot::SetupViews() +void CoverArt::SetupViews() { nux::VLayout* layout = new nux::VLayout(); layout->AddSpace(0, 1); @@ -171,7 +172,7 @@ void ApplicationScreenshot::SetupViews() overlay_text_->SetText("No Image Available"); } -void ApplicationScreenshot::SetFont(std::string const& font) +void CoverArt::SetFont(std::string const& font) { overlay_text_->SetFont(font); } diff --git a/unity-shared/ApplicationScreenshot.h b/unity-shared/CoverArt.h index 122a30c99..dad9969ae 100644 --- a/unity-shared/ApplicationScreenshot.h +++ b/unity-shared/CoverArt.h @@ -17,11 +17,12 @@ * <http://www.gnu.org/licenses/> * * Authored by: Andrea Cimitan <andrea.cimitan@canonical.com> + * Nick Dedekind <nick.dedekind@canonical.com> * */ -#ifndef APPLICATIONSCREENSHOT_H -#define APPLICATIONSCREENSHOT_H +#ifndef COVERART_H +#define COVERART_H #include <Nux/Nux.h> #include <Nux/View.h> @@ -36,14 +37,14 @@ namespace dash namespace previews { -class ApplicationScreenshot : public nux::View +class CoverArt : public nux::View { public: - typedef nux::ObjectPtr<ApplicationScreenshot> Ptr; - NUX_DECLARE_OBJECT_TYPE(ApplicationScreenshot, nux::View); + typedef nux::ObjectPtr<CoverArt> Ptr; + NUX_DECLARE_OBJECT_TYPE(CoverArt, nux::View); - ApplicationScreenshot(); - virtual ~ApplicationScreenshot(); + CoverArt(); + virtual ~CoverArt(); void SetImage(std::string const& image_hint); diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index d9c28394a..934fe8752 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -19,9 +19,14 @@ * Authored by: Nick Dedekind <nick.dedekind@canonical.com> * */ + #include "PreviewStyle.h" #include <NuxCore/Logger.h> +#include <NuxGraphics/GLTextureResourceManager.h> +#include <UnityCore/GLibWrapper.h> +#include "config.h" + namespace unity { namespace dash @@ -34,9 +39,48 @@ Style* style_instance = nullptr; nux::logging::Logger logger("unity.dash.previews.style"); +typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; + +class LazyLoadTexture +{ +public: + LazyLoadTexture(std::string const& filename, int size = -1); + nux::BaseTexture* texture(); +private: + void LoadTexture(); +private: + std::string filename_; + int size_; + BaseTexturePtr texture_; +}; + } // namespace + +class Style::Impl +{ +public: + Impl(Style* owner) + : owner_(owner) + , preview_nav_left_texture_("/prev.svg") + , preview_nav_right_texture_("/next.svg") + , preview_play_texture_("/play.svg") + , preview_pause_texture_("/pause.svg") + { + } + ~Impl() {} + + Style* owner_; + + LazyLoadTexture preview_nav_left_texture_; + LazyLoadTexture preview_nav_right_texture_; + LazyLoadTexture preview_play_texture_; + LazyLoadTexture preview_pause_texture_; +}; + + Style::Style() +: pimpl(new Impl(this)) { if (style_instance) { @@ -64,23 +108,23 @@ Style& Style::Instance() return *style_instance; } -int Style::NavigatorMinimumWidth() const +int Style::GetNavigatorWidth() const { return 42; } -int Style::NavigatorMaximumWidth() const +int Style::GetImageWidth() const { - return 42; + return 400; } -std::string Style::app_name_font() const +std::string Style::title_font() const { - return "Ubuntu 20"; + return "Ubuntu 22"; } -std::string Style::version_size_font() const +std::string Style::subtitle_size_font() const { - return "Ubuntu 12"; + return "Ubuntu 12.5"; } std::string Style::app_license_font() const { @@ -112,6 +156,69 @@ std::string Style::no_preview_image_font() const return "Ubuntu Light 16"; } +std::string Style::track_font() const +{ + return "Ubuntu Light 10"; +} + + + +nux::BaseTexture* Style::GetNavLeftIcon() +{ + return pimpl->preview_nav_left_texture_.texture(); } + +nux::BaseTexture* Style::GetNavRightIcon() +{ + return pimpl->preview_nav_right_texture_.texture(); } + +nux::BaseTexture* Style::GetPlayIcon() +{ + return pimpl->preview_play_texture_.texture(); } + +nux::BaseTexture* Style::GetPauseIcon() +{ + return pimpl->preview_pause_texture_.texture(); +} + + + +namespace +{ +LazyLoadTexture::LazyLoadTexture(std::string const& filename, int size) + : filename_(filename) + , size_(size) +{ +} + +nux::BaseTexture* LazyLoadTexture::texture() +{ + if (!texture_) + LoadTexture(); + return texture_.GetPointer(); +} + +void LazyLoadTexture::LoadTexture() +{ + std::string full_path = PKGDATADIR + filename_; + glib::Object<GdkPixbuf> pixbuf; + glib::Error error; + + pixbuf = ::gdk_pixbuf_new_from_file_at_size(full_path.c_str(), size_, size_, &error); + if (error) + { + LOG_WARN(logger) << "Unable to texture " << full_path << ": " << error; + } + else + { + texture_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); + } +} + +} // namesspace + +} // namespace previews +} // namespace dash +} // namespace unity diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index 75132f709..0570ece7f 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -23,7 +23,16 @@ #ifndef PREVIEWSTYLE_H #define PREVIEWSTYLE_H - #include <string> +#include <Nux/Nux.h> +#include <Nux/View.h> + +#include <string> +#include <memory> + +namespace nux +{ + class BaseTexture; +} namespace unity { @@ -47,13 +56,15 @@ public: static Style& Instance(); - int NavigatorMinimumWidth() const; - int NavigatorMaximumWidth() const; + int GetNavigatorWidth() const; + int GetImageWidth() const; + + + std::string title_font() const; + std::string subtitle_size_font() const; //////////////////////////////// // Application Preview - std::string app_name_font() const; - std::string version_size_font() const; std::string app_license_font() const; std::string app_last_update_font() const; std::string app_copywrite_font() const; @@ -62,8 +73,21 @@ public: std::string user_rating_font() const; std::string no_preview_image_font() const; //////////////////////////////// + + //////////////////////////////// + // Music Preview + std::string track_font() const; + //////////////////////////////// + + + nux::BaseTexture* GetNavLeftIcon(); + nux::BaseTexture* GetNavRightIcon(); + nux::BaseTexture* GetPlayIcon(); + nux::BaseTexture* GetPauseIcon(); protected: + class Impl; + std::unique_ptr<Impl> pimpl; }; |
