summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-06-15 16:11:48 +0200
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-06-15 16:18:25 +0200
commitce409be66b8e62f36f210818e7fcaffcf29935ce (patch)
treeaed4de32a5a11b3f208d54d462cd5e01734e6b23 /examples/network
parente294deae12b433c9923869dd5257c7801a3ba03a (diff)
Improving the code for setting the default IAP.
First we ask if there is already active IAP. If yes, we will use that one, if not IAP dialog will pop-up. This strategy should save us from some dialogs when accessing the network.
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/ftp/ftp.pro2
-rw-r--r--examples/network/ftp/main.cpp99
2 files changed, 75 insertions, 26 deletions
diff --git a/examples/network/ftp/ftp.pro b/examples/network/ftp/ftp.pro
index b958f6a479..0fb99346ef 100644
--- a/examples/network/ftp/ftp.pro
+++ b/examples/network/ftp/ftp.pro
@@ -15,5 +15,5 @@ include($$QT_SOURCE_TREE/examples/examplebase.pri)
symbian {
TARGET.CAPABILITY="NetworkServices"
TARGET.UID3 = 0xA000A648
- LIBS+=-lesock # For IAP selection
+ LIBS+=-lesock -lconnmon # For IAP selection
} \ No newline at end of file
diff --git a/examples/network/ftp/main.cpp b/examples/network/ftp/main.cpp
index a92a8b2ed4..118dcfc5c6 100644
--- a/examples/network/ftp/main.cpp
+++ b/examples/network/ftp/main.cpp
@@ -48,32 +48,82 @@
#include <es_sock.h>
#include <sys/socket.h>
+#include <rconnmon.h>
#include <net/if.h>
-static void setDefaultIapL()
-{
- TInt err = KErrNone;
- RSocketServ serv;
- CleanupClosePushL(serv);
- User::LeaveIfError(serv.Connect());
+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
+}
- RConnection conn;
- CleanupClosePushL(conn);
- User::LeaveIfError(conn.Open(serv));
- User::LeaveIfError(conn.Start());
-
- _LIT(KIapNameSetting, "IAP\\Name");
- TBuf8<50> iapName;
- User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iapName));
- iapName.ZeroTerminate();
-
- conn.Stop();
- CleanupStack::PopAndDestroy(&conn);
- CleanupStack::PopAndDestroy(&serv);
+static void setDefaultIapL() {
+ RConnectionMonitor monitor;
+ CleanupClosePushL(monitor);
+ monitor.ConnectL();
+ TUint count;
+ TRequestStatus status;
+ TUint ids[ 15 ];
- struct ifreq ifReq;
- strcpy( ifReq.ifr_name, (char*)iapName.Ptr());
- User::LeaveIfError(setdefaultif( &ifReq ));
+ 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();
+
+ struct ifreq ifReq;
+ strcpy( ifReq.ifr_name, (char*)iap8Name.Ptr());
+ User::LeaveIfError(setdefaultif( &ifReq ));
+
+ conn.Stop();
+ conn.Close();
+ serv.Close();
+ CleanupStack::PopAndDestroy(&conn);
+ CleanupStack::PopAndDestroy(&serv);
+ }
+ monitor.Close();
+ CleanupStack::PopAndDestroy(&monitor);
}
static int setDefaultIap()
@@ -86,13 +136,12 @@ static int setDefaultIap()
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(ftp);
-
#ifdef Q_OS_SYMBIAN
setDefaultIap();
// Change current directory from default private to c:\data
// in order that user can access the downloaded content
QDir::setCurrent( "c:\\data" );
-#endif
+#endif
QApplication app(argc, argv);
FtpWindow ftpWin;
#ifdef Q_OS_SYMBIAN
@@ -100,6 +149,6 @@ int main(int argc, char *argv[])
ftpWin.showMaximized();
#else
ftpWin.show();
-#endif
+#endif
return ftpWin.exec();
}