Skip to content

Commit

Permalink
[TIMOB-14768] Added Ti.Network.online
Browse files Browse the repository at this point in the history
  • Loading branch information
pec1985 committed Aug 6, 2013
1 parent 38d15c9 commit 9efc63d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/tibb/TiNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void TiNetwork::addObjectToParent(TiObject* parent, NativeObjectFactory* objectF
obj->release();
}

static Handle<Value> _getNetworkType(void*)
Handle<Value> TiNetwork::_getNetworkType(void*)
{
QNetworkConfigurationManager *qncm = new QNetworkConfigurationManager();
QList<QNetworkConfiguration> activeConfigs = qncm->allConfigurations(QNetworkConfiguration::Active);
QNetworkConfigurationManager qncm;
QList<QNetworkConfiguration> activeConfigs = qncm.allConfigurations(QNetworkConfiguration::Active);
foreach (QNetworkConfiguration qnc, activeConfigs){
int type = 0;
switch(qnc.bearerType())
Expand All @@ -55,18 +55,18 @@ static Handle<Value> _getNetworkType(void*)
case QNetworkConfiguration::BearerWCDMA : type = 5; break;
case QNetworkConfiguration::BearerHSPA : type = 6; break;
case QNetworkConfiguration::BearerBluetooth : type = 7; break;

default: type = 8; break;
}
return Number::New(type);
}
return Null();

}

static Handle<Value> _getNetworkTypeName(void*)
Handle<Value> TiNetwork::_getNetworkTypeName(void*)
{
QNetworkConfigurationManager *qncm = new QNetworkConfigurationManager();
QList<QNetworkConfiguration> activeConfigs = qncm->allConfigurations(QNetworkConfiguration::Active);
QNetworkConfigurationManager qncm;
QList<QNetworkConfiguration> activeConfigs = qncm.allConfigurations(QNetworkConfiguration::Active);
foreach (QNetworkConfiguration qnc, activeConfigs){
QString typeName = qnc.bearerTypeName();
return String::New(typeName.toLocal8Bit().constData());
Expand All @@ -75,6 +75,13 @@ static Handle<Value> _getNetworkTypeName(void*)

}

Handle<Value> TiNetwork::_getOnline(void*)
{
QNetworkConfigurationManager m;
return Boolean::New(m.isOnline());

}

void TiNetwork::onCreateStaticMembers()
{
TiProxy::onCreateStaticMembers();
Expand All @@ -86,6 +93,7 @@ void TiNetwork::onCreateStaticMembers()

TiPropertySetGetObject::createProperty(this, "networkTypeName", this, NULL, _getNetworkTypeName);
TiPropertySetGetObject::createProperty(this, "networkType", this, NULL, _getNetworkType);
TiPropertySetGetObject::createProperty(this, "online", this, NULL, _getOnline);
}

Handle<Value> TiNetwork::_encodeURIComponent(void* userContext, TiObject* /*caller*/, const Arguments& args)
Expand Down
4 changes: 3 additions & 1 deletion src/tibb/TiNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ class TiNetwork : public TiProxy
explicit TiNetwork(NativeObjectFactory* objectFactory);
TiNetwork(const TiNetwork&);
TiNetwork& operator=(const TiNetwork&);

static Handle<Value> _getNetworkTypeName(void*);
static Handle<Value> _getNetworkType(void*);
static Handle<Value> _getOnline(void*);
NativeObjectFactory* objectFactory_;
};

Expand Down

0 comments on commit 9efc63d

Please sign in to comment.