diff options
author | Aleksandar Sasha Babic <aleksandar.babic@nokia.com> | 2009-04-28 12:02:40 (GMT) |
---|---|---|
committer | Aleksandar Sasha Babic <aleksandar.babic@nokia.com> | 2009-04-28 12:02:40 (GMT) |
commit | 251e63bfcd5db5947ad3b6699cae6fd3d67d873c (patch) | |
tree | 2502cde31f58195ed8e04a840290afe0c5c60ab5 | |
parent | 0e5fd6b280e597edd8b5884f38e7450891224846 (diff) | |
download | Qt-251e63bfcd5db5947ad3b6699cae6fd3d67d873c.zip Qt-251e63bfcd5db5947ad3b6699cae6fd3d67d873c.tar.gz Qt-251e63bfcd5db5947ad3b6699cae6fd3d67d873c.tar.bz2 |
Simple refactoring how the data are fetched and stored.
-rw-r--r-- | tests/auto/network-settings.h | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 9afe815..952ab89 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -131,11 +131,10 @@ public: if(QtNetworkSettings::entries.contains("server.ip")) { QtNetworkSettingsRecord* entry = entries["server.ip"]; - QByteArray valueAsAscii = entry->recordValue().toAscii(); - if(*serverIPAscii == 0) { - ::strcpy(serverIPAscii, valueAsAscii.data()); + if(serverIp.isNull()) { + serverIp = entry->recordValue().toAscii(); } - return serverIPAscii; + return serverIp.data(); } #endif //return "10.10.0.147"; @@ -178,13 +177,22 @@ public: #ifdef Q_OS_SYMBIAN static void setDefaultIap() { + loadDefaultIap(); + struct ifreq ifReq; - strcpy( ifReq.ifr_name, getDefaultIap().toAscii().constData()); + if(entries.contains("iap.default")) { + QtNetworkSettingsRecord* entry = entries["iap.default"]; + QByteArray tmp(entry->recordValue().toAscii()); + strcpy( ifReq.ifr_name, tmp.data()); + } + else // some default value + strcpy( ifReq.ifr_name, "Lab"); + int err = setdefaultif( &ifReq ); if(err) - printf("Setting default IAP - '%s' failed: %d\n", getDefaultIap().toAscii().constData(), err); + printf("Setting default IAP - '%s' failed: %d\n", ifReq.ifr_name, err); else - printf("'%s' used as an default IAP\n", getDefaultIap().toAscii().constData()); + printf("'%s' used as an default IAP\n", ifReq.ifr_name); } #endif @@ -196,20 +204,14 @@ private: static bool bDefaultIapLoaded; static bool bTestSettingsLoaded; static QString iapFileFullPath; - static QString strDefaultIap; - static char serverIPAscii[256]; - - static QString getDefaultIap() { - if(!bDefaultIapLoaded) { - if(!loadDefaultIap()) // not found in file - use default - strDefaultIap = QString("Lab"); - } - - return strDefaultIap; - } + static QByteArray serverIp; static bool loadDefaultIap() { + if(bDefaultIapLoaded) + return true; + QFile iapCfgFile(iapFileFullPath); + bool bFoundDefaultIapTag = false; if (iapCfgFile.open(QFile::ReadOnly)) { @@ -222,21 +224,24 @@ private: if(line.contains(QString("[DEFAULT]"))) { bFoundDefaultIapTag = true; - } else if(line.startsWith(QString("[")) && bFoundDefaultIapTag) { - bFoundDefaultIapTag = false; - break; // stick to default + } else if(line.contains(QString("[")) && bFoundDefaultIapTag) { + break; } if(bFoundDefaultIapTag && line.contains("name")) { int position = line.indexOf(QString("=")); position += QString("=").length(); - strDefaultIap = line.mid(position).trimmed(); + + //create record + QtNetworkSettingsRecord *entry = + new QtNetworkSettingsRecord( QString("iap.default"), line.mid(position).trimmed() ); + entries.insert(entry->recordName(), entry); break; } } while (!line.isNull()); } - return bFoundDefaultIapTag; + return bDefaultIapLoaded = bFoundDefaultIapTag; } static bool loadTestSettings() { @@ -290,8 +295,7 @@ QHash<QString, QtNetworkSettingsRecord* > QtNetworkSettings::entries = QHash<QSt bool QtNetworkSettings::bDefaultIapLoaded = false; bool QtNetworkSettings::bTestSettingsLoaded = false; QString QtNetworkSettings::iapFileFullPath = QString("C:\\Data\\iap.txt"); -QString QtNetworkSettings::strDefaultIap = QString(""); -char QtNetworkSettings::serverIPAscii[256]; +QByteArray QtNetworkSettings::serverIp; #endif #ifdef Q_OS_SYMBIAN |