3#include <QDesktopServices>
4#include <QLoggingCategory>
9#include "DlgSettingsTerminal.h"
12static Q_LOGGING_CATEGORY(log,
"Plugin.Terminal.Operate")
16 , m_pOpenFolderWithExplorer(
nullptr)
17 , m_pCopyToClipboard(
nullptr)
19 qDebug(log) << Q_FUNC_INFO;
20 SetParameter(&m_Parameters);
23CTerminal::~CTerminal()
25 qDebug(log) << Q_FUNC_INFO;
35 slotUpdateParameter(
this);
37 bool check = connect(m_pTerminal, &QTermWidget::titleChanged,
39 qDebug(log) <<
"Title changed:" << m_pTerminal->title()
40 <<
"; Working directory:"
41 << m_pTerminal->workingDirectory();
42 if(m_Parameters.GetEnableTitleChanged()) {
43 m_pTerminal->setWindowTitle(m_pTerminal->title());
46 if(m_Parameters.GetRestoreDirectory()) {
47 if(!m_pTerminal->workingDirectory().isEmpty())
48 m_Parameters.SetLasterDirectory(m_pTerminal->workingDirectory());
52 if(!m_Parameters.GetShell().isEmpty())
53 m_pTerminal->setShellProgram(m_Parameters.GetShell());
54 if(!m_Parameters.GetShellParameters().isEmpty())
55 m_pTerminal->setArgs(QStringList() << m_Parameters.GetShellParameters());
56 qDebug(log) <<
"Start:" << m_Parameters.GetShell() << m_Parameters.GetShellParameters();
57 m_pTerminal->startShellProgram();
58 if(m_Parameters.GetRestoreDirectory() && !m_Parameters.GetLasterDirectory().isEmpty())
59 m_pTerminal->sendText(
"cd " + m_Parameters.GetLasterDirectory() +
"\r");
60 if(!m_Parameters.GetCommands().isEmpty()) {
61 foreach (
auto c, m_Parameters.GetCommands())
62 m_pTerminal->sendText(c +
"\r");
95#if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
96 m_pOpenFolderWithExplorer = m_Menu.addAction(
97 QIcon::fromTheme(
"folder-open"),
98 tr(
"Open working directory with file explorer") +
"\tCtrl+O",
99 QKeySequence(QKeySequence::Open),
101 QDesktopServices::openUrl(
102 QUrl::fromLocalFile(m_pTerminal->workingDirectory()));
105 m_pOpenFolderWithExplorer = m_Menu.addAction(
106 QIcon::fromTheme(
"folder-open"),
107 tr(
"Open working directory with file explorer") +
"\tCtrl+O",
110 QDesktopServices::openUrl(
111 QUrl::fromLocalFile(m_pTerminal->workingDirectory()));
113 QKeySequence(QKeySequence::Open)
116 m_Menu.insertAction(m_pActionFind, m_pOpenFolderWithExplorer);
117 m_pCopyToClipboard = m_Menu.addAction(
118 QIcon::fromTheme(
"edit-copy"),
119 tr(
"Copy working directory to clipboard"),
121 if(!m_pTerminal)
return;
122 QClipboard* pClipboard = QApplication::clipboard();
123 if(!pClipboard)
return;
124 pClipboard->setText(m_pTerminal->workingDirectory());
126 m_Menu.insertAction(m_pActionFind, m_pCopyToClipboard);
133 if(!m_Parameters.GetName().isEmpty())
134 return m_Parameters.GetName();
135 if(!m_Parameters.GetShellName().isEmpty())
140void CTerminal::SetShotcuts(
bool bEnable)
142 if(!m_pOpenFolderWithExplorer || !m_pCopyToClipboard)
144 COperateTerminal::SetShotcuts(bEnable);
146 m_pOpenFolderWithExplorer->setShortcut(QKeySequence(QKeySequence::Open));
149 m_pOpenFolderWithExplorer->setShortcut(QKeySequence());
150 m_pCopyToClipboard->setShortcut(QKeySequence());
155 QString szDescription;
156 if(!
Name().isEmpty())
157 szDescription = tr(
"Name: ") +
Name() +
"\n";
160 szDescription += tr(
"Type: ") +
GetTypeName() +
"\n";
163 szDescription += tr(
"Protocol: ") +
Protocol();
165 if(!
GetPlugin()->DisplayName().isEmpty())
168 szDescription +=
"\n";
171 if(!m_Parameters.GetShellName().isEmpty())
172 szDescription += tr(
"Shell name: ") + m_Parameters.GetShellName() +
"\n";
173 if(!m_Parameters.GetShell().isEmpty())
174 szDescription += tr(
"Shell path: ") + m_Parameters.GetShell() +
"\n";
175 if(!m_Parameters.GetShellParameters().isEmpty())
176 szDescription += tr(
"Shell parameters: ") + m_Parameters.GetShellParameters() +
"\n";
177 if(m_Parameters.GetCommands().size() > 0) {
178 szDescription += tr(
"Start commands:") +
"\n";
179 foreach(
auto cmd, m_Parameters.GetCommands())
180 szDescription +=
" " + cmd +
"\n";
185 szDescription += tr(
"Security level: ");
186 if(!sl.GetUnicodeIcon().isEmpty())
187 szDescription += sl.GetUnicodeIcon() +
" ";
188 szDescription += sl.GetString() +
"\n";
194 return szDescription;
199 bool check = connect(&m_Parameters, &CTerminalParameter::sigEnableTitleChanged,
200 this, [&](
bool changed) {
202 slotTerminalTitleChanged();
210void CTerminal::slotTerminalTitleChanged()
212 if(!m_pTerminal)
return;
后端接口。它由协议插件实现。 它默认启动一个定时器来开启一个非 Qt 事件循环(就是普通的循环处理)。 详见: Start()、 slotTimeOut()、 OnProcess() 。 当然,它仍然支...
virtual int Initial() override
Initial parameters and resource
virtual const QString Name() override
名称
virtual int SetParameter(CParameterTerminalBase *pPara)
设置参数指针
virtual CSecurityLevel::Levels GetSecurityLevel() const
Get Security Level
void sigFinished()
断开连接成功信号。仅由插件触发
void sigRunning()
开始成功信号。仅由插件触发。
virtual const QString Protocol() const
协议
Q_INVOKABLE CPlugin * GetPlugin() const
Get plugin
void sigUpdateName(const QString &szName)
virtual const QString GetTypeName() const
类型名
virtual const QString DisplayName() const
在界面上显示的名称
virtual const QString Description() const =0
描述
virtual int Initial() override
Initial parameters and resource
virtual int SetParameter(CParameterTerminalBase *pPara) override
设置参数指针
virtual QDialog * OnOpenDialogSettings(QWidget *parent) override
得到设置对话框
virtual const QString Description() override
描述
virtual const QString Name() override
名称
virtual CBackend * InstanceBackend() override
新建后端实例。它的所有者是调用者, 如果调用者不再使用它,调用者必须负责释放它。
CStats * GetStats() override
得到统计信息。如果有,其派生类则需要重载此函数提供统计信息。