|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Dialog for asking file name from user |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <StringLoader.h> |
|
21 #include <aknnotewrappers.h> |
|
22 #include <bautils.h> |
|
23 #include <CFileManagerEngine.h> |
|
24 #include <filemanagerview.rsg> |
|
25 #include "CFileManagerFileNameQueryDlg.h" |
|
26 #include "CFileManagerCommonDefinitions.h" |
|
27 #include "CFileManagerItemProperties.h" |
|
28 #include "FileManagerDlgUtils.h" |
|
29 |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CFileManagerFileNameQueryDlg::NewL |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CFileManagerFileNameQueryDlg* CFileManagerFileNameQueryDlg::NewL( |
|
39 const TDesC& aOldName, |
|
40 TDes& aNewName, |
|
41 CFileManagerEngine& aEngine ) |
|
42 { |
|
43 CFileManagerFileNameQueryDlg* self = |
|
44 new( ELeave ) CFileManagerFileNameQueryDlg( |
|
45 aNewName, aEngine ); |
|
46 |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL( aOldName ); |
|
49 CleanupStack::Pop( self ); |
|
50 |
|
51 return self; |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CFileManagerFileNameQueryDlg::CFileManagerFileNameQueryDlg |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CFileManagerFileNameQueryDlg::CFileManagerFileNameQueryDlg( |
|
61 TDes& aNewName, |
|
62 CFileManagerEngine& aEngine ) : |
|
63 CAknTextQueryDialog( aNewName ), |
|
64 iEngine( aEngine ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CFileManagerFileNameQueryDlg::ConstructL |
|
70 // |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CFileManagerFileNameQueryDlg::ConstructL( const TDesC& aOldName ) |
|
74 { |
|
75 TParsePtrC name( aOldName ); |
|
76 Text().Copy( name.NameAndExt() ); |
|
77 iOldName = aOldName.AllocL(); |
|
78 |
|
79 // Strip any directionality markers to get pure name |
|
80 TPtr ptr( iOldName->Des() ); |
|
81 AknTextUtils::StripCharacters( ptr, KFmgrDirectionalChars ); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CFileManagerFileNameQueryDlg::~CFileManagerFileNameQueryDlg |
|
86 // Destructor |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CFileManagerFileNameQueryDlg::~CFileManagerFileNameQueryDlg() |
|
90 { |
|
91 delete iOldName; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CFileManagerFileNameQueryDlg::DoOkToExitL |
|
96 // |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 TBool CFileManagerFileNameQueryDlg::DoOkToExitL( TInt aButtonId ) |
|
100 { |
|
101 TBool result( CAknTextQueryDialog::OkToExitL( aButtonId ) ); |
|
102 |
|
103 HBufC* userText = Text().AllocLC(); |
|
104 TPtr ptrUserText( userText->Des() ); |
|
105 ptrUserText.TrimRight(); |
|
106 |
|
107 // Strip any directionality markers to get pure name |
|
108 AknTextUtils::StripCharacters( ptrUserText, KFmgrDirectionalChars ); |
|
109 |
|
110 // Check file name |
|
111 TBool isValidName( EFalse ); |
|
112 TParsePtrC oldName( *iOldName ); |
|
113 if ( oldName.PathPresent() ) |
|
114 { |
|
115 isValidName = iEngine.IsValidName( |
|
116 oldName.DriveAndPath(), *userText, EFalse ); |
|
117 } |
|
118 else |
|
119 { |
|
120 isValidName = iEngine.IsValidName( KNullDesC, *userText, EFalse ); |
|
121 } |
|
122 |
|
123 if( !isValidName ) |
|
124 { |
|
125 if( iEngine.IllegalChars( *userText ) ) |
|
126 { |
|
127 FileManagerDlgUtils::ShowInfoNoteL( |
|
128 R_QTN_FLDR_ILLEGAL_CHARACTERS ); |
|
129 } |
|
130 else |
|
131 { |
|
132 FileManagerDlgUtils::ShowInfoNoteL( |
|
133 R_QTN_FLDR_BAD_FILE_NAME ); |
|
134 } |
|
135 CAknQueryControl* queryControl = QueryControl(); |
|
136 if (queryControl) |
|
137 { |
|
138 CEikEdwin* edwin = static_cast< CEikEdwin* >( |
|
139 queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
140 if (edwin) |
|
141 { |
|
142 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
143 } |
|
144 } |
|
145 CleanupStack::PopAndDestroy( userText ); |
|
146 return EFalse; |
|
147 } |
|
148 |
|
149 HBufC* userTextFullPath = HBufC::NewLC( KMaxFileName ); |
|
150 TPtr ptrUserTextFullPath( userTextFullPath->Des() ); |
|
151 |
|
152 ptrUserTextFullPath.Append( oldName.DriveAndPath() ); |
|
153 ptrUserTextFullPath.Append( *userText ); |
|
154 // if some other entry found with same name |
|
155 // not ok except if name same as original |
|
156 if( oldName.NameAndExt().CompareF( *userText ) && |
|
157 ( iEngine.IsNameFoundL( ptrUserTextFullPath ) || |
|
158 BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), ptrUserTextFullPath)) ) |
|
159 { |
|
160 TBool overWrite( EFalse ); |
|
161 TUint32 fileType( 0 ); |
|
162 |
|
163 TRAPD( err, fileType = iEngine.FileTypeL( ptrUserTextFullPath ) ); |
|
164 if ( err != KErrNone && err != KErrNotFound && err != KErrAccessDenied ) |
|
165 { |
|
166 User::Leave( err ); |
|
167 } |
|
168 |
|
169 if( ( err == KErrNotFound ) || |
|
170 ( err == KErrAccessDenied ) || |
|
171 ( fileType & ( CFileManagerItemProperties::EOpen | |
|
172 CFileManagerItemProperties::EReadOnly | |
|
173 CFileManagerItemProperties::EFolder ) ) ) |
|
174 { |
|
175 FileManagerDlgUtils::ShowInfoNoteL( |
|
176 R_QTN_FLDR_NAME_ALREADY_USED, Text() ); |
|
177 } |
|
178 else |
|
179 { |
|
180 overWrite = |
|
181 FileManagerDlgUtils::ShowConfirmQueryWithYesNoL( |
|
182 R_QTN_ITEM_OVERWRITE_QUERY, Text() ); |
|
183 } |
|
184 |
|
185 if( !overWrite ) |
|
186 { |
|
187 CAknQueryControl* queryControl = QueryControl(); |
|
188 if (queryControl) |
|
189 { |
|
190 CEikEdwin* edwin = static_cast< CEikEdwin* >( |
|
191 queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
192 if (edwin) |
|
193 { |
|
194 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
195 } |
|
196 } |
|
197 result = EFalse; |
|
198 } |
|
199 } |
|
200 |
|
201 TParsePtrC newName( ptrUserText ); |
|
202 if ( result && oldName.Ext().CompareF( newName.Ext() ) ) |
|
203 { |
|
204 FileManagerDlgUtils::ShowWarningNoteL( |
|
205 R_QTN_FM_WARNING_FILE_EXTENSION ); |
|
206 } |
|
207 |
|
208 CleanupStack::PopAndDestroy( userTextFullPath ); |
|
209 CleanupStack::PopAndDestroy( userText ); |
|
210 return result; |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CFileManagerFileNameQueryDlg::OkToExitL |
|
215 // |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 TBool CFileManagerFileNameQueryDlg::OkToExitL( TInt aButtonId ) |
|
219 { |
|
220 if ( iCallbackDisabled ) |
|
221 { |
|
222 return EFalse; // Block unwanted softkey events |
|
223 } |
|
224 TBool ret( EFalse ); |
|
225 iCallbackDisabled = ETrue; |
|
226 TRAPD( err, ret = DoOkToExitL( aButtonId ) ); |
|
227 iCallbackDisabled = EFalse; |
|
228 User::LeaveIfError( err ); |
|
229 return ret; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CFileManagerFileNameQueryDlg::OfferKeyEventL |
|
234 // |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TKeyResponse CFileManagerFileNameQueryDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
238 { |
|
239 TKeyResponse response = EKeyWasNotConsumed; |
|
240 if ( aType == EEventKey && aKeyEvent.iCode == EKeyEnter ) |
|
241 { |
|
242 response = EKeyWasConsumed; |
|
243 } |
|
244 else |
|
245 { |
|
246 response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType); |
|
247 } |
|
248 return response; |
|
249 } |
|
250 |
|
251 // End of File |