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

Proposed by Manuel de la Peña
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
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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

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

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

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :
Download full text (4.0 KiB)

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

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

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

Please update all headers to include 2013 and your contact details

277 {
278 +
279 if (!preview_displaying_)

extra line.

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

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

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

What is sorted about a map ? ;)

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

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

should check if sorted_buttons_ contains the actions before adding them.

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

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

Read more...

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :
Download full text (4.8 KiB)

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

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

No problem.

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

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

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

No problem,

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

Read more...

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

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

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

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

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
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.

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

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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/CMakeLists.txt'
--- UnityCore/CMakeLists.txt 2013-03-19 14:05:51 +0000
+++ UnityCore/CMakeLists.txt 2013-03-21 17:32:22 +0000
@@ -45,6 +45,7 @@
45 ModelIterator.h45 ModelIterator.h
46 ModelRowAdaptor.h46 ModelRowAdaptor.h
47 ModelRowAdaptor-inl.h47 ModelRowAdaptor-inl.h
48 PaymentPreview.h
48 Preview.h49 Preview.h
49 PreviewPlayer.h50 PreviewPlayer.h
50 RadioOptionFilter.h51 RadioOptionFilter.h
@@ -89,6 +90,7 @@
89 MultiRangeFilter.cpp90 MultiRangeFilter.cpp
90 MusicPreview.cpp91 MusicPreview.cpp
91 ModelRowAdaptor.cpp92 ModelRowAdaptor.cpp
93 PaymentPreview.cpp
92 Preview.cpp94 Preview.cpp
93 PreviewPlayer.cpp95 PreviewPlayer.cpp
94 RatingsFilter.cpp96 RatingsFilter.cpp
9597
=== added file 'UnityCore/PaymentPreview.cpp'
--- UnityCore/PaymentPreview.cpp 1970-01-01 00:00:00 +0000
+++ UnityCore/PaymentPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,120 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011-2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 */
19
20#include <unity-protocol.h>
21
22#include "PaymentPreview.h"
23
24namespace unity
25{
26namespace dash
27{
28
29class PaymentPreview::Impl
30{
31
32public:
33 Impl(PaymentPreview* owner, glib::Object<GObject> const& proto_obj);
34
35 void SetupGetters();
36
37 // getters for the data properties
38
39 std::string get_header() const { return header_; };
40 std::string get_email() const { return email_; };
41 std::string get_payment_method() const { return payment_method_; };
42 std::string get_purchase_prize() const { return purchase_prize_; };
43 std::string get_purchase_type() const { return purchase_type_; };
44 PreviewType get_preview_type() const { return preview_type_; };
45
46 // getters for the lables
47
48 // instance vars
49 PaymentPreview* owner_;
50
51 std::string header_;
52 std::string email_;
53 std::string payment_method_;
54 std::string purchase_prize_;
55 std::string purchase_type_;
56 PaymentPreview::PreviewType preview_type_;
57
58};
59
60PaymentPreview::Impl::Impl(PaymentPreview* owner, glib::Object<GObject> const& proto_obj)
61 : owner_(owner)
62{
63 const gchar* s;
64 auto preview = glib::object_cast<UnityProtocolPaymentPreview>(proto_obj);
65
66 s = unity_protocol_payment_preview_get_header(preview);
67 if (s) header_ = s;
68 s = unity_protocol_payment_preview_get_email(preview);
69 if (s) email_ = s;
70 s = unity_protocol_payment_preview_get_email(preview);
71 if (s) email_ = s;
72 s = unity_protocol_payment_preview_get_payment_method(preview);
73 if (s) payment_method_ = s;
74 s = unity_protocol_payment_preview_get_purchase_prize(preview);
75 if (s) purchase_prize_ = s;
76 s = unity_protocol_payment_preview_get_purchase_type(preview);
77 if (s) purchase_type_ = s;
78 UnityProtocolPreviewPaymentType t = unity_protocol_payment_preview_get_preview_type(preview);
79 switch(t)
80 {
81 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_APPLICATION:
82 preview_type_ = PaymentPreview::APPLICATION;
83 break;
84 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC:
85 preview_type_ = PaymentPreview::MUSIC;
86 break;
87 case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR:
88 preview_type_ = PaymentPreview::ERROR;
89 break;
90 }
91 SetupGetters();
92}
93
94void PaymentPreview::Impl::SetupGetters()
95{
96 owner_->header.SetGetterFunction(
97 sigc::mem_fun(this, &PaymentPreview::Impl::get_header));
98 owner_->email.SetGetterFunction(
99 sigc::mem_fun(this, &PaymentPreview::Impl::get_email));
100 owner_->payment_method.SetGetterFunction(
101 sigc::mem_fun(this, &PaymentPreview::Impl::get_payment_method));
102 owner_->purchase_prize.SetGetterFunction(
103 sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_prize));
104 owner_->preview_type.SetGetterFunction(
105 sigc::mem_fun(this, &PaymentPreview::Impl::get_preview_type));
106}
107
108PaymentPreview::PaymentPreview(unity::glib::Object<GObject> const& proto_obj)
109 : Preview(proto_obj)
110 , pimpl(new Impl(this, proto_obj))
111{
112}
113
114PaymentPreview::~PaymentPreview()
115{
116}
117
118
119}
120}
0121
=== added file 'UnityCore/PaymentPreview.h'
--- UnityCore/PaymentPreview.h 1970-01-01 00:00:00 +0000
+++ UnityCore/PaymentPreview.h 2013-03-21 17:32:22 +0000
@@ -0,0 +1,62 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2011-2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 */
19
20#ifndef UNITY_PAYMENT_PREVIEW_PREVIEW_H
21#define UNITY_PAYMENT_PREVIEW_PREVIEW_H
22
23#include <memory>
24
25#include <sigc++/trackable.h>
26
27#include "Preview.h"
28
29namespace unity
30{
31namespace dash
32{
33
34class PaymentPreview : public Preview
35{
36public:
37 enum PreviewType { APPLICATION, MUSIC, ERROR };
38
39 typedef std::shared_ptr<PaymentPreview> Ptr;
40
41 PaymentPreview(unity::glib::Object<GObject> const& proto_obj);
42 ~PaymentPreview();
43
44 // properties that contain the data
45 nux::RWProperty<std::string> title;
46 nux::RWProperty<std::string> subtitle;
47 nux::RWProperty<std::string> header;
48 nux::RWProperty<std::string> email;
49 nux::RWProperty<std::string> payment_method;
50 nux::RWProperty<std::string> purchase_prize;
51 nux::RWProperty<std::string> purchase_type;
52 nux::RWProperty<PaymentPreview::PreviewType> preview_type;
53
54private:
55 class Impl;
56 std::unique_ptr<Impl> pimpl;
57};
58
59}
60}
61
62#endif
063
=== modified file 'UnityCore/Preview.cpp'
--- UnityCore/Preview.cpp 2013-02-27 18:04:26 +0000
+++ UnityCore/Preview.cpp 2013-03-21 17:32:22 +0000
@@ -1,6 +1,6 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*2/*
3 * Copyright (C) 2011-2012 Canonical Ltd3 * Copyright (C) 2011-2013 Canonical Ltd
4 *4 *
5 * This program is free software: you can redistribute it and/or modify5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as6 * it under the terms of the GNU General Public License version 3 as
@@ -16,6 +16,7 @@
16 *16 *
17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>17 * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
18 * Michal Hruby <michal.hruby@canonical.com>18 * Michal Hruby <michal.hruby@canonical.com>
19 * Manuel de la Pena <manuel.delapena@canonical.com>
19 */20 */
2021
21#include <NuxCore/Logger.h>22#include <NuxCore/Logger.h>
@@ -28,6 +29,7 @@
28#include "GenericPreview.h"29#include "GenericPreview.h"
29#include "MusicPreview.h"30#include "MusicPreview.h"
30#include "MoviePreview.h"31#include "MoviePreview.h"
32#include "PaymentPreview.h"
31#include "SocialPreview.h"33#include "SocialPreview.h"
3234
33namespace unity35namespace unity
@@ -50,23 +52,27 @@
5052
51 if (renderer_name == "preview-generic")53 if (renderer_name == "preview-generic")
52 {54 {
53 return Preview::Ptr(new GenericPreview(proto_obj));55 return std::make_shared<GenericPreview>(proto_obj);
56 }
57 else if (renderer_name == "preview-payment")
58 {
59 return std::make_shared<PaymentPreview>(proto_obj);
54 }60 }
55 else if (renderer_name == "preview-application")61 else if (renderer_name == "preview-application")
56 {62 {
57 return Preview::Ptr(new ApplicationPreview(proto_obj));63 return std::make_shared<ApplicationPreview>(proto_obj);
58 }64 }
59 else if (renderer_name == "preview-music")65 else if (renderer_name == "preview-music")
60 {66 {
61 return Preview::Ptr(new MusicPreview(proto_obj));67 return std::make_shared<MusicPreview>(proto_obj);
62 }68 }
63 else if (renderer_name == "preview-movie")69 else if (renderer_name == "preview-movie")
64 {70 {
65 return Preview::Ptr(new MoviePreview(proto_obj));71 return std::make_shared<MoviePreview>(proto_obj);
66 }72 }
67 else if (renderer_name == "preview-social")73 else if (renderer_name == "preview-social")
68 {74 {
69 return Preview::Ptr(new SocialPreview(proto_obj));75 return std::make_shared<SocialPreview>(proto_obj);
70 }76 }
71 else77 else
72 {78 {
@@ -166,7 +172,7 @@
166 static_cast<LayoutHint>(raw_action->layout_hint),172 static_cast<LayoutHint>(raw_action->layout_hint),
167 raw_action->hints));173 raw_action->hints));
168 }174 }
169 175
170 int info_hints_len;176 int info_hints_len;
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);
172 for (int i = 0; i < info_hints_len; i++)178 for (int i = 0; i < info_hints_len; i++)
173179
=== modified file 'UnityCore/Preview.h'
--- UnityCore/Preview.h 2013-02-27 18:04:26 +0000
+++ UnityCore/Preview.h 2013-03-21 17:32:22 +0000
@@ -95,7 +95,7 @@
95 unity::glib::Variant value;95 unity::glib::Variant value;
9696
97 InfoHint() {};97 InfoHint() {};
98 InfoHint(const gchar* id_, const gchar* display_name_, 98 InfoHint(const gchar* id_, const gchar* display_name_,
99 const gchar* icon_hint_, GVariant* value_)99 const gchar* icon_hint_, GVariant* value_)
100 : id(id_ != NULL ? id_ : "")100 : id(id_ != NULL ? id_ : "")
101 , display_name(display_name_ != NULL ? display_name_ : "")101 , display_name(display_name_ != NULL ? display_name_ : "")
102102
=== modified file 'dash/DashView.cpp'
--- dash/DashView.cpp 2013-03-20 16:56:53 +0000
+++ dash/DashView.cpp 2013-03-21 17:32:22 +0000
@@ -30,6 +30,7 @@
30#include <NuxCore/Logger.h>30#include <NuxCore/Logger.h>
31#include <UnityCore/GLibWrapper.h>31#include <UnityCore/GLibWrapper.h>
32#include <UnityCore/RadioOptionFilter.h>32#include <UnityCore/RadioOptionFilter.h>
33#include <UnityCore/PaymentPreview.h>
3334
34#include "unity-shared/DashStyle.h"35#include "unity-shared/DashStyle.h"
35#include "unity-shared/KeyboardUtil.h"36#include "unity-shared/KeyboardUtil.h"
@@ -1217,7 +1218,15 @@
1217 // Hook up to the new preview infrastructure1218 // Hook up to the new preview infrastructure
1218 scope->preview_ready.connect([&] (LocalResult const& result, Preview::Ptr model)1219 scope->preview_ready.connect([&] (LocalResult const& result, Preview::Ptr model)
1219 {1220 {
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
1222 // an ActionResponse and therefore transition does not work, this hack allows
1223 // to set the navigation mode to ensure that we have a nice transition
1224 if (dynamic_cast<PaymentPreview*>(model.get()) != NULL)
1225 {
1226 preview_state_machine_.left_results.Set(0);
1227 preview_state_machine_.right_results.Set(0);
1228 preview_navigation_mode_ = previews::Navigation::RIGHT;
1229 }
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.
1222 });1231 });
12231232
@@ -1619,7 +1628,7 @@
1619 }1628 }
1620 }1629 }
16211630
1622 if (search_key || search_bar_->im_preedit)1631 if (!preview_displaying_ && (search_key || search_bar_->im_preedit))
1623 {1632 {
1624 // then send the event to the search entry1633 // then send the event to the search entry
1625 return search_bar_->text_entry();1634 return search_bar_->text_entry();
16261635
=== modified file 'dash/previews/CMakeLists.txt'
--- dash/previews/CMakeLists.txt 2013-01-18 16:02:50 +0000
+++ dash/previews/CMakeLists.txt 2013-03-21 17:32:22 +0000
@@ -23,6 +23,7 @@
23 GenericPreview.cpp23 GenericPreview.cpp
24 MusicPreview.cpp24 MusicPreview.cpp
25 MoviePreview.cpp25 MoviePreview.cpp
26 PaymentPreview.cpp
26 Preview.cpp27 Preview.cpp
27 PreviewContainer.cpp28 PreviewContainer.cpp
28 PreviewInfoHintWidget.cpp29 PreviewInfoHintWidget.cpp
@@ -34,6 +35,8 @@
34 TabIterator.cpp35 TabIterator.cpp
35 Track.cpp36 Track.cpp
36 Tracks.cpp37 Tracks.cpp
38 MusicPaymentPreview.cpp
39 ErrorPreview.cpp
37 )40 )
3841
39add_library (previews-lib STATIC ${PREVIEWS_SOURCES})42add_library (previews-lib STATIC ${PREVIEWS_SOURCES})
@@ -41,26 +44,40 @@
41target_link_libraries (previews-lib unity-shared)44target_link_libraries (previews-lib unity-shared)
42add_pch(pch/previews_pch.hh previews-lib)45add_pch(pch/previews_pch.hh previews-lib)
4346
44# 47#
45# Application Standalone variant48# Application Standalone variant
46#49#
47add_executable (app_previews StandaloneApplicationPreview.cpp)50add_executable (app_previews StandaloneApplicationPreview.cpp)
48target_link_libraries (app_previews previews-lib unity-shared)51target_link_libraries (app_previews previews-lib unity-shared)
4952
50# 53#
51# Music Standalone variant54# Music Standalone variant
52#55#
53add_executable (music_previews StandaloneMusicPreview.cpp)56add_executable (music_previews StandaloneMusicPreview.cpp)
54target_link_libraries (music_previews previews-lib unity-shared)57target_link_libraries (music_previews previews-lib unity-shared)
5558
56# 59#
57# Social Standalone variant60# Social Standalone variant
58#61#
59add_executable (social_previews StandaloneSocialPreview.cpp)62add_executable (social_previews StandaloneSocialPreview.cpp)
60target_link_libraries (social_previews previews-lib unity-shared)63target_link_libraries (social_previews previews-lib unity-shared)
6164
62# 65#
63# Music Standalone variant66# Movie Standalone variant
64#67#
65add_executable (movie_previews StandaloneMoviePreview.cpp)68add_executable (movie_previews StandaloneMoviePreview.cpp)
66target_link_libraries (movie_previews previews-lib unity-shared)69target_link_libraries (movie_previews previews-lib unity-shared)
70
71#
72# Payment Standalone variant
73#
74add_executable (payment_previews StandaloneMusicPaymentPreview.cpp)
75add_dependencies (payment_previews previews-lib)
76target_link_libraries (payment_previews previews-lib unity-shared)
77
78#
79# Error Standalone variant
80#
81add_executable (error_previews StandaloneErrorPreview.cpp)
82add_dependencies (error_previews previews-lib)
83target_link_libraries (error_previews previews-lib unity-shared)
6784
=== added file 'dash/previews/ErrorPreview.cpp'
--- dash/previews/ErrorPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/ErrorPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,246 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23
24#include "unity-shared/IntrospectableWrappers.h"
25#include "unity-shared/PreviewStyle.h"
26#include "unity-shared/CoverArt.h"
27#include "unity-shared/StaticCairoText.h"
28#include "unity-shared/PlacesVScrollBar.h"
29#include <NuxCore/Logger.h>
30#include <Nux/VLayout.h>
31#include <Nux/HLayout.h>
32#include <Nux/GridHLayout.h>
33#include <Nux/AbstractButton.h>
34
35#include "ErrorPreview.h"
36#include "PreviewInfoHintWidget.h"
37
38#include "stdio.h"
39#include "config.h"
40
41namespace unity
42{
43namespace dash
44{
45namespace previews
46{
47
48namespace
49{
50nux::logging::Logger logger("unity.dash.previews.ErrorPreview");
51
52}
53
54class DetailsScrollView : public nux::ScrollView
55{
56public:
57 DetailsScrollView(NUX_FILE_LINE_PROTO)
58 : ScrollView(NUX_FILE_LINE_PARAM)
59 {
60 SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
61 }
62
63};
64
65NUX_IMPLEMENT_OBJECT_TYPE(ErrorPreview)
66
67ErrorPreview::ErrorPreview(dash::Preview::Ptr preview_model)
68: PaymentPreview(preview_model)
69{
70 PaymentPreview::SetupBackground();
71 SetupViews();
72}
73
74ErrorPreview::~ErrorPreview()
75{
76}
77
78nux::Area* ErrorPreview::FindKeyFocusArea(unsigned int key_symbol,
79 unsigned long x11_key_code,
80 unsigned long special_keys_state)
81{
82 return Preview::FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
83}
84
85std::string ErrorPreview::GetName() const
86{
87 return "ErrorPreview";
88}
89
90void ErrorPreview::OnActionActivated(ActionButton* button, std::string const& id)
91{
92}
93
94void ErrorPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
95{
96 if (preview_model_)
97 preview_model_->PerformAction(id);
98}
99
100void ErrorPreview::LoadActions()
101{
102 // Loop over the buttons and add them to the correct var
103 // this is not efficient but is the only way we have atm
104 for (dash::Preview::ActionPtr action : preview_model_->GetActions())
105 {
106 const char *action_id = action->id.c_str();
107 if(strcmp(OPEN_U1_LINK_ACTION, action_id) == 0)
108 {
109 nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
110 link->activate.connect(sigc::mem_fun(this,
111 &ErrorPreview::OnActionLinkActivated));
112
113 std::pair<std::string, nux::ObjectPtr<nux::AbstractButton>> data (action->id, link);
114 sorted_buttons_.insert(data);
115 }
116 LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
117 }
118}
119
120nux::Layout* ErrorPreview::GetTitle()
121{
122 previews::Style& style = dash::previews::Style::Instance();
123 nux::VLayout* title_data_layout = new nux::VLayout();
124 title_data_layout->SetMaximumHeight(76);
125 title_data_layout->SetSpaceBetweenChildren(10);
126
127 title_ = new StaticCairoText(
128 preview_model_->title.Get(), true,
129 NUX_TRACKER_LOCATION);
130
131 title_->SetFont(style.payment_title_font().c_str());
132 title_->SetLines(-1);
133 title_->SetFont(style.title_font().c_str());
134 title_data_layout->AddView(title_.GetPointer(), 1);
135
136 subtitle_ = new StaticCairoText(
137 preview_model_->subtitle.Get(), true,
138 NUX_TRACKER_LOCATION);
139 subtitle_->SetLines(-1);
140 subtitle_->SetFont(style.payment_subtitle_font().c_str());
141 title_data_layout->AddView(subtitle_.GetPointer(), 1);
142 title_data_layout->AddSpace(1, 1);
143 return title_data_layout;
144}
145
146nux::Layout* ErrorPreview::GetPrice()
147{
148 previews::Style& style = dash::previews::Style::Instance();
149 nux::VLayout *prize_data_layout = new nux::VLayout();
150 prize_data_layout->SetMaximumHeight(76);
151 prize_data_layout->SetSpaceBetweenChildren(5);
152
153 purchase_prize_ = new StaticCairoText(
154 error_preview_model_->purchase_prize.Get(), true,
155 NUX_TRACKER_LOCATION);
156 purchase_prize_->SetLines(-1);
157 purchase_prize_->SetFont(style.payment_prize_title_font().c_str());
158 prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
159 nux::MINOR_POSITION_END);
160
161 purchase_hint_ = new StaticCairoText(
162 _("Ubuntu One best offer"),
163 true, NUX_TRACKER_LOCATION);
164 purchase_hint_->SetLines(-1);
165 purchase_hint_->SetFont(style.payment_prize_subtitle_font().c_str());
166 prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
167 nux::MINOR_POSITION_END);
168
169 purchase_type_ = new StaticCairoText(
170 error_preview_model_->purchase_type.Get(), true,
171 NUX_TRACKER_LOCATION);
172 purchase_type_->SetLines(-1);
173 purchase_type_->SetFont(style.payment_prize_subtitle_font().c_str());
174 prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
175 nux::MINOR_POSITION_END);
176 return prize_data_layout;
177}
178
179nux::Layout* ErrorPreview::GetBody()
180{
181 previews::Style& style = dash::previews::Style::Instance();
182 nux::HLayout *body_layout = new nux::HLayout();
183
184 lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
185 style.GetPaymentLockHeight());
186
187 intro_ = new StaticCairoText(
188 error_preview_model_->header.Get(), true,
189 NUX_TRACKER_LOCATION);
190 intro_->SetMaximumWidth(style.GetPaymentHeaderWidth());
191 intro_->SetFont(style.payment_intro_font().c_str());
192 intro_->SetLineSpacing(10);
193 intro_->SetLines(-style.GetDescriptionLineCount());
194 intro_->SetMinimumHeight(50);
195 body_layout->AddView(sorted_buttons_[OPEN_U1_LINK_ACTION].GetPointer(),
196 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
197 nux::NUX_LAYOUT_END);
198 body_layout->AddView(lock_texture_, 0, nux::MINOR_POSITION_CENTER,
199 nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
200 body_layout->AddView(intro_.GetPointer(), 1);
201 return body_layout;
202}
203
204nux::Layout* ErrorPreview::GetFooter()
205{
206 nux::HLayout* buttons_data_layout = new nux::HLayout();
207 return buttons_data_layout;
208}
209
210void ErrorPreview::PreLayoutManagement()
211{
212 nux::Geometry geo = GetGeometry();
213 GetLayout()->SetGeometry(geo);
214
215 previews::Style& style = dash::previews::Style::Instance();
216
217 int width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
218
219 if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
220 if(header_layout_) { header_layout_->SetMaximumWidth(width); }
221 if(intro_) { intro_->SetMaximumWidth(width); }
222 if(form_layout_) { form_layout_->SetMaximumWidth(width); }
223 if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
224
225 Preview::PreLayoutManagement();
226}
227
228void ErrorPreview::SetupViews()
229{
230 error_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
231 if (!error_preview_model_)
232 {
233 LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
234 return;
235 }
236
237 // load the buttons so that they can be accessed in order
238 LoadActions();
239
240 PaymentPreview::SetupViews();
241}
242
243
244}
245}
246}
0247
=== added file 'dash/previews/ErrorPreview.h'
--- dash/previews/ErrorPreview.h 1970-01-01 00:00:00 +0000
+++ dash/previews/ErrorPreview.h 2013-03-21 17:32:22 +0000
@@ -0,0 +1,119 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23
24#ifndef ERROR_PREVIEW_H
25#define ERROR_PREVIEW_H
26
27// key used to find the correct info hint
28#define ERROR_INFOHINT_ID "error_preview"
29
30// keys of the data preview
31// Necessary??
32#define DATA_MESSAGE_KEY "message"
33
34// ations ids
35#define OPEN_U1_LINK_ACTION "open_u1_link"
36
37#include <Nux/Nux.h>
38#include <Nux/AbstractButton.h>
39#include <UnityCore/Lens.h>
40#include "ActionButton.h"
41#include "ActionLink.h"
42#include "PaymentPreview.h"
43#include "unity-shared/IconTexture.h"
44#include "unity-shared/TextInput.h"
45
46namespace nux
47{
48class AbstractPaintLayer;
49class StaticCairoText;
50class VLayout;
51}
52
53namespace unity
54{
55namespace dash
56{
57namespace previews
58{
59class CoverArt;
60class PreviewInfoHintWidget;
61
62class ErrorPreview : public PaymentPreview
63{
64public:
65 typedef nux::ObjectPtr<ErrorPreview> Ptr;
66 NUX_DECLARE_OBJECT_TYPE(ErrorPreview, Preview)
67
68 ErrorPreview(dash::Preview::Ptr preview_model);
69 ~ErrorPreview();
70
71 nux::Area* FindKeyFocusArea(unsigned int key_symbol,
72 unsigned long x11_key_code,
73 unsigned long special_keys_state);
74 // From debug::Introspectable
75 std::string GetName() const;
76 nux::Layout* GetTitle();
77 nux::Layout* GetPrice();
78 nux::Layout* GetBody();
79 nux::Layout* GetFooter();
80
81private:
82 void LoadActions();
83
84protected:
85 void OnActionActivated(ActionButton* button, std::string const& id);
86 void OnActionLinkActivated(ActionLink* link, std::string const& id);
87
88 void PreLayoutManagement();
89
90 virtual void SetupViews();
91 // content elements
92 nux::ObjectPtr<CoverArt> image_;
93 nux::ObjectPtr<StaticCairoText> intro_;
94 nux::ObjectPtr<StaticCairoText> title_;
95 nux::ObjectPtr<StaticCairoText> subtitle_;
96 nux::ObjectPtr<StaticCairoText> purchase_hint_;
97 nux::ObjectPtr<StaticCairoText> purchase_prize_;
98 nux::ObjectPtr<StaticCairoText> purchase_type_;
99 nux::ObjectPtr<nux::HLayout> form_layout_;
100
101 dash::PaymentPreview* error_preview_model_;
102 // do we want to type?
103 bool entry_selected_;
104
105 // actions
106 std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> sorted_buttons_;
107
108 // lock texture
109 IconTexture* lock_texture_;
110
111 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
112 LayerPtr details_bg_layer_;
113};
114
115}
116}
117}
118
119#endif // ERROR_PREVIEW_H
0120
=== added file 'dash/previews/MusicPaymentPreview.cpp'
--- dash/previews/MusicPaymentPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/MusicPaymentPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,459 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
20 *
21 */
22
23#include "unity-shared/IntrospectableWrappers.h"
24#include "unity-shared/PreviewStyle.h"
25#include "unity-shared/CoverArt.h"
26#include "unity-shared/StaticCairoText.h"
27#include "unity-shared/PlacesVScrollBar.h"
28#include "config.h"
29
30#include <glib/gi18n-lib.h>
31#include <NuxCore/Logger.h>
32#include <Nux/VLayout.h>
33#include <Nux/GridHLayout.h>
34#include <Nux/AbstractButton.h>
35
36#include "MusicPaymentPreview.h"
37#include "PreviewInfoHintWidget.h"
38
39#include "stdio.h"
40
41namespace unity
42{
43namespace dash
44{
45namespace previews
46{
47
48namespace
49{
50nux::logging::Logger logger("unity.dash.previews.payment.preview.music");
51
52}
53
54// static string definitions
55const std::string MusicPaymentPreview::DATA_INFOHINT_ID = "album_purchase_preview";
56const std::string MusicPaymentPreview::DATA_PASSWORD_KEY = "password";
57const std::string MusicPaymentPreview::CHANGE_PAYMENT_ACTION = "change_payment_method";
58const std::string MusicPaymentPreview::FORGOT_PASSWORD_ACTION = "forgot_password";
59const std::string MusicPaymentPreview::CANCEL_PURCHASE_ACTION = "cancel_purchase";
60const std::string MusicPaymentPreview::PURCHASE_ALBUM_ACTION = "purchase_album";
61
62class DetailsScrollView : public nux::ScrollView
63{
64public:
65 DetailsScrollView(NUX_FILE_LINE_PROTO)
66 : ScrollView(NUX_FILE_LINE_PARAM)
67 {
68 SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
69 }
70
71};
72
73NUX_IMPLEMENT_OBJECT_TYPE(MusicPaymentPreview)
74
75MusicPaymentPreview::MusicPaymentPreview(dash::Preview::Ptr preview_model)
76: PaymentPreview(preview_model)
77{
78 SetupViews();
79 PaymentPreview::SetupBackground();
80}
81
82std::string MusicPaymentPreview::GetName() const
83{
84 return "MusicPaymentPreview";
85}
86
87void MusicPaymentPreview::OnActionActivated(ActionButton* button, std::string const& id)
88{
89 // Check the action id and send the password only when we
90 // purchasing a song
91 if(id == MusicPaymentPreview::PURCHASE_ALBUM_ACTION && preview_model_
92 && password_entry_)
93 {
94 // HACK: We need to think a better way to do this
95 auto const& password = password_entry_->text_entry()->GetText();
96 glib::Variant variant_pw(g_variant_new_string(password.c_str()));
97 Lens::Hints hints {
98 std::make_pair(MusicPaymentPreview::DATA_PASSWORD_KEY, variant_pw)
99 };
100 preview_model_->PerformAction(id, hints);
101
102 // show the overlay
103 ShowOverlay();
104 return;
105 }
106 Preview::OnActionActivated(button, id);
107}
108
109void MusicPaymentPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
110{
111 if (preview_model_)
112 preview_model_->PerformAction(id);
113}
114
115void MusicPaymentPreview::LoadActions()
116{
117 // Loop over the buttons and add them to the correct var
118 // this is not efficient but is the only way we have atm
119 for (dash::Preview::ActionPtr action : preview_model_->GetActions())
120 {
121 const char *action_id = action->id.c_str();
122 if(MusicPaymentPreview::CHANGE_PAYMENT_ACTION == action_id
123 || MusicPaymentPreview::FORGOT_PASSWORD_ACTION == action_id)
124 {
125 nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
126 link->activate.connect(sigc::mem_fun(this,
127 &MusicPaymentPreview::OnActionLinkActivated));
128
129 buttons_map_.insert(std::make_pair(action->id, link));
130 }
131 else
132 {
133 nux::ObjectPtr<ActionButton> button = this->CreateButton(action);
134 button->activate.connect(sigc::mem_fun(this,
135 &MusicPaymentPreview::OnActionActivated));
136
137 buttons_map_.insert(std::make_pair(action->id, button));
138 }
139 LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
140 }
141}
142
143nux::Layout* MusicPaymentPreview::GetTitle()
144{
145 previews::Style& style = dash::previews::Style::Instance();
146 nux::VLayout* title_data_layout = new nux::VLayout();
147 title_data_layout->SetMaximumHeight(76);
148 title_data_layout->SetSpaceBetweenChildren(10);
149
150 title_ = new StaticCairoText(
151 preview_model_->title.Get(), true,
152 NUX_TRACKER_LOCATION);
153
154 title_->SetFont(style.payment_title_font());
155 title_->SetLines(-1);
156 title_->SetFont(style.title_font());
157 title_data_layout->AddView(title_.GetPointer(), 1);
158
159 subtitle_ = new StaticCairoText(
160 preview_model_->subtitle.Get(), true,
161 NUX_TRACKER_LOCATION);
162 subtitle_->SetLines(-1);
163 subtitle_->SetFont(style.payment_subtitle_font());
164 title_data_layout->AddView(subtitle_.GetPointer(), 1);
165 title_data_layout->AddSpace(1, 1);
166 return title_data_layout;
167}
168
169nux::Layout* MusicPaymentPreview::GetPrice()
170{
171 previews::Style& style = dash::previews::Style::Instance();
172 nux::VLayout *prize_data_layout = new nux::VLayout();
173 prize_data_layout->SetMaximumHeight(76);
174 prize_data_layout->SetSpaceBetweenChildren(5);
175
176 purchase_prize_ = new StaticCairoText(
177 payment_preview_model_->purchase_prize.Get(), true,
178 NUX_TRACKER_LOCATION);
179 purchase_prize_->SetLines(-1);
180 purchase_prize_->SetFont(style.payment_prize_title_font());
181 prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
182 nux::MINOR_POSITION_END);
183
184 purchase_hint_ = new StaticCairoText(
185 _("Ubuntu One best offer"),
186 true, NUX_TRACKER_LOCATION);
187 purchase_hint_->SetLines(-1);
188 purchase_hint_->SetFont(style.payment_prize_subtitle_font());
189 prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
190 nux::MINOR_POSITION_END);
191
192 purchase_type_ = new StaticCairoText(
193 payment_preview_model_->purchase_type.Get(), true,
194 NUX_TRACKER_LOCATION);
195 purchase_type_->SetLines(-1);
196 purchase_type_->SetFont(style.payment_prize_subtitle_font());
197 prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
198 nux::MINOR_POSITION_END);
199 return prize_data_layout;
200}
201
202nux::Layout* MusicPaymentPreview::GetBody()
203{
204 previews::Style& style = dash::previews::Style::Instance();
205 nux::VLayout *body_layout = new nux::VLayout();
206 body_layout->SetSpaceBetweenChildren(20);
207
208 intro_ = new StaticCairoText(
209 payment_preview_model_->header.Get(), true,
210 NUX_TRACKER_LOCATION);
211 intro_->SetFont(style.payment_intro_font());
212 intro_->SetLineSpacing(10);
213 intro_->SetLines(-style.GetDescriptionLineCount());
214 intro_->SetMinimumHeight(50);
215
216 form_layout_ = new nux::HLayout();
217 form_layout_->SetSpaceBetweenChildren(10);
218 form_layout_->SetMinimumHeight(107);
219 form_layout_->SetLeftAndRightPadding(20);
220 form_layout_->SetTopAndBottomPadding(10);
221
222 form_layout_->AddLayout(GetFormLabels(), 1, nux::MINOR_POSITION_END);
223 form_layout_->AddLayout(GetFormFields(), 1, nux::MINOR_POSITION_END);
224 form_layout_->AddLayout(GetFormActions(), 1, nux::MINOR_POSITION_END);
225
226
227 body_layout->AddView(intro_.GetPointer(), 1);
228 body_layout->AddLayout(form_layout_.GetPointer(), 1);
229
230
231 return body_layout;
232}
233
234nux::Layout* MusicPaymentPreview::GetFormLabels()
235{
236 previews::Style& style = dash::previews::Style::Instance();
237 nux::VLayout *labels_layout = new nux::VLayout();
238 if (error_message_.empty())
239 {
240 labels_layout->SetSpaceBetweenChildren(18);
241 }
242 else
243 {
244 labels_layout->SetSpaceBetweenChildren(10);
245 }
246
247 email_label_ = new StaticCairoText(
248 _("Ubuntu One email:"), true,
249 NUX_TRACKER_LOCATION);
250 email_label_->SetLines(-1);
251 email_label_->SetFont(style.payment_form_labels_font());
252 labels_layout->AddView(email_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
253
254 payment_label_ = new StaticCairoText(
255 _("Payment method:"), true,
256 NUX_TRACKER_LOCATION);
257 payment_label_->SetLines(-1);
258 payment_label_->SetFont(style.payment_form_labels_font());
259 labels_layout->AddView(payment_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
260
261 password_label_ = new StaticCairoText(
262 _("Ubuntu One Password:"), true,
263 NUX_TRACKER_LOCATION);
264 password_label_->SetLines(-1);
265 password_label_->SetFont(style.payment_form_labels_font());
266 password_label_->SetMinimumHeight(40);
267 labels_layout->AddView(password_label_.GetPointer(), 0, nux::MINOR_POSITION_END);
268
269 return labels_layout;
270}
271
272nux::Layout* MusicPaymentPreview::GetFormFields()
273{
274 previews::Style& style = dash::previews::Style::Instance();
275 nux::VLayout *fields_layout = new nux::VLayout();
276 if (error_message_.empty())
277 {
278 fields_layout->SetSpaceBetweenChildren(18);
279 }
280 else
281 {
282 fields_layout->SetSpaceBetweenChildren(10);
283 }
284
285 email_ = new StaticCairoText(
286 payment_preview_model_->email.Get(), true,
287 NUX_TRACKER_LOCATION);
288 email_->SetLines(-1);
289 email_->SetFont(style.payment_form_data_font());
290 fields_layout->AddView(email_.GetPointer(), 1,
291 nux::MINOR_POSITION_START);
292
293 payment_ = new StaticCairoText(
294 payment_preview_model_->payment_method.Get(), true,
295 NUX_TRACKER_LOCATION);
296 payment_->SetLines(-1);
297 payment_->SetFont(style.payment_form_data_font());
298 fields_layout->AddView(payment_.GetPointer(), 1,
299 nux::MINOR_POSITION_START);
300
301 password_entry_ = new TextInput();
302 password_entry_->SetMinimumHeight(40);
303 password_entry_->SetMinimumWidth(240);
304 password_entry_->input_hint = _("Password");
305
306 fields_layout->AddView(password_entry_.GetPointer(),
307 1, nux::MINOR_POSITION_START);
308
309 password_entry_->text_entry()->SetPasswordMode(true);
310 const char password_char = '*';
311 password_entry_->text_entry()->SetPasswordChar(&password_char);
312
313 if (!error_message_.empty())
314 {
315 StaticCairoText* error = new StaticCairoText(
316 _("Wrong password"), true, NUX_TRACKER_LOCATION);
317 error->SetLines(-1);
318 error->SetFont(style.payment_form_data_font());
319 // ensure it is an error using red
320 error->SetTextColor(style.payment_error_color());
321 fields_layout->AddView(error, 0, nux::MINOR_POSITION_START);
322 }
323
324 return fields_layout;
325}
326
327nux::Layout* MusicPaymentPreview::GetFormActions()
328{
329 previews::Style& style = dash::previews::Style::Instance();
330 nux::VLayout *actions_layout = new nux::VLayout();
331 if (error_message_.empty())
332 {
333 actions_layout->SetSpaceBetweenChildren(16);
334 }
335 else
336 {
337 actions_layout->SetSpaceBetweenChildren(8);
338 }
339
340 nux::ObjectPtr<StaticCairoText> empty_;
341 empty_ = new StaticCairoText(
342 "", true,
343 NUX_TRACKER_LOCATION);
344 empty_->SetLines(-1);
345 empty_->SetFont(style.payment_form_labels_font());
346 actions_layout->AddView(empty_.GetPointer(), 1,
347 nux::MINOR_POSITION_START);
348
349 if(buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer())
350 actions_layout->AddView(
351 buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer(),
352 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
353 100.0f, nux::NUX_LAYOUT_END);
354 if(buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer())
355 actions_layout->AddView(
356 buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer(),
357 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL,
358 100.0f, nux::NUX_LAYOUT_END);
359
360 return actions_layout;
361}
362
363nux::Layout* MusicPaymentPreview::GetFooter()
364{
365 previews::Style& style = dash::previews::Style::Instance();
366 nux::HLayout* actions_buffer_h = new nux::HLayout();
367 actions_buffer_h->AddSpace(0, 1);
368
369 nux::HLayout* buttons_data_layout = new nux::HLayout();
370 buttons_data_layout->SetSpaceBetweenChildren(style.GetSpaceBetweenActions());
371
372 lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
373 style.GetPaymentLockHeight());
374 buttons_data_layout->AddView(lock_texture_.GetPointer(), 0, nux::MINOR_POSITION_CENTER,
375 nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
376
377 buttons_data_layout->AddSpace(20, 1);
378 if(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer())
379 buttons_data_layout->AddView(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer(),
380 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
381 nux::NUX_LAYOUT_END);
382 if(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer())
383 buttons_data_layout->AddView(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer(),
384 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
385 nux::NUX_LAYOUT_END);
386
387 return buttons_data_layout;
388}
389
390const std::string MusicPaymentPreview::GetErrorMessage(GVariant *dict)
391{
392
393 glib::Variant data(g_variant_lookup_value(dict, "error_message",
394 G_VARIANT_TYPE_ANY));
395
396 if (!data)
397 return "";
398
399 return data.GetString();
400}
401
402void MusicPaymentPreview::PreLayoutManagement()
403{
404 nux::Geometry const& geo = GetGeometry();
405 GetLayout()->SetGeometry(geo);
406
407 previews::Style& style = dash::previews::Style::Instance();
408
409 int width = std::max<int>(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
410
411 if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
412 if(header_layout_) { header_layout_->SetMaximumWidth(width); }
413 if(intro_) { intro_->SetMaximumWidth(width); }
414 if(form_layout_) { form_layout_->SetMaximumWidth(width); }
415 if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
416
417 // set the tab ordering
418 SetFirstInTabOrder(password_entry_->text_entry());
419 SetLastInTabOrder(buttons_map_[MusicPaymentPreview::CANCEL_PURCHASE_ACTION].GetPointer());
420 SetLastInTabOrder(buttons_map_[MusicPaymentPreview::PURCHASE_ALBUM_ACTION].GetPointer());
421 SetLastInTabOrder(buttons_map_[MusicPaymentPreview::CHANGE_PAYMENT_ACTION].GetPointer());
422 SetLastInTabOrder(buttons_map_[MusicPaymentPreview::FORGOT_PASSWORD_ACTION].GetPointer());
423
424 Preview::PreLayoutManagement();
425}
426
427void MusicPaymentPreview::SetupViews()
428{
429 payment_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
430 if (!payment_preview_model_)
431 {
432 LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
433 return;
434 }
435
436 dash::Preview::InfoHintPtrList hints = preview_model_->GetInfoHints();
437 GVariant *preview_data = NULL;
438 for (dash::Preview::InfoHintPtr info_hint : hints)
439 {
440 if (info_hint->id == MusicPaymentPreview::DATA_INFOHINT_ID)
441 {
442 preview_data = info_hint->value;
443 if (preview_data != NULL)
444 {
445 error_message_ = GetErrorMessage(preview_data);
446 }
447 break;
448 }
449 }
450
451 // load the buttons so that they can be accessed in order
452 LoadActions();
453 PaymentPreview::SetupViews();
454}
455
456
457}
458}
459}
0460
=== added file 'dash/previews/MusicPaymentPreview.h'
--- dash/previews/MusicPaymentPreview.h 1970-01-01 00:00:00 +0000
+++ dash/previews/MusicPaymentPreview.h 2013-03-21 17:32:22 +0000
@@ -0,0 +1,134 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
20 *
21 */
22
23#ifndef MUSIC_PAYMENT_PREVIEW_H
24#define MUSIC_PAYMENT_PREVIEW_H
25
26#include <Nux/Nux.h>
27#include <Nux/AbstractButton.h>
28#include <UnityCore/Lens.h>
29#include <UnityCore/PaymentPreview.h>
30#include "ActionButton.h"
31#include "ActionLink.h"
32#include "PaymentPreview.h"
33#include "unity-shared/IconTexture.h"
34#include "unity-shared/TextInput.h"
35
36namespace nux
37{
38class AbstractPaintLayer;
39class StaticCairoText;
40class VLayout;
41}
42
43namespace unity
44{
45namespace dash
46{
47namespace previews
48{
49class CoverArt;
50class PreviewInfoHintWidget;
51
52class MusicPaymentPreview : public PaymentPreview
53{
54public:
55 typedef nux::ObjectPtr<MusicPaymentPreview> Ptr;
56 NUX_DECLARE_OBJECT_TYPE(MusicPaymentPreview, Preview);
57
58 MusicPaymentPreview(dash::Preview::Ptr preview_model);
59
60private:
61 void LoadActions();
62
63protected:
64 // key used to find the correct info hint
65 static const std::string DATA_INFOHINT_ID;
66
67 // keys of the data preview
68 static const std::string DATA_PASSWORD_KEY;
69
70 // ations ids
71 static const std::string CHANGE_PAYMENT_ACTION;
72 static const std::string FORGOT_PASSWORD_ACTION;
73 static const std::string CANCEL_PURCHASE_ACTION;
74 static const std::string PURCHASE_ALBUM_ACTION;
75
76 // From debug::Introspectable
77 std::string GetName() const;
78
79 nux::Layout* GetTitle();
80 nux::Layout* GetPrice();
81 nux::Layout* GetBody();
82 nux::Layout* GetFormLabels();
83 nux::Layout* GetFormFields();
84 nux::Layout* GetFormActions();
85 nux::Layout* GetFooter();
86
87 const std::string GetErrorMessage(GVariant *dict);
88
89 void OnActionActivated(ActionButton* button, std::string const& id);
90 void OnActionLinkActivated(ActionLink* link, std::string const& id);
91
92 virtual void SetupViews();
93
94 void PreLayoutManagement();
95
96protected:
97 // content elements
98 nux::ObjectPtr<CoverArt> image_;
99 nux::ObjectPtr<StaticCairoText> intro_;
100 nux::ObjectPtr<StaticCairoText> title_;
101 nux::ObjectPtr<StaticCairoText> subtitle_;
102 nux::ObjectPtr<StaticCairoText> email_label_;
103 nux::ObjectPtr<StaticCairoText> email_;
104 nux::ObjectPtr<StaticCairoText> payment_label_;
105 nux::ObjectPtr<StaticCairoText> payment_;
106 nux::ObjectPtr<StaticCairoText> password_label_;
107 nux::ObjectPtr<TextInput> password_entry_;
108 nux::ObjectPtr<StaticCairoText> purchase_hint_;
109 nux::ObjectPtr<StaticCairoText> purchase_prize_;
110 nux::ObjectPtr<StaticCairoText> purchase_type_;
111 nux::ObjectPtr<StaticCairoText> change_payment_;
112 nux::ObjectPtr<StaticCairoText> forgotten_password_;
113 nux::ObjectPtr<StaticCairoText> error_label_;
114 nux::ObjectPtr<nux::HLayout> form_layout_;
115
116 dash::PaymentPreview* payment_preview_model_;
117 // do we want to type?
118 std::string error_message_;
119
120 // actions
121 std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> buttons_map_;
122
123 // lock texture
124 nux::ObjectPtr<IconTexture> lock_texture_;
125
126 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
127 LayerPtr details_bg_layer_;
128};
129
130}
131}
132}
133
134#endif // MUSIC_PAYMENT_PREVIEW_H
0135
=== added file 'dash/previews/PaymentPreview.cpp'
--- dash/previews/PaymentPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/PaymentPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,368 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23#include <NuxCore/Logger.h>
24#include "PaymentPreview.h"
25#include "unity-shared/CoverArt.h"
26#include "unity-shared/PreviewStyle.h"
27
28namespace unity
29{
30
31namespace dash
32{
33
34namespace previews
35{
36
37namespace
38{
39
40nux::logging::Logger logger("unity.dash.previews.payment.preview");
41
42}
43
44class OverlaySpinner : public unity::debug::Introspectable, public nux::View
45{
46 NUX_DECLARE_OBJECT_TYPE(OverlaySpinner, nux::View);
47public:
48 OverlaySpinner();
49
50 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
51 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
52
53protected:
54 // Introspectable methods
55 std::string GetName() const;
56 void AddProperties(GVariantBuilder* builder);
57
58 // Key navigation
59 virtual bool AcceptKeyNavFocus();
60
61private:
62 bool OnFrameTimeout();
63
64 nux::BaseTexture* spin_;
65
66 glib::Source::UniquePtr frame_timeout_;
67
68 nux::Matrix4 rotate_;
69 float rotation_;
70};
71
72NUX_IMPLEMENT_OBJECT_TYPE(OverlaySpinner);
73
74OverlaySpinner::OverlaySpinner()
75 : nux::View(NUX_TRACKER_LOCATION),
76 rotation_(0.0f)
77{
78 previews::Style& style = dash::previews::Style::Instance();
79
80 spin_ = style.GetSearchSpinIcon();
81
82 rotate_.Identity();
83 rotate_.Rotate_z(0.0);
84}
85
86void OverlaySpinner::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
87{
88 nux::Geometry const& geo = GetGeometry();
89 nux::TexCoordXForm texxform;
90
91 GfxContext.PushClippingRectangle(geo);
92
93 nux::GetPainter().PaintBackground(GfxContext, geo);
94
95 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
96 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
97 texxform.min_filter = nux::TEXFILTER_LINEAR;
98 texxform.mag_filter = nux::TEXFILTER_LINEAR;
99
100 unsigned int current_alpha_blend;
101 unsigned int current_src_blend_factor;
102 unsigned int current_dest_blend_factor;
103 GfxContext.GetRenderStates().GetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
104 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
105
106 nux::Geometry spin_geo(geo.x + ((geo.width - spin_->GetWidth()) / 2),
107 geo.y + ((geo.height - spin_->GetHeight()) / 2),
108 spin_->GetWidth(),
109 spin_->GetHeight());
110 // Geometry (== Rect) uses integers which were rounded above,
111 // hence an extra 0.5 offset for odd sizes is needed
112 // because pure floating point is not being used.
113 int spin_offset_w = !(geo.width % 2) ? 0 : 1;
114 int spin_offset_h = !(geo.height % 2) ? 0 : 1;
115
116 nux::Matrix4 matrix_texture;
117 matrix_texture = nux::Matrix4::TRANSLATE(-spin_geo.x - (spin_geo.width + spin_offset_w) / 2.0f,
118 -spin_geo.y - (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
119 matrix_texture = rotate_ * matrix_texture;
120 matrix_texture = nux::Matrix4::TRANSLATE(spin_geo.x + (spin_geo.width + spin_offset_w) / 2.0f,
121 spin_geo.y + (spin_geo.height + spin_offset_h) / 2.0f, 0) * matrix_texture;
122
123 GfxContext.SetModelViewMatrix(GfxContext.GetModelViewMatrix() * matrix_texture);
124
125 GfxContext.QRP_1Tex(spin_geo.x,
126 spin_geo.y,
127 spin_geo.width,
128 spin_geo.height,
129 spin_->GetDeviceTexture(),
130 texxform,
131 nux::color::White);
132
133 // revert to model view matrix stack
134 GfxContext.ApplyModelViewMatrix();
135
136 GfxContext.PopClippingRectangle();
137
138 GfxContext.GetRenderStates().SetBlend(current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
139
140 if (!frame_timeout_)
141 {
142 frame_timeout_.reset(new glib::Timeout(22, sigc::mem_fun(this, &OverlaySpinner::OnFrameTimeout)));
143 }
144}
145
146
147void OverlaySpinner::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw)
148{
149}
150
151
152bool OverlaySpinner::OnFrameTimeout()
153{
154 rotation_ += 0.1f;
155
156 if (rotation_ >= 360.0f)
157 rotation_ = 0.0f;
158
159 rotate_.Rotate_z(rotation_);
160 QueueDraw();
161
162 frame_timeout_.reset();
163 return false;
164}
165
166std::string OverlaySpinner::GetName() const
167{
168 return "OverlaySpinner";
169}
170
171void OverlaySpinner::AddProperties(GVariantBuilder* builder)
172{
173 nux::Geometry geo = GetGeometry();
174
175 variant::BuilderWrapper(builder)
176 .add("x", geo.x)
177 .add("y", geo.y)
178 .add("width", geo.width)
179 .add("height", geo.height);
180}
181
182
183bool OverlaySpinner::AcceptKeyNavFocus()
184{
185 return false;
186}
187
188PaymentPreview::PaymentPreview(dash::Preview::Ptr preview_model)
189: Preview(preview_model)
190, data_(nullptr)
191, full_data_layout_(nullptr)
192{
193}
194
195std::string PaymentPreview::GetName() const
196{
197 return "";
198}
199
200
201nux::Layout* PaymentPreview::GetHeader()
202{
203 nux::HLayout* header_data_layout = new nux::HLayout();
204 header_data_layout->SetSpaceBetweenChildren(10);
205 header_data_layout->SetMaximumHeight(76);
206 header_data_layout->SetMinimumHeight(76);
207
208 image_ = new CoverArt();
209 image_->SetMinMaxSize(64, 64);
210 AddChild(image_.GetPointer());
211 UpdateCoverArtImage(image_.GetPointer());
212
213 header_data_layout->AddView(image_.GetPointer(), 0);
214 header_data_layout->AddLayout(GetTitle(), 0);
215 header_data_layout->AddSpace(20, 1);
216 header_data_layout->AddLayout(GetPrice(), 0);
217 return header_data_layout;
218}
219
220nux::ObjectPtr<ActionLink> PaymentPreview::CreateLink(dash::Preview::ActionPtr action)
221{
222 previews::Style& style = dash::previews::Style::Instance();
223
224 nux::ObjectPtr<ActionLink> link;
225 link = new ActionLink(action->id,
226 action->display_name, NUX_TRACKER_LOCATION);
227 link->font_hint.Set(style.payment_form_labels_font().c_str());
228 link->SetMinimumWidth(178);
229 link->SetMaximumHeight(34);
230 return link;
231}
232
233
234nux::ObjectPtr<ActionButton> PaymentPreview::CreateButton(dash::Preview::ActionPtr action)
235{
236 previews::Style& style = dash::previews::Style::Instance();
237
238 nux::ObjectPtr<ActionButton> button;
239 button = new ActionButton(action->id,
240 action->display_name, action->icon_hint,
241 NUX_TRACKER_LOCATION);
242 button->SetFont(style.action_font());
243 button->SetExtraHint(action->extra_text, style.action_extra_font());
244 button->SetMinimumWidth(178);
245 button->SetMaximumHeight(34);
246 return button;
247}
248
249
250void PaymentPreview::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
251{
252 nux::Geometry const& base = GetGeometry();
253
254 gfx_engine.PushClippingRectangle(base);
255 nux::GetPainter().PaintBackground(gfx_engine, base);
256
257 if (full_data_layout_)
258 {
259 unsigned int alpha, src, dest = 0;
260 gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
261 gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
262
263 details_bg_layer_->SetGeometry(full_data_layout_->GetGeometry());
264 nux::GetPainter().RenderSinglePaintLayer(gfx_engine, full_data_layout_->GetGeometry(), details_bg_layer_.get());
265
266 gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
267 }
268
269 gfx_engine.PopClippingRectangle();
270}
271
272void PaymentPreview::DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
273{
274 nux::Geometry const& base = GetGeometry();
275 gfx_engine.PushClippingRectangle(base);
276
277 if (!IsFullRedraw())
278 nux::GetPainter().PushLayer(gfx_engine, details_bg_layer_->GetGeometry(), details_bg_layer_.get());
279
280 unsigned int alpha, src, dest = 0;
281 gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
282 gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
283
284 if (GetCompositionLayout())
285 GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
286
287 gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
288
289 if (!IsFullRedraw())
290 nux::GetPainter().PopBackground();
291
292 gfx_engine.PopClippingRectangle();
293}
294
295void PaymentPreview::ShowOverlay(bool isShown)
296{
297 if (!full_data_layout_)
298 return;
299
300 if (isShown)
301 {
302 full_data_layout_->SetActiveLayerN(1);
303 }
304 else
305 {
306 full_data_layout_->SetActiveLayerN(0);
307 }
308 QueueDraw();
309}
310
311void PaymentPreview::ShowOverlay()
312{
313 ShowOverlay(true);
314}
315
316void PaymentPreview::HideOverlay()
317{
318 ShowOverlay(false);
319}
320
321void PaymentPreview::SetupBackground()
322{
323 details_bg_layer_.reset(dash::previews::Style::Instance().GetBackgroundLayer());
324}
325
326void PaymentPreview::SetupViews()
327{
328 full_data_layout_ = new nux::LayeredLayout();
329
330 // layout to be used to show the info
331 content_data_layout_ = new nux::VLayout();
332 content_data_layout_->SetSpaceBetweenChildren(5);
333 content_data_layout_->SetPadding(10, 10, 0, 10);
334
335 header_layout_ = GetHeader();
336
337 content_data_layout_->AddLayout(header_layout_.GetPointer(), 1);
338
339 body_layout_ = GetBody();
340 content_data_layout_->AddLayout(body_layout_.GetPointer(), 1);
341
342 footer_layout_ = GetFooter();
343 content_data_layout_->AddLayout(footer_layout_.GetPointer(), 1);
344
345 full_data_layout_->AddLayout(content_data_layout_.GetPointer());
346
347 // layout to draw an overlay
348 overlay_layout_ = new nux::VLayout();
349 StaticCairoText* calculating = new StaticCairoText(
350 "Performing purchase", true,
351 NUX_TRACKER_LOCATION);
352
353 OverlaySpinner* spinner_ = new OverlaySpinner();
354 overlay_layout_->AddSpace(20, 1);
355 overlay_layout_->AddView(calculating, 0, nux::MINOR_POSITION_CENTER);
356 overlay_layout_->AddView(spinner_, 1, nux::MINOR_POSITION_CENTER);
357 overlay_layout_->AddSpace(20, 1);
358
359 full_data_layout_->AddLayout(overlay_layout_.GetPointer());
360
361 SetLayout(full_data_layout_.GetPointer());
362}
363
364}
365
366}
367
368}
0369
=== added file 'dash/previews/PaymentPreview.h'
--- dash/previews/PaymentPreview.h 1970-01-01 00:00:00 +0000
+++ dash/previews/PaymentPreview.h 2013-03-21 17:32:22 +0000
@@ -0,0 +1,132 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright 2012-2013 Canonical Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License version 3, as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
14 *
15 * You should have received a copy of both the GNU Lesser General Public
16 * License version 3 along with this program. If not, see
17 * <http://www.gnu.org/licenses/>
18 *
19 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
20 * Manuel de la Pena <manuel.delapena@canonical.com>
21 *
22 */
23
24#ifndef PAYMENT_PREVIEW_H
25#define PAYMENT_PREVIEW_H
26
27#include <Nux/Nux.h>
28#include <Nux/HLayout.h>
29#include <Nux/LayeredLayout.h>
30#include <Nux/AbstractButton.h>
31#include <UnityCore/Lens.h>
32#include <UnityCore/PaymentPreview.h>
33#include "ActionButton.h"
34#include "ActionLink.h"
35#include "Preview.h"
36#include "unity-shared/IconTexture.h"
37#include "unity-shared/TextInput.h"
38
39namespace nux
40{
41class AbstractPaintLayer;
42class StaticCairoText;
43class VLayout;
44}
45
46namespace unity
47{
48namespace dash
49{
50namespace previews
51{
52class CoverArt;
53class PreviewInfoHintWidget;
54
55class PaymentPreview : public Preview
56{
57public:
58 typedef nux::ObjectPtr<PaymentPreview> Ptr;
59
60 PaymentPreview(dash::Preview::Ptr preview_model);
61
62 // From debug::Introspectable
63 std::string GetName() const;
64
65 // Create and connect an action link to OnActionLinkActivated
66 nux::ObjectPtr<ActionLink> CreateLink(dash::Preview::ActionPtr action);
67
68 // Create and connect an action button OnActioButtonActivated
69 nux::ObjectPtr<ActionButton> CreateButton(dash::Preview::ActionPtr action);
70
71 void Draw(nux::GraphicsEngine& GfxContext, bool force_draw);
72 void DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw);
73 void ShowOverlay(bool isShown);
74 void ShowOverlay();
75 void HideOverlay();
76
77private:
78
79protected:
80 GVariant *data_;
81
82 // build the header to be shown in the preview
83 nux::Layout* GetHeader();
84
85 // Return the title layout (including layout data) to be added to the header
86 // NULL is a possible return value.
87 virtual nux::Layout* GetTitle() = 0;
88
89 // Return the pize layout (including data) to be added to the header
90 // NULL is a possible return value.
91 virtual nux::Layout* GetPrice() = 0;
92
93 // Return layout with the content to show. NULL is a possible return value.
94 virtual nux::Layout* GetBody() = 0;
95
96 // Return layout with the content to show. NULL is a possible return value.
97 virtual nux::Layout* GetFooter() = 0;
98
99 // Executed when a link is clicked.
100 virtual void OnActionActivated(ActionButton* button, std::string const& id) = 0;
101
102 // Executed when a button is clicked.
103 virtual void OnActionLinkActivated(ActionLink* link, std::string const& id) = 0;
104
105 virtual void PreLayoutManagement() = 0;
106
107 virtual void LoadActions() = 0;
108 virtual void SetupViews();
109 virtual void SetupBackground();
110
111 nux::ObjectPtr<nux::LayeredLayout> full_data_layout_;
112 nux::ObjectPtr<nux::VLayout> content_data_layout_;
113 nux::ObjectPtr<nux::VLayout> overlay_layout_;
114 nux::ObjectPtr<nux::Layout> header_layout_;
115 nux::ObjectPtr<nux::Layout> body_layout_;
116 nux::ObjectPtr<nux::Layout> footer_layout_;
117
118 // content elements
119 nux::ObjectPtr<CoverArt> image_;
120
121 // do we want to type?
122 bool entry_selected_;
123
124 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
125 LayerPtr details_bg_layer_;
126};
127
128}
129}
130}
131
132#endif // PAYMENT_PREVIEW_H
0133
=== modified file 'dash/previews/Preview.cpp'
--- dash/previews/Preview.cpp 2013-02-27 18:04:26 +0000
+++ dash/previews/Preview.cpp 2013-03-21 17:32:22 +0000
@@ -27,12 +27,15 @@
27#include <NuxCore/Logger.h>27#include <NuxCore/Logger.h>
28#include <Nux/HLayout.h>28#include <Nux/HLayout.h>
29#include <Nux/VLayout.h>29#include <Nux/VLayout.h>
30#include <UnityCore/PaymentPreview.h>
30#include "ActionButton.h"31#include "ActionButton.h"
3132
32#include "GenericPreview.h"33#include "GenericPreview.h"
33#include "ApplicationPreview.h"34#include "ApplicationPreview.h"
35#include "ErrorPreview.h"
34#include "MusicPreview.h"36#include "MusicPreview.h"
35#include "MoviePreview.h"37#include "MoviePreview.h"
38#include "MusicPaymentPreview.h"
36#include "SocialPreview.h"39#include "SocialPreview.h"
37#include "PreviewInfoHintWidget.h"40#include "PreviewInfoHintWidget.h"
3841
@@ -56,6 +59,19 @@
56 {59 {
57 return Preview::Ptr(new GenericPreview(model));60 return Preview::Ptr(new GenericPreview(model));
58 }61 }
62 else if (model->renderer_name == "preview-payment")
63 {
64 dash::PaymentPreview* payment_preview_model = dynamic_cast<dash::PaymentPreview*>(
65 model.get());
66 if (payment_preview_model->preview_type.Get() == dash::PaymentPreview::MUSIC)
67 {
68 return Preview::Ptr(new MusicPaymentPreview(model));
69 }
70 else
71 {
72 return Preview::Ptr(new ErrorPreview(model));
73 }
74 }
59 else if (model->renderer_name == "preview-application")75 else if (model->renderer_name == "preview-application")
60 {76 {
61 return Preview::Ptr(new ApplicationPreview(model));77 return Preview::Ptr(new ApplicationPreview(model));
@@ -129,7 +145,7 @@
129 {145 {
130 nux::HLayout* actions_layout_h = new TabIteratorHLayout(tab_iterator_);146 nux::HLayout* actions_layout_h = new TabIteratorHLayout(tab_iterator_);
131 actions_layout_h->SetSpaceBetweenChildren(style.GetSpaceBetweenActions());147 actions_layout_h->SetSpaceBetweenChildren(style.GetSpaceBetweenActions());
132 148
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++)
134 {150 {
135 dash::Preview::ActionPtr action = actions[action_iter];151 dash::Preview::ActionPtr action = actions[action_iter];
@@ -181,7 +197,7 @@
181{197{
182 if (!preview_model_)198 if (!preview_model_)
183 return;199 return;
184 200
185 previews::Style& style = dash::previews::Style::Instance();201 previews::Style& style = dash::previews::Style::Instance();
186202
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); };
188204
=== added file 'dash/previews/StandaloneErrorPreview.cpp'
--- dash/previews/StandaloneErrorPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/StandaloneErrorPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,219 @@
1/*
2 * Copyright 2012-2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 *
19 */
20
21#include <gtk/gtk.h>
22
23#include "Nux/Nux.h"
24#include "Nux/VLayout.h"
25#include "Nux/WindowThread.h"
26#include "NuxGraphics/GraphicsEngine.h"
27#include <Nux/Layout.h>
28#include <NuxCore/Logger.h>
29#include <UnityCore/Variant.h>
30#include <UnityCore/Preview.h>
31#include <unity-protocol.h>
32
33#include "unity-shared/FontSettings.h"
34#include "unity-shared/UnitySettings.h"
35#include "unity-shared/PreviewStyle.h"
36#include "unity-shared/DashStyle.h"
37#include "unity-shared/ThumbnailGenerator.h"
38
39#include "Preview.h"
40#include "PreviewContainer.h"
41
42
43#define WIDTH 1100
44#define HEIGHT 600
45
46using namespace unity;
47using namespace unity::dash;
48
49namespace
50{
51nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
52}
53
54class DummyView : public nux::View
55{
56public:
57 DummyView(nux::View* view)
58 : View(NUX_TRACKER_LOCATION)
59 {
60 SetAcceptKeyNavFocusOnMouseDown(false);
61 SetAcceptKeyNavFocusOnMouseEnter(false);
62
63 nux::ROPConfig rop;
64 rop.Blend = true;
65 rop.SrcBlend = GL_ONE;
66 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
67 bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
68
69 nux::Layout* layout = new nux::VLayout();
70 layout->SetPadding(10);
71 layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
72 SetLayout(layout);
73 }
74
75 // Keyboard navigation
76 bool AcceptKeyNavFocus()
77 {
78 return false;
79 }
80
81protected:
82 virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
83 {
84 nux::Geometry const& base = GetGeometry();
85
86 gfx_engine.PushClippingRectangle(base);
87 nux::GetPainter().PaintBackground(gfx_engine, base);
88
89 unsigned int alpha, src, dest = 0;
90 gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
91 gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
92
93 bg_layer_->SetGeometry(GetGeometry());
94 nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
95
96 gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
97
98 gfx_engine.PopClippingRectangle();
99 }
100
101 virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
102 {
103 nux::Geometry const& base = GetGeometry();
104 gfx_engine.PushClippingRectangle(base);
105
106 if (!IsFullRedraw())
107 nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
108
109 if (GetCompositionLayout())
110 GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
111
112 if (!IsFullRedraw())
113 nux::GetPainter().PopBackground();
114
115 gfx_engine.PopClippingRectangle();
116 }
117
118 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
119 LayerPtr bg_layer_;
120};
121
122class TestRunner
123{
124public:
125 TestRunner ();
126 ~TestRunner ();
127
128 static void InitWindowThread (nux::NThread* thread, void* InitData);
129 void Init ();
130
131 previews::PreviewContainer::Ptr container_;
132 nux::Layout *layout_;
133 unsigned int nav_iter;
134 previews::Navigation nav_direction_;
135 std::string search_string_;
136 bool first_;
137};
138
139TestRunner::TestRunner ()
140{
141}
142
143TestRunner::~TestRunner ()
144{
145}
146
147void TestRunner::Init ()
148{
149 container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
150 container_->request_close.connect([&]() { exit(0); });
151 container_->DisableNavButton(previews::Navigation::BOTH);
152
153 DummyView* dummyView = new DummyView(container_.GetPointer());
154 layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
155 layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
156 nux::GetWindowThread()->SetLayout (layout_);
157
158 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
159 unity_protocol_payment_preview_new()));
160
161 unity_protocol_preview_set_title(
162 proto_obj, "This Modern Glitch");
163 unity_protocol_preview_set_subtitle(
164 proto_obj, "The Wombats");
165 unity_protocol_payment_preview_set_header(
166 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
167 "A horrible error ocurred!!!");
168 unity_protocol_payment_preview_set_purchase_prize(
169 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
170 "10 eur");
171 unity_protocol_payment_preview_set_purchase_type(
172 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
173 "Digital CD");
174 unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
175 UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR);
176
177 // set the diff actions
178 unity_protocol_preview_add_action(proto_obj, "open_u1_link", "Go to u1 page", NULL, 0);
179
180 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
181 glib::StealRef());
182
183 dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
184 container_->Preview(preview_model, previews::Navigation::LEFT);
185}
186
187void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
188{
189 TestRunner *self = (TestRunner *) InitData;
190 self->Init ();
191}
192
193int main(int argc, char **argv)
194{
195 nux::WindowThread* wt = NULL;
196
197 gtk_init (&argc, &argv);
198
199 nux::NuxInitialize(0);
200 nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
201 // The instances for the pseudo-singletons.
202 unity::Settings settings;
203 unity::dash::previews::Style panel_style;
204 unity::dash::Style dash_style;
205 unity::ThumbnailGenerator thumbnail_generator;
206
207 TestRunner *test_runner = new TestRunner ();
208 wt = nux::CreateGUIThread(TEXT("Unity Preview"),
209 WIDTH, HEIGHT,
210 0,
211 &TestRunner::InitWindowThread,
212 test_runner);
213
214 wt->Run (NULL);
215 delete wt;
216 return 0;
217}
218
219
0220
=== added file 'dash/previews/StandaloneMusicPaymentPreview.cpp'
--- dash/previews/StandaloneMusicPaymentPreview.cpp 1970-01-01 00:00:00 +0000
+++ dash/previews/StandaloneMusicPaymentPreview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,223 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * version 3 along with this program. If not, see
15 * <http://www.gnu.org/licenses/>
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 *
19 */
20#include <gtk/gtk.h>
21
22#include "Nux/Nux.h"
23#include "Nux/VLayout.h"
24#include "Nux/WindowThread.h"
25#include "NuxGraphics/GraphicsEngine.h"
26#include <Nux/Layout.h>
27#include <NuxCore/Logger.h>
28#include <UnityCore/Variant.h>
29#include <UnityCore/Preview.h>
30#include <unity-protocol.h>
31
32#include "unity-shared/FontSettings.h"
33#include "unity-shared/UnitySettings.h"
34#include "unity-shared/PreviewStyle.h"
35#include "unity-shared/DashStyle.h"
36#include "unity-shared/ThumbnailGenerator.h"
37
38#include "Preview.h"
39#include "PreviewContainer.h"
40
41
42#define WIDTH 1100
43#define HEIGHT 600
44
45using namespace unity;
46using namespace unity::dash;
47
48namespace
49{
50nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
51}
52
53class DummyView : public nux::View
54{
55public:
56 DummyView(nux::View* view)
57 : View(NUX_TRACKER_LOCATION)
58 {
59 SetAcceptKeyNavFocusOnMouseDown(false);
60 SetAcceptKeyNavFocusOnMouseEnter(false);
61
62 nux::ROPConfig rop;
63 rop.Blend = true;
64 rop.SrcBlend = GL_ONE;
65 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
66 bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
67
68 nux::Layout* layout = new nux::VLayout();
69 layout->SetPadding(10);
70 layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
71 SetLayout(layout);
72 }
73
74 // Keyboard navigation
75 bool AcceptKeyNavFocus()
76 {
77 return false;
78 }
79
80protected:
81 virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
82 {
83 nux::Geometry const& base = GetGeometry();
84
85 gfx_engine.PushClippingRectangle(base);
86 nux::GetPainter().PaintBackground(gfx_engine, base);
87
88 unsigned int alpha, src, dest = 0;
89 gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
90 gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
91
92 bg_layer_->SetGeometry(GetGeometry());
93 nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
94
95 gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
96
97 gfx_engine.PopClippingRectangle();
98 }
99
100 virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
101 {
102 nux::Geometry const& base = GetGeometry();
103 gfx_engine.PushClippingRectangle(base);
104
105 if (!IsFullRedraw())
106 nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
107
108 if (GetCompositionLayout())
109 GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
110
111 if (!IsFullRedraw())
112 nux::GetPainter().PopBackground();
113
114 gfx_engine.PopClippingRectangle();
115 }
116
117 typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
118 LayerPtr bg_layer_;
119};
120
121class TestRunner
122{
123public:
124 TestRunner ();
125 ~TestRunner ();
126
127 static void InitWindowThread (nux::NThread* thread, void* InitData);
128 void Init ();
129
130 previews::PreviewContainer::Ptr container_;
131 nux::Layout *layout_;
132 unsigned int nav_iter;
133 previews::Navigation nav_direction_;
134 std::string search_string_;
135 bool first_;
136};
137
138TestRunner::TestRunner ()
139{
140}
141
142TestRunner::~TestRunner ()
143{
144}
145
146void TestRunner::Init ()
147{
148 container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
149 container_->request_close.connect([&]() { exit(0); });
150 container_->DisableNavButton(previews::Navigation::BOTH);
151
152 DummyView* dummyView = new DummyView(container_.GetPointer());
153 layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
154 layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
155 nux::GetWindowThread()->SetLayout (layout_);
156
157 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
158 unity_protocol_payment_preview_new()));
159
160 unity_protocol_preview_set_title(
161 proto_obj.RawPtr(), "This Modern Glitch");
162 unity_protocol_preview_set_subtitle(
163 proto_obj.RawPtr(), "The Wombats");
164 unity_protocol_payment_preview_set_header(
165 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
166 "Hi mandel, you purchased in the past from Ubuntu One, would you like to use the same payment details? Please review your order:");
167 unity_protocol_payment_preview_set_email(
168 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
169 "manuel@canonical.com");
170 unity_protocol_payment_preview_set_payment_method(
171 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
172 "***** *** **** 246");
173 unity_protocol_payment_preview_set_purchase_prize(
174 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
175 "10 eur");
176 unity_protocol_payment_preview_set_purchase_type(
177 UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
178 "Digital CD");
179
180 // set the diff actions
181 unity_protocol_preview_add_action(proto_obj, "purchase_album", "Buy Now", NULL, 0);
182 unity_protocol_preview_add_action(proto_obj, "cancel_purchase", "Cancel", NULL, 0);
183 unity_protocol_preview_add_action(proto_obj, "forgot_password", "forgotten your Ubuntu One password?", NULL, 0);
184 unity_protocol_preview_add_action(proto_obj, "change_payment_method", "change payment method", NULL, 0);
185
186 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
187 glib::StealRef());
188
189 dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
190 container_->Preview(preview_model, previews::Navigation::LEFT);
191}
192
193void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
194{
195 TestRunner *self = (TestRunner *) InitData;
196 self->Init ();
197}
198
199int main(int argc, char **argv)
200{
201 nux::WindowThread* wt = NULL;
202
203 gtk_init (&argc, &argv);
204
205 nux::NuxInitialize(0);
206 nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
207 // The instances for the pseudo-singletons.
208 unity::Settings settings;
209 unity::dash::previews::Style panel_style;
210 unity::dash::Style dash_style;
211 unity::ThumbnailGenerator thumbnail_generator;
212
213 TestRunner *test_runner = new TestRunner ();
214 wt = nux::CreateGUIThread(TEXT("Unity Preview"),
215 WIDTH, HEIGHT,
216 0,
217 &TestRunner::InitWindowThread,
218 test_runner);
219
220 wt->Run (NULL);
221 delete wt;
222 return 0;
223}
0224
=== added file 'resources/lock_icon.png'
1Binary files resources/lock_icon.png 1970-01-01 00:00:00 +0000 and resources/lock_icon.png 2013-03-21 17:32:22 +0000 differ225Binary 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
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-03-21 11:36:49 +0000
+++ tests/CMakeLists.txt 2013-03-21 17:32:22 +0000
@@ -244,6 +244,7 @@
244 test_dash_controller.cpp244 test_dash_controller.cpp
245 test_desktop_launcher_icon.cpp245 test_desktop_launcher_icon.cpp
246 test_device_launcher_section.cpp246 test_device_launcher_section.cpp
247 test_error_preview.cpp
247 test_edge_barrier_controller.cpp248 test_edge_barrier_controller.cpp
248 test_expo_launcher_icon.cpp249 test_expo_launcher_icon.cpp
249 test_filter_widgets.cpp250 test_filter_widgets.cpp
@@ -276,6 +277,8 @@
276 test_previews_generic.cpp277 test_previews_generic.cpp
277 test_previews_movie.cpp278 test_previews_movie.cpp
278 test_previews_music.cpp279 test_previews_music.cpp
280 test_previews_music_payment.cpp
281 test_previews_payment.cpp
279 test_previews_social.cpp282 test_previews_social.cpp
280 test_overlay_scrollbar.cpp283 test_overlay_scrollbar.cpp
281 test_quicklist_manager.cpp284 test_quicklist_manager.cpp
282285
=== added file 'tests/test_error_preview.cpp'
--- tests/test_error_preview.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_error_preview.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,111 @@
1/*
2 * Copyright 2012-2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the applicable version of the GNU Lesser General Public
12 * License for more details.
13 *
14 * You should have received a copy of both the GNU Lesser General Public
15 * License version 3 along with this program. If not, see
16 * <http://www.gnu.org/licenses/>
17 *
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19 *
20 */
21#include <list>
22#include <gmock/gmock.h>
23using namespace testing;
24
25#include <Nux/Nux.h>
26#include <Nux/BaseWindow.h>
27#include <unity-shared/StaticCairoText.h>
28#include <unity-shared/DashStyle.h>
29#include <unity-shared/PreviewStyle.h>
30#include <unity-shared/ThumbnailGenerator.h>
31#include "unity-shared/UnitySettings.h"
32
33#include <unity-protocol.h>
34#include "dash/previews/ErrorPreview.h"
35#include "test_utils.h"
36
37namespace unity
38{
39
40namespace dash
41{
42
43namespace previews
44{
45
46class ErrorPreviewMock : public ErrorPreview
47{
48 public:
49 ErrorPreviewMock(dash::Preview::Ptr preview_model)
50 : ErrorPreview(preview_model){}
51 ~ErrorPreviewMock(){}
52
53 using ErrorPreview::intro_;
54 using ErrorPreview::title_;
55 using ErrorPreview::subtitle_;
56 using ErrorPreview::purchase_hint_;
57 using ErrorPreview::purchase_prize_;
58 using ErrorPreview::purchase_type_;
59};
60
61class TestErrorPreview : public Test
62{
63 protected:
64 TestErrorPreview() :
65 Test(),
66 parent_window_(new nux::BaseWindow("TestErrorPayment"))
67 {
68 title = "Turning Japanese";
69 subtitle = "The vapors";
70 header = "Hi test, you purchased in the past from Ubuntu One.";
71 purchase_prize = "65$";
72 purchase_type = "Mp3";
73 preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR;
74
75 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
76
77 unity_protocol_preview_set_title(proto_obj, title.c_str());
78 unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
79
80 unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
81 unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
82 unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
83 unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
84
85 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
86
87 preview_model = dash::Preview::PreviewForVariant(v);
88
89 }
90
91 nux::ObjectPtr<nux::BaseWindow> parent_window_;
92 dash::Preview::Ptr preview_model;
93
94 // testing data
95 std::string title;
96 std::string subtitle;
97 std::string header;
98 std::string purchase_prize;
99 std::string purchase_type;
100 UnityProtocolPreviewPaymentType preview_type;
101
102 // needed for styles
103 unity::Settings settings;
104 dash::Style dash_style;
105};
106
107} // previews
108
109} // dash
110
111} // unity
0112
=== added file 'tests/test_previews_music_payment.cpp'
--- tests/test_previews_music_payment.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_previews_music_payment.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,151 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012-2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 */
19
20#include <list>
21#include <gmock/gmock.h>
22
23#include <Nux/Nux.h>
24#include <Nux/BaseWindow.h>
25#include <unity-shared/StaticCairoText.h>
26#include <unity-shared/CoverArt.h>
27#include <unity-shared/DashStyle.h>
28#include <unity-shared/PreviewStyle.h>
29#include <unity-shared/ThumbnailGenerator.h>
30#include "unity-shared/UnitySettings.h"
31
32#include <unity-protocol.h>
33#include "dash/previews/MusicPaymentPreview.h"
34#include "test_utils.h"
35
36using namespace testing;
37
38namespace unity
39{
40
41namespace dash
42{
43
44namespace previews
45{
46
47class MockedMusicPaymentPreview : public MusicPaymentPreview
48{
49public:
50 typedef nux::ObjectPtr<MockedMusicPaymentPreview> Ptr;
51
52 MockedMusicPaymentPreview(dash::Preview::Ptr preview_model)
53 : MusicPaymentPreview(preview_model)
54 {}
55
56 using MusicPaymentPreview::image_;
57 using MusicPaymentPreview::intro_;
58 using MusicPaymentPreview::title_;
59 using MusicPaymentPreview::subtitle_;
60 using MusicPaymentPreview::email_label_;
61 using MusicPaymentPreview::email_;
62 using MusicPaymentPreview::payment_label_;
63 using MusicPaymentPreview::payment_;
64 using MusicPaymentPreview::password_label_;
65 using MusicPaymentPreview::password_entry_;
66 using MusicPaymentPreview::purchase_hint_;
67 using MusicPaymentPreview::purchase_prize_;
68 using MusicPaymentPreview::purchase_type_;
69 using MusicPaymentPreview::change_payment_;
70 using MusicPaymentPreview::forgotten_password_;
71 using MusicPaymentPreview::error_label_;
72 using MusicPaymentPreview::form_layout_;
73 using MusicPaymentPreview::SetupViews;
74};
75
76class TestMusicPaymentPreview : public ::testing::Test
77{
78 protected:
79 TestMusicPaymentPreview() :
80 Test(),
81 parent_window_(new nux::BaseWindow("TestPreviewMusicPayment"))
82 {
83 title = "Turning Japanese";
84 subtitle = "The vapors";
85 header = "Hi test, you purchased in the past from Ubuntu One.";
86 email = "test@canonical.com";
87 payment_method = "*** *** ** 12";
88 purchase_prize = "65$";
89 purchase_type = "Mp3";
90 preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC;
91
92 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
93
94 unity_protocol_preview_set_title(proto_obj, title.c_str());
95 unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
96 unity_protocol_preview_add_action(proto_obj, "change_payment_method", "Change payment", NULL, 0);
97 unity_protocol_preview_add_action(proto_obj, "forgot_password", "Forgot password", NULL, 0);
98 unity_protocol_preview_add_action(proto_obj, "cancel_purchase", "Cancel", NULL, 0);
99 unity_protocol_preview_add_action(proto_obj, "purchase_album", "Purchase", NULL, 0);
100
101
102 unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
103 unity_protocol_payment_preview_set_email(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), email.c_str());
104 unity_protocol_payment_preview_set_payment_method(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), payment_method.c_str());
105 unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
106 unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
107 unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
108
109 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
110
111 preview_model = dash::Preview::PreviewForVariant(v);
112 }
113
114 nux::ObjectPtr<nux::BaseWindow> parent_window_;
115 dash::Preview::Ptr preview_model;
116
117 // testing data
118 std::string title;
119 std::string subtitle;
120 std::string header;
121 std::string email;
122 std::string payment_method;
123 std::string purchase_prize;
124 std::string purchase_type;
125 UnityProtocolPreviewPaymentType preview_type;
126
127 // needed for styles
128 unity::Settings settings;
129 dash::Style dash_style;
130
131};
132
133TEST_F(TestMusicPaymentPreview, TestContentLoading)
134{
135 MockedMusicPaymentPreview::Ptr preview_view(new MockedMusicPaymentPreview(preview_model));
136
137 EXPECT_EQ(preview_view->title_->GetText(), title);
138 EXPECT_EQ(preview_view->subtitle_->GetText(), subtitle);
139 EXPECT_EQ(preview_view->intro_->GetText(), header);
140 EXPECT_EQ(preview_view->email_->GetText(), email);
141 EXPECT_EQ(preview_view->payment_->GetText(), payment_method);
142 EXPECT_EQ(preview_view->purchase_type_->GetText(), purchase_type);
143 EXPECT_EQ(preview_view->purchase_prize_->GetText(), purchase_prize);
144}
145
146
147} // previews
148
149} // dash
150
151} // unity
0152
=== added file 'tests/test_previews_payment.cpp'
--- tests/test_previews_payment.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_previews_payment.cpp 2013-03-21 17:32:22 +0000
@@ -0,0 +1,186 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3 * Copyright (C) 2012-2013 Canonical Ltd
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
18 */
19#include <list>
20#include <gmock/gmock.h>
21
22#include <Nux/Nux.h>
23#include <Nux/Layout.h>
24#include <Nux/VLayout.h>
25#include <Nux/BaseWindow.h>
26#include <unity-shared/StaticCairoText.h>
27#include <unity-shared/DashStyle.h>
28#include <unity-shared/PreviewStyle.h>
29#include <unity-shared/ThumbnailGenerator.h>
30#include <unity-shared/CoverArt.h>
31#include "unity-shared/UnitySettings.h"
32
33#include <unity-protocol.h>
34#include "dash/previews/PaymentPreview.h"
35#include "dash/previews/ActionButton.h"
36#include "dash/previews/ActionLink.h"
37#include "test_utils.h"
38
39using namespace testing;
40using ::testing::Return;
41
42namespace unity
43{
44
45namespace dash
46{
47
48namespace previews
49{
50
51class NonAbstractPreview : public PaymentPreview
52{
53public:
54 NonAbstractPreview(dash::Preview::Ptr preview_model)
55 : PaymentPreview(preview_model)
56 {}
57
58 virtual nux::Layout* GetTitle()
59 {
60 return new nux::VLayout();
61 }
62
63 virtual nux::Layout* GetPrice()
64 {
65 return new nux::VLayout();
66 }
67
68 virtual nux::Layout* GetBody()
69 {
70 return new nux::VLayout();
71 }
72
73 virtual nux::Layout* GetFooter()
74 {
75 return new nux::VLayout();
76 }
77
78 virtual void OnActionActivated(ActionButton* button, std::string const& id)
79 {
80 // do nothing
81 }
82
83 virtual void OnActionLinkActivated(ActionLink* link, std::string const& id)
84 {
85 // do nothing
86 }
87
88 virtual void PreLayoutManagement()
89 {
90 // do nothing
91 }
92
93 virtual void LoadActions()
94 {
95 // do nothing
96 }
97
98 using PaymentPreview::GetHeader;
99 using PaymentPreview::full_data_layout_;
100 using PaymentPreview::content_data_layout_;
101 using PaymentPreview::overlay_layout_;
102 using PaymentPreview::header_layout_;
103 using PaymentPreview::body_layout_;
104 using PaymentPreview::footer_layout_;
105 using PaymentPreview::SetupViews;
106
107};
108
109class MockedPaymentPreview : public NonAbstractPreview
110{
111public:
112 typedef nux::ObjectPtr<MockedPaymentPreview> Ptr;
113
114 MockedPaymentPreview(dash::Preview::Ptr preview_model)
115 : NonAbstractPreview(preview_model)
116 {}
117
118 // Mock methods that should be implemented so that we can assert that they are
119 // called in the correct moments.
120 MOCK_METHOD0(GetTitle, nux::Layout*());
121 MOCK_METHOD0(GetPrice, nux::Layout*());
122 MOCK_METHOD0(GetBody, nux::Layout*());
123 MOCK_METHOD0(GetFooter, nux::Layout*());
124 MOCK_METHOD2(OnActionActivated, void(unity::dash::ActionButton*, std::string));
125 MOCK_METHOD2(OnActionLinkActivated, void(unity::dash::ActionLink*, std::string));
126 MOCK_METHOD0(PreLayoutManagement, void());
127 MOCK_METHOD0(LoadActions, void());
128
129};
130
131class TestPaymentPreview : public ::testing::Test
132{
133 protected:
134 TestPaymentPreview() : Test()
135 {
136 glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
137 // we are not testing how the info is really used is more asserting the method calls, we do not add any data then
138 glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
139
140 preview_model = dash::Preview::PreviewForVariant(v);
141
142 preview = new MockedPaymentPreview(preview_model);
143
144 }
145 nux::ObjectPtr<MockedPaymentPreview> preview;
146 dash::Preview::Ptr preview_model;
147
148 // needed for styles
149 unity::Settings settings;
150 dash::Style dash_style;
151
152};
153
154TEST_F(TestPaymentPreview, GetHeaderCallsCorrectMethods)
155{
156 ON_CALL(*preview.GetPointer(), GetTitle()).WillByDefault(Return(new nux::VLayout()));
157 EXPECT_CALL(*preview.GetPointer(), GetTitle()).Times(1);
158
159 ON_CALL(*preview.GetPointer(), GetPrice()).WillByDefault(Return(new nux::VLayout()));
160 EXPECT_CALL(*preview.GetPointer(), GetPrice()).Times(1);
161
162 preview->GetHeader();
163}
164
165TEST_F(TestPaymentPreview, SetupViewsCallCorrectMethods)
166{
167 ON_CALL(*preview.GetPointer(), GetTitle()).WillByDefault(Return(new nux::VLayout()));
168 EXPECT_CALL(*preview.GetPointer(), GetTitle()).Times(1);
169
170 ON_CALL(*preview.GetPointer(), GetPrice()).WillByDefault(Return(new nux::VLayout()));
171 EXPECT_CALL(*preview.GetPointer(), GetPrice()).Times(1);
172
173 ON_CALL(*preview.GetPointer(), GetBody()).WillByDefault(Return(new nux::VLayout()));
174 EXPECT_CALL(*preview.GetPointer(), GetBody()).Times(1);
175
176 ON_CALL(*preview.GetPointer(), GetFooter()).WillByDefault(Return(new nux::VLayout()));
177 EXPECT_CALL(*preview.GetPointer(), GetFooter()).Times(1);
178
179 preview->SetupViews();
180}
181
182} // previews
183
184} // dash
185
186} // unity
0187
=== modified file 'unity-shared/PreviewStyle.cpp'
--- unity-shared/PreviewStyle.cpp 2012-11-29 10:19:01 +0000
+++ unity-shared/PreviewStyle.cpp 2013-03-21 17:32:22 +0000
@@ -292,6 +292,91 @@
292 return 12;292 return 12;
293}293}
294294
295std::string Style::payment_title_font() const
296{
297 return "Ubuntu 22";
298}
299
300std::string Style::payment_subtitle_font() const
301{
302 return "Ubuntu 12.5";
303}
304
305std::string Style::payment_prize_title_font() const
306{
307 return "Ubuntu Bold 12.5";
308}
309
310std::string Style::payment_prize_subtitle_font() const
311{
312 return "Ubuntu 10";
313}
314
315std::string Style::payment_intro_font() const
316{
317 return "Ubuntu 11.5";
318}
319
320std::string Style::payment_form_labels_font() const
321{
322 return "Ubuntu 10";
323}
324
325std::string Style::payment_form_data_font() const
326{
327 return "Ubuntu Bold 10";
328}
329
330std::string Style::payment_form_actions_font() const
331{
332 return "Ubuntu 10";
333}
334
335std::string Style::payment_text_input_font() const
336{
337 return "Ubuntu 14";
338}
339
340nux::Color Style::payment_error_color() const
341{
342 return nux::Color(255, 0, 0);
343}
344
345int Style::GetPaymentIconAreaWidth() const
346{
347 return 64;
348}
349
350int Style::GetPaymentTextInputHeight() const
351{
352 return 40;
353}
354
355int Style::GetPaymentLockWidth() const
356{
357 return 22;
358}
359
360int Style::GetPaymentLockHeight() const
361{
362 return 22;
363}
364
365int Style::GetPaymentHeaderWidth() const
366{
367 return 850;
368}
369
370int Style::GetPaymentHeaderSpace() const
371{
372 return 0;
373}
374
375int Style::GetPaymentFormSpace() const
376{
377 return 5;
378}
379
295float Style::GetVideoImageAspectRatio() const380float Style::GetVideoImageAspectRatio() const
296{381{
297 return float(540)/380;382 return float(540)/380;
@@ -401,6 +486,12 @@
401 return pimpl->preview_pause_texture_.texture();486 return pimpl->preview_pause_texture_.texture();
402}487}
403488
489nux::BaseTexture* Style::GetLockIcon()
490{
491 return nux::CreateTexture2DFromFile(
492 PKGDATADIR"/lock_icon.png", -1, true);
493}
494
404nux::BaseTexture* Style::GetSearchSpinIcon(int size)495nux::BaseTexture* Style::GetSearchSpinIcon(int size)
405{496{
406 return pimpl->preview_spin_texture_.texture(size);497 return pimpl->preview_spin_texture_.texture(size);
407498
=== modified file 'unity-shared/PreviewStyle.h'
--- unity-shared/PreviewStyle.h 2012-11-29 10:19:01 +0000
+++ unity-shared/PreviewStyle.h 2013-03-21 17:32:22 +0000
@@ -25,7 +25,7 @@
2525
26#include <Nux/Nux.h>26#include <Nux/Nux.h>
27#include <Nux/View.h>27#include <Nux/View.h>
28 28
29#include <string>29#include <string>
30#include <memory>30#include <memory>
3131
@@ -54,12 +54,12 @@
54public:54public:
55 Style();55 Style();
56 ~Style();56 ~Style();
57 57
58 static Style& Instance();58 static Style& Instance();
5959
60 int GetNavigatorWidth() const;60 int GetNavigatorWidth() const;
61 int GetNavigatorIconSize() const;61 int GetNavigatorIconSize() const;
62 62
63 int GetPreviewWidth() const;63 int GetPreviewWidth() const;
64 int GetPreviewHeight() const;64 int GetPreviewHeight() const;
65 int GetPreviewTopPadding() const;65 int GetPreviewTopPadding() const;
@@ -123,7 +123,7 @@
123123
124 int GetTrackHeight() const;124 int GetTrackHeight() const;
125 ////////////////////////////////125 ////////////////////////////////
126 126
127 ////////////////////////////////127 ////////////////////////////////
128 // Movie Preview128 // Movie Preview
129 float GetVideoImageAspectRatio() const;129 float GetVideoImageAspectRatio() const;
@@ -146,8 +146,33 @@
146 nux::BaseTexture* GetNavRightIcon();146 nux::BaseTexture* GetNavRightIcon();
147 nux::BaseTexture* GetPlayIcon();147 nux::BaseTexture* GetPlayIcon();
148 nux::BaseTexture* GetPauseIcon();148 nux::BaseTexture* GetPauseIcon();
149 nux::BaseTexture* GetLockIcon();
149 nux::BaseTexture* GetSearchSpinIcon(int size = -1);150 nux::BaseTexture* GetSearchSpinIcon(int size = -1);
150 151
152 ////////////////////////////////
153 // Payment Preview
154 std::string payment_title_font() const;
155 std::string payment_subtitle_font() const;
156 std::string payment_prize_title_font() const;
157 std::string payment_prize_subtitle_font() const;
158 std::string payment_intro_font() const;
159 std::string payment_form_labels_font() const;
160 std::string payment_form_data_font() const;
161 std::string payment_form_actions_font() const;
162 std::string payment_text_input_font() const;
163 nux::Color payment_error_color() const;
164
165
166 int GetPaymentIconAreaWidth() const;
167 int GetPaymentTextInputHeight() const;
168 int GetPaymentLockWidth() const;
169 int GetPaymentLockHeight() const;
170 int GetPaymentHeaderWidth() const;
171 int GetPaymentHeaderSpace() const;
172 int GetPaymentFormSpace() const;
173
174 /////////////////////////////////
175
151protected:176protected:
152 class Impl;177 class Impl;
153 std::unique_ptr<Impl> pimpl;178 std::unique_ptr<Impl> pimpl;

Subscribers

People subscribed via source and target branches