TTKMusicPlayer  3.7.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 
20 {
21  m_hostName = name;
22 }
23 
25 {
26  return m_hostName;
27 }
28 
30 {
31  m_port = port;
32 }
33 
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)
50 {
51  m_user = user;
52 }
53 
54 QString MusicNetworkProxy::user() const
55 {
56  return m_user;
57 }
58 
59 void MusicNetworkProxy::setPassword(const QString &pwd)
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 }
#define TTKStaticCast(x, y)
Definition: ttkglobal.h:159
MusicNetworkProxy(QObject *parent=nullptr)
const char * name
Definition: http_parser.c:458
void setHostName(const QString &name)
void setUser(const QString &user)
void testProxyChanged(QAbstractSocket::SocketState state)
void setType(int type)
void setPassword(const QString &pwd)
void testProxyStateChanged(bool state)
void setPort(int port)
QString user() const
QString password() const
state
Definition: http_parser.c:279
QString hostName() const