Adding ActivationQueryBase into the scope template to respond to button clicks

Bug #1468603 reported by XiaoGuo, Liu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
qtcreator-plugin-ubuntu (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

Currently, in our scope template, there is no code touching the ActivationQueryBase, which is needed for responding the button/actions clicks. It is needed in the rating-input PreviewWidget as well.

I would commend adding it into the template to make it more complete though some of the scopes may not need them. A reference design is like:

action.h

#ifndef SCOPE_ACTION_H_
#define SCOPE_ACTION_H_

#include <unity/scopes/ActionMetadata.h>
#include <unity/scopes/ActivationQueryBase.h>
#include <unity/scopes/ActivationResponse.h>
#include <unity/scopes/Result.h>

class Action : public unity::scopes::ActivationQueryBase
{
public:
    Action(unity::scopes::Result const& result,
           unity::scopes::ActionMetadata const& metadata,
           std::string const& action_id);
    ~Action() = default;

     virtual unity::scopes::ActivationResponse activate() override;

private:
    std::string const action_id_;
};

#endif // SCOPE_ACTION_H_

action.cpp

`#include <scope/action.h>
#include <unity/scopes/ActivationResponse.h>
#include <unity/UnityExceptions.h>

#include <QString>
#include <QDebug>

#include <iostream>

namespace sc = unity::scopes;
using namespace std;

QString qstr_(std::string str)
{
    return QString::fromStdString(str);
}

Action::Action(const unity::scopes::Result &result,
               const unity::scopes::ActionMetadata &metadata,
               std::string const& action_id)
    : sc::ActivationQueryBase(result, metadata),
      action_id_(action_id)
{
    qDebug() << "action id: " << qstr_(action_id_);
}

sc::ActivationResponse Action::activate()
{
    qDebug() << "action id in activate: " << qstr_(action_id());

    QString review = QString("%1").arg(qstr_(action_metadata().scope_data().
                                              get_dict()["review"].get_string()));

    double rating = action_metadata().scope_data().
                          get_dict()["rating"].get_double();

    qDebug() << "review: " << review;
    qDebug() << "rating: " << rating;

    sc::ActivationResponse done(sc::ActivationResponse::ShowDash);
    cerr << "activate called" << endl;
    return done;
}

Changed in qtcreator-plugin-ubuntu (Ubuntu):
importance: Undecided → Wishlist
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.