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

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

Commit message

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

Description of the change

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

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

LGTM

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/PaymentPreview.cpp'
2--- UnityCore/PaymentPreview.cpp 2013-03-21 16:35:40 +0000
3+++ UnityCore/PaymentPreview.cpp 2013-03-21 16:35:46 +0000
4@@ -41,6 +41,7 @@
5 std::string get_payment_method() const { return payment_method_; };
6 std::string get_purchase_prize() const { return purchase_prize_; };
7 std::string get_purchase_type() const { return purchase_type_; };
8+ PreviewType get_preview_type() const { return preview_type_; };
9
10 // getters for the lables
11
12@@ -52,6 +53,7 @@
13 std::string payment_method_;
14 std::string purchase_prize_;
15 std::string purchase_type_;
16+ PaymentPreview::PreviewType preview_type_;
17
18 };
19
20@@ -73,7 +75,19 @@
21 if (s) purchase_prize_ = s;
22 s = unity_protocol_payment_preview_get_purchase_type(preview);
23 if (s) purchase_type_ = s;
24-
25+ UnityProtocolPreviewPaymentType t = unity_protocol_payment_preview_get_preview_type(preview);
26+ switch(t)
27+ {
28+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_APPLICATION:
29+ preview_type_ = PaymentPreview::APPLICATION;
30+ break;
31+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_MUSIC:
32+ preview_type_ = PaymentPreview::MUSIC;
33+ break;
34+ case UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR:
35+ preview_type_ = PaymentPreview::ERROR;
36+ break;
37+ }
38 SetupGetters();
39 }
40
41@@ -87,8 +101,8 @@
42 sigc::mem_fun(this, &PaymentPreview::Impl::get_payment_method));
43 owner_->purchase_prize.SetGetterFunction(
44 sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_prize));
45- owner_->purchase_type.SetGetterFunction(
46- sigc::mem_fun(this, &PaymentPreview::Impl::get_purchase_type));
47+ owner_->preview_type.SetGetterFunction(
48+ sigc::mem_fun(this, &PaymentPreview::Impl::get_preview_type));
49 }
50
51 PaymentPreview::PaymentPreview(unity::glib::Object<GObject> const& proto_obj)
52
53=== modified file 'UnityCore/PaymentPreview.h'
54--- UnityCore/PaymentPreview.h 2013-03-21 16:35:40 +0000
55+++ UnityCore/PaymentPreview.h 2013-03-21 16:35:46 +0000
56@@ -34,6 +34,8 @@
57 class PaymentPreview : public Preview
58 {
59 public:
60+ enum PreviewType { APPLICATION, MUSIC, ERROR };
61+
62 typedef std::shared_ptr<PaymentPreview> Ptr;
63
64 PaymentPreview(unity::glib::Object<GObject> const& proto_obj);
65@@ -47,6 +49,7 @@
66 nux::RWProperty<std::string> payment_method;
67 nux::RWProperty<std::string> purchase_prize;
68 nux::RWProperty<std::string> purchase_type;
69+ nux::RWProperty<PaymentPreview::PreviewType> preview_type;
70
71 private:
72 class Impl;
73
74=== modified file 'UnityCore/Preview.cpp'
75--- UnityCore/Preview.cpp 2013-03-21 16:35:40 +0000
76+++ UnityCore/Preview.cpp 2013-03-21 16:35:46 +0000
77@@ -32,7 +32,6 @@
78 #include "PaymentPreview.h"
79 #include "SocialPreview.h"
80
81-
82 namespace unity
83 {
84 namespace dash
85
86=== modified file 'UnityCore/Preview.h'
87--- UnityCore/Preview.h 2013-02-27 18:04:26 +0000
88+++ UnityCore/Preview.h 2013-03-21 16:35:46 +0000
89@@ -95,7 +95,7 @@
90 unity::glib::Variant value;
91
92 InfoHint() {};
93- InfoHint(const gchar* id_, const gchar* display_name_,
94+ InfoHint(const gchar* id_, const gchar* display_name_,
95 const gchar* icon_hint_, GVariant* value_)
96 : id(id_ != NULL ? id_ : "")
97 , display_name(display_name_ != NULL ? display_name_ : "")
98
99=== modified file 'dash/previews/CMakeLists.txt'
100--- dash/previews/CMakeLists.txt 2013-03-21 16:35:40 +0000
101+++ dash/previews/CMakeLists.txt 2013-03-21 16:35:46 +0000
102@@ -36,6 +36,7 @@
103 Track.cpp
104 Tracks.cpp
105 MusicPaymentPreview.cpp
106+ ErrorPreview.cpp
107 )
108
109 add_library (previews-lib STATIC ${PREVIEWS_SOURCES})
110@@ -43,33 +44,40 @@
111 target_link_libraries (previews-lib unity-shared)
112 add_pch(pch/previews_pch.hh previews-lib)
113
114-#
115+#
116 # Application Standalone variant
117 #
118 add_executable (app_previews StandaloneApplicationPreview.cpp)
119 target_link_libraries (app_previews previews-lib unity-shared)
120
121-#
122+#
123 # Music Standalone variant
124 #
125 add_executable (music_previews StandaloneMusicPreview.cpp)
126 target_link_libraries (music_previews previews-lib unity-shared)
127
128-#
129+#
130 # Social Standalone variant
131 #
132 add_executable (social_previews StandaloneSocialPreview.cpp)
133 target_link_libraries (social_previews previews-lib unity-shared)
134
135-#
136+#
137 # Movie Standalone variant
138 #
139 add_executable (movie_previews StandaloneMoviePreview.cpp)
140 target_link_libraries (movie_previews previews-lib unity-shared)
141
142-#
143+#
144 # Payment Standalone variant
145 #
146 add_executable (payment_previews StandaloneMusicPaymentPreview.cpp)
147 add_dependencies (payment_previews previews-lib)
148 target_link_libraries (payment_previews previews-lib unity-shared)
149+
150+#
151+# Error Standalone variant
152+#
153+add_executable (error_previews StandaloneErrorPreview.cpp)
154+add_dependencies (error_previews previews-lib)
155+target_link_libraries (error_previews previews-lib unity-shared)
156
157=== added file 'dash/previews/ErrorPreview.cpp'
158--- dash/previews/ErrorPreview.cpp 1970-01-01 00:00:00 +0000
159+++ dash/previews/ErrorPreview.cpp 2013-03-21 16:35:46 +0000
160@@ -0,0 +1,246 @@
161+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
162+/*
163+ * Copyright 2012-2013 Canonical Ltd.
164+ *
165+ * This program is free software: you can redistribute it and/or modify it
166+ * under the terms of the GNU Lesser General Public License version 3, as
167+ * published by the Free Software Foundation.
168+ *
169+ * This program is distributed in the hope that it will be useful, but
170+ * WITHOUT ANY WARRANTY; without even the implied warranties of
171+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
172+ * PURPOSE. See the applicable version of the GNU Lesser General Public
173+ * License for more details.
174+ *
175+ * You should have received a copy of both the GNU Lesser General Public
176+ * License version 3 along with this program. If not, see
177+ * <http://www.gnu.org/licenses/>
178+ *
179+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
180+ * Manuel de la Pena <manuel.delapena@canonical.com>
181+ *
182+ */
183+
184+#include "unity-shared/IntrospectableWrappers.h"
185+#include "unity-shared/PreviewStyle.h"
186+#include "unity-shared/CoverArt.h"
187+#include "unity-shared/StaticCairoText.h"
188+#include "unity-shared/PlacesVScrollBar.h"
189+#include <NuxCore/Logger.h>
190+#include <Nux/VLayout.h>
191+#include <Nux/HLayout.h>
192+#include <Nux/GridHLayout.h>
193+#include <Nux/AbstractButton.h>
194+
195+#include "ErrorPreview.h"
196+#include "PreviewInfoHintWidget.h"
197+
198+#include "stdio.h"
199+#include "config.h"
200+
201+namespace unity
202+{
203+namespace dash
204+{
205+namespace previews
206+{
207+
208+namespace
209+{
210+nux::logging::Logger logger("unity.dash.previews.ErrorPreview");
211+
212+}
213+
214+class DetailsScrollView : public nux::ScrollView
215+{
216+public:
217+ DetailsScrollView(NUX_FILE_LINE_PROTO)
218+ : ScrollView(NUX_FILE_LINE_PARAM)
219+ {
220+ SetVScrollBar(new dash::PlacesVScrollBar(NUX_TRACKER_LOCATION));
221+ }
222+
223+};
224+
225+NUX_IMPLEMENT_OBJECT_TYPE(ErrorPreview)
226+
227+ErrorPreview::ErrorPreview(dash::Preview::Ptr preview_model)
228+: PaymentPreview(preview_model)
229+{
230+ PaymentPreview::SetupBackground();
231+ SetupViews();
232+}
233+
234+ErrorPreview::~ErrorPreview()
235+{
236+}
237+
238+nux::Area* ErrorPreview::FindKeyFocusArea(unsigned int key_symbol,
239+ unsigned long x11_key_code,
240+ unsigned long special_keys_state)
241+{
242+ return Preview::FindKeyFocusArea(key_symbol, x11_key_code, special_keys_state);
243+}
244+
245+std::string ErrorPreview::GetName() const
246+{
247+ return "ErrorPreview";
248+}
249+
250+void ErrorPreview::OnActionActivated(ActionButton* button, std::string const& id)
251+{
252+}
253+
254+void ErrorPreview::OnActionLinkActivated(ActionLink *link, std::string const& id)
255+{
256+ if (preview_model_)
257+ preview_model_->PerformAction(id);
258+}
259+
260+void ErrorPreview::LoadActions()
261+{
262+ // Loop over the buttons and add them to the correct var
263+ // this is not efficient but is the only way we have atm
264+ for (dash::Preview::ActionPtr action : preview_model_->GetActions())
265+ {
266+ const char *action_id = action->id.c_str();
267+ if(strcmp(OPEN_U1_LINK_ACTION, action_id) == 0)
268+ {
269+ nux::ObjectPtr<ActionLink> link = this->CreateLink(action);
270+ link->activate.connect(sigc::mem_fun(this,
271+ &ErrorPreview::OnActionLinkActivated));
272+
273+ std::pair<std::string, nux::ObjectPtr<nux::AbstractButton>> data (action->id, link);
274+ sorted_buttons_.insert(data);
275+ }
276+ LOG_DEBUG(logger) << "added button for action with id '" << action->id << "'";
277+ }
278+}
279+
280+nux::Layout* ErrorPreview::GetTitle()
281+{
282+ previews::Style& style = dash::previews::Style::Instance();
283+ nux::VLayout* title_data_layout = new nux::VLayout();
284+ title_data_layout->SetMaximumHeight(76);
285+ title_data_layout->SetSpaceBetweenChildren(10);
286+
287+ title_ = new StaticCairoText(
288+ preview_model_->title.Get(), true,
289+ NUX_TRACKER_LOCATION);
290+
291+ title_->SetFont(style.payment_title_font().c_str());
292+ title_->SetLines(-1);
293+ title_->SetFont(style.title_font().c_str());
294+ title_data_layout->AddView(title_.GetPointer(), 1);
295+
296+ subtitle_ = new StaticCairoText(
297+ preview_model_->subtitle.Get(), true,
298+ NUX_TRACKER_LOCATION);
299+ subtitle_->SetLines(-1);
300+ subtitle_->SetFont(style.payment_subtitle_font().c_str());
301+ title_data_layout->AddView(subtitle_.GetPointer(), 1);
302+ title_data_layout->AddSpace(1, 1);
303+ return title_data_layout;
304+}
305+
306+nux::Layout* ErrorPreview::GetPrice()
307+{
308+ previews::Style& style = dash::previews::Style::Instance();
309+ nux::VLayout *prize_data_layout = new nux::VLayout();
310+ prize_data_layout->SetMaximumHeight(76);
311+ prize_data_layout->SetSpaceBetweenChildren(5);
312+
313+ purchase_prize_ = new StaticCairoText(
314+ error_preview_model_->purchase_prize.Get(), true,
315+ NUX_TRACKER_LOCATION);
316+ purchase_prize_->SetLines(-1);
317+ purchase_prize_->SetFont(style.payment_prize_title_font().c_str());
318+ prize_data_layout->AddView(purchase_prize_.GetPointer(), 1,
319+ nux::MINOR_POSITION_END);
320+
321+ purchase_hint_ = new StaticCairoText(
322+ _("Ubuntu One best offer"),
323+ true, NUX_TRACKER_LOCATION);
324+ purchase_hint_->SetLines(-1);
325+ purchase_hint_->SetFont(style.payment_prize_subtitle_font().c_str());
326+ prize_data_layout->AddView(purchase_hint_.GetPointer(), 1,
327+ nux::MINOR_POSITION_END);
328+
329+ purchase_type_ = new StaticCairoText(
330+ error_preview_model_->purchase_type.Get(), true,
331+ NUX_TRACKER_LOCATION);
332+ purchase_type_->SetLines(-1);
333+ purchase_type_->SetFont(style.payment_prize_subtitle_font().c_str());
334+ prize_data_layout->AddView(purchase_type_.GetPointer(), 1,
335+ nux::MINOR_POSITION_END);
336+ return prize_data_layout;
337+}
338+
339+nux::Layout* ErrorPreview::GetBody()
340+{
341+ previews::Style& style = dash::previews::Style::Instance();
342+ nux::HLayout *body_layout = new nux::HLayout();
343+
344+ lock_texture_ = new IconTexture(style.GetLockIcon(), style.GetPaymentLockWidth(),
345+ style.GetPaymentLockHeight());
346+
347+ intro_ = new StaticCairoText(
348+ error_preview_model_->header.Get(), true,
349+ NUX_TRACKER_LOCATION);
350+ intro_->SetMaximumWidth(style.GetPaymentHeaderWidth());
351+ intro_->SetFont(style.payment_intro_font().c_str());
352+ intro_->SetLineSpacing(10);
353+ intro_->SetLines(-style.GetDescriptionLineCount());
354+ intro_->SetMinimumHeight(50);
355+ body_layout->AddView(sorted_buttons_[OPEN_U1_LINK_ACTION].GetPointer(),
356+ 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0f,
357+ nux::NUX_LAYOUT_END);
358+ body_layout->AddView(lock_texture_, 0, nux::MINOR_POSITION_CENTER,
359+ nux::MINOR_SIZE_FULL, 100.0f, nux::NUX_LAYOUT_BEGIN);
360+ body_layout->AddView(intro_.GetPointer(), 1);
361+ return body_layout;
362+}
363+
364+nux::Layout* ErrorPreview::GetFooter()
365+{
366+ nux::HLayout* buttons_data_layout = new nux::HLayout();
367+ return buttons_data_layout;
368+}
369+
370+void ErrorPreview::PreLayoutManagement()
371+{
372+ nux::Geometry geo = GetGeometry();
373+ GetLayout()->SetGeometry(geo);
374+
375+ previews::Style& style = dash::previews::Style::Instance();
376+
377+ int width = MAX(0, geo.width - style.GetPanelSplitWidth() - style.GetDetailsLeftMargin() - style.GetDetailsRightMargin());
378+
379+ if(full_data_layout_) { full_data_layout_->SetMaximumWidth(width); }
380+ if(header_layout_) { header_layout_->SetMaximumWidth(width); }
381+ if(intro_) { intro_->SetMaximumWidth(width); }
382+ if(form_layout_) { form_layout_->SetMaximumWidth(width); }
383+ if(footer_layout_) { footer_layout_->SetMaximumWidth(width); }
384+
385+ Preview::PreLayoutManagement();
386+}
387+
388+void ErrorPreview::SetupViews()
389+{
390+ error_preview_model_ = dynamic_cast<dash::PaymentPreview*>(preview_model_.get());
391+ if (!error_preview_model_)
392+ {
393+ LOG_ERROR(logger) << "Could not derive preview model from given parameter.";
394+ return;
395+ }
396+
397+ // load the buttons so that they can be accessed in order
398+ LoadActions();
399+
400+ PaymentPreview::SetupViews();
401+}
402+
403+
404+}
405+}
406+}
407
408=== added file 'dash/previews/ErrorPreview.h'
409--- dash/previews/ErrorPreview.h 1970-01-01 00:00:00 +0000
410+++ dash/previews/ErrorPreview.h 2013-03-21 16:35:46 +0000
411@@ -0,0 +1,119 @@
412+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
413+/*
414+ * Copyright 2012-2013 Canonical Ltd.
415+ *
416+ * This program is free software: you can redistribute it and/or modify it
417+ * under the terms of the GNU Lesser General Public License version 3, as
418+ * published by the Free Software Foundation.
419+ *
420+ * This program is distributed in the hope that it will be useful, but
421+ * WITHOUT ANY WARRANTY; without even the implied warranties of
422+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
423+ * PURPOSE. See the applicable version of the GNU Lesser General Public
424+ * License for more details.
425+ *
426+ * You should have received a copy of both the GNU Lesser General Public
427+ * License version 3 along with this program. If not, see
428+ * <http://www.gnu.org/licenses/>
429+ *
430+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
431+ * Manuel de la Pena <manuel.delapena@canonical.com>
432+ *
433+ */
434+
435+#ifndef ERROR_PREVIEW_H
436+#define ERROR_PREVIEW_H
437+
438+// key used to find the correct info hint
439+#define ERROR_INFOHINT_ID "error_preview"
440+
441+// keys of the data preview
442+// Necessary??
443+#define DATA_MESSAGE_KEY "message"
444+
445+// ations ids
446+#define OPEN_U1_LINK_ACTION "open_u1_link"
447+
448+#include <Nux/Nux.h>
449+#include <Nux/AbstractButton.h>
450+#include <UnityCore/Lens.h>
451+#include "ActionButton.h"
452+#include "ActionLink.h"
453+#include "PaymentPreview.h"
454+#include "unity-shared/IconTexture.h"
455+#include "unity-shared/TextInput.h"
456+
457+namespace nux
458+{
459+class AbstractPaintLayer;
460+class StaticCairoText;
461+class VLayout;
462+}
463+
464+namespace unity
465+{
466+namespace dash
467+{
468+namespace previews
469+{
470+class CoverArt;
471+class PreviewInfoHintWidget;
472+
473+class ErrorPreview : public PaymentPreview
474+{
475+public:
476+ typedef nux::ObjectPtr<ErrorPreview> Ptr;
477+ NUX_DECLARE_OBJECT_TYPE(ErrorPreview, Preview)
478+
479+ ErrorPreview(dash::Preview::Ptr preview_model);
480+ ~ErrorPreview();
481+
482+ nux::Area* FindKeyFocusArea(unsigned int key_symbol,
483+ unsigned long x11_key_code,
484+ unsigned long special_keys_state);
485+ // From debug::Introspectable
486+ std::string GetName() const;
487+ nux::Layout* GetTitle();
488+ nux::Layout* GetPrice();
489+ nux::Layout* GetBody();
490+ nux::Layout* GetFooter();
491+
492+private:
493+ void LoadActions();
494+
495+protected:
496+ void OnActionActivated(ActionButton* button, std::string const& id);
497+ void OnActionLinkActivated(ActionLink* link, std::string const& id);
498+
499+ void PreLayoutManagement();
500+
501+ virtual void SetupViews();
502+ // content elements
503+ nux::ObjectPtr<CoverArt> image_;
504+ nux::ObjectPtr<StaticCairoText> intro_;
505+ nux::ObjectPtr<StaticCairoText> title_;
506+ nux::ObjectPtr<StaticCairoText> subtitle_;
507+ nux::ObjectPtr<StaticCairoText> purchase_hint_;
508+ nux::ObjectPtr<StaticCairoText> purchase_prize_;
509+ nux::ObjectPtr<StaticCairoText> purchase_type_;
510+ nux::ObjectPtr<nux::HLayout> form_layout_;
511+
512+ dash::PaymentPreview* error_preview_model_;
513+ // do we want to type?
514+ bool entry_selected_;
515+
516+ // actions
517+ std::map<std::string, nux::ObjectPtr<nux::AbstractButton>> sorted_buttons_;
518+
519+ // lock texture
520+ IconTexture* lock_texture_;
521+
522+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
523+ LayerPtr details_bg_layer_;
524+};
525+
526+}
527+}
528+}
529+
530+#endif // ERROR_PREVIEW_H
531
532=== modified file 'dash/previews/PaymentPreview.cpp'
533--- dash/previews/PaymentPreview.cpp 2013-03-21 16:35:40 +0000
534+++ dash/previews/PaymentPreview.cpp 2013-03-21 16:35:46 +0000
535@@ -36,6 +36,7 @@
536
537 namespace
538 {
539+
540 nux::logging::Logger logger("unity.dash.previews.payment.preview");
541
542 }
543
544=== modified file 'dash/previews/Preview.cpp'
545--- dash/previews/Preview.cpp 2013-03-21 16:35:40 +0000
546+++ dash/previews/Preview.cpp 2013-03-21 16:35:46 +0000
547@@ -32,6 +32,7 @@
548
549 #include "GenericPreview.h"
550 #include "ApplicationPreview.h"
551+#include "ErrorPreview.h"
552 #include "MusicPreview.h"
553 #include "MoviePreview.h"
554 #include "MusicPaymentPreview.h"
555@@ -60,7 +61,16 @@
556 }
557 else if (model->renderer_name == "preview-payment")
558 {
559- return Preview::Ptr(new MusicPaymentPreview(model));
560+ dash::PaymentPreview* payment_preview_model = dynamic_cast<dash::PaymentPreview*>(
561+ model.get());
562+ if (payment_preview_model->preview_type.Get() == dash::PaymentPreview::MUSIC)
563+ {
564+ return Preview::Ptr(new MusicPaymentPreview(model));
565+ }
566+ else
567+ {
568+ return Preview::Ptr(new ErrorPreview(model));
569+ }
570 }
571 else if (model->renderer_name == "preview-application")
572 {
573
574=== added file 'dash/previews/StandaloneErrorPreview.cpp'
575--- dash/previews/StandaloneErrorPreview.cpp 1970-01-01 00:00:00 +0000
576+++ dash/previews/StandaloneErrorPreview.cpp 2013-03-21 16:35:46 +0000
577@@ -0,0 +1,219 @@
578+/*
579+ * Copyright 2012-2013 Canonical Ltd.
580+ *
581+ * This program is free software: you can redistribute it and/or modify it
582+ * under the terms of the GNU General Public License version 3, as published
583+ * by the Free Software Foundation.
584+ *
585+ * This program is distributed in the hope that it will be useful, but
586+ * WITHOUT ANY WARRANTY; without even the implied warranties of
587+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
588+ * PURPOSE. See the GNU General Public License for more details.
589+ *
590+ * You should have received a copy of the GNU General Public License
591+ * version 3 along with this program. If not, see
592+ * <http://www.gnu.org/licenses/>
593+ *
594+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
595+ *
596+ */
597+
598+#include <gtk/gtk.h>
599+
600+#include "Nux/Nux.h"
601+#include "Nux/VLayout.h"
602+#include "Nux/WindowThread.h"
603+#include "NuxGraphics/GraphicsEngine.h"
604+#include <Nux/Layout.h>
605+#include <NuxCore/Logger.h>
606+#include <UnityCore/Variant.h>
607+#include <UnityCore/Preview.h>
608+#include <unity-protocol.h>
609+
610+#include "unity-shared/FontSettings.h"
611+#include "unity-shared/UnitySettings.h"
612+#include "unity-shared/PreviewStyle.h"
613+#include "unity-shared/DashStyle.h"
614+#include "unity-shared/ThumbnailGenerator.h"
615+
616+#include "Preview.h"
617+#include "PreviewContainer.h"
618+
619+
620+#define WIDTH 1100
621+#define HEIGHT 600
622+
623+using namespace unity;
624+using namespace unity::dash;
625+
626+namespace
627+{
628+nux::logging::Logger logger("unity.dash.StandaloneMusicPreview");
629+}
630+
631+class DummyView : public nux::View
632+{
633+public:
634+ DummyView(nux::View* view)
635+ : View(NUX_TRACKER_LOCATION)
636+ {
637+ SetAcceptKeyNavFocusOnMouseDown(false);
638+ SetAcceptKeyNavFocusOnMouseEnter(false);
639+
640+ nux::ROPConfig rop;
641+ rop.Blend = true;
642+ rop.SrcBlend = GL_ONE;
643+ rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
644+ bg_layer_.reset(new nux::ColorLayer(nux::Color(81, 26, 48), true, rop));
645+
646+ nux::Layout* layout = new nux::VLayout();
647+ layout->SetPadding(10);
648+ layout->AddView(view, 1, nux::MINOR_POSITION_CENTER);
649+ SetLayout(layout);
650+ }
651+
652+ // Keyboard navigation
653+ bool AcceptKeyNavFocus()
654+ {
655+ return false;
656+ }
657+
658+protected:
659+ virtual void Draw(nux::GraphicsEngine& gfx_engine, bool force_draw)
660+ {
661+ nux::Geometry const& base = GetGeometry();
662+
663+ gfx_engine.PushClippingRectangle(base);
664+ nux::GetPainter().PaintBackground(gfx_engine, base);
665+
666+ unsigned int alpha, src, dest = 0;
667+ gfx_engine.GetRenderStates().GetBlend(alpha, src, dest);
668+ gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
669+
670+ bg_layer_->SetGeometry(GetGeometry());
671+ nux::GetPainter().RenderSinglePaintLayer(gfx_engine, GetGeometry(), bg_layer_.get());
672+
673+ gfx_engine.GetRenderStates().SetBlend(alpha, src, dest);
674+
675+ gfx_engine.PopClippingRectangle();
676+ }
677+
678+ virtual void DrawContent(nux::GraphicsEngine& gfx_engine, bool force_draw)
679+ {
680+ nux::Geometry const& base = GetGeometry();
681+ gfx_engine.PushClippingRectangle(base);
682+
683+ if (!IsFullRedraw())
684+ nux::GetPainter().PushLayer(gfx_engine, GetGeometry(), bg_layer_.get());
685+
686+ if (GetCompositionLayout())
687+ GetCompositionLayout()->ProcessDraw(gfx_engine, force_draw);
688+
689+ if (!IsFullRedraw())
690+ nux::GetPainter().PopBackground();
691+
692+ gfx_engine.PopClippingRectangle();
693+ }
694+
695+ typedef std::unique_ptr<nux::AbstractPaintLayer> LayerPtr;
696+ LayerPtr bg_layer_;
697+};
698+
699+class TestRunner
700+{
701+public:
702+ TestRunner ();
703+ ~TestRunner ();
704+
705+ static void InitWindowThread (nux::NThread* thread, void* InitData);
706+ void Init ();
707+
708+ previews::PreviewContainer::Ptr container_;
709+ nux::Layout *layout_;
710+ unsigned int nav_iter;
711+ previews::Navigation nav_direction_;
712+ std::string search_string_;
713+ bool first_;
714+};
715+
716+TestRunner::TestRunner ()
717+{
718+}
719+
720+TestRunner::~TestRunner ()
721+{
722+}
723+
724+void TestRunner::Init ()
725+{
726+ container_ = new previews::PreviewContainer(NUX_TRACKER_LOCATION);
727+ container_->request_close.connect([&]() { exit(0); });
728+ container_->DisableNavButton(previews::Navigation::BOTH);
729+
730+ DummyView* dummyView = new DummyView(container_.GetPointer());
731+ layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
732+ layout_->AddView(dummyView, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
733+ nux::GetWindowThread()->SetLayout (layout_);
734+
735+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(
736+ unity_protocol_payment_preview_new()));
737+
738+ unity_protocol_preview_set_title(
739+ proto_obj, "This Modern Glitch");
740+ unity_protocol_preview_set_subtitle(
741+ proto_obj, "The Wombats");
742+ unity_protocol_payment_preview_set_header(
743+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
744+ "A horrible error ocurred!!!");
745+ unity_protocol_payment_preview_set_purchase_prize(
746+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
747+ "10 eur");
748+ unity_protocol_payment_preview_set_purchase_type(
749+ UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
750+ "Digital CD");
751+ unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()),
752+ UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR);
753+
754+ // set the diff actions
755+ unity_protocol_preview_add_action(proto_obj, "open_u1_link", "Go to u1 page", NULL, 0);
756+
757+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())),
758+ glib::StealRef());
759+
760+ dash::Preview::Ptr preview_model(dash::Preview::PreviewForVariant(v));
761+ container_->Preview(preview_model, previews::Navigation::LEFT);
762+}
763+
764+void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
765+{
766+ TestRunner *self = (TestRunner *) InitData;
767+ self->Init ();
768+}
769+
770+int main(int argc, char **argv)
771+{
772+ nux::WindowThread* wt = NULL;
773+
774+ gtk_init (&argc, &argv);
775+
776+ nux::NuxInitialize(0);
777+ nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
778+ // The instances for the pseudo-singletons.
779+ unity::Settings settings;
780+ unity::dash::previews::Style panel_style;
781+ unity::dash::Style dash_style;
782+ unity::ThumbnailGenerator thumbnail_generator;
783+
784+ TestRunner *test_runner = new TestRunner ();
785+ wt = nux::CreateGUIThread(TEXT("Unity Preview"),
786+ WIDTH, HEIGHT,
787+ 0,
788+ &TestRunner::InitWindowThread,
789+ test_runner);
790+
791+ wt->Run (NULL);
792+ delete wt;
793+ return 0;
794+}
795+
796+
797
798=== modified file 'tests/CMakeLists.txt'
799--- tests/CMakeLists.txt 2013-03-21 16:35:40 +0000
800+++ tests/CMakeLists.txt 2013-03-21 16:35:46 +0000
801@@ -244,6 +244,7 @@
802 test_dash_controller.cpp
803 test_desktop_launcher_icon.cpp
804 test_device_launcher_section.cpp
805+ test_error_preview.cpp
806 test_edge_barrier_controller.cpp
807 test_expo_launcher_icon.cpp
808 test_filter_widgets.cpp
809
810=== added file 'tests/test_error_preview.cpp'
811--- tests/test_error_preview.cpp 1970-01-01 00:00:00 +0000
812+++ tests/test_error_preview.cpp 2013-03-21 16:35:46 +0000
813@@ -0,0 +1,111 @@
814+/*
815+ * Copyright 2012-2013 Canonical Ltd.
816+ *
817+ * This program is free software: you can redistribute it and/or modify it
818+ * under the terms of the GNU Lesser General Public License version 3, as
819+ * published by the Free Software Foundation.
820+ *
821+ * This program is distributed in the hope that it will be useful, but
822+ * WITHOUT ANY WARRANTY; without even the implied warranties of
823+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
824+ * PURPOSE. See the applicable version of the GNU Lesser General Public
825+ * License for more details.
826+ *
827+ * You should have received a copy of both the GNU Lesser General Public
828+ * License version 3 along with this program. If not, see
829+ * <http://www.gnu.org/licenses/>
830+ *
831+ * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
832+ *
833+ */
834+#include <list>
835+#include <gmock/gmock.h>
836+using namespace testing;
837+
838+#include <Nux/Nux.h>
839+#include <Nux/BaseWindow.h>
840+#include <unity-shared/StaticCairoText.h>
841+#include <unity-shared/DashStyle.h>
842+#include <unity-shared/PreviewStyle.h>
843+#include <unity-shared/ThumbnailGenerator.h>
844+#include "unity-shared/UnitySettings.h"
845+
846+#include <unity-protocol.h>
847+#include "dash/previews/ErrorPreview.h"
848+#include "test_utils.h"
849+
850+namespace unity
851+{
852+
853+namespace dash
854+{
855+
856+namespace previews
857+{
858+
859+class ErrorPreviewMock : public ErrorPreview
860+{
861+ public:
862+ ErrorPreviewMock(dash::Preview::Ptr preview_model)
863+ : ErrorPreview(preview_model){}
864+ ~ErrorPreviewMock(){}
865+
866+ using ErrorPreview::intro_;
867+ using ErrorPreview::title_;
868+ using ErrorPreview::subtitle_;
869+ using ErrorPreview::purchase_hint_;
870+ using ErrorPreview::purchase_prize_;
871+ using ErrorPreview::purchase_type_;
872+};
873+
874+class TestErrorPreview : public Test
875+{
876+ protected:
877+ TestErrorPreview() :
878+ Test(),
879+ parent_window_(new nux::BaseWindow("TestErrorPayment"))
880+ {
881+ title = "Turning Japanese";
882+ subtitle = "The vapors";
883+ header = "Hi test, you purchased in the past from Ubuntu One.";
884+ purchase_prize = "65$";
885+ purchase_type = "Mp3";
886+ preview_type = UNITY_PROTOCOL_PREVIEW_PAYMENT_TYPE_ERROR;
887+
888+ glib::Object<UnityProtocolPreview> proto_obj(UNITY_PROTOCOL_PREVIEW(unity_protocol_payment_preview_new()));
889+
890+ unity_protocol_preview_set_title(proto_obj, title.c_str());
891+ unity_protocol_preview_set_subtitle(proto_obj, subtitle.c_str());
892+
893+ unity_protocol_payment_preview_set_header(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), header.c_str());
894+ unity_protocol_payment_preview_set_purchase_prize(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_prize.c_str());
895+ unity_protocol_payment_preview_set_purchase_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), purchase_type.c_str());
896+ unity_protocol_payment_preview_set_preview_type(UNITY_PROTOCOL_PAYMENT_PREVIEW(proto_obj.RawPtr()), preview_type);
897+
898+ glib::Variant v(dee_serializable_serialize(DEE_SERIALIZABLE(proto_obj.RawPtr())), glib::StealRef());
899+
900+ preview_model = dash::Preview::PreviewForVariant(v);
901+
902+ }
903+
904+ nux::ObjectPtr<nux::BaseWindow> parent_window_;
905+ dash::Preview::Ptr preview_model;
906+
907+ // testing data
908+ std::string title;
909+ std::string subtitle;
910+ std::string header;
911+ std::string purchase_prize;
912+ std::string purchase_type;
913+ UnityProtocolPreviewPaymentType preview_type;
914+
915+ // needed for styles
916+ unity::Settings settings;
917+ dash::Style dash_style;
918+};
919+
920+} // previews
921+
922+} // dash
923+
924+} // unity

Subscribers

People subscribed via source and target branches