321 Saves the given \a relationships in the database and returns true if the operation was successful. |
325 Saves the given \a relationships in the database and returns true if the operation was successful. |
322 For any relationship which was unable to be saved, an entry into the \a errorMap will be created, |
326 For any relationship which was unable to be saved, an entry into the \a errorMap will be created, |
323 with the key being the index into the input relationships list, and the value being the error which |
327 with the key being the index into the input relationships list, and the value being the error which |
324 occurred for that index. |
328 occurred for that index. |
325 |
329 |
|
330 The supplied \a errorMap parameter may be null, if the client does not desire detailed error information. |
|
331 If supplied, it will be empty upon entry to this function. |
|
332 |
326 The overall operation error will be saved in \a error. |
333 The overall operation error will be saved in \a error. |
327 */ |
334 */ |
328 bool QContactManagerEngine::saveRelationships(QList<QContactRelationship>* relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error) |
335 bool QContactManagerEngine::saveRelationships(QList<QContactRelationship>* relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error) |
329 { |
336 { |
330 Q_UNUSED(relationships); |
337 Q_UNUSED(relationships); |
395 /*! |
402 /*! |
396 Removes the given \a relationships from the database and returns true if the operation was successful. |
403 Removes the given \a relationships from the database and returns true if the operation was successful. |
397 For any relationship which was unable to be removed, an entry into the \a errorMap will be created, |
404 For any relationship which was unable to be removed, an entry into the \a errorMap will be created, |
398 with the key being the index into the input relationships list, and the value being the error which |
405 with the key being the index into the input relationships list, and the value being the error which |
399 occurred for that index. |
406 occurred for that index. |
|
407 |
|
408 The supplied \a errorMap parameter may be null, if the client does not desire detailed error information. |
|
409 If supplied, it will be empty upon entry to this function. |
400 |
410 |
401 The overall operation error will be saved in \a error. |
411 The overall operation error will be saved in \a error. |
402 */ |
412 */ |
403 bool QContactManagerEngine::removeRelationships(const QList<QContactRelationship>& relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error) |
413 bool QContactManagerEngine::removeRelationships(const QList<QContactRelationship>& relationships, QMap<int, QContactManager::Error>* errorMap, QContactManager::Error* error) |
404 { |
414 { |
1414 Returns true if the contacts were saved successfully, otherwise false. |
1424 Returns true if the contacts were saved successfully, otherwise false. |
1415 |
1425 |
1416 The manager might populate \a errorMap (the map of indices of the \a contacts list to |
1426 The manager might populate \a errorMap (the map of indices of the \a contacts list to |
1417 the error which occurred when saving the contact at that index) for |
1427 the error which occurred when saving the contact at that index) for |
1418 every index for which the contact could not be saved, if it is able. |
1428 every index for which the contact could not be saved, if it is able. |
|
1429 |
|
1430 The supplied \a errorMap parameter may be null, if the client does not desire detailed error information. |
|
1431 If supplied, it will be empty upon entry to this function. |
|
1432 |
1419 The \l QContactManager::error() function will only return \c QContactManager::NoError |
1433 The \l QContactManager::error() function will only return \c QContactManager::NoError |
1420 if all contacts were saved successfully. |
1434 if all contacts were saved successfully. |
1421 |
1435 |
1422 For each newly saved contact that was successful, the id of the contact |
1436 For each newly saved contact that was successful, the id of the contact |
1423 in the \a contacts list will be updated with the new value. If a failure occurs |
1437 in the \a contacts list will be updated with the new value. If a failure occurs |
1445 in which it was involved removed also. |
1459 in which it was involved removed also. |
1446 |
1460 |
1447 The manager might populate \a errorMap (the map of indices of the \a contactIds list to |
1461 The manager might populate \a errorMap (the map of indices of the \a contactIds list to |
1448 the error which occurred when saving the contact at that index) for every |
1462 the error which occurred when saving the contact at that index) for every |
1449 index for which the contact could not be removed, if it is able. |
1463 index for which the contact could not be removed, if it is able. |
|
1464 |
|
1465 The supplied \a errorMap parameter may be null, if the client does not desire detailed error information. |
|
1466 If supplied, it will be empty upon entry to this function. |
|
1467 |
1450 The \l QContactManager::error() function will |
1468 The \l QContactManager::error() function will |
1451 only return \c QContactManager::NoError if all contacts were removed |
1469 only return \c QContactManager::NoError if all contacts were removed |
1452 successfully. |
1470 successfully. |
1453 |
1471 |
1454 If the list contains ids which do not identify a valid contact in the manager, the function will |
1472 If the list contains ids which do not identify a valid contact in the manager, the function will |
1519 |
1537 |
1520 // check that the value is allowable |
1538 // check that the value is allowable |
1521 // if the allowable values is an empty list, any are allowed. |
1539 // if the allowable values is an empty list, any are allowed. |
1522 if (!field.allowableValues().isEmpty()) { |
1540 if (!field.allowableValues().isEmpty()) { |
1523 // if the field datatype is a list, remove non-allowable values |
1541 // if the field datatype is a list, remove non-allowable values |
1524 if (field.dataType() == QVariant::List || field.dataType() == QVariant::StringList) { |
1542 if (field.dataType() == QVariant::List) { |
1525 QList<QVariant> innerValues = variant.toList(); |
1543 QVariantList innerValues = variant.toList(); |
1526 QMutableListIterator<QVariant> it(innerValues); |
1544 QMutableListIterator<QVariant> it(innerValues); |
|
1545 while (it.hasNext()) { |
|
1546 if (!field.allowableValues().contains(it.next())) { |
|
1547 it.remove(); |
|
1548 } |
|
1549 } |
|
1550 if (innerValues.isEmpty()) |
|
1551 detail.removeValue(key); |
|
1552 else |
|
1553 detail.setValue(key, innerValues); |
|
1554 } |
|
1555 if (field.dataType() == QVariant::StringList) { |
|
1556 QStringList innerValues = variant.toStringList(); |
|
1557 QMutableListIterator<QString> it(innerValues); |
1527 while (it.hasNext()) { |
1558 while (it.hasNext()) { |
1528 if (!field.allowableValues().contains(it.next())) { |
1559 if (!field.allowableValues().contains(it.next())) { |
1529 it.remove(); |
1560 it.remove(); |
1530 } |
1561 } |
1531 } |
1562 } |
1550 else |
1581 else |
1551 *error = QContactManager::DoesNotExistError; |
1582 *error = QContactManager::DoesNotExistError; |
1552 return conforming; |
1583 return conforming; |
1553 } |
1584 } |
1554 |
1585 |
|
1586 |
|
1587 /* This implements the string comparison behaviour required for compareVariant, amongst others */ |
|
1588 static inline int compareStrings(const QString& left, const QString& right, Qt::CaseSensitivity sensitivity) |
|
1589 { |
|
1590 if (sensitivity == Qt::CaseSensitive) { |
|
1591 return left.localeAwareCompare(right); |
|
1592 } else { |
|
1593 return left.toCaseFolded().localeAwareCompare(right.toCaseFolded()); |
|
1594 } |
|
1595 } |
|
1596 |
1555 /*! |
1597 /*! |
1556 Compares \a first against \a second. If the types are |
1598 Compares \a first against \a second. If the types are |
1557 strings (QVariant::String), the \a sensitivity argument controls |
1599 strings (QVariant::String), the \a sensitivity argument controls |
1558 case sensitivity when comparing. |
1600 case sensitivity when comparing. Also, when comparing strings, |
|
1601 a locale aware comparison is used, and if the sensitivity is |
|
1602 CaseSensitive, strings that are identical under a case insensitive |
|
1603 sort are then sorted case sensitively within that context. |
|
1604 |
|
1605 |
|
1606 For example: |
|
1607 |
|
1608 aaron |
|
1609 Bob |
|
1610 Aaron |
|
1611 aAron |
|
1612 Carol |
|
1613 |
|
1614 would sort as: |
|
1615 |
|
1616 aaron |
|
1617 aAron |
|
1618 Aaron |
|
1619 Bob |
|
1620 Carol |
1559 |
1621 |
1560 Returns: |
1622 Returns: |
1561 <0 if \a first is less than \a second |
1623 <0 if \a first is less than \a second |
1562 0 if \a first is equal to \a second |
1624 0 if \a first is equal to \a second |
1563 >0 if \a first is greater than \a second. |
1625 >0 if \a first is greater than \a second. |
1821 |
1885 |
1822 /* open or closed interval testing support */ |
1886 /* open or closed interval testing support */ |
1823 const int minComp = cdf.rangeFlags() & QContactDetailRangeFilter::ExcludeLower ? 1 : 0; |
1887 const int minComp = cdf.rangeFlags() & QContactDetailRangeFilter::ExcludeLower ? 1 : 0; |
1824 const int maxComp = cdf.rangeFlags() & QContactDetailRangeFilter::IncludeUpper ? 1 : 0; |
1888 const int maxComp = cdf.rangeFlags() & QContactDetailRangeFilter::IncludeUpper ? 1 : 0; |
1825 |
1889 |
1826 const bool testMin = cdf.minValue().isValid(); |
|
1827 const bool testMax = cdf.maxValue().isValid(); |
|
1828 |
|
1829 /* At this point we know that at least of testMin & testMax is true */ |
|
1830 |
|
1831 /* Case sensitivity, for those parts that use it */ |
1890 /* Case sensitivity, for those parts that use it */ |
1832 Qt::CaseSensitivity cs = (cdf.matchFlags() & QContactFilter::MatchCaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive; |
1891 Qt::CaseSensitivity cs = (cdf.matchFlags() & QContactFilter::MatchCaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive; |
1833 |
1892 |
1834 /* See what flags are requested, since we're looking at a value */ |
1893 /* See what flags are requested, since we're looking at a value */ |
1835 if (cdf.matchFlags() & (QContactFilter::MatchEndsWith | QContactFilter::MatchStartsWith | QContactFilter::MatchContains | QContactFilter::MatchFixedString)) { |
1894 if (cdf.matchFlags() & QContactFilter::MatchFixedString) { |
1836 /* We're strictly doing string comparisons here */ |
1895 /* We're strictly doing string comparisons here */ |
1837 //bool matchStarts = (cdf.matchFlags() & 7) == QContactFilter::MatchStartsWith; |
|
1838 bool matchEnds = (cdf.matchFlags() & 7) == QContactFilter::MatchEndsWith; |
|
1839 bool matchContains = (cdf.matchFlags() & 7) == QContactFilter::MatchContains; |
|
1840 |
|
1841 /* Min/Max and contains do not make sense */ |
|
1842 if (matchContains) |
|
1843 return false; |
|
1844 |
|
1845 QString minVal = cdf.minValue().toString(); |
1896 QString minVal = cdf.minValue().toString(); |
1846 QString maxVal = cdf.maxValue().toString(); |
1897 QString maxVal = cdf.maxValue().toString(); |
1847 |
1898 |
1848 /* Starts with is the normal compare case, endsWith is a bit trickier */ |
1899 const bool testMin = !minVal.isEmpty(); |
|
1900 const bool testMax = !maxVal.isEmpty(); |
|
1901 |
1849 for(int j=0; j < details.count(); j++) { |
1902 for(int j=0; j < details.count(); j++) { |
1850 const QContactDetail& detail = details.at(j); |
1903 const QContactDetail& detail = details.at(j); |
|
1904 |
|
1905 // The detail has to have a field of this type in order to be compared. |
|
1906 if (!detail.variantValue(cdf.detailFieldName()).isValid()) |
|
1907 continue; |
1851 const QString& var = detail.value(cdf.detailFieldName()); |
1908 const QString& var = detail.value(cdf.detailFieldName()); |
1852 if (!matchEnds) { |
1909 if (testMin && compareStrings(var, minVal, cs) < minComp) |
1853 // MatchStarts or MatchFixedString |
1910 continue; |
1854 if (testMin && QString::compare(var, minVal, cs) < minComp) |
1911 if (testMax && compareStrings(var, maxVal, cs) >= maxComp) |
1855 continue; |
1912 continue; |
1856 if (testMax && QString::compare(var, maxVal, cs) >= maxComp) |
1913 return true; |
1857 continue; |
|
1858 return true; |
|
1859 } else { |
|
1860 /* Have to test the length of min & max */ |
|
1861 // using refs means the parameter order is backwards, so negate the result of compare |
|
1862 if (testMin && -QString::compare(minVal, var.rightRef(minVal.length()), cs) < minComp) |
|
1863 continue; |
|
1864 if (testMax && -QString::compare(maxVal, var.rightRef(maxVal.length()), cs) >= maxComp) |
|
1865 continue; |
|
1866 return true; |
|
1867 } |
|
1868 } |
1914 } |
1869 // Fall through to end |
1915 // Fall through to end |
1870 } else { |
1916 } else { |
|
1917 const bool testMin = cdf.minValue().isValid(); |
|
1918 const bool testMax = cdf.maxValue().isValid(); |
|
1919 |
1871 /* Nope, testing the values as a variant */ |
1920 /* Nope, testing the values as a variant */ |
1872 for(int j=0; j < details.count(); j++) { |
1921 for(int j=0; j < details.count(); j++) { |
1873 const QContactDetail& detail = details.at(j); |
1922 const QContactDetail& detail = details.at(j); |
1874 const QVariant& var = detail.variantValue(cdf.detailFieldName()); |
1923 const QVariant& var = detail.variantValue(cdf.detailFieldName()); |
|
1924 |
|
1925 // The detail has to have a field of this type in order to be compared. |
|
1926 if (!var.isValid()) |
|
1927 continue; |
1875 |
1928 |
1876 if (testMin && compareVariant(var, cdf.minValue(), cs) < minComp) |
1929 if (testMin && compareVariant(var, cdf.minValue(), cs) < minComp) |
1877 continue; |
1930 continue; |
1878 if (testMax && compareVariant(var, cdf.maxValue(), cs) >= maxComp) |
1931 if (testMax && compareVariant(var, cdf.maxValue(), cs) >= maxComp) |
1879 continue; |
1932 continue; |
2003 before \a b according to the sort order, a positive number if \a a should appear after \a b according to the sort order, |
2056 before \a b according to the sort order, a positive number if \a a should appear after \a b according to the sort order, |
2004 and zero if the two are unable to be sorted. |
2057 and zero if the two are unable to be sorted. |
2005 */ |
2058 */ |
2006 int QContactManagerEngine::compareContact(const QContact& a, const QContact& b, const QList<QContactSortOrder>& sortOrders) |
2059 int QContactManagerEngine::compareContact(const QContact& a, const QContact& b, const QList<QContactSortOrder>& sortOrders) |
2007 { |
2060 { |
2008 QList<QContactSortOrder> copy = sortOrders; |
2061 foreach(const QContactSortOrder& sortOrder, sortOrders) { |
2009 while (copy.size()) { |
|
2010 // retrieve the next sort order in the list |
|
2011 QContactSortOrder sortOrder = copy.takeFirst(); |
|
2012 if (!sortOrder.isValid()) |
2062 if (!sortOrder.isValid()) |
2013 break; |
2063 break; |
2014 |
2064 |
2015 // obtain the values which this sort order concerns |
2065 // obtain the values which this sort order concerns |
2016 const QVariant& aVal = a.detail(sortOrder.detailDefinitionName()).variantValue(sortOrder.detailFieldName()); |
2066 const QVariant& aVal = a.detail(sortOrder.detailDefinitionName()).variantValue(sortOrder.detailFieldName()); |
2043 } |
2093 } |
2044 |
2094 |
2045 return 0; // or according to id? return (a.id() < b.id() ? -1 : 1); |
2095 return 0; // or according to id? return (a.id() < b.id() ? -1 : 1); |
2046 } |
2096 } |
2047 |
2097 |
|
2098 /* A functor that returns true iff a is less than b, according to the sortOrders passed in to the |
|
2099 * ctor. The sortOrders pointer passed in must remain valid for the lifetime of the functor. */ |
|
2100 class ContactLessThan { |
|
2101 public: |
|
2102 ContactLessThan(const QList<QContactSortOrder>* sortOrders) : mSortOrders(sortOrders) {} |
|
2103 bool operator()(const QContact& a, const QContact& b) const |
|
2104 { |
|
2105 return QContactManagerEngine::compareContact(a, b, *mSortOrders) < 0; |
|
2106 } |
|
2107 private: |
|
2108 const QList<QContactSortOrder>* mSortOrders; |
|
2109 }; |
2048 |
2110 |
2049 /*! |
2111 /*! |
2050 Performs insertion sort of the contact \a toAdd into the \a sorted list, according to the provided \a sortOrders list. |
2112 Performs insertion sort of the contact \a toAdd into the \a sorted list, according to the provided \a sortOrders list. |
2051 The first QContactSortOrder in the list has the highest priority; if the contact \a toAdd is deemed equal to another |
2113 The first QContactSortOrder in the list has the highest priority: if the contact \a toAdd is deemed equal to another |
2052 in the \a sorted list, the second QContactSortOrder in the list is used (and so on until either the contact is inserted |
2114 in the \a sorted list according to the first QContactSortOrder, the second QContactSortOrder in the list is used (and |
2053 or there are no more sort order objects in the list). |
2115 so on until either the contact is inserted or there are no more sort order objects in the list). |
|
2116 |
|
2117 If a contact is equal to another contact according to all sort orders, it is inserted after the previously-added contact. |
2054 */ |
2118 */ |
2055 void QContactManagerEngine::addSorted(QList<QContact>* sorted, const QContact& toAdd, const QList<QContactSortOrder>& sortOrders) |
2119 void QContactManagerEngine::addSorted(QList<QContact>* sorted, const QContact& toAdd, const QList<QContactSortOrder>& sortOrders) |
2056 { |
2120 { |
2057 if (sortOrders.count() > 0) { |
2121 if (sortOrders.count() > 0) { |
2058 for (int i = 0; i < sorted->size(); i++) { |
2122 ContactLessThan lessThan(&sortOrders); |
2059 // check to see if the new contact should be inserted here |
2123 QList<QContact>::iterator it(qUpperBound(sorted->begin(), sorted->end(), toAdd, lessThan)); |
2060 int comparison = compareContact(sorted->at(i), toAdd, sortOrders); |
2124 sorted->insert(it, toAdd); |
2061 if (comparison > 0) { |
2125 } else { |
2062 sorted->insert(i, toAdd); |
2126 // no sort order? just add it to the end |
2063 return; |
2127 sorted->append(toAdd); |
2064 } |
2128 } |
2065 } |
|
2066 } |
|
2067 |
|
2068 // hasn't been inserted yet? append to the list. |
|
2069 sorted->append(toAdd); |
|
2070 } |
2129 } |
2071 |
2130 |
2072 /*! Sorts the given list of contacts \a cs according to the provided \a sortOrders */ |
2131 /*! Sorts the given list of contacts \a cs according to the provided \a sortOrders */ |
2073 QList<QContactLocalId> QContactManagerEngine::sortContacts(const QList<QContact>& cs, const QList<QContactSortOrder>& sortOrders) |
2132 QList<QContactLocalId> QContactManagerEngine::sortContacts(const QList<QContact>& cs, const QList<QContactSortOrder>& sortOrders) |
2074 { |
2133 { |
2075 QList<QContactLocalId> sortedIds; |
2134 QList<QContactLocalId> sortedIds; |
2076 QList<QContact> sortedContacts; |
2135 QList<QContact> sortedContacts = cs; |
2077 if (!sortOrders.isEmpty()) { |
2136 if (!sortOrders.isEmpty()) { |
2078 foreach (const QContact& c, cs) { |
2137 ContactLessThan lessThan(&sortOrders); |
2079 QContactManagerEngine::addSorted(&sortedContacts, c, sortOrders); |
2138 qStableSort(sortedContacts.begin(), sortedContacts.end(), lessThan); |
2080 } |
2139 } |
2081 |
2140 |
2082 foreach(const QContact& c, sortedContacts) { |
2141 foreach(const QContact& c, sortedContacts) { |
2083 sortedIds.append(c.localId()); |
2142 sortedIds.append(c.localId()); |
2084 } |
|
2085 } else { |
|
2086 foreach(const QContact& c, cs) { |
|
2087 sortedIds.append(c.localId()); |
|
2088 } |
|
2089 } |
2143 } |
2090 return sortedIds; |
2144 return sortedIds; |
2091 } |
2145 } |
2092 |
2146 |
2093 /*! |
2147 /*! |
2145 of the request. If the new state is different, the stateChanged() signal |
2199 of the request. If the new state is different, the stateChanged() signal |
2146 will be emitted by the request. |
2200 will be emitted by the request. |
2147 */ |
2201 */ |
2148 void QContactManagerEngine::updateRequestState(QContactAbstractRequest* req, QContactAbstractRequest::State state) |
2202 void QContactManagerEngine::updateRequestState(QContactAbstractRequest* req, QContactAbstractRequest::State state) |
2149 { |
2203 { |
2150 if (req->d_ptr->m_state != state) { |
2204 if (req) { |
2151 req->d_ptr->m_state = state; |
2205 QMutexLocker ml(&req->d_ptr->m_mutex); |
2152 emit req->stateChanged(state); |
2206 if (req->d_ptr->m_state != state) { |
|
2207 req->d_ptr->m_state = state; |
|
2208 ml.unlock(); |
|
2209 emit req->stateChanged(state); |
|
2210 } |
2153 } |
2211 } |
2154 } |
2212 } |
2155 |
2213 |
2156 /*! |
2214 /*! |
2157 Updates the given QContactLocalIdFetchRequest \a req with the latest results \a result, and operation error \a error. |
2215 Updates the given QContactLocalIdFetchRequest \a req with the latest results \a result, and operation error \a error. |
2161 |
2219 |
2162 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2220 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2163 */ |
2221 */ |
2164 void QContactManagerEngine::updateContactLocalIdFetchRequest(QContactLocalIdFetchRequest* req, const QList<QContactLocalId>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2222 void QContactManagerEngine::updateContactLocalIdFetchRequest(QContactLocalIdFetchRequest* req, const QList<QContactLocalId>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2165 { |
2223 { |
2166 QContactLocalIdFetchRequestPrivate* rd = static_cast<QContactLocalIdFetchRequestPrivate*>(req->d_ptr); |
2224 if (req) { |
2167 req->d_ptr->m_error = error; |
2225 QWeakPointer<QContactLocalIdFetchRequest> ireq(req); // Take this in case the first emit deletes us |
2168 rd->m_ids = result; |
2226 QContactLocalIdFetchRequestPrivate* rd = static_cast<QContactLocalIdFetchRequestPrivate*>(ireq.data()->d_ptr); |
2169 bool emitState = rd->m_state != newState; |
2227 QMutexLocker ml(&rd->m_mutex); |
2170 rd->m_state = newState; |
2228 bool emitState = rd->m_state != newState; |
2171 emit req->resultsAvailable(); |
2229 rd->m_ids = result; |
2172 if (emitState) |
2230 rd->m_error = error; |
2173 emit req->stateChanged(newState); |
2231 rd->m_state = newState; |
|
2232 ml.unlock(); |
|
2233 emit ireq.data()->resultsAvailable(); |
|
2234 if (emitState && ireq) |
|
2235 emit ireq.data()->stateChanged(newState); |
|
2236 } |
2174 } |
2237 } |
2175 |
2238 |
2176 /*! |
2239 /*! |
2177 Updates the given QContactFetchRequest \a req with the latest results \a result, and operation error \a error. |
2240 Updates the given QContactFetchRequest \a req with the latest results \a result, and operation error \a error. |
2178 In addition, the state of the request will be changed to \a newState. |
2241 In addition, the state of the request will be changed to \a newState. |
2181 |
2244 |
2182 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2245 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2183 */ |
2246 */ |
2184 void QContactManagerEngine::updateContactFetchRequest(QContactFetchRequest* req, const QList<QContact>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2247 void QContactManagerEngine::updateContactFetchRequest(QContactFetchRequest* req, const QList<QContact>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2185 { |
2248 { |
2186 QContactFetchRequestPrivate* rd = static_cast<QContactFetchRequestPrivate*>(req->d_ptr); |
2249 if (req) { |
2187 req->d_ptr->m_error = error; |
2250 QWeakPointer<QContactFetchRequest> ireq(req); // Take this in case the first emit deletes us |
2188 rd->m_contacts = result; |
2251 QContactFetchRequestPrivate* rd = static_cast<QContactFetchRequestPrivate*>(ireq.data()->d_ptr); |
2189 bool emitState = rd->m_state != newState; |
2252 QMutexLocker ml(&rd->m_mutex); |
2190 rd->m_state = newState; |
2253 bool emitState = rd->m_state != newState; |
2191 emit req->resultsAvailable(); |
2254 rd->m_contacts = result; |
2192 if (emitState) |
2255 rd->m_error = error; |
2193 emit req->stateChanged(newState); |
2256 rd->m_state = newState; |
|
2257 ml.unlock(); |
|
2258 emit ireq.data()->resultsAvailable(); |
|
2259 if (emitState && ireq) |
|
2260 emit ireq.data()->stateChanged(newState); |
|
2261 } |
2194 } |
2262 } |
2195 |
2263 |
2196 /*! |
2264 /*! |
2197 Updates the given QContactRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2265 Updates the given QContactRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2198 In addition, the state of the request will be changed to \a newState. |
2266 In addition, the state of the request will be changed to \a newState. |
2201 |
2269 |
2202 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2270 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2203 */ |
2271 */ |
2204 void QContactManagerEngine::updateContactRemoveRequest(QContactRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2272 void QContactManagerEngine::updateContactRemoveRequest(QContactRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2205 { |
2273 { |
2206 QContactRemoveRequestPrivate* rd = static_cast<QContactRemoveRequestPrivate*>(req->d_ptr); |
2274 if (req) { |
2207 req->d_ptr->m_error = error; |
2275 QWeakPointer<QContactRemoveRequest> ireq(req); // Take this in case the first emit deletes us |
2208 rd->m_errors = errorMap; |
2276 QContactRemoveRequestPrivate* rd = static_cast<QContactRemoveRequestPrivate*>(ireq.data()->d_ptr); |
2209 bool emitState = rd->m_state != newState; |
2277 QMutexLocker ml(&rd->m_mutex); |
2210 rd->m_state = newState; |
2278 bool emitState = rd->m_state != newState; |
2211 emit req->resultsAvailable(); |
2279 rd->m_errors = errorMap; |
2212 if (emitState) |
2280 rd->m_error = error; |
2213 emit req->stateChanged(newState); |
2281 rd->m_state = newState; |
|
2282 ml.unlock(); |
|
2283 emit ireq.data()->resultsAvailable(); |
|
2284 if (emitState && ireq) |
|
2285 emit ireq.data()->stateChanged(newState); |
|
2286 } |
2214 } |
2287 } |
2215 |
2288 |
2216 /*! |
2289 /*! |
2217 Updates the given QContactSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2290 Updates the given QContactSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2218 In addition, the state of the request will be changed to \a newState. |
2291 In addition, the state of the request will be changed to \a newState. |
2221 |
2294 |
2222 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2295 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2223 */ |
2296 */ |
2224 void QContactManagerEngine::updateContactSaveRequest(QContactSaveRequest* req, const QList<QContact>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2297 void QContactManagerEngine::updateContactSaveRequest(QContactSaveRequest* req, const QList<QContact>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2225 { |
2298 { |
2226 QContactSaveRequestPrivate* rd = static_cast<QContactSaveRequestPrivate*>(req->d_ptr); |
2299 if (req) { |
2227 req->d_ptr->m_error = error; |
2300 QWeakPointer<QContactSaveRequest> ireq(req); // Take this in case the first emit deletes us |
2228 rd->m_errors = errorMap; |
2301 QContactSaveRequestPrivate* rd = static_cast<QContactSaveRequestPrivate*>(ireq.data()->d_ptr); |
2229 rd->m_contacts = result; |
2302 QMutexLocker ml(&rd->m_mutex); |
2230 bool emitState = rd->m_state != newState; |
2303 bool emitState = rd->m_state != newState; |
2231 rd->m_state = newState; |
2304 rd->m_contacts = result; |
2232 emit req->resultsAvailable(); |
2305 rd->m_errors = errorMap; |
2233 if (emitState) |
2306 rd->m_error = error; |
2234 emit req->stateChanged(newState); |
2307 rd->m_state = newState; |
|
2308 ml.unlock(); |
|
2309 emit ireq.data()->resultsAvailable(); |
|
2310 if (emitState && ireq) |
|
2311 emit ireq.data()->stateChanged(newState); |
|
2312 } |
2235 } |
2313 } |
2236 |
2314 |
2237 /*! |
2315 /*! |
2238 Updates the given QContactDetailDefinitionSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2316 Updates the given QContactDetailDefinitionSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2239 In addition, the state of the request will be changed to \a newState. |
2317 In addition, the state of the request will be changed to \a newState. |
2242 |
2320 |
2243 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2321 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2244 */ |
2322 */ |
2245 void QContactManagerEngine::updateDefinitionSaveRequest(QContactDetailDefinitionSaveRequest* req, const QList<QContactDetailDefinition>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2323 void QContactManagerEngine::updateDefinitionSaveRequest(QContactDetailDefinitionSaveRequest* req, const QList<QContactDetailDefinition>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2246 { |
2324 { |
2247 QContactDetailDefinitionSaveRequestPrivate* rd = static_cast<QContactDetailDefinitionSaveRequestPrivate*>(req->d_ptr); |
2325 if (req) { |
2248 req->d_ptr->m_error = error; |
2326 QWeakPointer<QContactDetailDefinitionSaveRequest> ireq(req); // Take this in case the first emit deletes us |
2249 rd->m_errors = errorMap; |
2327 QContactDetailDefinitionSaveRequestPrivate* rd = static_cast<QContactDetailDefinitionSaveRequestPrivate*>(req->d_ptr); |
2250 rd->m_definitions = result; |
2328 QMutexLocker ml(&rd->m_mutex); |
2251 bool emitState = rd->m_state != newState; |
2329 bool emitState = rd->m_state != newState; |
2252 rd->m_state = newState; |
2330 rd->m_definitions = result; |
2253 emit req->resultsAvailable(); |
2331 rd->m_errors = errorMap; |
2254 if (emitState) |
2332 rd->m_error = error; |
2255 emit req->stateChanged(newState); |
2333 rd->m_state = newState; |
|
2334 ml.unlock(); |
|
2335 emit ireq.data()->resultsAvailable(); |
|
2336 if (emitState && ireq) |
|
2337 emit ireq.data()->stateChanged(newState); |
|
2338 } |
2256 } |
2339 } |
2257 |
2340 |
2258 /*! |
2341 /*! |
2259 Updates the given QContactDetailDefinitionRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2342 Updates the given QContactDetailDefinitionRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2260 In addition, the state of the request will be changed to \a newState. |
2343 In addition, the state of the request will be changed to \a newState. |
2263 |
2346 |
2264 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2347 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2265 */ |
2348 */ |
2266 void QContactManagerEngine::updateDefinitionRemoveRequest(QContactDetailDefinitionRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2349 void QContactManagerEngine::updateDefinitionRemoveRequest(QContactDetailDefinitionRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2267 { |
2350 { |
2268 QContactDetailDefinitionRemoveRequestPrivate* rd = static_cast<QContactDetailDefinitionRemoveRequestPrivate*>(req->d_ptr); |
2351 if (req) { |
2269 req->d_ptr->m_error = error; |
2352 QWeakPointer<QContactDetailDefinitionRemoveRequest> ireq(req); // Take this in case the first emit deletes us |
2270 rd->m_errors = errorMap; |
2353 QContactDetailDefinitionRemoveRequestPrivate* rd = static_cast<QContactDetailDefinitionRemoveRequestPrivate*>(req->d_ptr); |
2271 bool emitState = rd->m_state != newState; |
2354 QMutexLocker ml(&rd->m_mutex); |
2272 rd->m_state = newState; |
2355 bool emitState = rd->m_state != newState; |
2273 emit req->resultsAvailable(); |
2356 rd->m_errors = errorMap; |
2274 if (emitState) |
2357 rd->m_error = error; |
2275 emit req->stateChanged(newState); |
2358 rd->m_state = newState; |
|
2359 ml.unlock(); |
|
2360 emit ireq.data()->resultsAvailable(); |
|
2361 if (emitState && ireq) |
|
2362 emit ireq.data()->stateChanged(newState); |
|
2363 } |
2276 } |
2364 } |
2277 |
2365 |
2278 /*! |
2366 /*! |
2279 Updates the given QContactDetailDefinitionFetchRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2367 Updates the given QContactDetailDefinitionFetchRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2280 In addition, the state of the request will be changed to \a newState. |
2368 In addition, the state of the request will be changed to \a newState. |
2283 |
2371 |
2284 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2372 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2285 */ |
2373 */ |
2286 void QContactManagerEngine::updateDefinitionFetchRequest(QContactDetailDefinitionFetchRequest* req, const QMap<QString, QContactDetailDefinition>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2374 void QContactManagerEngine::updateDefinitionFetchRequest(QContactDetailDefinitionFetchRequest* req, const QMap<QString, QContactDetailDefinition>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2287 { |
2375 { |
2288 QContactDetailDefinitionFetchRequestPrivate* rd = static_cast<QContactDetailDefinitionFetchRequestPrivate*>(req->d_ptr); |
2376 if (req) { |
2289 req->d_ptr->m_error = error; |
2377 QWeakPointer<QContactDetailDefinitionFetchRequest> ireq(req); // Take this in case the first emit deletes us |
2290 rd->m_errors = errorMap; |
2378 QContactDetailDefinitionFetchRequestPrivate* rd = static_cast<QContactDetailDefinitionFetchRequestPrivate*>(req->d_ptr); |
2291 rd->m_definitions = result; |
2379 QMutexLocker ml(&rd->m_mutex); |
2292 bool emitState = rd->m_state != newState; |
2380 bool emitState = rd->m_state != newState; |
2293 rd->m_state = newState; |
2381 rd->m_definitions = result; |
2294 emit req->resultsAvailable(); |
2382 rd->m_errors = errorMap; |
2295 if (emitState) |
2383 rd->m_error = error; |
2296 emit req->stateChanged(newState); |
2384 rd->m_state = newState; |
|
2385 ml.unlock(); |
|
2386 emit ireq.data()->resultsAvailable(); |
|
2387 if (emitState && ireq) |
|
2388 emit ireq.data()->stateChanged(newState); |
|
2389 } |
2297 } |
2390 } |
2298 |
2391 |
2299 /*! |
2392 /*! |
2300 Updates the given QContactRelationshipSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2393 Updates the given QContactRelationshipSaveRequest \a req with the latest results \a result, operation error \a error, and map of input index to individual error \a errorMap. |
2301 In addition, the state of the request will be changed to \a newState. |
2394 In addition, the state of the request will be changed to \a newState. |
2304 |
2397 |
2305 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2398 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2306 */ |
2399 */ |
2307 void QContactManagerEngine::updateRelationshipSaveRequest(QContactRelationshipSaveRequest* req, const QList<QContactRelationship>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2400 void QContactManagerEngine::updateRelationshipSaveRequest(QContactRelationshipSaveRequest* req, const QList<QContactRelationship>& result, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2308 { |
2401 { |
2309 QContactRelationshipSaveRequestPrivate* rd = static_cast<QContactRelationshipSaveRequestPrivate*>(req->d_ptr); |
2402 if (req) { |
2310 req->d_ptr->m_error = error; |
2403 QWeakPointer<QContactRelationshipSaveRequest> ireq(req); // Take this in case the first emit deletes us |
2311 rd->m_errors = errorMap; |
2404 QContactRelationshipSaveRequestPrivate* rd = static_cast<QContactRelationshipSaveRequestPrivate*>(req->d_ptr); |
2312 rd->m_relationships = result; |
2405 QMutexLocker ml(&rd->m_mutex); |
2313 bool emitState = rd->m_state != newState; |
2406 bool emitState = rd->m_state != newState; |
2314 rd->m_state = newState; |
2407 rd->m_relationships = result; |
2315 emit req->resultsAvailable(); |
2408 rd->m_errors = errorMap; |
2316 if (emitState) |
2409 rd->m_error = error; |
2317 emit req->stateChanged(newState); |
2410 rd->m_state = newState; |
|
2411 ml.unlock(); |
|
2412 emit ireq.data()->resultsAvailable(); |
|
2413 if (emitState && ireq) |
|
2414 emit ireq.data()->stateChanged(newState); |
|
2415 } |
2318 } |
2416 } |
2319 |
2417 |
2320 /*! |
2418 /*! |
2321 Updates the given QContactRelationshipRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2419 Updates the given QContactRelationshipRemoveRequest \a req with the operation error \a error, and map of input index to individual error \a errorMap. |
2322 In addition, the state of the request will be changed to \a newState. |
2420 In addition, the state of the request will be changed to \a newState. |
2325 |
2423 |
2326 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2424 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2327 */ |
2425 */ |
2328 void QContactManagerEngine::updateRelationshipRemoveRequest(QContactRelationshipRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2426 void QContactManagerEngine::updateRelationshipRemoveRequest(QContactRelationshipRemoveRequest* req, QContactManager::Error error, const QMap<int, QContactManager::Error>& errorMap, QContactAbstractRequest::State newState) |
2329 { |
2427 { |
2330 QContactRelationshipRemoveRequestPrivate* rd = static_cast<QContactRelationshipRemoveRequestPrivate*>(req->d_ptr); |
2428 if (req) { |
2331 req->d_ptr->m_error = error; |
2429 QWeakPointer<QContactRelationshipRemoveRequest> ireq(req); // Take this in case the first emit deletes us |
2332 rd->m_errors = errorMap; |
2430 QContactRelationshipRemoveRequestPrivate* rd = static_cast<QContactRelationshipRemoveRequestPrivate*>(req->d_ptr); |
2333 bool emitState = rd->m_state != newState; |
2431 QMutexLocker ml(&rd->m_mutex); |
2334 rd->m_state = newState; |
2432 bool emitState = rd->m_state != newState; |
2335 emit req->resultsAvailable(); |
2433 rd->m_errors = errorMap; |
2336 if (emitState) |
2434 rd->m_error = error; |
2337 emit req->stateChanged(newState); |
2435 rd->m_state = newState; |
|
2436 ml.unlock(); |
|
2437 emit ireq.data()->resultsAvailable(); |
|
2438 if (emitState && ireq) |
|
2439 emit ireq.data()->stateChanged(newState); |
|
2440 } |
2338 } |
2441 } |
2339 |
2442 |
2340 /*! |
2443 /*! |
2341 Updates the given QContactRelationshipFetchRequest \a req with the latest results \a result, and operation error \a error. |
2444 Updates the given QContactRelationshipFetchRequest \a req with the latest results \a result, and operation error \a error. |
2342 In addition, the state of the request will be changed to \a newState. |
2445 In addition, the state of the request will be changed to \a newState. |
2345 |
2448 |
2346 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2449 If the new request state is different from the previous state, the stateChanged() signal will also be emitted from the request. |
2347 */ |
2450 */ |
2348 void QContactManagerEngine::updateRelationshipFetchRequest(QContactRelationshipFetchRequest* req, const QList<QContactRelationship>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2451 void QContactManagerEngine::updateRelationshipFetchRequest(QContactRelationshipFetchRequest* req, const QList<QContactRelationship>& result, QContactManager::Error error, QContactAbstractRequest::State newState) |
2349 { |
2452 { |
2350 QContactRelationshipFetchRequestPrivate* rd = static_cast<QContactRelationshipFetchRequestPrivate*>(req->d_ptr); |
2453 if (req) { |
2351 req->d_ptr->m_error = error; |
2454 QWeakPointer<QContactRelationshipFetchRequest> ireq(req); // Take this in case the first emit deletes us |
2352 rd->m_relationships = result; |
2455 QContactRelationshipFetchRequestPrivate* rd = static_cast<QContactRelationshipFetchRequestPrivate*>(req->d_ptr); |
2353 bool emitState = rd->m_state != newState; |
2456 QMutexLocker ml(&rd->m_mutex); |
2354 rd->m_state = newState; |
2457 bool emitState = rd->m_state != newState; |
2355 emit req->resultsAvailable(); |
2458 rd->m_relationships = result; |
2356 if (emitState) |
2459 rd->m_error = error; |
2357 emit req->stateChanged(newState); |
2460 rd->m_state = newState; |
|
2461 ml.unlock(); |
|
2462 emit ireq.data()->resultsAvailable(); |
|
2463 if (emitState && ireq) |
|
2464 emit ireq.data()->stateChanged(newState); |
|
2465 } |
2358 } |
2466 } |
2359 |
2467 |
2360 #include "moc_qcontactmanagerengine.cpp" |
2468 #include "moc_qcontactmanagerengine.cpp" |
2361 |
2469 |
2362 QTM_END_NAMESPACE |
2470 QTM_END_NAMESPACE |