|
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 iPath->Back(); |
|
61 |
|
62 iBackMediaList = MGlxMediaList::InstanceL(*iPath); |
|
63 |
|
64 /// @todo: This idSpaceId must be calculated properly |
|
65 TGlxIdSpaceId idSpaceId = iBackMediaList->IdSpaceId(0); |
|
66 |
|
67 TGlxMediaId id(iPathId); |
|
68 TBool requestAttributes = ETrue; |
|
69 TInt index = iBackMediaList->Index(idSpaceId, id); |
|
70 |
|
71 if ( index != KErrNotFound ) |
|
72 { |
|
73 const TGlxMedia& item = iBackMediaList->Item(index); |
|
74 const CGlxMedia* media = item.Properties(); |
|
75 |
|
76 // get the Title from the attribute if it is already present |
|
77 if (media && media->IsSupported(KMPXMediaGeneralTitle) |
|
78 && index != KErrNotFound) |
|
79 { |
|
80 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
81 // notify the observer |
|
82 iObserver.HandleTitleAvailableL(title); |
|
83 requestAttributes = EFalse; |
|
84 } |
|
85 } |
|
86 |
|
87 if ( requestAttributes ) |
|
88 { |
|
89 // Otherwise add a context setting range to cover all items |
|
90 iContext = CGlxDefaultAttributeContext::NewL(); |
|
91 iContext->SetRangeOffsets(10000,10000); |
|
92 iContext->AddAttributeL(KMPXMediaGeneralTitle); |
|
93 // Add the context at a high priority |
|
94 iBackMediaList->AddContextL( iContext, |
|
95 KGlxFetchContextPriorityTitleFetcher ); |
|
96 // Set self as observer |
|
97 iBackMediaList->AddMediaListObserverL(this); |
|
98 } |
|
99 } |
|
100 |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Two-phased constructor. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CGlxTitleFetcher* CGlxTitleFetcher::NewL(MGlxTitleFetcherObserver& aObserver, |
|
107 CMPXCollectionPath* aPath) |
|
108 { |
|
109 CGlxTitleFetcher* self = new (ELeave) CGlxTitleFetcher(aObserver, aPath); |
|
110 CleanupStack::PushL(self); |
|
111 self->ConstructL(); |
|
112 CleanupStack::Pop(self); |
|
113 return self; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Destructor |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CGlxTitleFetcher::~CGlxTitleFetcher() |
|
121 { |
|
122 TRACER("CGlxTitleFetcher::~CGlxTitleFetcher ()"); |
|
123 |
|
124 if(iBackMediaList) |
|
125 { |
|
126 if(iContext) |
|
127 { |
|
128 iBackMediaList->RemoveContext(iContext); |
|
129 delete iContext; |
|
130 } |
|
131 iBackMediaList->RemoveMediaListObserver(this); |
|
132 iBackMediaList->Close(); |
|
133 } |
|
134 |
|
135 } |
|
136 // --------------------------------------------------------------------------- |
|
137 // CGlxTitleFetcher::HandleItemAddedL |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CGlxTitleFetcher::HandleItemAddedL(TInt aStartIndex, TInt aEndIndex, |
|
141 MGlxMediaList* aList) |
|
142 { |
|
143 TRACER("CGlxTitleFetcher::HandleItemAddedL ()"); |
|
144 if(aList == iBackMediaList) |
|
145 { |
|
146 for(TInt index = aStartIndex;index <= aEndIndex;index++) |
|
147 // Is it the item (path) that we want |
|
148 { |
|
149 if(aList->Item(index).Id().Value() == (TUint32)iPathId) |
|
150 { |
|
151 const TGlxMedia& item = aList->Item(index); |
|
152 const CGlxMedia* media = item.Properties(); |
|
153 // get the Title from the attribute |
|
154 if (media && media->IsSupported(KMPXMediaGeneralTitle)) |
|
155 { |
|
156 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
157 // notify the observer |
|
158 iObserver.HandleTitleAvailableL(title); |
|
159 iBackMediaList->RemoveContext(iContext); |
|
160 delete iContext; |
|
161 iContext = NULL; |
|
162 } |
|
163 } |
|
164 } |
|
165 } |
|
166 } |
|
167 // --------------------------------------------------------------------------- |
|
168 // CGlxTitleFetcher::HandleAttributesAvailableL |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CGlxTitleFetcher::HandleAttributesAvailableL(TInt aItemIndex, |
|
172 const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* aList) |
|
173 { |
|
174 TRACER("CGlxTitleFetcher::HandleAttributesAvailableL ()"); |
|
175 // Is it the list that we want |
|
176 if(aList == iBackMediaList) |
|
177 { |
|
178 // Is it the item (path) that we want |
|
179 if(aList->Item(aItemIndex).Id().Value() == (TUint32)iPathId) |
|
180 { |
|
181 const TGlxMedia& item = aList->Item(aItemIndex); |
|
182 const CGlxMedia* media = item.Properties(); |
|
183 // get the Title from the attribute |
|
184 if (media && media->IsSupported(KMPXMediaGeneralTitle)) |
|
185 { |
|
186 const TDesC& title = media->ValueText(KMPXMediaGeneralTitle); |
|
187 // notify the observer |
|
188 iObserver.HandleTitleAvailableL(title); |
|
189 iBackMediaList->RemoveContext(iContext); |
|
190 delete iContext; |
|
191 iContext = NULL; |
|
192 |
|
193 } |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 // End of File |