unity.scopes.qt.QResult
The attributes of a result returned by a Scope. More...
#include <unity/scopes/qt/QResult.h>
Inheritance diagram for unity::scopes::qt::QResult: src="https://assets.ubuntu.com/v1/78c8944c-classunity_1_1scopes_1_1qt_1_1_q_result__inherit__graph.png" border="0" alt="Inheritance graph"/>
Public Member Functions | |
virtual | ~QResult () |
void | store (QResult const &other, bool intercept_activation=false) |
Stores a Result inside this Result instance. More... | |
bool | has_stored_result () const |
Check if this Result instance has a stored result. More... | |
QResult | retrieve () const |
Get a stored result. More... | |
void | set_uri (QString const &uri) |
Set the "uri" attribute of this result. | |
void | set_title (QString const &title) |
Set the "title" attribute of this result. More... | |
void | set_art (QString const &image) |
Set the "art" attribute of this result. More... | |
void | set_dnd_uri (QString const &dnd_uri) |
Set the "dnd_uri" attribute of this result. More... | |
void | set_intercept_activation () |
Indicates to the receiver that this scope should intercept activation requests for this result. More... | |
bool | direct_activation () const |
Check if this result should be activated directly by the shell because the scope doesn't handle activation of this result. More... | |
ScopeProxy | target_scope_proxy () const |
Get the proxy of a scope that handles activation and preview of this result. More... | |
QVariant & | operator[] (QString const &key) |
Returns reference of a Result attribute. More... | |
QVariant const & | operator[] (QString const &key) const |
Returns a const reference to a Result attribute. More... | |
QString | uri () const noexcept |
Get the "uri" property of this Result. More... | |
QString | title () const noexcept |
Get the "title" property of this Result. More... | |
QString | art () const noexcept |
Get the "art" property of this Result. More... | |
QString | dnd_uri () const noexcept |
Get the "dnd_uri" property of this Result. More... | |
bool | contains (QString const &key) const |
Check if this Result has an attribute. More... | |
QVariant const & | value (QString const &key) const |
Get the value of an attribute. More... | |
QVariantMap | serialize () const |
Returns a dictionary of all attributes of this Result instance. More... | |
Copy and assignment | |
Copy and assignment (move and non-move versions) have the usual value semantics. | |
QResult (QResult const &other) | |
QResult (QResult &&) | |
QResult & | operator= (QResult const &other) |
QResult & | operator= (QResult &&) |
Detailed Description
The attributes of a result returned by a Scope.
The Result API provides convenience methods for some typical attributes (title, art), but scopes are free to add and use any custom attributes with operator[]
. The only required attribute is 'uri' and it must not be empty before calling Reply::push().
Constructor & Destructor Documentation
|
virtual |
Destructor.
Member Function Documentation
|
noexcept |
Get the "art" property of this Result.
This method returns an empty string if this attribute is not of type Variant::Type::String (e.g. it was set with operator[]).
- Returns
- The value of "art" or the empty string.
bool unity::scopes::qt::QResult::contains | ( | QString const & | key | ) | const |
Check if this Result has an attribute.
- Parameters
-
key The attribute name.
- Returns
- True if the attribute is set.
bool unity::scopes::qt::QResult::direct_activation | ( | ) | const |
Check if this result should be activated directly by the shell because the scope doesn't handle activation of this result.
- Returns
- True if this result needs to be activated directly.
|
noexcept |
Get the "dnd_uri" property of this Result.
This method returns an empty string if this attribute is not of type Variant::Type::String type (e.g. it was set with operator[]).
- Returns
- The value of "dnd_uri" or the empty string.
bool unity::scopes::qt::QResult::has_stored_result | ( | ) | const |
Check if this Result instance has a stored result.
- Returns
- True if there is a stored result
QVariant& unity::scopes::qt::QResult::operator[] | ( | QString const & | key | ) |
Returns reference of a Result attribute.
This method can be used to read or initialize both standard ("uri", "title", "art", "dnd_uri") and custom metadata attributes. Referencing a non-existing attribute automatically creates it with a default value of Variant::Type::Null.
- Parameters
-
key The name of the attribute.
- Returns
- A reference to the attribute.
- Exceptions
-
unity::Invalidargument if no attribute with the given name exists.
QVariant const& unity::scopes::qt::QResult::operator[] | ( | QString const & | key | ) | const |
Returns a const reference to a Result attribute.
This method can be used for read-only access to both standard ("uri", "title", "art", "dnd_uri") and custom metadata attributes. Referencing a non-existing attribute throws unity::InvalidArgumentException.
- Parameters
-
key The name of the attribute.
- Returns
- A const reference to the attribute.
- Exceptions
-
unity::Invalidargument if no attribute with the given name exists.
QResult unity::scopes::qt::QResult::retrieve | ( | ) | const |
Get a stored result.
- Returns
- stored result
- Exceptions
-
unity::InvalidArgumentException if no result was stored in this Result instance.
QVariantMap unity::scopes::qt::QResult::serialize | ( | ) | const |
Returns a dictionary of all attributes of this Result instance.
- Returns
- All base attributes and custom attributes set with add_metadata().
void unity::scopes::qt::QResult::set_art | ( | QString const & | image | ) |
Set the "art" attribute of this result.
Equivalent to calling result["art"] = image;
void unity::scopes::qt::QResult::set_dnd_uri | ( | QString const & | dnd_uri | ) |
Set the "dnd_uri" attribute of this result.
Equivalent to calling result["dnd_uri"] = dnd_uri;
void unity::scopes::qt::QResult::set_intercept_activation | ( | ) |
Indicates to the receiver that this scope should intercept activation requests for this result.
By default, a scope receives preview requests for the results it creates, but does not receive activation requests (they are handled directly by the shell). Intercepting activation implies intercepting preview requests as well; this is important for scopes that forward results from other scopes and call set_intercept_activation() on these scopes. A scope that sets intercept activation flag for a result should re-implement ScopeBase::activate() and provide an implementation of ActivationQueryBase that handles the actual activation. If not called, the result will be activated directly by the Unity shell whithout involving the scope, assuming an appropriate URI schema handler is present on the system.
void unity::scopes::qt::QResult::set_title | ( | QString const & | title | ) |
Set the "title" attribute of this result.
Equivalent to calling result["title"] = title;
void unity::scopes::qt::QResult::store | ( | QResult const & | other, |
bool | intercept_activation = false |
||
) |
Stores a Result inside this Result instance.
This method is meant to be used by aggregator scopes which want to modify results they receive, but want to keep a copy of the original result so that they can be correctly handled by the original scopes who created them when it comes to activation or previews. Scopes middleware will automatically pass the correct inner stored result to the activation or preview request handler of a scope which created it.
- Parameters
-
other The original result to store within this result. intercept_activation True if this scope should receive activation and preview requests.
ScopeProxy unity::scopes::qt::QResult::target_scope_proxy | ( | ) | const |
Get the proxy of a scope that handles activation and preview of this result.
The proxy is available only when receiving this result from a scope, otherwise this method throws LogicException. Activation requests should be sent to a scope returned by this method only if direct_activation() is false.
- Returns
- The scope proxy.
|
noexcept |
Get the "title" property of this Result.
This method returns an empty string if this attribute is not of type Variant::Type::String (e.g. it was set with operator[]).
- Returns
- The value of "title" or the empty string.
|
noexcept |
Get the "uri" property of this Result.
This method returns an empty string if this attribute is not of type Variant::Type::String (e.g. it was set with operator[]).
- Returns
- The value of "uri" or the empty string.
QVariant const& unity::scopes::qt::QResult::value | ( | QString const & | key | ) | const |
Get the value of an attribute.
- Parameters
-
key The attribute name.
- Returns
- The attribute value.
- Exceptions
-
unity::InvalidArgumentException if given attribute hasn't been set.