TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicnetworkthread.cpp
Go to the documentation of this file.
1 #include "musicnetworkthread.h"
2 #include "musicconnectionpool.h"
3 #include "musicsettingmanager.h"
4 #include "ttkconcurrent.h"
5 
6 #include <QHostInfo>
7 
8 static constexpr int NETWORK_DETECT_INTERVAL = 5000; // second
9 static constexpr const char *NETWORK_REQUEST_ADDRESS = "www.baidu.com"; // ip
10 
12  : QObject(nullptr),
13  m_networkState(true)
14 {
15  connect(&m_timer, SIGNAL(timeout()), SLOT(networkStateChanged()));
16 
17  G_CONNECTION_PTR->setValue(className(), this);
18 }
19 
21 {
22  m_timer.stop();
23 }
24 
26 {
27  TTK_INFO_STREAM("Load NetworkThread");
30 }
31 
33 {
35 }
36 
38 {
40  {
41  const bool block = G_SETTING_PTR->value(MusicSettingManager::CloseNetWorkMode).toBool();
42  const QHostInfo &info = QHostInfo::fromName(NETWORK_REQUEST_ADDRESS);
43  m_networkState = !info.addresses().isEmpty();
44  m_networkState = block ? false : m_networkState;
46  });
47 }
void networkConnectionStateChanged(bool state)
static constexpr const char * NETWORK_REQUEST_ADDRESS
void setBlockNetwork(bool block)
#define G_CONNECTION_PTR
static constexpr int NETWORK_DETECT_INTERVAL
#define TTK_INFO_STREAM(msg)
Definition: ttklogger.h:67
#define TTKConcurrent(...)
Definition: ttkconcurrent.h:34
#define G_SETTING_PTR