|
1 /* |
|
2 * Copyright (c) 2002-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: Dialog for asking folder name from user |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <StringLoader.h> |
|
22 #include <aknnotewrappers.h> |
|
23 #include <bautils.h> |
|
24 #include <CFileManagerEngine.h> |
|
25 #include <CFileManagerUtils.h> |
|
26 #include <FileManagerView.rsg> |
|
27 #include "Cfilemanagerfoldernamequerydlg.h" |
|
28 #include "CFileManagerCommonDefinitions.h" |
|
29 #include "FileManagerDlgUtils.h" |
|
30 #include "CFileManagerItemProperties.h" |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 // If number is 10 or more 2 digits are needed to display it |
|
35 const TInt KTwoDigitNeeded = 10; |
|
36 _LIT( KFormatStringTwoDigit, "%02d" ); |
|
37 _LIT( KFormatString, "%d" ); |
|
38 const TInt KFormatBufLen = 16; |
|
39 |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CFileManagerFolderNameQueryDlg::NewL |
|
45 // |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CFileManagerFolderNameQueryDlg* CFileManagerFolderNameQueryDlg::NewL( |
|
49 TDes& aDataText, |
|
50 CFileManagerEngine& aEngine, |
|
51 TBool aNameGeneration ) |
|
52 { |
|
53 CFileManagerFolderNameQueryDlg* self = |
|
54 new( ELeave ) CFileManagerFolderNameQueryDlg( aDataText, aEngine ); |
|
55 |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aNameGeneration, aDataText ); |
|
58 CleanupStack::Pop( self ); |
|
59 |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CFileManagerFolderNameQueryDlg::CFileManagerFolderNameQueryDlg |
|
65 // C++ default constructor can NOT contain any code, that |
|
66 // might leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CFileManagerFolderNameQueryDlg::CFileManagerFolderNameQueryDlg( |
|
70 TDes& aDataText, |
|
71 CFileManagerEngine& aEngine ) : |
|
72 CAknTextQueryDialog( aDataText ), |
|
73 iEngine( aEngine ) |
|
74 { |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CFileManagerFolderNameQueryDlg::ConstructL |
|
79 // |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 void CFileManagerFolderNameQueryDlg::ConstructL( TBool aNameGeneration, |
|
83 TDes& aDataText ) |
|
84 { |
|
85 if( aNameGeneration ) |
|
86 { |
|
87 TInt i( 1 ); |
|
88 HBufC* folderName = |
|
89 StringLoader::LoadLC( R_FILEMANAGER_DEFAULT_FOLDER_NAME ); |
|
90 TBuf< KFormatBufLen > numBuf; |
|
91 |
|
92 while( iEngine.IsNameFoundL( *folderName ) ) |
|
93 { |
|
94 CleanupStack::PopAndDestroy( folderName ); |
|
95 numBuf.Zero(); |
|
96 if( i < KTwoDigitNeeded ) |
|
97 { |
|
98 numBuf.Format( KFormatStringTwoDigit, i ); |
|
99 } |
|
100 else |
|
101 { |
|
102 numBuf.Format( KFormatString, i ); |
|
103 } |
|
104 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( |
|
105 numBuf ); |
|
106 folderName = StringLoader::LoadLC( |
|
107 R_FILEMANAGER_DEFAULT_FOLDER_NAME_N, numBuf ); |
|
108 ++i; |
|
109 } |
|
110 Text().Copy( *folderName ); |
|
111 CleanupStack::PopAndDestroy( folderName ); |
|
112 } |
|
113 else |
|
114 { |
|
115 iOldName = aDataText.AllocL(); |
|
116 TParsePtrC parse( |
|
117 CFileManagerUtils::StripFinalBackslash( *iOldName ) ); |
|
118 if ( parse.PathPresent() ) |
|
119 { |
|
120 Text().Copy( parse.NameAndExt() ); |
|
121 } |
|
122 else |
|
123 { |
|
124 Text().Copy( *iOldName ); |
|
125 } |
|
126 |
|
127 // Strip any directionality markers to get pure name |
|
128 TPtr ptr( iOldName->Des() ); |
|
129 AknTextUtils::StripCharacters( ptr, KFmgrDirectionalChars ); |
|
130 } |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CFileManagerFolderNameQueryDlg::~CFileManagerFolderNameQueryDlg |
|
135 // Destructor |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 CFileManagerFolderNameQueryDlg::~CFileManagerFolderNameQueryDlg() |
|
139 { |
|
140 delete iOldName; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CFileManagerFolderNameQueryDlg::DoOkToExitL |
|
145 // |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TBool CFileManagerFolderNameQueryDlg::DoOkToExitL( TInt aButtonId ) |
|
149 { |
|
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, KFmgrDirectionalChars ); |
|
157 |
|
158 // Check folder name |
|
159 TBool isValidName( EFalse ); |
|
160 TPtrC empty( KNullDesC ); |
|
161 TParsePtrC oldName( CFileManagerUtils::StripFinalBackslash( |
|
162 iOldName ? *iOldName : empty ) ); |
|
163 if ( oldName.PathPresent() ) |
|
164 { |
|
165 isValidName = iEngine.IsValidName( |
|
166 oldName.DriveAndPath(), *userText, ETrue ); |
|
167 } |
|
168 else |
|
169 { |
|
170 isValidName = iEngine.IsValidName( KNullDesC, *userText, ETrue ); |
|
171 } |
|
172 |
|
173 if( !isValidName ) |
|
174 { |
|
175 if( iEngine.IllegalChars( *userText ) ) |
|
176 { |
|
177 FileManagerDlgUtils::ShowInfoNoteL( |
|
178 R_QTN_FLDR_ILLEGAL_CHARACTERS ); |
|
179 } |
|
180 else |
|
181 { |
|
182 FileManagerDlgUtils::ShowInfoNoteL( |
|
183 R_QTN_FLDR_BAD_FILE_NAME ); |
|
184 } |
|
185 CAknQueryControl* queryControl = QueryControl(); |
|
186 if ( queryControl ) |
|
187 { |
|
188 CEikEdwin* edwin = static_cast< CEikEdwin* >( queryControl-> |
|
189 ControlByLayoutOrNull( EDataLayout ) ); |
|
190 if ( edwin ) |
|
191 { |
|
192 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
193 } |
|
194 } |
|
195 CleanupStack::PopAndDestroy( userText ); |
|
196 return EFalse; |
|
197 } |
|
198 |
|
199 HBufC* userTextFullPath = HBufC::NewLC( KMaxFileName ); |
|
200 TPtr ptrUserTextFullPath( userTextFullPath->Des() ); |
|
201 if ( oldName.PathPresent() ) |
|
202 { |
|
203 ptrUserTextFullPath.Append( oldName.DriveAndPath() ); |
|
204 } |
|
205 |
|
206 ptrUserTextFullPath.Append( *userText ); |
|
207 |
|
208 // if entry with same name - not ok except if name same as original |
|
209 if( iEngine.IsNameFoundL( ptrUserTextFullPath ) && |
|
210 ( !iOldName || ( iOldName && |
|
211 iOldName->Des().CompareF( ptrUserTextFullPath ) ) ) ) |
|
212 { |
|
213 FileManagerDlgUtils::ShowInfoNoteL( |
|
214 R_QTN_WMLBM_NAME_ALREADY_USED ); |
|
215 |
|
216 CAknQueryControl* queryControl = QueryControl(); |
|
217 if ( queryControl ) |
|
218 { |
|
219 CEikEdwin* edwin = static_cast< CEikEdwin* > |
|
220 ( queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
221 if ( edwin ) |
|
222 { |
|
223 edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
224 } |
|
225 } |
|
226 result = EFalse; |
|
227 } |
|
228 CleanupStack::PopAndDestroy( userTextFullPath ); |
|
229 CleanupStack::PopAndDestroy( userText ); |
|
230 return result; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CFileManagerFileNameQueryDlg::OkToExitL |
|
235 // |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CFileManagerFolderNameQueryDlg::OkToExitL( TInt aButtonId ) |
|
239 { |
|
240 if ( iCallbackDisabled ) |
|
241 { |
|
242 return EFalse; // Block unwanted softkey events |
|
243 } |
|
244 TBool ret( EFalse ); |
|
245 iCallbackDisabled = ETrue; |
|
246 TRAPD( err, ret = DoOkToExitL( aButtonId ) ); |
|
247 iCallbackDisabled = EFalse; |
|
248 User::LeaveIfError( err ); |
|
249 return ret; |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CFileManagerFolderNameQueryDlg::OfferKeyEventL |
|
254 // |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TKeyResponse CFileManagerFolderNameQueryDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
258 { |
|
259 TKeyResponse response = EKeyWasNotConsumed; |
|
260 if ( aType == EEventKey && aKeyEvent.iCode == EKeyEnter ) |
|
261 { |
|
262 response = EKeyWasConsumed; |
|
263 } |
|
264 else |
|
265 { |
|
266 response = CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType); |
|
267 } |
|
268 return response; |
|
269 } |
|
270 |
|
271 // End of File |