|
1 /* |
|
2 * Copyright (c) 2004 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 * The model of the connections. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "ConnectionModel.h" |
|
22 #include "DisconnectDlgUi.h" |
|
23 #include "ConnectionInfo.h" |
|
24 #include "ConnectionCArray.h" |
|
25 #include "DisconnectDlgDialog.h" |
|
26 #include "ConnectionDialogsLogger.h" |
|
27 |
|
28 #include <aknnotedialog.h> |
|
29 #include <StringLoader.h> |
|
30 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
31 #include <commsdat.h> |
|
32 #else |
|
33 #include <commsdat.h> |
|
34 #include <commsdat_partner.h> |
|
35 #endif |
|
36 |
|
37 #include <DisconnectDlg.rsg> |
|
38 |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 _LIT( KMrouterName, "mRouter" ); |
|
43 |
|
44 // ================= MEMBER FUNCTIONS ======================= |
|
45 |
|
46 // --------------------------------------------------------- |
|
47 // CConnectionModel::NewL |
|
48 // --------------------------------------------------------- |
|
49 // |
|
50 CConnectionModel* CConnectionModel::NewL( |
|
51 CDisconnectDialogUi* aDisconnectDialogUi, |
|
52 CConnectionInfo* aConnectionInfo ) |
|
53 { |
|
54 CLOG_ENTERFN("CConnectionModel::NewL"); |
|
55 |
|
56 CConnectionModel* self = |
|
57 new( ELeave ) CConnectionModel( aDisconnectDialogUi ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL( aConnectionInfo ); |
|
60 CleanupStack::Pop( self ); |
|
61 CLOG_LEAVEFN("CConnectionModel::NewL"); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // CConnectionModel::~CConnectionModel |
|
68 // --------------------------------------------------------- |
|
69 // |
|
70 CConnectionModel::~CConnectionModel() |
|
71 { |
|
72 CLOG_ENTERFN("CConnectionModel::~CConnectionModel"); |
|
73 |
|
74 // RConnectionMonitor stop sending its notifications |
|
75 iMonitor.CancelNotifications(); |
|
76 iMonitor.Close(); |
|
77 |
|
78 // Delete connetion array and its content |
|
79 if( iConnArray ) |
|
80 { |
|
81 delete iConnArray; |
|
82 } |
|
83 |
|
84 CLOG_LEAVEFN("CConnectionModel::~CConnectionModel"); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CConnectionModel::CConnectionModel |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 CConnectionModel::CConnectionModel( CDisconnectDialogUi* aDisconnectDialogUi ) |
|
92 : iClosingConnectionIndex( 0 ), |
|
93 iDeleting( EFalse ) |
|
94 { |
|
95 iDisconnectDialogUi = aDisconnectDialogUi; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CConnectionModel::ConstructL |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CConnectionModel::ConstructL( CConnectionInfo* aConnectionInfo ) |
|
104 { |
|
105 CLOG_ENTERFN("CConnectionModel::ConstructL"); |
|
106 |
|
107 // Connect to the RConectionMonitor and listen to its event's |
|
108 iMonitor.ConnectL(); |
|
109 iMonitor.NotifyEventL( *this ); |
|
110 |
|
111 // Construct the connection array |
|
112 iConnArray = CConnectionCArray::NewL(); |
|
113 iConnArray->AppendL( aConnectionInfo ); |
|
114 |
|
115 // Start collecting the connection info |
|
116 InitConnectionArrayL(); |
|
117 |
|
118 // Sort on basis of connection duration. Oldest connection top. |
|
119 iConnArray->Sort(); |
|
120 |
|
121 CLOG_LEAVEFN("CConnectionModel::ConstructL"); |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------- |
|
126 // CConnectionModel::InitConnectionArrayL |
|
127 // --------------------------------------------------------- |
|
128 // |
|
129 void CConnectionModel::InitConnectionArrayL() |
|
130 { |
|
131 CLOG_ENTERFN("CConnectionModel::InitConnectionArrayL"); |
|
132 |
|
133 TUint i( 0 ); |
|
134 TUint connNum( 0 ); |
|
135 TUint subConnectionCount( 0 ); |
|
136 TUint connId( 0 ); |
|
137 CConnectionInfo* info = iConnArray->At( 0 ); |
|
138 TUint firstConnId = info->GetConnId(); |
|
139 |
|
140 TInt bearer( 0 ); |
|
141 TInt connStatus( 0 ); |
|
142 |
|
143 TRequestStatus status; |
|
144 TConnMonClientEnumBuf clientEnum; |
|
145 TBuf<CommsDat::KMaxTextLength> apName; |
|
146 |
|
147 iMonitor.GetConnectionCount( connNum, status ); |
|
148 User::WaitForRequest( status ); |
|
149 |
|
150 CLOG_WRITEF(_L( "status: %d" ), status.Int() ); |
|
151 CLOG_WRITEF(_L( "connNum: %d" ), connNum ); |
|
152 |
|
153 for( i = 1; i < connNum + 1; ++i ) |
|
154 { |
|
155 iMonitor.GetConnectionInfo( i, connId, subConnectionCount ); |
|
156 if( firstConnId != connId ) |
|
157 { // do not add the first connection to array, again |
|
158 iMonitor.GetStringAttribute( connId, 0, KIAPName, apName, status ); |
|
159 User::WaitForRequest( status ); |
|
160 |
|
161 CLOG_WRITEF(_L( "KIAPName status: %d" ), status.Int() ); |
|
162 |
|
163 iMonitor.GetPckgAttribute( connId, 0, KClientInfo, clientEnum, |
|
164 status ); |
|
165 User::WaitForRequest( status ); |
|
166 CLOG_WRITEF(_L( "KClientInfo status: %d" ), status.Int() ); |
|
167 |
|
168 |
|
169 iMonitor.GetIntAttribute( connId, 0, KBearer, bearer, status ); |
|
170 User::WaitForRequest( status ); |
|
171 CLOG_WRITEF(_L( "KBearer status: %d" ), status.Int() ); |
|
172 |
|
173 |
|
174 iMonitor.GetIntAttribute( connId, 0, KConnectionStatus, connStatus, |
|
175 status ); |
|
176 User::WaitForRequest( status ); |
|
177 CLOG_WRITEF(_L( "KConnectionStatus status: %d" ), status.Int() ); |
|
178 |
|
179 CLOG_WRITEF(_L( "bearer: %d" ), (TInt)bearer ); |
|
180 |
|
181 TUint iapId( 0 ); |
|
182 iMonitor.GetUintAttribute( connId, 0, KIAPId, iapId, status ); |
|
183 User::WaitForRequest( status ); |
|
184 CLOG_WRITEF(_L( "KIAPId status: %d" ), status.Int() ); |
|
185 CLOG_WRITEF(_L( "iapId: %d" ), iapId ); |
|
186 |
|
187 TConnMonTimeBuf timeBuf; |
|
188 iMonitor.GetPckgAttribute( connId, 0, KStartTime, timeBuf, status ); |
|
189 User::WaitForRequest( status ); |
|
190 CLOG_WRITEF(_L( "KStartTime status: %d" ), status.Int() ); |
|
191 |
|
192 switch( bearer ) |
|
193 { |
|
194 case EBearerGPRS : |
|
195 case EBearerEdgeGPRS : |
|
196 case EBearerExternalGPRS : |
|
197 case EBearerExternalEdgeGPRS : |
|
198 case EBearerWCDMA : |
|
199 case EBearerExternalWCDMA : |
|
200 #ifdef __WINS__ |
|
201 case EBearerLAN : |
|
202 #endif // WINS |
|
203 { |
|
204 if ( ( connStatus == KLinkLayerOpen ) || |
|
205 ( connStatus == KConnectionOpen && |
|
206 bearer >= EBearerExternalCSD ) ) |
|
207 { |
|
208 apName.Trim(); |
|
209 if( apName.Left( KMrouterName().Length() ). |
|
210 CompareF( KMrouterName ) ) |
|
211 { |
|
212 // add array: |
|
213 CConnectionInfo* info = CConnectionInfo::NewLC(); |
|
214 |
|
215 info->SetConnId( connId ); |
|
216 info->SetBearerType( bearer); |
|
217 info->SetIapNameL( apName ); |
|
218 info->SetIAPId( iapId ); |
|
219 info->SetClientInfo( clientEnum() ); |
|
220 info->SetStartTime( timeBuf() ); |
|
221 |
|
222 iConnArray->AppendL( info ); |
|
223 |
|
224 CleanupStack::Pop( info ); // info |
|
225 } |
|
226 } |
|
227 break; |
|
228 } |
|
229 default : |
|
230 { |
|
231 break; |
|
232 } |
|
233 } |
|
234 } |
|
235 } |
|
236 CLOG_LEAVEFN("CConnectionModel::InitConnectionArrayL"); |
|
237 |
|
238 } |
|
239 |
|
240 |
|
241 // --------------------------------------------------------- |
|
242 // CConnectionModel::EndConnection |
|
243 // --------------------------------------------------------- |
|
244 // |
|
245 TInt CConnectionModel::EndConnection( TUint aConnIndex ) |
|
246 { |
|
247 CLOG_ENTERFN("CConnectionModel::EndConnection"); |
|
248 |
|
249 // Syncron request, we will wait for ConnMonEvent |
|
250 // and the we can say the connection is closed. |
|
251 iClosingConnectionIndex = aConnIndex; |
|
252 CConnectionInfo* info = iConnArray->At( iClosingConnectionIndex ); |
|
253 TUint connId = info->GetConnId(); |
|
254 |
|
255 CLOG_WRITEF(_L( "connId: %d" ), connId ); |
|
256 |
|
257 TInt result = iMonitor.SetBoolAttribute( connId, 0, KConnectionStop, |
|
258 ETrue ); |
|
259 CLOG_WRITEF(_L( "result: %d" ), result ); |
|
260 |
|
261 if ( result ) // if there is an error, notifier will finish, |
|
262 { // so cancel all other notifications |
|
263 iMonitor.CancelNotifications(); |
|
264 if( KNullUnit == result ) |
|
265 { |
|
266 TUint iapId = info->GetIAPId(); |
|
267 iDisconnectDialogUi->SetClosedIapId( iapId ); |
|
268 } |
|
269 } |
|
270 else |
|
271 { |
|
272 iDeleting = ETrue; |
|
273 TUint iapId = info->GetIAPId(); |
|
274 iDisconnectDialogUi->SetClosedIapId( iapId ); |
|
275 } |
|
276 CLOG_LEAVEFN("CConnectionModel::EndConnection"); |
|
277 |
|
278 return result; |
|
279 } |
|
280 |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CConnectionModel::CancelNotification |
|
284 // --------------------------------------------------------- |
|
285 // |
|
286 void CConnectionModel::CancelNotification() |
|
287 { |
|
288 iMonitor.CancelNotifications(); |
|
289 } |
|
290 |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CConnectionModel::EventL |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 void CConnectionModel::EventL( const CConnMonEventBase& aConnMonEvent ) |
|
297 { |
|
298 CLOG_ENTERFN("CConnectionModel::EventL"); |
|
299 |
|
300 CConnectionInfo* info = iConnArray->At( iClosingConnectionIndex ); |
|
301 TUint connId = info->GetConnId(); |
|
302 CLOG_WRITEF(_L( "connId: %d" ), connId ); |
|
303 CLOG_WRITEF(_L( "iDeleting: %b" ), iDeleting ); |
|
304 |
|
305 if( iDeleting && iDisconnectDialogUi && |
|
306 ( EConnMonDeleteConnection == aConnMonEvent.EventType() ) |
|
307 && ( connId == aConnMonEvent.ConnectionId() ) ) |
|
308 { |
|
309 // notifier will finish, so cancel all other notifications |
|
310 iMonitor.CancelNotifications(); |
|
311 SelectedConnectionClosedL(); |
|
312 |
|
313 iDisconnectDialogUi->CompleteL( KErrNone ); |
|
314 } |
|
315 else if( iDisconnectDialogUi && |
|
316 ( EConnMonDeleteConnection == aConnMonEvent.EventType() ) ) |
|
317 { |
|
318 connId = aConnMonEvent.ConnectionId(); |
|
319 CLOG_WRITEF(_L( "connId: %d" ), connId ); |
|
320 |
|
321 TInt result = iConnArray->GetArrayIndex( connId ); |
|
322 CLOG_WRITEF(_L( "result: %d" ), result ); |
|
323 |
|
324 if ( result != KErrNotFound ) |
|
325 { |
|
326 iMonitor.CancelNotifications(); |
|
327 info = iConnArray->At( result ); |
|
328 TUint iapId = info->GetIAPId(); |
|
329 CLOG_WRITEF(_L( "iapId: %d" ), iapId ); |
|
330 |
|
331 iDisconnectDialogUi->SetClosedIapId( iapId ); |
|
332 iDisconnectDialogUi->CompleteL( KErrNone ); |
|
333 } |
|
334 } |
|
335 |
|
336 CLOG_LEAVEFN("CConnectionModel::EventL"); |
|
337 } |
|
338 |
|
339 |
|
340 // --------------------------------------------------------- |
|
341 // CConnectionModel::GetConnArray |
|
342 // --------------------------------------------------------- |
|
343 // |
|
344 CConnectionCArray* CConnectionModel::GetConnArray() const |
|
345 { |
|
346 return iConnArray; |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------- |
|
351 // CConnectionModel::SelectedConnectionClosedL |
|
352 // --------------------------------------------------------- |
|
353 // |
|
354 void CConnectionModel::SelectedConnectionClosedL() |
|
355 { |
|
356 CLOG_ENTERFN("CConnectionModel::SelectedConnectionClosedL"); |
|
357 |
|
358 // the connection is succesfully closed |
|
359 CConnectionInfo* info = iConnArray->At( iClosingConnectionIndex ); |
|
360 |
|
361 TPtrC iap = info->GetIapNameL(); |
|
362 TInt bearerType = info->GetBearerType(); |
|
363 |
|
364 if( bearerType < EBearerExternalCSD ) |
|
365 { |
|
366 InfoNoteL( R_QTN_NETW_CONF_CONN_DISCONNECTED, &iap ); |
|
367 } |
|
368 else |
|
369 { |
|
370 InfoNoteL( R_QTN_NETW_CONF_MODEM_CONN_DISCONNECTED ); |
|
371 } |
|
372 |
|
373 CLOG_LEAVEFN("CConnectionModel::SelectedConnectionClosedL"); |
|
374 } |
|
375 |
|
376 |
|
377 // --------------------------------------------------------- |
|
378 // CDisconnectDlgDialog::InfoNoteL |
|
379 // --------------------------------------------------------- |
|
380 // |
|
381 void CConnectionModel::InfoNoteL( const TInt aPromptResourceId, |
|
382 const TDesC* aPrompt ) |
|
383 { |
|
384 CLOG_ENTERFN("CConnectionModel::InfoNoteL"); |
|
385 |
|
386 HBufC* informationText; |
|
387 if ( aPrompt ) |
|
388 { |
|
389 informationText = StringLoader::LoadLC( aPromptResourceId, *aPrompt ); |
|
390 } |
|
391 else |
|
392 { |
|
393 informationText = StringLoader::LoadLC( aPromptResourceId ); |
|
394 } |
|
395 |
|
396 CAknNoteDialog* dialog = new( ELeave )CAknNoteDialog( |
|
397 REINTERPRET_CAST( CEikDialog**, &dialog ) ); |
|
398 dialog->PrepareLC( R_DISCONNECTDLG_CONFIRM_NOTE ); |
|
399 dialog->SetCurrentLabelL( EGeneralNote, informationText->Des() ); |
|
400 dialog->RunDlgLD( CAknNoteDialog::ELongTimeout, CAknNoteDialog::ENoTone ); |
|
401 |
|
402 CleanupStack::PopAndDestroy( informationText ); // informationText |
|
403 |
|
404 CLOG_LEAVEFN("CConnectionModel::InfoNoteL"); |
|
405 } |
|
406 |
|
407 |
|
408 // End of File |