mirror of
https://gitee.com/shuto/cordova-plugin-network-information.git
synced 2025-01-18 21:52:48 +08:00
added ubuntu support
This commit is contained in:
commit
50218b43e2
11
plugin.xml
11
plugin.xml
@ -66,6 +66,17 @@ xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
</platform>
|
||||
|
||||
|
||||
<!-- ubuntu -->
|
||||
<platform name="ubuntu">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="Camera">
|
||||
<param policy_group="connectivity" policy_version="1" />
|
||||
</feature>
|
||||
</config-file>
|
||||
<header-file src="src/ubuntu/network_information.h" />
|
||||
<source-file src="src/ubuntu/network_information.cpp" />
|
||||
</platform>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
|
63
src/ubuntu/network_information.cpp
Normal file
63
src/ubuntu/network_information.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "network_information.h"
|
||||
|
||||
void NetworkInformation::getConnectionInfo(int scId, int ecId) {
|
||||
Q_UNUSED(ecId);
|
||||
|
||||
QString result;
|
||||
QNetworkInfo::NetworkMode networkMode = m_systemNetworkInfo.currentNetworkMode();
|
||||
QNetworkInfo::NetworkStatus networkStatus = m_systemNetworkInfo.networkStatus(networkMode, 0);
|
||||
QNetworkInfo::CellDataTechnology cellDataTechnology = m_systemNetworkInfo.currentCellDataTechnology(0);
|
||||
|
||||
if (networkStatus == QNetworkInfo::NoNetworkAvailable)
|
||||
result = "Connection.NONE";
|
||||
|
||||
switch (networkMode) {
|
||||
case QNetworkInfo::WimaxMode:
|
||||
case QNetworkInfo::WlanMode:
|
||||
result = "Connection.WIFI";
|
||||
break;
|
||||
case QNetworkInfo::EthernetMode:
|
||||
result = "Connection.ETHERNET";
|
||||
break;
|
||||
case QNetworkInfo::LteMode:
|
||||
result = "Connection.CELL_4G";
|
||||
break;
|
||||
case QNetworkInfo::GsmMode:
|
||||
case QNetworkInfo::CdmaMode:
|
||||
case QNetworkInfo::TdscdmaMode:
|
||||
case QNetworkInfo::WcdmaMode:
|
||||
switch (cellDataTechnology) {
|
||||
case QNetworkInfo::UmtsDataTechnology:
|
||||
case QNetworkInfo::HspaDataTechnology:
|
||||
result = "Connection.CELL_3G";
|
||||
break;
|
||||
case QNetworkInfo::EdgeDataTechnology:
|
||||
case QNetworkInfo::GprsDataTechnology:
|
||||
result = "Connection.CELL_2G";
|
||||
break;
|
||||
case QNetworkInfo::UnknownDataTechnology:
|
||||
result = "Connection.UNKNOWN";
|
||||
break;
|
||||
}
|
||||
case QNetworkInfo::BluetoothMode:
|
||||
case QNetworkInfo::UnknownMode:
|
||||
result = "Connection.UNKNOWN";
|
||||
break;
|
||||
}
|
||||
|
||||
this->callback(scId, result);
|
||||
}
|
47
src/ubuntu/network_information.h
Normal file
47
src/ubuntu/network_information.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NETWORK_INFORMATION_H
|
||||
#define NETWORK_INFORMATION_H
|
||||
|
||||
#include <cplugin.h>
|
||||
|
||||
#include <QtSystemInfo>
|
||||
#include <QtCore>
|
||||
|
||||
class NetworkInformation: public CPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetworkInformation(Cordova *cordova): CPlugin(cordova) {}
|
||||
|
||||
virtual const QString fullName() override {
|
||||
return NetworkInformation::fullID();
|
||||
}
|
||||
|
||||
virtual const QString shortName() override {
|
||||
return "Connection";
|
||||
}
|
||||
|
||||
static const QString fullID() {
|
||||
return "NetworkStatus";
|
||||
}
|
||||
|
||||
public slots:
|
||||
void getConnectionInfo(int scId, int ecId);
|
||||
|
||||
private:
|
||||
QNetworkInfo m_systemNetworkInfo;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user