summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/WebCore/platform/network/qt/NetworkStateNotifierQt.cpp
blob: e694264875cd06f98c32ee72644e9866c6513b7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
    Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "config.h"
#include "NetworkStateNotifier.h"

#include "NetworkStateNotifierPrivate.h"
#include "qnetworkconfigmanager.h"

using namespace QtMobility;

namespace WebCore {

NetworkStateNotifierPrivate::NetworkStateNotifierPrivate(NetworkStateNotifier* notifier)
    : m_configurationManager(new QNetworkConfigurationManager())
    , m_online(m_configurationManager->isOnline())
    , m_networkAccessAllowed(true)
    , m_notifier(notifier)
{
    Q_ASSERT(notifier);
    connect(m_configurationManager, SIGNAL(onlineStateChanged(bool)), this, SLOT(onlineStateChanged(bool)));
}

void NetworkStateNotifierPrivate::onlineStateChanged(bool isOnline)
{
    if (m_online == isOnline)
        return;

    m_online = isOnline;
    if (m_networkAccessAllowed)
        m_notifier->updateState();
}

void NetworkStateNotifierPrivate::networkAccessPermissionChanged(bool isAllowed)
{
    if (isAllowed == m_networkAccessAllowed)
        return;

    m_networkAccessAllowed = isAllowed;
    if (m_online)
        m_notifier->updateState();
}

NetworkStateNotifierPrivate::~NetworkStateNotifierPrivate()
{
    delete m_configurationManager;
}

void NetworkStateNotifier::updateState()
{
    if (m_isOnLine == (p->m_online && p->m_networkAccessAllowed))
        return;

    m_isOnLine = p->m_online && p->m_networkAccessAllowed;
    if (m_networkStateChangedFunction)
        m_networkStateChangedFunction();
}

NetworkStateNotifier::NetworkStateNotifier()
    : m_isOnLine(true)
    , m_networkStateChangedFunction(0)
{
    p = new NetworkStateNotifierPrivate(this);
    m_isOnLine = p->m_online && p->m_networkAccessAllowed;
}

void NetworkStateNotifier::setNetworkAccessAllowed(bool isAllowed)
{
    p->networkAccessPermissionChanged(isAllowed);
}

} // namespace WebCore

#include "moc_NetworkStateNotifierPrivate.cpp"