Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
ConnecterTerminal.cpp
1#include "ConnecterTerminal.h"
2#include "Connect.h"
3#include "ConnectThreadTerminal.h"
4
5#include <QDialog>
6#include <QApplication>
7#include <QDebug>
8#include <QTextCodec>
9#include <QSettings>
10
11#ifdef BUILD_QUIWidget
12 #include "QUIWidget/QUIWidget.h"
13#endif
14
15#include <QLoggingCategory>
16
17Q_DECLARE_LOGGING_CATEGORY(Terminal)
18
19CConnecterTerminal::CConnecterTerminal(CPluginClient *parent)
20 : CConnecter(parent),
21 m_pConsole(nullptr),
22 m_pThread(nullptr),
23 m_bThread(false),
24 m_bExit(false),
25 m_pPara(nullptr)
26{
27 m_pConsole = new CFrmTermWidget();
28 m_pConsole->setAutoClose(true);
29
30 bool check = false;
31 check = connect(m_pConsole, SIGNAL(titleChanged()),
32 this, SLOT(slotTerminalTitleChanged()));
33 Q_ASSERT(check);
34 check = connect(m_pConsole, SIGNAL(finished()),
35 this, SIGNAL(sigDisconnected()));
36 Q_ASSERT(check);
37 check = connect(m_pConsole, SIGNAL(sigZoomReset()),
38 this, SLOT(slotZoomReset()));
39 Q_ASSERT(check);
40}
41
42CConnecterTerminal::~CConnecterTerminal()
43{
44 qDebug(Terminal) << "CConnecterTerminal::~CConnecterTerminal()";
45
46 if(m_pConsole)
47 {
48 m_pConsole->deleteLater();
49 m_pConsole = nullptr;
50 }
51}
52
54{
55 return m_pConsole;
56}
57
59{
60 return 0;
61}
62
63int CConnecterTerminal::Load(QSettings &set)
64{
65 int nRet = 0;
66 CParameterConnecter* pPara = GetParameter();
67 Q_ASSERT(pPara);
68 if(!pPara) return -1;
69 pPara->Load(set);
70 return nRet;
71}
72
73int CConnecterTerminal::Save(QSettings &set)
74{
75 int nRet = 0;
76
77 CParameterConnecter* pPara = GetParameter();
78 Q_ASSERT(pPara);
79 if(!pPara) return -1;
80 pPara->Save(set);
81 return nRet;
82}
83
84int CConnecterTerminal::Connect()
85{
86 int nRet = 0;
87
88 nRet = SetParameter();
89
90 if(m_bThread)
91 {
92 m_pThread = new CConnectThreadTerminal(this);
93 bool check = connect(m_pThread, SIGNAL(finished()),
94 m_pThread, SLOT(deleteLater()));
95 Q_ASSERT(check);
96 if(m_pThread)
97 m_pThread->start();
98 return 0;
99 }
100
101 nRet = OnConnect();
102 if(nRet < 0)
103 emit sigDisconnected();
104 else if(0 == nRet)
105 emit sigConnected();
106
107 if(m_pConsole)
108 emit sigUpdateName(Name());
109
110 return nRet;
111}
112
113int CConnecterTerminal::DisConnect()
114{
115 int nRet = 0;
116
117 if(m_bThread && m_pThread)
118 {
119 m_pThread->quit();
120 } else
121 nRet = OnDisConnect();
122 emit sigDisconnected();
123 return nRet;
124}
125
126int CConnecterTerminal::SetParameter()
127{
128 int nRet = 0;
129
130 CParameterTerminal* pPara = GetParameter();
131 Q_ASSERT(pPara);
132 if(!pPara) return -1;
133#if QTERMWIDGET_VERSION >= QT_VERSION_CHECK(0, 9, 0)
134 m_pConsole->setTerminalSizeHint(pPara->GetSizeHint());
135 m_pConsole->setBidiEnabled(pPara->GetDirectional());
136 m_pConsole->disableBracketedPasteMode(pPara->GetDisableBracketedPasteMode());
137#endif
138 m_pConsole->setTerminalFont(pPara->GetFont());
139 m_pConsole->setKeyboardCursorShape(pPara->GetCursorShape());
140 m_pConsole->setColorScheme(pPara->GetColorScheme());
141 m_pConsole->setScrollBarPosition(pPara->GetScrollBarPosition());
142 m_pConsole->setFlowControlEnabled(pPara->GetFlowControl());
143 m_pConsole->setFlowControlWarningEnabled(pPara->GetFlowControlWarning());
144 m_pConsole->setMotionAfterPasting(pPara->GetMotionAfterPasting());
145 m_pConsole->setTerminalOpacity(1.0 - pPara->GetTransparency() / 100.0);
146 m_pConsole->setTerminalBackgroundImage(pPara->GetBackgroupImage());
147
148 m_pConsole->setKeyBindings(pPara->GetKeyBindings());
149 m_pConsole->setTextCodec(QTextCodec::codecForName(pPara->GetTextCodec().toStdString().c_str()));
150 m_pConsole->setHistorySize(pPara->GetHistorySize());
151
152// m_pConsole->setMonitorActivity(false);
153// m_pConsole->setMonitorSilence(false);
154// m_pConsole->setBlinkingCursor(true);
155
156 return nRet;
157}
158
159void CConnecterTerminal::slotTerminalTitleChanged()
160{
161 m_pConsole->setWindowTitle(m_pConsole->title());
162 slotSetServerName(m_pConsole->title());
163}
164
165void CConnecterTerminal::slotZoomReset()
166{
167 if(!m_pConsole) return;
168 CParameterTerminal* pPara = dynamic_cast<CParameterTerminal*>(GetParameter());
169 if(!pPara) return;
170 m_pConsole->setTerminalFont(pPara->GetFont());
171}
172
174{
175 return 0;
176}
177
178int CConnecterTerminal::OnDisConnect()
179{
180 return 0;
181}
182
183QString CConnecterTerminal::ServerName()
184{
185 if(GetParameter())
186 if(!GetParameter()->GetShowServerName()
187 || CConnecter::ServerName().isEmpty())
188 {
189 if(!GetParameter()->GetHost().isEmpty())
190 return GetParameter()->GetHost() + ":"
191 + QString::number(GetParameter()->GetPort());
192 }
193 return CConnecter::ServerName();
194}
195
196CConnect* CConnecterTerminal::InstanceConnect()
197{
198 return nullptr;
199}
200
201CParameterTerminal* CConnecterTerminal::GetParameter()
202{
203 return m_pPara;
204}
Connect interface.
Definition Connect.h:45
virtual int OnConnect()
OnConnect.
virtual qint16 Version() override
Version.
virtual int Save(QSettings &set) override
Save parameters.
QWidget * GetViewer() override
Get Viewer.
virtual int Load(QSettings &set) override
Load parameters.
Connecter interface.
Definition Connecter.h:62
void sigUpdateName(const QString &szName)
void sigConnected()
Successful connection signal.
void sigDisconnected()
Successful disconnection signal.
virtual const QString Name()
Name.
Definition Connecter.cpp:53
the parameters of connecter interface.
virtual int Save(QString szFile=QString(), bool bForce=true)
Save to file.
Definition Parameter.cpp:44
virtual int Load(QString szFile=QString())
Load from file.
Definition Parameter.cpp:33
The plugin interface.