1 /* |
|
2 * Copyright (c) 2008 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: Dublicate detector for images and videos |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <mdelogiccondition.h> |
|
19 #include <mdesession.h> |
|
20 #include <mdccommon.h> |
|
21 #include <mdeconstants.h> |
|
22 |
|
23 #include "cmfilllistitem.h" |
|
24 #include "cmfmitemhandlerobserver.h" |
|
25 #include "cmfmmdeduplicatedetector.h" |
|
26 #include "cmfmmpxduplicatedetector.h" |
|
27 #include "cmfmmain.h" |
|
28 #include "msdebug.h" |
|
29 |
|
30 |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CCmFmMdEDuplicateDetector::NewL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CCmFmMdEDuplicateDetector* CCmFmMdEDuplicateDetector::NewL( |
|
37 MCmFmItemHandlerObserver& aObserver, CMdESession& aSession ) |
|
38 { |
|
39 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::NewL() start")); |
|
40 CCmFmMdEDuplicateDetector* self = |
|
41 CCmFmMdEDuplicateDetector::NewLC( aObserver, aSession ); |
|
42 CleanupStack::Pop( self ); |
|
43 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::NewL() end")); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // CCmFmMdEDuplicateDetector::NewLC |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CCmFmMdEDuplicateDetector* CCmFmMdEDuplicateDetector::NewLC( |
|
52 MCmFmItemHandlerObserver& aObserver, CMdESession& aSession ) |
|
53 { |
|
54 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::NewLC() start")); |
|
55 CCmFmMdEDuplicateDetector* self = |
|
56 new ( ELeave ) CCmFmMdEDuplicateDetector( aObserver, aSession ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::NewLC() end")); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CCmFmMdEDuplicateDetector::~CCmFmMdEDuplicateDetector |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CCmFmMdEDuplicateDetector::~CCmFmMdEDuplicateDetector() |
|
68 { |
|
69 LOG(_L("[FILL MNGR]\t ~CCmFmMdEDuplicateDetector()")); |
|
70 delete iTitle; |
|
71 delete iDate; |
|
72 delete iSize; |
|
73 |
|
74 delete iQuery; |
|
75 delete iMediaTypeDef; |
|
76 delete iObjectDef; |
|
77 delete iNamespace; |
|
78 delete iCheckItem; |
|
79 iExistFiles.ResetAndDestroy(); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CCmFmMdEDuplicateDetector::CCmFmMdEDuplicateDetector |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CCmFmMdEDuplicateDetector::CCmFmMdEDuplicateDetector( |
|
87 MCmFmItemHandlerObserver& aObserver, CMdESession& aSession ) |
|
88 : iObserver( aObserver ), iSession( aSession ) |
|
89 { |
|
90 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::\ |
|
91 CCmFmMdEDuplicateDetector")); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CCmFmMdEDuplicateDetector::ConstructL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 void CCmFmMdEDuplicateDetector::ConstructL() |
|
99 { |
|
100 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::ConstructL")); |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------------------------- |
|
104 // CCmFmMdEDuplicateDetector::CheckImageOrVideoL |
|
105 // --------------------------------------------------------------------------- |
|
106 // |
|
107 void CCmFmMdEDuplicateDetector::CheckImageOrVideoL( |
|
108 const CCmFillListItem& aItem ) |
|
109 { |
|
110 LOG(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::CheckImageOrVideoL")); |
|
111 TCmMediaType theType = aItem.MediaType(); |
|
112 if( iExistFiles.Count() > 0 && iCurrentMediaType == theType ) |
|
113 { |
|
114 CheckImageOrVideoLIfDuplicated( aItem ); |
|
115 } |
|
116 else |
|
117 { |
|
118 delete iCheckItem; |
|
119 iCheckItem = NULL; |
|
120 iCheckItem = CCmFillListItem::NewL(); |
|
121 iCheckItem->SetPrimaryTextL( aItem.PrimaryText() ); |
|
122 iCheckItem->SetSize( aItem.Size() ); |
|
123 iCheckItem->SetDate( aItem.Date() ); |
|
124 delete iQuery; |
|
125 iQuery = NULL; |
|
126 |
|
127 if( !iNamespace ) |
|
128 { |
|
129 iNamespace = &iSession.GetDefaultNamespaceDefL(); |
|
130 } |
|
131 if( iNamespace ) |
|
132 { |
|
133 iObjectDef = |
|
134 &iNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject ); |
|
135 } |
|
136 |
|
137 iCurrentMediaType = theType; |
|
138 if( ECmImage == theType || ECmOtherImage == theType ) |
|
139 { |
|
140 TRACE(Print(_L("ECmImage == aType"))); |
|
141 iMediaTypeDef = |
|
142 &iNamespace->GetObjectDefL( MdeConstants::Image::KImageObject ); |
|
143 } |
|
144 else if( ECmVideo == theType || ECmOtherVideo == theType ) |
|
145 { |
|
146 TRACE(Print(_L("ECmVideo == aType"))); |
|
147 iMediaTypeDef = |
|
148 &iNamespace->GetObjectDefL( MdeConstants::Video::KVideoObject ); |
|
149 } |
|
150 else |
|
151 { |
|
152 User::Leave( KErrArgument ); |
|
153 } |
|
154 if( !iObjectDef || !iMediaTypeDef ) |
|
155 { |
|
156 User::Leave( KErrArgument ); |
|
157 } |
|
158 |
|
159 iQuery = iSession.NewObjectQueryL( |
|
160 *iNamespace, *iMediaTypeDef, this ); |
|
161 if( !iQuery ) |
|
162 { |
|
163 User::Leave( KErrArgument ); |
|
164 } |
|
165 SetLogicConditionL( aItem ); |
|
166 //iQuery->SetResultMode( EQueryResultModeId ); |
|
167 iQuery->SetResultMode( EQueryResultModeItem ); |
|
168 /** Start query, no need to query more than one item */ |
|
169 iQuery->FindL(); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CCmFmMdEDuplicateDetector::HandleQueryNewResults |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CCmFmMdEDuplicateDetector::HandleQueryNewResults(CMdEQuery& aQuery, |
|
178 TInt aFirstNewItemIndex, |
|
179 TInt aNewItemCount) |
|
180 { |
|
181 TRACE(Print(_L("[FILL MNGR]\t CCmFmMdEDuplicateDetector::\ |
|
182 HandleQueryNewResultsaNewItemCount %d"), aNewItemCount )); |
|
183 CMdEObjectQuery& query = (CMdEObjectQuery &) aQuery; |
|
184 iExistFiles.Reset(); |
|
185 TRACE(Print(_L("[FILL MNGR]\t aNewItemCount %d"), aNewItemCount )); |
|
186 if( &query ) |
|
187 { |
|
188 for ( TInt i = aFirstNewItemIndex; |
|
189 i < aFirstNewItemIndex+aNewItemCount; |
|
190 i++ ) |
|
191 { |
|
192 CCmFillListItem *itm = CCmFillListItem::NewLC(); |
|
193 CMdEObject* object = (CMdEObject*)query.TakeOwnershipOfResult(i); |
|
194 CMdEProperty* prop; |
|
195 TInt propIndex = object->Property( *iTitle, prop ); |
|
196 if( propIndex != KErrNotFound ) |
|
197 { |
|
198 CMdETextProperty* textprop = (CMdETextProperty*) prop; |
|
199 itm->SetPrimaryTextL( textprop->Value() ); |
|
200 } |
|
201 else |
|
202 { |
|
203 TParsePtrC parser( object->Uri()); |
|
204 itm->SetPrimaryTextL( parser.Name() ); |
|
205 } |
|
206 |
|
207 propIndex = object->Property( *iSize, prop ); |
|
208 if( propIndex != KErrNotFound ) |
|
209 { |
|
210 itm->SetSize( prop->Uint32ValueL() ); |
|
211 } |
|
212 iExistFiles.AppendL( itm ); |
|
213 TRACE(Print(_L("[FILL MNGR]\t HandleQueryNewResults [%S][%d]"), |
|
214 &itm->PrimaryText(), itm->Size() )); |
|
215 CleanupStack::Pop( itm ); |
|
216 } |
|
217 |
|
218 // sort by size |
|
219 TLinearOrder<CCmFillListItem> key( CCmFmMain::CompareBySize ); |
|
220 iExistFiles.Sort( key ); |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // CCmFmMdEDuplicateDetector::HandleQueryCompleted |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 #ifdef _DEBUG |
|
229 void CCmFmMdEDuplicateDetector::HandleQueryCompleted( CMdEQuery& /*aQuery*/, |
|
230 TInt aError ) |
|
231 #else |
|
232 void CCmFmMdEDuplicateDetector::HandleQueryCompleted( CMdEQuery& /*aQuery*/, |
|
233 TInt /*aError*/ ) |
|
234 #endif |
|
235 { |
|
236 TRACE(Print(_L("[FILL MNGR]\t HandleQueryCompleted error = %d"), |
|
237 aError )); |
|
238 if( iCheckItem ) |
|
239 { |
|
240 CheckImageOrVideoLIfDuplicated( *iCheckItem ); |
|
241 } |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------------------------- |
|
245 // CCmFmMdEDuplicateDetector::SetLogicConditionL |
|
246 // --------------------------------------------------------------------------- |
|
247 // |
|
248 void CCmFmMdEDuplicateDetector::SetLogicConditionL( |
|
249 const CCmFillListItem& /*aItem*/ ) |
|
250 { |
|
251 LOG(_L("[FILL MNGR]\t SetLogicConditionL")); |
|
252 CMdELogicCondition& rootCondition = iQuery->Conditions(); |
|
253 CMdELogicCondition* contentCondition = &rootCondition; |
|
254 CMdELogicCondition& logicCondition = |
|
255 contentCondition->AddLogicConditionL( ELogicConditionOperatorOr ); |
|
256 logicCondition.AddObjectConditionL( *iMediaTypeDef ); |
|
257 |
|
258 iTitle = &iMediaTypeDef->GetPropertyDefL( |
|
259 MdeConstants::Object::KTitleProperty ); |
|
260 iSize = &iMediaTypeDef->GetPropertyDefL( |
|
261 MdeConstants::Object::KSizeProperty ); |
|
262 iDate = &iMediaTypeDef->GetPropertyDefL( |
|
263 MdeConstants::Object::KCreationDateProperty ); |
|
264 iQuery->AddPropertyFilterL( iTitle ); |
|
265 iQuery->AddPropertyFilterL( iSize ); |
|
266 iQuery->AddPropertyFilterL( iDate ); |
|
267 } |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // CCmFmMdEDuplicateDetector::CheckImageOrVideoLIfDuplicated |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void CCmFmMdEDuplicateDetector::CheckImageOrVideoLIfDuplicated( |
|
274 const CCmFillListItem& aItem ) |
|
275 { |
|
276 TInt count( iExistFiles.Count() ); |
|
277 TBool dup( EFalse ); |
|
278 for( TInt i = 0; i < count; i++ ) |
|
279 { |
|
280 if( iExistFiles[i]->Size() > aItem.Size() ) |
|
281 { |
|
282 //quit loop |
|
283 i = count; |
|
284 } |
|
285 else if( iExistFiles[i]->Size() == aItem.Size() && KErrNone == |
|
286 iExistFiles[i]->PrimaryText().CompareF( aItem.PrimaryText() ) ) |
|
287 { |
|
288 //quit loop |
|
289 i = count; |
|
290 dup = ETrue; |
|
291 } |
|
292 } |
|
293 iObserver.DuplicateL( dup ); |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CCmFmMdEDuplicateDetector::AppendToArray |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CCmFmMdEDuplicateDetector::AppendToArrayL( const CCmFillListItem& aItem ) |
|
301 { |
|
302 CCmFillListItem* p = CCmFillListItem::NewLC(); |
|
303 p->SetPrimaryTextL( aItem.PrimaryText() ); |
|
304 p->SetSize( aItem.Size() ); |
|
305 iExistFiles.AppendL( p ); |
|
306 CleanupStack::Pop( p ); |
|
307 |
|
308 // sort by size |
|
309 TLinearOrder<CCmFillListItem> key( CCmFmMain::CompareBySize ); |
|
310 iExistFiles.Sort( key ); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CCmFmMdEDuplicateDetector::ResetArrayL |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CCmFmMdEDuplicateDetector::ResetArray() |
|
318 { |
|
319 iExistFiles.Reset(); |
|
320 } |
|
321 |
|
322 // End of file |
|