• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 
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.
8 
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.
13 
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.
18 */
19 
20 #include "config.h"
21 #include "NetworkStateNotifier.h"
22 
23 #if PLATFORM(QT) && ENABLE(QT_BEARER)
24 
25 #include "NetworkStateNotifierPrivate.h"
26 #include "qnetworkconfigmanager.h"
27 
28 namespace WebCore {
29 
NetworkStateNotifierPrivate(NetworkStateNotifier * notifier)30 NetworkStateNotifierPrivate::NetworkStateNotifierPrivate(NetworkStateNotifier* notifier)
31     : m_configurationManager(new QNetworkConfigurationManager())
32     , m_online(m_configurationManager->isOnline())
33     , m_networkAccessAllowed(true)
34     , m_notifier(notifier)
35 {
36     Q_ASSERT(notifier);
37     connect(m_configurationManager, SIGNAL(onlineStateChanged(bool)), this, SLOT(onlineStateChanged(bool)));
38 }
39 
onlineStateChanged(bool isOnline)40 void NetworkStateNotifierPrivate::onlineStateChanged(bool isOnline)
41 {
42     if (m_online == isOnline)
43         return;
44 
45     m_online = isOnline;
46     if (m_networkAccessAllowed)
47         m_notifier->updateState();
48 }
49 
networkAccessPermissionChanged(bool isAllowed)50 void NetworkStateNotifierPrivate::networkAccessPermissionChanged(bool isAllowed)
51 {
52     if (isAllowed == m_networkAccessAllowed)
53         return;
54 
55     m_networkAccessAllowed = isAllowed;
56     if (m_online)
57         m_notifier->updateState();
58 }
59 
~NetworkStateNotifierPrivate()60 NetworkStateNotifierPrivate::~NetworkStateNotifierPrivate()
61 {
62     delete m_configurationManager;
63 }
64 
updateState()65 void NetworkStateNotifier::updateState()
66 {
67     if (m_isOnLine == (p->m_online && p->m_networkAccessAllowed))
68         return;
69 
70     m_isOnLine = p->m_online && p->m_networkAccessAllowed;
71     if (m_networkStateChangedFunction)
72         m_networkStateChangedFunction();
73 }
74 
NetworkStateNotifier()75 NetworkStateNotifier::NetworkStateNotifier()
76     : m_isOnLine(true)
77     , m_networkStateChangedFunction(0)
78 {
79     p = new NetworkStateNotifierPrivate(this);
80     m_isOnLine = p->m_online && p->m_networkAccessAllowed;
81 }
82 
setNetworkAccessAllowed(bool isAllowed)83 void NetworkStateNotifier::setNetworkAccessAllowed(bool isAllowed)
84 {
85     p->networkAccessPermissionChanged(isAllowed);
86 }
87 
88 } // namespace WebCore
89 
90 #include "moc_NetworkStateNotifierPrivate.cpp"
91 
92 #endif
93