|
1 /* |
|
2 * Copyright (c) 2006-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: Image Composer's listener for changes in db location relations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <mdelogiccondition.h> |
|
20 #include <mdequery.h> |
|
21 |
|
22 #include "locationrelationobserver.h" |
|
23 #include "harvesterlog.h" |
|
24 #include "mdeconstants.h" |
|
25 #include "composerimageplugin.h" |
|
26 |
|
27 using namespace MdeConstants; |
|
28 |
|
29 |
|
30 CLocationRelationObserver::CLocationRelationObserver() : |
|
31 iDefaultNamespace( NULL ), iSession( NULL ), iComposer( NULL ), |
|
32 iQuery( NULL ), iQueryStarted( EFalse ) |
|
33 { |
|
34 // No implementation required |
|
35 } |
|
36 |
|
37 CLocationRelationObserver::~CLocationRelationObserver() |
|
38 { |
|
39 iRelationIdArray.Close(); |
|
40 |
|
41 if( iSession ) |
|
42 { |
|
43 TRAP_IGNORE( iSession->RemoveRelationObserverL( *this ) ); |
|
44 } |
|
45 } |
|
46 |
|
47 CLocationRelationObserver* CLocationRelationObserver::NewL( CMdESession* aSession, CComposerImagePlugin* aComposer ) |
|
48 { |
|
49 WRITELOG( "CLocationRelationObserver::NewL start" ); |
|
50 CLocationRelationObserver* self = new (ELeave)CLocationRelationObserver(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL( aSession, aComposer ); |
|
53 CleanupStack::Pop(); // self; |
|
54 WRITELOG( "CLocationRelationObserver::NewL end" ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 void CLocationRelationObserver::ConstructL( CMdESession* aSession, CComposerImagePlugin* aComposer ) |
|
59 { |
|
60 WRITELOG( "CLocationRelationObserver::ConstructL start" ); |
|
61 User::LeaveIfNull( iSession = aSession ); |
|
62 User::LeaveIfNull( iComposer = aComposer ); |
|
63 |
|
64 iDefaultNamespace = &iSession->GetDefaultNamespaceDefL(); |
|
65 |
|
66 // start listening to mde location object changes |
|
67 CMdELogicCondition* condition = CMdELogicCondition::NewL( ELogicConditionOperatorAnd ); |
|
68 CleanupStack::PushL( condition ); |
|
69 |
|
70 CMdERelationDef& relationDef = iDefaultNamespace->GetRelationDefL( |
|
71 MdeConstants::Relations::KContainsLocation ); |
|
72 |
|
73 // Create relation condition |
|
74 CMdERelationCondition* relCond = &condition->AddRelationConditionL( relationDef ); |
|
75 |
|
76 // Remove relation condition from logic condition |
|
77 condition->Remove( 0 ); |
|
78 // and delete logic condition |
|
79 CleanupStack::PopAndDestroy( condition ); |
|
80 |
|
81 iSession->AddRelationObserverL( *this, relCond, ENotifyAdd | ENotifyModify | ENotifyRemove, iDefaultNamespace ); |
|
82 |
|
83 WRITELOG( "CLocationRelationObserver::ConstructL end" ); |
|
84 } |
|
85 |
|
86 void CLocationRelationObserver::HandleRelationNotification( |
|
87 CMdESession& /*aSession*/, TObserverNotificationType aType, |
|
88 const RArray<TItemId>& aRelationIdArray) |
|
89 { |
|
90 #ifdef _DEBUG |
|
91 WRITELOG2( "CLocationRelationObserver::HandleObjectModified() objects: %d, aType: %d", aRelationIdArray.Count(), aType ); |
|
92 #endif |
|
93 |
|
94 if ( aType == ENotifyAdd || aType == ENotifyModify ) |
|
95 { |
|
96 #ifdef _DEBUG |
|
97 WRITELOG1( "CLocationRelationObserver::HandleObjectModified() objects: %d", aRelationIdArray.Count() ); |
|
98 #endif |
|
99 |
|
100 // get images |
|
101 const TInt count = aRelationIdArray.Count(); |
|
102 for( TInt i = 0; i < count; i ++ ) |
|
103 { |
|
104 iRelationIdArray.Append( aRelationIdArray[i] ); |
|
105 } |
|
106 |
|
107 if( !iQueryStarted ) |
|
108 { |
|
109 TRAP_IGNORE( QueryRelationItemsL() ); |
|
110 } |
|
111 } |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // QueryImageObjectIdsL |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CLocationRelationObserver::QueryRelationItemsL() |
|
119 { |
|
120 if ( iRelationIdArray.Count() > 0 ) |
|
121 { |
|
122 iQueryStarted = ETrue; |
|
123 } |
|
124 else |
|
125 { |
|
126 iQueryStarted = EFalse; |
|
127 return; |
|
128 } |
|
129 |
|
130 delete iQuery; iQuery = NULL; |
|
131 |
|
132 RArray<TItemId> objectIds; |
|
133 CleanupClosePushL( objectIds ); |
|
134 const TInt count = iRelationIdArray.Count(); |
|
135 for ( TInt i = 0; i < count; i++ ) |
|
136 { |
|
137 objectIds.Append( iRelationIdArray[i] ); |
|
138 } |
|
139 iRelationIdArray.Reset(); |
|
140 |
|
141 iQuery = iSession->NewRelationQueryL( *iDefaultNamespace, this ); |
|
142 User::LeaveIfNull( iQuery ); |
|
143 |
|
144 iQuery->SetResultMode( EQueryResultModeId ); |
|
145 iQuery->Conditions().SetOperator( ELogicConditionOperatorAnd ); |
|
146 |
|
147 // Relation id must be in array |
|
148 iQuery->Conditions().AddRelationConditionL( objectIds ); |
|
149 |
|
150 CMdERelationCondition& filterCondLeft = iQuery->Conditions(). |
|
151 AddRelationConditionL( ERelationConditionSideLeft ); |
|
152 |
|
153 // Left object in relation must be an image object. |
|
154 CMdEObjectDef& imageObjDef = iDefaultNamespace->GetObjectDefL( |
|
155 MdeConstants::Image::KImageObject ); |
|
156 filterCondLeft.LeftL().AddObjectConditionL( imageObjDef ); |
|
157 |
|
158 CMdERelationCondition& filterCondRight = iQuery->Conditions(). |
|
159 AddRelationConditionL( ERelationConditionSideRight ); |
|
160 |
|
161 // Right object in relation must be a location object. |
|
162 CMdEObjectDef& locationObjDef = iDefaultNamespace->GetObjectDefL( |
|
163 Location::KLocationObject ); |
|
164 filterCondRight.RightL().AddObjectConditionL( locationObjDef ); |
|
165 |
|
166 iQuery->FindL(); // results to a call to HandleQueryCompleted() |
|
167 |
|
168 CleanupStack::PopAndDestroy( &objectIds ); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // HandleQueryCompleted |
|
173 // From MMdEQueryObserver. |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void CLocationRelationObserver::HandleQueryNewResults( CMdEQuery& /*aQuery*/, |
|
177 TInt /*aFirstNewItemIndex*/, TInt /*aNewItemCount*/ ) |
|
178 { |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // HandleQueryCompleted |
|
183 // From MMdEQueryObserver. |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CLocationRelationObserver::HandleQueryCompleted( CMdEQuery& aQuery, TInt /*aError*/ ) |
|
187 { |
|
188 if ( aQuery.Count() == 0 ) |
|
189 { |
|
190 WRITELOG( "CLocationObjectObserver::HandleQueryCompleted() - no items found" ); |
|
191 } |
|
192 else |
|
193 { |
|
194 TRAP_IGNORE( |
|
195 const TInt count = aQuery.Count(); |
|
196 for ( TInt i = 0; i < count; i++ ) |
|
197 { |
|
198 CMdERelation* relation = iSession->GetRelationL( aQuery.ResultId(i) ); |
|
199 if ( iComposer && relation ) |
|
200 { |
|
201 iComposer->WriteGPSTagsL( relation->LeftObjectId(), relation->RightObjectId() ); |
|
202 } |
|
203 |
|
204 delete relation; |
|
205 } |
|
206 ) |
|
207 } |
|
208 |
|
209 TRAP_IGNORE( QueryRelationItemsL() ); |
|
210 } |