Merge lp:~mandel/unity/error-preview into lp:~unity-team/unity/libunity-7.0-breakage

Proposed by Manuel de la Peña
Status: Merged
Merged at revision: 3091
Proposed branch: lp:~mandel/unity/error-preview
Merge into: lp:~unity-team/unity/libunity-7.0-breakage
Prerequisite: lp:~mandel/unity/generic-payment-preview
Diff against target: 924 lines (+742/-11)
12 files modified
UnityCore/PaymentPreview.cpp (+17/-3)
UnityCore/PaymentPreview.h (+3/-0)
UnityCore/Preview.cpp (+0/-1)
UnityCore/Preview.h (+1/-1)
dash/previews/CMakeLists.txt (+13/-5)
dash/previews/ErrorPreview.cpp (+246/-0)
dash/previews/ErrorPreview.h (+119/-0)
dash/previews/PaymentPreview.cpp (+1/-0)
dash/previews/Preview.cpp (+11/-1)
dash/previews/StandaloneErrorPreview.cpp (+219/-0)
tests/CMakeLists.txt (+1/-0)
tests/test_error_preview.cpp (+111/-0)
To merge this branch: bzr merge lp:~mandel/unity/error-preview
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Nick Dedekind (community) Approve
Review via email: mp+154640@code.launchpad.net

Commit message

Adds an error preview that can be used by scopes to show errors that occur during the purchase.

Description of the change

Adds an error preview that can be used by scopes to show errors that occur during the purchase.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/PaymentPreview.cpp'
--- UnityCore/PaymentPreview.cpp 2013-03-21 16:35:40 +0000
+++ UnityCore/PaymentPreview.cpp 2013-03-21 16:35:46 +0000
@@ -41,6 +41,7 @@
41 std::string get_payment_method() const { return payment_method_; };41 std::string get_payment_method() const { return payment_method_; };
42 std::string get_purchase_prize() const { return purchase_prize_; };42 std::string get_purchase_prize() const { return purchase_prize_; };
43 std::string get_purchase_type() const { return purchase_type_; };43 std::string get_purchase_type() const { return purchase_type_; };
44 PreviewType get_preview_type() const { return preview_type_; };
4445
45 // getters for the lables46 // getters for the lables
4647
@@ -52,6 +53,7 @@
52 std::string payment_method_;53 std::string payment_method_;
53 std::string purchase_prize_;54 std::string purchase_prize_;
54 std::string purchase_type_;55 std::string purchase_type_;
56 PaymentPreview::PreviewType preview_type_;
5557
56};58};
5759
@@ -73,7 +75,19 @@
73 if (s) purchase_prize_ = s;75 if (s) purchase_prize_ = s;
74 s = unity_protocol_payment_preview_get_purchase_type(preview);76 s = unity_protocol_payment_preview_get_purchase_type(preview);
75 if (s) purchase_type_ = s;77 if (s) purchase_type_ = s;
7678 UnityProtocolPreviewPaymentType t = unity_protocol_payment_preview_get_preview_type(preview);
79 switch(t)
80 {
81 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_APPLICATION:
82 preview_type_ = PaymentPreview::APPLICATION;
83 break;
84 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC:
85 preview_type_ = PaymentPreview::MUSIC;
86 break;
87 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR:
88 preview_type_ = PaymentPreview::ERROR;
89 break;
90 }
77 SetupGetters();91 SetupGetters();
78}92}
7993
@@ -87,8 +101,8 @@
87 sigc::mem_fun(this, &PaymentPreview::Impl::get_payment_method));101 sigc::mem_fun(this, &PaymentPreview::Impl::get_payment_method));
88 owner_->purchase_prize.SetGetterFunction(102 owner_->purchase_prize.SetGetterFunction(
89 sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_prize));103 sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_prize));
90 owner_->purchase_type.SetGetterFunction(104 owner_->preview_type.SetGetterFunction(
91 sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_type));105 sigc::mem_fun(this, &PaymentPreview::Impl::get_preview_type));
92}106}
93107
94PaymentPreview::PaymentPreview(unity::glib::Object<GObject> const& proto_obj)108PaymentPreview::PaymentPreview(unity::glib::Object<GObject> const& proto_obj)
95109
=== modified file 'UnityCore/PaymentPreview.h'
--- UnityCore/PaymentPreview.h 2013-03-21 16:35:40 +0000
+++ UnityCore/PaymentPreview.h 2013-03-21 16:35:46 +0000
@@ -34,6 +34,8 @@
34class PaymentPreview : public Preview34class PaymentPreview : public Preview
35{35{
36public:36public:
37 enum PreviewType { APPLICATION, MUSIC, ERROR };
38
37 typedef std::shared_ptr<PaymentPreview> Ptr;39 typedef std::shared_ptr<PaymentPreview> Ptr;
3840
39 PaymentPreview(unity::glib::Object<GObject> const& proto_obj);41 PaymentPreview(unity::glib::Object<GObject> const& proto_obj);
@@ -47,6 +49,7 @@
47 nux::RWProperty<std::string> payment_method;49 nux::RWProperty<std::string> payment_method;
48 nux::RWProperty<std::string> purchase_prize;50 nux::RWProperty<std::string> purchase_prize;
49 nux::RWProperty<std::string> purchase_type;51 nux::RWProperty<std::string> purchase_type;
52 nux::RWProperty<PaymentPreview::PreviewType> preview_type;
5053
51private:54private:
52 class Impl;55 class Impl;
5356
=== modified file 'UnityCore/Preview.cpp'
--- UnityCore/Preview.cpp 2013-03-21 16:35:40 +0000
+++ UnityCore/Preview.cpp 2013-03-21 16:35:46 +0000
@@ -32,7 +32,6 @@
32#include "PaymentPreview.h"32#include "PaymentPreview.h"
33#include "SocialPreview.h"33#include "SocialPreview.h"
3434
35
36namespace unity35namespace unity
37{36{
38namespace dash37namespace dash
3938
=== modified file 'UnityCore/Preview.h'
--- UnityCore/Preview.h 2013-02-27 18:04:26 +0000
+++ UnityCore/Preview.h 2013-03-21 16:35:46 +0000
@@ -95,7 +95,7 @@
95 unity::glib::Variant value;95 unity::glib::Variant value;
9696
97 InfoHint() {};97 InfoHint() {};
98 InfoHint(const gchar* id_, const gchar* display_name_, 98 InfoHint(const gchar* id_, const gchar* display_name_,
99 const gchar* icon_hint_, GVariant* value_)99 const gchar* icon_hint_, GVariant* value_)
100 : id(id_ != NULL ? id_ : "")100 : id(id_ != NULL ? id_ : "")
101 , display_name(display_name_ != NULL ? display_name_ : "")101 , display_name(display_name_ != NULL ? display_name_ : "")
102102
=== modified file 'dash/previews/CMakeLists.txt'
--- dash/previews/CMakeLists.txt 2013-03-21 16:35:40 +0000
+++ dash/previews/CMakeLists.txt 2013-03-21 16:35:46 +0000
@@ -36,6 +36,7 @@
36 Track.cpp36 Track.cpp
37 Tracks.cpp37 Tracks.cpp
38 MusicPaymentPreview.cpp38 MusicPaymentPreview.cpp
39 ErrorPreview.cpp
39 )40 )
4041
41add_library (previews-lib STATIC ${PREVIEWS_SOURCES})42add_library (previews-lib STATIC ${PREVIEWS_SOURCES})
@@ -43,33 +44,40 @@
43target_link_libraries (previews-lib unity-shared)44target_link_libraries (previews-lib unity-shared)
44add_pch(pch/previews_pch.hh previews-lib)45add_pch(pch/previews_pch.hh previews-lib)
4546
46# 47#
47# Application Standalone variant48# Application Standalone variant
48#49#
49add_executable (app_previews StandaloneApplicationPreview.cpp)50add_executable (app_previews StandaloneApplicationPreview.cpp)
50target_link_libraries (app_previews previews-lib unity-shared)51target_link_libraries (app_previews previews-lib unity-shared)
5152
52# 53#
53# Music Standalone variant54# Music Standalone variant
54#55#
55add_executable (music_previews StandaloneMusicPreview.cpp)56add_executable (music_previews StandaloneMusicPreview.cpp)
56target_link_libraries (music_previews previews-lib unity-shared)57target_link_libraries (music_previews previews-lib unity-shared)
5758
58# 59#
59# Social Standalone variant60# Social Standalone variant
60#61#
61add_executable (social_previews StandaloneSocialPreview.cpp)62add_executable (social_previews StandaloneSocialPreview.cpp)
62target_link_libraries (social_previews previews-lib unity-shared)63target_link_libraries (social_previews previews-lib unity-shared)
6364
64# 65#
65# Movie Standalone variant66# Movie Standalone variant
66#67#
67add_executable (movie_previews StandaloneMoviePreview.cpp)68add_executable (movie_previews StandaloneMoviePreview.cpp)
68target_link_libraries (movie_previews previews-lib unity-shared)69target_link_libraries (movie_previews previews-lib unity-shared)
6970
70# 71#
71# Payment Standalone variant72# Payment Standalone variant
72#73#
73add_executable (payment_previews StandaloneMusicPaymentPreview.cpp)74add_executable (payment_previews StandaloneMusicPaymentPreview.cpp)
74add_dependencies (payment_previews previews-lib)75add_dependencies (payment_previews previews-lib)
75target_link_libraries (payment_previews previews-lib unity-shared)76target_link_libraries (payment_previews previews-lib unity-shared)
77
78#
79# Error Standalone variant
80#
81add_executable (error_previews StandaloneErrorPreview.cpp)
82add_dependencies (error_previews previews-lib)
83target_link_libraries (error_previews previews-lib unity-shared)
7684
=== added file 'dash/previews/ErrorPreview.cpp'
--- dash/previews/ErrorPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/ErrorPreview.cpp 2013-03-21 16:35:46 +0000
@@ -0,0 +1,246 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23
24#include "unity-shared/IntrospectableWrappers.h"
25#include "unity-shared/PreviewStyle.h"
26#include "unity-shared/CoverArt.h"
27#include "unity-shared/StaticCairoText.h"
28#include "unity-shared/PlacesVScrollBar.h"
29#include <NuxCore/Logger.h>
30#include <Nux/VLayout.h>
31#include <Nux/HLayout.h>
32#include <Nux/GridHLayout.h>
33#include <Nux/AbstractButton.h>
34
35#include "ErrorPreview.h"
36#include "PreviewInfoHintWidget.h"
37
38#include "stdio.h"
39#include "config.h"
40
41namespace unity
42{
43namespace dash
44{
45namespace previews
46{
47
48namespace
49{
50nux::logging::Logger logger("unity.dash.previews.ErrorPreview");
51
52}
53
54class DetailsScrollView : public nux::ScrollView
55{
56public:
57 DetailsScrollView(NUX_FILE_LINE_PROTO)
58 : ScrollView(NUX_FILE_LINE_PARAM)
59 {
60 SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
61 }
62
63};
64
65NUX_IMPLEMENT_OBJECT_TYPE(ErrorPreview)
66
67ErrorPreview::ErrorPreview(dash::Preview::Ptr preview_model)
68: PaymentPreview(preview_model)
69{
70 PaymentPreview::SetupBackground();
71 SetupViews();
72}
73
74ErrorPreview::~ErrorPreview()
75{
76}
77
78nux::Area* ErrorPreview::FindKeyFocusArea(unsigned int key_symbol,
79 unsigned long x11_key_code,
80 unsigned long special_keys_state)
81{
82 return Preview::FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
83}
84
85std::string ErrorPreview::GetName() const
86{
87 return "ErrorPreview";
88}
89
90void ErrorPreview::OnActionActivated(ActionButton* button, std::string const& id)
91{
92}
93
94void ErrorPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
95{
96 if (preview_model_)
97 preview_model_->PerformAction(id);
98}
99
100void ErrorPreview::LoadActions()
101{
102 // Loop over the buttons and add them to the correct var
103 // this is not efficient but is the only way we have atm
104 for (dash::Preview::ActionPtr action : preview_model_->GetActions())
105 {
106 const char *action_id = action->id.c_str();
107 if(strcmp(OPEN_U1_LINK_ACTION, action_id) == 0)
108 {
109 nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
110 link->activate.connect(sigc::mem_fun(this,
111 &ErrorPreview::OnActionLinkActivated));
112
113 std::pair<std::string, nux::ObjectPtr<nux::AbstractButton>> data (action->id, link);
114 sorted_buttons_.insert(data);
115 }
116 LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
117 }
118}
119
120nux::Layout* ErrorPreview::GetTitle()
121{
122 previews::Style& style = dash::previews::Style::Instance();
123 nux::VLayout* title_data_layout = new nux::VLayout();
124 title_data_layout->SetMaximumHeight(76);
125 title_data_layout->SetSpaceBetweenChildren(10);
126
127 title_ = new StaticCairoText(
128 preview_model_->title.Get(), true,
129 NUX_TRACKER_LOCATION);
130
131 title_->SetFont(style.payment_title_font().c_str());
132 title_->SetLines(-1);
133 title_->SetFont(style.title_font().c_str());
134 title_data_layout->AddView(title_.GetPointer(), 1);
135
136 subtitle_ = new StaticCairoText(
137 preview_model_->subtitle.Get(), true,
138 NUX_TRACKER_LOCATION);
139 subtitle_->SetLines(-1);
140 subtitle_->SetFont(style.payment_subtitle_font().c_str());
141 title_data_layout->AddView(subtitle_.GetPointer(), 1);
142 title_data_layout->AddSpace(1, 1);
143 return title_data_layout;
144}
145
146nux::Layout* ErrorPreview::GetPrice()
147{
148 previews::Style& style = dash::previews::Style::Instance();
149 nux::VLayout *prize_data_layout = new nux::VLayout();
150 prize_data_layout->SetMaximumHeight(76);
151 prize_data_layout->SetSpaceBetweenChildren(5);
152
153 purchase_prize_ = new StaticCairoText(
154 error_preview_model_->purchase_prize.Get(), true,
155 NUX_TRACKER_LOCATION);
156 purchase_prize_->SetLines(-1);
157 purchase_prize_->SetFont(style.payment_prize_title_font().c_str());
158 prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
159 nux::MINOR_POSITION_END);
160
161 purchase_hint_ = new StaticCairoText(
162 _("Ubuntu One best offer"),
163 true, NUX_TRACKER_LOCATION);
164 purchase_hint_->SetLines(-1);
165 purchase_hint_->SetFont(style.payment_prize_subtitle_font().c_str());
166 prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
167 nux::MINOR_POSITION_END);
168
169 purchase_type_ = new StaticCairoText(
170 error_preview_model_->purchase_type.Get(), true,
171 NUX_TRACKER_LOCATION);
172 purchase_type_->SetLines(-1);
173 purchase_type_->SetFont(style.payment_prize_subtitle_font().c_str());
174 prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
175 nux::MINOR_POSITION_END);
176 return prize_data_layout;
177}
178
179nux::Layout* ErrorPreview::GetBody()
180{
181 previews::Style& style = dash::previews::Style::Instance();
182 nux::HLayout *body_layout = new nux::HLayout();
183
184 lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
185 style.GetPaymentLockHeight());
186
187 intro_ = new StaticCairoText(
188 error_preview_model_->header.Get(), true,
189 NUX_TRACKER_LOCATION);
190 intro_->SetMaximumWidth(style.GetPaymentHeaderWidth());
191 intro_->SetFont(style.payment_intro_font().c_str());
192 intro_->SetLineSpacing(10);
193 intro_->SetLines(-style.GetDescriptionLineCount());
194 intro_->SetMinimumHeight(50);
195 body_layout->AddView(sorted_buttons_[OPEN_U1_LINK_ACTION].GetPointer(),
196 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
197 nux::NUX_LAYOUT_END);
198 body_layout->AddView(lock_texture_, 0, nux::MINOR_POSITION_CENTER,
199 nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
200 body_layout->AddView(intro_.GetPointer(), 1);
201 return body_layout;
202}
203
204nux::Layout* ErrorPreview::GetFooter()
205{
206 nux::HLayout* buttons_data_layout = new nux::HLayout();
207 return buttons_data_layout;
208}
209
210void ErrorPreview::PreLayoutManagement()
211{
212 nux::Geometry geo = GetGeometry();
213 GetLayout()->SetGeometry(geo);
214
215 previews::Style& style = dash::previews::Style::Instance();
216
217 int width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
218
219 if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
220 if(header_layout_) { header_layout_->SetMaximumWidth(width); }
221 if(intro_) { intro_->SetMaximumWidth(width); }
222 if(form_layout_) { form_layout_->SetMaximumWidth(width); }
223 if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
224
225 Preview::PreLayoutManagement();
226}
227
228void ErrorPreview::SetupViews()
229{
230 error_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
231 if (!error_preview_model_)
232 {
233 LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
234 return;
235 }
236
237 // load the buttons so that they can be accessed in order
238 LoadActions();
239
240 PaymentPreview::SetupViews();
241}
242
243
244}
245}
246}
0247
=== added file 'dash/previews/ErrorPreview.h'
--- dash/previews/ErrorPreview.h 1970-01-01 00:00:00 +0000
+++ dash/previews/ErrorPreview.h 2013-03-21 16:35:46 +0000
@@ -0,0 +1,119 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23
24#ifndef ERROR_PREVIEW_H
25#define ERROR_PREVIEW_H
26
27// key used to find the correct info hint
28#define ERROR_INFOHINT_ID "error_preview"
29
30// keys of the data preview
31// Necessary??
32#define DATA_MESSAGE_KEY "message"
33
34// ations ids
35#define OPEN_U1_LINK_ACTION "open_u1_link"
36
37#include <Nux/Nux.h>
38#include <Nux/AbstractButton.h>
39#include <UnityCore/Lens.h>
40#include "ActionButton.h"
41#include "ActionLink.h"
42#include "PaymentPreview.h"
43#include "unity-shared/IconTexture.h"
44#include "unity-shared/TextInput.h"
45
46namespace nux
47{
48class AbstractPaintLayer;
49class StaticCairoText;
50class VLayout;
51}
52
53namespace unity
54{
55namespace dash
56{
57namespace previews
58{
59class CoverArt;
60class PreviewInfoHintWidget;
61
62class ErrorPreview : public PaymentPreview
63{
64public:
65 typedef nux::ObjectPtr<ErrorPreview> Ptr;
66 NUX_DECLARE_OBJECT_TYPE(ErrorPreview, Preview)
67
68 ErrorPreview(dash::Preview::Ptr preview_model);
69 ~ErrorPreview();
70
71 nux::Area* FindKeyFocusArea(unsigned int key_symbol,
72 unsigned long x11_key_code,
73 unsigned long special_keys_state);
74 // From debug::Introspectable
75 std::string GetName() const;
76 nux::Layout* GetTitle();
77 nux::Layout* GetPrice();
78 nux::Layout* GetBody();
79 nux::Layout* GetFooter();
80
81private:
82 void LoadActions();
83
84protected:
85 void OnActionActivated(ActionButton* button, std::string const& id);
86 void OnActionLinkActivated(ActionLink* link, std::string const& id);
87
88 void PreLayoutManagement();
89
90 virtual void SetupViews();
91 // content elements
92 nux::ObjectPtr<CoverArt> image_;
93 nux::ObjectPtr<StaticCairoText> intro_;
94 nux::ObjectPtr<StaticCairoText> title_;
95 nux::ObjectPtr<StaticCairoText> subtitle_;
96 nux::ObjectPtr<StaticCairoText> purchase_hint_;
97 nux::ObjectPtr<StaticCairoText> purchase_prize_;
98 nux::ObjectPtr<StaticCairoText> purchase_type_;
99 nux::ObjectPtr<nux::HLayout> form_layout_;
100
101 dash::PaymentPreview* error_preview_model_;
102 // do we want to type?
103 bool entry_selected_;
104
105 // actions
106 std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> sorted_buttons_;
107
108 // lock texture
109 IconTexture* lock_texture_;
110
111 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
112 LayerPtr details_bg_layer_;
113};
114
115}
116}
117}
118
119#endif // ERROR_PREVIEW_H
0120
=== modified file 'dash/previews/PaymentPreview.cpp'
--- dash/previews/PaymentPreview.cpp 2013-03-21 16:35:40 +0000
+++ dash/previews/PaymentPreview.cpp 2013-03-21 16:35:46 +0000
@@ -36,6 +36,7 @@
3636
37namespace37namespace
38{38{
39
39nux::logging::Logger logger("unity.dash.previews.payment.preview");40nux::logging::Logger logger("unity.dash.previews.payment.preview");
4041
41}42}
4243
=== modified file 'dash/previews/Preview.cpp'
--- dash/previews/Preview.cpp 2013-03-21 16:35:40 +0000
+++ dash/previews/Preview.cpp 2013-03-21 16:35:46 +0000
@@ -32,6 +32,7 @@
3232
33#include "GenericPreview.h"33#include "GenericPreview.h"
34#include "ApplicationPreview.h"34#include "ApplicationPreview.h"
35#include "ErrorPreview.h"
35#include "MusicPreview.h"36#include "MusicPreview.h"
36#include "MoviePreview.h"37#include "MoviePreview.h"
37#include "MusicPaymentPreview.h"38#include "MusicPaymentPreview.h"
@@ -60,7 +61,16 @@
60 }61 }
61 else if (model->renderer_name == "preview-payment")62 else if (model->renderer_name == "preview-payment")
62 {63 {
63 return Preview::Ptr(new MusicPaymentPreview(model));64 dash::PaymentPreview* payment_preview_model = dynamic_cast<dash::PaymentPreview*>(
65 model.get());
66 if (payment_preview_model->preview_type.Get() == dash::PaymentPreview::MUSIC)
67 {
68 return Preview::Ptr(new MusicPaymentPreview(model));
69 }
70 else
71 {
72 return Preview::Ptr(new ErrorPreview(model));
73 }
64 }74 }
65 else if (model->renderer_name == "preview-application")75 else if (model->renderer_name == "preview-application")
66 {76 {
6777
=== added file 'dash/previews/StandaloneErrorPreview.cpp'
--- dash/previews/StandaloneErrorPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/StandaloneErrorPreview.cpp 2013-03-21 16:35:46 +0000
@@ -0,0 +1,219 @@
1/*
2 * Copyright 2012-2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 *
19 */
20
21#include <gtk/gtk.h>
22
23#include "Nux/Nux.h"
24#include "Nux/VLayout.h"
25#include "Nux/WindowThread.h"
26#include "NuxGraphics/GraphicsEngine.h"
27#include <Nux/Layout.h>
28#include <NuxCore/Logger.h>
29#include <UnityCore/Variant.h>
30#include <UnityCore/Preview.h>
31#include <unity-protocol.h>
32
33#include "unity-shared/FontSettings.h"
34#include "unity-shared/UnitySettings.h"
35#include "unity-shared/PreviewStyle.h"
36#include "unity-shared/DashStyle.h"
37#include "unity-shared/ThumbnailGenerator.h"
38
39#include "Preview.h"
40#include "PreviewContainer.h"
41
42
43#define WIDTH 1100
44#define HEIGHT 600
45
46using namespace unity;
47using namespace unity::dash;
48
49namespace
50{
51nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
52}
53
54class DummyView : public nux::View
55{
56public:
57 DummyView(nux::View* view)
58 : View(NUX_TRACKER_LOCATION)
59 {
60 SetAcceptKeyNavFocusOnMouseDown(false);
61 SetAcceptKeyNavFocusOnMouseEnter(false);
62
63 nux::ROPConfig rop;
64 rop.Blend = true;
65 rop.SrcBlend = GL_ONE;
66 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
67 bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
68
69 nux::Layout* layout = new nux::VLayout();
70 layout->SetPadding(10);
71 layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
72 SetLayout(layout);
73 }
74
75 // Keyboard navigation
76 bool AcceptKeyNavFocus()
77 {
78 return false;
79 }
80
81protected:
82 virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
83 {
84 nux::Geometry const& base = GetGeometry();
85
86 gfx_engine.PushClippingRectangle(base);
87 nux::GetPainter().PaintBackground(gfx_engine, base);
88
89 unsigned int alpha, src, dest = 0;
90 gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
91 gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
92
93 bg_layer_->SetGeometry(GetGeometry());
94 nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
95
96 gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
97
98 gfx_engine.PopClippingRectangle();
99 }
100
101 virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
102 {
103 nux::Geometry const& base = GetGeometry();
104 gfx_engine.PushClippingRectangle(base);
105
106 if (!IsFullRedraw())
107 nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
108
109 if (GetCompositionLayout())
110 GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
111
112 if (!IsFullRedraw())
113 nux::GetPainter().PopBackground();
114
115 gfx_engine.PopClippingRectangle();
116 }
117
118 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
119 LayerPtr bg_layer_;
120};
121
122class TestRunner
123{
124public:
125 TestRunner ();
126 ~TestRunner ();
127
128 static void InitWindowThread (nux::NThread* thread, void* InitData);
129 void Init ();
130
131 previews::PreviewContainer::Ptr container_;
132 nux::Layout *layout_;
133 unsigned int nav_iter;
134 previews::Navigation nav_direction_;
135 std::string search_string_;
136 bool first_;
137};
138
139TestRunner::TestRunner ()
140{
141}
142
143TestRunner::~TestRunner ()
144{
145}
146
147void TestRunner::Init ()
148{
149 container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
150 container_->request_close.connect([&]() { exit(0); });
151 container_->DisableNavButton(previews::Navigation::BOTH);
152
153 DummyView* dummyView = new DummyView(container_.GetPointer());
154 layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
155 layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
156 nux::GetWindowThread()->SetLayout (layout_);
157
158 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
159 unity_protocol_payment_preview_new()));
160
161 unity_protocol_preview_set_title(
162 proto_obj, "This Modern Glitch");
163 unity_protocol_preview_set_subtitle(
164 proto_obj, "The Wombats");
165 unity_protocol_payment_preview_set_header(
166 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
167 "A horrible error ocurred!!!");
168 unity_protocol_payment_preview_set_purchase_prize(
169 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
170 "10 eur");
171 unity_protocol_payment_preview_set_purchase_type(
172 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
173 "Digital CD");
174 unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
175 UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR);
176
177 // set the diff actions
178 unity_protocol_preview_add_action(proto_obj, "open_u1_link", "Go to u1 page", NULL, 0);
179
180 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
181 glib::StealRef());
182
183 dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
184 container_->Preview(preview_model, previews::Navigation::LEFT);
185}
186
187void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
188{
189 TestRunner *self = (TestRunner *) InitData;
190 self->Init ();
191}
192
193int main(int argc, char **argv)
194{
195 nux::WindowThread* wt = NULL;
196
197 gtk_init (&argc, &argv);
198
199 nux::NuxInitialize(0);
200 nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
201 // The instances for the pseudo-singletons.
202 unity::Settings settings;
203 unity::dash::previews::Style panel_style;
204 unity::dash::Style dash_style;
205 unity::ThumbnailGenerator thumbnail_generator;
206
207 TestRunner *test_runner = new TestRunner ();
208 wt = nux::CreateGUIThread(TEXT("Unity Preview"),
209 WIDTH, HEIGHT,
210 0,
211 &TestRunner::InitWindowThread,
212 test_runner);
213
214 wt->Run (NULL);
215 delete wt;
216 return 0;
217}
218
219
0220
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-03-21 16:35:40 +0000
+++ tests/CMakeLists.txt 2013-03-21 16:35:46 +0000
@@ -244,6 +244,7 @@
244 test_dash_controller.cpp244 test_dash_controller.cpp
245 test_desktop_launcher_icon.cpp245 test_desktop_launcher_icon.cpp
246 test_device_launcher_section.cpp246 test_device_launcher_section.cpp
247 test_error_preview.cpp
247 test_edge_barrier_controller.cpp248 test_edge_barrier_controller.cpp
248 test_expo_launcher_icon.cpp249 test_expo_launcher_icon.cpp
249 test_filter_widgets.cpp250 test_filter_widgets.cpp
250251
=== added file 'tests/test_error_preview.cpp'
--- tests/test_error_preview.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_error_preview.cpp 2013-03-21 16:35:46 +0000
@@ -0,0 +1,111 @@
1/*
2 * Copyright 2012-2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19 *
20 */
21#include <list>
22#include <gmock/gmock.h>
23using namespace testing;
24
25#include <Nux/Nux.h>
26#include <Nux/BaseWindow.h>
27#include <unity-shared/StaticCairoText.h>
28#include <unity-shared/DashStyle.h>
29#include <unity-shared/PreviewStyle.h>
30#include <unity-shared/ThumbnailGenerator.h>
31#include "unity-shared/UnitySettings.h"
32
33#include <unity-protocol.h>
34#include "dash/previews/ErrorPreview.h"
35#include "test_utils.h"
36
37namespace unity
38{
39
40namespace dash
41{
42
43namespace previews
44{
45
46class ErrorPreviewMock : public ErrorPreview
47{
48 public:
49 ErrorPreviewMock(dash::Preview::Ptr preview_model)
50 : ErrorPreview(preview_model){}
51 ~ErrorPreviewMock(){}
52
53 using ErrorPreview::intro_;
54 using ErrorPreview::title_;
55 using ErrorPreview::subtitle_;
56 using ErrorPreview::purchase_hint_;
57 using ErrorPreview::purchase_prize_;
58 using ErrorPreview::purchase_type_;
59};
60
61class TestErrorPreview : public Test
62{
63 protected:
64 TestErrorPreview() :
65 Test(),
66 parent_window_(new nux::BaseWindow("TestErrorPayment"))
67 {
68 title = "Turning Japanese";
69 subtitle = "The vapors";
70 header = "Hi test, you purchased in the past from Ubuntu One.";
71 purchase_prize = "65$";
72 purchase_type = "Mp3";
73 preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR;
74
75 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
76
77 unity_protocol_preview_set_title(proto_obj, title.c_str());
78 unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
79
80 unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
81 unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
82 unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
83 unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
84
85 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
86
87 preview_model = dash::Preview::PreviewForVariant(v);
88
89 }
90
91 nux::ObjectPtr<nux::BaseWindow> parent_window_;
92 dash::Preview::Ptr preview_model;
93
94 // testing data
95 std::string title;
96 std::string subtitle;
97 std::string header;
98 std::string purchase_prize;
99 std::string purchase_type;
100 UnityProtocolPreviewPaymentType preview_type;
101
102 // needed for styles
103 unity::Settings settings;
104 dash::Style dash_style;
105};
106
107} // previews
108
109} // dash
110
111} // unity

Subscribers

People subscribed via source and target branches