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