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 the License "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 CWmlBrowserBookmarksEditFormApModel. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <coemain.h> |
|
24 #include <ApListItem.h> |
|
25 #include <ApListItemList.h> |
|
26 #include <AknQueryValueText.h> |
|
27 #include "BrowserBookmarksEditFormApModel.h" |
|
28 #include "CommsModel.h" |
|
29 #include "Browser.hrh" |
|
30 #include <BrowserNG.rsg> |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 /// Granularity of iDesCArrayText. |
|
35 LOCAL_D const TInt KGranularity = 4; |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CBrowserBookmarksEditFormApModel::NewL |
|
41 // --------------------------------------------------------- |
|
42 // |
|
43 CBrowserBookmarksEditFormApModel* |
|
44 CBrowserBookmarksEditFormApModel::NewL( MCommsModel& aCommsModel ) |
|
45 { |
|
46 CBrowserBookmarksEditFormApModel* model = |
|
47 new (ELeave) CBrowserBookmarksEditFormApModel( aCommsModel ); |
|
48 CleanupStack::PushL( model ); |
|
49 model->ConstructL(); |
|
50 CleanupStack::Pop(); // model |
|
51 return model; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // CBrowserBookmarksEditFormApModel::~CBrowserBookmarksEditFormApModel |
|
56 // --------------------------------------------------------- |
|
57 // |
|
58 CBrowserBookmarksEditFormApModel::~CBrowserBookmarksEditFormApModel() |
|
59 { |
|
60 delete iTextValue; |
|
61 delete iTextArray; |
|
62 delete iDesCArrayText; |
|
63 delete iApList; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CBrowserBookmarksEditFormApModel::ReadApDataL |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 void CBrowserBookmarksEditFormApModel::ReadApDataL() |
|
71 { |
|
72 // Work on new lists, until they are fully created. |
|
73 CApListItemList* apList = iCommsModel->CopyAccessPointsL(); |
|
74 //CApListItemList* apList = new (ELeave) CApListItemList(); // Test empty. |
|
75 CleanupStack::PushL( apList ); |
|
76 CDesCArrayFlat* desCArrayText = |
|
77 new (ELeave) CDesCArrayFlat( KGranularity ); |
|
78 CleanupStack::PushL( desCArrayText ); |
|
79 |
|
80 TInt count = apList->Count(); |
|
81 if ( count ) |
|
82 { |
|
83 // We have some access points; fill iDesCArray with names (otherwise |
|
84 // it stays empty). |
|
85 |
|
86 // Add "Default" first. |
|
87 HBufC* defaultApName = CCoeEnv::Static()->AllocReadResourceLC |
|
88 ( R_BROWSER_BOKMARKS_TEXT_DEFAULT_WAPAP ); |
|
89 desCArrayText->AppendL( *defaultApName ); |
|
90 CleanupStack::PopAndDestroy(); // defaultApName |
|
91 |
|
92 // Then continue with real AP names. |
|
93 TInt i; |
|
94 TPtrC apName; |
|
95 for ( i = 0; i < count; i++ ) |
|
96 { |
|
97 apName.Set( apList->At( i )->Name() ); |
|
98 if ( apName.Length() > KBrowserMaxWapApName ) |
|
99 { |
|
100 // Since AP names are of unlimited length, we might have to |
|
101 // trim. |
|
102 apName.Set( apName.Left( KBrowserMaxWapApName ) ); |
|
103 } |
|
104 desCArrayText->AppendL( apName ); |
|
105 } |
|
106 } |
|
107 |
|
108 // Replace inst vars with new lists only after success. |
|
109 CleanupStack::Pop( 2 ); // desCArrayText, apList: become members |
|
110 delete iDesCArrayText; // (does not leave) |
|
111 iDesCArrayText = desCArrayText; // (does not leave) |
|
112 delete iApList; // (does not leave) |
|
113 iApList = apList; // (does not leave) |
|
114 iTextArray->SetArray( *iDesCArrayText ); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CBrowserBookmarksEditFormApModel::SetCurrentWapApL |
|
119 // --------------------------------------------------------- |
|
120 // |
|
121 void CBrowserBookmarksEditFormApModel::SetCurrentWapApL |
|
122 ( const TFavouritesWapAp& aAp ) |
|
123 { |
|
124 TInt count = iApList->Count(); |
|
125 |
|
126 if ( count ) |
|
127 { |
|
128 // Default value index is KErrNotFound ("Invalid" is displayed). |
|
129 // If AP is Null, or specified but does not exist, this value is used. |
|
130 TInt index = KErrNotFound; |
|
131 if ( aAp.IsDefault() ) |
|
132 { |
|
133 // For "Default" Ap-s, highlight 0th element "Default". |
|
134 index = 0; |
|
135 } |
|
136 else if ( !aAp.IsNull() ) |
|
137 { |
|
138 // Get index of element having this ApId. If not found, index stays |
|
139 // KErrNotFound (That will display the "Invalid" text). |
|
140 // |
|
141 // "Null" and "Default" checks already done: call to ApId is safe. |
|
142 TUint32 apId = aAp.ApId(); |
|
143 TInt i; |
|
144 for ( i = 0; i < count; i++ ) |
|
145 { |
|
146 if ( iApList->At( i )->Uid() == apId ) |
|
147 { |
|
148 // Got it; i is the index of the AP in the array. Add 1 |
|
149 // to it, since 0th element is "Default". |
|
150 index = i + 1; |
|
151 break; |
|
152 } |
|
153 } |
|
154 } |
|
155 iTextValue->SetCurrentValueIndex( index ); |
|
156 } |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------- |
|
160 // CBrowserBookmarksEditFormApModel::CurrentWapAp |
|
161 // --------------------------------------------------------- |
|
162 // |
|
163 TFavouritesWapAp CBrowserBookmarksEditFormApModel::CurrentWapAp() const |
|
164 { |
|
165 TFavouritesWapAp ap; |
|
166 |
|
167 ap.SetNull(); // "Null" value used if no AP-s exist or AP is "Invalid". |
|
168 |
|
169 TInt count = iApList->Count(); |
|
170 if ( count ) |
|
171 { |
|
172 TInt index = iTextValue->CurrentValueIndex(); |
|
173 if ( index == 0 ) |
|
174 { |
|
175 // Oth element ("Default"). |
|
176 ap.SetDefault(); |
|
177 } |
|
178 else if ( index > 0 && index <= count ) |
|
179 { |
|
180 // "Index-1" is a valid index into array (real AP). |
|
181 // |
|
182 // (CurrentValueIndex may return an out-of-bounds value, if AP is |
|
183 // "Invalid". This value is -1; but is not well published; so |
|
184 // instead of testing for -1, we do proper range checking. That |
|
185 // is the safest we can do, and adds minuscule overhead.) |
|
186 ap.SetApId( iApList->At( index - 1 )->Uid() ); |
|
187 } |
|
188 } |
|
189 |
|
190 return ap; |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CBrowserBookmarksEditFormApModel::ApCount |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 TInt CBrowserBookmarksEditFormApModel::ApCount() |
|
198 { |
|
199 return iApList->Count(); |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // CBrowserBookmarksEditFormApModel::CBrowserBookmarksEditFormApModel |
|
204 // --------------------------------------------------------- |
|
205 // |
|
206 CBrowserBookmarksEditFormApModel::CBrowserBookmarksEditFormApModel |
|
207 ( MCommsModel& aCommsModel ) |
|
208 : iCommsModel( &aCommsModel ) |
|
209 { |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------- |
|
213 // CBrowserBookmarksEditFormApModel::ConstructL |
|
214 // --------------------------------------------------------- |
|
215 // |
|
216 void CBrowserBookmarksEditFormApModel::ConstructL() |
|
217 { |
|
218 iApList = new (ELeave) CApListItemList(); |
|
219 iDesCArrayText = new (ELeave) CDesCArrayFlat( KGranularity ); |
|
220 iTextArray = CAknQueryValueTextArray::NewL(); |
|
221 iTextArray->SetArray( *iDesCArrayText ); |
|
222 iTextValue = CAknQueryValueText::NewL(); |
|
223 iTextValue->SetArrayL( iTextArray ); |
|
224 |
|
225 ReadApDataL(); |
|
226 } |
|
227 |
|
228 // End of File |
|