|
1 /* |
|
2 * Copyright (c) 2008-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: Title fetcher |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "glxtitlefetcher.h" |
|
24 |
|
25 #include <mpxcollectionpath.h> |
|
26 #include <mpxmediageneraldefs.h> |
|
27 #include <mglxmedialist.h> |
|
28 #include <glxattributecontext.h> |
|
29 #include <glxuistd.h> |
|
30 #include "glxlog.h" |
|
31 #include "glxtracer.h" |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 CGlxTitleFetcher::CGlxTitleFetcher(MGlxTitleFetcherObserver& aObserver, |
|
42 CMPXCollectionPath* aPath) : |
|
43 iObserver(aObserver), iPath(aPath) |
|
44 { |
|
45 TRACER("CGlxTitleFetcher::CGlxTitleFetcher"); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 |
|
53 void CGlxTitleFetcher::ConstructL() |
|
54 { |
|
55 TRACER("CGlxTitleFetcher::ConstructL"); |
|
56 // Go back one level to obtain the ID |
|
57 iPathId = iPath->Id(); |
|
58 // Go back another level from which to create a media list containing |
|
59 // this path |
|
60 if(iPath->Levels() > 0) |
|
61 { |
|
62 iPath->Back(); |
|
63 } |
|
64 |
|
65 iBackMediaList = MGlxMediaList::InstanceL(*iPath); |
|
66 |
|
67 /// @todo: This idSpaceId must be calculated properly |
|
68 TGlxIdSpaceId idSpaceId = iBackMediaList->IdSpaceId(0); |
|
69 |
|
70 TGlxMediaId id(iPathId); |
|
71 TBool requestAttributes = ETrue; |
|
72 TInt index = iBackMediaList->Index(idSpaceId, id); |
|
73 |
|
74 if ( index != KErrNotFound ) |
|
75 { |
|
76 const TGlxMedia& item = iBackMediaList->Item(index); |
|
77 const CGlxMedia* media = item.Properties(); |
|
78 |
|
79 // get the Title from the attribute if it is already present |
|
80 if (media && media->IsSupported(KMPXMediaGeneralTitle) |
|
81 && index != KErrNotFound) |
|
82 { |
|
83 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
84 // notify the observer |
|
85 iObserver.HandleTitleAvailableL(title); |
|
86 requestAttributes = EFalse; |
|
87 } |
|
88 } |
|
89 |
|
90 if ( requestAttributes ) |
|
91 { |
|
92 // Otherwise add a context setting range to cover all items |
|
93 iContext = CGlxDefaultAttributeContext::NewL(); |
|
94 iContext->SetRangeOffsets(10000,10000); |
|
95 iContext->AddAttributeL(KMPXMediaGeneralTitle); |
|
96 // Add the context at a high priority |
|
97 iBackMediaList->AddContextL( iContext, |
|
98 KGlxFetchContextPriorityTitleFetcher ); |
|
99 // Set self as observer |
|
100 iBackMediaList->AddMediaListObserverL(this); |
|
101 } |
|
102 } |
|
103 |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Two-phased constructor. |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CGlxTitleFetcher* CGlxTitleFetcher::NewL(MGlxTitleFetcherObserver& aObserver, |
|
110 CMPXCollectionPath* aPath) |
|
111 { |
|
112 CGlxTitleFetcher* self = new (ELeave) CGlxTitleFetcher(aObserver, aPath); |
|
113 CleanupStack::PushL(self); |
|
114 self->ConstructL(); |
|
115 CleanupStack::Pop(self); |
|
116 return self; |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Destructor |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 CGlxTitleFetcher::~CGlxTitleFetcher() |
|
124 { |
|
125 TRACER("CGlxTitleFetcher::~CGlxTitleFetcher ()"); |
|
126 |
|
127 if(iBackMediaList) |
|
128 { |
|
129 if(iContext) |
|
130 { |
|
131 iBackMediaList->RemoveContext(iContext); |
|
132 delete iContext; |
|
133 } |
|
134 iBackMediaList->RemoveMediaListObserver(this); |
|
135 iBackMediaList->Close(); |
|
136 } |
|
137 |
|
138 } |
|
139 // --------------------------------------------------------------------------- |
|
140 // CGlxTitleFetcher::HandleItemAddedL |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 void CGlxTitleFetcher::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex, |
|
144 MGlxMediaList* aList) |
|
145 { |
|
146 TRACER("CGlxTitleFetcher::HandleItemAddedL ()"); |
|
147 if(aList == iBackMediaList) |
|
148 { |
|
149 for(TInt index = aStartIndex;index <= aEndIndex;index++) |
|
150 // Is it the item (path) that we want |
|
151 { |
|
152 if(aList->Item(index).Id().Value() == (TUint32)iPathId) |
|
153 { |
|
154 const TGlxMedia& item = aList->Item(index); |
|
155 const CGlxMedia* media = item.Properties(); |
|
156 // get the Title from the attribute |
|
157 if (media && media->IsSupported(KMPXMediaGeneralTitle)) |
|
158 { |
|
159 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
160 // notify the observer |
|
161 iObserver.HandleTitleAvailableL(title); |
|
162 iBackMediaList->RemoveContext(iContext); |
|
163 delete iContext; |
|
164 iContext = NULL; |
|
165 } |
|
166 } |
|
167 } |
|
168 } |
|
169 } |
|
170 // --------------------------------------------------------------------------- |
|
171 // CGlxTitleFetcher::HandleAttributesAvailableL |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 void CGlxTitleFetcher::HandleAttributesAvailableL(TInt aItemIndex, |
|
175 const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* aList) |
|
176 { |
|
177 TRACER("CGlxTitleFetcher::HandleAttributesAvailableL ()"); |
|
178 // Is it the list that we want |
|
179 if(aList == iBackMediaList) |
|
180 { |
|
181 // Is it the item (path) that we want |
|
182 if(aList->Item(aItemIndex).Id().Value() == (TUint32)iPathId) |
|
183 { |
|
184 const TGlxMedia& item = aList->Item(aItemIndex); |
|
185 const CGlxMedia* media = item.Properties(); |
|
186 // get the Title from the attribute |
|
187 if (media && media->IsSupported(KMPXMediaGeneralTitle)) |
|
188 { |
|
189 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
190 // notify the observer |
|
191 iObserver.HandleTitleAvailableL(title); |
|
192 iBackMediaList->RemoveContext(iContext); |
|
193 delete iContext; |
|
194 iContext = NULL; |
|
195 |
|
196 } |
|
197 } |
|
198 } |
|
199 } |
|
200 |
|
201 |
|
202 |
|
203 // End of File |