~gary-wzl77/+junk/newproperty

« back to all changes in this revision

Viewing changes to src/scope/preview.cpp

  • Committer: Gary.Wzl
  • Date: 2015-08-31 09:23:43 UTC
  • Revision ID: gary.wang@canonical.com-20150831092343-x7coc5ukz9yelqjn
Init repo

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <scope/preview.h>
 
2
 
 
3
#include <unity/scopes/ColumnLayout.h>
 
4
#include <unity/scopes/PreviewWidget.h>
 
5
#include <unity/scopes/PreviewReply.h>
 
6
#include <unity/scopes/Result.h>
 
7
#include <unity/scopes/VariantBuilder.h>
 
8
 
 
9
#include <iostream>
 
10
 
 
11
namespace sc = unity::scopes;
 
12
 
 
13
using namespace std;
 
14
using namespace scope;
 
15
 
 
16
Preview::Preview(const sc::Result &result, const sc::ActionMetadata &metadata) :
 
17
    sc::PreviewQueryBase(result, metadata) {
 
18
}
 
19
 
 
20
void Preview::cancelled() {
 
21
}
 
22
 
 
23
void Preview::run(sc::PreviewReplyProxy const& reply) {
 
24
    // Support three different column layouts
 
25
    sc::ColumnLayout layout1col(1);
 
26
 
 
27
    // We define 3 different layouts, that will be used depending on the
 
28
    // device. The shell (view) will decide which layout fits best.
 
29
    // If, for instance, we are executing in a tablet probably the view will use
 
30
    // 2 or more columns.
 
31
    // Column layout definitions are optional.
 
32
    // However, we recommend that scopes define layouts for the best visual appearance.
 
33
 
 
34
    // Single column layout
 
35
    layout1col.add_column( { "image", "header", "summary","ratingId",  "infoId", "expId", "commendId", "commendId2", "actionId"});
 
36
 
 
37
    // Register the layouts we just created
 
38
    reply->register_layout( { layout1col});
 
39
 
 
40
    // Define the header section
 
41
    sc::PreviewWidget header("header", "header");
 
42
    // It has title and a subtitle properties
 
43
    header.add_attribute_mapping("title", "title");
 
44
    header.add_attribute_mapping("subtitle", "subtitle");
 
45
 
 
46
    // Define the image section
 
47
    sc::PreviewWidget image("image", "image");
 
48
    // It has a single source property, mapped to the result's art property
 
49
    image.add_attribute_mapping("source", "art");
 
50
 
 
51
    // Define the summary section
 
52
    sc::PreviewWidget description("summary", "text");
 
53
    // It has a text property, mapped to the result's description property
 
54
    description.add_attribute_mapping("text", "description");
 
55
 
 
56
    sc::PreviewWidget w_subTitle("subtitleId", "text");
 
57
    sc::PreviewWidget w_rating ("ratingId", "reviews");
 
58
    sc::PreviewWidget w_Info("infoId", "text");
 
59
    sc::PreviewWidget w_link("actionId", "actions");
 
60
    sc::PreviewWidget w_exp("expId", "expandable");
 
61
    sc::PreviewWidget w_commend("commendId", "rating-input" );
 
62
    sc::PreviewWidget w_commend2("commendId2", "comment-input" );
 
63
    sc::PreviewWidget w_description("description", "text");
 
64
 
 
65
    w_subTitle.add_attribute_value("text", sc::Variant("<i> subTitle </i>"));
 
66
    w_exp.add_attribute_value("title", sc::Variant("<b>Description: </b>"));
 
67
    w_description.add_attribute_value("text", sc::Variant("description \nldfkjalsdjf\n\n "
 
68
                                                                                            "jsldfkjalsdjf\nasdflkajsdlfkajdfs"));
 
69
    w_exp.add_attribute_value("collapsed-widgets", sc::Variant(2));
 
70
    w_exp.add_attribute_value("expanded", sc::Variant(false));
 
71
 
 
72
    w_exp.add_widget(w_commend);
 
73
    w_exp.add_widget(w_subTitle);
 
74
    w_exp.add_widget(w_Info);
 
75
    w_exp.add_widget(w_description);
 
76
    w_exp.add_widget(w_commend2);
 
77
 
 
78
 
 
79
    sc::VariantBuilder rat_builder;
 
80
    rat_builder.add_tuple({{"rating", sc::Variant(6)}});
 
81
    w_rating.add_attribute_value("reviews", rat_builder.end());
 
82
 
 
83
    sc::VariantBuilder builder;
 
84
    builder.add_tuple({
 
85
                            {"id", sc::Variant("open")},
 
86
                            {"label", sc::Variant("Google")},
 
87
                            {"uri", sc::Variant("http://www.google.com")}
 
88
                    });
 
89
    w_link.add_attribute_value("actions", builder.end());
 
90
 
 
91
    // Push each of the sections
 
92
    reply->push( { image, header, description ,w_rating,  w_exp,w_link});
 
93
}
 
94