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