qtmobility/src/contacts/qcontactaction.cpp
changeset 15 1f895d8a5b2b
equal deleted inserted replaced
14:6fbed849b4f4 15:1f895d8a5b2b
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Mobility Components.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qcontactaction.h"
       
    43 #include "qcontactmanager_p.h"
       
    44 #include "qcontactactiondescriptor.h"
       
    45 
       
    46 #include <QSet>
       
    47 #include <QString>
       
    48 
       
    49 QTM_BEGIN_NAMESPACE
       
    50 
       
    51 QContactAction::~QContactAction()
       
    52 {
       
    53 }
       
    54 
       
    55 /*!
       
    56   \class QContactAction
       
    57   \brief The QContactAction class provides an interface for performing an
       
    58   action on a QContact or QContactDetail.
       
    59   \ingroup contacts-main
       
    60   \ingroup contacts-actions
       
    61 
       
    62   An action is anything that can be performed on a contact, or a detail of a contact.  An example
       
    63   of an action might be "Send Email" or "Dial" or "Plot Navigation Route".  One action may be
       
    64   implemented by multiple vendors, and indeed one vendor may provide multiple implementations of
       
    65   the same action.  The name of an action identifies its semantics, while its implementation version
       
    66   distinguishes it from other implementations of the action by the same vendor.
       
    67 
       
    68   Invocation of an action is asynchronous; at some stage after calling \l invokeAction() the
       
    69   action instance will emit the \l stateChanged() signal.  Any results of the action may be retrieved
       
    70   by calling \l results(), and as results become available the action will emit \l resultsAvailable().
       
    71 
       
    72   Each instance of a QContactAction is created by a \l QContactActionFactory when
       
    73   \l QContactActionFactory::instance() is called; the caller takes ownership of the action instance.
       
    74  
       
    75   \sa QContactActionFactory, QContactActionFilter
       
    76  */
       
    77 
       
    78 /*!
       
    79   \fn QContactAction::~QContactAction()
       
    80   Clears any memory in use by this instance of the action implementation
       
    81  */
       
    82 
       
    83 /*!
       
    84   \fn QContactAction::actionDescriptor() const
       
    85   Returns the descriptor which uniquely identifies this action implementation.  A descriptor
       
    86   consists of an action name, a vendor name and an implementation version.
       
    87   The name of the action identifies the action provided; different implementations of an action
       
    88   with the same name must provide the same functionality, but may differ in implementation semantics.
       
    89   Hence, the action name includes the major version of the interface definition implemented.
       
    90   The vendor name is the identification string of the vendor which has provided this implementation.
       
    91   The implementation version is the (minor) version of the implementation, and is vendor-specific.
       
    92 
       
    93   \sa QContactActionDescriptor
       
    94  */
       
    95 
       
    96 /*!
       
    97   \fn QContactAction::state() const
       
    98   Returns the current state of the action.
       
    99   \sa stateChanged()
       
   100  */
       
   101 
       
   102 /*!
       
   103   \fn QContactAction::metaData() const
       
   104   Returns the meta-data associated with this action, such as icons, labels or sound cues
       
   105  */
       
   106 
       
   107 /*!
       
   108   \fn QContactAction::contactFilter(const QVariant& value) const
       
   109   Returns a filter which may be used to filter contacts by the availability of this action implementation for them.
       
   110   If \a value is valid, only contacts which have a detail with the given value and for which the action is available are returned
       
   111  */
       
   112 
       
   113 /*!
       
   114   \fn QContactAction::isDetailSupported(const QContactDetail &detail, const QContact &contact = QContact()) const
       
   115   Returns true if the provided \a detail contains the fields required for this action to be
       
   116   performed on it; otherwise, returns false.
       
   117   Some actions may require other information to be available in order to complete successfully; in that case,
       
   118   the action will also inspect the given \a contact to ensure that it contains the information required.
       
   119   If the contact contains the required information, the function will return true; otherwise, returns false.
       
   120  */
       
   121 
       
   122 /*!
       
   123   \fn QContactAction::supportedDetails(const QContact& contact) const
       
   124   Returns a list of the details saved in the given \a contact which contain the fields required
       
   125   for this action to be performed on them.
       
   126 
       
   127   The default implementation of this function simply tests all the details in the contact
       
   128   using \l isDetailSupported()
       
   129  */
       
   130 QList<QContactDetail> QContactAction::supportedDetails(const QContact& contact) const
       
   131 {
       
   132     QList<QContactDetail> ret;
       
   133     QList<QContactDetail> details = contact.details();
       
   134     for (int j=0; j < details.count(); j++) {
       
   135         if (isDetailSupported(details.at(j), contact))
       
   136             ret.append(details.at(j));
       
   137     }
       
   138     return ret;
       
   139 }
       
   140 
       
   141 /*!
       
   142   \fn QContactAction::invokeAction(const QContact& contact, const QContactDetail& detail = QContactDetail(), const QVariantMap& parameters = QVariantMap())
       
   143   Initiates the implemented action on the specified \a detail of the given \a contact, or on the first
       
   144   eligible detail saved in the contact if the given \a detail is empty, with the given \a parameters specified.
       
   145   At some point after invocation, one or more \l resultsAvailable() signals will be emitted by the action instance.
       
   146   The results of the action (if any) may be retrieved by calling \l results().
       
   147   When the state of the action changes, the \l stateChanged() signal will be emitted.
       
   148 
       
   149   Returns true if the action was invoked successfully, otherwise false.  The return value says nothing
       
   150   about whether the action which was invoked was successful or not, only whether it was initiated or
       
   151   the request for it to be initiated was sent successfully (e.g., if the action is implemented as a one-way
       
   152   RPC call).
       
   153 
       
   154   \sa results(), stateChanged()
       
   155  */
       
   156 
       
   157 /*!
       
   158   \fn QContactAction::results() const
       
   159   Returns the result of the action, if any exists.  Calling this function prior to receiving the \l resultsAvailable()
       
   160   signal will not return a meaningful result.
       
   161  */
       
   162 
       
   163 /*!
       
   164   \enum QContactAction::State
       
   165   Describes the current status of the asynchronous action operation
       
   166   \value InactiveState The operation has not yet been initiated
       
   167   \value FinishedDetachedState The operation was initiated but no further information is or will be available
       
   168   \value ActiveState The operation was initiated and is not yet finished
       
   169   \value FinishedState The operation successfully completed
       
   170   \value FinishedWithErrorState The operation has finished, but an error occurred
       
   171  */
       
   172 
       
   173 /*!
       
   174   \fn QContactAction::resultsAvailable()
       
   175   This signal is emitted by an action instance whose functionality has been initiated with \l invokeAction()
       
   176   when results of the action are available.  Not all actions will have results, and these
       
   177   actions will not emit the resultsAvailable() signal.
       
   178 
       
   179   If the action implementation is incapable of reporting results of the operation (for example, the
       
   180   action is implemented via a one-way IPC call) it should transition to the \c QContactAction::FinishedDetachedState state
       
   181   immediately upon invocation.
       
   182  */
       
   183 
       
   184 /*!
       
   185   \fn QContactAction::stateChanged(QContactAction::State newState)
       
   186   This signal is emitted when the state of an action changes to the given \a newState.
       
   187   \sa state()
       
   188  */
       
   189 
       
   190 /*!
       
   191   Returns a list of identifiers of the available actions which are provided by the given \a vendor and of the given \a implementationVersion.
       
   192   If \a vendor is empty, actions from all vendors and of any implementation version are returned; if \a implementationVersion is empty,
       
   193   any actions from the given \a vendor (regardless of implementation version) are returned.
       
   194  */
       
   195 QStringList QContactAction::availableActions(const QString& vendor, int implementationVersion)
       
   196 {
       
   197     // SLOW naive implementation...
       
   198     QSet<QString> ret;
       
   199     QContactManagerData::loadFactories();
       
   200     QList<QContactActionDescriptor> actionDescriptors = QContactManagerData::actionDescriptors(QString(), vendor, implementationVersion);
       
   201     for (int i = 0; i < actionDescriptors.size(); i++) {
       
   202         QContactActionDescriptor descriptor = actionDescriptors.at(i);
       
   203         ret.insert(descriptor.actionName());
       
   204     }
       
   205 
       
   206     return ret.toList();
       
   207 }
       
   208 
       
   209 /*!
       
   210   Returns a list of QContactActionDescriptor instances which identified implementations of the given \a actionName which are provided by the
       
   211   given \a vendorName and are of the given \a implementationVersion.  If \a actionName is empty, descriptors for
       
   212   implementations of all actions are returned; if \a vendorName is empty, descriptors for implementations provided by any vendor and
       
   213   of any implementation version are returned; if \a implementationVersion is empty, descriptors for any implementations provided by the
       
   214   given \a vendorName of the given \a actionName are returned.
       
   215  */
       
   216 QList<QContactActionDescriptor> QContactAction::actionDescriptors(const QString& actionName, const QString& vendorName, int implementationVersion)
       
   217 {
       
   218     QContactManagerData::loadFactories();
       
   219     return QContactManagerData::actionDescriptors(actionName, vendorName, implementationVersion);
       
   220 }
       
   221 
       
   222 /*!
       
   223   Returns a pointer to a new instance of the action implementation identified by the given \a descriptor.
       
   224   The caller takes ownership of the action implementation and must delete it to avoid leaking memory.
       
   225  */
       
   226 QContactAction* QContactAction::action(const QContactActionDescriptor& descriptor)
       
   227 {
       
   228     QContactManagerData::loadFactories();
       
   229     return QContactManagerData::action(descriptor);
       
   230 }
       
   231 
       
   232 #include "moc_qcontactaction.cpp"
       
   233 
       
   234 QTM_END_NAMESPACE