1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "FileNameSettingItem.h" |
|
23 #include <aknnotewrappers.h> |
|
24 #include <stringloader.h> |
|
25 |
|
26 |
|
27 CFileNameSettingItem::CFileNameSettingItem( TInt aIdentifier, TDes& aText, |
|
28 TInt aIllegalFilenameTextResourceID, |
|
29 TInt aUnsuitableFilenameTextResourceID ) |
|
30 :CAknTextSettingItem( aIdentifier, aText ), |
|
31 iIllegalFilenameTextResourceID(aIllegalFilenameTextResourceID), |
|
32 iUnsuitableFilenameTextResourceID(aUnsuitableFilenameTextResourceID) |
|
33 { |
|
34 } |
|
35 |
|
36 CFileNameSettingItem::~CFileNameSettingItem() |
|
37 { |
|
38 if ( iTextBeforeEditing ) |
|
39 { |
|
40 delete iTextBeforeEditing; |
|
41 } |
|
42 } |
|
43 |
|
44 void CFileNameSettingItem::EditItemL( TBool aCalledFromMenu ) |
|
45 { |
|
46 if ( !iInvalidFilenameOked ) |
|
47 { |
|
48 // Delete old buffer if allocated |
|
49 if ( iTextBeforeEditing ) |
|
50 { |
|
51 delete iTextBeforeEditing; |
|
52 iTextBeforeEditing = NULL; |
|
53 } |
|
54 // Save the value before editing it |
|
55 iTextBeforeEditing = HBufC::NewL( SettingTextL().Length()); |
|
56 iTextBeforeEditing->Des().Copy( SettingTextL()); |
|
57 } |
|
58 CAknTextSettingItem::EditItemL( aCalledFromMenu ); |
|
59 } |
|
60 |
|
61 void CFileNameSettingItem::HandleSettingPageEventL( |
|
62 CAknSettingPage* aSettingPage, |
|
63 TAknSettingPageEvent aEventType ) |
|
64 { |
|
65 |
|
66 switch ( aEventType ) |
|
67 { |
|
68 /** |
|
69 * Cancel event. |
|
70 */ |
|
71 case EEventSettingCancelled: |
|
72 { |
|
73 if ( iInvalidFilenameOked ) |
|
74 { |
|
75 iInvalidFilenameOked = EFalse; // Reset invalid filename flag |
|
76 |
|
77 TPtr internalText = InternalTextPtr(); |
|
78 internalText.Delete( 0, internalText.Length()); |
|
79 internalText.Append( *iTextBeforeEditing ); |
|
80 StoreL(); |
|
81 LoadL(); |
|
82 } |
|
83 break; |
|
84 } |
|
85 /** |
|
86 * Change event. |
|
87 */ |
|
88 case EEventSettingChanged: |
|
89 break; |
|
90 /** |
|
91 * Ok event. |
|
92 */ |
|
93 case EEventSettingOked: |
|
94 { |
|
95 RFs fileSystem; |
|
96 |
|
97 CleanupClosePushL( fileSystem ); |
|
98 User::LeaveIfError( fileSystem.Connect()); |
|
99 |
|
100 TText illegalCharacter; |
|
101 |
|
102 if ( !fileSystem.IsValidName( SettingTextL(), illegalCharacter ) ) |
|
103 { |
|
104 iInvalidFilenameOked = ETrue; |
|
105 |
|
106 HBufC* noteText; |
|
107 |
|
108 // If dot keyed |
|
109 if ( illegalCharacter == KCharDot ) |
|
110 { |
|
111 noteText = StringLoader::LoadLC( iUnsuitableFilenameTextResourceID ); |
|
112 } |
|
113 else |
|
114 { |
|
115 noteText = StringLoader::LoadLC( iIllegalFilenameTextResourceID ); |
|
116 } |
|
117 |
|
118 CAknWarningNote* note = new( ELeave )CAknWarningNote( ETrue ); |
|
119 |
|
120 note->ExecuteLD( *noteText ); |
|
121 CleanupStack::PopAndDestroy( noteText ); |
|
122 |
|
123 EditItemL( EFalse ); // Start editing the text again. |
|
124 } |
|
125 else if ( SettingTextL().Find( KCharColon ) == 1 ) |
|
126 { |
|
127 iInvalidFilenameOked = ETrue; |
|
128 |
|
129 // Load note text from resources. |
|
130 HBufC* noteText = StringLoader::LoadLC( iIllegalFilenameTextResourceID ); |
|
131 |
|
132 |
|
133 CAknWarningNote* note = new( ELeave )CAknWarningNote( ETrue ); |
|
134 note->ExecuteLD( *noteText ); |
|
135 |
|
136 CleanupStack::PopAndDestroy( noteText ); // Pop and destroy. |
|
137 |
|
138 EditItemL( EFalse ); // Start editing the text again. |
|
139 } |
|
140 else |
|
141 { |
|
142 // Do nothing. |
|
143 } |
|
144 |
|
145 CleanupStack::PopAndDestroy( &fileSystem ); |
|
146 break; |
|
147 } |
|
148 } |
|
149 // Super class handles events. |
|
150 CAknTextSettingItem::HandleSettingPageEventL( aSettingPage, aEventType ); |
|
151 |
|
152 } |
|
153 // End of File |
|