Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
250 andreas 1
/*
2
 * Copyright (C) 2021, 2022 by Andreas Theofilu <andreas@theosys.at>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program 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
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#include <QObject>
20
 
21
#include "tqnetworkinfo.h"
22
#include "tpagemanager.h"
23
#include "terror.h"
24
 
25
TQNetworkInfo::TQNetworkInfo()
26
{
27
    DECL_TRACER("TQNetworkInfo::TQNetworkInfo()");
28
 
29
#if QT_VERSION >= QT_VERSION_CHECK(_SUPPORTED_MAJOR, _SUPPORTED_MINOR, _SUPPORTED_PATCH)
30
    if (!QNetworkInformation::instance())
31
    {
32
        if (!QNetworkInformation::loadDefaultBackend())
33
        {
34
            MSG_WARNING("No network backend available!");
35
            mInitialized = false;
36
            return;
37
        }
38
    }
39
 
40
    QNetworkInformation *inst = QNetworkInformation::instance();
41
    connect(inst, &QNetworkInformation::reachabilityChanged, this, &TQNetworkInfo::onReachabilityChanged);
42
    connect(inst, &QNetworkInformation::transportMediumChanged, this, &TQNetworkInfo::onTransportMediumChanged);
43
    QNetworkInformation::TransportMedium trans = inst->transportMedium();
44
    mType = toNetTransport(trans);
45
    mReachability = inst->reachability();
46
 
47
    if (mReachability == QNetworkInformation::Reachability::Disconnected)
48
    {
49
        mConnection = false;
50
 
51
        if (gPageManager)
52
            gPageManager->informTPanelNetwork(false, 0, mType);
53
    }
54
    else if (gPageManager)
55
    {
56
        gPageManager->informTPanelNetwork(true, mLevel, mType);
57
        mConnection = true;
58
    }
59
#else
60
    mConnection = true;
61
#endif
62
    mLevel = 6;     // Range is 0 - 6
63
    mInitialized = true;
64
}
65
 
66
TQNetworkInfo::~TQNetworkInfo()
67
{
68
    DECL_TRACER("TQNetworkInfo::~TQNetworkInfo()");
69
}
70
 
71
 
72
#if QT_VERSION >= QT_VERSION_CHECK(_SUPPORTED_MAJOR, _SUPPORTED_MINOR, _SUPPORTED_PATCH)
73
void TQNetworkInfo::onReachabilityChanged(QNetworkInformation::Reachability reachability)
74
{
75
    DECL_TRACER("TQNetworkInfo::onReachabilityChanged(QNetworkInformation::Reachability reachability)");
76
 
77
    mReachability = reachability;
78
    MSG_DEBUG("Rachability changed to " << (int)mReachability);
79
    if (reachability == QNetworkInformation::Reachability::Disconnected)
80
    {
81
        mConnection = false;
82
 
83
        if (gPageManager)
84
            gPageManager->informTPanelNetwork(false, 0, mType);
85
    }
86
    else if (gPageManager)
87
    {
88
        gPageManager->informTPanelNetwork(true, mLevel, mType);
89
        mConnection = true;
90
    }
91
}
92
 
93
void TQNetworkInfo::onTransportMediumChanged(QNetworkInformation::TransportMedium current)
94
{
95
    DECL_TRACER("TQNetworkInfo::onTransportMediumChanged(QNetworkInformation::TransportMedium current)");
96
 
97
    mType = toNetTransport(current);
98
    MSG_DEBUG("Transport changed to: " << mType);
99
    if (mReachability == QNetworkInformation::Reachability::Disconnected)
100
    {
101
        if (gPageManager)
102
            gPageManager->informTPanelNetwork(false, 0, mType);
103
    }
104
    else if (gPageManager)
105
        gPageManager->informTPanelNetwork(true, mLevel, mType);
106
}
107
 
108
TQNetworkInfo::NET_TRANSPORT TQNetworkInfo::toNetTransport(QNetworkInformation::TransportMedium trans)
109
{
110
    DECL_TRACER("TQNetworkInfo::toNetTransport(QNetworkInformation::TransportMedium trans)");
111
 
112
    NET_TRANSPORT net = NET_UNKNOWN;
113
 
114
    switch(trans)
115
    {
116
        case QNetworkInformation::TransportMedium::Ethernet:    net = NET_ETHERNET;  break;
117
        case QNetworkInformation::TransportMedium::Cellular:    net = NET_CELLULAR;  break;
118
        case QNetworkInformation::TransportMedium::WiFi:        net = NET_WIFI;      break;
119
        case QNetworkInformation::TransportMedium::Bluetooth:   net = NET_BLUETOOTH; break;
120
        case QNetworkInformation::TransportMedium::Unknown:     net = NET_UNKNOWN;   break;
121
    }
122
 
123
    return net;
124
}
125
#endif