1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef LOGSCNTFINDER_H |
|
19 #define LOGSCNTFINDER_H |
|
20 |
|
21 #include <logscntfinderexport.h> |
|
22 #include <QObject> |
|
23 #include <QList> |
|
24 #include <QString> |
|
25 #include <qmobilityglobal.h> |
|
26 |
|
27 |
|
28 class LogsCntEntry; |
|
29 typedef QObject LogsCntEntryHandle; |
|
30 |
|
31 QTM_BEGIN_NAMESPACE |
|
32 class QContactManager; |
|
33 QTM_END_NAMESPACE |
|
34 |
|
35 QTM_USE_NAMESPACE |
|
36 |
|
37 class LogsCntText |
|
38 { |
|
39 public: |
|
40 |
|
41 inline LogsCntText() : mHighlights(0){} |
|
42 inline const QString& text() const {return mText;} |
|
43 inline int highlights() const {return mHighlights;} |
|
44 LOGSCNTFINDER_EXPORT QString richText( QString startTag = QString("<b><u>"), |
|
45 QString endTag = QString("</u></b>")) const; |
|
46 |
|
47 |
|
48 private: |
|
49 |
|
50 QString mText; |
|
51 QString mTranslatedText; |
|
52 int mHighlights; |
|
53 |
|
54 friend class LogsCntEntry; |
|
55 friend class UT_LogsCntEntry; |
|
56 friend class UT_LogsCntFinder; |
|
57 }; |
|
58 |
|
59 typedef QList<LogsCntText> LogsCntTextList; |
|
60 |
|
61 class LogsCntEntry |
|
62 { |
|
63 public: |
|
64 |
|
65 enum EntryType { |
|
66 EntryTypeHistory, |
|
67 EntryTypeContact |
|
68 }; |
|
69 |
|
70 LOGSCNTFINDER_EXPORT LogsCntEntry( LogsCntEntryHandle& handle, |
|
71 quint32 cid ); |
|
72 LogsCntEntry( quint32 cid ); |
|
73 LogsCntEntry( const LogsCntEntry& entry ); |
|
74 ~LogsCntEntry(); |
|
75 LOGSCNTFINDER_EXPORT EntryType type() const; |
|
76 LOGSCNTFINDER_EXPORT const LogsCntTextList& firstName() const; |
|
77 LOGSCNTFINDER_EXPORT const LogsCntTextList& lastName() const; |
|
78 LOGSCNTFINDER_EXPORT quint32 contactId() const; |
|
79 LOGSCNTFINDER_EXPORT LogsCntEntryHandle* handle() const; |
|
80 LOGSCNTFINDER_EXPORT void setFirstName( const QString& name ); |
|
81 LOGSCNTFINDER_EXPORT void setLastName( const QString& name ); |
|
82 LOGSCNTFINDER_EXPORT const LogsCntText& phoneNumber() const; |
|
83 LOGSCNTFINDER_EXPORT const QString& avatarPath() const; |
|
84 LOGSCNTFINDER_EXPORT void setPhoneNumber( const QString& number ); |
|
85 LOGSCNTFINDER_EXPORT void setAvatarPath( const QString& avatarpath ); |
|
86 LOGSCNTFINDER_EXPORT const QString& speedDial() const; |
|
87 |
|
88 bool isCached() const; |
|
89 void setHighlights( const QString& pattern ); |
|
90 void setSpeedDial( const QString& number ); |
|
91 bool match( const QString& pattern ) const; |
|
92 |
|
93 private: |
|
94 |
|
95 void doSetText( const QString& text, LogsCntTextList& textlist ); |
|
96 QStringList tokens( const QString& source, const QChar& separ = ' ' ) const; |
|
97 void doSetHighlights( const QString& pattern, LogsCntTextList& nameArray ); |
|
98 void resetHighlights( LogsCntTextList& nameArray ); |
|
99 bool doSimpleMatch( const QString& pattern ) const; |
|
100 bool doComplexMatch( QStringList patternArray ) const; |
|
101 |
|
102 private: |
|
103 |
|
104 EntryType mType; |
|
105 quint32 mCid; |
|
106 LogsCntTextList mFirstName; |
|
107 LogsCntTextList mLastName; |
|
108 bool mCached; |
|
109 LogsCntEntryHandle* mHandle; |
|
110 LogsCntText mPhoneNumber; |
|
111 QString mAvatarPath; |
|
112 QString mSpeedDial; |
|
113 |
|
114 friend class UT_LogsCntEntry; |
|
115 friend class UT_LogsCntFinder; |
|
116 }; |
|
117 |
|
118 typedef QList<LogsCntEntry*> LogsCntEntryList; |
|
119 |
|
120 /** |
|
121 * Log events and contacts finder |
|
122 * |
|
123 */ |
|
124 class LogsCntFinder : public QObject |
|
125 { |
|
126 |
|
127 Q_OBJECT |
|
128 |
|
129 public: // The exported API |
|
130 |
|
131 LOGSCNTFINDER_EXPORT LogsCntFinder(); |
|
132 LOGSCNTFINDER_EXPORT LogsCntFinder(QContactManager& contactManager); |
|
133 LOGSCNTFINDER_EXPORT ~LogsCntFinder(); |
|
134 |
|
135 /** |
|
136 * Starts/continues predictive query based on pattern. If |
|
137 * there is a previously executed query with same pattern, |
|
138 * call is treated as continue query. |
|
139 * @param pattern the predictive pattern, containing digit(s) |
|
140 */ |
|
141 LOGSCNTFINDER_EXPORT |
|
142 void predictiveSearchQuery( const QString& pattern ); |
|
143 |
|
144 /** |
|
145 * returns number of results |
|
146 * @return number of results |
|
147 */ |
|
148 LOGSCNTFINDER_EXPORT |
|
149 int resultsCount() const; |
|
150 |
|
151 /** |
|
152 * returns result at index |
|
153 * @param index the index |
|
154 */ |
|
155 LOGSCNTFINDER_EXPORT |
|
156 const LogsCntEntry& resultAt( int index ); |
|
157 |
|
158 /** |
|
159 * Used for adding entiries to be part of a query |
|
160 * Ownership is transfered |
|
161 * @param entry the entry |
|
162 */ |
|
163 LOGSCNTFINDER_EXPORT |
|
164 void insertEntry( int index, LogsCntEntry* entry ); |
|
165 |
|
166 /** |
|
167 * Used for updating entiries |
|
168 * @param handle the handle |
|
169 */ |
|
170 LOGSCNTFINDER_EXPORT |
|
171 LogsCntEntry* getEntry( const LogsCntEntryHandle& handle ) const; |
|
172 |
|
173 /** |
|
174 * Used for updating entiries |
|
175 * @param entry the entry |
|
176 */ |
|
177 LOGSCNTFINDER_EXPORT |
|
178 void deleteEntry( const LogsCntEntryHandle& handle ); |
|
179 |
|
180 signals: |
|
181 |
|
182 /** |
|
183 * emitted when query is ready |
|
184 */ |
|
185 void queryReady(); |
|
186 |
|
187 private: |
|
188 |
|
189 void doPredictiveHistoryQuery(); |
|
190 void doPredictiveContactQuery( LogsCntEntryList& recentResults ); |
|
191 void doPredictiveCacheQuery(); |
|
192 |
|
193 LogsCntEntry* doGetEntry( const LogsCntEntryList& list, |
|
194 const LogsCntEntryHandle& handle ) const; |
|
195 |
|
196 void addResult( quint32 cntId, LogsCntEntryList& recentResults ); |
|
197 void addResult( LogsCntEntry* entry ); |
|
198 void updateResult( LogsCntEntry* entry ); |
|
199 |
|
200 |
|
201 |
|
202 private: |
|
203 |
|
204 QString mCurrentPredictivePattern; |
|
205 LogsCntEntryList mResults; |
|
206 QContactManager* mContactManager; |
|
207 LogsCntEntryList mHistoryEvents; |
|
208 int mCachedCounter; |
|
209 |
|
210 friend class UT_LogsCntFinder; |
|
211 |
|
212 }; |
|
213 |
|
214 #endif //LOGSCNTFINDER_H |
|