81
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Asynchronously fetches and caches visual contact info for
|
|
15 |
* e.g. list views.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef CNTCACHE_H
|
|
20 |
#define CNTCACHE_H
|
|
21 |
|
|
22 |
#include <QObject>
|
|
23 |
#include <QTimer>
|
|
24 |
#include <QSet>
|
|
25 |
#include <HbIcon>
|
|
26 |
#include <cntuids.h>
|
|
27 |
#include <qcontactmanager.h>
|
|
28 |
#include <cntinfoprovider.h>
|
|
29 |
|
|
30 |
class CntNameFetcher;
|
|
31 |
class CntInfoFetcher;
|
|
32 |
class CntIconFetcher;
|
|
33 |
class CntNameCacheItem;
|
|
34 |
class CntInfoCacheItem;
|
|
35 |
class CntIconCacheItem;
|
|
36 |
|
|
37 |
QTM_USE_NAMESPACE
|
|
38 |
|
|
39 |
class CntContactInfo : public QObject
|
|
40 |
{
|
|
41 |
Q_OBJECT
|
|
42 |
public:
|
|
43 |
CntContactInfo(QContactLocalId id,
|
|
44 |
const QString& name,
|
|
45 |
const QString& text,
|
|
46 |
const HbIcon& icon1,
|
|
47 |
const HbIcon& icon2)
|
|
48 |
{
|
|
49 |
mId = id;
|
|
50 |
mName = name;
|
|
51 |
mText = text;
|
|
52 |
mIcon1 = icon1;
|
|
53 |
mIcon2 = icon2;
|
|
54 |
}
|
|
55 |
~CntContactInfo() {}
|
|
56 |
|
|
57 |
int id() const { return mId; }
|
|
58 |
QString name() const { return mName; }
|
|
59 |
QString text() const { return mText; }
|
|
60 |
HbIcon icon1() const { return mIcon1; }
|
|
61 |
HbIcon icon2() const { return mIcon2; }
|
|
62 |
|
|
63 |
private:
|
|
64 |
QContactLocalId mId;
|
|
65 |
QString mName;
|
|
66 |
QString mText;
|
|
67 |
HbIcon mIcon1;
|
|
68 |
HbIcon mIcon2;
|
|
69 |
};
|
|
70 |
|
|
71 |
class CntCache : public QObject
|
|
72 |
{
|
|
73 |
Q_OBJECT
|
|
74 |
public:
|
|
75 |
static CntCache* createSession(void *client, QContactManager *manager);
|
|
76 |
void closeSession(void *client);
|
|
77 |
|
|
78 |
CntContactInfo* fetchContactInfo(int row, const QList<QContactLocalId>& idList);
|
|
79 |
QList<QContactLocalId> sortIdsByName(const QSet<QContactLocalId>* idFilter = NULL) const;
|
|
80 |
QList<QContactLocalId> sortIdsByName(const QStringList &searchList) const;
|
|
81 |
|
|
82 |
bool event(QEvent *event);
|
|
83 |
|
|
84 |
signals:
|
|
85 |
void contactInfoUpdated(QContactLocalId contactId);
|
|
86 |
void contactsChanged(const QList<QContactLocalId> &changedContacts);
|
|
87 |
void contactsRemoved(const QList<QContactLocalId> &removedContacts);
|
|
88 |
void contactsAdded(const QList<QContactLocalId> &addedContacts);
|
|
89 |
void dataChanged();
|
|
90 |
|
|
91 |
private slots:
|
|
92 |
void startUrgencyMode();
|
|
93 |
void stopUrgencyMode();
|
|
94 |
void processJobs();
|
|
95 |
void postponeJobs(int postponementType, int duration = 0);
|
|
96 |
void resumeJobs();
|
|
97 |
|
|
98 |
void updateCachedInfo(QContactLocalId contactId, const ContactInfoField &infoField, const QString &infoValue);
|
|
99 |
void cancelInfoFetch(QContactLocalId contactId);
|
|
100 |
void updateCachedIcon(const QString &iconName, const HbIcon &icon);
|
|
101 |
void cancelIconFetch(const QString &iconName);
|
|
102 |
|
|
103 |
void updateContacts(const QList<QContactLocalId> &changedContacts);
|
|
104 |
void removeContacts(const QList<QContactLocalId> &removedContacts);
|
|
105 |
void addContacts(const QList<QContactLocalId> &addedContacts);
|
|
106 |
|
|
107 |
void reformatNames(CntNameOrder newFormat);
|
|
108 |
void setNameList(QList<CntNameCacheItem *> newSortedNames);
|
|
109 |
|
|
110 |
private:
|
|
111 |
CntCache(QContactManager *manager);
|
|
112 |
~CntCache();
|
|
113 |
void loadNames();
|
|
114 |
bool contactExists(QContactLocalId contactId) const;
|
|
115 |
QString contactName(QContactLocalId contactId) const;
|
|
116 |
CntInfoCacheItem* createInfoCacheItem(QContactLocalId contactId);
|
|
117 |
CntIconCacheItem* createIconCacheItem(const QString &iconName);
|
|
118 |
void updateReadAheadCache(int mostRecentRow, const QList<QContactLocalId> &idList);
|
|
119 |
void emitContactInfoUpdated(QContactLocalId contactId);
|
|
120 |
|
|
121 |
private:
|
|
122 |
static CntCache *mInstance; // the one and only instance of CntCache
|
|
123 |
QSet<void*> mClients; // the current clients of cache
|
|
124 |
|
|
125 |
QContactManager *mContactManager; // for getting notifications about changes to contacts
|
|
126 |
CntNameFetcher *mNameFetcher; // fetches contact names
|
|
127 |
CntInfoFetcher *mInfoFetcher; // fetches secondary text and icon paths
|
|
128 |
CntIconFetcher *mIconFetcher; // fetches icons
|
|
129 |
|
|
130 |
QList<CntNameCacheItem *> mSortedNames; // list of all contact names, in sorted order
|
|
131 |
QHash<QContactLocalId, CntNameCacheItem *> mNameCache; // cache with all contact names, indexed by contact id
|
|
132 |
QHash<QContactLocalId, CntInfoCacheItem *> mInfoCache; // cache with recent contact info, indexed by contact id
|
|
133 |
QHash<QString, CntIconCacheItem *> mIconCache; // cache with recent icons, indexed by contact id and icon name
|
|
134 |
QList<QPair<QContactLocalId, int> > mReadAheadCache; // cache with contacts to prefetch (they are likely to be needed soon)
|
|
135 |
|
|
136 |
QTimer mResumeJobsTimer; // timer used to resume postponed jobs
|
|
137 |
bool mProcessingJobs; // true from when job loop event has been posted until job loop exits
|
|
138 |
int mJobsPostponed; // are jobs postponed (no / for some time / until further notice)
|
|
139 |
bool mIsInUrgencyMode; // true if cache is in urgency mode; secondary info is fetched immediately
|
|
140 |
int mLastEmittedContactId; // id of the last contact emitted to UI
|
|
141 |
bool mHasModifiedNames; // monitors whether any names have changed since file cache was last updated
|
|
142 |
bool mAllNamesFetchStarted; // false until the asynch fetching of all names from the DB has started;
|
|
143 |
// this operation is done only once
|
|
144 |
friend class TestCntCache;
|
|
145 |
};
|
|
146 |
|
|
147 |
#endif
|