53
|
1 |
/*
|
|
2 |
* Copyright (c) 2006 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 dialog for Common UI
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <coeutils.h>
|
|
21 |
#include <eikapp.h>
|
|
22 |
#include <StringLoader.h>
|
|
23 |
#include <aknnotewrappers.h>
|
|
24 |
#include <mpxcollectionuihelper.h>
|
|
25 |
#include <mpxcollectionhelperfactory.h>
|
|
26 |
#include <mpxcommonui.rsg>
|
|
27 |
#include <mpxlog.h>
|
|
28 |
|
|
29 |
#include "mpxcommonuihelper.h"
|
|
30 |
#include "mpxfilenamequerydlg.h"
|
|
31 |
|
|
32 |
// CONSTANTS
|
|
33 |
const TInt KMPXMaxPlaylistPathLen ( 200 );
|
|
34 |
|
|
35 |
_LIT( KBackslash, "\\" );
|
|
36 |
_LIT( KDirectionalChars, "\x202A\x202B\x202C\x202D\x200E\x200F" );
|
|
37 |
|
|
38 |
const TUint16 KIllegalChars[] = {
|
|
39 |
'<', '>', '"', '/', '\\', '|', ':', '*', '?',
|
|
40 |
0xFF02, // Full width quote
|
|
41 |
0xFF0A, // Full width asterisk
|
|
42 |
0xFF0F, // Full width slash
|
|
43 |
0xFF1A, // Full width colon
|
|
44 |
0xFF1C, // Full width left arrow
|
|
45 |
0xFF1E, // Full width right arrow
|
|
46 |
0xFF1F, // Full width question mark
|
|
47 |
0xFF3C, // Full width back slash
|
|
48 |
0xFF5C, // Full width pipe
|
|
49 |
0x201C, // Left quote
|
|
50 |
0x201D, // Right quote
|
|
51 |
0x201F, // Reversed quote
|
|
52 |
0, // Array terminator
|
|
53 |
};
|
|
54 |
|
|
55 |
|
|
56 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
57 |
|
|
58 |
|
|
59 |
// ---------------------------------------------------------------------------
|
|
60 |
// Two-phased constructor.
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
CMPXFileNameQueryDlg* CMPXFileNameQueryDlg::NewL(
|
|
64 |
const TDesC& aOldName,
|
|
65 |
TDes& aNewName,
|
|
66 |
const TDesC& aPath,
|
|
67 |
TMPXGeneralCategory aCategory,
|
|
68 |
CMPXCommonUiHelper* aParent )
|
|
69 |
{
|
|
70 |
MPX_FUNC( "CMPXFileNameQueryDlg::NewL" );
|
|
71 |
CMPXFileNameQueryDlg* self =
|
|
72 |
new( ELeave ) CMPXFileNameQueryDlg( aNewName, aCategory, aParent );
|
|
73 |
|
|
74 |
CleanupStack::PushL( self );
|
|
75 |
self->ConstructL( aOldName, aPath );
|
|
76 |
CleanupStack::Pop( self );
|
|
77 |
|
|
78 |
return self;
|
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
// C++ default constructor can NOT contain any code, that
|
|
83 |
// might leave.
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
CMPXFileNameQueryDlg::CMPXFileNameQueryDlg(
|
|
87 |
TDes& aNewName,
|
|
88 |
TMPXGeneralCategory aCategory,
|
|
89 |
CMPXCommonUiHelper* aParent ) :
|
|
90 |
CAknTextQueryDialog( aNewName ),
|
|
91 |
iParent( aParent ),
|
|
92 |
iCategory( aCategory )
|
|
93 |
{
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
// Symbian 2nd phase constructor can leave.
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CMPXFileNameQueryDlg::ConstructL(
|
|
101 |
const TDesC& aOldName, const TDesC& aPath )
|
|
102 |
{
|
|
103 |
MPX_FUNC( "CMPXFileNameQueryDlg::ConstructL" );
|
|
104 |
TParsePtrC name( aOldName );
|
|
105 |
iOldName = aOldName.AllocL();
|
|
106 |
iPath = aPath.AllocL();
|
|
107 |
// Strip any directionality markers to get pure name
|
|
108 |
TPtr ptr( iOldName->Des() );
|
|
109 |
AknTextUtils::StripCharacters( ptr, KDirectionalChars );
|
|
110 |
TInt extLength( 0 );
|
|
111 |
if ( iCategory == EMPXPlaylist )
|
|
112 |
{
|
|
113 |
Text().Copy( name.NameAndExt() );
|
|
114 |
}
|
|
115 |
else
|
|
116 |
{
|
|
117 |
Text().Copy( name.Name() );
|
|
118 |
if ( name.ExtPresent() )
|
|
119 |
{
|
|
120 |
extLength = name.Ext().Length();
|
|
121 |
}
|
|
122 |
}
|
|
123 |
TInt maxLength( KMPXMaxPlaylistPathLen - aPath.Length() - extLength );
|
|
124 |
MPX_DEBUG2( "CMPXFileNameQueryDlg::ConstructL setting max length = %d", maxLength );
|
|
125 |
SetMaxLength( maxLength );
|
|
126 |
iCollectionUiHelper = CMPXCollectionHelperFactory::NewCollectionUiHelperL();
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// Destructor
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
CMPXFileNameQueryDlg::~CMPXFileNameQueryDlg()
|
|
134 |
{
|
|
135 |
if ( iCollectionUiHelper )
|
|
136 |
{
|
|
137 |
iCollectionUiHelper->Close();
|
|
138 |
}
|
|
139 |
delete iOldName;
|
|
140 |
delete iPath;
|
|
141 |
}
|
|
142 |
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
// CFileManagerFileNameQueryDlg::OkToExitL
|
|
145 |
// ---------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
TBool CMPXFileNameQueryDlg::OkToExitL( TInt aButtonId )
|
|
148 |
{
|
|
149 |
MPX_FUNC( "CMPXFileNameQueryDlg::OkToExitL" );
|
|
150 |
TBool result( CAknTextQueryDialog::OkToExitL( aButtonId ) );
|
|
151 |
|
|
152 |
HBufC* userText = Text().AllocLC();
|
|
153 |
TPtr ptrUserText( userText->Des() );
|
|
154 |
|
|
155 |
// Strip any directionality markers to get pure name
|
|
156 |
AknTextUtils::StripCharacters( ptrUserText, KDirectionalChars );
|
|
157 |
|
|
158 |
TParsePtrC currentPath( *iPath );
|
|
159 |
// Check file name
|
|
160 |
TBool isValidName = IsValidName( currentPath.DriveAndPath(), *userText, EFalse );
|
|
161 |
if( !isValidName )
|
|
162 |
{
|
|
163 |
if( IllegalChars( *userText ) )
|
|
164 |
{
|
|
165 |
iParent->DisplayInfoNoteL(
|
|
166 |
R_MPX_QTN_FLDR_ILLEGAL_CHARACTERS );
|
|
167 |
}
|
|
168 |
else
|
|
169 |
{
|
|
170 |
iParent->DisplayInfoNoteL(
|
|
171 |
R_MPX_QTN_FLDR_BAD_FILE_NAME );
|
|
172 |
}
|
|
173 |
CAknQueryControl* queryControl = QueryControl();
|
|
174 |
if ( queryControl )
|
|
175 |
{
|
|
176 |
CEikEdwin* edwin = static_cast< CEikEdwin* >(
|
|
177 |
queryControl->ControlByLayoutOrNull( EDataLayout ) );
|
|
178 |
if (edwin)
|
|
179 |
{
|
|
180 |
edwin->SetSelectionL( edwin->TextLength(), 0 );
|
|
181 |
}
|
|
182 |
}
|
|
183 |
CleanupStack::PopAndDestroy( userText );
|
|
184 |
return EFalse;
|
|
185 |
}
|
|
186 |
|
|
187 |
// if some other entry found with same name
|
|
188 |
// not ok except if name same as original
|
|
189 |
if ( iCategory != EMPXPlaylist )
|
|
190 |
{
|
|
191 |
if ( iCollectionUiHelper->TitleExistsL( iCategory, *userText ) )
|
|
192 |
{
|
|
193 |
TBool overWrite( EFalse );
|
|
194 |
HBufC* text = StringLoader::LoadLC( R_MPX_QTN_FLDR_OVERWRITE_QUERY, Text() );
|
|
195 |
CAknQueryDialog* dlg = CAknQueryDialog::NewL();
|
|
196 |
overWrite = dlg->ExecuteLD( R_MPX_CONFIRM_QUERY_WITH_YES_NO, *text );
|
|
197 |
CleanupStack::PopAndDestroy( text );
|
|
198 |
if( !overWrite )
|
|
199 |
{
|
|
200 |
CAknQueryControl* queryControl = QueryControl();
|
|
201 |
if (queryControl)
|
|
202 |
{
|
|
203 |
CEikEdwin* edwin = static_cast< CEikEdwin* >(
|
|
204 |
queryControl->ControlByLayoutOrNull( EDataLayout ) );
|
|
205 |
|
|
206 |
HBufC* newTitle = iParent->GenerateTitleL( iCategory, *userText );
|
|
207 |
CleanupStack::PushL(newTitle);
|
|
208 |
|
|
209 |
if ( edwin )
|
|
210 |
{
|
|
211 |
edwin->SetTextL( newTitle );
|
|
212 |
edwin->SetSelectionL( edwin->TextLength(), 0 );
|
|
213 |
}
|
|
214 |
CleanupStack::PopAndDestroy(newTitle);
|
|
215 |
}
|
|
216 |
result = EFalse;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
CleanupStack::PopAndDestroy( userText );
|
|
221 |
if ( result && iCategory != EMPXPlaylist )
|
|
222 |
{
|
|
223 |
// playlist has no extension, don't need to do this
|
|
224 |
TParsePtrC oldName( *iOldName );
|
|
225 |
iDataText.Append( oldName.Ext() );
|
|
226 |
}
|
|
227 |
return result;
|
|
228 |
}
|
|
229 |
|
|
230 |
// -----------------------------------------------------------------------------
|
|
231 |
// CMPXFileNameQueryDlg::OfferKeyEventL
|
|
232 |
//
|
|
233 |
// -----------------------------------------------------------------------------
|
|
234 |
//
|
|
235 |
TKeyResponse CMPXFileNameQueryDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
|
|
236 |
{
|
|
237 |
TKeyResponse response = EKeyWasNotConsumed;
|
|
238 |
// consume 'enter' so it won't acknowledge the dialog
|
|
239 |
TBool vkbOpen = EFalse;
|
|
240 |
CAknQueryControl* queryControl = QueryControl();
|
|
241 |
if ( queryControl )
|
|
242 |
{
|
|
243 |
CEikEdwin* edwin = static_cast< CEikEdwin* >(
|
|
244 |
queryControl->ControlByLayoutOrNull( EDataLayout ) );
|
|
245 |
if ( edwin )
|
|
246 |
{
|
|
247 |
if ( edwin->AknEdwinFlags() & EAknEditorFlagTouchInputModeOpened )
|
|
248 |
{
|
|
249 |
// virtual keyboard is active.
|
|
250 |
vkbOpen = ETrue;
|
|
251 |
}
|
|
252 |
}
|
|
253 |
}
|
|
254 |
|
|
255 |
if ( vkbOpen && aType == EEventKey && aKeyEvent.iCode == EKeyEnter )
|
|
256 |
{
|
|
257 |
response = EKeyWasConsumed;
|
|
258 |
}
|
|
259 |
else
|
|
260 |
{
|
|
261 |
response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType);
|
|
262 |
}
|
|
263 |
return response;
|
|
264 |
}
|
|
265 |
|
|
266 |
// -----------------------------------------------------------------------------
|
|
267 |
// CMPXFileNameQueryDlg::IsValidName
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
//
|
|
270 |
TBool CMPXFileNameQueryDlg::IsValidName(
|
|
271 |
const TDesC& aDriveAndPath, const TDesC& aName, TBool aIsFolder ) const
|
|
272 |
{
|
|
273 |
MPX_FUNC( "CMPXFileNameQueryDlg::IsValidName" );
|
|
274 |
// Check name for bad chars
|
|
275 |
const TUint16 KMinAllowedChar = 0x0020;
|
|
276 |
const TUint16 KParagraphSeparator = 0x2029;
|
|
277 |
const TUint16 KDot = '.';
|
|
278 |
TInt nameLen( aName.Length() );
|
|
279 |
if ( !nameLen )
|
|
280 |
{
|
|
281 |
return EFalse;
|
|
282 |
}
|
|
283 |
for ( TInt i( 0 ); i < nameLen; i++ )
|
|
284 |
{
|
|
285 |
TUint16 ch( aName[ i ] );
|
|
286 |
if ( ch < KMinAllowedChar || ch == KParagraphSeparator )
|
|
287 |
{
|
|
288 |
return EFalse;
|
|
289 |
}
|
|
290 |
}
|
|
291 |
// File system ignores totally dot in the end of name, so
|
|
292 |
// we set here as not valid name, so that user gets correctly informed
|
|
293 |
if ( aName[ nameLen - 1 ] == KDot || IllegalChars( aName ) )
|
|
294 |
{
|
|
295 |
return EFalse;
|
|
296 |
}
|
|
297 |
// Get full path length
|
|
298 |
TPtrC pathPtr( aDriveAndPath );
|
|
299 |
TInt pathLen( pathPtr.Length() );
|
|
300 |
if ( !pathLen )
|
|
301 |
{
|
|
302 |
return EFalse;
|
|
303 |
}
|
|
304 |
TInt fullPathLen( pathLen );
|
|
305 |
if ( pathPtr[ pathLen - 1 ] != KBackslash()[ 0 ] )
|
|
306 |
{
|
|
307 |
++fullPathLen; // Add backslash before name
|
|
308 |
}
|
|
309 |
fullPathLen += nameLen;
|
|
310 |
if ( aIsFolder )
|
|
311 |
{
|
|
312 |
++fullPathLen; // Add folder final backslash
|
|
313 |
}
|
|
314 |
|
|
315 |
TBool ret( EFalse );
|
|
316 |
if ( fullPathLen <= KMaxFileName )
|
|
317 |
{
|
|
318 |
// Check full path
|
|
319 |
HBufC* fullPath = HBufC::New( KMaxFileName );
|
|
320 |
if ( fullPath )
|
|
321 |
{
|
|
322 |
TPtr ptr( fullPath->Des() );
|
|
323 |
ptr.Copy( pathPtr );
|
|
324 |
if ( pathPtr[ pathLen - 1 ] != KBackslash()[ 0 ] )
|
|
325 |
{
|
|
326 |
ptr.Append( KBackslash ); // Add backslash before name
|
|
327 |
}
|
|
328 |
ptr.Append( aName );
|
|
329 |
RFs fs;
|
|
330 |
TInt connectError = fs.Connect();
|
|
331 |
if ( connectError == KErrNone )
|
|
332 |
{
|
|
333 |
ret = fs.IsValidName( ptr );
|
|
334 |
fs.Close();
|
|
335 |
}
|
|
336 |
delete fullPath;
|
|
337 |
}
|
|
338 |
}
|
|
339 |
return ret;
|
|
340 |
}
|
|
341 |
|
|
342 |
// -----------------------------------------------------------------------------
|
|
343 |
// CMPXFileNameQueryDlg::IllegalChars
|
|
344 |
// -----------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
TBool CMPXFileNameQueryDlg::IllegalChars( const TDesC& aName ) const
|
|
347 |
{
|
|
348 |
MPX_FUNC( "CMPXFileNameQueryDlg::IllegalChars" );
|
|
349 |
for ( TInt i( 0 ); KIllegalChars[ i ]; i++ )
|
|
350 |
{
|
|
351 |
if ( aName.Locate( KIllegalChars[ i ] ) != KErrNotFound )
|
|
352 |
{
|
|
353 |
return ETrue;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
return EFalse;
|
|
357 |
}
|
|
358 |
|
|
359 |
// End of File
|