React to network configuration changes, fixes #504
This commit is contained in:
parent
f91eb7936a
commit
a9b6bf5817
3 changed files with 96 additions and 4 deletions
|
@ -61,7 +61,9 @@ namespace {
|
||||||
const QString MESSAGE_CONTENT_TYPE_VENUE("messageVenue");
|
const QString MESSAGE_CONTENT_TYPE_VENUE("messageVenue");
|
||||||
}
|
}
|
||||||
|
|
||||||
FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
|
FernschreiberUtils::FernschreiberUtils(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, manager(new QNetworkAccessManager(this))
|
||||||
{
|
{
|
||||||
LOG("Initializing audio recorder...");
|
LOG("Initializing audio recorder...");
|
||||||
|
|
||||||
|
@ -92,8 +94,6 @@ FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent)
|
||||||
} else {
|
} else {
|
||||||
LOG("Unable to initialize geolocation!");
|
LOG("Unable to initialize geolocation!");
|
||||||
}
|
}
|
||||||
|
|
||||||
this->manager = new QNetworkAccessManager(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FernschreiberUtils::~FernschreiberUtils()
|
FernschreiberUtils::~FernschreiberUtils()
|
||||||
|
|
|
@ -53,7 +53,11 @@ namespace {
|
||||||
const QString CHAT_LIST_MAIN("chatListMain");
|
const QString CHAT_LIST_MAIN("chatListMain");
|
||||||
}
|
}
|
||||||
|
|
||||||
TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, QObject *parent) : QObject(parent), manager(new QNetworkAccessManager(this)), joinChatRequested(false)
|
TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, manager(new QNetworkAccessManager(this))
|
||||||
|
, networkConfigurationManager(new QNetworkConfigurationManager(this))
|
||||||
|
, joinChatRequested(false)
|
||||||
{
|
{
|
||||||
LOG("Initializing TD Lib...");
|
LOG("Initializing TD Lib...");
|
||||||
this->appSettings = appSettings;
|
this->appSettings = appSettings;
|
||||||
|
@ -82,6 +86,8 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
|
||||||
connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged()));
|
connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged()));
|
||||||
connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged()));
|
connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged()));
|
||||||
|
|
||||||
|
connect(networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(handleNetworkConfigurationChanged(QNetworkConfiguration)));
|
||||||
|
|
||||||
this->setLogVerbosityLevel();
|
this->setLogVerbosityLevel();
|
||||||
this->setOptionInteger("notification_group_count_max", 5);
|
this->setOptionInteger("notification_group_count_max", 5);
|
||||||
}
|
}
|
||||||
|
@ -1459,6 +1465,40 @@ void TDLibWrapper::setMessageReaction(qlonglong chatId, qlonglong messageId, con
|
||||||
this->sendRequest(requestObject);
|
this->sendRequest(requestObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TDLibWrapper::setNetworkType(NetworkType networkType)
|
||||||
|
{
|
||||||
|
LOG("Set network type" << networkType);
|
||||||
|
|
||||||
|
QVariantMap requestObject;
|
||||||
|
requestObject.insert(_TYPE, "setNetworkType");
|
||||||
|
requestObject.insert(_EXTRA, "setNetworkType");
|
||||||
|
QVariantMap networkTypeObject;
|
||||||
|
switch (networkType) {
|
||||||
|
case Mobile:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeMobile");
|
||||||
|
break;
|
||||||
|
case MobileRoaming:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeMobileRoaming");
|
||||||
|
break;
|
||||||
|
case None:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeNone");
|
||||||
|
break;
|
||||||
|
case Other:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeOther");
|
||||||
|
break;
|
||||||
|
case WiFi:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeWiFi");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
networkTypeObject.insert(_TYPE, "networkTypeOther");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
requestObject.insert("type", networkTypeObject);
|
||||||
|
|
||||||
|
this->sendRequest(requestObject);
|
||||||
|
}
|
||||||
|
|
||||||
void TDLibWrapper::searchEmoji(const QString &queryString)
|
void TDLibWrapper::searchEmoji(const QString &queryString)
|
||||||
{
|
{
|
||||||
LOG("Searching emoji" << queryString);
|
LOG("Searching emoji" << queryString);
|
||||||
|
@ -1948,6 +1988,45 @@ void TDLibWrapper::handleSponsoredMessage(qlonglong chatId, const QVariantMap &m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TDLibWrapper::handleNetworkConfigurationChanged(const QNetworkConfiguration &config)
|
||||||
|
{
|
||||||
|
LOG("A network configuration changed: " << config.bearerTypeName() << config.state());
|
||||||
|
LOG("Checking overall network state...");
|
||||||
|
|
||||||
|
bool wifiFound = false;
|
||||||
|
bool mobileFound = false;
|
||||||
|
|
||||||
|
QList<QNetworkConfiguration> activeConfigurations = networkConfigurationManager->allConfigurations(QNetworkConfiguration::Active);
|
||||||
|
QListIterator<QNetworkConfiguration> configurationIterator(activeConfigurations);
|
||||||
|
while (configurationIterator.hasNext()) {
|
||||||
|
QNetworkConfiguration activeConfiguration = configurationIterator.next();
|
||||||
|
if (activeConfiguration.bearerType() == QNetworkConfiguration::BearerWLAN
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerEthernet) {
|
||||||
|
LOG("Active WiFi found...");
|
||||||
|
wifiFound = true;
|
||||||
|
}
|
||||||
|
if (activeConfiguration.bearerType() == QNetworkConfiguration::Bearer2G
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::Bearer3G
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::Bearer4G
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerCDMA2000
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerEVDO
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerHSPA
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerLTE
|
||||||
|
|| activeConfiguration.bearerType() == QNetworkConfiguration::BearerWCDMA) {
|
||||||
|
LOG("Active mobile connection found...");
|
||||||
|
mobileFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (wifiFound) {
|
||||||
|
this->setNetworkType(NetworkType::WiFi);
|
||||||
|
} else if (mobileFound) {
|
||||||
|
this->setNetworkType(NetworkType::Mobile);
|
||||||
|
} else {
|
||||||
|
this->setNetworkType(NetworkType::None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TDLibWrapper::handleGetPageSourceFinished()
|
void TDLibWrapper::handleGetPageSourceFinished()
|
||||||
{
|
{
|
||||||
LOG("TDLibWrapper::handleGetPageSourceFinished");
|
LOG("TDLibWrapper::handleGetPageSourceFinished");
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
#include <td/telegram/td_json_client.h>
|
#include <td/telegram/td_json_client.h>
|
||||||
#include "tdlibreceiver.h"
|
#include "tdlibreceiver.h"
|
||||||
#include "dbusadaptor.h"
|
#include "dbusadaptor.h"
|
||||||
|
@ -114,6 +115,15 @@ public:
|
||||||
};
|
};
|
||||||
Q_ENUM(UserPrivacySettingRule)
|
Q_ENUM(UserPrivacySettingRule)
|
||||||
|
|
||||||
|
enum NetworkType {
|
||||||
|
Mobile,
|
||||||
|
MobileRoaming,
|
||||||
|
None,
|
||||||
|
Other,
|
||||||
|
WiFi
|
||||||
|
};
|
||||||
|
Q_ENUM(NetworkType)
|
||||||
|
|
||||||
class Group {
|
class Group {
|
||||||
public:
|
public:
|
||||||
Group(qlonglong id) : groupId(id) { }
|
Group(qlonglong id) : groupId(id) { }
|
||||||
|
@ -239,6 +249,7 @@ public:
|
||||||
Q_INVOKABLE void getMessageAvailableReactions(qlonglong chatId, qlonglong messageId);
|
Q_INVOKABLE void getMessageAvailableReactions(qlonglong chatId, qlonglong messageId);
|
||||||
Q_INVOKABLE void getPageSource(const QString &address);
|
Q_INVOKABLE void getPageSource(const QString &address);
|
||||||
Q_INVOKABLE void setMessageReaction(qlonglong chatId, qlonglong messageId, const QString &reaction);
|
Q_INVOKABLE void setMessageReaction(qlonglong chatId, qlonglong messageId, const QString &reaction);
|
||||||
|
Q_INVOKABLE void setNetworkType(NetworkType networkType);
|
||||||
|
|
||||||
// Others (candidates for extraction ;))
|
// Others (candidates for extraction ;))
|
||||||
Q_INVOKABLE void searchEmoji(const QString &queryString);
|
Q_INVOKABLE void searchEmoji(const QString &queryString);
|
||||||
|
@ -352,6 +363,7 @@ public slots:
|
||||||
void handleUserPrivacySettingRules(const QVariantMap &rules);
|
void handleUserPrivacySettingRules(const QVariantMap &rules);
|
||||||
void handleUpdatedUserPrivacySettingRules(const QVariantMap &updatedRules);
|
void handleUpdatedUserPrivacySettingRules(const QVariantMap &updatedRules);
|
||||||
void handleSponsoredMessage(qlonglong chatId, const QVariantMap &message);
|
void handleSponsoredMessage(qlonglong chatId, const QVariantMap &message);
|
||||||
|
void handleNetworkConfigurationChanged(const QNetworkConfiguration &config);
|
||||||
|
|
||||||
void handleGetPageSourceFinished();
|
void handleGetPageSourceFinished();
|
||||||
|
|
||||||
|
@ -366,6 +378,7 @@ private:
|
||||||
private:
|
private:
|
||||||
void *tdLibClient;
|
void *tdLibClient;
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
|
QNetworkConfigurationManager *networkConfigurationManager;
|
||||||
AppSettings *appSettings;
|
AppSettings *appSettings;
|
||||||
MceInterface *mceInterface;
|
MceInterface *mceInterface;
|
||||||
TDLibReceiver *tdLibReceiver;
|
TDLibReceiver *tdLibReceiver;
|
||||||
|
|
Loading…
Reference in a new issue