|
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 |
|
106 // Strip any directionality markers to get pure name |
|
107 AknTextUtils::StripCharacters( ptrUserText, KFmgrDirectionalChars ); |
|
108 |
|
109 // Check file name |
|
110 TBool isValidName( EFalse ); |
|
111 TParsePtrC oldName( *iOldName ); |
|
112 if ( oldName.PathPresent() ) |
|
113 { |
|
114 isValidName = iEngine.IsValidName( |
|
115 oldName.DriveAndPath(), *userText, EFalse ); |
|
116 } |
|
117 else |
|
118 { |
|
119 isValidName = iEngine.IsValidName( KNullDesC, *userText, EFalse ); |
|
120 } |
|
121 |
|
122 if( !isValidName ) |
|
123 { |
|
124 if( iEngine.IllegalChars( *userText ) ) |
|
125 { |
|
126 FileManagerDlgUtils::ShowInfoNoteL( |
|
127 R_QTN_FLDR_ILLEGAL_CHARACTERS ); |
|
128 } |
|
129 else |
|
130 { |
|
131 FileManagerDlgUtils::ShowInfoNoteL( |
|
132 R_QTN_FLDR_BAD_FILE_NAME ); |
|
133 } |
|
134 CAknQueryControl* queryControl = QueryControl(); |
|
135 if (queryControl) |
|
136 { |
|
137 CEikEdwin* edwin = static_cast< CEikEdwin* >( |
|
138 queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
139 if (edwin) |
|
140 { |
|
141 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
142 } |
|
143 } |
|
144 CleanupStack::PopAndDestroy( userText ); |
|
145 return EFalse; |
|
146 } |
|
147 |
|
148 HBufC* userTextFullPath = HBufC::NewLC( KMaxFileName ); |
|
149 TPtr ptrUserTextFullPath( userTextFullPath->Des() ); |
|
150 |
|
151 ptrUserTextFullPath.Append( oldName.DriveAndPath() ); |
|
152 ptrUserTextFullPath.Append( *userText ); |
|
153 // if some other entry found with same name |
|
154 // not ok except if name same as original |
|
155 if( oldName.NameAndExt().CompareF( *userText ) && |
|
156 ( iEngine.IsNameFoundL( ptrUserTextFullPath ) || |
|
157 BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), ptrUserTextFullPath)) ) |
|
158 { |
|
159 TBool overWrite( EFalse ); |
|
160 TUint32 fileType( 0 ); |
|
161 |
|
162 TRAPD( err, fileType = iEngine.FileTypeL( ptrUserTextFullPath ) ); |
|
163 if ( err != KErrNone && err != KErrAccessDenied ) |
|
164 { |
|
165 User::Leave( err ); |
|
166 } |
|
167 |
|
168 if( ( fileType & ( CFileManagerItemProperties::EOpen | |
|
169 CFileManagerItemProperties::EReadOnly | |
|
170 CFileManagerItemProperties::EFolder ) ) || |
|
171 ( err == KErrAccessDenied ) ) |
|
172 { |
|
173 FileManagerDlgUtils::ShowInfoNoteL( |
|
174 R_QTN_FLDR_NAME_ALREADY_USED, Text() ); |
|
175 } |
|
176 else |
|
177 { |
|
178 overWrite = |
|
179 FileManagerDlgUtils::ShowConfirmQueryWithYesNoL( |
|
180 R_QTN_ITEM_OVERWRITE_QUERY, Text() ); |
|
181 } |
|
182 |
|
183 if( !overWrite ) |
|
184 { |
|
185 CAknQueryControl* queryControl = QueryControl(); |
|
186 if (queryControl) |
|
187 { |
|
188 CEikEdwin* edwin = static_cast< CEikEdwin* >( |
|
189 queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
190 if (edwin) |
|
191 { |
|
192 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
193 } |
|
194 } |
|
195 result = EFalse; |
|
196 } |
|
197 } |
|
198 |
|
199 TParsePtrC newName( ptrUserText ); |
|
200 if ( result && oldName.Ext().CompareF( newName.Ext() ) ) |
|
201 { |
|
202 FileManagerDlgUtils::ShowWarningNoteL( |
|
203 R_QTN_FM_WARNING_FILE_EXTENSION ); |
|
204 } |
|
205 |
|
206 CleanupStack::PopAndDestroy( userTextFullPath ); |
|
207 CleanupStack::PopAndDestroy( userText ); |
|
208 return result; |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CFileManagerFileNameQueryDlg::OkToExitL |
|
213 // |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TBool CFileManagerFileNameQueryDlg::OkToExitL( TInt aButtonId ) |
|
217 { |
|
218 if ( iCallbackDisabled ) |
|
219 { |
|
220 return EFalse; // Block unwanted softkey events |
|
221 } |
|
222 TBool ret( EFalse ); |
|
223 iCallbackDisabled = ETrue; |
|
224 TRAPD( err, ret = DoOkToExitL( aButtonId ) ); |
|
225 iCallbackDisabled = EFalse; |
|
226 User::LeaveIfError( err ); |
|
227 return ret; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // CFileManagerFileNameQueryDlg::OfferKeyEventL |
|
232 // |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 TKeyResponse CFileManagerFileNameQueryDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
236 { |
|
237 TKeyResponse response = EKeyWasNotConsumed; |
|
238 if ( aType == EEventKey && aKeyEvent.iCode == EKeyEnter ) |
|
239 { |
|
240 response = EKeyWasConsumed; |
|
241 } |
|
242 else |
|
243 { |
|
244 response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType); |
|
245 } |
|
246 return response; |
|
247 } |
|
248 |
|
249 // End of File |