qtmobility/plugins/contacts/symbian/src/cntrelationshipgroup.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    67  * 
    67  * 
    68  * \a affectedContactIds will include the affected contact ids 
    68  * \a affectedContactIds will include the affected contact ids 
    69  * \a relationship to be saved
    69  * \a relationship to be saved
    70  * \a error t
    70  * \a error t
    71  */
    71  */
    72 bool CntRelationshipGroup::saveRelationshipL(QSet<QContactLocalId> *affectedContactIds, QContactRelationship* relationship, QContactManager::Error& error)
    72 bool CntRelationshipGroup::saveRelationshipL(QSet<QContactLocalId> *affectedContactIds, QContactRelationship* relationship, QContactManager::Error* error)
    73 {
    73 {
    74     //get the ids of the relationship
    74     //get the ids of the relationship
    75     QScopedPointer<QContactId> groupId(new QContactId(relationship->first()));
    75     QScopedPointer<QContactId> groupId(new QContactId(relationship->first()));
    76     QScopedPointer<QContactId> contactId(new QContactId(relationship->second()));
    76     QScopedPointer<QContactId> contactId(new QContactId(relationship->second()));
    77     
    77     
    81     //add the group  and group member to the list of affected contacts
    81     //add the group  and group member to the list of affected contacts
    82     //note if the value already exists in the QSet nothing happens
    82     //note if the value already exists in the QSet nothing happens
    83     affectedContactIds->insert(groupId->localId());
    83     affectedContactIds->insert(groupId->localId());
    84     affectedContactIds->insert(contactId->localId());
    84     affectedContactIds->insert(contactId->localId());
    85     
    85     
    86     error = QContactManager::NoError;
    86     *error = QContactManager::NoError;
    87     return true;
    87     return true;
    88 }
    88 }
    89 
    89 
    90 bool CntRelationshipGroup::removeRelationshipL(QSet<QContactLocalId> *affectedContactIds, const QContactRelationship& relationship, QContactManager::Error& error)
    90 bool CntRelationshipGroup::removeRelationshipL(QSet<QContactLocalId> *affectedContactIds, const QContactRelationship& relationship, QContactManager::Error* error)
    91 {
    91 {
    92     //get the ids of the relationship
    92     //get the ids of the relationship
    93     QScopedPointer<QContactId> groupId(new QContactId(relationship.first()));
    93     QScopedPointer<QContactId> groupId(new QContactId(relationship.first()));
    94     QScopedPointer<QContactId> contactId(new QContactId(relationship.second()));
    94     QScopedPointer<QContactId> contactId(new QContactId(relationship.second()));
    95 
    95 
   108     affectedContactIds->insert(contactId->localId());
   108     affectedContactIds->insert(contactId->localId());
   109     
   109     
   110     CleanupStack::PopAndDestroy(contact);
   110     CleanupStack::PopAndDestroy(contact);
   111     CleanupStack::PopAndDestroy(groupContact);
   111     CleanupStack::PopAndDestroy(groupContact);
   112 
   112 
   113     error = QContactManager::NoError;
   113     *error = QContactManager::NoError;
   114     return true;
   114     return true;
   115 }
   115 }
   116 
   116 
   117 bool CntRelationshipGroup::validateRelationship(const QContactRelationship &relationship, QContactManager::Error& error)
   117 bool CntRelationshipGroup::validateRelationship(const QContactRelationship &relationship, QContactManager::Error* error)
   118 {
   118 {
   119     // check that "second" is in this manager
   119     // check that "second" is in this manager
   120     if (!relationship.second().managerUri().isEmpty() && relationship.second().managerUri() != managerUri()) {
   120     if (!relationship.second().managerUri().isEmpty() && relationship.second().managerUri() != managerUri()) {
   121         error = QContactManager::InvalidRelationshipError;
   121         *error = QContactManager::InvalidRelationshipError;
   122         return false;
   122         return false;
   123     }
   123     }
   124 
   124 
   125     return true;
   125     return true;
   126 }
   126 }
   160         User::Leave(KErrNotFound);
   160         User::Leave(KErrNotFound);
   161     }
   161     }
   162 }
   162 }
   163 
   163 
   164 //retrieve all the groups that the contact is part of
   164 //retrieve all the groups that the contact is part of
   165 QList<QContactRelationship> CntRelationshipGroup::relationshipsL(const QContactId& participantId, QContactRelationshipFilter::Role role, QContactManager::Error& error)
   165 QList<QContactRelationship> CntRelationshipGroup::relationshipsL(const QContactId& participantId, QContactRelationship::Role role, QContactManager::Error* error)
   166 {
   166 {
   167     QList<QContactRelationship> returnValue;
   167     QList<QContactRelationship> returnValue;
   168     
   168     
   169     if (participantId != QContactId())
   169     if (participantId != QContactId())
   170     {
   170     {
   171         //role is a group
   171         //role is a group
   172         if(role == QContactRelationshipFilter::First || role == QContactRelationshipFilter::Either)
   172         if(role == QContactRelationship::First || role == QContactRelationship::Either)
   173         {
   173         {
   174             fetchGroupMembersL(participantId.localId(), &returnValue);
   174             fetchGroupMembersL(participantId.localId(), &returnValue);
   175         }
   175         }
   176     
   176     
   177         //role is member of a group
   177         //role is member of a group
   178         if(role == QContactRelationshipFilter::Second || role == QContactRelationshipFilter::Either)
   178         if(role == QContactRelationship::Second || role == QContactRelationship::Either)
   179         {
   179         {
   180             fetchMemberOfGroupsL(participantId.localId(), &returnValue);
   180             fetchMemberOfGroupsL(participantId.localId(), &returnValue);
   181         }
   181         }
   182     }
   182     }
   183     else
   183     else
   186         // all relationships of the given relationshipType are returned.
   186         // all relationships of the given relationshipType are returned.
   187         fetchMembersOfAllGroupsL(&returnValue);
   187         fetchMembersOfAllGroupsL(&returnValue);
   188     }
   188     }
   189     
   189     
   190     if (returnValue.isEmpty())
   190     if (returnValue.isEmpty())
   191         error = QContactManager::DoesNotExistError;
   191         *error = QContactManager::DoesNotExistError;
   192 
   192 
   193     return returnValue;
   193     return returnValue;
   194 }
   194 }
   195 
   195 
   196 void CntRelationshipGroup::fetchGroupMembersL(const QContactLocalId& participantId, QList<QContactRelationship> *relationships)
   196 void CntRelationshipGroup::fetchGroupMembersL(const QContactLocalId& participantId, QList<QContactRelationship> *relationships)