|
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: Add to container command handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 * @internal reviewed 05/06/2007 by Dave Schofield |
|
23 */ |
|
24 |
|
25 #include "glxcommandhandleraddtocontainer.h" |
|
26 |
|
27 #include <AknUtils.h> |
|
28 #include <bautils.h> |
|
29 #include <data_caging_path_literals.hrh> |
|
30 #include <eikmenup.h> |
|
31 #include <glxcollectionpluginalbums.hrh> |
|
32 #include <glxcollectionplugintags.hrh> |
|
33 #include <glxcommandfactory.h> |
|
34 #include <glxcommandhandlers.hrh> |
|
35 #include <glxfilterfactory.h> |
|
36 #include <glxuiutility.h> |
|
37 #include <glxuistd.h> |
|
38 #include <glxresourceutilities.h> // for CGlxResourceUtilities |
|
39 #include <glxuiutilities.rsg> |
|
40 #include <mglxmedialist.h> |
|
41 |
|
42 #include <mpxcollectioncommanddefs.h> |
|
43 #include <mpxcollectionpath.h> |
|
44 #include <mpxcommandgeneraldefs.h> |
|
45 #include <mpxmediaarray.h> |
|
46 #include <mpxmediacontainerdefs.h> |
|
47 #include <StringLoader.h> |
|
48 |
|
49 #include "glxmediaselectionpopup.h" |
|
50 #include <glxicons.mbg> |
|
51 |
|
52 TInt CGlxCommandHandlerAddToContainer::iSelectionCount = 0; |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Return add to album command handler |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C CGlxCommandHandlerAddToContainer* |
|
59 CGlxCommandHandlerAddToContainer::NewAddToAlbumCommandHandlerL( |
|
60 MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) |
|
61 { |
|
62 return CGlxCommandHandlerAddToContainer::NewL (aMediaListProvider, |
|
63 EGlxCmdAddToAlbum, aHasToolbarItem); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // Return add (to) tags command handler |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CGlxCommandHandlerAddToContainer* |
|
71 CGlxCommandHandlerAddToContainer::NewAddToTagCommandHandlerL( |
|
72 MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) |
|
73 { |
|
74 return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider, |
|
75 EGlxCmdAddTag, aHasToolbarItem); |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // Return add (to) Favourites command handler |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CGlxCommandHandlerAddToContainer* |
|
83 CGlxCommandHandlerAddToContainer::NewAddToFavCommandHandlerL( |
|
84 MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) |
|
85 { |
|
86 return CGlxCommandHandlerAddToContainer::NewL(aMediaListProvider, |
|
87 EGlxCmdAddToFavourites, aHasToolbarItem); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // Two-phased constructor. |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C CGlxCommandHandlerAddToContainer* CGlxCommandHandlerAddToContainer::NewL( |
|
95 MGlxMediaListProvider* aMediaListProvider, TInt aCommandId, TBool aHasToolbarItem) |
|
96 { |
|
97 CGlxCommandHandlerAddToContainer* self = |
|
98 new ( ELeave ) CGlxCommandHandlerAddToContainer( aMediaListProvider, aHasToolbarItem ); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL( aCommandId ); |
|
101 CleanupStack::Pop( self ); |
|
102 return self; |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // Constructor |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 CGlxCommandHandlerAddToContainer::CGlxCommandHandlerAddToContainer( |
|
110 MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem) |
|
111 : CGlxMpxCommandCommandHandler( aMediaListProvider, aHasToolbarItem ) |
|
112 { |
|
113 // Do nothing |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // Symbian 2nd phase constructor can leave. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 void CGlxCommandHandlerAddToContainer::ConstructL(TInt aCommandId) |
|
121 { |
|
122 // Load resource |
|
123 TParse parse; |
|
124 parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL); |
|
125 TFileName resourceFile; |
|
126 resourceFile.Append(parse.FullName()); |
|
127 CGlxResourceUtilities::GetResourceFilenameL(resourceFile); |
|
128 iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile); |
|
129 // Reset the Flag inorder to allow for a new selection pop-up to be created. |
|
130 iIsProcessOngoing = EFalse; |
|
131 // Add supported command |
|
132 TCommandInfo info(aCommandId); |
|
133 |
|
134 // Filter out static items - user must have selected at least one item to |
|
135 // enable the command handler |
|
136 const TInt KGlxCommandHandlerMinSelectionAllowSingle = 1; |
|
137 info.iMinSelectionLength = KGlxCommandHandlerMinSelectionAllowSingle; |
|
138 |
|
139 AddCommandL(info); |
|
140 iCommandId = aCommandId; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Destructor |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C CGlxCommandHandlerAddToContainer::~CGlxCommandHandlerAddToContainer() |
|
148 { |
|
149 if ( iResourceOffset ) |
|
150 { |
|
151 CCoeEnv::Static()->DeleteResourceFile(iResourceOffset); |
|
152 } |
|
153 // Reset the Flag inorder to allow for a new selection pop-up to be created. |
|
154 iIsProcessOngoing = EFalse; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Create an add to container command |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 CMPXCommand* CGlxCommandHandlerAddToContainer::CreateCommandL(TInt aCommandId, |
|
162 MGlxMediaList& aMediaList, TBool& /*aConsume*/) const |
|
163 { |
|
164 // Ignore the current command in case the previous command has still not been completed |
|
165 if(iIsProcessOngoing) |
|
166 { |
|
167 return NULL; |
|
168 } |
|
169 iSelectionCount = 0; |
|
170 // Set the Flag inorder to block any new subsequent selection pop-ups from getting created. |
|
171 iIsProcessOngoing = ETrue; |
|
172 CMPXCollectionPath* targetCollection = CMPXCollectionPath::NewL(); |
|
173 CleanupStack::PushL(targetCollection); |
|
174 TBool enableMultipleSelection = EFalse; |
|
175 TBool enablePopup = EFalse; |
|
176 CMPXFilter* filter = NULL; |
|
177 switch(aCommandId) |
|
178 { |
|
179 case EGlxCmdAddToFavourites: |
|
180 { |
|
181 targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid); |
|
182 // The target collection has also to be appeneded with the the relation id. |
|
183 // appending another level into the albums to get favourites and 1 is the relation id of albums |
|
184 targetCollection->AppendL( TMPXItemId(1) ); |
|
185 targetCollection->Set( 0 ); |
|
186 break; |
|
187 } |
|
188 case EGlxCmdAddToAlbum: |
|
189 { |
|
190 enablePopup = ETrue; |
|
191 targetCollection->AppendL(KGlxCollectionPluginAlbumsImplementationUid); |
|
192 filter = TGlxFilterFactory::CreateCameraAlbumExclusionFilterL(); |
|
193 CleanupStack::PushL(filter); |
|
194 break; |
|
195 } |
|
196 case EGlxCmdAddTag: |
|
197 { |
|
198 enableMultipleSelection = ETrue; |
|
199 enablePopup = ETrue; |
|
200 targetCollection->AppendL(KGlxTagCollectionPluginImplementationUid); |
|
201 filter = TGlxFilterFactory::CreateIncludeEmptyContainersFilterL(); |
|
202 CleanupStack::PushL(filter); |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 CMPXCollectionPath* sourceItems = aMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection ); |
|
208 CMPXCommand* command = NULL; |
|
209 if (enablePopup ) |
|
210 { |
|
211 CGlxMediaSelectionPopup* popup = new (ELeave) CGlxMediaSelectionPopup; |
|
212 |
|
213 TBool accepted = EFalse; |
|
214 CMPXCollectionPath* targetContainers = |
|
215 popup->ExecuteLD(*targetCollection, accepted, enableMultipleSelection, ETrue, filter); |
|
216 |
|
217 if (accepted) |
|
218 { |
|
219 // Set the container selection count to give correct completion text |
|
220 TArray<TInt> selection = targetContainers->Selection(); |
|
221 iSelectionCount = selection.Count(); |
|
222 |
|
223 CleanupStack::PushL(targetContainers); |
|
224 command = TGlxCommandFactory::AddToContainerCommandLC( |
|
225 *sourceItems, *targetContainers); |
|
226 CleanupStack::Pop(command); |
|
227 CleanupStack::PopAndDestroy(targetContainers); |
|
228 } |
|
229 else |
|
230 { |
|
231 // Reset the Flag inorder to allow any new selection pop-up to be created. |
|
232 iIsProcessOngoing = EFalse; |
|
233 } |
|
234 } |
|
235 else |
|
236 { |
|
237 command = TGlxCommandFactory::AddToContainerCommandLC( |
|
238 *sourceItems, *targetCollection); |
|
239 CleanupStack::Pop(command); |
|
240 } |
|
241 CleanupStack::PopAndDestroy(sourceItems); |
|
242 if (filter) |
|
243 { |
|
244 CleanupStack::PopAndDestroy(filter); |
|
245 } |
|
246 CleanupStack::PopAndDestroy(targetCollection); |
|
247 return command; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CGlxCommandHandlerAddToContainer::CompletionTextL |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 HBufC* CGlxCommandHandlerAddToContainer::CompletionTextL() const |
|
255 { |
|
256 if (iCommandId == EGlxCmdAddToAlbum) |
|
257 { |
|
258 if (iSelectionCount > 1) |
|
259 { |
|
260 return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_ALBUM); |
|
261 } |
|
262 return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_ALBUM); |
|
263 } |
|
264 else if (iCommandId == EGlxCmdAddTag) |
|
265 { |
|
266 if (iSelectionCount > 1) |
|
267 { |
|
268 return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_MULTI_ITEM_TAG); |
|
269 } |
|
270 return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_CONTAINER_ONE_ITEM_TAG); |
|
271 } |
|
272 else // considered as favourites |
|
273 { |
|
274 return StringLoader::LoadL(R_GLX_COMPLETION_ADD_TO_FAVOURITES); |
|
275 } |
|
276 } |
|
277 |
|
278 // ----------------------------------------------------------------------------- |
|
279 // CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 void CGlxCommandHandlerAddToContainer::DoHandleCommandCompleteL(TAny* /*aSessionId*/, |
|
283 CMPXCommand* /*aCommandResult*/, TInt /*aError*/, MGlxMediaList* /*aList*/) |
|
284 { |
|
285 // Reset the Flag inorder to allow any new selection pop-up to be created. |
|
286 iIsProcessOngoing = EFalse; |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CGlxCommandHandlerAddToContainer::DoActivateL |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CGlxCommandHandlerAddToContainer::DoActivateL(TInt /*aViewId*/) |
|
294 { |
|
295 |
|
296 } |
|
297 |
|
298 void CGlxCommandHandlerAddToContainer::PopulateToolbarL() |
|
299 { |
|
300 |
|
301 } |