|
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: Encoding setting item and setting page |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cmsgmailencodingsetting.h" |
|
20 #include "MsgMailEditorDocument.h" |
|
21 #include "MailLog.h" |
|
22 #include <MsgMailEditor.rsg> |
|
23 #include <StringLoader.h> |
|
24 #include <charconv.h> |
|
25 |
|
26 |
|
27 inline void CMsgMailEditorEncodingSettingItem::ConstructL() |
|
28 { |
|
29 SetSettingValueL(); |
|
30 } |
|
31 |
|
32 CMsgMailEditorEncodingSettingItem* |
|
33 CMsgMailEditorEncodingSettingItem::NewL( |
|
34 TInt aIdentifier, CMsgMailEditorDocument& aDocument ) |
|
35 { |
|
36 CMsgMailEditorEncodingSettingItem* self = |
|
37 new( ELeave ) CMsgMailEditorEncodingSettingItem( |
|
38 aIdentifier, aDocument ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL(); |
|
41 CleanupStack::Pop(self); // self |
|
42 return self; |
|
43 } |
|
44 |
|
45 CMsgMailEditorEncodingSettingItem::CMsgMailEditorEncodingSettingItem( |
|
46 TInt aIdentifier, |
|
47 CMsgMailEditorDocument& aDocument ): |
|
48 CAknTextSettingItem( aIdentifier, iSettingValue ), |
|
49 iDocument( aDocument ) |
|
50 { |
|
51 // iSettingValue is set later |
|
52 } |
|
53 |
|
54 CMsgMailEditorEncodingSettingItem::~CMsgMailEditorEncodingSettingItem() |
|
55 { |
|
56 iSettingValue.Close(); |
|
57 delete iIdArray; |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // // From CAknTextSettingItem |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 void CMsgMailEditorEncodingSettingItem::EditItemL( |
|
65 TBool /* aCalledFromMenu */ ) |
|
66 { |
|
67 TPtrC settingName = SettingName(); |
|
68 TInt currentSelection( 0 ); |
|
69 NameArrayL( currentSelection ); |
|
70 |
|
71 CAknSettingPage* dlg = new( ELeave )CMsgMailEditorEncodingSettingPage( |
|
72 &settingName, |
|
73 SettingNumber(), |
|
74 EEikCtTextButton, |
|
75 SettingEditorResourceId(), |
|
76 SettingPageResourceId(), |
|
77 currentSelection, |
|
78 iIdArray ); |
|
79 SetSettingPage( dlg ); |
|
80 SettingPage()->SetSettingPageObserver( this ); // not used |
|
81 SettingPage()->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted ); |
|
82 |
|
83 SaveSettingValueL( currentSelection ); |
|
84 SetSettingValueL(); |
|
85 LoadL(); // update setting value to listbox |
|
86 UpdateListBoxTextL(); |
|
87 SetSettingPage( 0 ); // it is deleted now |
|
88 } |
|
89 |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // Create name array |
|
93 // ---------------------------------------------------------------------------- |
|
94 // |
|
95 void CMsgMailEditorEncodingSettingItem::NameArrayL( TInt& aSelected ) |
|
96 { |
|
97 LOG("CMsgMailEditorEncodingSettingItem::NameArrayL"); |
|
98 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
99 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* charSets = |
|
100 CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC( fs ); |
|
101 CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC(); |
|
102 |
|
103 TInt charsetCount = charSets->Count(); |
|
104 // +1 for "autom" string |
|
105 delete iIdArray; |
|
106 iIdArray = NULL; |
|
107 iIdArray = new( ELeave )CDesCArrayFlat( charsetCount+1 ); |
|
108 |
|
109 CMsgMailPreferences& prefs = iDocument.SendOptions(); |
|
110 TUid charId = prefs.SendingCharacterSet(); |
|
111 |
|
112 HBufC* autom = StringLoader::LoadLC( R_QTN_MBXS_SETT_DEFENC_AUTOMATIC ); |
|
113 iIdArray->AppendL( *autom ); |
|
114 CleanupStack::PopAndDestroy(autom); // autom |
|
115 |
|
116 for ( TInt i(0); i<charsetCount; i++) |
|
117 { |
|
118 TUint cId = (*charSets)[i].Identifier(); |
|
119 // set focus |
|
120 if ( cId == charId.iUid ) |
|
121 { |
|
122 // -1 because of autom is located at 0 index |
|
123 aSelected = i-1; |
|
124 } |
|
125 |
|
126 HBufC8* charaSetName = |
|
127 charConv->ConvertCharacterSetIdentifierToStandardNameL( |
|
128 cId, fs ); |
|
129 |
|
130 if ( charaSetName ) |
|
131 { |
|
132 CleanupStack::PushL( charaSetName ); |
|
133 HBufC* nameBuf = HBufC::NewLC( charaSetName->Length() ); |
|
134 nameBuf->Des().Copy( *charaSetName ); |
|
135 iIdArray->AppendL( *nameBuf ); |
|
136 CleanupStack::PopAndDestroy(2, charaSetName); // CSI: 47,12 # nameBuf, charaSetName |
|
137 } |
|
138 |
|
139 } |
|
140 CleanupStack::PopAndDestroy( 2, charSets ); // CSI: 47,12 # charSets, charConv |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // Save selected mbox id to settings |
|
145 // ---------------------------------------------------------------------------- |
|
146 // |
|
147 void CMsgMailEditorEncodingSettingItem::SaveSettingValueL( |
|
148 TInt aSelected ) |
|
149 { |
|
150 ASSERT( iIdArray ); |
|
151 ASSERT( iIdArray->Count() >= 0 && aSelected < iIdArray->Count() ); |
|
152 |
|
153 TPtrC name = (*iIdArray)[aSelected]; |
|
154 HBufC8* charsetName = HBufC8::NewLC( name.Length() ); |
|
155 charsetName->Des().Copy( name ); |
|
156 |
|
157 CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC(); |
|
158 |
|
159 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
160 TUint charsetId = |
|
161 charConv->ConvertStandardNameOfCharacterSetToIdentifierL( |
|
162 *charsetName, fs); |
|
163 |
|
164 CleanupStack::PopAndDestroy(2, charsetName ); // CSI: 47,12 # charConv, charsetName |
|
165 |
|
166 // Update selected ID to settings |
|
167 TUid charId; |
|
168 charId.iUid = charsetId; |
|
169 iDocument.SendOptions().SetSendingCharacterSet( charId ); |
|
170 |
|
171 iDocument.SetChanged( ETrue ); |
|
172 } |
|
173 |
|
174 // ---------------------------------------------------------------------------- |
|
175 // Set current character set name to setting list |
|
176 // ---------------------------------------------------------------------------- |
|
177 // |
|
178 void CMsgMailEditorEncodingSettingItem::SetSettingValueL() |
|
179 { |
|
180 HBufC* charset = GetCharsetNameLC(); |
|
181 iSettingValue.Close(); |
|
182 iSettingValue.CreateL( *charset ); |
|
183 CleanupStack::PopAndDestroy( charset ); |
|
184 } |
|
185 |
|
186 // ---------------------------------------------------------------------------- |
|
187 // Get current character set name |
|
188 // ---------------------------------------------------------------------------- |
|
189 // |
|
190 HBufC* CMsgMailEditorEncodingSettingItem::GetCharsetNameLC() |
|
191 { |
|
192 CMsgMailPreferences& prefs = iDocument.SendOptions(); |
|
193 TUint charsetId = prefs.SendingCharacterSet().iUid; |
|
194 |
|
195 HBufC* returnName(NULL); |
|
196 if (charsetId) |
|
197 { |
|
198 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
199 CCnvCharacterSetConverter* charConv = |
|
200 CCnvCharacterSetConverter::NewLC(); |
|
201 |
|
202 HBufC8* charSetName = charConv-> |
|
203 ConvertCharacterSetIdentifierToStandardNameL( |
|
204 charsetId, fs); |
|
205 CleanupStack::PopAndDestroy(charConv); // charConv |
|
206 |
|
207 if (charSetName) |
|
208 { |
|
209 CleanupStack::PushL( charSetName ); |
|
210 // 1 because length might be zero |
|
211 returnName = HBufC::NewL( Max(charSetName->Length(), 1) ); |
|
212 returnName->Des().Copy( *charSetName ); |
|
213 CleanupStack::PopAndDestroy(charSetName); // charSetName |
|
214 CleanupStack::PushL( returnName ); |
|
215 } |
|
216 else |
|
217 { |
|
218 ASSERT(0); // panic |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 returnName = StringLoader::LoadLC( R_QTN_MBXS_SETT_DEFENC_AUTOMATIC ); |
|
224 } |
|
225 return returnName; |
|
226 } |
|
227 |
|
228 |
|
229 CMsgMailEditorEncodingSettingPage::CMsgMailEditorEncodingSettingPage( |
|
230 TInt aResourceID, |
|
231 TInt& aCurrentSelectionIndex, |
|
232 const MDesCArray* aItemArray ) |
|
233 : CAknRadioButtonSettingPage( |
|
234 aResourceID, aCurrentSelectionIndex, aItemArray ) |
|
235 { |
|
236 } |
|
237 |
|
238 CMsgMailEditorEncodingSettingPage::CMsgMailEditorEncodingSettingPage( |
|
239 const TDesC* aSettingText, |
|
240 TInt aSettingNumber, |
|
241 TInt aControlType, |
|
242 TInt aEditorResourceId, |
|
243 TInt aResourceID, |
|
244 TInt& aCurrentSelectionIndex, |
|
245 const MDesCArray* aItemArray) |
|
246 : CAknRadioButtonSettingPage( |
|
247 aSettingText, |
|
248 aSettingNumber, |
|
249 aControlType, |
|
250 aEditorResourceId, |
|
251 aResourceID, |
|
252 aCurrentSelectionIndex, |
|
253 aItemArray ) |
|
254 { |
|
255 } |
|
256 |
|
257 CMsgMailEditorEncodingSettingPage::~CMsgMailEditorEncodingSettingPage() |
|
258 { |
|
259 } |
|
260 |
|
261 void CMsgMailEditorEncodingSettingPage::ConstructL() |
|
262 { |
|
263 CAknRadioButtonSettingPage::ConstructL(); |
|
264 } |
|
265 |
|
266 // End of File |