TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicnetworkproxy.cpp
Go to the documentation of this file.
1 #include "musicnetworkproxy.h"
2 
3 #include <QNetworkProxy>
4 
6  : QObject(parent),
7  m_port(-1),
8  m_type(2),
9  m_socket(nullptr)
10 {
11 
12 }
13 
15 {
16  delete m_socket;
17 }
18 
19 void MusicNetworkProxy::setHostName(const QString &name) noexcept
20 {
21  m_hostName = name;
22 }
23 
25 {
26  return m_hostName;
27 }
28 
29 void MusicNetworkProxy::setPort(int port) noexcept
30 {
31  m_port = port;
32 }
33 
34 void MusicNetworkProxy::setType(int type) noexcept
35 {
36  m_type = type;
37 }
38 
40 {
41  return m_type;
42 }
43 
45 {
46  return m_port;
47 }
48 
49 void MusicNetworkProxy::setUser(const QString &user) noexcept
50 {
51  m_user = user;
52 }
53 
54 QString MusicNetworkProxy::user() const noexcept
55 {
56  return m_user;
57 }
58 
59 void MusicNetworkProxy::setPassword(const QString &pwd) noexcept
60 {
61  m_pwd = pwd;
62 }
63 
65 {
66  return m_pwd;
67 }
68 
70 {
71  if(!m_socket)
72  {
73  m_socket = new QTcpSocket(this);
74  connect(m_socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), SLOT(testProxyChanged(QAbstractSocket::SocketState)));
75  }
76 
77  m_socket->abort();
78  m_socket->connectToHost(m_hostName, m_port);
79 }
80 
82 {
83  QNetworkProxy proxy;
84  proxy.setType(TTKStaticCast(QNetworkProxy::ProxyType, m_type));
85  if(!m_hostName.isEmpty())
86  {
87  proxy.setHostName(m_hostName);
88  }
89 
90  if(m_port != -1)
91  {
92  proxy.setPort(m_port);
93  }
94 
95  if(!m_user.isEmpty())
96  {
97  proxy.setUser(m_user);
98  }
99 
100  if(!m_pwd.isEmpty())
101  {
102  proxy.setPassword(m_pwd);
103  }
104  QNetworkProxy::setApplicationProxy(proxy);
105 }
106 
107 void MusicNetworkProxy::testProxyChanged(QAbstractSocket::SocketState state)
108 {
109  if(state == QAbstractSocket::UnconnectedState)
110  {
111  Q_EMIT testProxyStateChanged(false);
112  }
113 
114  if(state == QAbstractSocket::ConnectedState)
115  {
116  Q_EMIT testProxyStateChanged(true);
117  }
118 }
void setUser(const QString &user) noexcept
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:231
MusicNetworkProxy(QObject *parent=nullptr)
void setType(int type) noexcept
void setPort(int port) noexcept
int type() const noexcept
QString user() const noexcept
const char * name
Definition: http_parser.c:458
void setPassword(const QString &pwd) noexcept
void testProxyChanged(QAbstractSocket::SocketState state)
void setHostName(const QString &name) noexcept
void testProxyStateChanged(bool state)
int port() const noexcept
#define const
Definition: zconf.h:233
QString hostName() const noexcept
state
Definition: http_parser.c:279
QString password() const noexcept