Commit 0004b232 authored by Richard Braakman's avatar Richard Braakman

Merge pull request #100 from amtep/master

Fix UI freeze on first start
parents 5b5c00d3 4bfe8804
......@@ -682,6 +682,24 @@ void SeasideCache::unregisterResolveListener(ResolveListener *listener)
++it2;
}
}
QList<ResolveData>::iterator it3 = instancePtr->m_unknownResolveAddresses.begin();
while (it3 != instancePtr->m_unknownResolveAddresses.end()) {
if (it3->listener == listener) {
it3 = instancePtr->m_unknownResolveAddresses.erase(it3);
} else {
++it3;
}
}
QSet<ResolveData>::iterator it4 = instancePtr->m_pendingResolve.begin();
while (it4 != instancePtr->m_pendingResolve.end()) {
if (it4->listener == listener) {
it4 = instancePtr->m_pendingResolve.erase(it4);
} else {
++it4;
}
}
}
void SeasideCache::setNameGrouper(SeasideNameGrouper *grouper)
......@@ -1420,6 +1438,7 @@ void SeasideCache::startRequest(bool *idleProcessing)
m_fetchRequest.setFilter(favoriteFilter());
m_fetchRequest.setFetchHint(favoriteFetchHint(m_fetchTypes));
m_fetchRequest.setSorting(m_sortOrder);
qDebug() << "Starting favorites query at" << m_timer.elapsed() << "ms";
m_fetchRequest.start();
m_fetchProcessedCount = 0;
......@@ -1464,6 +1483,7 @@ void SeasideCache::startRequest(bool *idleProcessing)
m_fetchRequest.setFilter(allFilter());
m_fetchRequest.setFetchHint(metadataFetchHint(m_fetchTypes));
m_fetchRequest.setSorting(m_sortOrder);
qDebug() << "Starting metadata query at" << m_timer.elapsed() << "ms";
m_fetchRequest.start();
m_fetchProcessedCount = 0;
......@@ -1473,6 +1493,7 @@ void SeasideCache::startRequest(bool *idleProcessing)
m_fetchRequest.setFilter(onlineFilter());
m_fetchRequest.setFetchHint(onlineFetchHint(m_fetchTypes | SeasideCache::FetchAccountUri));
m_fetchRequest.setSorting(m_onlineSortOrder);
qDebug() << "Starting online query at" << m_timer.elapsed() << "ms";
m_fetchRequest.start();
m_fetchProcessedCount = 0;
......@@ -2707,6 +2728,7 @@ void SeasideCache::addressRequestStateChanged(QContactAbstractRequest::State sta
}
data.listener->addressResolved(data.first, data.second, item);
delete it.key();
m_pendingResolve.remove(data);
m_resolveAddresses.erase(it);
}
......@@ -3078,6 +3100,10 @@ void SeasideCache::resolveAddress(ResolveListener *listener, const QString &firs
data.requireComplete = requireComplete;
data.listener = listener;
// filter out duplicate requests
if (m_pendingResolve.find(data) != m_pendingResolve.end())
return;
// Is this address a known-unknown?
bool knownUnknown = false;
QList<ResolveData>::const_iterator it = instancePtr->m_unknownAddresses.constBegin(), end = m_unknownAddresses.constEnd();
......@@ -3126,6 +3152,7 @@ void SeasideCache::resolveAddress(ResolveListener *listener, const QString &firs
connect(request, SIGNAL(stateChanged(QContactAbstractRequest::State)),
this, SLOT(addressRequestStateChanged(QContactAbstractRequest::State)));
m_resolveAddresses[request] = data;
m_pendingResolve.insert(data);
request->start();
}
}
......@@ -3193,5 +3220,27 @@ QContactRelationship SeasideCache::makeRelationship(const QString &type, const Q
return makeRelationship(type, contact1.id(), contact2.id());
}
bool operator==(const SeasideCache::ResolveData &lhs, const SeasideCache::ResolveData &rhs)
{
// .listener and .requireComplete first because they are the cheapest comparisons
// then .second before .first because .second is most likely to be unequal
// .compare is derived from first and second so it does not need to be checked
return lhs.listener == rhs.listener
&& lhs.requireComplete == rhs.requireComplete
&& lhs.second == rhs.second
&& lhs.first == rhs.first;
}
uint qHash(const SeasideCache::ResolveData &key, uint seed)
{
uint h1 = qHash(key.first, seed);
uint h2 = qHash(key.second, seed);
uint h3 = key.requireComplete;
uint h4 = qHash(key.listener, seed);
// Don't xor with seed here because h4 already did that
return h1 ^ h2 ^ h3 ^ h4;
}
// Instantiate the contact ID functions for qtcontacts-sqlite
#include <qtcontacts-extensions_impl.h>
......@@ -52,6 +52,7 @@
#include <QContactIdFetchRequest>
#include <QBasicTimer>
#include <QHash>
#include <QSet>
#include <QElapsedTimer>
......@@ -469,11 +470,12 @@ private:
struct ResolveData {
QString first;
QString second;
QString compare;
QString compare; // only used in m_unknownAddresses
bool requireComplete;
ResolveListener *listener;
};
QHash<QContactFetchRequest *, ResolveData> m_resolveAddresses;
QSet<ResolveData> m_pendingResolve; // these have active requests already
QList<ResolveData> m_unknownResolveAddresses;
QList<ResolveData> m_unknownAddresses;
QSet<QString> m_resolvedPhoneNumbers;
......@@ -484,6 +486,12 @@ private:
static SeasideCache *instancePtr;
static int contactNameGroupCount;
static QStringList allContactNameGroups;
friend bool operator==(const SeasideCache::ResolveData &lhs, const SeasideCache::ResolveData &rhs);
friend uint qHash(const SeasideCache::ResolveData &key, uint seed);
};
bool operator==(const SeasideCache::ResolveData &lhs, const SeasideCache::ResolveData &rhs);
uint qHash(const SeasideCache::ResolveData &key, uint seed = 0);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment