author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 19 | fcece45ef507 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
9 |
** $QT_BEGIN_LICENSE:BSD$ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
10 |
** You may use this file under the terms of the BSD license as follows: |
0 | 11 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
12 |
** "Redistribution and use in source and binary forms, with or without |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
13 |
** modification, are permitted provided that the following conditions are |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
14 |
** met: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
15 |
** * Redistributions of source code must retain the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
16 |
** notice, this list of conditions and the following disclaimer. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
17 |
** * Redistributions in binary form must reproduce the above copyright |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
18 |
** notice, this list of conditions and the following disclaimer in |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
19 |
** the documentation and/or other materials provided with the |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
20 |
** distribution. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
21 |
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
22 |
** the names of its contributors may be used to endorse or promote |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
23 |
** products derived from this software without specific prior written |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
24 |
** permission. |
0 | 25 |
** |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
26 |
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
27 |
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
28 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
29 |
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
30 |
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
31 |
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
32 |
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
33 |
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
34 |
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
35 |
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
36 |
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
0 | 37 |
** $QT_END_LICENSE$ |
38 |
** |
|
39 |
****************************************************************************/ |
|
40 |
#ifndef QSYM_IAP_UTIL_H |
|
41 |
#define QSYM_IAP_UTIL_H |
|
42 |
||
43 |
// Symbian |
|
44 |
#include <utf.h> |
|
45 |
#include <es_sock.h> |
|
46 |
#include <in_sock.h> |
|
47 |
#include <es_enum.h> |
|
48 |
#include <in_iface.h> |
|
49 |
#include <commdbconnpref.h> |
|
50 |
#include <e32cmn.h> |
|
51 |
||
52 |
// OpenC |
|
53 |
#include <sys/socket.h> |
|
54 |
#include <net/if.h> |
|
55 |
||
56 |
//Qt |
|
57 |
#include <QSettings> |
|
58 |
#include <QStringList> |
|
59 |
//#include <QTextCodec> |
|
60 |
||
61 |
_LIT(KIapNameSetting, "IAP\\Name"); // text - mandatory |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
62 |
_LIT(KIapTableIdField, "IAP\\Id"); |
0 | 63 |
_LIT(KIapDialogPref, "IAP\\DialogPref"); // TUnit32 - optional |
64 |
_LIT(KIapService, "IAP\\IAPService"); // TUnit32 - mandatory |
|
65 |
_LIT(KIapServiceType, "IAP\\IAPServiceType"); // text - mandatory |
|
66 |
_LIT(KIapBearer, "IAP\\IAPBearer"); // TUint32 - optional |
|
67 |
_LIT(KIapBearerType, "IAP\\IAPBearerType"); // text - optional |
|
68 |
_LIT(KIapNetwork, "IAP\\IAPNetwork"); // TUint32 - optional |
|
69 |
||
70 |
const QLatin1String qtOrganizationTag("Trolltech"); |
|
71 |
const QLatin1String qtNetworkModuleTag("QtNetwork"); |
|
72 |
const QLatin1String iapGroupTag("IAP"); |
|
73 |
const QLatin1String iapNamesArrayTag("Names"); |
|
74 |
const QLatin1String iapNameItemTag("Name"); |
|
75 |
||
76 |
static QTextCodec *utf16LETextCodec = 0; |
|
77 |
||
78 |
void clearIapNamesSettings(QSettings &settings) { |
|
79 |
settings.beginGroup(qtNetworkModuleTag); |
|
80 |
settings.beginGroup(iapGroupTag); |
|
81 |
settings.remove(iapNamesArrayTag); |
|
82 |
settings.endGroup(); |
|
83 |
settings.endGroup(); |
|
84 |
} |
|
85 |
||
86 |
void writeIapNamesSettings(QSettings &settings, const QStringList& iapNames) { |
|
87 |
clearIapNamesSettings(settings); |
|
88 |
settings.beginGroup(qtNetworkModuleTag); |
|
89 |
settings.beginGroup(iapGroupTag); |
|
90 |
settings.beginWriteArray(iapNamesArrayTag); |
|
91 |
for (int index = 0; index < iapNames.size(); ++index) { |
|
92 |
settings.setArrayIndex(index); |
|
93 |
settings.setValue(iapNameItemTag, iapNames.at(index)); |
|
94 |
} |
|
95 |
settings.endArray(); |
|
96 |
settings.endGroup(); |
|
97 |
settings.endGroup(); |
|
98 |
} |
|
99 |
||
100 |
void readIapNamesSettings(QSettings &settings, QStringList& iapNames) { |
|
101 |
settings.beginGroup(qtNetworkModuleTag); |
|
102 |
settings.beginGroup(iapGroupTag); |
|
103 |
int last = settings.beginReadArray(iapNamesArrayTag); |
|
104 |
for (int index = 0; index < last; ++index) { |
|
105 |
settings.setArrayIndex(index); |
|
106 |
iapNames.append(settings.value(iapNameItemTag).toString()); |
|
107 |
} |
|
108 |
settings.endArray(); |
|
109 |
settings.endGroup(); |
|
110 |
settings.endGroup(); |
|
111 |
} |
|
112 |
||
113 |
static QString qt_TNameToQString(TName data) { |
|
114 |
if(utf16LETextCodec == 0) |
|
115 |
utf16LETextCodec = QTextCodec::codecForName("UTF-16LE"); |
|
116 |
||
117 |
QByteArray tmpByteArray = QByteArray::fromRawData((char*)(data.PtrZ()), data.Length() * 2); |
|
118 |
return utf16LETextCodec->toUnicode(tmpByteArray); |
|
119 |
} |
|
120 |
||
121 |
static QString qt_InterfaceInfoL() |
|
122 |
{ |
|
123 |
QString output; |
|
124 |
||
125 |
TBuf8<512> buffer; |
|
126 |
TBuf<128> t; |
|
127 |
TAutoClose<RSocketServ> ss; |
|
128 |
User::LeaveIfError(ss.iObj.Connect()); |
|
129 |
ss.PushL(); |
|
130 |
||
131 |
TAutoClose<RSocket> sock; |
|
132 |
User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); |
|
133 |
sock.PushL(); |
|
134 |
||
135 |
User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl)); |
|
136 |
||
137 |
TProtocolDesc in; |
|
138 |
User::LeaveIfError(sock.iObj.Info(in)); |
|
139 |
printf("EPOC32 IP Configuration TCPIP Version %d.%d.%d\n", in.iVersion.iMajor, in.iVersion.iMinor, in.iVersion.iBuild); |
|
140 |
||
141 |
TPckgBuf<TSoInetInterfaceInfo> info, next; |
|
142 |
||
143 |
TInt res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, info); |
|
144 |
if(res!=KErrNone) |
|
145 |
User::Leave(res); |
|
146 |
TInt count = 0; |
|
147 |
while(res==KErrNone) { |
|
148 |
res=sock.iObj.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, next); |
|
149 |
||
150 |
if(info().iName != _L("") && info().iName != _L("loop6") && info().iName != _L("loop4")) { |
|
151 |
printf("Interface %d\n", count++); |
|
152 |
||
153 |
printf("Name \"%s\"\n", qt_TNameToQString(info().iName).toLatin1().data()); |
|
154 |
printf("NIF tag \"%s\"\n", qt_TNameToQString(info().iTag).toLatin1().data()); |
|
155 |
||
156 |
printf("State "); |
|
157 |
switch (info().iState) |
|
158 |
{ |
|
159 |
case EIfPending: |
|
160 |
printf("pending\n"); |
|
161 |
break; |
|
162 |
case EIfUp: |
|
163 |
printf("up\n"); |
|
164 |
break; |
|
165 |
case EIfBusy: |
|
166 |
printf("busy\n"); |
|
167 |
break; |
|
168 |
default: |
|
169 |
printf("down\n"); |
|
170 |
break; |
|
171 |
} |
|
172 |
||
173 |
printf("Mtu %d\n", info().iMtu); |
|
174 |
printf("Speed Metric %d\n", info().iSpeedMetric); |
|
175 |
||
176 |
printf("Features:"); |
|
177 |
info().iFeatures & KIfIsLoopback ? printf(" loopback") : printf(""); |
|
178 |
info().iFeatures & KIfIsDialup ? printf(" dialup") : printf(""); |
|
179 |
info().iFeatures & KIfIsPointToPoint ? printf(" pointtopoint") : printf(""); |
|
180 |
info().iFeatures & KIfCanBroadcast ? printf(" canbroadcast") : printf(""); |
|
181 |
info().iFeatures & KIfCanMulticast ? printf(" canmulticast") : printf(""); |
|
182 |
info().iFeatures & KIfCanSetMTU ? printf(" cansetmtu") : printf(""); |
|
183 |
info().iFeatures & KIfHasHardwareAddr ? printf(" hardwareaddr") : printf(""); |
|
184 |
info().iFeatures & KIfCanSetHardwareAddr ? printf(" cansethardwareaddr") : printf(""); |
|
185 |
printf("\n"); |
|
186 |
||
187 |
TName address; |
|
188 |
info().iAddress.Output(address); |
|
189 |
printf("Addr: %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
190 |
||
191 |
if(info().iAddress.IsLinkLocal()) { |
|
192 |
printf(" -link local\n"); |
|
193 |
} else if(info().iAddress.IsSiteLocal()) { |
|
194 |
printf(" -site local\n"); |
|
195 |
} else { |
|
196 |
printf(" -global\n"); |
|
197 |
} |
|
198 |
||
199 |
info().iNetMask.Output(address); |
|
200 |
printf("Netmask %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
201 |
||
202 |
info().iBrdAddr.Output(address); |
|
203 |
printf("Broadcast address %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
204 |
||
205 |
info().iDefGate.Output(address); |
|
206 |
printf("Gatew: %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
207 |
||
208 |
info().iNameSer1.Output(address); |
|
209 |
printf("DNS 1: %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
210 |
||
211 |
info().iNameSer2.Output(address); |
|
212 |
printf("DNS 2: %s\n", qt_TNameToQString(address).toLatin1().data()); |
|
213 |
||
214 |
if (info().iHwAddr.Family() != KAFUnspec) { |
|
215 |
printf("Hardware address "); |
|
216 |
TUint j; |
|
217 |
for(j = sizeof(SSockAddr) ; j < sizeof(SSockAddr) + 6 ; ++j) { |
|
218 |
if(j < (TUint)info().iHwAddr.Length()) { |
|
219 |
printf("%02X", info().iHwAddr[j]); |
|
220 |
} else { |
|
221 |
printf("??"); |
|
222 |
} |
|
223 |
if(j < sizeof(SSockAddr) + 5) |
|
224 |
printf("-"); |
|
225 |
else |
|
226 |
printf("\n"); |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
230 |
if(res == KErrNone) { |
|
231 |
info = next; |
|
232 |
printf("\n"); |
|
233 |
} else { |
|
234 |
printf("\n"); |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
sock.Pop(); |
|
239 |
ss.Pop(); |
|
240 |
||
241 |
return output; |
|
242 |
} |
|
243 |
||
244 |
static QString qt_RouteInfoL() { |
|
245 |
QString output; |
|
246 |
TAutoClose<RSocketServ> ss; |
|
247 |
User::LeaveIfError(ss.iObj.Connect()); |
|
248 |
ss.PushL(); |
|
249 |
||
250 |
TAutoClose<RSocket> sock; |
|
251 |
User::LeaveIfError(sock.iObj.Open(ss.iObj, _L("udp"))); |
|
252 |
sock.PushL(); |
|
253 |
||
254 |
TSoInetRouteInfo routeInfo; |
|
255 |
TPckg<TSoInetRouteInfo> routeInfoPkg(routeInfo); |
|
256 |
||
257 |
TName destAddr; |
|
258 |
TName netMask; |
|
259 |
TName gateway; |
|
260 |
TName ifAddr; |
|
261 |
||
262 |
// Begins enumeration of routes by setting this option |
|
263 |
User::LeaveIfError(sock.iObj.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl)); |
|
264 |
||
265 |
// The TSoInetRouteInfo contains information for a new route each time GetOpt returns KErrNone |
|
266 |
for(TInt i = 0; sock.iObj.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, routeInfoPkg) == KErrNone ; i++) |
|
267 |
{ |
|
268 |
// Extract the destination and netmask |
|
269 |
routeInfo.iDstAddr.Output(destAddr); |
|
270 |
routeInfo.iNetMask.Output(netMask); |
|
271 |
routeInfo.iGateway.Output(gateway); |
|
272 |
routeInfo.iIfAddr.Output(ifAddr); |
|
273 |
/* |
|
274 |
if(destAddr.Length() <= 2) |
|
275 |
continue; |
|
276 |
||
277 |
if(netMask.Find(_L("255.255.255.255")) != KErrNotFound |
|
278 |
|| netMask.Find(_L("0.0.0.0")) != KErrNotFound |
|
279 |
|| netMask.Find(_L("ffff:ffff:ffff:ffff")) != KErrNotFound) |
|
280 |
continue; |
|
281 |
*/ |
|
282 |
printf("Route Info #[%i]\n", i); |
|
283 |
printf("DstAddr %s\n", qt_TNameToQString(destAddr).toLatin1().data()); |
|
284 |
printf("NetMask %s\n", qt_TNameToQString(netMask).toLatin1().data()); |
|
285 |
printf("Gateway %s\n", qt_TNameToQString(gateway).toLatin1().data()); |
|
286 |
printf("IfAddr %s\n", qt_TNameToQString(ifAddr).toLatin1().data()); |
|
287 |
printf("\n"); |
|
288 |
} |
|
289 |
||
290 |
sock.Pop(); |
|
291 |
ss.Pop(); |
|
292 |
||
293 |
return output; |
|
294 |
} |
|
295 |
||
296 |
QString qt_TDesC2QStringL(const TDesC& aDescriptor) |
|
297 |
{ |
|
298 |
#ifdef QT_NO_UNICODE |
|
299 |
return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); |
|
300 |
#else |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
301 |
return QString((const QChar *)aDescriptor.Ptr(), aDescriptor.Length()); |
0 | 302 |
#endif |
303 |
} |
|
304 |
||
305 |
static bool qt_SetDefaultIapName(const QString &iapName, int &error) { |
|
306 |
struct ifreq ifReq; |
|
307 |
// clear structure |
|
308 |
memset(&ifReq, 0, sizeof(struct ifreq)); |
|
309 |
// set IAP name value |
|
310 |
// make sure it is in UTF8 |
|
311 |
strcpy(ifReq.ifr_name, iapName.toUtf8().data()); |
|
312 |
||
313 |
if(setdefaultif(&ifReq) == 0) { |
|
314 |
// OK |
|
315 |
error = 0; |
|
316 |
return true; |
|
317 |
} else { |
|
318 |
error = errno; |
|
319 |
return false; |
|
320 |
} |
|
321 |
||
322 |
} |
|
323 |
static bool qt_SetDefaultSnapId(const int snapId, int &error) { |
|
324 |
struct ifreq ifReq; |
|
325 |
// clear structure |
|
326 |
memset(&ifReq, 0, sizeof(struct ifreq)); |
|
327 |
// set SNAP ID value |
|
328 |
ifReq.ifr_ifru.snap_id = snapId; |
|
329 |
||
330 |
if(setdefaultif(&ifReq) == 0) { |
|
331 |
// OK |
|
332 |
error = 0; |
|
333 |
return true; |
|
334 |
} else { |
|
335 |
error = errno; |
|
336 |
return false; |
|
337 |
} |
|
338 |
||
339 |
} |
|
340 |
||
341 |
static void qt_SaveIapName(QSettings& settings, QStringList& iapNames, QString& iapNameValue) { |
|
342 |
if(iapNames.contains(iapNameValue) && iapNames.first() == iapNameValue) { |
|
343 |
// no need to update |
|
344 |
} else { |
|
345 |
if(iapNameValue != QString("Easy WLAN")) { |
|
346 |
// new selection alway on top |
|
347 |
iapNames.removeAll(iapNameValue); |
|
348 |
iapNames.prepend(iapNameValue); |
|
349 |
writeIapNamesSettings(settings, iapNames); |
|
350 |
} else { |
|
351 |
// Unbeliveable ... if IAP dodn't exist before |
|
352 |
// no matter what you choose from IAP selection list |
|
353 |
// you will get "Easy WLAN" as IAP name value |
|
354 |
||
355 |
// somehow commsdb is not in sync |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
static QString qt_OfferIapDialog() { |
|
361 |
TBuf8<256> iapName; |
|
362 |
||
363 |
RSocketServ socketServ; |
|
364 |
CleanupClosePushL(socketServ); |
|
365 |
||
366 |
RConnection connection; |
|
367 |
CleanupClosePushL(connection); |
|
368 |
||
369 |
socketServ.Connect(); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
370 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
371 |
TCommDbConnPref prefs; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
372 |
prefs.SetDialogPreference(ECommDbDialogPrefPrompt); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
373 |
|
0 | 374 |
connection.Open(socketServ); |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
375 |
connection.Start(prefs); |
0 | 376 |
|
377 |
connection.GetDesSetting(TPtrC(KIapNameSetting), iapName); |
|
378 |
//connection.Stop(); |
|
379 |
||
380 |
iapName.ZeroTerminate(); |
|
381 |
QString strIapName((char*)iapName.Ptr()); |
|
382 |
||
383 |
int error = 0; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
384 |
if(!strIapName.isEmpty()) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
385 |
if(!qt_SetDefaultIapName(strIapName, error)) { |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
386 |
//printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
387 |
strIapName = QString(""); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
388 |
} |
0 | 389 |
} |
390 |
||
391 |
CleanupStack::PopAndDestroy(&connection); |
|
392 |
CleanupStack::PopAndDestroy(&socketServ); |
|
393 |
||
394 |
return strIapName; |
|
395 |
} |
|
396 |
||
397 |
static QString qt_CheckForActiveConnection() { |
|
398 |
TUint count; |
|
399 |
||
400 |
RSocketServ serv; |
|
401 |
CleanupClosePushL(serv); |
|
402 |
||
403 |
RConnection conn; |
|
404 |
CleanupClosePushL(conn); |
|
405 |
||
406 |
serv.Connect(); |
|
407 |
conn.Open(serv); |
|
408 |
||
409 |
TConnectionInfoBuf connInfo; |
|
410 |
||
411 |
TBuf8<256> iapName; |
|
412 |
TBuf8<256> iapServiceType; |
|
413 |
||
414 |
QString strIapName; |
|
415 |
||
416 |
if (conn.EnumerateConnections(count) == KErrNone) { |
|
417 |
if(count > 0) { |
|
418 |
for (TUint i = 1; i <= count; i++) { |
|
419 |
if (conn.GetConnectionInfo(i, connInfo) == KErrNone) { |
|
420 |
RConnection tempConn; |
|
421 |
CleanupClosePushL(tempConn); |
|
422 |
tempConn.Open(serv); |
|
423 |
if (tempConn.Attach(connInfo, RConnection::EAttachTypeNormal) == KErrNone) { |
|
424 |
tempConn.GetDesSetting(TPtrC(KIapNameSetting), iapName); |
|
425 |
tempConn.GetDesSetting(TPtrC(KIapServiceType), iapServiceType); |
|
426 |
//tempConn.Stop(); |
|
427 |
iapName.ZeroTerminate(); |
|
428 |
iapServiceType.ZeroTerminate(); |
|
429 |
||
430 |
// if(iapServiceType.Find(_L8("LANService")) != KErrNotFound) { |
|
431 |
// activeLanConnectionFound = ETrue; |
|
432 |
// break; |
|
433 |
// } |
|
434 |
strIapName = QString((char*)iapName.Ptr()); |
|
435 |
int error = 0; |
|
436 |
if(!qt_SetDefaultIapName(strIapName, error)) { |
|
437 |
//printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); |
|
438 |
strIapName = QString(""); |
|
439 |
} |
|
440 |
||
441 |
CleanupStack::PopAndDestroy(&tempConn); |
|
442 |
break; |
|
443 |
} |
|
444 |
} |
|
445 |
} |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
//conn.Stop(); |
|
450 |
||
451 |
CleanupStack::PopAndDestroy(&conn); |
|
452 |
CleanupStack::PopAndDestroy(&serv); |
|
453 |
||
454 |
return strIapName; |
|
455 |
} |
|
456 |
||
457 |
static QString qt_CheckSettingsForConnection(QStringList& iapNames) { |
|
458 |
QString strIapName; |
|
459 |
for(int index = 0; index < iapNames.size(); ++index) { |
|
460 |
strIapName = iapNames.at(index); |
|
461 |
int error = 0; |
|
462 |
if(!qt_SetDefaultIapName(strIapName, error)) { |
|
463 |
//printf("failed setdefaultif @ %i with %s and errno = %d \n", __LINE__, strIapName.toUtf8().data(), error); |
|
464 |
strIapName = QString(""); |
|
465 |
} else { |
|
466 |
return strIapName; |
|
467 |
} |
|
468 |
} |
|
469 |
return strIapName; |
|
470 |
} |
|
471 |
||
472 |
static void qt_SetDefaultIapL() |
|
473 |
{ |
|
474 |
// settings @ /c/data/.config/Trolltech.com |
|
475 |
QSettings settings(QSettings::UserScope, qtOrganizationTag); |
|
476 |
// populate iap name list |
|
477 |
QStringList iapNames; |
|
478 |
readIapNamesSettings(settings, iapNames); |
|
479 |
||
480 |
QString iapNameValue; |
|
481 |
||
482 |
iapNameValue = qt_CheckForActiveConnection(); |
|
483 |
||
484 |
if(!iapNameValue.isEmpty()) { |
|
485 |
qt_SaveIapName(settings, iapNames, iapNameValue); |
|
486 |
return; |
|
487 |
} |
|
488 |
||
489 |
iapNameValue = qt_CheckSettingsForConnection(iapNames); |
|
490 |
||
491 |
if(!iapNameValue.isEmpty()) { |
|
492 |
qt_SaveIapName(settings, iapNames, iapNameValue); |
|
493 |
return; |
|
494 |
} |
|
495 |
||
496 |
/* |
|
497 |
* no active LAN connections yet |
|
498 |
* no IAP in settings |
|
499 |
* offer IAP dialog to user |
|
500 |
*/ |
|
501 |
iapNameValue = qt_OfferIapDialog(); |
|
502 |
qt_SaveIapName(settings, iapNames, iapNameValue); |
|
503 |
return; |
|
504 |
||
505 |
} |
|
506 |
||
507 |
static int qt_SetDefaultIap() |
|
508 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
509 |
#ifndef __WINS__ |
0 | 510 |
TRAPD(err1, qt_SetDefaultIapL()); |
511 |
// TRAPD(err2, qt_InterfaceInfoL()); |
|
512 |
// TRAPD(err3, qt_RouteInfoL()); |
|
513 |
return err1; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
#else |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
return 0; // IAP dialog not required for emulator |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
#endif |
0 | 517 |
} |
518 |
||
519 |
#endif // QSYM_IAP_UTIL_H |