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 LOGSDBCONNECTOR_H |
|
19 #define LOGSDBCONNECTOR_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <QObject> |
|
23 #include "logsengdefs.h" |
|
24 #include "logsreaderobserver.h" |
|
25 #include "logsremoveobserver.h" |
|
26 #include "logsmodel.h" |
|
27 // MACROS |
|
28 |
|
29 // DATA TYPES |
|
30 |
|
31 // FUNCTION PROTOTYPES |
|
32 |
|
33 // FORWARD DECLARATIONS |
|
34 class CLogClient; |
|
35 class LogsReader; |
|
36 class LogsEvent; |
|
37 class LogsRemove; |
|
38 class RFs; |
|
39 class CRepository; |
|
40 |
|
41 // CLASS DECLARATIONS |
|
42 |
|
43 |
|
44 /** |
|
45 * LogsDbConnector is used to initialize database access |
|
46 */ |
|
47 class LogsDbConnector : |
|
48 public QObject, public LogsReaderObserver, public LogsRemoveObserver |
|
49 { |
|
50 Q_OBJECT |
|
51 |
|
52 public: |
|
53 |
|
54 /** |
|
55 * Constructor |
|
56 * @param events, connector fills the array with events |
|
57 * read from database. Ownership of events is not transferred. |
|
58 * @param checkAllEvents, true if interested in all events of the database, |
|
59 * false if interested only in recent events |
|
60 */ |
|
61 LogsDbConnector( QList<LogsEvent*>& events, bool checkAllEvents = false ); |
|
62 ~LogsDbConnector(); |
|
63 |
|
64 signals: |
|
65 |
|
66 /** |
|
67 * Signaled once some new data has been read from database. |
|
68 * Added data is placed to event array already when this signal |
|
69 * is emitted. |
|
70 * @param addedIndexes, indexes for new events |
|
71 */ |
|
72 void dataAdded(QList<int> addedIndexes); |
|
73 |
|
74 /** |
|
75 * Signaled once some data has been updated. |
|
76 * Corresponding events have been already updated at event array |
|
77 * when this signal is emitted. |
|
78 * @param updatedIndexes, indexes for updated events |
|
79 */ |
|
80 void dataUpdated(QList<int> updatedIndexes); |
|
81 |
|
82 /** |
|
83 * Signaled once some data has been removed. |
|
84 * Corresponding events have been already removed from event array |
|
85 * when this signal is emitted. |
|
86 * @param removedIndexes, indexes for removed events |
|
87 */ |
|
88 void dataRemoved(QList<int> removedIndexes); |
|
89 |
|
90 /** |
|
91 * Signaled once asycn event clearing has completed. |
|
92 * @param err, 0 if marking completed succesfully |
|
93 */ |
|
94 void clearingCompleted(int err); |
|
95 |
|
96 /** |
|
97 * Signaled once asycn event marking has completed. |
|
98 * @param err, 0 if marking completed succesfully |
|
99 */ |
|
100 void markingCompleted(int err); |
|
101 |
|
102 /** |
|
103 * Signaled once duplicate reading has completed. |
|
104 */ |
|
105 void duplicatesRead(); |
|
106 |
|
107 public: |
|
108 |
|
109 /** |
|
110 * Initialize database access |
|
111 * @return 0 if initialized succesfully |
|
112 */ |
|
113 int init(); |
|
114 |
|
115 /** |
|
116 * Start reading data from database |
|
117 * @return 0 if reading started succesfully |
|
118 */ |
|
119 int start(); |
|
120 |
|
121 /** |
|
122 * Synchronously updates details (rematches from phonebook) for |
|
123 * already read events |
|
124 * @param clearCached if true, cached matches will be cleaned before |
|
125 * rematching |
|
126 */ |
|
127 int updateDetails(bool clearCached); |
|
128 |
|
129 /** |
|
130 * Clear events of defined type. Clearing is async and completion is |
|
131 * indicated by clearingCompleted signal. |
|
132 * @return true if async clearing started |
|
133 */ |
|
134 bool clearList(LogsModel::ClearType cleartype); |
|
135 |
|
136 /** |
|
137 * Starts removing events and all their duplicates. Clearing |
|
138 * can be sync or async. In case of async, completion is |
|
139 * indicated by clearingCompleted signal. |
|
140 * @param eventIds, ids of the events to be removed |
|
141 * @return true if async clearing started |
|
142 */ |
|
143 bool clearEvents(const QList<int>& eventIds); |
|
144 |
|
145 /** |
|
146 * Mark events as seen. Completion is indicated by |
|
147 * markingCompleted signal. |
|
148 * @param eventIds, ids of the events to be marked |
|
149 * @return true if marking started |
|
150 */ |
|
151 bool markEventsSeen(const QList<int>& eventIds); |
|
152 |
|
153 /** |
|
154 * Clear missed calls counter. |
|
155 * @return 0 if clearing was success |
|
156 */ |
|
157 int clearMissedCallsCounter(); |
|
158 |
|
159 /** |
|
160 * Read duplicates for specified event |
|
161 * @param eventId |
|
162 * @return 0 if reading started succesfully |
|
163 */ |
|
164 int readDuplicates(int eventId); |
|
165 |
|
166 /** |
|
167 * Take current duplicates. |
|
168 * @return list of duplicate events, ownership is transferred |
|
169 */ |
|
170 QList<LogsEvent*> takeDuplicates(); |
|
171 |
|
172 protected: // From LogsReaderObserver |
|
173 |
|
174 virtual void readCompleted(int readCount); |
|
175 virtual void errorOccurred(int err); |
|
176 virtual void temporaryErrorOccurred(int err); |
|
177 virtual void eventModifyingCompleted(); |
|
178 virtual void duplicatesReadingCompleted(QList<LogsEvent*> duplicates); |
|
179 |
|
180 protected: // From LogsRemoveObserver |
|
181 virtual void removeCompleted(); |
|
182 virtual void logsRemoveErrorOccured(int err); |
|
183 |
|
184 private: |
|
185 void initL(); |
|
186 void handleTemporaryError(int& error); |
|
187 void deleteRemoved(int newEventCount); |
|
188 int doMarkEventSeen(); |
|
189 bool handleModifyingCompletion(int err=0); |
|
190 |
|
191 private: // data |
|
192 |
|
193 QList<LogsEvent*>& mModelEvents; |
|
194 bool mCheckAllEvents; |
|
195 CLogClient* mLogClient; |
|
196 LogsEventStrings mLogEventStrings; |
|
197 RFs* mFsSession; |
|
198 LogsReader* mReader; |
|
199 LogsRemove* mLogsRemove; |
|
200 CRepository* mRepository; |
|
201 |
|
202 QList<LogsEvent*> mEvents; |
|
203 QList<LogsEvent*> mDuplicatedEvents; |
|
204 QList<int> mRemovedEventIndexes; |
|
205 QList<int> mUpdatedEventIndexes; |
|
206 QList<int> mAddedEventIndexes; |
|
207 QList<int> mEventsSeen; |
|
208 |
|
209 private: // Testing related friend definitions |
|
210 |
|
211 friend class UT_LogsDbConnector; |
|
212 friend class UT_LogsRemove; |
|
213 friend class UT_LogsModel; |
|
214 friend class UT_LogsDetailsModel; |
|
215 |
|
216 }; |
|
217 |
|
218 |
|
219 #endif |
|
220 |
|
221 // End of File LOGSDBCONNECTOR_H |
|