qtmobility/plugins/contacts/wince/qcontactrequestworker.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    43 #include <QTimer>
    43 #include <QTimer>
    44 
    44 
    45 #include "qcontactrequests.h"
    45 #include "qcontactrequests.h"
    46 #include "qcontactmanagerengine.h"
    46 #include "qcontactmanagerengine.h"
    47 #include "qcontactrequestworker_p.h"
    47 #include "qcontactrequestworker_p.h"
       
    48 #include "qcontactwincebackend_p.h"
    48 
    49 
    49 
    50 
    50 /*!
    51 /*!
    51  * \class QContactRequestWorker
    52  * \class QContactRequestWorker
    52  *
    53  *
   284 void QContactRequestWorker::processContactFetchRequest(QContactFetchRequest* req)
   285 void QContactRequestWorker::processContactFetchRequest(QContactFetchRequest* req)
   285 {
   286 {
   286     if (req->manager()) {   
   287     if (req->manager()) {   
   287         QContactFilter filter = req->filter();
   288         QContactFilter filter = req->filter();
   288         QList<QContactSortOrder> sorting = req->sorting();
   289         QList<QContactSortOrder> sorting = req->sorting();
   289         QStringList defs = req->definitionRestrictions();
   290         QStringList defs = req->fetchHint().detailDefinitionsHint();
   290 
   291 
   291         QContactManager::Error operationError;
   292         QContactManager::Error operationError;
   292         QList<QContact> requestedContacts;
   293         QList<QContact> requestedContacts;
   293 
   294 
   294         QList<QContactLocalId> requestedContactIds = req->manager()->contactIds(filter, sorting);
   295         QList<QContactLocalId> requestedContactIds = req->manager()->contactIds(filter, sorting);
   318             // add the contact to the result list.
   319             // add the contact to the result list.
   319             requestedContacts.append(current);
   320             requestedContacts.append(current);
   320         }
   321         }
   321 
   322 
   322         // update the request with the results.
   323         // update the request with the results.
   323         QContactManagerEngine::updateContactFetchRequest(req, requestedContacts, operationError);
   324         QContactManagerEngine::updateContactFetchRequest(req, requestedContacts, operationError, QContactAbstractRequest::FinishedState);
   324     }
   325     }
   325 }
   326 }
   326 
   327 
   327 /*!
   328 /*!
   328  * Processes the QContactLocalIdFetchRequest \a req
   329  * Processes the QContactLocalIdFetchRequest \a req
   336 
   337 
   337         QContactManager::Error operationError = QContactManager::NoError;
   338         QContactManager::Error operationError = QContactManager::NoError;
   338         QList<QContactLocalId> requestedContactIds = req->manager()->contactIds(filter, sorting);
   339         QList<QContactLocalId> requestedContactIds = req->manager()->contactIds(filter, sorting);
   339         operationError = req->manager()->error();
   340         operationError = req->manager()->error();
   340 
   341 
   341         QContactManagerEngine::updateContactLocalIdFetchRequest(req, requestedContactIds, operationError);
   342         QContactManagerEngine::updateContactLocalIdFetchRequest(req, requestedContactIds, operationError, QContactAbstractRequest::FinishedState);
   342     }
   343     }
   343 }
   344 }
   344 
   345 
   345 /*!
   346 /*!
   346  * Processes the QContactSaveRequest \a req
   347  * Processes the QContactSaveRequest \a req
   354         QContactManager::Error operationError = QContactManager::NoError;
   355         QContactManager::Error operationError = QContactManager::NoError;
   355         QMap<int, QContactManager::Error> errorMap;
   356         QMap<int, QContactManager::Error> errorMap;
   356         req->manager()->saveContacts(&contacts, &errorMap);
   357         req->manager()->saveContacts(&contacts, &errorMap);
   357         operationError = req->manager()->error();
   358         operationError = req->manager()->error();
   358 
   359 
   359         QContactManagerEngine::updateContactSaveRequest(req, contacts, operationError, errorMap);
   360         QContactManagerEngine::updateContactSaveRequest(req, contacts, operationError, errorMap, QContactAbstractRequest::FinishedState);
   360     }
   361     }
   361 }
   362 }
   362 
   363 
   363 /*!
   364 /*!
   364  * Processes the QContactRemoveRequest \a req
   365  * Processes the QContactRemoveRequest \a req
   389                 operationError = tempError;
   390                 operationError = tempError;
   390             }
   391             }
   391         }
   392         }
   392 
   393 
   393         // there are no results, so just update the status with the error.
   394         // there are no results, so just update the status with the error.
   394         QContactManagerEngine::updateContactRemoveRequest(req, operationError, errorMap);
   395         QContactManagerEngine::updateContactRemoveRequest(req, operationError, errorMap, QContactAbstractRequest::FinishedState);
   395     }
   396     }
   396 }
   397 }
   397 
   398 
   398 
   399 
   399 /*!
   400 /*!
   423                 operationError = tempError;
   424                 operationError = tempError;
   424             }
   425             }
   425         }
   426         }
   426 
   427 
   427         // update the request with the results.
   428         // update the request with the results.
   428         QContactManagerEngine::updateDefinitionFetchRequest(req, requestedDefinitions, operationError, errorMap);
   429         QContactManagerEngine::updateDefinitionFetchRequest(req, requestedDefinitions, operationError, errorMap, QContactAbstractRequest::FinishedState);
   429     }
   430     }
   430 }
   431 }
   431 /*!
   432 /*!
   432  * Processes the QContactDetailDefinitionSaveRequest \a req
   433  * Processes the QContactDetailDefinitionSaveRequest \a req
   433  * \sa QContactDetailDefinitionSaveRequest
   434  * \sa QContactDetailDefinitionSaveRequest
   452                 operationError = tempError;
   453                 operationError = tempError;
   453             }
   454             }
   454         }
   455         }
   455 
   456 
   456         // update the request with the results.
   457         // update the request with the results.
   457         QContactManagerEngine::updateDefinitionSaveRequest(req, savedDefinitions, operationError, errorMap);
   458         QContactManagerEngine::updateDefinitionSaveRequest(req, savedDefinitions, operationError, errorMap, QContactAbstractRequest::FinishedState);
   458     }
   459     }
   459 }
   460 }
   460 /*!
   461 /*!
   461  * Processes the QContactDetailDefinitionRemoveRequest \a req
   462  * Processes the QContactDetailDefinitionRemoveRequest \a req
   462  * \sa QContactDetailDefinitionRemoveRequest
   463  * \sa QContactDetailDefinitionRemoveRequest
   479                 operationError = tempError;
   480                 operationError = tempError;
   480             }
   481             }
   481         }
   482         }
   482 
   483 
   483         // there are no results, so just update the status with the error.
   484         // there are no results, so just update the status with the error.
   484         QContactManagerEngine::updateDefinitionRemoveRequest(req, operationError, errorMap);
   485         QContactManagerEngine::updateDefinitionRemoveRequest(req, operationError, errorMap, QContactAbstractRequest::FinishedState);
   485     }
   486     }
   486 }
   487 }
   487 
   488 
   488 /*!
   489 /*!
   489  * Processes the QContactRelationshipFetchRequest \a req
   490  * Processes the QContactRelationshipFetchRequest \a req
   490  * \sa QContactRelationshipFetchRequest
   491  * \sa QContactRelationshipFetchRequest
   491  */
   492  */
   492 void QContactRequestWorker::processContactRelationshipFetchRequest(QContactRelationshipFetchRequest* req)
   493 void QContactRequestWorker::processContactRelationshipFetchRequest(QContactRelationshipFetchRequest* req)
   493 {
   494 {
   494     if (req->manager()) {
   495     if (req->manager()) {
   495         QList<QContactRelationship> allRelationships = req->manager()->relationships(QString(), QContactId(), QContactRelationshipFilter::Either);
   496         QList<QContactRelationship> allRelationships = req->manager()->relationships(QString(), QContactId(), QContactRelationship::Either);
   496         QContactManager::Error operationError = req->manager()->error();
   497         QContactManager::Error operationError = req->manager()->error();
   497         QList<QContactRelationship> requestedRelationships;
   498         QList<QContactRelationship> requestedRelationships;
   498 
   499 
   499         // first criteria: source contact id must be empty or must match
   500         // first criteria: source contact id must be empty or must match
   500         if (req->first() == QContactId()) {
   501         if (req->first() == QContactId()) {
   521             }
   522             }
   522         }
   523         }
   523 
   524 
   524         // third criteria: participant must be empty or must match (including role in relationship)
   525         // third criteria: participant must be empty or must match (including role in relationship)
   525         QString myUri = req->manager()->managerUri();
   526         QString myUri = req->manager()->managerUri();
   526         QContactId anonymousParticipant;
   527         if (req->second() != QContactId()) {
   527         anonymousParticipant.setLocalId(QContactLocalId(0));
       
   528         anonymousParticipant.setManagerUri(QString());
       
   529         if (req->second() != anonymousParticipant) {
       
   530             allRelationships = requestedRelationships;
   528             allRelationships = requestedRelationships;
   531             requestedRelationships.clear();
   529             requestedRelationships.clear();
   532             for (int i = 0; i < allRelationships.size(); i++) {
   530             for (int i = 0; i < allRelationships.size(); i++) {
   533                 QContactRelationship currRelationship = allRelationships.at(i);
   531                 QContactRelationship currRelationship = allRelationships.at(i);
   534                 if ((req->participantRole() == QContactRelationshipFilter::Either || req->participantRole() == QContactRelationshipFilter::Second)
   532                 if (currRelationship.second() == req->second()) {
   535                         && currRelationship.second() == req->second()) {
       
   536                     requestedRelationships.append(currRelationship);
       
   537                 } else if ((req->participantRole() == QContactRelationshipFilter::Either || req->participantRole() == QContactRelationshipFilter::First)
       
   538                         && currRelationship.first() == req->second()) {
       
   539                     requestedRelationships.append(currRelationship);
   533                     requestedRelationships.append(currRelationship);
   540                 }
   534                 }
   541             }
   535             }
   542         }
   536         }
   543 
   537 
   544         // update the request with the results.
   538         // update the request with the results.
   545         QContactManagerEngine::updateRelationshipFetchRequest(req, requestedRelationships, operationError);
   539         QContactManagerEngine::updateRelationshipFetchRequest(req, requestedRelationships, operationError, QContactAbstractRequest::FinishedState);
   546     }
   540     }
   547 }
   541 }
   548 
   542 
   549 /*!
   543 /*!
   550  * Processes the QContactRelationshipRemoveRequest \a req
   544  * Processes the QContactRelationshipRemoveRequest \a req
   554 {
   548 {
   555     if (req->manager()) {
   549     if (req->manager()) {
   556         QMap<int, QContactManager::Error> errorMap;
   550         QMap<int, QContactManager::Error> errorMap;
   557         QContactManager::Error operationError = req->manager()->error();
   551         QContactManager::Error operationError = req->manager()->error();
   558         foreach (const QContactRelationship& relationship, req->relationships()) {
   552         foreach (const QContactRelationship& relationship, req->relationships()) {
   559             QList<QContactRelationship> matchingRelationships = req->manager()->relationships(relationship.relationshipType(), relationship.first(), QContactRelationshipFilter::First);
   553             QList<QContactRelationship> matchingRelationships = req->manager()->relationships(relationship.relationshipType(), relationship.first(), QContactRelationship::First);
   560 
   554 
   561             for (int i = 0; i < matchingRelationships.size(); i++) {
   555             for (int i = 0; i < matchingRelationships.size(); i++) {
   562                 QContactManager::Error tempError;
   556                 QContactManager::Error tempError;
   563                 QContactRelationship possibleMatch = matchingRelationships.at(i);
   557                 QContactRelationship possibleMatch = matchingRelationships.at(i);
   564 
   558 
   574                 }
   568                 }
   575             }
   569             }
   576         }
   570         }
   577 
   571 
   578         // there are no results, so just update the status with the error.
   572         // there are no results, so just update the status with the error.
   579         QContactManagerEngine::updateRelationshipRemoveRequest(req, operationError, errorMap);
   573         QContactManagerEngine::updateRelationshipRemoveRequest(req, operationError, errorMap, QContactAbstractRequest::FinishedState);
   580     }
   574     }
   581 }
   575 }
   582 
   576 
   583 /*!
   577 /*!
   584  * Processes the QContactRelationshipSaveRequest \a req
   578  * Processes the QContactRelationshipSaveRequest \a req
   604                 operationError = tempError;
   598                 operationError = tempError;
   605             }
   599             }
   606         }
   600         }
   607 
   601 
   608         // update the request with the results.
   602         // update the request with the results.
   609         QContactManagerEngine::updateRelationshipSaveRequest(req, savedRelationships, operationError, errorMap);
   603         QContactManagerEngine::updateRelationshipSaveRequest(req, savedRelationships, operationError, errorMap, QContactAbstractRequest::FinishedState);
   610     }
   604     }
   611 }
   605 }
   612 
   606 
   613 QContactRequestElement* QContactRequestWorkerData::takeFirstRequestElement()
   607 QContactRequestElement* QContactRequestWorkerData::takeFirstRequestElement()
   614 {
   608 {