NetworkStateNotifierQt.cpp [plain text]
#include "config.h"
#include "NetworkStateNotifier.h"
#if (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT))
#include "NetworkStateNotifierPrivate.h"
#include <QNetworkConfigurationManager>
#include <QTimer>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
NetworkStateNotifierPrivate::NetworkStateNotifierPrivate(NetworkStateNotifier* notifier)
: m_online(false)
, m_networkAccessAllowed(true)
, m_notifier(notifier)
{
ASSERT(notifier);
QTimer::singleShot(0, this, SLOT(initialize()));
}
void NetworkStateNotifierPrivate::setNetworkAccessAllowed(bool isAllowed)
{
if (isAllowed == m_networkAccessAllowed)
return;
m_networkAccessAllowed = isAllowed;
if (m_online)
m_notifier->updateState();
}
void NetworkStateNotifierPrivate::setOnlineState(bool isOnline)
{
if (m_online == isOnline)
return;
m_online = isOnline;
if (m_networkAccessAllowed)
m_notifier->updateState();
}
void NetworkStateNotifierPrivate::initialize()
{
m_configurationManager = adoptPtr(new QNetworkConfigurationManager());
setOnlineState(m_configurationManager->isOnline());
connect(m_configurationManager.get(), SIGNAL(onlineStateChanged(bool)), this, SLOT(setOnlineState(bool)));
}
NetworkStateNotifierPrivate::~NetworkStateNotifierPrivate()
{
}
void NetworkStateNotifier::updateState()
{
if (m_isOnLine == p->effectivelyOnline())
return;
m_isOnLine = p->effectivelyOnline();
if (m_networkStateChangedFunction)
m_networkStateChangedFunction();
}
NetworkStateNotifier::NetworkStateNotifier()
: m_isOnLine(true)
, m_networkStateChangedFunction(0)
{
p = new NetworkStateNotifierPrivate(this);
m_isOnLine = p->effectivelyOnline();
}
void NetworkStateNotifier::setNetworkAccessAllowed(bool isAllowed)
{
p->setNetworkAccessAllowed(isAllowed);
}
}
#include "moc_NetworkStateNotifierPrivate.cpp"
#endif