~marcustomlinson/unity-scopes-shell/lp-1552082

« back to all changes in this revision

Viewing changes to tests/data/mock-scope/mock-scope.cpp

  • Committer: Pawel Stolowski
  • Date: 2015-11-30 09:23:32 UTC
  • mfrom: (278 unity-scopes-shell)
  • mto: This revision was merged to the branch mainline in revision 279.
  • Revision ID: pawel.stolowski@canonical.com-20151130092332-io500es46ww36vfc
Merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
            res.set_title("result for: \"" + query_ + "\"");
147
147
            reply->push(res);
148
148
        }
 
149
        else if (query_ == "result-action")
 
150
        {
 
151
            CategoryRenderer minimal_rndr(R"({"schema-version": 1, "components": {"title": "title"}})");
 
152
            auto cat = reply->register_category("cat1", "Category 1", "", minimal_rndr);
 
153
            CategorisedResult res(cat);
 
154
 
 
155
            res.set_uri("test:result-action");
 
156
            res.set_title("result for: \"" + query_ + "\"");
 
157
 
 
158
            // Add result actions
 
159
            VariantBuilder builder;
 
160
            builder.add_tuple({
 
161
                    {"id", Variant("action1")},
 
162
                    {"icon", Variant("icon1")},
 
163
                    {"label", Variant("Action1")},
 
164
            });
 
165
            builder.add_tuple({
 
166
                    {"id", Variant("action2")},
 
167
                    {"icon", Variant("icon2")},
 
168
                    {"label", Variant("Action2")},
 
169
            });
 
170
            res["social_attributes"] = builder.end(); // TODO: verify with shell
 
171
            reply->push(res);
 
172
        }
149
173
        else if (query_ == "update-preview")
150
174
        {
151
175
            CategoryRenderer minimal_rndr(R"({"schema-version": 1, "components": {"title": "title"}})");
445
469
    {
446
470
    }
447
471
 
 
472
    MyActivation(Result const& result, ActionMetadata const& metadata, ActivationResponse::Status status, std::string const& action_id) :
 
473
        ActivationQueryBase(result, metadata),
 
474
        status_(status),
 
475
        action_id_(action_id)
 
476
    {
 
477
    }
 
478
 
448
479
    ~MyActivation() noexcept
449
480
    {
450
481
    }
460
491
 
461
492
    virtual ActivationResponse activate() override
462
493
    {
463
 
        if (status_ == ActivationResponse::Status::PerformQuery) {
 
494
        if (status_ == ActivationResponse::Status::UpdateResult) {
 
495
            Result updatedRes(result());
 
496
            updatedRes["actionId"] = Variant(action_id_);
 
497
            return ActivationResponse(updatedRes);
 
498
        }
 
499
        else if (status_ == ActivationResponse::Status::PerformQuery) {
464
500
            auto resp = ActivationResponse(CannedQuery(result()["scope-id"].get_string()));
465
501
            return resp;
466
502
        } else {
473
509
private:
474
510
    Variant extra_data_;
475
511
    ActivationResponse::Status status_;
 
512
    std::string action_id_;
476
513
};
477
514
 
478
515
 
554
591
        }
555
592
        return ActivationQueryBase::UPtr(new MyActivation(result, meta));
556
593
    }
 
594
 
 
595
    ActivationQueryBase::UPtr activate_result_action(Result const& result, ActionMetadata const& meta, std::string const& action_id) override
 
596
    {
 
597
        return ActivationQueryBase::UPtr(new MyActivation(result, meta, ActivationResponse::UpdateResult, action_id));
 
598
    }
557
599
};
558
600
 
559
601
extern "C"