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

Proposed by Manuel de la Peña on 2013-03-19
Status: Merged
Approved by: Didier Roche on 2013-03-22
Approved revision: 2906
Merged at revision: 3091
Proposed branch: lp:~mandel/unity/generic-payment-preview
Merge into: lp:~unity-team/unity/libunity-7.0-breakage
Diff against target: 3064 lines (+2721/-22)
22 files modified
UnityCore/CMakeLists.txt (+2/-0)
UnityCore/PaymentPreview.cpp (+120/-0)
UnityCore/PaymentPreview.h (+62/-0)
UnityCore/Preview.cpp (+13/-7)
UnityCore/Preview.h (+1/-1)
dash/DashView.cpp (+11/-2)
dash/previews/CMakeLists.txt (+22/-5)
dash/previews/ErrorPreview.cpp (+246/-0)
dash/previews/ErrorPreview.h (+119/-0)
dash/previews/MusicPaymentPreview.cpp (+459/-0)
dash/previews/MusicPaymentPreview.h (+134/-0)
dash/previews/PaymentPreview.cpp (+368/-0)
dash/previews/PaymentPreview.h (+132/-0)
dash/previews/Preview.cpp (+18/-2)
dash/previews/StandaloneErrorPreview.cpp (+219/-0)
dash/previews/StandaloneMusicPaymentPreview.cpp (+223/-0)
tests/CMakeLists.txt (+3/-0)
tests/test_error_preview.cpp (+111/-0)
tests/test_previews_music_payment.cpp (+151/-0)
tests/test_previews_payment.cpp (+186/-0)
unity-shared/PreviewStyle.cpp (+91/-0)
unity-shared/PreviewStyle.h (+30/-5)
To merge this branch: bzr merge lp:~mandel/unity/generic-payment-preview
Reviewer Review Type Date Requested Status
Didier Roche Approve on 2013-03-22
PS Jenkins bot continuous-integration Approve on 2013-03-21
Nick Dedekind (community) 2013-03-19 Approve on 2013-03-21
Review via email: mp+154071@code.launchpad.net

Commit message

Adds implementations for the payment previews that are required for the new payment in the music scopes.

Description of the change

Adds implementations for the payment previews that are required for the new payment in the music scopes.

To post a comment you must log in.
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:2896
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mandel/unity/generic-payment-preview/+merge/154071/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-ci/6/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-raring-amd64-ci/6/console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-ci/6/rebuild

review: Needs Fixing (continuous-integration)
Nick Dedekind (nick-dedekind) wrote :
Download full text (4.0 KiB)

You have some text conflicts in dash/DashView.cpp & UnityCore/Preview.cpp

27 + * Copyright (C) 2011-2012 Canonical Ltd

41 + * Authored by: Neil Jagdish Patel <email address hidden>
42 + * Michal Hruby <email address hidden>

Please update all headers to include 2013 and your contact details

277 {
278 +
279 if (!preview_displaying_)

extra line.

407 +const std::string MusicPaymentPreview::DATA_INFOHINT_ID = "album_purchase_preview";
408 +const std::string MusicPaymentPreview::DATA_PASSWORD_KEY = "password";
409 +const std::string MusicPaymentPreview::CHANGE_PAYMENT_ACTION = "change_payment_method";
410 +const std::string MusicPaymentPreview::FORGOT_PASSWORD_ACTION = "forgot_password";
411 +const std::string MusicPaymentPreview::CANCEL_PURCHASE_ACTION = "cancel_purchase";
412 +const std::string MusicPaymentPreview::PURCHASE_ALBUM_ACTION = "purchase_album";

Is there a reason why these are scoped to MusicPaymentPreview class? Can you put them in global namespace?

936 + std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> sorted_buttons_;

What is sorted about a map ? ;)

701 + actions_layout->AddView(
702 + sorted_buttons_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer(),
703 + 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
704 + 100.0f, nux::NUX_LAYOUT_END);
705 + actions_layout->AddView(
706 + sorted_buttons_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer(),
707 + 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
708 + 100.0f, nux::NUX_LAYOUT_END);

728 + buttons_data_layout->AddView(sorted_buttons_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer(),
729 + 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
730 + nux::NUX_LAYOUT_END);
731 + buttons_data_layout->AddView(sorted_buttons_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer(),
732 + 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
733 + nux::NUX_LAYOUT_END);

should check if sorted_buttons_ contains the actions before adding them.

784 + dash::Preview::InfoHintPtrList hints = preview_model_->GetInfoHints();
785 + GVariant *preview_data = NULL;
786 + dash::Preview::InfoHintPtr data_info_hint_ = NULL;
787 + if (!hints.empty())
788 + {
789 + for (dash::Preview::InfoHintPtr info_hint : hints)
790 + {
791 + if (info_hint->id == MusicPaymentPreview::DATA_INFOHINT_ID)
792 + {
793 + preview_data = info_hint->value;
794 + }
795 + if (preview_data != NULL)
796 + {
797 + error_message_ = GetErrorMessage(preview_data);
798 + }
799 + }
800 + }

1. data_info_hint_ doesn't seem to be used.
2. Don't need to check if the hints are empty if you're iterating over them.
3. dash::Preview::InfoHintPtr const& info_hint. even though it's a pointer, you're still constructing the wrapper.
4. Not sure what this is doing, but i might be missing something. looping over the info hints. if it is a speicifc id, then set the preview data and get an error message; otherwise continue looping, but dont update the data, even though you are continuing to do a GetErrorMessage for it?
...

Read more...

review: Needs Fixing
Manuel de la Peña (mandel) wrote :
Download full text (4.8 KiB)

> You have some text conflicts in dash/DashView.cpp & UnityCore/Preview.cpp
>
> 27 + * Copyright (C) 2011-2012 Canonical Ltd
>
> 41 + * Authored by: Neil Jagdish Patel <email address hidden>
> 42 + * Michal Hruby <email address hidden>
>
> Please update all headers to include 2013 and your contact details
>
Sorry, I yy those lines, fixed.

> 277 {
> 278 +
> 279 if (!preview_displaying_)
>
> extra line.

No problem.

>
> 407 +const std::string MusicPaymentPreview::DATA_INFOHINT_ID =
> "album_purchase_preview";
> 408 +const std::string MusicPaymentPreview::DATA_PASSWORD_KEY =
> "password";
> 409 +const std::string MusicPaymentPreview::CHANGE_PAYMENT_ACTION =
> "change_payment_method";
> 410 +const std::string MusicPaymentPreview::FORGOT_PASSWORD_ACTION =
> "forgot_password";
> 411 +const std::string MusicPaymentPreview::CANCEL_PURCHASE_ACTION =
> "cancel_purchase";
> 412 +const std::string MusicPaymentPreview::PURCHASE_ALBUM_ACTION =
> "purchase_album";
>
> Is there a reason why these are scoped to MusicPaymentPreview class? Can you
> put them in global namespace?
>

Is there a reason for that,I mean, it can be done but it will be nice to be able to access them for the tests.

> 936 + std::map<std::string, nux::ObjectPtr<nux::AbstractButton>>
> sorted_buttons_;
>
> What is sorted about a map ? ;)
>
> 701 + actions_layout->AddView(
> 702 +
> sorted_buttons_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer(),
> 703 + 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
> 704 + 100.0f, nux::NUX_LAYOUT_END);
> 705 + actions_layout->AddView(
> 706 +
> sorted_buttons_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer(),
> 707 + 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
> 708 + 100.0f, nux::NUX_LAYOUT_END);
>
> 728 + buttons_data_layout->AddView(sorted_buttons_[MusicPaymentPreview::C
> ANCEL_PURCHASE_ACTION].GetPointer(),
> 729 + 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL,
> 100.0f,
> 730 + nux::NUX_LAYOUT_END);
> 731 + buttons_data_layout->AddView(sorted_buttons_[MusicPaymentPreview::P
> URCHASE_ALBUM_ACTION].GetPointer(),
> 732 + 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL,
> 100.0f,
> 733 + nux::NUX_LAYOUT_END);
>
> should check if sorted_buttons_ contains the actions before adding them.
>

No problem,

> 784 + dash::Preview::InfoHintPtrList hints =
> preview_model_->GetInfoHints();
> 785 + GVariant *preview_data = NULL;
> 786 + dash::Preview::InfoHintPtr data_info_hint_ = NULL;
> 787 + if (!hints.empty())
> 788 + {
> 789 + for (dash::Preview::InfoHintPtr info_hint : hints)
> 790 + {
> 791 + if (info_hint->id == MusicPaymentPreview::DATA_INFOHINT_ID)
> 792 + {
> 793 + preview_data = info_hint->value;
> 794 + }
> 795 + if (preview_data != NULL)
> 796 + {
> 797 + error_message_ = GetErrorMessage(preview_data);
> 798 + }
> 799 + }
> 800 + }
>
> 1. data_info_hint_ doesn't s...

Read more...

PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:2901
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mandel/unity/generic-payment-preview/+merge/154071/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-ci/10/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-raring-amd64-ci/10/console

Click here to trigger a rebuild:
http://jenkins.qa.ubuntu.com/job/unity-team-unity-libunity-7.0-breakage-ci/10/rebuild

review: Needs Fixing (continuous-integration)
Nick Dedekind (nick-dedekind) wrote :

LGTM

review: Approve
Didier Roche (didrocks) wrote :

urgh urgh, shouldn't have been approved/merged. Synced back with Nick and reverted :)

2906. By Manuel de la Peña on 2013-03-21

Added error previews.

Didier Roche (didrocks) wrote :

Online services QA gave its +1, let's get it merged

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/CMakeLists.txt'
2--- UnityCore/CMakeLists.txt 2013-03-19 14:05:51 +0000
3+++ UnityCore/CMakeLists.txt 2013-03-21 17:32:22 +0000
4@@ -45,6 +45,7 @@
5 ModelIterator.h
6 ModelRowAdaptor.h
7 ModelRowAdaptor-inl.h
8+ PaymentPreview.h
9 Preview.h
10 PreviewPlayer.h
11 RadioOptionFilter.h
12@@ -89,6 +90,7 @@
13 MultiRangeFilter.cpp
14 MusicPreview.cpp
15 ModelRowAdaptor.cpp
16+ PaymentPreview.cpp
17 Preview.cpp
18 PreviewPlayer.cpp
19 RatingsFilter.cpp
20
21=== added file 'UnityCore/PaymentPreview.cpp'
22--- UnityCore/PaymentPreview.cpp 1970-01-01 00:00:00 +0000
23+++ UnityCore/PaymentPreview.cpp 2013-03-21 17:32:22 +0000
24@@ -0,0 +1,120 @@
25+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
26+/*
27+ * Copyright (C) 2011-2013 Canonical Ltd
28+ *
29+ * This program is free software: you can redistribute it and/or modify
30+ * it under the terms of the GNU General Public License version 3 as
31+ * published by the Free Software Foundation.
32+ *
33+ * This program is distributed in the hope that it will be useful,
34+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
35+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36+ * GNU General Public License for more details.
37+ *
38+ * You should have received a copy of the GNU General Public License
39+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
40+ *
41+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
42+ */
43+
44+#include <unity-protocol.h>
45+
46+#include "PaymentPreview.h"
47+
48+namespace unity
49+{
50+namespace dash
51+{
52+
53+class PaymentPreview::Impl
54+{
55+
56+public:
57+ Impl(PaymentPreview* owner, glib::Object<GObject> const& proto_obj);
58+
59+ void SetupGetters();
60+
61+ // getters for the data properties
62+
63+ std::string get_header() const { return header_; };
64+ std::string get_email() const { return email_; };
65+ std::string get_payment_method() const { return payment_method_; };
66+ std::string get_purchase_prize() const { return purchase_prize_; };
67+ std::string get_purchase_type() const { return purchase_type_; };
68+ PreviewType get_preview_type() const { return preview_type_; };
69+
70+ // getters for the lables
71+
72+ // instance vars
73+ PaymentPreview* owner_;
74+
75+ std::string header_;
76+ std::string email_;
77+ std::string payment_method_;
78+ std::string purchase_prize_;
79+ std::string purchase_type_;
80+ PaymentPreview::PreviewType preview_type_;
81+
82+};
83+
84+PaymentPreview::Impl::Impl(PaymentPreview* owner, glib::Object<GObject> const& proto_obj)
85+ : owner_(owner)
86+{
87+ const gchar* s;
88+ auto preview = glib::object_cast<UnityProtocolPaymentPreview>(proto_obj);
89+
90+ s = unity_protocol_payment_preview_get_header(preview);
91+ if (s) header_ = s;
92+ s = unity_protocol_payment_preview_get_email(preview);
93+ if (s) email_ = s;
94+ s = unity_protocol_payment_preview_get_email(preview);
95+ if (s) email_ = s;
96+ s = unity_protocol_payment_preview_get_payment_method(preview);
97+ if (s) payment_method_ = s;
98+ s = unity_protocol_payment_preview_get_purchase_prize(preview);
99+ if (s) purchase_prize_ = s;
100+ s = unity_protocol_payment_preview_get_purchase_type(preview);
101+ if (s) purchase_type_ = s;
102+ UnityProtocolPreviewPaymentType t = unity_protocol_payment_preview_get_preview_type(preview);
103+ switch(t)
104+ {
105+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_APPLICATION:
106+ preview_type_ = PaymentPreview::APPLICATION;
107+ break;
108+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC:
109+ preview_type_ = PaymentPreview::MUSIC;
110+ break;
111+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR:
112+ preview_type_ = PaymentPreview::ERROR;
113+ break;
114+ }
115+ SetupGetters();
116+}
117+
118+void PaymentPreview::Impl::SetupGetters()
119+{
120+ owner_->header.SetGetterFunction(
121+ sigc::mem_fun(this, &PaymentPreview::Impl::get_header));
122+ owner_->email.SetGetterFunction(
123+ sigc::mem_fun(this, &PaymentPreview::Impl::get_email));
124+ owner_->payment_method.SetGetterFunction(
125+ sigc::mem_fun(this, &PaymentPreview::Impl::get_payment_method));
126+ owner_->purchase_prize.SetGetterFunction(
127+ sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_prize));
128+ owner_->preview_type.SetGetterFunction(
129+ sigc::mem_fun(this, &PaymentPreview::Impl::get_preview_type));
130+}
131+
132+PaymentPreview::PaymentPreview(unity::glib::Object<GObject> const& proto_obj)
133+ : Preview(proto_obj)
134+ , pimpl(new Impl(this, proto_obj))
135+{
136+}
137+
138+PaymentPreview::~PaymentPreview()
139+{
140+}
141+
142+
143+}
144+}
145
146=== added file 'UnityCore/PaymentPreview.h'
147--- UnityCore/PaymentPreview.h 1970-01-01 00:00:00 +0000
148+++ UnityCore/PaymentPreview.h 2013-03-21 17:32:22 +0000
149@@ -0,0 +1,62 @@
150+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
151+/*
152+ * Copyright (C) 2011-2013 Canonical Ltd
153+ *
154+ * This program is free software: you can redistribute it and/or modify
155+ * it under the terms of the GNU General Public License version 3 as
156+ * published by the Free Software Foundation.
157+ *
158+ * This program is distributed in the hope that it will be useful,
159+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
160+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+ * GNU General Public License for more details.
162+ *
163+ * You should have received a copy of the GNU General Public License
164+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
165+ *
166+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
167+ */
168+
169+#ifndef UNITY_PAYMENT_PREVIEW_PREVIEW_H
170+#define UNITY_PAYMENT_PREVIEW_PREVIEW_H
171+
172+#include <memory>
173+
174+#include <sigc++/trackable.h>
175+
176+#include "Preview.h"
177+
178+namespace unity
179+{
180+namespace dash
181+{
182+
183+class PaymentPreview : public Preview
184+{
185+public:
186+ enum PreviewType { APPLICATION, MUSIC, ERROR };
187+
188+ typedef std::shared_ptr<PaymentPreview> Ptr;
189+
190+ PaymentPreview(unity::glib::Object<GObject> const& proto_obj);
191+ ~PaymentPreview();
192+
193+ // properties that contain the data
194+ nux::RWProperty<std::string> title;
195+ nux::RWProperty<std::string> subtitle;
196+ nux::RWProperty<std::string> header;
197+ nux::RWProperty<std::string> email;
198+ nux::RWProperty<std::string> payment_method;
199+ nux::RWProperty<std::string> purchase_prize;
200+ nux::RWProperty<std::string> purchase_type;
201+ nux::RWProperty<PaymentPreview::PreviewType> preview_type;
202+
203+private:
204+ class Impl;
205+ std::unique_ptr<Impl> pimpl;
206+};
207+
208+}
209+}
210+
211+#endif
212
213=== modified file 'UnityCore/Preview.cpp'
214--- UnityCore/Preview.cpp 2013-02-27 18:04:26 +0000
215+++ UnityCore/Preview.cpp 2013-03-21 17:32:22 +0000
216@@ -1,6 +1,6 @@
217 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
218 /*
219- * Copyright (C) 2011-2012 Canonical Ltd
220+ * Copyright (C) 2011-2013 Canonical Ltd
221 *
222 * This program is free software: you can redistribute it and/or modify
223 * it under the terms of the GNU General Public License version 3 as
224@@ -16,6 +16,7 @@
225 *
226 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
227 * Michal Hruby <michal.hruby@canonical.com>
228+ * Manuel de la Pena <manuel.delapena@canonical.com>
229 */
230
231 #include <NuxCore/Logger.h>
232@@ -28,6 +29,7 @@
233 #include "GenericPreview.h"
234 #include "MusicPreview.h"
235 #include "MoviePreview.h"
236+#include "PaymentPreview.h"
237 #include "SocialPreview.h"
238
239 namespace unity
240@@ -50,23 +52,27 @@
241
242 if (renderer_name == "preview-generic")
243 {
244- return Preview::Ptr(new GenericPreview(proto_obj));
245+ return std::make_shared<GenericPreview>(proto_obj);
246+ }
247+ else if (renderer_name == "preview-payment")
248+ {
249+ return std::make_shared<PaymentPreview>(proto_obj);
250 }
251 else if (renderer_name == "preview-application")
252 {
253- return Preview::Ptr(new ApplicationPreview(proto_obj));
254+ return std::make_shared<ApplicationPreview>(proto_obj);
255 }
256 else if (renderer_name == "preview-music")
257 {
258- return Preview::Ptr(new MusicPreview(proto_obj));
259+ return std::make_shared<MusicPreview>(proto_obj);
260 }
261 else if (renderer_name == "preview-movie")
262 {
263- return Preview::Ptr(new MoviePreview(proto_obj));
264+ return std::make_shared<MoviePreview>(proto_obj);
265 }
266 else if (renderer_name == "preview-social")
267 {
268- return Preview::Ptr(new SocialPreview(proto_obj));
269+ return std::make_shared<SocialPreview>(proto_obj);
270 }
271 else
272 {
273@@ -166,7 +172,7 @@
274 static_cast<LayoutHint>(raw_action->layout_hint),
275 raw_action->hints));
276 }
277-
278+
279 int info_hints_len;
280 auto info_hints = unity_protocol_preview_get_info_hints(raw_preview_, &info_hints_len);
281 for (int i = 0; i < info_hints_len; i++)
282
283=== modified file 'UnityCore/Preview.h'
284--- UnityCore/Preview.h 2013-02-27 18:04:26 +0000
285+++ UnityCore/Preview.h 2013-03-21 17:32:22 +0000
286@@ -95,7 +95,7 @@
287 unity::glib::Variant value;
288
289 InfoHint() {};
290- InfoHint(const gchar* id_, const gchar* display_name_,
291+ InfoHint(const gchar* id_, const gchar* display_name_,
292 const gchar* icon_hint_, GVariant* value_)
293 : id(id_ != NULL ? id_ : "")
294 , display_name(display_name_ != NULL ? display_name_ : "")
295
296=== modified file 'dash/DashView.cpp'
297--- dash/DashView.cpp 2013-03-20 16:56:53 +0000
298+++ dash/DashView.cpp 2013-03-21 17:32:22 +0000
299@@ -30,6 +30,7 @@
300 #include <NuxCore/Logger.h>
301 #include <UnityCore/GLibWrapper.h>
302 #include <UnityCore/RadioOptionFilter.h>
303+#include <UnityCore/PaymentPreview.h>
304
305 #include "unity-shared/DashStyle.h"
306 #include "unity-shared/KeyboardUtil.h"
307@@ -1217,7 +1218,15 @@
308 // Hook up to the new preview infrastructure
309 scope->preview_ready.connect([&] (LocalResult const& result, Preview::Ptr model)
310 {
311- LOG_DEBUG(logger) << "Got preview for: " << result.uri;
312+ // HACK: Atm we don't support well the fact that a preview can be sent from
313+ // an ActionResponse and therefore transition does not work, this hack allows
314+ // to set the navigation mode to ensure that we have a nice transition
315+ if (dynamic_cast<PaymentPreview*>(model.get()) != NULL)
316+ {
317+ preview_state_machine_.left_results.Set(0);
318+ preview_state_machine_.right_results.Set(0);
319+ preview_navigation_mode_ = previews::Navigation::RIGHT;
320+ }
321 preview_state_machine_.ActivatePreview(model); // this does not immediately display a preview - we now wait.
322 });
323
324@@ -1619,7 +1628,7 @@
325 }
326 }
327
328- if (search_key || search_bar_->im_preedit)
329+ if (!preview_displaying_ && (search_key || search_bar_->im_preedit))
330 {
331 // then send the event to the search entry
332 return search_bar_->text_entry();
333
334=== modified file 'dash/previews/CMakeLists.txt'
335--- dash/previews/CMakeLists.txt 2013-01-18 16:02:50 +0000
336+++ dash/previews/CMakeLists.txt 2013-03-21 17:32:22 +0000
337@@ -23,6 +23,7 @@
338 GenericPreview.cpp
339 MusicPreview.cpp
340 MoviePreview.cpp
341+ PaymentPreview.cpp
342 Preview.cpp
343 PreviewContainer.cpp
344 PreviewInfoHintWidget.cpp
345@@ -34,6 +35,8 @@
346 TabIterator.cpp
347 Track.cpp
348 Tracks.cpp
349+ MusicPaymentPreview.cpp
350+ ErrorPreview.cpp
351 )
352
353 add_library (previews-lib STATIC ${PREVIEWS_SOURCES})
354@@ -41,26 +44,40 @@
355 target_link_libraries (previews-lib unity-shared)
356 add_pch(pch/previews_pch.hh previews-lib)
357
358-#
359+#
360 # Application Standalone variant
361 #
362 add_executable (app_previews StandaloneApplicationPreview.cpp)
363 target_link_libraries (app_previews previews-lib unity-shared)
364
365-#
366+#
367 # Music Standalone variant
368 #
369 add_executable (music_previews StandaloneMusicPreview.cpp)
370 target_link_libraries (music_previews previews-lib unity-shared)
371
372-#
373+#
374 # Social Standalone variant
375 #
376 add_executable (social_previews StandaloneSocialPreview.cpp)
377 target_link_libraries (social_previews previews-lib unity-shared)
378
379-#
380-# Music Standalone variant
381+#
382+# Movie Standalone variant
383 #
384 add_executable (movie_previews StandaloneMoviePreview.cpp)
385 target_link_libraries (movie_previews previews-lib unity-shared)
386+
387+#
388+# Payment Standalone variant
389+#
390+add_executable (payment_previews StandaloneMusicPaymentPreview.cpp)
391+add_dependencies (payment_previews previews-lib)
392+target_link_libraries (payment_previews previews-lib unity-shared)
393+
394+#
395+# Error Standalone variant
396+#
397+add_executable (error_previews StandaloneErrorPreview.cpp)
398+add_dependencies (error_previews previews-lib)
399+target_link_libraries (error_previews previews-lib unity-shared)
400
401=== added file 'dash/previews/ErrorPreview.cpp'
402--- dash/previews/ErrorPreview.cpp 1970-01-01 00:00:00 +0000
403+++ dash/previews/ErrorPreview.cpp 2013-03-21 17:32:22 +0000
404@@ -0,0 +1,246 @@
405+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
406+/*
407+ * Copyright 2012-2013 Canonical Ltd.
408+ *
409+ * This program is free software: you can redistribute it and/or modify it
410+ * under the terms of the GNU Lesser General Public License version 3, as
411+ * published by the Free Software Foundation.
412+ *
413+ * This program is distributed in the hope that it will be useful, but
414+ * WITHOUT ANY WARRANTY; without even the implied warranties of
415+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
416+ * PURPOSE. See the applicable version of the GNU Lesser General Public
417+ * License for more details.
418+ *
419+ * You should have received a copy of both the GNU Lesser General Public
420+ * License version 3 along with this program. If not, see
421+ * <http://www.gnu.org/licenses/>
422+ *
423+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
424+ * Manuel de la Pena <manuel.delapena@canonical.com>
425+ *
426+ */
427+
428+#include "unity-shared/IntrospectableWrappers.h"
429+#include "unity-shared/PreviewStyle.h"
430+#include "unity-shared/CoverArt.h"
431+#include "unity-shared/StaticCairoText.h"
432+#include "unity-shared/PlacesVScrollBar.h"
433+#include <NuxCore/Logger.h>
434+#include <Nux/VLayout.h>
435+#include <Nux/HLayout.h>
436+#include <Nux/GridHLayout.h>
437+#include <Nux/AbstractButton.h>
438+
439+#include "ErrorPreview.h"
440+#include "PreviewInfoHintWidget.h"
441+
442+#include "stdio.h"
443+#include "config.h"
444+
445+namespace unity
446+{
447+namespace dash
448+{
449+namespace previews
450+{
451+
452+namespace
453+{
454+nux::logging::Logger logger("unity.dash.previews.ErrorPreview");
455+
456+}
457+
458+class DetailsScrollView : public nux::ScrollView
459+{
460+public:
461+ DetailsScrollView(NUX_FILE_LINE_PROTO)
462+ : ScrollView(NUX_FILE_LINE_PARAM)
463+ {
464+ SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
465+ }
466+
467+};
468+
469+NUX_IMPLEMENT_OBJECT_TYPE(ErrorPreview)
470+
471+ErrorPreview::ErrorPreview(dash::Preview::Ptr preview_model)
472+: PaymentPreview(preview_model)
473+{
474+ PaymentPreview::SetupBackground();
475+ SetupViews();
476+}
477+
478+ErrorPreview::~ErrorPreview()
479+{
480+}
481+
482+nux::Area* ErrorPreview::FindKeyFocusArea(unsigned int key_symbol,
483+ unsigned long x11_key_code,
484+ unsigned long special_keys_state)
485+{
486+ return Preview::FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
487+}
488+
489+std::string ErrorPreview::GetName() const
490+{
491+ return "ErrorPreview";
492+}
493+
494+void ErrorPreview::OnActionActivated(ActionButton* button, std::string const& id)
495+{
496+}
497+
498+void ErrorPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
499+{
500+ if (preview_model_)
501+ preview_model_->PerformAction(id);
502+}
503+
504+void ErrorPreview::LoadActions()
505+{
506+ // Loop over the buttons and add them to the correct var
507+ // this is not efficient but is the only way we have atm
508+ for (dash::Preview::ActionPtr action : preview_model_->GetActions())
509+ {
510+ const char *action_id = action->id.c_str();
511+ if(strcmp(OPEN_U1_LINK_ACTION, action_id) == 0)
512+ {
513+ nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
514+ link->activate.connect(sigc::mem_fun(this,
515+ &ErrorPreview::OnActionLinkActivated));
516+
517+ std::pair<std::string, nux::ObjectPtr<nux::AbstractButton>> data (action->id, link);
518+ sorted_buttons_.insert(data);
519+ }
520+ LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
521+ }
522+}
523+
524+nux::Layout* ErrorPreview::GetTitle()
525+{
526+ previews::Style& style = dash::previews::Style::Instance();
527+ nux::VLayout* title_data_layout = new nux::VLayout();
528+ title_data_layout->SetMaximumHeight(76);
529+ title_data_layout->SetSpaceBetweenChildren(10);
530+
531+ title_ = new StaticCairoText(
532+ preview_model_->title.Get(), true,
533+ NUX_TRACKER_LOCATION);
534+
535+ title_->SetFont(style.payment_title_font().c_str());
536+ title_->SetLines(-1);
537+ title_->SetFont(style.title_font().c_str());
538+ title_data_layout->AddView(title_.GetPointer(), 1);
539+
540+ subtitle_ = new StaticCairoText(
541+ preview_model_->subtitle.Get(), true,
542+ NUX_TRACKER_LOCATION);
543+ subtitle_->SetLines(-1);
544+ subtitle_->SetFont(style.payment_subtitle_font().c_str());
545+ title_data_layout->AddView(subtitle_.GetPointer(), 1);
546+ title_data_layout->AddSpace(1, 1);
547+ return title_data_layout;
548+}
549+
550+nux::Layout* ErrorPreview::GetPrice()
551+{
552+ previews::Style& style = dash::previews::Style::Instance();
553+ nux::VLayout *prize_data_layout = new nux::VLayout();
554+ prize_data_layout->SetMaximumHeight(76);
555+ prize_data_layout->SetSpaceBetweenChildren(5);
556+
557+ purchase_prize_ = new StaticCairoText(
558+ error_preview_model_->purchase_prize.Get(), true,
559+ NUX_TRACKER_LOCATION);
560+ purchase_prize_->SetLines(-1);
561+ purchase_prize_->SetFont(style.payment_prize_title_font().c_str());
562+ prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
563+ nux::MINOR_POSITION_END);
564+
565+ purchase_hint_ = new StaticCairoText(
566+ _("Ubuntu One best offer"),
567+ true, NUX_TRACKER_LOCATION);
568+ purchase_hint_->SetLines(-1);
569+ purchase_hint_->SetFont(style.payment_prize_subtitle_font().c_str());
570+ prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
571+ nux::MINOR_POSITION_END);
572+
573+ purchase_type_ = new StaticCairoText(
574+ error_preview_model_->purchase_type.Get(), true,
575+ NUX_TRACKER_LOCATION);
576+ purchase_type_->SetLines(-1);
577+ purchase_type_->SetFont(style.payment_prize_subtitle_font().c_str());
578+ prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
579+ nux::MINOR_POSITION_END);
580+ return prize_data_layout;
581+}
582+
583+nux::Layout* ErrorPreview::GetBody()
584+{
585+ previews::Style& style = dash::previews::Style::Instance();
586+ nux::HLayout *body_layout = new nux::HLayout();
587+
588+ lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
589+ style.GetPaymentLockHeight());
590+
591+ intro_ = new StaticCairoText(
592+ error_preview_model_->header.Get(), true,
593+ NUX_TRACKER_LOCATION);
594+ intro_->SetMaximumWidth(style.GetPaymentHeaderWidth());
595+ intro_->SetFont(style.payment_intro_font().c_str());
596+ intro_->SetLineSpacing(10);
597+ intro_->SetLines(-style.GetDescriptionLineCount());
598+ intro_->SetMinimumHeight(50);
599+ body_layout->AddView(sorted_buttons_[OPEN_U1_LINK_ACTION].GetPointer(),
600+ 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
601+ nux::NUX_LAYOUT_END);
602+ body_layout->AddView(lock_texture_, 0, nux::MINOR_POSITION_CENTER,
603+ nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
604+ body_layout->AddView(intro_.GetPointer(), 1);
605+ return body_layout;
606+}
607+
608+nux::Layout* ErrorPreview::GetFooter()
609+{
610+ nux::HLayout* buttons_data_layout = new nux::HLayout();
611+ return buttons_data_layout;
612+}
613+
614+void ErrorPreview::PreLayoutManagement()
615+{
616+ nux::Geometry geo = GetGeometry();
617+ GetLayout()->SetGeometry(geo);
618+
619+ previews::Style& style = dash::previews::Style::Instance();
620+
621+ int width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
622+
623+ if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
624+ if(header_layout_) { header_layout_->SetMaximumWidth(width); }
625+ if(intro_) { intro_->SetMaximumWidth(width); }
626+ if(form_layout_) { form_layout_->SetMaximumWidth(width); }
627+ if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
628+
629+ Preview::PreLayoutManagement();
630+}
631+
632+void ErrorPreview::SetupViews()
633+{
634+ error_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
635+ if (!error_preview_model_)
636+ {
637+ LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
638+ return;
639+ }
640+
641+ // load the buttons so that they can be accessed in order
642+ LoadActions();
643+
644+ PaymentPreview::SetupViews();
645+}
646+
647+
648+}
649+}
650+}
651
652=== added file 'dash/previews/ErrorPreview.h'
653--- dash/previews/ErrorPreview.h 1970-01-01 00:00:00 +0000
654+++ dash/previews/ErrorPreview.h 2013-03-21 17:32:22 +0000
655@@ -0,0 +1,119 @@
656+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
657+/*
658+ * Copyright 2012-2013 Canonical Ltd.
659+ *
660+ * This program is free software: you can redistribute it and/or modify it
661+ * under the terms of the GNU Lesser General Public License version 3, as
662+ * published by the Free Software Foundation.
663+ *
664+ * This program is distributed in the hope that it will be useful, but
665+ * WITHOUT ANY WARRANTY; without even the implied warranties of
666+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
667+ * PURPOSE. See the applicable version of the GNU Lesser General Public
668+ * License for more details.
669+ *
670+ * You should have received a copy of both the GNU Lesser General Public
671+ * License version 3 along with this program. If not, see
672+ * <http://www.gnu.org/licenses/>
673+ *
674+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
675+ * Manuel de la Pena <manuel.delapena@canonical.com>
676+ *
677+ */
678+
679+#ifndef ERROR_PREVIEW_H
680+#define ERROR_PREVIEW_H
681+
682+// key used to find the correct info hint
683+#define ERROR_INFOHINT_ID "error_preview"
684+
685+// keys of the data preview
686+// Necessary??
687+#define DATA_MESSAGE_KEY "message"
688+
689+// ations ids
690+#define OPEN_U1_LINK_ACTION "open_u1_link"
691+
692+#include <Nux/Nux.h>
693+#include <Nux/AbstractButton.h>
694+#include <UnityCore/Lens.h>
695+#include "ActionButton.h"
696+#include "ActionLink.h"
697+#include "PaymentPreview.h"
698+#include "unity-shared/IconTexture.h"
699+#include "unity-shared/TextInput.h"
700+
701+namespace nux
702+{
703+class AbstractPaintLayer;
704+class StaticCairoText;
705+class VLayout;
706+}
707+
708+namespace unity
709+{
710+namespace dash
711+{
712+namespace previews
713+{
714+class CoverArt;
715+class PreviewInfoHintWidget;
716+
717+class ErrorPreview : public PaymentPreview
718+{
719+public:
720+ typedef nux::ObjectPtr<ErrorPreview> Ptr;
721+ NUX_DECLARE_OBJECT_TYPE(ErrorPreview, Preview)
722+
723+ ErrorPreview(dash::Preview::Ptr preview_model);
724+ ~ErrorPreview();
725+
726+ nux::Area* FindKeyFocusArea(unsigned int key_symbol,
727+ unsigned long x11_key_code,
728+ unsigned long special_keys_state);
729+ // From debug::Introspectable
730+ std::string GetName() const;
731+ nux::Layout* GetTitle();
732+ nux::Layout* GetPrice();
733+ nux::Layout* GetBody();
734+ nux::Layout* GetFooter();
735+
736+private:
737+ void LoadActions();
738+
739+protected:
740+ void OnActionActivated(ActionButton* button, std::string const& id);
741+ void OnActionLinkActivated(ActionLink* link, std::string const& id);
742+
743+ void PreLayoutManagement();
744+
745+ virtual void SetupViews();
746+ // content elements
747+ nux::ObjectPtr<CoverArt> image_;
748+ nux::ObjectPtr<StaticCairoText> intro_;
749+ nux::ObjectPtr<StaticCairoText> title_;
750+ nux::ObjectPtr<StaticCairoText> subtitle_;
751+ nux::ObjectPtr<StaticCairoText> purchase_hint_;
752+ nux::ObjectPtr<StaticCairoText> purchase_prize_;
753+ nux::ObjectPtr<StaticCairoText> purchase_type_;
754+ nux::ObjectPtr<nux::HLayout> form_layout_;
755+
756+ dash::PaymentPreview* error_preview_model_;
757+ // do we want to type?
758+ bool entry_selected_;
759+
760+ // actions
761+ std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> sorted_buttons_;
762+
763+ // lock texture
764+ IconTexture* lock_texture_;
765+
766+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
767+ LayerPtr details_bg_layer_;
768+};
769+
770+}
771+}
772+}
773+
774+#endif // ERROR_PREVIEW_H
775
776=== added file 'dash/previews/MusicPaymentPreview.cpp'
777--- dash/previews/MusicPaymentPreview.cpp 1970-01-01 00:00:00 +0000
778+++ dash/previews/MusicPaymentPreview.cpp 2013-03-21 17:32:22 +0000
779@@ -0,0 +1,459 @@
780+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
781+/*
782+ * Copyright 2012-2013 Canonical Ltd.
783+ *
784+ * This program is free software: you can redistribute it and/or modify it
785+ * under the terms of the GNU Lesser General Public License version 3, as
786+ * published by the Free Software Foundation.
787+ *
788+ * This program is distributed in the hope that it will be useful, but
789+ * WITHOUT ANY WARRANTY; without even the implied warranties of
790+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
791+ * PURPOSE. See the applicable version of the GNU Lesser General Public
792+ * License for more details.
793+ *
794+ * You should have received a copy of both the GNU Lesser General Public
795+ * License version 3 along with this program. If not, see
796+ * <http://www.gnu.org/licenses/>
797+ *
798+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
799+ *
800+ */
801+
802+#include "unity-shared/IntrospectableWrappers.h"
803+#include "unity-shared/PreviewStyle.h"
804+#include "unity-shared/CoverArt.h"
805+#include "unity-shared/StaticCairoText.h"
806+#include "unity-shared/PlacesVScrollBar.h"
807+#include "config.h"
808+
809+#include <glib/gi18n-lib.h>
810+#include <NuxCore/Logger.h>
811+#include <Nux/VLayout.h>
812+#include <Nux/GridHLayout.h>
813+#include <Nux/AbstractButton.h>
814+
815+#include "MusicPaymentPreview.h"
816+#include "PreviewInfoHintWidget.h"
817+
818+#include "stdio.h"
819+
820+namespace unity
821+{
822+namespace dash
823+{
824+namespace previews
825+{
826+
827+namespace
828+{
829+nux::logging::Logger logger("unity.dash.previews.payment.preview.music");
830+
831+}
832+
833+// static string definitions
834+const std::string MusicPaymentPreview::DATA_INFOHINT_ID = "album_purchase_preview";
835+const std::string MusicPaymentPreview::DATA_PASSWORD_KEY = "password";
836+const std::string MusicPaymentPreview::CHANGE_PAYMENT_ACTION = "change_payment_method";
837+const std::string MusicPaymentPreview::FORGOT_PASSWORD_ACTION = "forgot_password";
838+const std::string MusicPaymentPreview::CANCEL_PURCHASE_ACTION = "cancel_purchase";
839+const std::string MusicPaymentPreview::PURCHASE_ALBUM_ACTION = "purchase_album";
840+
841+class DetailsScrollView : public nux::ScrollView
842+{
843+public:
844+ DetailsScrollView(NUX_FILE_LINE_PROTO)
845+ : ScrollView(NUX_FILE_LINE_PARAM)
846+ {
847+ SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
848+ }
849+
850+};
851+
852+NUX_IMPLEMENT_OBJECT_TYPE(MusicPaymentPreview)
853+
854+MusicPaymentPreview::MusicPaymentPreview(dash::Preview::Ptr preview_model)
855+: PaymentPreview(preview_model)
856+{
857+ SetupViews();
858+ PaymentPreview::SetupBackground();
859+}
860+
861+std::string MusicPaymentPreview::GetName() const
862+{
863+ return "MusicPaymentPreview";
864+}
865+
866+void MusicPaymentPreview::OnActionActivated(ActionButton* button, std::string const& id)
867+{
868+ // Check the action id and send the password only when we
869+ // purchasing a song
870+ if(id == MusicPaymentPreview::PURCHASE_ALBUM_ACTION && preview_model_
871+ && password_entry_)
872+ {
873+ // HACK: We need to think a better way to do this
874+ auto const& password = password_entry_->text_entry()->GetText();
875+ glib::Variant variant_pw(g_variant_new_string(password.c_str()));
876+ Lens::Hints hints {
877+ std::make_pair(MusicPaymentPreview::DATA_PASSWORD_KEY, variant_pw)
878+ };
879+ preview_model_->PerformAction(id, hints);
880+
881+ // show the overlay
882+ ShowOverlay();
883+ return;
884+ }
885+ Preview::OnActionActivated(button, id);
886+}
887+
888+void MusicPaymentPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
889+{
890+ if (preview_model_)
891+ preview_model_->PerformAction(id);
892+}
893+
894+void MusicPaymentPreview::LoadActions()
895+{
896+ // Loop over the buttons and add them to the correct var
897+ // this is not efficient but is the only way we have atm
898+ for (dash::Preview::ActionPtr action : preview_model_->GetActions())
899+ {
900+ const char *action_id = action->id.c_str();
901+ if(MusicPaymentPreview::CHANGE_PAYMENT_ACTION == action_id
902+ || MusicPaymentPreview::FORGOT_PASSWORD_ACTION == action_id)
903+ {
904+ nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
905+ link->activate.connect(sigc::mem_fun(this,
906+ &MusicPaymentPreview::OnActionLinkActivated));
907+
908+ buttons_map_.insert(std::make_pair(action->id, link));
909+ }
910+ else
911+ {
912+ nux::ObjectPtr<ActionButton> button = this->CreateButton(action);
913+ button->activate.connect(sigc::mem_fun(this,
914+ &MusicPaymentPreview::OnActionActivated));
915+
916+ buttons_map_.insert(std::make_pair(action->id, button));
917+ }
918+ LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
919+ }
920+}
921+
922+nux::Layout* MusicPaymentPreview::GetTitle()
923+{
924+ previews::Style& style = dash::previews::Style::Instance();
925+ nux::VLayout* title_data_layout = new nux::VLayout();
926+ title_data_layout->SetMaximumHeight(76);
927+ title_data_layout->SetSpaceBetweenChildren(10);
928+
929+ title_ = new StaticCairoText(
930+ preview_model_->title.Get(), true,
931+ NUX_TRACKER_LOCATION);
932+
933+ title_->SetFont(style.payment_title_font());
934+ title_->SetLines(-1);
935+ title_->SetFont(style.title_font());
936+ title_data_layout->AddView(title_.GetPointer(), 1);
937+
938+ subtitle_ = new StaticCairoText(
939+ preview_model_->subtitle.Get(), true,
940+ NUX_TRACKER_LOCATION);
941+ subtitle_->SetLines(-1);
942+ subtitle_->SetFont(style.payment_subtitle_font());
943+ title_data_layout->AddView(subtitle_.GetPointer(), 1);
944+ title_data_layout->AddSpace(1, 1);
945+ return title_data_layout;
946+}
947+
948+nux::Layout* MusicPaymentPreview::GetPrice()
949+{
950+ previews::Style& style = dash::previews::Style::Instance();
951+ nux::VLayout *prize_data_layout = new nux::VLayout();
952+ prize_data_layout->SetMaximumHeight(76);
953+ prize_data_layout->SetSpaceBetweenChildren(5);
954+
955+ purchase_prize_ = new StaticCairoText(
956+ payment_preview_model_->purchase_prize.Get(), true,
957+ NUX_TRACKER_LOCATION);
958+ purchase_prize_->SetLines(-1);
959+ purchase_prize_->SetFont(style.payment_prize_title_font());
960+ prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
961+ nux::MINOR_POSITION_END);
962+
963+ purchase_hint_ = new StaticCairoText(
964+ _("Ubuntu One best offer"),
965+ true, NUX_TRACKER_LOCATION);
966+ purchase_hint_->SetLines(-1);
967+ purchase_hint_->SetFont(style.payment_prize_subtitle_font());
968+ prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
969+ nux::MINOR_POSITION_END);
970+
971+ purchase_type_ = new StaticCairoText(
972+ payment_preview_model_->purchase_type.Get(), true,
973+ NUX_TRACKER_LOCATION);
974+ purchase_type_->SetLines(-1);
975+ purchase_type_->SetFont(style.payment_prize_subtitle_font());
976+ prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
977+ nux::MINOR_POSITION_END);
978+ return prize_data_layout;
979+}
980+
981+nux::Layout* MusicPaymentPreview::GetBody()
982+{
983+ previews::Style& style = dash::previews::Style::Instance();
984+ nux::VLayout *body_layout = new nux::VLayout();
985+ body_layout->SetSpaceBetweenChildren(20);
986+
987+ intro_ = new StaticCairoText(
988+ payment_preview_model_->header.Get(), true,
989+ NUX_TRACKER_LOCATION);
990+ intro_->SetFont(style.payment_intro_font());
991+ intro_->SetLineSpacing(10);
992+ intro_->SetLines(-style.GetDescriptionLineCount());
993+ intro_->SetMinimumHeight(50);
994+
995+ form_layout_ = new nux::HLayout();
996+ form_layout_->SetSpaceBetweenChildren(10);
997+ form_layout_->SetMinimumHeight(107);
998+ form_layout_->SetLeftAndRightPadding(20);
999+ form_layout_->SetTopAndBottomPadding(10);
1000+
1001+ form_layout_->AddLayout(GetFormLabels(), 1, nux::MINOR_POSITION_END);
1002+ form_layout_->AddLayout(GetFormFields(), 1, nux::MINOR_POSITION_END);
1003+ form_layout_->AddLayout(GetFormActions(), 1, nux::MINOR_POSITION_END);
1004+
1005+
1006+ body_layout->AddView(intro_.GetPointer(), 1);
1007+ body_layout->AddLayout(form_layout_.GetPointer(), 1);
1008+
1009+
1010+ return body_layout;
1011+}
1012+
1013+nux::Layout* MusicPaymentPreview::GetFormLabels()
1014+{
1015+ previews::Style& style = dash::previews::Style::Instance();
1016+ nux::VLayout *labels_layout = new nux::VLayout();
1017+ if (error_message_.empty())
1018+ {
1019+ labels_layout->SetSpaceBetweenChildren(18);
1020+ }
1021+ else
1022+ {
1023+ labels_layout->SetSpaceBetweenChildren(10);
1024+ }
1025+
1026+ email_label_ = new StaticCairoText(
1027+ _("Ubuntu One email:"), true,
1028+ NUX_TRACKER_LOCATION);
1029+ email_label_->SetLines(-1);
1030+ email_label_->SetFont(style.payment_form_labels_font());
1031+ labels_layout->AddView(email_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
1032+
1033+ payment_label_ = new StaticCairoText(
1034+ _("Payment method:"), true,
1035+ NUX_TRACKER_LOCATION);
1036+ payment_label_->SetLines(-1);
1037+ payment_label_->SetFont(style.payment_form_labels_font());
1038+ labels_layout->AddView(payment_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
1039+
1040+ password_label_ = new StaticCairoText(
1041+ _("Ubuntu One Password:"), true,
1042+ NUX_TRACKER_LOCATION);
1043+ password_label_->SetLines(-1);
1044+ password_label_->SetFont(style.payment_form_labels_font());
1045+ password_label_->SetMinimumHeight(40);
1046+ labels_layout->AddView(password_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
1047+
1048+ return labels_layout;
1049+}
1050+
1051+nux::Layout* MusicPaymentPreview::GetFormFields()
1052+{
1053+ previews::Style& style = dash::previews::Style::Instance();
1054+ nux::VLayout *fields_layout = new nux::VLayout();
1055+ if (error_message_.empty())
1056+ {
1057+ fields_layout->SetSpaceBetweenChildren(18);
1058+ }
1059+ else
1060+ {
1061+ fields_layout->SetSpaceBetweenChildren(10);
1062+ }
1063+
1064+ email_ = new StaticCairoText(
1065+ payment_preview_model_->email.Get(), true,
1066+ NUX_TRACKER_LOCATION);
1067+ email_->SetLines(-1);
1068+ email_->SetFont(style.payment_form_data_font());
1069+ fields_layout->AddView(email_.GetPointer(), 1,
1070+ nux::MINOR_POSITION_START);
1071+
1072+ payment_ = new StaticCairoText(
1073+ payment_preview_model_->payment_method.Get(), true,
1074+ NUX_TRACKER_LOCATION);
1075+ payment_->SetLines(-1);
1076+ payment_->SetFont(style.payment_form_data_font());
1077+ fields_layout->AddView(payment_.GetPointer(), 1,
1078+ nux::MINOR_POSITION_START);
1079+
1080+ password_entry_ = new TextInput();
1081+ password_entry_->SetMinimumHeight(40);
1082+ password_entry_->SetMinimumWidth(240);
1083+ password_entry_->input_hint = _("Password");
1084+
1085+ fields_layout->AddView(password_entry_.GetPointer(),
1086+ 1, nux::MINOR_POSITION_START);
1087+
1088+ password_entry_->text_entry()->SetPasswordMode(true);
1089+ const char password_char = '*';
1090+ password_entry_->text_entry()->SetPasswordChar(&password_char);
1091+
1092+ if (!error_message_.empty())
1093+ {
1094+ StaticCairoText* error = new StaticCairoText(
1095+ _("Wrong password"), true, NUX_TRACKER_LOCATION);
1096+ error->SetLines(-1);
1097+ error->SetFont(style.payment_form_data_font());
1098+ // ensure it is an error using red
1099+ error->SetTextColor(style.payment_error_color());
1100+ fields_layout->AddView(error, 0, nux::MINOR_POSITION_START);
1101+ }
1102+
1103+ return fields_layout;
1104+}
1105+
1106+nux::Layout* MusicPaymentPreview::GetFormActions()
1107+{
1108+ previews::Style& style = dash::previews::Style::Instance();
1109+ nux::VLayout *actions_layout = new nux::VLayout();
1110+ if (error_message_.empty())
1111+ {
1112+ actions_layout->SetSpaceBetweenChildren(16);
1113+ }
1114+ else
1115+ {
1116+ actions_layout->SetSpaceBetweenChildren(8);
1117+ }
1118+
1119+ nux::ObjectPtr<StaticCairoText> empty_;
1120+ empty_ = new StaticCairoText(
1121+ "", true,
1122+ NUX_TRACKER_LOCATION);
1123+ empty_->SetLines(-1);
1124+ empty_->SetFont(style.payment_form_labels_font());
1125+ actions_layout->AddView(empty_.GetPointer(), 1,
1126+ nux::MINOR_POSITION_START);
1127+
1128+ if(buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer())
1129+ actions_layout->AddView(
1130+ buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer(),
1131+ 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
1132+ 100.0f, nux::NUX_LAYOUT_END);
1133+ if(buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer())
1134+ actions_layout->AddView(
1135+ buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer(),
1136+ 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
1137+ 100.0f, nux::NUX_LAYOUT_END);
1138+
1139+ return actions_layout;
1140+}
1141+
1142+nux::Layout* MusicPaymentPreview::GetFooter()
1143+{
1144+ previews::Style& style = dash::previews::Style::Instance();
1145+ nux::HLayout* actions_buffer_h = new nux::HLayout();
1146+ actions_buffer_h->AddSpace(0, 1);
1147+
1148+ nux::HLayout* buttons_data_layout = new nux::HLayout();
1149+ buttons_data_layout->SetSpaceBetweenChildren(style.GetSpaceBetweenActions());
1150+
1151+ lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
1152+ style.GetPaymentLockHeight());
1153+ buttons_data_layout->AddView(lock_texture_.GetPointer(), 0, nux::MINOR_POSITION_CENTER,
1154+ nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
1155+
1156+ buttons_data_layout->AddSpace(20, 1);
1157+ if(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer())
1158+ buttons_data_layout->AddView(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer(),
1159+ 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
1160+ nux::NUX_LAYOUT_END);
1161+ if(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer())
1162+ buttons_data_layout->AddView(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer(),
1163+ 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
1164+ nux::NUX_LAYOUT_END);
1165+
1166+ return buttons_data_layout;
1167+}
1168+
1169+const std::string MusicPaymentPreview::GetErrorMessage(GVariant *dict)
1170+{
1171+
1172+ glib::Variant data(g_variant_lookup_value(dict, "error_message",
1173+ G_VARIANT_TYPE_ANY));
1174+
1175+ if (!data)
1176+ return "";
1177+
1178+ return data.GetString();
1179+}
1180+
1181+void MusicPaymentPreview::PreLayoutManagement()
1182+{
1183+ nux::Geometry const& geo = GetGeometry();
1184+ GetLayout()->SetGeometry(geo);
1185+
1186+ previews::Style& style = dash::previews::Style::Instance();
1187+
1188+ int width = std::max<int>(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
1189+
1190+ if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
1191+ if(header_layout_) { header_layout_->SetMaximumWidth(width); }
1192+ if(intro_) { intro_->SetMaximumWidth(width); }
1193+ if(form_layout_) { form_layout_->SetMaximumWidth(width); }
1194+ if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
1195+
1196+ // set the tab ordering
1197+ SetFirstInTabOrder(password_entry_->text_entry());
1198+ SetLastInTabOrder(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer());
1199+ SetLastInTabOrder(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer());
1200+ SetLastInTabOrder(buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer());
1201+ SetLastInTabOrder(buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer());
1202+
1203+ Preview::PreLayoutManagement();
1204+}
1205+
1206+void MusicPaymentPreview::SetupViews()
1207+{
1208+ payment_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
1209+ if (!payment_preview_model_)
1210+ {
1211+ LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
1212+ return;
1213+ }
1214+
1215+ dash::Preview::InfoHintPtrList hints = preview_model_->GetInfoHints();
1216+ GVariant *preview_data = NULL;
1217+ for (dash::Preview::InfoHintPtr info_hint : hints)
1218+ {
1219+ if (info_hint->id == MusicPaymentPreview::DATA_INFOHINT_ID)
1220+ {
1221+ preview_data = info_hint->value;
1222+ if (preview_data != NULL)
1223+ {
1224+ error_message_ = GetErrorMessage(preview_data);
1225+ }
1226+ break;
1227+ }
1228+ }
1229+
1230+ // load the buttons so that they can be accessed in order
1231+ LoadActions();
1232+ PaymentPreview::SetupViews();
1233+}
1234+
1235+
1236+}
1237+}
1238+}
1239
1240=== added file 'dash/previews/MusicPaymentPreview.h'
1241--- dash/previews/MusicPaymentPreview.h 1970-01-01 00:00:00 +0000
1242+++ dash/previews/MusicPaymentPreview.h 2013-03-21 17:32:22 +0000
1243@@ -0,0 +1,134 @@
1244+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1245+/*
1246+ * Copyright 2012-2013 Canonical Ltd.
1247+ *
1248+ * This program is free software: you can redistribute it and/or modify it
1249+ * under the terms of the GNU Lesser General Public License version 3, as
1250+ * published by the Free Software Foundation.
1251+ *
1252+ * This program is distributed in the hope that it will be useful, but
1253+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1254+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1255+ * PURPOSE. See the applicable version of the GNU Lesser General Public
1256+ * License for more details.
1257+ *
1258+ * You should have received a copy of both the GNU Lesser General Public
1259+ * License version 3 along with this program. If not, see
1260+ * <http://www.gnu.org/licenses/>
1261+ *
1262+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
1263+ *
1264+ */
1265+
1266+#ifndef MUSIC_PAYMENT_PREVIEW_H
1267+#define MUSIC_PAYMENT_PREVIEW_H
1268+
1269+#include <Nux/Nux.h>
1270+#include <Nux/AbstractButton.h>
1271+#include <UnityCore/Lens.h>
1272+#include <UnityCore/PaymentPreview.h>
1273+#include "ActionButton.h"
1274+#include "ActionLink.h"
1275+#include "PaymentPreview.h"
1276+#include "unity-shared/IconTexture.h"
1277+#include "unity-shared/TextInput.h"
1278+
1279+namespace nux
1280+{
1281+class AbstractPaintLayer;
1282+class StaticCairoText;
1283+class VLayout;
1284+}
1285+
1286+namespace unity
1287+{
1288+namespace dash
1289+{
1290+namespace previews
1291+{
1292+class CoverArt;
1293+class PreviewInfoHintWidget;
1294+
1295+class MusicPaymentPreview : public PaymentPreview
1296+{
1297+public:
1298+ typedef nux::ObjectPtr<MusicPaymentPreview> Ptr;
1299+ NUX_DECLARE_OBJECT_TYPE(MusicPaymentPreview, Preview);
1300+
1301+ MusicPaymentPreview(dash::Preview::Ptr preview_model);
1302+
1303+private:
1304+ void LoadActions();
1305+
1306+protected:
1307+ // key used to find the correct info hint
1308+ static const std::string DATA_INFOHINT_ID;
1309+
1310+ // keys of the data preview
1311+ static const std::string DATA_PASSWORD_KEY;
1312+
1313+ // ations ids
1314+ static const std::string CHANGE_PAYMENT_ACTION;
1315+ static const std::string FORGOT_PASSWORD_ACTION;
1316+ static const std::string CANCEL_PURCHASE_ACTION;
1317+ static const std::string PURCHASE_ALBUM_ACTION;
1318+
1319+ // From debug::Introspectable
1320+ std::string GetName() const;
1321+
1322+ nux::Layout* GetTitle();
1323+ nux::Layout* GetPrice();
1324+ nux::Layout* GetBody();
1325+ nux::Layout* GetFormLabels();
1326+ nux::Layout* GetFormFields();
1327+ nux::Layout* GetFormActions();
1328+ nux::Layout* GetFooter();
1329+
1330+ const std::string GetErrorMessage(GVariant *dict);
1331+
1332+ void OnActionActivated(ActionButton* button, std::string const& id);
1333+ void OnActionLinkActivated(ActionLink* link, std::string const& id);
1334+
1335+ virtual void SetupViews();
1336+
1337+ void PreLayoutManagement();
1338+
1339+protected:
1340+ // content elements
1341+ nux::ObjectPtr<CoverArt> image_;
1342+ nux::ObjectPtr<StaticCairoText> intro_;
1343+ nux::ObjectPtr<StaticCairoText> title_;
1344+ nux::ObjectPtr<StaticCairoText> subtitle_;
1345+ nux::ObjectPtr<StaticCairoText> email_label_;
1346+ nux::ObjectPtr<StaticCairoText> email_;
1347+ nux::ObjectPtr<StaticCairoText> payment_label_;
1348+ nux::ObjectPtr<StaticCairoText> payment_;
1349+ nux::ObjectPtr<StaticCairoText> password_label_;
1350+ nux::ObjectPtr<TextInput> password_entry_;
1351+ nux::ObjectPtr<StaticCairoText> purchase_hint_;
1352+ nux::ObjectPtr<StaticCairoText> purchase_prize_;
1353+ nux::ObjectPtr<StaticCairoText> purchase_type_;
1354+ nux::ObjectPtr<StaticCairoText> change_payment_;
1355+ nux::ObjectPtr<StaticCairoText> forgotten_password_;
1356+ nux::ObjectPtr<StaticCairoText> error_label_;
1357+ nux::ObjectPtr<nux::HLayout> form_layout_;
1358+
1359+ dash::PaymentPreview* payment_preview_model_;
1360+ // do we want to type?
1361+ std::string error_message_;
1362+
1363+ // actions
1364+ std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> buttons_map_;
1365+
1366+ // lock texture
1367+ nux::ObjectPtr<IconTexture> lock_texture_;
1368+
1369+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
1370+ LayerPtr details_bg_layer_;
1371+};
1372+
1373+}
1374+}
1375+}
1376+
1377+#endif // MUSIC_PAYMENT_PREVIEW_H
1378
1379=== added file 'dash/previews/PaymentPreview.cpp'
1380--- dash/previews/PaymentPreview.cpp 1970-01-01 00:00:00 +0000
1381+++ dash/previews/PaymentPreview.cpp 2013-03-21 17:32:22 +0000
1382@@ -0,0 +1,368 @@
1383+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1384+/*
1385+ * Copyright 2012-2013 Canonical Ltd.
1386+ *
1387+ * This program is free software: you can redistribute it and/or modify it
1388+ * under the terms of the GNU Lesser General Public License version 3, as
1389+ * published by the Free Software Foundation.
1390+ *
1391+ * This program is distributed in the hope that it will be useful, but
1392+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1393+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1394+ * PURPOSE. See the applicable version of the GNU Lesser General Public
1395+ * License for more details.
1396+ *
1397+ * You should have received a copy of both the GNU Lesser General Public
1398+ * License version 3 along with this program. If not, see
1399+ * <http://www.gnu.org/licenses/>
1400+ *
1401+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
1402+ * Manuel de la Pena <manuel.delapena@canonical.com>
1403+ *
1404+ */
1405+#include <NuxCore/Logger.h>
1406+#include "PaymentPreview.h"
1407+#include "unity-shared/CoverArt.h"
1408+#include "unity-shared/PreviewStyle.h"
1409+
1410+namespace unity
1411+{
1412+
1413+namespace dash
1414+{
1415+
1416+namespace previews
1417+{
1418+
1419+namespace
1420+{
1421+
1422+nux::logging::Logger logger("unity.dash.previews.payment.preview");
1423+
1424+}
1425+
1426+class OverlaySpinner : public unity::debug::Introspectable, public nux::View
1427+{
1428+ NUX_DECLARE_OBJECT_TYPE(OverlaySpinner, nux::View);
1429+public:
1430+ OverlaySpinner();
1431+
1432+ void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1433+ void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1434+
1435+protected:
1436+ // Introspectable methods
1437+ std::string GetName() const;
1438+ void AddProperties(GVariantBuilder* builder);
1439+
1440+ // Key navigation
1441+ virtual bool AcceptKeyNavFocus();
1442+
1443+private:
1444+ bool OnFrameTimeout();
1445+
1446+ nux::BaseTexture* spin_;
1447+
1448+ glib::Source::UniquePtr frame_timeout_;
1449+
1450+ nux::Matrix4 rotate_;
1451+ float rotation_;
1452+};
1453+
1454+NUX_IMPLEMENT_OBJECT_TYPE(OverlaySpinner);
1455+
1456+OverlaySpinner::OverlaySpinner()
1457+ : nux::View(NUX_TRACKER_LOCATION),
1458+ rotation_(0.0f)
1459+{
1460+ previews::Style& style = dash::previews::Style::Instance();
1461+
1462+ spin_ = style.GetSearchSpinIcon();
1463+
1464+ rotate_.Identity();
1465+ rotate_.Rotate_z(0.0);
1466+}
1467+
1468+void OverlaySpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
1469+{
1470+ nux::Geometry const& geo = GetGeometry();
1471+ nux::TexCoordXForm texxform;
1472+
1473+ GfxContext.PushClippingRectangle(geo);
1474+
1475+ nux::GetPainter().PaintBackground(GfxContext, geo);
1476+
1477+ texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
1478+ texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
1479+ texxform.min_filter = nux::TEXFILTER_LINEAR;
1480+ texxform.mag_filter = nux::TEXFILTER_LINEAR;
1481+
1482+ unsigned int current_alpha_blend;
1483+ unsigned int current_src_blend_factor;
1484+ unsigned int current_dest_blend_factor;
1485+ GfxContext.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
1486+ GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1487+
1488+ nux::Geometry spin_geo(geo.x + ((geo.width - spin_->GetWidth()) / 2),
1489+ geo.y + ((geo.height - spin_->GetHeight()) / 2),
1490+ spin_->GetWidth(),
1491+ spin_->GetHeight());
1492+ // Geometry (== Rect) uses integers which were rounded above,
1493+ // hence an extra 0.5 offset for odd sizes is needed
1494+ // because pure floating point is not being used.
1495+ int spin_offset_w = !(geo.width % 2) ? 0 : 1;
1496+ int spin_offset_h = !(geo.height % 2) ? 0 : 1;
1497+
1498+ nux::Matrix4 matrix_texture;
1499+ matrix_texture = nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
1500+ -spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
1501+ matrix_texture = rotate_ * matrix_texture;
1502+ matrix_texture = nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w) / 2.0f,
1503+ spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
1504+
1505+ GfxContext.SetModelViewMatrix(GfxContext.GetModelViewMatrix() * matrix_texture);
1506+
1507+ GfxContext.QRP_1Tex(spin_geo.x,
1508+ spin_geo.y,
1509+ spin_geo.width,
1510+ spin_geo.height,
1511+ spin_->GetDeviceTexture(),
1512+ texxform,
1513+ nux::color::White);
1514+
1515+ // revert to model view matrix stack
1516+ GfxContext.ApplyModelViewMatrix();
1517+
1518+ GfxContext.PopClippingRectangle();
1519+
1520+ GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
1521+
1522+ if (!frame_timeout_)
1523+ {
1524+ frame_timeout_.reset(new glib::Timeout(22, sigc::mem_fun(this, &OverlaySpinner::OnFrameTimeout)));
1525+ }
1526+}
1527+
1528+
1529+void OverlaySpinner::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
1530+{
1531+}
1532+
1533+
1534+bool OverlaySpinner::OnFrameTimeout()
1535+{
1536+ rotation_ += 0.1f;
1537+
1538+ if (rotation_ >= 360.0f)
1539+ rotation_ = 0.0f;
1540+
1541+ rotate_.Rotate_z(rotation_);
1542+ QueueDraw();
1543+
1544+ frame_timeout_.reset();
1545+ return false;
1546+}
1547+
1548+std::string OverlaySpinner::GetName() const
1549+{
1550+ return "OverlaySpinner";
1551+}
1552+
1553+void OverlaySpinner::AddProperties(GVariantBuilder* builder)
1554+{
1555+ nux::Geometry geo = GetGeometry();
1556+
1557+ variant::BuilderWrapper(builder)
1558+ .add("x", geo.x)
1559+ .add("y", geo.y)
1560+ .add("width", geo.width)
1561+ .add("height", geo.height);
1562+}
1563+
1564+
1565+bool OverlaySpinner::AcceptKeyNavFocus()
1566+{
1567+ return false;
1568+}
1569+
1570+PaymentPreview::PaymentPreview(dash::Preview::Ptr preview_model)
1571+: Preview(preview_model)
1572+, data_(nullptr)
1573+, full_data_layout_(nullptr)
1574+{
1575+}
1576+
1577+std::string PaymentPreview::GetName() const
1578+{
1579+ return "";
1580+}
1581+
1582+
1583+nux::Layout* PaymentPreview::GetHeader()
1584+{
1585+ nux::HLayout* header_data_layout = new nux::HLayout();
1586+ header_data_layout->SetSpaceBetweenChildren(10);
1587+ header_data_layout->SetMaximumHeight(76);
1588+ header_data_layout->SetMinimumHeight(76);
1589+
1590+ image_ = new CoverArt();
1591+ image_->SetMinMaxSize(64, 64);
1592+ AddChild(image_.GetPointer());
1593+ UpdateCoverArtImage(image_.GetPointer());
1594+
1595+ header_data_layout->AddView(image_.GetPointer(), 0);
1596+ header_data_layout->AddLayout(GetTitle(), 0);
1597+ header_data_layout->AddSpace(20, 1);
1598+ header_data_layout->AddLayout(GetPrice(), 0);
1599+ return header_data_layout;
1600+}
1601+
1602+nux::ObjectPtr<ActionLink> PaymentPreview::CreateLink(dash::Preview::ActionPtr action)
1603+{
1604+ previews::Style& style = dash::previews::Style::Instance();
1605+
1606+ nux::ObjectPtr<ActionLink> link;
1607+ link = new ActionLink(action->id,
1608+ action->display_name, NUX_TRACKER_LOCATION);
1609+ link->font_hint.Set(style.payment_form_labels_font().c_str());
1610+ link->SetMinimumWidth(178);
1611+ link->SetMaximumHeight(34);
1612+ return link;
1613+}
1614+
1615+
1616+nux::ObjectPtr<ActionButton> PaymentPreview::CreateButton(dash::Preview::ActionPtr action)
1617+{
1618+ previews::Style& style = dash::previews::Style::Instance();
1619+
1620+ nux::ObjectPtr<ActionButton> button;
1621+ button = new ActionButton(action->id,
1622+ action->display_name, action->icon_hint,
1623+ NUX_TRACKER_LOCATION);
1624+ button->SetFont(style.action_font());
1625+ button->SetExtraHint(action->extra_text, style.action_extra_font());
1626+ button->SetMinimumWidth(178);
1627+ button->SetMaximumHeight(34);
1628+ return button;
1629+}
1630+
1631+
1632+void PaymentPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
1633+{
1634+ nux::Geometry const& base = GetGeometry();
1635+
1636+ gfx_engine.PushClippingRectangle(base);
1637+ nux::GetPainter().PaintBackground(gfx_engine, base);
1638+
1639+ if (full_data_layout_)
1640+ {
1641+ unsigned int alpha, src, dest = 0;
1642+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
1643+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1644+
1645+ details_bg_layer_->SetGeometry(full_data_layout_->GetGeometry());
1646+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, full_data_layout_->GetGeometry(), details_bg_layer_.get());
1647+
1648+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
1649+ }
1650+
1651+ gfx_engine.PopClippingRectangle();
1652+}
1653+
1654+void PaymentPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
1655+{
1656+ nux::Geometry const& base = GetGeometry();
1657+ gfx_engine.PushClippingRectangle(base);
1658+
1659+ if (!IsFullRedraw())
1660+ nux::GetPainter().PushLayer(gfx_engine, details_bg_layer_->GetGeometry(), details_bg_layer_.get());
1661+
1662+ unsigned int alpha, src, dest = 0;
1663+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
1664+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1665+
1666+ if (GetCompositionLayout())
1667+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
1668+
1669+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
1670+
1671+ if (!IsFullRedraw())
1672+ nux::GetPainter().PopBackground();
1673+
1674+ gfx_engine.PopClippingRectangle();
1675+}
1676+
1677+void PaymentPreview::ShowOverlay(bool isShown)
1678+{
1679+ if (!full_data_layout_)
1680+ return;
1681+
1682+ if (isShown)
1683+ {
1684+ full_data_layout_->SetActiveLayerN(1);
1685+ }
1686+ else
1687+ {
1688+ full_data_layout_->SetActiveLayerN(0);
1689+ }
1690+ QueueDraw();
1691+}
1692+
1693+void PaymentPreview::ShowOverlay()
1694+{
1695+ ShowOverlay(true);
1696+}
1697+
1698+void PaymentPreview::HideOverlay()
1699+{
1700+ ShowOverlay(false);
1701+}
1702+
1703+void PaymentPreview::SetupBackground()
1704+{
1705+ details_bg_layer_.reset(dash::previews::Style::Instance().GetBackgroundLayer());
1706+}
1707+
1708+void PaymentPreview::SetupViews()
1709+{
1710+ full_data_layout_ = new nux::LayeredLayout();
1711+
1712+ // layout to be used to show the info
1713+ content_data_layout_ = new nux::VLayout();
1714+ content_data_layout_->SetSpaceBetweenChildren(5);
1715+ content_data_layout_->SetPadding(10, 10, 0, 10);
1716+
1717+ header_layout_ = GetHeader();
1718+
1719+ content_data_layout_->AddLayout(header_layout_.GetPointer(), 1);
1720+
1721+ body_layout_ = GetBody();
1722+ content_data_layout_->AddLayout(body_layout_.GetPointer(), 1);
1723+
1724+ footer_layout_ = GetFooter();
1725+ content_data_layout_->AddLayout(footer_layout_.GetPointer(), 1);
1726+
1727+ full_data_layout_->AddLayout(content_data_layout_.GetPointer());
1728+
1729+ // layout to draw an overlay
1730+ overlay_layout_ = new nux::VLayout();
1731+ StaticCairoText* calculating = new StaticCairoText(
1732+ "Performing purchase", true,
1733+ NUX_TRACKER_LOCATION);
1734+
1735+ OverlaySpinner* spinner_ = new OverlaySpinner();
1736+ overlay_layout_->AddSpace(20, 1);
1737+ overlay_layout_->AddView(calculating, 0, nux::MINOR_POSITION_CENTER);
1738+ overlay_layout_->AddView(spinner_, 1, nux::MINOR_POSITION_CENTER);
1739+ overlay_layout_->AddSpace(20, 1);
1740+
1741+ full_data_layout_->AddLayout(overlay_layout_.GetPointer());
1742+
1743+ SetLayout(full_data_layout_.GetPointer());
1744+}
1745+
1746+}
1747+
1748+}
1749+
1750+}
1751
1752=== added file 'dash/previews/PaymentPreview.h'
1753--- dash/previews/PaymentPreview.h 1970-01-01 00:00:00 +0000
1754+++ dash/previews/PaymentPreview.h 2013-03-21 17:32:22 +0000
1755@@ -0,0 +1,132 @@
1756+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
1757+/*
1758+ * Copyright 2012-2013 Canonical Ltd.
1759+ *
1760+ * This program is free software: you can redistribute it and/or modify it
1761+ * under the terms of the GNU Lesser General Public License version 3, as
1762+ * published by the Free Software Foundation.
1763+ *
1764+ * This program is distributed in the hope that it will be useful, but
1765+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1766+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1767+ * PURPOSE. See the applicable version of the GNU Lesser General Public
1768+ * License for more details.
1769+ *
1770+ * You should have received a copy of both the GNU Lesser General Public
1771+ * License version 3 along with this program. If not, see
1772+ * <http://www.gnu.org/licenses/>
1773+ *
1774+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
1775+ * Manuel de la Pena <manuel.delapena@canonical.com>
1776+ *
1777+ */
1778+
1779+#ifndef PAYMENT_PREVIEW_H
1780+#define PAYMENT_PREVIEW_H
1781+
1782+#include <Nux/Nux.h>
1783+#include <Nux/HLayout.h>
1784+#include <Nux/LayeredLayout.h>
1785+#include <Nux/AbstractButton.h>
1786+#include <UnityCore/Lens.h>
1787+#include <UnityCore/PaymentPreview.h>
1788+#include "ActionButton.h"
1789+#include "ActionLink.h"
1790+#include "Preview.h"
1791+#include "unity-shared/IconTexture.h"
1792+#include "unity-shared/TextInput.h"
1793+
1794+namespace nux
1795+{
1796+class AbstractPaintLayer;
1797+class StaticCairoText;
1798+class VLayout;
1799+}
1800+
1801+namespace unity
1802+{
1803+namespace dash
1804+{
1805+namespace previews
1806+{
1807+class CoverArt;
1808+class PreviewInfoHintWidget;
1809+
1810+class PaymentPreview : public Preview
1811+{
1812+public:
1813+ typedef nux::ObjectPtr<PaymentPreview> Ptr;
1814+
1815+ PaymentPreview(dash::Preview::Ptr preview_model);
1816+
1817+ // From debug::Introspectable
1818+ std::string GetName() const;
1819+
1820+ // Create and connect an action link to OnActionLinkActivated
1821+ nux::ObjectPtr<ActionLink> CreateLink(dash::Preview::ActionPtr action);
1822+
1823+ // Create and connect an action button OnActioButtonActivated
1824+ nux::ObjectPtr<ActionButton> CreateButton(dash::Preview::ActionPtr action);
1825+
1826+ void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
1827+ void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
1828+ void ShowOverlay(bool isShown);
1829+ void ShowOverlay();
1830+ void HideOverlay();
1831+
1832+private:
1833+
1834+protected:
1835+ GVariant *data_;
1836+
1837+ // build the header to be shown in the preview
1838+ nux::Layout* GetHeader();
1839+
1840+ // Return the title layout (including layout data) to be added to the header
1841+ // NULL is a possible return value.
1842+ virtual nux::Layout* GetTitle() = 0;
1843+
1844+ // Return the pize layout (including data) to be added to the header
1845+ // NULL is a possible return value.
1846+ virtual nux::Layout* GetPrice() = 0;
1847+
1848+ // Return layout with the content to show. NULL is a possible return value.
1849+ virtual nux::Layout* GetBody() = 0;
1850+
1851+ // Return layout with the content to show. NULL is a possible return value.
1852+ virtual nux::Layout* GetFooter() = 0;
1853+
1854+ // Executed when a link is clicked.
1855+ virtual void OnActionActivated(ActionButton* button, std::string const& id) = 0;
1856+
1857+ // Executed when a button is clicked.
1858+ virtual void OnActionLinkActivated(ActionLink* link, std::string const& id) = 0;
1859+
1860+ virtual void PreLayoutManagement() = 0;
1861+
1862+ virtual void LoadActions() = 0;
1863+ virtual void SetupViews();
1864+ virtual void SetupBackground();
1865+
1866+ nux::ObjectPtr<nux::LayeredLayout> full_data_layout_;
1867+ nux::ObjectPtr<nux::VLayout> content_data_layout_;
1868+ nux::ObjectPtr<nux::VLayout> overlay_layout_;
1869+ nux::ObjectPtr<nux::Layout> header_layout_;
1870+ nux::ObjectPtr<nux::Layout> body_layout_;
1871+ nux::ObjectPtr<nux::Layout> footer_layout_;
1872+
1873+ // content elements
1874+ nux::ObjectPtr<CoverArt> image_;
1875+
1876+ // do we want to type?
1877+ bool entry_selected_;
1878+
1879+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
1880+ LayerPtr details_bg_layer_;
1881+};
1882+
1883+}
1884+}
1885+}
1886+
1887+#endif // PAYMENT_PREVIEW_H
1888
1889=== modified file 'dash/previews/Preview.cpp'
1890--- dash/previews/Preview.cpp 2013-02-27 18:04:26 +0000
1891+++ dash/previews/Preview.cpp 2013-03-21 17:32:22 +0000
1892@@ -27,12 +27,15 @@
1893 #include <NuxCore/Logger.h>
1894 #include <Nux/HLayout.h>
1895 #include <Nux/VLayout.h>
1896+#include <UnityCore/PaymentPreview.h>
1897 #include "ActionButton.h"
1898
1899 #include "GenericPreview.h"
1900 #include "ApplicationPreview.h"
1901+#include "ErrorPreview.h"
1902 #include "MusicPreview.h"
1903 #include "MoviePreview.h"
1904+#include "MusicPaymentPreview.h"
1905 #include "SocialPreview.h"
1906 #include "PreviewInfoHintWidget.h"
1907
1908@@ -56,6 +59,19 @@
1909 {
1910 return Preview::Ptr(new GenericPreview(model));
1911 }
1912+ else if (model->renderer_name == "preview-payment")
1913+ {
1914+ dash::PaymentPreview* payment_preview_model = dynamic_cast<dash::PaymentPreview*>(
1915+ model.get());
1916+ if (payment_preview_model->preview_type.Get() == dash::PaymentPreview::MUSIC)
1917+ {
1918+ return Preview::Ptr(new MusicPaymentPreview(model));
1919+ }
1920+ else
1921+ {
1922+ return Preview::Ptr(new ErrorPreview(model));
1923+ }
1924+ }
1925 else if (model->renderer_name == "preview-application")
1926 {
1927 return Preview::Ptr(new ApplicationPreview(model));
1928@@ -129,7 +145,7 @@
1929 {
1930 nux::HLayout* actions_layout_h = new TabIteratorHLayout(tab_iterator_);
1931 actions_layout_h->SetSpaceBetweenChildren(style.GetSpaceBetweenActions());
1932-
1933+
1934 for (uint j = 0; j < 2 && action_iter < actions.size(); j++, action_iter++)
1935 {
1936 dash::Preview::ActionPtr action = actions[action_iter];
1937@@ -181,7 +197,7 @@
1938 {
1939 if (!preview_model_)
1940 return;
1941-
1942+
1943 previews::Style& style = dash::previews::Style::Instance();
1944
1945 auto on_mouse_down = [&](int x, int y, unsigned long button_flags, unsigned long key_flags) { this->preview_container_->OnMouseDown(x, y, button_flags, key_flags); };
1946
1947=== added file 'dash/previews/StandaloneErrorPreview.cpp'
1948--- dash/previews/StandaloneErrorPreview.cpp 1970-01-01 00:00:00 +0000
1949+++ dash/previews/StandaloneErrorPreview.cpp 2013-03-21 17:32:22 +0000
1950@@ -0,0 +1,219 @@
1951+/*
1952+ * Copyright 2012-2013 Canonical Ltd.
1953+ *
1954+ * This program is free software: you can redistribute it and/or modify it
1955+ * under the terms of the GNU General Public License version 3, as published
1956+ * by the Free Software Foundation.
1957+ *
1958+ * This program is distributed in the hope that it will be useful, but
1959+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1960+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
1961+ * PURPOSE. See the GNU General Public License for more details.
1962+ *
1963+ * You should have received a copy of the GNU General Public License
1964+ * version 3 along with this program. If not, see
1965+ * <http://www.gnu.org/licenses/>
1966+ *
1967+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
1968+ *
1969+ */
1970+
1971+#include <gtk/gtk.h>
1972+
1973+#include "Nux/Nux.h"
1974+#include "Nux/VLayout.h"
1975+#include "Nux/WindowThread.h"
1976+#include "NuxGraphics/GraphicsEngine.h"
1977+#include <Nux/Layout.h>
1978+#include <NuxCore/Logger.h>
1979+#include <UnityCore/Variant.h>
1980+#include <UnityCore/Preview.h>
1981+#include <unity-protocol.h>
1982+
1983+#include "unity-shared/FontSettings.h"
1984+#include "unity-shared/UnitySettings.h"
1985+#include "unity-shared/PreviewStyle.h"
1986+#include "unity-shared/DashStyle.h"
1987+#include "unity-shared/ThumbnailGenerator.h"
1988+
1989+#include "Preview.h"
1990+#include "PreviewContainer.h"
1991+
1992+
1993+#define WIDTH 1100
1994+#define HEIGHT 600
1995+
1996+using namespace unity;
1997+using namespace unity::dash;
1998+
1999+namespace
2000+{
2001+nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
2002+}
2003+
2004+class DummyView : public nux::View
2005+{
2006+public:
2007+ DummyView(nux::View* view)
2008+ : View(NUX_TRACKER_LOCATION)
2009+ {
2010+ SetAcceptKeyNavFocusOnMouseDown(false);
2011+ SetAcceptKeyNavFocusOnMouseEnter(false);
2012+
2013+ nux::ROPConfig rop;
2014+ rop.Blend = true;
2015+ rop.SrcBlend = GL_ONE;
2016+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
2017+ bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
2018+
2019+ nux::Layout* layout = new nux::VLayout();
2020+ layout->SetPadding(10);
2021+ layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
2022+ SetLayout(layout);
2023+ }
2024+
2025+ // Keyboard navigation
2026+ bool AcceptKeyNavFocus()
2027+ {
2028+ return false;
2029+ }
2030+
2031+protected:
2032+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
2033+ {
2034+ nux::Geometry const& base = GetGeometry();
2035+
2036+ gfx_engine.PushClippingRectangle(base);
2037+ nux::GetPainter().PaintBackground(gfx_engine, base);
2038+
2039+ unsigned int alpha, src, dest = 0;
2040+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
2041+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2042+
2043+ bg_layer_->SetGeometry(GetGeometry());
2044+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
2045+
2046+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
2047+
2048+ gfx_engine.PopClippingRectangle();
2049+ }
2050+
2051+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
2052+ {
2053+ nux::Geometry const& base = GetGeometry();
2054+ gfx_engine.PushClippingRectangle(base);
2055+
2056+ if (!IsFullRedraw())
2057+ nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
2058+
2059+ if (GetCompositionLayout())
2060+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
2061+
2062+ if (!IsFullRedraw())
2063+ nux::GetPainter().PopBackground();
2064+
2065+ gfx_engine.PopClippingRectangle();
2066+ }
2067+
2068+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
2069+ LayerPtr bg_layer_;
2070+};
2071+
2072+class TestRunner
2073+{
2074+public:
2075+ TestRunner ();
2076+ ~TestRunner ();
2077+
2078+ static void InitWindowThread (nux::NThread* thread, void* InitData);
2079+ void Init ();
2080+
2081+ previews::PreviewContainer::Ptr container_;
2082+ nux::Layout *layout_;
2083+ unsigned int nav_iter;
2084+ previews::Navigation nav_direction_;
2085+ std::string search_string_;
2086+ bool first_;
2087+};
2088+
2089+TestRunner::TestRunner ()
2090+{
2091+}
2092+
2093+TestRunner::~TestRunner ()
2094+{
2095+}
2096+
2097+void TestRunner::Init ()
2098+{
2099+ container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
2100+ container_->request_close.connect([&]() { exit(0); });
2101+ container_->DisableNavButton(previews::Navigation::BOTH);
2102+
2103+ DummyView* dummyView = new DummyView(container_.GetPointer());
2104+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
2105+ layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
2106+ nux::GetWindowThread()->SetLayout (layout_);
2107+
2108+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
2109+ unity_protocol_payment_preview_new()));
2110+
2111+ unity_protocol_preview_set_title(
2112+ proto_obj, "This Modern Glitch");
2113+ unity_protocol_preview_set_subtitle(
2114+ proto_obj, "The Wombats");
2115+ unity_protocol_payment_preview_set_header(
2116+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2117+ "A horrible error ocurred!!!");
2118+ unity_protocol_payment_preview_set_purchase_prize(
2119+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2120+ "10 eur");
2121+ unity_protocol_payment_preview_set_purchase_type(
2122+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2123+ "Digital CD");
2124+ unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2125+ UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR);
2126+
2127+ // set the diff actions
2128+ unity_protocol_preview_add_action(proto_obj, "open_u1_link", "Go to u1 page", NULL, 0);
2129+
2130+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
2131+ glib::StealRef());
2132+
2133+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
2134+ container_->Preview(preview_model, previews::Navigation::LEFT);
2135+}
2136+
2137+void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
2138+{
2139+ TestRunner *self = (TestRunner *) InitData;
2140+ self->Init ();
2141+}
2142+
2143+int main(int argc, char **argv)
2144+{
2145+ nux::WindowThread* wt = NULL;
2146+
2147+ gtk_init (&argc, &argv);
2148+
2149+ nux::NuxInitialize(0);
2150+ nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
2151+ // The instances for the pseudo-singletons.
2152+ unity::Settings settings;
2153+ unity::dash::previews::Style panel_style;
2154+ unity::dash::Style dash_style;
2155+ unity::ThumbnailGenerator thumbnail_generator;
2156+
2157+ TestRunner *test_runner = new TestRunner ();
2158+ wt = nux::CreateGUIThread(TEXT("Unity Preview"),
2159+ WIDTH, HEIGHT,
2160+ 0,
2161+ &TestRunner::InitWindowThread,
2162+ test_runner);
2163+
2164+ wt->Run (NULL);
2165+ delete wt;
2166+ return 0;
2167+}
2168+
2169+
2170
2171=== added file 'dash/previews/StandaloneMusicPaymentPreview.cpp'
2172--- dash/previews/StandaloneMusicPaymentPreview.cpp 1970-01-01 00:00:00 +0000
2173+++ dash/previews/StandaloneMusicPaymentPreview.cpp 2013-03-21 17:32:22 +0000
2174@@ -0,0 +1,223 @@
2175+/*
2176+ * Copyright 2012 Canonical Ltd.
2177+ *
2178+ * This program is free software: you can redistribute it and/or modify it
2179+ * under the terms of the GNU General Public License version 3, as published
2180+ * by the Free Software Foundation.
2181+ *
2182+ * This program is distributed in the hope that it will be useful, but
2183+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2184+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
2185+ * PURPOSE. See the GNU General Public License for more details.
2186+ *
2187+ * You should have received a copy of the GNU General Public License
2188+ * version 3 along with this program. If not, see
2189+ * <http://www.gnu.org/licenses/>
2190+ *
2191+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
2192+ *
2193+ */
2194+#include <gtk/gtk.h>
2195+
2196+#include "Nux/Nux.h"
2197+#include "Nux/VLayout.h"
2198+#include "Nux/WindowThread.h"
2199+#include "NuxGraphics/GraphicsEngine.h"
2200+#include <Nux/Layout.h>
2201+#include <NuxCore/Logger.h>
2202+#include <UnityCore/Variant.h>
2203+#include <UnityCore/Preview.h>
2204+#include <unity-protocol.h>
2205+
2206+#include "unity-shared/FontSettings.h"
2207+#include "unity-shared/UnitySettings.h"
2208+#include "unity-shared/PreviewStyle.h"
2209+#include "unity-shared/DashStyle.h"
2210+#include "unity-shared/ThumbnailGenerator.h"
2211+
2212+#include "Preview.h"
2213+#include "PreviewContainer.h"
2214+
2215+
2216+#define WIDTH 1100
2217+#define HEIGHT 600
2218+
2219+using namespace unity;
2220+using namespace unity::dash;
2221+
2222+namespace
2223+{
2224+nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
2225+}
2226+
2227+class DummyView : public nux::View
2228+{
2229+public:
2230+ DummyView(nux::View* view)
2231+ : View(NUX_TRACKER_LOCATION)
2232+ {
2233+ SetAcceptKeyNavFocusOnMouseDown(false);
2234+ SetAcceptKeyNavFocusOnMouseEnter(false);
2235+
2236+ nux::ROPConfig rop;
2237+ rop.Blend = true;
2238+ rop.SrcBlend = GL_ONE;
2239+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
2240+ bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
2241+
2242+ nux::Layout* layout = new nux::VLayout();
2243+ layout->SetPadding(10);
2244+ layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
2245+ SetLayout(layout);
2246+ }
2247+
2248+ // Keyboard navigation
2249+ bool AcceptKeyNavFocus()
2250+ {
2251+ return false;
2252+ }
2253+
2254+protected:
2255+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
2256+ {
2257+ nux::Geometry const& base = GetGeometry();
2258+
2259+ gfx_engine.PushClippingRectangle(base);
2260+ nux::GetPainter().PaintBackground(gfx_engine, base);
2261+
2262+ unsigned int alpha, src, dest = 0;
2263+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
2264+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
2265+
2266+ bg_layer_->SetGeometry(GetGeometry());
2267+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
2268+
2269+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
2270+
2271+ gfx_engine.PopClippingRectangle();
2272+ }
2273+
2274+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
2275+ {
2276+ nux::Geometry const& base = GetGeometry();
2277+ gfx_engine.PushClippingRectangle(base);
2278+
2279+ if (!IsFullRedraw())
2280+ nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
2281+
2282+ if (GetCompositionLayout())
2283+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
2284+
2285+ if (!IsFullRedraw())
2286+ nux::GetPainter().PopBackground();
2287+
2288+ gfx_engine.PopClippingRectangle();
2289+ }
2290+
2291+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
2292+ LayerPtr bg_layer_;
2293+};
2294+
2295+class TestRunner
2296+{
2297+public:
2298+ TestRunner ();
2299+ ~TestRunner ();
2300+
2301+ static void InitWindowThread (nux::NThread* thread, void* InitData);
2302+ void Init ();
2303+
2304+ previews::PreviewContainer::Ptr container_;
2305+ nux::Layout *layout_;
2306+ unsigned int nav_iter;
2307+ previews::Navigation nav_direction_;
2308+ std::string search_string_;
2309+ bool first_;
2310+};
2311+
2312+TestRunner::TestRunner ()
2313+{
2314+}
2315+
2316+TestRunner::~TestRunner ()
2317+{
2318+}
2319+
2320+void TestRunner::Init ()
2321+{
2322+ container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
2323+ container_->request_close.connect([&]() { exit(0); });
2324+ container_->DisableNavButton(previews::Navigation::BOTH);
2325+
2326+ DummyView* dummyView = new DummyView(container_.GetPointer());
2327+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
2328+ layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
2329+ nux::GetWindowThread()->SetLayout (layout_);
2330+
2331+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
2332+ unity_protocol_payment_preview_new()));
2333+
2334+ unity_protocol_preview_set_title(
2335+ proto_obj.RawPtr(), "This Modern Glitch");
2336+ unity_protocol_preview_set_subtitle(
2337+ proto_obj.RawPtr(), "The Wombats");
2338+ unity_protocol_payment_preview_set_header(
2339+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2340+ "Hi mandel, you purchased in the past from Ubuntu One, would you like to use the same payment details? Please review your order:");
2341+ unity_protocol_payment_preview_set_email(
2342+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2343+ "manuel@canonical.com");
2344+ unity_protocol_payment_preview_set_payment_method(
2345+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2346+ "***** *** **** 246");
2347+ unity_protocol_payment_preview_set_purchase_prize(
2348+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2349+ "10 eur");
2350+ unity_protocol_payment_preview_set_purchase_type(
2351+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
2352+ "Digital CD");
2353+
2354+ // set the diff actions
2355+ unity_protocol_preview_add_action(proto_obj, "purchase_album", "Buy Now", NULL, 0);
2356+ unity_protocol_preview_add_action(proto_obj, "cancel_purchase", "Cancel", NULL, 0);
2357+ unity_protocol_preview_add_action(proto_obj, "forgot_password", "forgotten your Ubuntu One password?", NULL, 0);
2358+ unity_protocol_preview_add_action(proto_obj, "change_payment_method", "change payment method", NULL, 0);
2359+
2360+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
2361+ glib::StealRef());
2362+
2363+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
2364+ container_->Preview(preview_model, previews::Navigation::LEFT);
2365+}
2366+
2367+void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
2368+{
2369+ TestRunner *self = (TestRunner *) InitData;
2370+ self->Init ();
2371+}
2372+
2373+int main(int argc, char **argv)
2374+{
2375+ nux::WindowThread* wt = NULL;
2376+
2377+ gtk_init (&argc, &argv);
2378+
2379+ nux::NuxInitialize(0);
2380+ nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
2381+ // The instances for the pseudo-singletons.
2382+ unity::Settings settings;
2383+ unity::dash::previews::Style panel_style;
2384+ unity::dash::Style dash_style;
2385+ unity::ThumbnailGenerator thumbnail_generator;
2386+
2387+ TestRunner *test_runner = new TestRunner ();
2388+ wt = nux::CreateGUIThread(TEXT("Unity Preview"),
2389+ WIDTH, HEIGHT,
2390+ 0,
2391+ &TestRunner::InitWindowThread,
2392+ test_runner);
2393+
2394+ wt->Run (NULL);
2395+ delete wt;
2396+ return 0;
2397+}
2398
2399=== added file 'resources/lock_icon.png'
2400Binary files resources/lock_icon.png 1970-01-01 00:00:00 +0000 and resources/lock_icon.png 2013-03-21 17:32:22 +0000 differ
2401=== modified file 'tests/CMakeLists.txt'
2402--- tests/CMakeLists.txt 2013-03-21 11:36:49 +0000
2403+++ tests/CMakeLists.txt 2013-03-21 17:32:22 +0000
2404@@ -244,6 +244,7 @@
2405 test_dash_controller.cpp
2406 test_desktop_launcher_icon.cpp
2407 test_device_launcher_section.cpp
2408+ test_error_preview.cpp
2409 test_edge_barrier_controller.cpp
2410 test_expo_launcher_icon.cpp
2411 test_filter_widgets.cpp
2412@@ -276,6 +277,8 @@
2413 test_previews_generic.cpp
2414 test_previews_movie.cpp
2415 test_previews_music.cpp
2416+ test_previews_music_payment.cpp
2417+ test_previews_payment.cpp
2418 test_previews_social.cpp
2419 test_overlay_scrollbar.cpp
2420 test_quicklist_manager.cpp
2421
2422=== added file 'tests/test_error_preview.cpp'
2423--- tests/test_error_preview.cpp 1970-01-01 00:00:00 +0000
2424+++ tests/test_error_preview.cpp 2013-03-21 17:32:22 +0000
2425@@ -0,0 +1,111 @@
2426+/*
2427+ * Copyright 2012-2013 Canonical Ltd.
2428+ *
2429+ * This program is free software: you can redistribute it and/or modify it
2430+ * under the terms of the GNU Lesser General Public License version 3, as
2431+ * published by the Free Software Foundation.
2432+ *
2433+ * This program is distributed in the hope that it will be useful, but
2434+ * WITHOUT ANY WARRANTY; without even the implied warranties of
2435+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
2436+ * PURPOSE. See the applicable version of the GNU Lesser General Public
2437+ * License for more details.
2438+ *
2439+ * You should have received a copy of both the GNU Lesser General Public
2440+ * License version 3 along with this program. If not, see
2441+ * <http://www.gnu.org/licenses/>
2442+ *
2443+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
2444+ *
2445+ */
2446+#include <list>
2447+#include <gmock/gmock.h>
2448+using namespace testing;
2449+
2450+#include <Nux/Nux.h>
2451+#include <Nux/BaseWindow.h>
2452+#include <unity-shared/StaticCairoText.h>
2453+#include <unity-shared/DashStyle.h>
2454+#include <unity-shared/PreviewStyle.h>
2455+#include <unity-shared/ThumbnailGenerator.h>
2456+#include "unity-shared/UnitySettings.h"
2457+
2458+#include <unity-protocol.h>
2459+#include "dash/previews/ErrorPreview.h"
2460+#include "test_utils.h"
2461+
2462+namespace unity
2463+{
2464+
2465+namespace dash
2466+{
2467+
2468+namespace previews
2469+{
2470+
2471+class ErrorPreviewMock : public ErrorPreview
2472+{
2473+ public:
2474+ ErrorPreviewMock(dash::Preview::Ptr preview_model)
2475+ : ErrorPreview(preview_model){}
2476+ ~ErrorPreviewMock(){}
2477+
2478+ using ErrorPreview::intro_;
2479+ using ErrorPreview::title_;
2480+ using ErrorPreview::subtitle_;
2481+ using ErrorPreview::purchase_hint_;
2482+ using ErrorPreview::purchase_prize_;
2483+ using ErrorPreview::purchase_type_;
2484+};
2485+
2486+class TestErrorPreview : public Test
2487+{
2488+ protected:
2489+ TestErrorPreview() :
2490+ Test(),
2491+ parent_window_(new nux::BaseWindow("TestErrorPayment"))
2492+ {
2493+ title = "Turning Japanese";
2494+ subtitle = "The vapors";
2495+ header = "Hi test, you purchased in the past from Ubuntu One.";
2496+ purchase_prize = "65$";
2497+ purchase_type = "Mp3";
2498+ preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR;
2499+
2500+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
2501+
2502+ unity_protocol_preview_set_title(proto_obj, title.c_str());
2503+ unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
2504+
2505+ unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
2506+ unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
2507+ unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
2508+ unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
2509+
2510+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
2511+
2512+ preview_model = dash::Preview::PreviewForVariant(v);
2513+
2514+ }
2515+
2516+ nux::ObjectPtr<nux::BaseWindow> parent_window_;
2517+ dash::Preview::Ptr preview_model;
2518+
2519+ // testing data
2520+ std::string title;
2521+ std::string subtitle;
2522+ std::string header;
2523+ std::string purchase_prize;
2524+ std::string purchase_type;
2525+ UnityProtocolPreviewPaymentType preview_type;
2526+
2527+ // needed for styles
2528+ unity::Settings settings;
2529+ dash::Style dash_style;
2530+};
2531+
2532+} // previews
2533+
2534+} // dash
2535+
2536+} // unity
2537
2538=== added file 'tests/test_previews_music_payment.cpp'
2539--- tests/test_previews_music_payment.cpp 1970-01-01 00:00:00 +0000
2540+++ tests/test_previews_music_payment.cpp 2013-03-21 17:32:22 +0000
2541@@ -0,0 +1,151 @@
2542+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2543+/*
2544+ * Copyright (C) 2012-2013 Canonical Ltd
2545+ *
2546+ * This program is free software: you can redistribute it and/or modify
2547+ * it under the terms of the GNU General Public License version 3 as
2548+ * published by the Free Software Foundation.
2549+ *
2550+ * This program is distributed in the hope that it will be useful,
2551+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2552+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2553+ * GNU General Public License for more details.
2554+ *
2555+ * You should have received a copy of the GNU General Public License
2556+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2557+ *
2558+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
2559+ */
2560+
2561+#include <list>
2562+#include <gmock/gmock.h>
2563+
2564+#include <Nux/Nux.h>
2565+#include <Nux/BaseWindow.h>
2566+#include <unity-shared/StaticCairoText.h>
2567+#include <unity-shared/CoverArt.h>
2568+#include <unity-shared/DashStyle.h>
2569+#include <unity-shared/PreviewStyle.h>
2570+#include <unity-shared/ThumbnailGenerator.h>
2571+#include "unity-shared/UnitySettings.h"
2572+
2573+#include <unity-protocol.h>
2574+#include "dash/previews/MusicPaymentPreview.h"
2575+#include "test_utils.h"
2576+
2577+using namespace testing;
2578+
2579+namespace unity
2580+{
2581+
2582+namespace dash
2583+{
2584+
2585+namespace previews
2586+{
2587+
2588+class MockedMusicPaymentPreview : public MusicPaymentPreview
2589+{
2590+public:
2591+ typedef nux::ObjectPtr<MockedMusicPaymentPreview> Ptr;
2592+
2593+ MockedMusicPaymentPreview(dash::Preview::Ptr preview_model)
2594+ : MusicPaymentPreview(preview_model)
2595+ {}
2596+
2597+ using MusicPaymentPreview::image_;
2598+ using MusicPaymentPreview::intro_;
2599+ using MusicPaymentPreview::title_;
2600+ using MusicPaymentPreview::subtitle_;
2601+ using MusicPaymentPreview::email_label_;
2602+ using MusicPaymentPreview::email_;
2603+ using MusicPaymentPreview::payment_label_;
2604+ using MusicPaymentPreview::payment_;
2605+ using MusicPaymentPreview::password_label_;
2606+ using MusicPaymentPreview::password_entry_;
2607+ using MusicPaymentPreview::purchase_hint_;
2608+ using MusicPaymentPreview::purchase_prize_;
2609+ using MusicPaymentPreview::purchase_type_;
2610+ using MusicPaymentPreview::change_payment_;
2611+ using MusicPaymentPreview::forgotten_password_;
2612+ using MusicPaymentPreview::error_label_;
2613+ using MusicPaymentPreview::form_layout_;
2614+ using MusicPaymentPreview::SetupViews;
2615+};
2616+
2617+class TestMusicPaymentPreview : public ::testing::Test
2618+{
2619+ protected:
2620+ TestMusicPaymentPreview() :
2621+ Test(),
2622+ parent_window_(new nux::BaseWindow("TestPreviewMusicPayment"))
2623+ {
2624+ title = "Turning Japanese";
2625+ subtitle = "The vapors";
2626+ header = "Hi test, you purchased in the past from Ubuntu One.";
2627+ email = "test@canonical.com";
2628+ payment_method = "*** *** ** 12";
2629+ purchase_prize = "65$";
2630+ purchase_type = "Mp3";
2631+ preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC;
2632+
2633+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
2634+
2635+ unity_protocol_preview_set_title(proto_obj, title.c_str());
2636+ unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
2637+ unity_protocol_preview_add_action(proto_obj, "change_payment_method", "Change payment", NULL, 0);
2638+ unity_protocol_preview_add_action(proto_obj, "forgot_password", "Forgot password", NULL, 0);
2639+ unity_protocol_preview_add_action(proto_obj, "cancel_purchase", "Cancel", NULL, 0);
2640+ unity_protocol_preview_add_action(proto_obj, "purchase_album", "Purchase", NULL, 0);
2641+
2642+
2643+ unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
2644+ unity_protocol_payment_preview_set_email(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), email.c_str());
2645+ unity_protocol_payment_preview_set_payment_method(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), payment_method.c_str());
2646+ unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
2647+ unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
2648+ unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
2649+
2650+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
2651+
2652+ preview_model = dash::Preview::PreviewForVariant(v);
2653+ }
2654+
2655+ nux::ObjectPtr<nux::BaseWindow> parent_window_;
2656+ dash::Preview::Ptr preview_model;
2657+
2658+ // testing data
2659+ std::string title;
2660+ std::string subtitle;
2661+ std::string header;
2662+ std::string email;
2663+ std::string payment_method;
2664+ std::string purchase_prize;
2665+ std::string purchase_type;
2666+ UnityProtocolPreviewPaymentType preview_type;
2667+
2668+ // needed for styles
2669+ unity::Settings settings;
2670+ dash::Style dash_style;
2671+
2672+};
2673+
2674+TEST_F(TestMusicPaymentPreview, TestContentLoading)
2675+{
2676+ MockedMusicPaymentPreview::Ptr preview_view(new MockedMusicPaymentPreview(preview_model));
2677+
2678+ EXPECT_EQ(preview_view->title_->GetText(), title);
2679+ EXPECT_EQ(preview_view->subtitle_->GetText(), subtitle);
2680+ EXPECT_EQ(preview_view->intro_->GetText(), header);
2681+ EXPECT_EQ(preview_view->email_->GetText(), email);
2682+ EXPECT_EQ(preview_view->payment_->GetText(), payment_method);
2683+ EXPECT_EQ(preview_view->purchase_type_->GetText(), purchase_type);
2684+ EXPECT_EQ(preview_view->purchase_prize_->GetText(), purchase_prize);
2685+}
2686+
2687+
2688+} // previews
2689+
2690+} // dash
2691+
2692+} // unity
2693
2694=== added file 'tests/test_previews_payment.cpp'
2695--- tests/test_previews_payment.cpp 1970-01-01 00:00:00 +0000
2696+++ tests/test_previews_payment.cpp 2013-03-21 17:32:22 +0000
2697@@ -0,0 +1,186 @@
2698+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2699+/*
2700+ * Copyright (C) 2012-2013 Canonical Ltd
2701+ *
2702+ * This program is free software: you can redistribute it and/or modify
2703+ * it under the terms of the GNU General Public License version 3 as
2704+ * published by the Free Software Foundation.
2705+ *
2706+ * This program is distributed in the hope that it will be useful,
2707+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
2708+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2709+ * GNU General Public License for more details.
2710+ *
2711+ * You should have received a copy of the GNU General Public License
2712+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
2713+ *
2714+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
2715+ */
2716+#include <list>
2717+#include <gmock/gmock.h>
2718+
2719+#include <Nux/Nux.h>
2720+#include <Nux/Layout.h>
2721+#include <Nux/VLayout.h>
2722+#include <Nux/BaseWindow.h>
2723+#include <unity-shared/StaticCairoText.h>
2724+#include <unity-shared/DashStyle.h>
2725+#include <unity-shared/PreviewStyle.h>
2726+#include <unity-shared/ThumbnailGenerator.h>
2727+#include <unity-shared/CoverArt.h>
2728+#include "unity-shared/UnitySettings.h"
2729+
2730+#include <unity-protocol.h>
2731+#include "dash/previews/PaymentPreview.h"
2732+#include "dash/previews/ActionButton.h"
2733+#include "dash/previews/ActionLink.h"
2734+#include "test_utils.h"
2735+
2736+using namespace testing;
2737+using ::testing::Return;
2738+
2739+namespace unity
2740+{
2741+
2742+namespace dash
2743+{
2744+
2745+namespace previews
2746+{
2747+
2748+class NonAbstractPreview : public PaymentPreview
2749+{
2750+public:
2751+ NonAbstractPreview(dash::Preview::Ptr preview_model)
2752+ : PaymentPreview(preview_model)
2753+ {}
2754+
2755+ virtual nux::Layout* GetTitle()
2756+ {
2757+ return new nux::VLayout();
2758+ }
2759+
2760+ virtual nux::Layout* GetPrice()
2761+ {
2762+ return new nux::VLayout();
2763+ }
2764+
2765+ virtual nux::Layout* GetBody()
2766+ {
2767+ return new nux::VLayout();
2768+ }
2769+
2770+ virtual nux::Layout* GetFooter()
2771+ {
2772+ return new nux::VLayout();
2773+ }
2774+
2775+ virtual void OnActionActivated(ActionButton* button, std::string const& id)
2776+ {
2777+ // do nothing
2778+ }
2779+
2780+ virtual void OnActionLinkActivated(ActionLink* link, std::string const& id)
2781+ {
2782+ // do nothing
2783+ }
2784+
2785+ virtual void PreLayoutManagement()
2786+ {
2787+ // do nothing
2788+ }
2789+
2790+ virtual void LoadActions()
2791+ {
2792+ // do nothing
2793+ }
2794+
2795+ using PaymentPreview::GetHeader;
2796+ using PaymentPreview::full_data_layout_;
2797+ using PaymentPreview::content_data_layout_;
2798+ using PaymentPreview::overlay_layout_;
2799+ using PaymentPreview::header_layout_;
2800+ using PaymentPreview::body_layout_;
2801+ using PaymentPreview::footer_layout_;
2802+ using PaymentPreview::SetupViews;
2803+
2804+};
2805+
2806+class MockedPaymentPreview : public NonAbstractPreview
2807+{
2808+public:
2809+ typedef nux::ObjectPtr<MockedPaymentPreview> Ptr;
2810+
2811+ MockedPaymentPreview(dash::Preview::Ptr preview_model)
2812+ : NonAbstractPreview(preview_model)
2813+ {}
2814+
2815+ // Mock methods that should be implemented so that we can assert that they are
2816+ // called in the correct moments.
2817+ MOCK_METHOD0(GetTitle, nux::Layout*());
2818+ MOCK_METHOD0(GetPrice, nux::Layout*());
2819+ MOCK_METHOD0(GetBody, nux::Layout*());
2820+ MOCK_METHOD0(GetFooter, nux::Layout*());
2821+ MOCK_METHOD2(OnActionActivated, void(unity::dash::ActionButton*, std::string));
2822+ MOCK_METHOD2(OnActionLinkActivated, void(unity::dash::ActionLink*, std::string));
2823+ MOCK_METHOD0(PreLayoutManagement, void());
2824+ MOCK_METHOD0(LoadActions, void());
2825+
2826+};
2827+
2828+class TestPaymentPreview : public ::testing::Test
2829+{
2830+ protected:
2831+ TestPaymentPreview() : Test()
2832+ {
2833+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
2834+ // we are not testing how the info is really used is more asserting the method calls, we do not add any data then
2835+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
2836+
2837+ preview_model = dash::Preview::PreviewForVariant(v);
2838+
2839+ preview = new MockedPaymentPreview(preview_model);
2840+
2841+ }
2842+ nux::ObjectPtr<MockedPaymentPreview> preview;
2843+ dash::Preview::Ptr preview_model;
2844+
2845+ // needed for styles
2846+ unity::Settings settings;
2847+ dash::Style dash_style;
2848+
2849+};
2850+
2851+TEST_F(TestPaymentPreview, GetHeaderCallsCorrectMethods)
2852+{
2853+ ON_CALL(*preview.GetPointer(), GetTitle()).WillByDefault(Return(new nux::VLayout()));
2854+ EXPECT_CALL(*preview.GetPointer(), GetTitle()).Times(1);
2855+
2856+ ON_CALL(*preview.GetPointer(), GetPrice()).WillByDefault(Return(new nux::VLayout()));
2857+ EXPECT_CALL(*preview.GetPointer(), GetPrice()).Times(1);
2858+
2859+ preview->GetHeader();
2860+}
2861+
2862+TEST_F(TestPaymentPreview, SetupViewsCallCorrectMethods)
2863+{
2864+ ON_CALL(*preview.GetPointer(), GetTitle()).WillByDefault(Return(new nux::VLayout()));
2865+ EXPECT_CALL(*preview.GetPointer(), GetTitle()).Times(1);
2866+
2867+ ON_CALL(*preview.GetPointer(), GetPrice()).WillByDefault(Return(new nux::VLayout()));
2868+ EXPECT_CALL(*preview.GetPointer(), GetPrice()).Times(1);
2869+
2870+ ON_CALL(*preview.GetPointer(), GetBody()).WillByDefault(Return(new nux::VLayout()));
2871+ EXPECT_CALL(*preview.GetPointer(), GetBody()).Times(1);
2872+
2873+ ON_CALL(*preview.GetPointer(), GetFooter()).WillByDefault(Return(new nux::VLayout()));
2874+ EXPECT_CALL(*preview.GetPointer(), GetFooter()).Times(1);
2875+
2876+ preview->SetupViews();
2877+}
2878+
2879+} // previews
2880+
2881+} // dash
2882+
2883+} // unity
2884
2885=== modified file 'unity-shared/PreviewStyle.cpp'
2886--- unity-shared/PreviewStyle.cpp 2012-11-29 10:19:01 +0000
2887+++ unity-shared/PreviewStyle.cpp 2013-03-21 17:32:22 +0000
2888@@ -292,6 +292,91 @@
2889 return 12;
2890 }
2891
2892+std::string Style::payment_title_font() const
2893+{
2894+ return "Ubuntu 22";
2895+}
2896+
2897+std::string Style::payment_subtitle_font() const
2898+{
2899+ return "Ubuntu 12.5";
2900+}
2901+
2902+std::string Style::payment_prize_title_font() const
2903+{
2904+ return "Ubuntu Bold 12.5";
2905+}
2906+
2907+std::string Style::payment_prize_subtitle_font() const
2908+{
2909+ return "Ubuntu 10";
2910+}
2911+
2912+std::string Style::payment_intro_font() const
2913+{
2914+ return "Ubuntu 11.5";
2915+}
2916+
2917+std::string Style::payment_form_labels_font() const
2918+{
2919+ return "Ubuntu 10";
2920+}
2921+
2922+std::string Style::payment_form_data_font() const
2923+{
2924+ return "Ubuntu Bold 10";
2925+}
2926+
2927+std::string Style::payment_form_actions_font() const
2928+{
2929+ return "Ubuntu 10";
2930+}
2931+
2932+std::string Style::payment_text_input_font() const
2933+{
2934+ return "Ubuntu 14";
2935+}
2936+
2937+nux::Color Style::payment_error_color() const
2938+{
2939+ return nux::Color(255, 0, 0);
2940+}
2941+
2942+int Style::GetPaymentIconAreaWidth() const
2943+{
2944+ return 64;
2945+}
2946+
2947+int Style::GetPaymentTextInputHeight() const
2948+{
2949+ return 40;
2950+}
2951+
2952+int Style::GetPaymentLockWidth() const
2953+{
2954+ return 22;
2955+}
2956+
2957+int Style::GetPaymentLockHeight() const
2958+{
2959+ return 22;
2960+}
2961+
2962+int Style::GetPaymentHeaderWidth() const
2963+{
2964+ return 850;
2965+}
2966+
2967+int Style::GetPaymentHeaderSpace() const
2968+{
2969+ return 0;
2970+}
2971+
2972+int Style::GetPaymentFormSpace() const
2973+{
2974+ return 5;
2975+}
2976+
2977 float Style::GetVideoImageAspectRatio() const
2978 {
2979 return float(540)/380;
2980@@ -401,6 +486,12 @@
2981 return pimpl->preview_pause_texture_.texture();
2982 }
2983
2984+nux::BaseTexture* Style::GetLockIcon()
2985+{
2986+ return nux::CreateTexture2DFromFile(
2987+ PKGDATADIR"/lock_icon.png", -1, true);
2988+}
2989+
2990 nux::BaseTexture* Style::GetSearchSpinIcon(int size)
2991 {
2992 return pimpl->preview_spin_texture_.texture(size);
2993
2994=== modified file 'unity-shared/PreviewStyle.h'
2995--- unity-shared/PreviewStyle.h 2012-11-29 10:19:01 +0000
2996+++ unity-shared/PreviewStyle.h 2013-03-21 17:32:22 +0000
2997@@ -25,7 +25,7 @@
2998
2999 #include <Nux/Nux.h>
3000 #include <Nux/View.h>
3001-
3002+
3003 #include <string>
3004 #include <memory>
3005
3006@@ -54,12 +54,12 @@
3007 public:
3008 Style();
3009 ~Style();
3010-
3011+
3012 static Style& Instance();
3013
3014 int GetNavigatorWidth() const;
3015 int GetNavigatorIconSize() const;
3016-
3017+
3018 int GetPreviewWidth() const;
3019 int GetPreviewHeight() const;
3020 int GetPreviewTopPadding() const;
3021@@ -123,7 +123,7 @@
3022
3023 int GetTrackHeight() const;
3024 ////////////////////////////////
3025-
3026+
3027 ////////////////////////////////
3028 // Movie Preview
3029 float GetVideoImageAspectRatio() const;
3030@@ -146,8 +146,33 @@
3031 nux::BaseTexture* GetNavRightIcon();
3032 nux::BaseTexture* GetPlayIcon();
3033 nux::BaseTexture* GetPauseIcon();
3034+ nux::BaseTexture* GetLockIcon();
3035 nux::BaseTexture* GetSearchSpinIcon(int size = -1);
3036-
3037+
3038+ ////////////////////////////////
3039+ // Payment Preview
3040+ std::string payment_title_font() const;
3041+ std::string payment_subtitle_font() const;
3042+ std::string payment_prize_title_font() const;
3043+ std::string payment_prize_subtitle_font() const;
3044+ std::string payment_intro_font() const;
3045+ std::string payment_form_labels_font() const;
3046+ std::string payment_form_data_font() const;
3047+ std::string payment_form_actions_font() const;
3048+ std::string payment_text_input_font() const;
3049+ nux::Color payment_error_color() const;
3050+
3051+
3052+ int GetPaymentIconAreaWidth() const;
3053+ int GetPaymentTextInputHeight() const;
3054+ int GetPaymentLockWidth() const;
3055+ int GetPaymentLockHeight() const;
3056+ int GetPaymentHeaderWidth() const;
3057+ int GetPaymentHeaderSpace() const;
3058+ int GetPaymentFormSpace() const;
3059+
3060+ /////////////////////////////////
3061+
3062 protected:
3063 class Impl;
3064 std::unique_ptr<Impl> pimpl;

Subscribers

People subscribed via source and target branches