|
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: Private data and helper classes used by class CntCache. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CNTNAMEFETCHER_H |
|
19 #define CNTNAMEFETCHER_H |
|
20 |
|
21 #include <QObject> |
|
22 #include <QThread> |
|
23 #include <QDataStream> |
|
24 #include <QEvent> |
|
25 #include <qcontactid.h> |
|
26 #include <cntuids.h> |
|
27 #include <cntabstractfetcher.h> |
|
28 |
|
29 QTM_USE_NAMESPACE |
|
30 |
|
31 class CntSrvSession; |
|
32 class CntNameCacheItem; |
|
33 class XQSettingsManager; |
|
34 class XQSettingsKey; |
|
35 |
|
36 class CntSrvConnection : public QObject |
|
37 { |
|
38 Q_OBJECT |
|
39 public: |
|
40 CntSrvConnection(); |
|
41 ~CntSrvConnection(); |
|
42 void setAsynchronous(); |
|
43 bool executeSqlQuery(const QString &sqlQuery, CntNameOrder nameFormat, int sizeHintKB); |
|
44 QList<CntNameCacheItem *> names() { return mNames; } |
|
45 |
|
46 protected: |
|
47 bool event(QEvent *event); |
|
48 |
|
49 signals: |
|
50 void namesRead(); |
|
51 void namesSorted(); |
|
52 |
|
53 private: |
|
54 QThread mThread; |
|
55 QList<CntNameCacheItem *> mNames; |
|
56 CntSrvSession *mSession; |
|
57 QString mSqlQuery; |
|
58 CntNameOrder mNameFormat; |
|
59 int mSizeHintKB; |
|
60 bool mIsAsynchronous; |
|
61 }; |
|
62 |
|
63 class CntAllNamesJob : public CntAbstractJob |
|
64 { |
|
65 public: |
|
66 virtual bool isEmpty() { return false; } |
|
67 virtual bool equals(const CntAbstractJob &/*other*/) { return true; } |
|
68 QString toString() { return QString(); } |
|
69 }; |
|
70 |
|
71 class CntNameFetcher : public CntAbstractFetcher |
|
72 { |
|
73 Q_OBJECT |
|
74 public: |
|
75 CntNameFetcher(); |
|
76 ~CntNameFetcher(); |
|
77 |
|
78 // functions for the asynchronous fetching of all names |
|
79 bool isProcessingJob(); |
|
80 void processNextJob(); |
|
81 |
|
82 // synchronous functions |
|
83 CntNameCacheItem * fetchOneName(QContactLocalId contactId) const; |
|
84 bool readNamesFromCache(QList<CntNameCacheItem *> &names); |
|
85 bool writeNamesToCache(const QList<CntNameCacheItem *> &names) const; |
|
86 void sortNames(QList<CntNameCacheItem *> &names) const; |
|
87 static bool compareNames(const CntNameCacheItem *a, const CntNameCacheItem *b); |
|
88 |
|
89 signals: |
|
90 void nameFormatChanged(CntNameOrder nameFormat); |
|
91 void databaseAccessComplete(); |
|
92 void namesAvailable(QList<CntNameCacheItem *> contactNames); |
|
93 |
|
94 private slots: |
|
95 void setNameFormat(const XQSettingsKey &key, const QVariant &value); |
|
96 void sendCompletionSignal(); |
|
97 |
|
98 private: |
|
99 CntSrvConnection *mDbConnection; |
|
100 CntSrvConnection *mAsynchDbConnection; |
|
101 XQSettingsManager *mSettingsManager; |
|
102 XQSettingsKey *mNameFormatSetting; |
|
103 CntNameOrder mNameFormat; |
|
104 int mBufferSizeEstimate; |
|
105 |
|
106 friend class TestNameFetcher; |
|
107 }; |
|
108 |
|
109 #endif |