|
1 /* |
|
2 * Copyright (c) 2003 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: Class for selecting servers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWVSettingsUIServerSelector.h" |
|
21 #include "CWVSettingsUIDialogImp.h" |
|
22 #include <aknpopupsettingpage.h> // CAknPopupSettingPage |
|
23 #include <badesca.h> |
|
24 #include <CWVSettingsUING.rsg> // Application resources |
|
25 #include <cimpssapsettingsstore.h> |
|
26 #include <cimpssapsettingslist.h> |
|
27 #include <cimpssapsettings.h> |
|
28 |
|
29 // ================= MEMBER FUNCTIONS ======================= |
|
30 |
|
31 // --------------------------------------------------------- |
|
32 // CWVSettingsUIServerSelector::ExecuteSelectionQueryLD |
|
33 // |
|
34 // (other items were commented in a header). |
|
35 // --------------------------------------------------------- |
|
36 // |
|
37 void CWVSettingsUIServerSelector::ExecuteSelectionQueryLD( |
|
38 CIMPSSAPSettingsStore& aSAPSettingsStore, |
|
39 CWVSettingsUIDialogImp& aDialog, |
|
40 TBool aShowDefaultSAP /*= ETrue*/, |
|
41 TBool aForceSelection /*= EFalse*/ ) |
|
42 { |
|
43 CWVSettingsUIServerSelector* self = new ( ELeave ) CWVSettingsUIServerSelector( |
|
44 aSAPSettingsStore, |
|
45 aShowDefaultSAP, |
|
46 aForceSelection, |
|
47 aDialog ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->DoSelectionL(); |
|
50 CleanupStack::PopAndDestroy( self ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------- |
|
54 // CWVSettingsUIServerSelector::DoSelectionL |
|
55 // |
|
56 // (other items were commented in a header). |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 void CWVSettingsUIServerSelector::DoSelectionL() |
|
60 { |
|
61 iSAPSettingsList = CIMPSSAPSettingsList::NewL(); |
|
62 |
|
63 iSAPSettingsStore.PopulateSAPSettingsListL( *iSAPSettingsList, EIMPSIMAccessGroup ); |
|
64 |
|
65 TInt popupResource( R_WVSETTINGSVIEW_SERVERLIST_SETTING_PAGE ); |
|
66 if ( iForceSelection ) |
|
67 { |
|
68 popupResource = R_WVSETTINGSVIEW_SERVERLIST_SETTING_PAGE_FORCED; |
|
69 } |
|
70 |
|
71 // Read server data to inner array |
|
72 TInt currentServerIndex( 0 ); |
|
73 iServerList = GenerateServerListL( currentServerIndex ); |
|
74 |
|
75 if ( !iServerList ) |
|
76 { |
|
77 return; |
|
78 } |
|
79 |
|
80 // Initialize query array |
|
81 CAknQueryValueTextArray* textArray = CAknQueryValueTextArray::NewLC(); |
|
82 textArray->SetArray( *iServerList ); |
|
83 |
|
84 // Sets the same array and sets initial index. |
|
85 CAknQueryValueText* queryValue = CAknQueryValueText::NewLC(); |
|
86 queryValue->SetArrayL( textArray ); |
|
87 queryValue->SetCurrentValueIndex( currentServerIndex ); |
|
88 |
|
89 // Creates Popup Setting Page object. |
|
90 CAknPopupSettingPage* popup = |
|
91 new( ELeave ) CAknPopupSettingPage( popupResource, *queryValue ); |
|
92 |
|
93 |
|
94 // Displays Popup Setting Page screen. |
|
95 TBool res = ETrue; |
|
96 res = popup->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ); |
|
97 |
|
98 if ( res || iForceSelection ) |
|
99 { |
|
100 iSAPSettingsStore.SetToDefaultL( |
|
101 TranslateSelectedIndexL( queryValue->CurrentValueIndex() ), EIMPSIMAccessGroup ); |
|
102 } |
|
103 |
|
104 CleanupStack::PopAndDestroy( queryValue ); |
|
105 CleanupStack::PopAndDestroy( textArray ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CWVSettingsUIServerSelector::GenerateServerListL |
|
110 // |
|
111 // (other items were commented in a header). |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 CDesCArrayFlat* CWVSettingsUIServerSelector::GenerateServerListL( TInt& aCurrentServerIndex ) |
|
115 { |
|
116 |
|
117 TInt srvCount( iSAPSettingsStore.SAPCountL( EIMPSIMAccessGroup ) ); |
|
118 |
|
119 // If there is no servers at all or there is only one server and default |
|
120 // is not shown, then the list is empty |
|
121 if ( ( srvCount == 0 ) || ( srvCount == 1 && !iShowDefaultSAP ) ) |
|
122 { |
|
123 return NULL; |
|
124 } |
|
125 |
|
126 TUint32 defaultUID( KIMPSSettingsNullUid ); |
|
127 iSAPSettingsStore.GetDefaultL( defaultUID, EIMPSIMAccessGroup ); |
|
128 |
|
129 // If we have only 2 servers, one of them is already default and |
|
130 // default is notshown, AND we have forced selection, then we can |
|
131 // automatically choose new default server. |
|
132 if ( srvCount == 2 && !iShowDefaultSAP && iForceSelection ) |
|
133 { |
|
134 if ( iSAPSettingsList->At( 0 )->Uid() == defaultUID ) |
|
135 { |
|
136 iSAPSettingsStore.SetToDefaultL( iSAPSettingsList->At( 1 )->Uid(), EIMPSIMAccessGroup ); |
|
137 } |
|
138 else |
|
139 { |
|
140 iSAPSettingsStore.SetToDefaultL( iSAPSettingsList->At( 0 )->Uid(), EIMPSIMAccessGroup ); |
|
141 } |
|
142 return NULL; |
|
143 } |
|
144 |
|
145 TBool isCurrentSAPDefault( EFalse ); |
|
146 |
|
147 //get existing server names |
|
148 CDesCArrayFlat* serverNames = new( ELeave ) CDesCArrayFlat( srvCount ); |
|
149 CleanupStack::PushL( serverNames ); |
|
150 |
|
151 for ( TInt ii( 0 ); ii < srvCount; ii++ ) |
|
152 { |
|
153 isCurrentSAPDefault = iSAPSettingsList->At( ii )->Uid() == defaultUID; |
|
154 |
|
155 if ( !iShowDefaultSAP ) |
|
156 { |
|
157 if ( !isCurrentSAPDefault ) |
|
158 { |
|
159 serverNames->AppendL( iSAPSettingsList->MdcaPoint( ii ) ); |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 serverNames->AppendL( iSAPSettingsList->MdcaPoint( ii ) ); |
|
165 |
|
166 if ( isCurrentSAPDefault ) |
|
167 { |
|
168 aCurrentServerIndex = ii; |
|
169 } |
|
170 } |
|
171 |
|
172 } |
|
173 |
|
174 CleanupStack::Pop( serverNames ); |
|
175 return serverNames; |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------- |
|
179 // CWVSettingsUIServerSelector::TranslateSelectedIndexL |
|
180 // |
|
181 // (other items were commented in a header). |
|
182 // --------------------------------------------------------- |
|
183 // |
|
184 TUint32 CWVSettingsUIServerSelector::TranslateSelectedIndexL( TInt aIndex ) |
|
185 { |
|
186 TInt listIndex( 0 ); |
|
187 if ( iSAPSettingsList->FindNameL( iServerList->MdcaPoint( aIndex ), listIndex ) == 0 ) |
|
188 { |
|
189 return iSAPSettingsList->UidForIndex( listIndex ); |
|
190 } |
|
191 |
|
192 return KIMPSSettingsNullUid; |
|
193 } |
|
194 |
|
195 // C++ default constructor can NOT contain any code, that |
|
196 // might leave. |
|
197 // |
|
198 CWVSettingsUIServerSelector::CWVSettingsUIServerSelector( CIMPSSAPSettingsStore& aSAPSettingsStore, |
|
199 TBool aShowDefaultSAP, |
|
200 TBool aForceSelection, |
|
201 CWVSettingsUIDialogImp& aDialog ) |
|
202 : iSAPSettingsStore( aSAPSettingsStore ), |
|
203 iForceSelection( aForceSelection ), |
|
204 iShowDefaultSAP( aShowDefaultSAP ), |
|
205 iDialog( aDialog ) |
|
206 { |
|
207 } |
|
208 |
|
209 // Destructor |
|
210 CWVSettingsUIServerSelector::~CWVSettingsUIServerSelector() |
|
211 { |
|
212 delete iServerList; |
|
213 delete iSAPSettingsList; |
|
214 } |
|
215 |
|
216 // End of File |