qtmobility/src/contacts/filters/qcontactrelationshipfilter.cpp
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     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 "qcontactrelationshipfilter.h"
       
    43 #include "qcontactrelationshipfilter_p.h"
       
    44 #include "qcontactmanager.h"
       
    45 
       
    46 QTM_BEGIN_NAMESPACE
       
    47 
       
    48 /*!
       
    49   \class QContactRelationshipFilter
       
    50   \brief The QContactRelationshipFilter class provides a filter based
       
    51   around relationship criteria.
       
    52   
       
    53   \ingroup contacts-filters
       
    54  
       
    55   It may be used to select contacts which are involved in relationships
       
    56   which are of a certain type, or which involve certain contacts.
       
    57 
       
    58   One common use-case might be to select the contacts which are a member of a particular group.
       
    59   This use-case may be met with the following filter:
       
    60 
       
    61   \code
       
    62   QContactRelationshipFilter groupFilter;                               // select all contacts which are involved
       
    63   groupFilter.setRelationshipType(QContactRelationship::HasMember);     // in a group relationship
       
    64   groupFilter.setRelatedContactId(groupContact.id());                   // with the group contact
       
    65   groupFilter.setRelatedContactRole(QContactRelationshipFilter::First); // where the group contact is the first participant
       
    66   \endcode
       
    67 
       
    68   Another common use-case might be to select the groups which a particular contact is a member of.
       
    69   This use-case may be met with the following filter:
       
    70 
       
    71   \code
       
    72   QContactRelationshipFilter whichGroupsFilter;                                 // select all contacts which are involved
       
    73   whichGroupsFilter.setRelationshipType(QContactRelationshipFilter::HasMember); // in a group relationship
       
    74   whichGroupsFilter.setRelatedContactId(particularContact.id());                // with the particular contact
       
    75   whichGroupsFilter.setRelatedContactRole(QContactRelationshipFilter::Second);  // where the particular contact is the second participant
       
    76   \endcode
       
    77 
       
    78  */
       
    79 
       
    80 Q_IMPLEMENT_CONTACTFILTER_PRIVATE(QContactRelationshipFilter)
       
    81 
       
    82 /*!
       
    83   \enum QContactRelationshipFilter::Role
       
    84   Describes the roles that a contact may take in a relationship
       
    85   \value First The contact is the first contact in the relationship
       
    86   \value Second The contact is the second contact in the relationship
       
    87   \value Either The contact is either the first or second contact in the relationship
       
    88  */
       
    89 
       
    90 /*!
       
    91   \fn QContactRelationshipFilter::QContactRelationshipFilter(const QContactFilter& other)
       
    92   Constructs a copy of \a other if possible, else constructs a new QContactRelationshipFilter.
       
    93  */
       
    94 
       
    95 /*!
       
    96   Constructs a new relationship filter
       
    97  */
       
    98 QContactRelationshipFilter::QContactRelationshipFilter()
       
    99     : QContactFilter(new QContactRelationshipFilterPrivate)
       
   100 {
       
   101 }
       
   102 
       
   103 /*!
       
   104   Sets the type of relationship which a contact must have in order to match this filter to \a relationshipType
       
   105  */
       
   106 void QContactRelationshipFilter::setRelationshipType(const QString& relationshipType)
       
   107 {
       
   108     Q_D(QContactRelationshipFilter);
       
   109     d->m_relationshipType = relationshipType;
       
   110 }
       
   111 
       
   112 /*!
       
   113   Returns the type of relationship that a contact must have in order to match the filter
       
   114  */
       
   115 QString QContactRelationshipFilter::relationshipType() const
       
   116 {
       
   117     Q_D(const QContactRelationshipFilter);
       
   118     return d->m_relationshipType;
       
   119 }
       
   120 
       
   121 /*!
       
   122   Sets the id of the contact with whom the tested contact must have a relationship in order for the tested contact to match this filter to be \a relatedContactId
       
   123  */
       
   124 void QContactRelationshipFilter::setRelatedContactId(const QContactId &relatedContactId)
       
   125 {
       
   126     Q_D(QContactRelationshipFilter);
       
   127     d->m_relatedContactId = relatedContactId;
       
   128 }
       
   129 
       
   130 /*!
       
   131   Returns the id of the contact with whom the tested contact must have a relationship in order for the tested contact to match this filter
       
   132  */
       
   133 QContactId QContactRelationshipFilter::relatedContactId() const
       
   134 {
       
   135     Q_D(const QContactRelationshipFilter);
       
   136     return d->m_relatedContactId;
       
   137 }
       
   138 
       
   139 /*!
       
   140   Sets the role in the relationship with the tested contact that the related contact must play in order for the tested contact to match this filter to be \a relatedContactRole
       
   141  */
       
   142 void QContactRelationshipFilter::setRelatedContactRole(QContactRelationshipFilter::Role relatedContactRole)
       
   143 {
       
   144     Q_D(QContactRelationshipFilter);
       
   145     d->m_relatedContactRole = relatedContactRole;
       
   146 }
       
   147 
       
   148 /*!
       
   149   Returns the role in the relationship with the tested contact that the related contact must play in order for the tested contact to match this filter
       
   150  */
       
   151 QContactRelationshipFilter::Role QContactRelationshipFilter::relatedContactRole() const
       
   152 {
       
   153     Q_D(const QContactRelationshipFilter);
       
   154     return d->m_relatedContactRole;
       
   155 }
       
   156 
       
   157 /*!
       
   158   \internal
       
   159   Sets the role in the relationship that a contact must be in order to match this filter to \a roleInRelationship
       
   160 
       
   161   This function has been deprecated - you should pass the opposite value (e.g. First instead of Second, Second
       
   162   instead of First) to \c setRelatedContactRole().
       
   163   \sa setRelatedContactRole()
       
   164  */
       
   165 void QContactRelationshipFilter::setRole(QContactRelationshipFilter::Role roleInRelationship)
       
   166 {
       
   167     Q_D(QContactRelationshipFilter);
       
   168     switch(roleInRelationship) {
       
   169         case QContactRelationshipFilter::Either:
       
   170             d->m_relatedContactRole = QContactRelationshipFilter::Either;
       
   171             break;
       
   172         case QContactRelationshipFilter::First:
       
   173             d->m_relatedContactRole = QContactRelationshipFilter::Second;
       
   174             break;
       
   175         case QContactRelationshipFilter::Second:
       
   176             d->m_relatedContactRole = QContactRelationshipFilter::First;
       
   177             break;
       
   178     }
       
   179 }
       
   180 
       
   181 /*!
       
   182   \internal
       
   183   Sets the contact id of the other participant which must be present in the relationship with the contact
       
   184   in order for the contact to match the filter to be \a id
       
   185  */
       
   186 void QContactRelationshipFilter::setOtherParticipantId(const QContactId& id)
       
   187 {
       
   188     Q_D(QContactRelationshipFilter);
       
   189     d->m_relatedContactId = id;
       
   190 }
       
   191 
       
   192 /*!
       
   193   \internal
       
   194   Returns the role that a contact must have in a relationship in order to match the filter
       
   195  */
       
   196 QContactRelationshipFilter::Role QContactRelationshipFilter::role() const
       
   197 {
       
   198     Q_D(const QContactRelationshipFilter);
       
   199     switch(d->m_relatedContactRole) {
       
   200         case QContactRelationshipFilter::First:
       
   201             return QContactRelationshipFilter::Second;
       
   202         case QContactRelationshipFilter::Second:
       
   203             return QContactRelationshipFilter::First;
       
   204         case QContactRelationshipFilter::Either:
       
   205         default:
       
   206             return QContactRelationshipFilter::Either;
       
   207     }
       
   208 }
       
   209 
       
   210 /*!
       
   211   \internal
       
   212   Returns the id of another contact with whom a contact must have a relationship in order to match the filter
       
   213  */
       
   214 QContactId QContactRelationshipFilter::otherParticipantId() const
       
   215 {
       
   216     Q_D(const QContactRelationshipFilter);
       
   217     return d->m_relatedContactId;
       
   218 }
       
   219 
       
   220 QTM_END_NAMESPACE