From be589f500689395f8579100a121bfdef7c3ed169 Mon Sep 17 00:00:00 2001 From: Aleksandar Sasha Babic Date: Thu, 18 Jun 2009 22:58:48 +0200 Subject: The native Symbian code that helps to select and set default IAP has been moved to separate header. This should make the code shareable among other examples. The location of the header is not perfect. Unfortunately, there is no shared include area for Qt examples. The proper way woud be to have proper API that manages IAP. --- examples/network/ftp/ftp.pro | 1 + examples/network/ftp/main.cpp | 90 +------------------------ examples/network/ftp/sym_iap_util.h | 131 ++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 87 deletions(-) create mode 100644 examples/network/ftp/sym_iap_util.h diff --git a/examples/network/ftp/ftp.pro b/examples/network/ftp/ftp.pro index 634c43c..c70b812 100644 --- a/examples/network/ftp/ftp.pro +++ b/examples/network/ftp/ftp.pro @@ -13,6 +13,7 @@ INSTALLS += target sources include($$QT_SOURCE_TREE/examples/examplebase.pri) symbian { + HEADERS += sym_iap_util.h INCLUDEPATH += $$APP_LAYER_SYSTEMINCLUDE TARGET.CAPABILITY="NetworkServices" TARGET.UID3 = 0xA000A648 diff --git a/examples/network/ftp/main.cpp b/examples/network/ftp/main.cpp index 17423b8..ecabb31 100644 --- a/examples/network/ftp/main.cpp +++ b/examples/network/ftp/main.cpp @@ -44,99 +44,15 @@ #ifdef Q_OS_SYMBIAN #include -#include - -#include -#include -#include -#include - -QString qt_TDesC2QStringL(const TDesC& aDescriptor) { -#ifdef QT_NO_UNICODE - return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); -#else - return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length()); -#endif -} - -static void setDefaultIapL() { - RConnectionMonitor monitor; - CleanupClosePushL(monitor); - monitor.ConnectL(); - TUint count; - TRequestStatus status; - TUint ids[ 15 ]; - - monitor.GetConnectionCount( count, status ); - User::WaitForRequest( status ); - if(status.Int() != KErrNone) { - User::Leave(status.Int()); - } - - TUint numSubConnections; - - if(count > 0) { - for ( TInt i = 1; i <= count; i++ ) { - User::LeaveIfError(monitor.GetConnectionInfo( i, ids[ i-1 ], numSubConnections )); - } - /* - * get IAP value for first active connection - */ - TBuf< 50 > iapName; - monitor.GetStringAttribute( ids[ 0 ], 0, KIAPName, iapName, status ); - User::WaitForRequest( status ); - if ( status.Int() != KErrNone ) { - User::Leave(status.Int()); - } else { - QString strIapName = qt_TDesC2QStringL(iapName); - struct ifreq ifReq; - strcpy( ifReq.ifr_name, strIapName.toLatin1().data()); - User::LeaveIfError(setdefaultif( &ifReq )); - } - } else { - /* - * no active connections yet - * use IAP dialog to select one - */ - RSocketServ serv; - CleanupClosePushL(serv); - User::LeaveIfError(serv.Connect()); - - RConnection conn; - CleanupClosePushL(conn); - User::LeaveIfError(conn.Open(serv)); - User::LeaveIfError(conn.Start()); - - _LIT(KIapNameSetting, "IAP\\Name"); - TBuf8<50> iap8Name; - User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iap8Name)); - iap8Name.ZeroTerminate(); - - conn.Stop(); - CleanupStack::PopAndDestroy(&conn); - CleanupStack::PopAndDestroy(&serv); - - struct ifreq ifReq; - strcpy( ifReq.ifr_name, (char*)iap8Name.Ptr()); - User::LeaveIfError(setdefaultif( &ifReq )); - - } - monitor.Close(); - CleanupStack::PopAndDestroy(&monitor); -} - -static int setDefaultIap() -{ - TRAPD(err, setDefaultIapL()); - return err; -} +#include +#include "sym_iap_util.h" #endif int main(int argc, char *argv[]) { Q_INIT_RESOURCE(ftp); #ifdef Q_OS_SYMBIAN - setDefaultIap(); + qt_SetDefaultIap(); // Change current directory from default private to c:\data // in order that user can access the downloaded content QDir::setCurrent( "c:\\data" ); diff --git a/examples/network/ftp/sym_iap_util.h b/examples/network/ftp/sym_iap_util.h new file mode 100644 index 0000000..14df5af --- /dev/null +++ b/examples/network/ftp/sym_iap_util.h @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef QSYM_IAP_UTIL_H +#define QSYM_IAP_UTIL_H + +#include +#include +#include +#include + +QString qt_TDesC2QStringL(const TDesC& aDescriptor) +{ +#ifdef QT_NO_UNICODE + return QString::fromLocal8Bit(aDescriptor.Ptr(), aDescriptor.Length()); +#else + return QString::fromUtf16(aDescriptor.Ptr(), aDescriptor.Length()); +#endif +} + +static void qt_SetDefaultIapL() +{ + TUint count; + TRequestStatus status; + TUint ids[15]; + + RSocketServ serv; + CleanupClosePushL(serv); + + RConnection conn; + CleanupClosePushL(conn); + + RConnectionMonitor monitor; + CleanupClosePushL(monitor); + + monitor.ConnectL(); + monitor.GetConnectionCount(count, status); + User::WaitForRequest(status); + if(status.Int() != KErrNone) { + User::Leave(status.Int()); + } + + TUint numSubConnections; + + if(count > 0) { + for (TInt i = 1; i <= count; i++) { + User::LeaveIfError(monitor.GetConnectionInfo(i, ids[i-1], numSubConnections)); + } + /* + * get IAP value for first active connection + */ + TBuf< 50 > iapName; + monitor.GetStringAttribute(ids[0], 0, KIAPName, iapName, status); + User::WaitForRequest(status); + if (status.Int() != KErrNone) { + User::Leave(status.Int()); + } else { + QString strIapName = qt_TDesC2QStringL(iapName); + struct ifreq ifReq; + strcpy(ifReq.ifr_name, strIapName.toLatin1().data()); + User::LeaveIfError(setdefaultif(&ifReq)); + } + } else { + /* + * no active connections yet + * use IAP dialog to select one + */ + User::LeaveIfError(serv.Connect()); + User::LeaveIfError(conn.Open(serv)); + User::LeaveIfError(conn.Start()); + + _LIT(KIapNameSetting, "IAP\\Name"); + TBuf8<50> iap8Name; + User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iap8Name)); + iap8Name.ZeroTerminate(); + + conn.Stop(); + + struct ifreq ifReq; + strcpy(ifReq.ifr_name, (char*)iap8Name.Ptr()); + User::LeaveIfError(setdefaultif(&ifReq)); + } + CleanupStack::PopAndDestroy(&monitor); + CleanupStack::PopAndDestroy(&conn); + CleanupStack::PopAndDestroy(&serv); +} + +static int qt_SetDefaultIap() +{ + TRAPD(err, qt_SetDefaultIapL()); + return err; +} + +#endif // QSYM_IAP_UTIL_H -- cgit v0.12