Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ParameterProxyUI.cpp
1#include "ParameterProxyUI.h"
2#include <QHBoxLayout>
3#include <QSpacerItem>
4
5CParameterProxyUI::CParameterProxyUI(QWidget *parent)
6 : CParameterUI(parent),
7 m_uiSockesV5(nullptr),
8 m_uiSSH(nullptr)
9{
10 bool bCheck = false;
11 setLayout(new QBoxLayout(QBoxLayout::TopToBottom, this));
12 QHBoxLayout* pType = new QHBoxLayout(this);
13 layout()->addItem(pType);
14
15 m_uiSockesV5 = new CParameterNetUI(this);
16 layout()->addWidget(m_uiSockesV5);
17
18 m_uiSSH = new CParameterNetUI(this);
19 layout()->addWidget(m_uiSSH);
20
21 m_lbType = new QLabel(this);
22 m_lbType->setText(tr("Type:"));
23 pType->addWidget(m_lbType);
24
25 m_cbType = new QComboBox(this);
26 pType->addWidget(m_cbType);
27 bCheck = connect(m_cbType, SIGNAL(currentIndexChanged(int)),
28 this, SLOT(slotTypeChanged(int)));
29 Q_ASSERT(bCheck);
30 m_cbType->addItem(tr("None"), (int)CParameterProxy::TYPE::None);
31 m_cbType->addItem(tr("Default"), (int)CParameterProxy::TYPE::Default);
32 m_cbType->addItem(tr("SockesV5"), (int)CParameterProxy::TYPE::SockesV5);
33 m_cbType->addItem(tr("SSH Tunnel"), (int)CParameterProxy::TYPE::SSHTunnel);
34
35 layout()->addItem(new QSpacerItem(0, 0,
36 QSizePolicy::Preferred,
37 QSizePolicy::Expanding));
38}
39
40void CParameterProxyUI::slotTypeChanged(int nIndex)
41{
42 Q_UNUSED(nIndex);
43 int type = m_cbType->currentData().toInt();
44 if(m_uiSockesV5)
45 m_uiSockesV5->setVisible(type == (int)CParameterProxy::TYPE::SockesV5);
46
47 if(m_uiSSH)
48 m_uiSSH->setVisible(type == (int)CParameterProxy::TYPE::SSHTunnel);
49
50}
51
53{
54 m_Proxy = qobject_cast<CParameterProxy*>(pParameter);
55 if(!m_Proxy)
56 return -1;
57 m_uiSockesV5->SetParameter(&m_Proxy->m_SockesV5);
58 m_uiSSH->SetParameter(&m_Proxy->m_SSH);
59
60 m_cbType->clear();
61 foreach(auto t, m_Proxy->GetType())
62 {
63 m_cbType->addItem(m_Proxy->ConvertTypeToName(t), (int)t);
64 }
65
66 int index = m_cbType->findData((int)m_Proxy->GetUsedType());
67 m_cbType->setCurrentIndex(index);
68 return 0;
69}
70
72{
73 bool bRet = true;
74 int type = m_cbType->currentData().toInt();
75 switch(type)
76 {
77 case (int)CParameterProxy::TYPE::SockesV5: {
78 bRet = m_uiSockesV5->CheckValidity(validity);
79 if(!bRet) return bRet;
80 break;
81 }
82 case (int)CParameterProxy::TYPE::SSHTunnel: {
83 bRet = m_uiSSH->CheckValidity(validity);
84 if(!bRet) return bRet;
85 break;
86 }
87 default:
88 break;
89 }
90
91 return bRet;
92}
93
95{
96 int nRet = 0;
97 int type = m_cbType->currentData().toInt();
98 switch(type)
99 {
100 case (int)CParameterProxy::TYPE::SockesV5: {
101 nRet = m_uiSockesV5->Accept();
102 if(nRet) return nRet;
103 break;
104 }
105 case (int)CParameterProxy::TYPE::SSHTunnel: {
106 nRet = m_uiSSH->Accept();
107 if(nRet) return nRet;
108 break;
109 }
110 default:
111 break;
112 }
113
114 m_Proxy->SetUsedType((CParameterProxy::TYPE)type);
115
116 return 0;
117}
The net parameter UI.
int Accept()
Accept parameters.
bool CheckValidity(bool validity=false)
[Set Parameter]
int SetParameter(CParameter *pParameter)
[Parameter commone functions]
int SetParameter(CParameter *pParameter)
Set the parameters and initialize the user interface.
bool CheckValidity(bool validity=false)
Check parameters validity.
int Accept()
Accept parameters.
The parameter UI interface.
Definition ParameterUI.h:15
Parameter interface.
Definition Parameter.h:169