summaryrefslogtreecommitdiffstats
path: root/examples/network
diff options
context:
space:
mode:
authorAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-07-03 15:53:26 (GMT)
committerAleksandar Sasha Babic <aleksandar.babic@nokia.com>2009-07-04 09:05:06 (GMT)
commit370bf22071f9064fd2a1d8de622c3503a465523b (patch)
tree55a198eea69273951d36556e1c623bf8324da4e9 /examples/network
parent6fa67856b88aaab401ef056b5f22d74a491857c3 (diff)
downloadQt-370bf22071f9064fd2a1d8de622c3503a465523b.zip
Qt-370bf22071f9064fd2a1d8de622c3503a465523b.tar.gz
Qt-370bf22071f9064fd2a1d8de622c3503a465523b.tar.bz2
We can store IAP selections in QSettings.
Might be usefull for later.
Diffstat (limited to 'examples/network')
-rw-r--r--examples/network/ftp/sym_iap_util.h85
1 files changed, 81 insertions, 4 deletions
diff --git a/examples/network/ftp/sym_iap_util.h b/examples/network/ftp/sym_iap_util.h
index 487aa8b..81bb1c4 100644
--- a/examples/network/ftp/sym_iap_util.h
+++ b/examples/network/ftp/sym_iap_util.h
@@ -44,11 +44,16 @@
// Symbian
#include <es_sock.h>
#include <es_enum.h>
+#include <commdbconnpref.h>
// OpenC
#include <sys/socket.h>
#include <net/if.h>
+//Qt
+#include <QSettings>
+#include <QStringList>
+
_LIT(KIapNameSetting, "IAP\\Name"); // text - mandatory
_LIT(KIapDialogPref, "IAP\\DialogPref"); // TUnit32 - optional
_LIT(KIapService, "IAP\\IAPService"); // TUnit32 - mandatory
@@ -57,6 +62,48 @@ _LIT(KIapBearer, "IAP\\IAPBearer"); // TUint32 - optional
_LIT(KIapBearerType, "IAP\\IAPBearerType"); // text - optional
_LIT(KIapNetwork, "IAP\\IAPNetwork"); // TUint32 - optional
+const QLatin1String qtOrganization("Trolltech");
+const QLatin1String qtModule("QtNetwork");
+const QLatin1String qtIapGroup("IAP");
+const QLatin1String namesArray("Names");
+const QLatin1String nameRecord("Name");
+
+
+void clearIapNamesSettings(QSettings &settings) {
+ settings.beginGroup(qtModule);
+ settings.beginGroup(qtIapGroup);
+ settings.remove(namesArray);
+ settings.endGroup();
+ settings.endGroup();
+}
+
+void writeIapNamesSettings(QSettings &settings, const QStringList& iapNames) {
+ clearIapNamesSettings(settings);
+ settings.beginGroup(qtModule);
+ settings.beginGroup(qtIapGroup);
+ settings.beginWriteArray(namesArray);
+ for (int index = 0; index < iapNames.size(); ++index) {
+ settings.setArrayIndex(index);
+ settings.setValue(nameRecord, iapNames.at(index));
+ }
+ settings.endArray();
+ settings.endGroup();
+ settings.endGroup();
+}
+
+void readIapNamesSettings(QSettings &settings, QStringList& iapNames) {
+ settings.beginGroup(qtModule);
+ settings.beginGroup(qtIapGroup);
+ int last = settings.beginReadArray(namesArray);
+ for (int index = 0; index < last; ++index) {
+ settings.setArrayIndex(index);
+ iapNames.append(settings.value(nameRecord).toString());
+ }
+ settings.endArray();
+ settings.endGroup();
+ settings.endGroup();
+}
+
QString qt_TDesC2QStringL(const TDesC& aDescriptor)
{
#ifdef QT_NO_UNICODE
@@ -68,6 +115,12 @@ QString qt_TDesC2QStringL(const TDesC& aDescriptor)
static void qt_SetDefaultIapL()
{
+ // settings @ /c/data/.config/Trolltech.com
+ QSettings settings(QSettings::UserScope, qtOrganization);
+ // populate iap name list
+ QStringList iapNames;
+ readIapNamesSettings(settings, iapNames);
+
TUint count;
TBool activeLanConnectionFound = EFalse;
@@ -114,16 +167,40 @@ static void qt_SetDefaultIapL()
* no active LAN connections yet
* offer IAP dialog to user
*/
+ TCommDbConnPref prefs;
conn.Close(); // might be opened after attach
User::LeaveIfError(conn.Open(serv));
- User::LeaveIfError(conn.Start());
- User::LeaveIfError(conn.GetDesSetting(TPtrC(KIapNameSetting), iapName));
+ prefs.SetDialogPreference( ECommDbDialogPrefPrompt );
+ User::LeaveIfError(conn.Start(prefs));
+ conn.GetDesSetting(TPtrC(KIapNameSetting), iapName);
+ conn.GetDesSetting(TPtrC(KIapServiceType), iapServiceType);
}
- iapName.ZeroTerminate();
-
+ // for some reason makes
+ // setting default more stable
conn.Stop();
+ // just in case ...
+ iapName.ZeroTerminate();
+ iapServiceType.ZeroTerminate();
+
+ QString iapNameValue((char*)iapName.Ptr());
+ QString iapServiceTypeValue((char*)iapServiceType.Ptr());
+
+ // save IAP name for latere user
+ // but only if (W)LAN service type
+ // and is not already in QSettings
+ if(iapServiceTypeValue.contains(QString("LANService"))) {
+ if(iapNames.contains(iapNameValue) && iapNames.first() == iapNameValue) {
+ // no need to update
+ } else {
+ // new selection alway on top
+ iapNames.removeAll(iapNameValue);
+ iapNames.prepend(iapNameValue);
+ writeIapNamesSettings(settings, iapNames);
+ }
+ }
+
struct ifreq ifReq;
strcpy(ifReq.ifr_name, (char*)iapName.Ptr());