1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * |
5 * under the terms of "Eclipse Public License v1.0" |
5 * This program is free software: you can redistribute it and/or modify |
6 * which accompanies this distribution, and is available |
6 * it under the terms of the GNU Lesser General Public License as published by |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * the Free Software Foundation, version 2.1 of the License. |
8 * |
8 * |
9 * Initial Contributors: |
9 * This program is distributed in the hope that it will be useful, |
10 * Nokia Corporation - initial contribution. |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * Contributors: |
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
15 * |
15 * along with this program. If not, |
16 */ |
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
17 |
17 * |
|
18 * Description: |
|
19 * |
|
20 */ |
18 |
21 |
19 #include "WebNetworkSession.h" |
22 #include "WebNetworkSession.h" |
20 |
23 |
|
24 /*! |
|
25 Constructs a Web Network Session based on \a QNetworkConfiguration with the given \a parent. |
|
26 |
|
27 \sa QNetworkConfiguration |
|
28 */ |
21 WebNetworkSession::WebNetworkSession(const QNetworkConfiguration &config, QObject *parent) |
29 WebNetworkSession::WebNetworkSession(const QNetworkConfiguration &config, QObject *parent) |
22 : QObject(parent) |
30 : QObject(parent) |
23 { |
31 { |
24 m_NetworkSession = new QNetworkSession(config); |
32 m_NetworkSession = new QNetworkSession(config); |
25 |
33 |
|
34 // set up the handlers for QNetworkSession signals |
|
35 connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), |
|
36 this, SLOT(handlePreferredConfigurationChanged(const QNetworkConfiguration&, bool))); |
|
37 connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(handleNewConfigurationActivated())); |
|
38 connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), |
|
39 this, SLOT(handleStateChanged(QNetworkSession::State))); |
|
40 connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(handleOpened())); |
|
41 connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(handleClosed())); |
|
42 connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), |
|
43 this, SLOT(handleError(QNetworkSession::SessionError))); |
|
44 |
26 m_NetworkSession->open(); |
45 m_NetworkSession->open(); |
27 |
46 } |
28 connect(m_NetworkSession, SIGNAL(preferredConfigurationChanged(const QNetworkConfiguration&, bool)), |
47 |
29 this, SLOT(preferredConfigurationChanged(const QNetworkConfiguration&, bool))); |
48 /*! |
30 connect(m_NetworkSession, SIGNAL(newConfigurationActivated()), this, SLOT(newConfigurationActivated())); |
49 Frees the resources associated with the WebNetworkSession object. |
31 connect(m_NetworkSession, SIGNAL(stateChanged(QNetworkSession::State)), |
50 */ |
32 this, SLOT(stateChanged(QNetworkSession::State))); |
|
33 connect(m_NetworkSession, SIGNAL(opened()), this, SLOT(opened())); |
|
34 connect(m_NetworkSession, SIGNAL(closed()), this, SLOT(closed())); |
|
35 connect(m_NetworkSession, SIGNAL(error(QNetworkSession::SessionError)), |
|
36 this, SLOT(error(QNetworkSession::SessionError))); |
|
37 } |
|
38 |
|
39 WebNetworkSession::~WebNetworkSession() |
51 WebNetworkSession::~WebNetworkSession() |
40 { |
52 { |
41 // Close the network connection session before delete. |
53 // Close the network connection session before delete. |
42 m_NetworkSession->close(); |
54 m_NetworkSession->close(); |
43 delete m_NetworkSession; |
55 delete m_NetworkSession; |
44 } |
56 } |
45 |
57 |
46 void WebNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) |
58 /*! |
|
59 Handle the preferredConfigurationChanged signal from Network Session. |
|
60 |
|
61 It emits networkNameChnaged signal if it migrates to the new QNetworkConfiguration. |
|
62 */ |
|
63 void WebNetworkSession::handlePreferredConfigurationChanged(const QNetworkConfiguration &config, bool isSeamless) |
47 { |
64 { |
48 bool isSelected = TRUE; |
65 bool isSelected = TRUE; |
49 |
66 |
50 if (isSeamless) |
67 if (isSeamless) |
51 { |
68 { |
52 m_NetworkSession->migrate(); |
69 m_NetworkSession->migrate(); |
53 qDebug() << "Migrate to new Network Connection: " << config.name(); |
70 qDebug() << "Migrate to new Network Connection: " << config.name(); |
|
71 emit sessionConfigurationChanged(config); |
54 } |
72 } |
55 else |
73 else |
56 { |
74 { |
57 // Dialog Box to select |
75 // Dialog Box to select |
58 if (isSelected) |
76 if (isSelected) |
59 { |
77 { |
60 m_NetworkSession->migrate(); |
78 m_NetworkSession->migrate(); |
61 qDebug() << "Migrate to new Network Connection: " << config.name(); |
79 qDebug() << "Migrate to new Network Connection: " << config.name(); |
|
80 emit sessionConfigurationChanged(config); |
62 } |
81 } |
63 else |
82 else |
64 { |
83 { |
65 m_NetworkSession->ignore(); |
84 m_NetworkSession->ignore(); |
66 qDebug() << "Ignore new Network Connection: " << config.name(); |
85 qDebug() << "Ignore new Network Connection: " << config.name(); |
67 } |
86 } |
68 } |
87 } |
69 } |
88 } |
70 |
89 |
71 void WebNetworkSession::newConfigurationActivated() |
90 /*! |
|
91 Handle the newConfigurationActivated from Network Session. |
|
92 |
|
93 It emits networknameChanged signal with current QNetworkConfiguration. |
|
94 |
|
95 */ |
|
96 void WebNetworkSession::handleNewConfigurationActivated() |
72 { |
97 { |
73 bool isConnected = TRUE; |
98 bool isConnected = TRUE; |
74 |
99 |
75 // isConnectionGood = testConnection(); |
100 // isConnectionGood = testConnection(); |
76 if (isConnected) |
101 if (isConnected) |
111 case QNetworkSession::Roaming: |
143 case QNetworkSession::Roaming: |
112 qDebug() << "Roaming"; |
144 qDebug() << "Roaming"; |
113 break; |
145 break; |
114 default: |
146 default: |
115 qDebug() << "Unknown"; |
147 qDebug() << "Unknown"; |
116 } |
148 } |
117 } |
149 emit sessionStateChanged(m_NetworkSession->configuration(), state); |
118 |
150 } |
119 void WebNetworkSession::opened() |
151 |
120 { |
152 /*! |
|
153 Handle the opened signal from Network Session. |
|
154 |
|
155 It emits networkNameChanged signal with activeConfiguration. |
|
156 */ |
|
157 void WebNetworkSession::handleOpened() |
|
158 { |
121 qDebug() << "Session Opened"; |
159 qDebug() << "Session Opened"; |
122 } |
160 |
123 |
161 emit sessionConfigurationChanged(activeConfiguration()); |
124 void WebNetworkSession::closed() |
162 } |
|
163 |
|
164 /*! |
|
165 Handle the closed signal from Network Session. |
|
166 */ |
|
167 void WebNetworkSession::handleClosed() |
125 { |
168 { |
126 qDebug() << "Session Closed"; |
169 qDebug() << "Session Closed"; |
127 } |
170 } |
128 |
171 |
129 void WebNetworkSession::error(QNetworkSession::SessionError error) |
172 /*! |
|
173 Handle the error signal from Network Session. |
|
174 */ |
|
175 void WebNetworkSession::handleError(QNetworkSession::SessionError error) |
130 { |
176 { |
131 switch (error) |
177 switch (error) |
132 { |
178 { |
133 case QNetworkSession::UnknownSessionError: |
179 case QNetworkSession::UnknownSessionError: |
134 qDebug() << "UnknownSessionError"; |
180 qDebug() << "UnknownSessionError"; |