1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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:BSD$ |
|
10 ** You may use this file under the terms of the BSD license as follows: |
|
11 ** |
|
12 ** "Redistribution and use in source and binary forms, with or without |
|
13 ** modification, are permitted provided that the following conditions are |
|
14 ** met: |
|
15 ** * Redistributions of source code must retain the above copyright |
|
16 ** notice, this list of conditions and the following disclaimer. |
|
17 ** * Redistributions in binary form must reproduce the above copyright |
|
18 ** notice, this list of conditions and the following disclaimer in |
|
19 ** the documentation and/or other materials provided with the |
|
20 ** distribution. |
|
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
|
22 ** the names of its contributors may be used to endorse or promote |
|
23 ** products derived from this software without specific prior written |
|
24 ** permission. |
|
25 ** |
|
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
37 ** $QT_END_LICENSE$ |
|
38 ** |
|
39 ****************************************************************************/ |
|
40 |
|
41 #include "sessionwidget.h" |
|
42 #include "qnetworkconfigmanager.h" |
|
43 |
|
44 SessionWidget::SessionWidget(const QNetworkConfiguration &config, QWidget *parent) |
|
45 : QWidget(parent) |
|
46 { |
|
47 setupUi(this); |
|
48 |
|
49 session = new QNetworkSession(config, this); |
|
50 |
|
51 connect(session, SIGNAL(stateChanged(QNetworkSession::State)), |
|
52 this, SLOT(updateSession())); |
|
53 connect(session, SIGNAL(error(QNetworkSession::SessionError)), |
|
54 this, SLOT(updateSessionError(QNetworkSession::SessionError))); |
|
55 |
|
56 updateSession(); |
|
57 |
|
58 sessionId->setText(QString("0x%1").arg(qulonglong(session), 8, 16, QChar('0'))); |
|
59 |
|
60 configuration->setText(session->configuration().name()); |
|
61 |
|
62 connect(openSessionButton, SIGNAL(clicked()), |
|
63 this, SLOT(openSession())); |
|
64 connect(openSyncSessionButton, SIGNAL(clicked()), |
|
65 this, SLOT(openSyncSession())); |
|
66 connect(closeSessionButton, SIGNAL(clicked()), |
|
67 this, SLOT(closeSession())); |
|
68 connect(stopSessionButton, SIGNAL(clicked()), |
|
69 this, SLOT(stopSession())); |
|
70 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) |
|
71 connect(deleteSessionButton, SIGNAL(clicked()), |
|
72 this, SLOT(deleteSession())); |
|
73 #endif |
|
74 } |
|
75 |
|
76 SessionWidget::~SessionWidget() |
|
77 { |
|
78 delete session; |
|
79 } |
|
80 |
|
81 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) |
|
82 void SessionWidget::deleteSession() |
|
83 { |
|
84 delete this; |
|
85 } |
|
86 #endif |
|
87 |
|
88 void SessionWidget::updateSession() |
|
89 { |
|
90 updateSessionState(session->state()); |
|
91 |
|
92 if (session->configuration().type() == QNetworkConfiguration::InternetAccessPoint) |
|
93 bearer->setText(session->configuration().bearerName()); |
|
94 else { |
|
95 QNetworkConfigurationManager mgr; |
|
96 QNetworkConfiguration c = mgr.configurationFromIdentifier(session->sessionProperty("ActiveConfiguration").toString()); |
|
97 bearer->setText(c.bearerName()); |
|
98 } |
|
99 |
|
100 interfaceName->setText(session->interface().humanReadableName()); |
|
101 interfaceGuid->setText(session->interface().name()); |
|
102 } |
|
103 |
|
104 void SessionWidget::openSession() |
|
105 { |
|
106 clearError(); |
|
107 session->open(); |
|
108 updateSession(); |
|
109 } |
|
110 |
|
111 void SessionWidget::openSyncSession() |
|
112 { |
|
113 clearError(); |
|
114 session->open(); |
|
115 session->waitForOpened(); |
|
116 updateSession(); |
|
117 } |
|
118 |
|
119 void SessionWidget::closeSession() |
|
120 { |
|
121 clearError(); |
|
122 session->close(); |
|
123 updateSession(); |
|
124 } |
|
125 |
|
126 void SessionWidget::stopSession() |
|
127 { |
|
128 clearError(); |
|
129 session->stop(); |
|
130 updateSession(); |
|
131 } |
|
132 |
|
133 void SessionWidget::updateSessionState(QNetworkSession::State state) |
|
134 { |
|
135 QString s = tr("%1 (%2)"); |
|
136 |
|
137 switch (state) { |
|
138 case QNetworkSession::Invalid: |
|
139 s = s.arg(tr("Invalid")); |
|
140 break; |
|
141 case QNetworkSession::NotAvailable: |
|
142 s = s.arg(tr("Not Available")); |
|
143 break; |
|
144 case QNetworkSession::Connecting: |
|
145 s = s.arg(tr("Connecting")); |
|
146 break; |
|
147 case QNetworkSession::Connected: |
|
148 s = s.arg(tr("Connected")); |
|
149 break; |
|
150 case QNetworkSession::Closing: |
|
151 s = s.arg(tr("Closing")); |
|
152 break; |
|
153 case QNetworkSession::Disconnected: |
|
154 s = s.arg(tr("Disconnected")); |
|
155 break; |
|
156 case QNetworkSession::Roaming: |
|
157 s = s.arg(tr("Roaming")); |
|
158 break; |
|
159 default: |
|
160 s = s.arg(tr("Unknown")); |
|
161 } |
|
162 |
|
163 if (session->isOpen()) |
|
164 s = s.arg(tr("Open")); |
|
165 else |
|
166 s = s.arg(tr("Closed")); |
|
167 |
|
168 sessionState->setText(s); |
|
169 } |
|
170 |
|
171 void SessionWidget::updateSessionError(QNetworkSession::SessionError error) |
|
172 { |
|
173 lastError->setText(QString::number(error)); |
|
174 errorString->setText(session->errorString()); |
|
175 } |
|
176 |
|
177 void SessionWidget::clearError() |
|
178 { |
|
179 lastError->clear(); |
|
180 errorString->clear(); |
|
181 } |
|