|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "sessionwidget.h" |
|
43 #include "qnetworkconfigmanager.h" |
|
44 |
|
45 SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) |
|
46 : QWidget(parent) |
|
47 { |
|
48 setupUi(this); |
|
49 |
|
50 session = new QNetworkSession(config, this); |
|
51 |
|
52 connect(session, SIGNAL(stateChanged(QNetworkSession::State)), |
|
53 this, SLOT(updateSession())); |
|
54 connect(session, SIGNAL(error(QNetworkSession::SessionError)), |
|
55 this, SLOT(updateSession())); |
|
56 |
|
57 updateSession(); |
|
58 |
|
59 sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0'))); |
|
60 |
|
61 configuration->setText(session->configuration().name()); |
|
62 |
|
63 connect(openSessionButton, SIGNAL(clicked()), |
|
64 this, SLOT(openSession())); |
|
65 connect(openSyncSessionButton, SIGNAL(clicked()), |
|
66 this, SLOT(openSyncSession())); |
|
67 connect(closeSessionButton, SIGNAL(clicked()), |
|
68 this, SLOT(closeSession())); |
|
69 connect(stopSessionButton, SIGNAL(clicked()), |
|
70 this, SLOT(stopSession())); |
|
71 } |
|
72 |
|
73 SessionWidget::~SessionWidget() |
|
74 { |
|
75 delete session; |
|
76 } |
|
77 |
|
78 void SessionWidget::updateSession() |
|
79 { |
|
80 updateSessionState(session->state()); |
|
81 updateSessionError(session->error()); |
|
82 |
|
83 if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) |
|
84 bearer->setText(session->configuration().bearerName()); |
|
85 else { |
|
86 QNetworkConfigurationManager mgr; |
|
87 QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); |
|
88 bearer->setText(c.bearerName()); |
|
89 } |
|
90 |
|
91 interfaceName->setText(session->interface().humanReadableName()); |
|
92 interfaceGuid->setText(session->interface().name()); |
|
93 } |
|
94 |
|
95 void SessionWidget::openSession() |
|
96 { |
|
97 session->open(); |
|
98 updateSession(); |
|
99 } |
|
100 |
|
101 void SessionWidget::openSyncSession() |
|
102 { |
|
103 session->open(); |
|
104 session->waitForOpened(); |
|
105 updateSession(); |
|
106 } |
|
107 |
|
108 void SessionWidget::closeSession() |
|
109 { |
|
110 session->close(); |
|
111 updateSession(); |
|
112 } |
|
113 |
|
114 void SessionWidget::stopSession() |
|
115 { |
|
116 session->stop(); |
|
117 updateSession(); |
|
118 } |
|
119 |
|
120 void SessionWidget::updateSessionState(QNetworkSession::State state) |
|
121 { |
|
122 QString s = tr("%1 (%2)"); |
|
123 |
|
124 switch (state) { |
|
125 case QNetworkSession::Invalid: |
|
126 s = s.arg(tr("Invalid")); |
|
127 break; |
|
128 case QNetworkSession::NotAvailable: |
|
129 s = s.arg(tr("Not Available")); |
|
130 break; |
|
131 case QNetworkSession::Connecting: |
|
132 s = s.arg(tr("Connecting")); |
|
133 break; |
|
134 case QNetworkSession::Connected: |
|
135 s = s.arg(tr("Connected")); |
|
136 break; |
|
137 case QNetworkSession::Closing: |
|
138 s = s.arg(tr("Closing")); |
|
139 break; |
|
140 case QNetworkSession::Disconnected: |
|
141 s = s.arg(tr("Disconnected")); |
|
142 break; |
|
143 case QNetworkSession::Roaming: |
|
144 s = s.arg(tr("Roaming")); |
|
145 break; |
|
146 default: |
|
147 s = s.arg(tr("Unknown")); |
|
148 } |
|
149 |
|
150 if (session->isOpen()) |
|
151 s = s.arg(tr("Open")); |
|
152 else |
|
153 s = s.arg(tr("Closed")); |
|
154 |
|
155 sessionState->setText(s); |
|
156 } |
|
157 |
|
158 void SessionWidget::updateSessionError(QNetworkSession::SessionError error) |
|
159 { |
|
160 lastError->setText(QString::number(error)); |
|
161 errorString->setText(session->errorString()); |
|
162 } |
|
163 |