|
1 /* |
|
2 * Copyright (c) 2006 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: Helper class for checking synch state. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "ccasyncchecker.h" |
|
21 |
|
22 #include "mcastoredcontacts.h" |
|
23 #include "mcapresence.h" |
|
24 |
|
25 #include "ccastoragemanagerfactory.h" |
|
26 #include "capresencemanager.h" |
|
27 |
|
28 #include "impsbuilddefinitions.h" |
|
29 #include "chatdebugprint.h" |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CCASyncChecker::NewLC() |
|
36 // Called when a contact is deleted |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 CCASyncChecker* CCASyncChecker::NewLC() |
|
40 { |
|
41 CCASyncChecker* self = new ( ELeave ) CCASyncChecker(); |
|
42 CleanupStack::PushL( self ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 // --------------------------------------------------------- |
|
48 // CCASyncChecker::~CCASyncChecker() |
|
49 // Called when a contact is deleted |
|
50 // --------------------------------------------------------- |
|
51 // |
|
52 CCASyncChecker::~CCASyncChecker() |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CCASyncChecker::WaitForSyncCompleteL() |
|
58 // Called when a contact is deleted |
|
59 // --------------------------------------------------------- |
|
60 // |
|
61 TBool CCASyncChecker::WaitForSyncCompleteL() |
|
62 { |
|
63 MCAStoredContacts* contacts = CCAStorageManagerFactory::ContactListInterfaceL(); |
|
64 |
|
65 TBool failed = EFalse; |
|
66 |
|
67 if ( !contacts->IsAllSynchronised( failed ) || |
|
68 !IsSyncDoneL() ) |
|
69 { |
|
70 contacts->AddObserverL( this ); |
|
71 |
|
72 if ( !iWait.IsStarted() ) |
|
73 { |
|
74 iWait.Start(); // CSI: 10 # iWait is not an active object |
|
75 } |
|
76 |
|
77 contacts->RemoveObserver( this ); |
|
78 } |
|
79 TBool allSync = contacts->IsAllSynchronised( failed ); |
|
80 TBool syncDone = IsSyncDoneL(); |
|
81 return ( allSync && !failed && syncDone ); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // CCASyncChecker::IsSyncDoneL() |
|
86 // Called when a contact is deleted |
|
87 // --------------------------------------------------------- |
|
88 // |
|
89 TBool CCASyncChecker::IsSyncDoneL() |
|
90 { |
|
91 MCAContactLists* listInterface = |
|
92 CAPresenceManager::InstanceL()->ContactLists(); |
|
93 |
|
94 return listInterface->IsSyncDone(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CCASyncChecker::CheckSyncStateL() |
|
99 // Called when a contact is deleted |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 TBool CCASyncChecker::CheckSyncStateL() |
|
103 { |
|
104 TBool retVal = ETrue; |
|
105 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
106 |
|
107 MCAStoredContacts* contactList = |
|
108 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
109 |
|
110 MCAContactLists* listInterface = |
|
111 CAPresenceManager::InstanceL()->ContactLists(); |
|
112 if ( !listInterface ) |
|
113 { |
|
114 // not logged in yet, so sync state is ok |
|
115 return ETrue; |
|
116 } |
|
117 |
|
118 TBool syncDone = listInterface->IsSyncDone(); |
|
119 |
|
120 TBool ignoreFailed; |
|
121 if ( !contactList->IsAllSynchronised( ignoreFailed ) || |
|
122 !syncDone ) |
|
123 { |
|
124 CCASyncChecker* checker = NewLC(); |
|
125 retVal = checker->WaitForSyncCompleteL(); |
|
126 CleanupStack::PopAndDestroy(); //checker |
|
127 } |
|
128 |
|
129 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
130 return retVal; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CCASyncChecker::HandleDelete() |
|
135 // Called when a contact is deleted |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 |
|
139 void CCASyncChecker::HandleContactDelete( const TDesC& /* aContact */ ) |
|
140 { |
|
141 // Not used |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CCASyncChecker::HandleAddition() |
|
146 // Called when a contact is added |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CCASyncChecker::HandleAddition( MCAContactList& /*aList*/, |
|
150 MCAStoredContact& /*aContact*/ ) |
|
151 { |
|
152 // Not used |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------- |
|
156 // CCASyncChecker::HandleChange() |
|
157 // Called when a contact is changed |
|
158 // --------------------------------------------------------- |
|
159 // |
|
160 void CCASyncChecker::HandleChange( |
|
161 MCAContactList* /*aList*/, |
|
162 MCAStoredContact* /*aContact*/, |
|
163 TStorageManagerGlobals::TCAObserverEventType /*aEventType*/, |
|
164 TBool /*aUserIdChanged*/ ) |
|
165 { |
|
166 CHAT_DP_FUNC_ENTER( "CCASyncChecker::HandleChange" ); |
|
167 |
|
168 MCAStoredContacts* storage = NULL; |
|
169 TRAPD( error, storage = CCAStorageManagerFactory::ContactListInterfaceL() ); |
|
170 |
|
171 if ( error != KErrNone ) |
|
172 { |
|
173 return; |
|
174 } |
|
175 |
|
176 TBool ignoreFailed = EFalse; |
|
177 TBool syncDone = EFalse; |
|
178 TRAP_IGNORE( syncDone = IsSyncDoneL() ); |
|
179 if ( storage->IsAllSynchronised( ignoreFailed ) && |
|
180 syncDone && |
|
181 iWait.IsStarted() ) |
|
182 { |
|
183 iWait.AsyncStop(); |
|
184 } |
|
185 |
|
186 CHAT_DP_FUNC_DONE( "CCASyncChecker::HandleChange" ); |
|
187 } |
|
188 |
|
189 // end of file |