|
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 LOGSREADER_H |
|
19 #define LOGSREADER_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <QList> |
|
23 #include <QHash> |
|
24 #include <e32base.h> |
|
25 #include <logclientchangeobserver.h> |
|
26 #include <logviewchangeobserver.h> |
|
27 #include "logsreaderstatecontext.h" |
|
28 #include "logsreaderstates.h" |
|
29 |
|
30 // FORWARD DECLARATION |
|
31 class CLogViewRecent; |
|
32 class RFs; |
|
33 class CLogClient; |
|
34 class CLogViewEvent; |
|
35 class LogsReaderObserver; |
|
36 class LogsEvent; |
|
37 class LogsEventStrings; |
|
38 class LogsReaderStateFiltering; |
|
39 |
|
40 // CLASS DECLARATION |
|
41 |
|
42 |
|
43 |
|
44 /** |
|
45 * LogsReader is used to read events from database |
|
46 */ |
|
47 class LogsReader : public CActive, |
|
48 public MLogClientChangeObserver, |
|
49 public MLogViewChangeObserver, |
|
50 public LogsReaderStateContext |
|
51 { |
|
52 |
|
53 friend class UT_LogsReader; |
|
54 friend class UT_LogsDbConnector; |
|
55 |
|
56 public: |
|
57 |
|
58 /** |
|
59 * Constructor |
|
60 * @param fsSession, connected fileserver session |
|
61 * @param logClient |
|
62 * @param strings, commonly used strings |
|
63 * @param events, filled with events once reading progresses |
|
64 * @param observer, information about read progress is notified |
|
65 * via the interface |
|
66 * @param readAllEvents, true if all events in db should be read, |
|
67 * otherwise only recent events are read |
|
68 */ |
|
69 LogsReader( RFs& fsSession, |
|
70 CLogClient& logClient, |
|
71 LogsEventStrings& strings, |
|
72 QList<LogsEvent*>& events, |
|
73 LogsReaderObserver& observer, |
|
74 bool readAllEvents = false ); |
|
75 |
|
76 /** |
|
77 * Destructor. |
|
78 */ |
|
79 virtual ~LogsReader(); |
|
80 |
|
81 |
|
82 |
|
83 public: |
|
84 |
|
85 /** |
|
86 * Start reading |
|
87 * @return 0 if reading started succesfully |
|
88 */ |
|
89 int start(); |
|
90 |
|
91 /** |
|
92 * Stop reading |
|
93 */ |
|
94 void stop(); |
|
95 |
|
96 /** |
|
97 * Synchronously update details (rematches from phonebook) for |
|
98 * already read events |
|
99 * @param clearCached if true, cached matches will be cleaned before |
|
100 * rematching |
|
101 */ |
|
102 void updateDetails(bool clearCached); |
|
103 |
|
104 /** |
|
105 * Starts modifying the event and all its duplicates as read |
|
106 * @param eventId, id of the event to be removed |
|
107 * @return 0 if removing started succesfully |
|
108 */ |
|
109 int markEventSeen(int eventId); |
|
110 |
|
111 /** |
|
112 * Starts reading duplicates of the event |
|
113 * @param eventId |
|
114 * @return 0 if removing started succesfully |
|
115 */ |
|
116 int readDuplicates(int eventId); |
|
117 |
|
118 protected: // From CActive |
|
119 |
|
120 void RunL(); |
|
121 void DoCancel(); |
|
122 TInt RunError(TInt error); |
|
123 |
|
124 private: // From MLogClientChangeObserver |
|
125 |
|
126 void HandleLogClientChangeEventL( TUid aChangeType, |
|
127 TInt aChangeParam1, |
|
128 TInt aChangeParam2, |
|
129 TInt aChangeParam3 ); |
|
130 private: // From MLogViewChangeObserver |
|
131 |
|
132 void HandleLogViewChangeEventAddedL( |
|
133 TLogId aId, TInt aViewIndex, |
|
134 TInt aChangeIndex, TInt aTotalChangeCount); |
|
135 |
|
136 void HandleLogViewChangeEventChangedL( |
|
137 TLogId aId, TInt aViewIndex, |
|
138 TInt aChangeIndex, TInt aTotalChangeCount); |
|
139 |
|
140 void HandleLogViewChangeEventDeletedL( |
|
141 TLogId aId, TInt aViewIndex, |
|
142 TInt aChangeIndex, TInt aTotalChangeCount); |
|
143 |
|
144 private: // From LogsReaderStateContext |
|
145 |
|
146 inline void setCurrentState(const LogsReaderStateBase& state); |
|
147 inline CLogView& logView(); |
|
148 inline CLogViewDuplicate& duplicatesView(); |
|
149 inline QList<LogsEvent*>& events(); |
|
150 inline int& index(); |
|
151 inline LogsEventStrings& strings(); |
|
152 inline TRequestStatus& reqStatus(); |
|
153 inline LogsReaderObserver& observer(); |
|
154 inline QHash<QString, ContactCacheEntry>& contactCache(); |
|
155 inline int currentEventId(); |
|
156 inline CLogClient& logClient(); |
|
157 inline bool isRecentView(); |
|
158 inline QList<LogsEvent*>& duplicatedEvents(); |
|
159 |
|
160 private: |
|
161 |
|
162 void startL(); |
|
163 void markEventSeenL(int eventId); |
|
164 void readDuplicatesL(int eventId); |
|
165 |
|
166 /** |
|
167 * Cancel all outstanding requests if possible. In case of deleting is |
|
168 * in progress, it will leave with error |
|
169 */ |
|
170 void cancelCurrentRequestL(); |
|
171 LogsReaderStateBase& currentState(); |
|
172 void initializeReadStates(); |
|
173 void initializeModifyingStates(); |
|
174 void initializeDuplicateReadingStates(); |
|
175 void handleViewChange( int totalChangeCount = 1 ); |
|
176 void handleError(int error); |
|
177 void createLogViewsL(); |
|
178 void deleteLogViews(); |
|
179 LogsReaderStateFiltering* createFilteringState(); |
|
180 void prepareReadingL(); |
|
181 void setGlobalObserver(); |
|
182 void clearGlobalObserver(); |
|
183 |
|
184 private: // data |
|
185 |
|
186 CLogViewRecent* mLogViewRecent; |
|
187 CLogViewEvent* mLogViewEvent; |
|
188 CLogViewDuplicate* mDuplicatesView; |
|
189 |
|
190 RFs& mFsSession; |
|
191 CLogClient& mLogClient; |
|
192 LogsEventStrings& mStrings; |
|
193 QList<LogsEvent*>& mEvents; |
|
194 LogsReaderObserver& mObserver; |
|
195 bool mReadAllEvents; |
|
196 |
|
197 int mIndex; |
|
198 QList<LogsReaderStateBase*> mReadStates; |
|
199 QList<LogsReaderStateBase*> mModifyingStates; |
|
200 QList<LogsReaderStateBase*> mDuplicateReadingStates; |
|
201 int mCurrentStateIndex; |
|
202 QList<LogsReaderStateBase*>* mCurrentStateMachine; |
|
203 |
|
204 QHash<QString, ContactCacheEntry> mContactCache; |
|
205 QList<LogsEvent*> mDuplicatedEvents; |
|
206 |
|
207 int mCurrentEventId; |
|
208 bool mGlobalObserverSet; |
|
209 }; |
|
210 |
|
211 #endif // LOGSREADER_H |
|
212 |
|
213 |
|
214 // End of File |
|
215 |
|
216 |
|
217 |
|
218 |