diff options
Diffstat (limited to 'src/intent-server-lib/intent.cpp')
-rw-r--r-- | src/intent-server-lib/intent.cpp | 138 |
1 files changed, 81 insertions, 57 deletions
diff --git a/src/intent-server-lib/intent.cpp b/src/intent-server-lib/intent.cpp index b1151910..72eff40b 100644 --- a/src/intent-server-lib/intent.cpp +++ b/src/intent-server-lib/intent.cpp @@ -1,10 +1,11 @@ /**************************************************************************** ** +** Copyright (C) 2019 The Qt Company Ltd. ** Copyright (C) 2019 Luxoft Sweden AB ** Copyright (C) 2018 Pelagicore AG ** Contact: https://www.qt.io/licensing/ ** -** This file is part of the Luxoft Application Manager. +** This file is part of the Qt Application Manager. ** ** $QT_BEGIN_LICENSE:LGPL-QTAS$ ** Commercial License Usage @@ -44,48 +45,48 @@ #include <QRegularExpression> #include <QVariant> +#include <QLocale> QT_BEGIN_NAMESPACE_AM /*! - \qmltype Intent + \qmltype IntentObject \inqmlmodule QtApplicationManager.SystemUI \ingroup system-ui-non-instantiable \brief This type represents an Intent definition on the System-UI side. - This is a QML gadget class representing a single Intent definition for a specific application. + This is a QML object class representing a single Intent definition for a specific application. It is not creatable from QML code and all properties are read-only. Only functions and - properties of IntentServer will return instances of this class. + properties of IntentServer will return pointers to this class. */ -/*! \qmlproperty bool Intent::valid +/*! \qmlproperty string IntentObject::intentId \readonly - Set to \c true, if this instance reprensents a valid intent, or \c false otherwise. + The id of the intent. */ -/*! \qmlproperty string Intent::intentId +/*! \qmlproperty string IntentObject::packageId \readonly - The id of the intent. + The id of the package that the handling application of this intent is part of. */ -/*! \qmlproperty string Intent::applicationId +/*! \qmlproperty string IntentObject::applicationId \readonly - The id of the application that is handling this intent. + The id of the application responsible for handling this intent. */ -/*! \qmlproperty Intent.Visibility Intent::visibility +/*! \qmlproperty IntentObject.Visibility IntentObject::visibility \readonly - The visibility of this intent for other applications. + The visibility of this intent for other packages. \list - \li Intent.Public - Any application can request this intent. - \li Intent.Private - Only the handling application can request this intent (this will be more - useful once application background services have been implemented). + \li IntentObject.Public - Any application can request this intent. + \li IntentObject.Private - Only applications from the same package can request this intent. \endlist */ -/*! \qmlproperty list<string> Intent::requiredCapabilities +/*! \qmlproperty list<string> IntentObject::requiredCapabilities \readonly An \l{ApplicationObject}{application} requesting this intent needs to have all of the given capabilities. @@ -93,56 +94,47 @@ QT_BEGIN_NAMESPACE_AM \sa ApplicationObject::capabilities */ -/*! \qmlproperty var Intent::parameterMatch +/*! \qmlproperty var IntentObject::parameterMatch \readonly - A handling application can limit what parameter values it accepts. One example would be an - open-mime-type intent that is implemented by many applications: there would be a \c mimeType - parameter and each application could limit the requests it wants to receive by setting a - parameterMatch on this \c mimeType parameter, e.g. \c{{ mimeType: "^image/.*\.png$" }} + A handling application can limit what parameter values it accepts. The property itself is an + object that corresponds to a subset of allowed parameter object of this intent. + When set, the parameters of each incoming intent request are matched against this object, + following these rules: + \list + \li a field missing from \c parameterMatch is ignored. + \li a field of type \c string specified in \c parameterMatch is matched as a regular + expressions against the corresponding parameter value. + \li for fields of type \c list specified in \c parameterMatch, the corresponding parameter value + has to match any of the values in the list (using QVariant compare). + \li any other fields in \c parameterMatch are compared as QVariants to the corresponding + parameter value. + \endlist + One example would be an \c open-mime-type intent that is implemented by many applications: there + would be a \c mimeType parameter and each application could limit the requests it wants to + receive by setting a parameterMatch on this \c mimeType parameter, e.g. + \c{{ mimeType: "^image/.*\.png$" }} */ Intent::Intent() { } -Intent::Intent(const Intent &other) - : m_intentId(other.m_intentId) - , m_visibility(other.m_visibility) - , m_requiredCapabilities(other.m_requiredCapabilities) - , m_parameterMatch(other.m_parameterMatch) - , m_applicationId(other.m_applicationId) - , m_backgroundHandlerId(other.m_backgroundHandlerId) -{ } - -Intent::Intent(const QString &id, const QString &applicationId, const QString &backgroundHandlerId, - const QStringList &capabilities, Intent::Visibility visibility, const QVariantMap ¶meterMatch) +Intent::Intent(const QString &id, const QString &packageId, const QString &applicationId, + const QStringList &capabilities, Intent::Visibility visibility, + const QVariantMap ¶meterMatch, const QMap<QString, QString> &names, + const QUrl &icon, const QStringList &categories) : m_intentId(id) , m_visibility(visibility) , m_requiredCapabilities(capabilities) , m_parameterMatch(parameterMatch) + , m_packageId(packageId) , m_applicationId(applicationId) - , m_backgroundHandlerId(backgroundHandlerId) -{ } - -Intent::operator bool() const + , m_categories(categories) + , m_icon(icon) { - return !m_intentId.isEmpty(); -} - -bool Intent::operator==(const Intent &other) const -{ - return (m_intentId == other.m_intentId) - && (m_visibility == other.m_visibility) - && (m_requiredCapabilities == other.m_requiredCapabilities) - && (m_parameterMatch == other.m_parameterMatch) - && (m_applicationId == other.m_applicationId) - && (m_backgroundHandlerId == other.m_backgroundHandlerId); -} - -bool Intent::operator <(const Intent &other) const -{ - return (m_intentId < other.m_intentId) ? true : (m_applicationId < other.m_applicationId); + for (auto it = names.cbegin(); it != names.cend(); ++it) + m_names.insert(it.key(), it.value()); } QString Intent::intentId() const @@ -165,14 +157,14 @@ QVariantMap Intent::parameterMatch() const return m_parameterMatch; } -QString Intent::applicationId() const +QString Intent::packageId() const { - return m_applicationId; + return m_packageId; } -QString Intent::backgroundServiceId() const +QString Intent::applicationId() const { - return m_backgroundHandlerId; + return m_applicationId; } bool Intent::checkParameterMatch(const QVariantMap ¶meters) const @@ -200,7 +192,7 @@ bool Intent::checkParameterMatch(const QVariantMap ¶meters) const bool foundMatch = false; const QVariantList rvlist = requiredValue.toList(); for (const QVariant &rv2 : rvlist) { - if (actualValue.canConvert(rv2.type()) && actualValue == rv2) { + if (actualValue.canConvert(int(rv2.type())) && actualValue == rv2) { foundMatch = true; break; } @@ -219,4 +211,36 @@ bool Intent::checkParameterMatch(const QVariantMap ¶meters) const return true; } +QUrl Intent::icon() const +{ + return m_icon; +} + +QString Intent::name() const +{ + QVariant name; + if (!m_names.isEmpty()) { + name = m_names.value(QLocale::system().name()); //TODO: language changes + if (name.isNull()) + name = m_names.value(qSL("en")); + if (name.isNull()) + name = m_names.value(qSL("en_US")); + if (name.isNull()) + name = *m_names.constBegin(); + } else { + name = intentId(); + } + return name.toString(); +} + +QVariantMap Intent::names() const +{ + return m_names; +} + +QStringList Intent::categories() const +{ + return m_categories; +} + QT_END_NAMESPACE_AM |