1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * Implementation of CCbsUiLanguageSettingPage. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <cbsuiApp.rsg> |
|
23 #include <AknQueryDialog.h> |
|
24 #include "CCbsUiLanguageSettingPage.h" |
|
25 #include "CCbsUiListQueryDialog.h" |
|
26 #include "CbsUiPanic.h" |
|
27 #include "CbsUiConstants.h" |
|
28 #include "MCbs.h" |
|
29 |
|
30 |
|
31 |
|
32 // CONSTANTS |
|
33 const TInt KFirstLaunch = 1; |
|
34 const TInt KAverageReceivedLanguages = 4; |
|
35 |
|
36 |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // |
|
44 CCbsUiLanguageSettingPage::CCbsUiLanguageSettingPage( |
|
45 TInt aResourceID, |
|
46 TInt& aCurrentSelectionIndex, |
|
47 CDesCArrayFlat* aItemArray, |
|
48 MCbs& aServer ) |
|
49 : |
|
50 CAknRadioButtonSettingPage(aResourceID, aCurrentSelectionIndex, aItemArray), |
|
51 iServer(aServer), |
|
52 iSelectionIndex(aCurrentSelectionIndex), |
|
53 iArray(*aItemArray) |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------- |
|
58 // CCbsUiLanguageSettingPage::OkToExitL |
|
59 // |
|
60 // (other iItems were commented in a header). |
|
61 // --------------------------------------------------------- |
|
62 // |
|
63 TBool CCbsUiLanguageSettingPage::OkToExitL( TBool aAccept ) |
|
64 { |
|
65 __ASSERT_DEBUG( &iServer, CbsUiPanic(EServerNullError) ); |
|
66 |
|
67 // if ok key has been pushed, then this level options |
|
68 // settings will be made |
|
69 if ( aAccept ) |
|
70 { |
|
71 TCbsDbLanguages lang; |
|
72 iServer.GetLanguages(lang); |
|
73 |
|
74 switch ( iSelectionIndex ) |
|
75 { |
|
76 case ECbsUiAll: |
|
77 lang.iLanguages[ECbsAll] = ETrue; |
|
78 lang.iLanguages[ECbsOther] = EFalse; |
|
79 break; |
|
80 case ECbsUiSelected: |
|
81 // don't set languages after this, allready set in language dlg |
|
82 LaunchLanguageDialogL(); |
|
83 break; |
|
84 case ECbsUiOther: |
|
85 lang.iLanguages[ECbsAll] = EFalse; |
|
86 lang.iLanguages[ECbsOther] = ETrue; |
|
87 break; |
|
88 default: |
|
89 __ASSERT_DEBUG( 0, CbsUiPanic(EErrInvalidValue) ); |
|
90 break; |
|
91 } |
|
92 |
|
93 if ( iSelectionIndex == ECbsUiAll || iSelectionIndex == ECbsUiOther ) |
|
94 { |
|
95 User::LeaveIfError( iServer.SetLanguages(lang) ); |
|
96 } |
|
97 } |
|
98 |
|
99 |
|
100 return ETrue; |
|
101 } |
|
102 |
|
103 |
|
104 // --------------------------------------------------------- |
|
105 // CCbsUiLanguageSettingPage::OfferKeyEventL |
|
106 // |
|
107 // (other iItems were commented in a header). |
|
108 // --------------------------------------------------------- |
|
109 // |
|
110 TKeyResponse CCbsUiLanguageSettingPage::OfferKeyEventL( |
|
111 const TKeyEvent& aKeyEvent, |
|
112 TEventCode aType ) |
|
113 { |
|
114 __ASSERT_DEBUG( ListBoxControl(), CbsUiPanic(EListBoxNullError) ); |
|
115 |
|
116 switch ( aKeyEvent.iCode ) |
|
117 { |
|
118 case EKeyOK: |
|
119 LaunchLanguageDialogL(); |
|
120 break; |
|
121 default: |
|
122 break; |
|
123 } |
|
124 |
|
125 return CAknSettingPage::OfferKeyEventL( aKeyEvent, aType ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CCbsUiLanguageSettingPage::GetLanguagesL |
|
130 // |
|
131 // (other iItems were commented in a header). |
|
132 // --------------------------------------------------------- |
|
133 // |
|
134 void CCbsUiLanguageSettingPage::GetLanguagesL( |
|
135 CArrayFix<TInt>& aIndexArray, TCbsDbLanguages& aLanguages ) |
|
136 { |
|
137 iServer.GetLanguages(aLanguages); |
|
138 |
|
139 for ( TInt j(0); j < ECbsOther; j++ ) |
|
140 { |
|
141 if ( aLanguages.iLanguages[j] ) |
|
142 { |
|
143 aIndexArray.AppendL(j); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------- |
|
149 // CCbsUiLanguageSettingPage::LaunchLanguageDialogL |
|
150 // |
|
151 // (other iItems were commented in a header). |
|
152 // --------------------------------------------------------- |
|
153 // |
|
154 void CCbsUiLanguageSettingPage::LaunchLanguageDialogL() |
|
155 { |
|
156 iCurrentLaunchingId++; |
|
157 |
|
158 if ( iCurrentLaunchingId == KFirstLaunch ) |
|
159 { |
|
160 if ( ListBoxControl()->CurrentItemIndex() == ECbsUiSelected ) |
|
161 { |
|
162 CArrayFixFlat<TInt>* indexArray = |
|
163 new (ELeave) CArrayFixFlat<TInt>(KAverageReceivedLanguages); |
|
164 CleanupStack::PushL(indexArray); |
|
165 |
|
166 TCbsDbLanguages languages; |
|
167 GetLanguagesL(*indexArray, languages); |
|
168 |
|
169 CCbsUiListQueryDialog* dlg = new (ELeave) |
|
170 CCbsUiListQueryDialog(*indexArray); |
|
171 TInt ret( dlg->ExecuteLD(R_LANGUAGE_MULTISELECTION_LIST_QUERY) ); |
|
172 |
|
173 if( ret ) |
|
174 { |
|
175 SetLanguagesL(*indexArray, languages); |
|
176 } |
|
177 else |
|
178 { |
|
179 iCurrentLaunchingId--; |
|
180 User::Leave( KErrNone ); |
|
181 } |
|
182 |
|
183 CleanupStack::PopAndDestroy(); // indexArray; |
|
184 } |
|
185 } |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------- |
|
189 // CCbsUiLanguageSettingPage::SetLanguagesL |
|
190 // |
|
191 // (other iItems were commented in a header). |
|
192 // --------------------------------------------------------- |
|
193 // |
|
194 void CCbsUiLanguageSettingPage::SetLanguagesL( |
|
195 CArrayFix<TInt>& aIndexArray, TCbsDbLanguages& aLanguages ) |
|
196 { |
|
197 // just clearing the language selection before setting them |
|
198 for ( TInt i(0); i < ECbsOther; i++ ) |
|
199 { |
|
200 aLanguages.iLanguages[i] = EFalse; |
|
201 } |
|
202 |
|
203 // set the values which are chosen |
|
204 if ( &aIndexArray ) |
|
205 { |
|
206 TInt count( aIndexArray.Count() ); |
|
207 |
|
208 for (TInt i(0); i < count; i++) |
|
209 { |
|
210 TInt selectedIndex( aIndexArray.At(i) ); |
|
211 __ASSERT_DEBUG( selectedIndex < ECbsOther, |
|
212 CbsUiPanic(EErrIndexOutOfBounds) ); |
|
213 aLanguages.iLanguages[selectedIndex] = ETrue; |
|
214 } |
|
215 |
|
216 TBool languageSelected( count > 0 ); |
|
217 if ( languageSelected ) |
|
218 { |
|
219 aLanguages.iLanguages[ECbsAll] = EFalse; |
|
220 aLanguages.iLanguages[ECbsOther] = EFalse; |
|
221 } |
|
222 else |
|
223 { |
|
224 // The user can clear the languages and then previously |
|
225 // defined value will be selected. |
|
226 // If other has not been previously selected, then |
|
227 // all has to be selected |
|
228 if ( !aLanguages.iLanguages[ECbsOther] ) |
|
229 { |
|
230 aLanguages.iLanguages[ECbsAll] = ETrue; |
|
231 } |
|
232 } |
|
233 |
|
234 User::LeaveIfError( iServer.SetLanguages( aLanguages ) ); |
|
235 } |
|
236 } |
|
237 |
|
238 |
|
239 // End of File |
|