2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "NetworkStateNotifier.h"
23 #if (PLATFORM(QT) && !defined(QT_NO_BEARERMANAGEMENT))
25 #include "NetworkStateNotifierPrivate.h"
26 #include "qnetworkconfigmanager.h"
30 NetworkStateNotifierPrivate::NetworkStateNotifierPrivate(NetworkStateNotifier* notifier)
31 : m_configurationManager(new QNetworkConfigurationManager())
32 , m_online(m_configurationManager->isOnline())
33 , m_networkAccessAllowed(true)
34 , m_notifier(notifier)
37 connect(m_configurationManager, SIGNAL(onlineStateChanged(bool)), this, SLOT(onlineStateChanged(bool)));
40 void NetworkStateNotifierPrivate::onlineStateChanged(bool isOnline)
42 if (m_online == isOnline)
46 if (m_networkAccessAllowed)
47 m_notifier->updateState();
50 void NetworkStateNotifierPrivate::networkAccessPermissionChanged(bool isAllowed)
52 if (isAllowed == m_networkAccessAllowed)
55 m_networkAccessAllowed = isAllowed;
57 m_notifier->updateState();
60 NetworkStateNotifierPrivate::~NetworkStateNotifierPrivate()
62 delete m_configurationManager;
65 void NetworkStateNotifier::updateState()
67 if (m_isOnLine == (p->m_online && p->m_networkAccessAllowed))
70 m_isOnLine = p->m_online && p->m_networkAccessAllowed;
71 if (m_networkStateChangedFunction)
72 m_networkStateChangedFunction();
75 NetworkStateNotifier::NetworkStateNotifier()
77 , m_networkStateChangedFunction(0)
79 p = new NetworkStateNotifierPrivate(this);
80 m_isOnLine = p->m_online && p->m_networkAccessAllowed;
83 void NetworkStateNotifier::setNetworkAccessAllowed(bool isAllowed)
85 p->networkAccessPermissionChanged(isAllowed);
88 } // namespace WebCore
90 #include "moc_NetworkStateNotifierPrivate.cpp"