author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:32:09 +0300 | |
branch | RCL_3 |
changeset 75 | 01504893d9cb |
parent 60 | 5b3385a43d68 |
permissions | -rw-r--r-- |
60 | 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: Rename command handler |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
#include "glxcommandhandlerrename.h" |
|
22 |
||
23 |
#include <bautils.h> |
|
24 |
#include <data_caging_path_literals.hrh> |
|
25 |
#include <StringLoader.h> |
|
26 |
||
27 |
#include <glxuiutilities.rsg> |
|
28 |
#include <mglxmedialist.h> |
|
29 |
#include <glxuistd.h> |
|
30 |
#include <glxcommandhandlers.hrh> |
|
31 |
#include <glxuiutility.h> |
|
32 |
#include <glxtextentrypopup.h> |
|
33 |
#include <glxattributeretriever.h> |
|
34 |
#include <glxattributecontext.h> |
|
35 |
#include <glxfetchcontextremover.h> |
|
36 |
#include <glxresourceutilities.h> // for CGlxResourceUtilities |
|
37 |
#include <glxgeneraluiutilities.h> |
|
38 |
#include <glxicons.mbg> |
|
39 |
#include <glxtracer.h> |
|
40 |
#include <glxlog.h> |
|
41 |
||
42 |
#include "glxcommandfactory.h" |
|
43 |
||
75
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
44 |
namespace |
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
45 |
{ |
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
46 |
const TInt KNameMaxLength = 128; |
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
47 |
} |
60 | 48 |
|
49 |
// --------------------------------------------------------------------------- |
|
50 |
// Two-phased constructor. |
|
51 |
// --------------------------------------------------------------------------- |
|
52 |
// |
|
53 |
EXPORT_C CGlxCommandHandlerRename* CGlxCommandHandlerRename::NewL( |
|
54 |
MGlxMediaListProvider* aMediaListProvider, TBool aHasToolbarItem, |
|
55 |
const TDesC& aFileName) |
|
56 |
{ |
|
57 |
CGlxCommandHandlerRename* self = new (ELeave) CGlxCommandHandlerRename( |
|
58 |
aMediaListProvider, aHasToolbarItem); |
|
59 |
CleanupStack::PushL(self); |
|
60 |
self->ConstructL(aFileName); |
|
61 |
CleanupStack::Pop(self); |
|
62 |
return self; |
|
63 |
} |
|
64 |
||
65 |
// --------------------------------------------------------------------------- |
|
66 |
// C++ default constructor can NOT contain any code, that |
|
67 |
// might leave. |
|
68 |
// --------------------------------------------------------------------------- |
|
69 |
// |
|
70 |
CGlxCommandHandlerRename::CGlxCommandHandlerRename( MGlxMediaListProvider* |
|
71 |
aMediaListProvider, TBool aHasToolbarItem ) |
|
72 |
: CGlxMpxCommandCommandHandler( aMediaListProvider, aHasToolbarItem ) |
|
73 |
{ |
|
74 |
// Do nothing |
|
75 |
} |
|
76 |
||
77 |
||
78 |
// --------------------------------------------------------------------------- |
|
79 |
// Symbian 2nd phase constructor can leave. |
|
80 |
// --------------------------------------------------------------------------- |
|
81 |
// |
|
82 |
void CGlxCommandHandlerRename::ConstructL(const TDesC& aFileName) |
|
83 |
{ |
|
75
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
84 |
iRenameText = HBufC::NewL(KNameMaxLength); |
60 | 85 |
|
86 |
iResourceOffset = CCoeEnv::Static()->AddResourceFileL(aFileName); |
|
87 |
||
88 |
// Add supported command |
|
89 |
TCommandInfo info(EGlxCmdRename); |
|
90 |
// This setup disables the command if a static item is focused, |
|
91 |
// if the view is empty or if more than one item is selected. |
|
92 |
info.iMinSelectionLength = 1; |
|
93 |
info.iMaxSelectionLength = 1; |
|
94 |
// Filter out system items |
|
95 |
info.iDisallowSystemItems = ETrue; |
|
96 |
// Allow animated GIFs to be renamed |
|
97 |
info.iStopAnimationForExecution = ETrue; |
|
98 |
||
99 |
AddCommandL(info); |
|
100 |
||
101 |
iErrorCallback = new (ELeave) CAsyncCallBack(TCallBack(HandleErrorL, this), |
|
102 |
CActive::EPriorityStandard); |
|
103 |
} |
|
104 |
||
105 |
// --------------------------------------------------------------------------- |
|
106 |
// Destructor |
|
107 |
// --------------------------------------------------------------------------- |
|
108 |
// |
|
109 |
EXPORT_C CGlxCommandHandlerRename::~CGlxCommandHandlerRename() |
|
110 |
{ |
|
111 |
delete iRenameText; |
|
112 |
||
113 |
iErrorCallback->Cancel(); |
|
114 |
delete iErrorCallback; |
|
115 |
||
116 |
if ( iResourceOffset ) |
|
117 |
{ |
|
118 |
CCoeEnv::Static()->DeleteResourceFile( iResourceOffset ); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
// --------------------------------------------------------------------------- |
|
123 |
// Create a rename command |
|
124 |
// --------------------------------------------------------------------------- |
|
125 |
// |
|
126 |
CMPXCommand* CGlxCommandHandlerRename::CreateCommandL(TInt /*aCommandId*/, |
|
127 |
MGlxMediaList& aMediaList, TBool& /*aConsume*/) const |
|
128 |
{ |
|
129 |
TRACER( "CGlxCommandHandlerRename::CreateCommandL" ); |
|
130 |
||
131 |
// Return value |
|
132 |
CMPXCommand* command = NULL; |
|
133 |
||
134 |
// Prompt the user for the new name |
|
135 |
// |
|
136 |
// Show popup with the item's current title |
|
137 |
TPtr textPtr = iRenameText->Des(); |
|
138 |
GetTitleL( textPtr, aMediaList ); |
|
139 |
// store the current name. |
|
75
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
140 |
TBuf<KNameMaxLength> currentName; |
60 | 141 |
currentName.Copy(textPtr); |
142 |
||
143 |
// Load the title for the popup |
|
144 |
HBufC* title = StringLoader::LoadLC( R_GLX_POPUP_RENAME_TITLE ); |
|
145 |
CGlxTextEntryPopup* popup = CGlxTextEntryPopup::NewL( *title, |
|
146 |
textPtr ); |
|
75
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
147 |
|
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
148 |
|
01504893d9cb
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
60
diff
changeset
|
149 |
|
60 | 150 |
if ( popup->ExecuteLD() == EEikBidOk && currentName != *iRenameText) |
151 |
{ |
|
152 |
// Text entry was successful |
|
153 |
// There can be no selection when renaming, so assume that path contains focused item |
|
154 |
CMPXCollectionPath* path = aMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection ); |
|
155 |
// Create the rename command with the relevant text |
|
156 |
command = TGlxCommandFactory::RenameCommandLC( *iRenameText, *path ); |
|
157 |
CleanupStack::Pop( command ); |
|
158 |
CleanupStack::PopAndDestroy( path) ; |
|
159 |
} |
|
160 |
||
161 |
CleanupStack::PopAndDestroy( title ); |
|
162 |
||
163 |
return command; |
|
164 |
} |
|
165 |
||
166 |
// ----------------------------------------------------------------------------- |
|
167 |
// Handle an error |
|
168 |
// ----------------------------------------------------------------------------- |
|
169 |
// |
|
170 |
void CGlxCommandHandlerRename::HandleErrorL(TInt aErrorCode) |
|
171 |
{ |
|
172 |
TRACER( "CGlxCommandHandlerRename::HandleErrorL" ); |
|
173 |
||
174 |
// Callback is required because the code to handle the error is blocking |
|
175 |
// There is only ever one command issued, store the error to handle later |
|
176 |
iError = aErrorCode; |
|
177 |
||
178 |
__ASSERT_DEBUG( !iErrorCallback->IsActive(), Panic( EGlxPanicLogicError ) ); |
|
179 |
iErrorCallback->CallBack(); |
|
180 |
} |
|
181 |
||
182 |
// ----------------------------------------------------------------------------- |
|
183 |
// Callback to handle an error |
|
184 |
// ----------------------------------------------------------------------------- |
|
185 |
// |
|
186 |
TBool CGlxCommandHandlerRename::HandleErrorL(TAny* aPtr) |
|
187 |
{ |
|
188 |
TRACER( "CGlxCommandHandlerRename::HandleErrorL" ); |
|
189 |
||
190 |
static_cast<CGlxCommandHandlerRename*>( aPtr )->HandleErrorL(); |
|
191 |
return 0; |
|
192 |
} |
|
193 |
||
194 |
// ----------------------------------------------------------------------------- |
|
195 |
// Handle an error - e.g. if user inputs a name that already exists. |
|
196 |
// ----------------------------------------------------------------------------- |
|
197 |
// |
|
198 |
void CGlxCommandHandlerRename::HandleErrorL() |
|
199 |
{ |
|
200 |
TRACER( "CGlxCommandHandlerRename::HandleErrorL" ); |
|
201 |
||
202 |
// If name already exists, Show rename query and allow the user to try again |
|
203 |
// See EMYP-7A2E6J |
|
204 |
if ( iError == KErrAlreadyExists ) |
|
205 |
{ |
|
206 |
HBufC* text = StringLoader::LoadLC( R_GLX_RENAME_QUERY, *iRenameText ); |
|
207 |
||
208 |
TBool confirmed = GlxGeneralUiUtilities::ConfirmQueryL( R_GLX_QUERY_OK_CANCEL, *text ); |
|
209 |
if ( confirmed ) |
|
210 |
{ |
|
211 |
// Let user have another try at entering the new name |
|
212 |
ExecuteL( EGlxCmdRename ); |
|
213 |
} |
|
214 |
||
215 |
CleanupStack::PopAndDestroy( text ); |
|
216 |
} |
|
217 |
else |
|
218 |
{ |
|
219 |
// Call the base class' implementation |
|
220 |
CGlxMpxCommandCommandHandler::HandleErrorL( iError ); |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
// ----------------------------------------------------------------------------- |
|
225 |
// Retrieve the current item's title string |
|
226 |
// ----------------------------------------------------------------------------- |
|
227 |
// |
|
228 |
void CGlxCommandHandlerRename::GetTitleL( TDes& aTitle, |
|
229 |
MGlxMediaList& aList ) const |
|
230 |
{ |
|
231 |
TRACER( "CGlxCommandHandlerRename::GetTitleL" ); |
|
232 |
||
233 |
// Set the title to a blank name by default |
|
234 |
aTitle = KNullDesC; |
|
235 |
||
236 |
// Create an iterator to retrieve the relevant attribute |
|
237 |
TGlxSelectionIterator iterator; |
|
238 |
// only want the title of one item |
|
239 |
iterator.SetRange( 1 ); |
|
240 |
CGlxAttributeContext* context = new( ELeave ) |
|
241 |
CGlxAttributeContext( &iterator ); |
|
242 |
CleanupStack::PushL( context ); |
|
243 |
||
244 |
// Want to read the title attribute |
|
245 |
// Configure the context |
|
246 |
context->AddAttributeL( KMPXMediaGeneralTitle ); |
|
247 |
||
248 |
// Add the context to the media list |
|
249 |
aList.AddContextL( context, KGlxFetchContextPriorityBlocking ); |
|
250 |
||
251 |
// TGlxContextRemover will remove the context when it goes out of scope |
|
252 |
// Used here to avoid a trap and still have safe cleanup |
|
253 |
TGlxFetchContextRemover contextRemover( context, aList ); |
|
254 |
// put to cleanupstack as cleanupstack is emptied before stack objects |
|
255 |
// are deleted |
|
256 |
CleanupClosePushL( contextRemover ); |
|
257 |
// Yuck - a leave and a return code |
|
258 |
// EFalse => don't show a progress dialog |
|
259 |
TInt err = GlxAttributeRetriever::RetrieveL( *context, aList, EFalse ); |
|
260 |
// Using a distinct error value as "LeaveIfError( FuncL() );" looks bad |
|
261 |
User::LeaveIfError( err ); |
|
262 |
// context off the list |
|
263 |
CleanupStack::PopAndDestroy( &contextRemover ); |
|
264 |
||
265 |
// Now get the title of the relevant item: if *an* item is selected use its |
|
266 |
// title, otherwise use the item with focus |
|
267 |
// Get the index of the item to rename |
|
268 |
TInt index = KErrNotFound; |
|
269 |
// first see if there's a selected item... |
|
270 |
if ( aList.SelectionCount() == 1 ) |
|
271 |
{ |
|
272 |
// Find the index of the selected item |
|
273 |
index = aList.Count(); |
|
274 |
do |
|
275 |
{ |
|
276 |
--index; |
|
277 |
} |
|
278 |
while ( !aList.IsSelected( index ) && index > 0 ); |
|
279 |
} |
|
280 |
else |
|
281 |
{ |
|
282 |
// Use the index of the item with focus |
|
283 |
index = aList.FocusIndex(); |
|
284 |
} |
|
285 |
||
286 |
if ( index != KErrNotFound ) |
|
287 |
{ |
|
288 |
// use iterator to get the right item |
|
289 |
iterator.SetToFirst( &aList ); |
|
290 |
const CGlxMedia* media = aList.Item( iterator++ ).Properties(); |
|
291 |
if( media ) |
|
292 |
{ |
|
293 |
// found the item's media properties, extract the title |
|
294 |
aTitle = media->ValueText( KMPXMediaGeneralTitle ) ; |
|
295 |
} |
|
296 |
} |
|
297 |
CleanupStack::PopAndDestroy( context ); |
|
298 |
} |
|
299 |
||
300 |
//----------------------------------------------------------------------------- |
|
301 |
// PopulateToolbar |
|
302 |
//----------------------------------------------------------------------------- |
|
303 |
// |
|
304 |
void CGlxCommandHandlerRename::PopulateToolbarL() |
|
305 |
{ |
|
306 |
TRACER( "CGlxCommandHandlerRename::PopulateToolbar" ); |
|
307 |
} |
|
308 |
||
309 |
//End of file |