Skip to content

Commit

Permalink
Update Internal Command Window
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Jul 19, 2024
1 parent 09d168f commit 330a52e
Show file tree
Hide file tree
Showing 14 changed files with 342 additions and 36 deletions.
Binary file added icons/about2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 76 additions & 3 deletions lang/quardCRT_zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,17 @@
<translation>显示公钥管理器</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="1620"/>
<location filename="../src/mainwindow.cpp" line="1628"/>
<source>Internal Command</source>
<translation>内部命令</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="1629"/>
<source>Display Internal Command window</source>
<translation>显示内部命令窗口</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="1644"/>
<source>Portuguese (Brazil)</source>
<translation>Português (Brasil)</translation>
</message>
Expand Down Expand Up @@ -1272,7 +1282,12 @@
<translation>插件 API 版本不匹配!</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2223"/>
<location filename="../src/mainwindow.cpp" line="2256"/>
<source>Plugin menu not found!</source>
<translation>未找到插件菜单!</translation>
</message>
<message>
<location filename="../src/mainwindow.cpp" line="2261"/>
<source>Plugin init failed!</source>
<translation>插件初始化失败!</translation>
</message>
Expand Down Expand Up @@ -2604,6 +2619,46 @@ If you need to use another shell, please create a session through [quick-connect
<translation>清除</translation>
</message>
</context>
<context>
<name>InternalCommandWindow</name>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.ui" line="14"/>
<source>Internal Command</source>
<translation>内部命令</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="111"/>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="121"/>
<source>Open URL</source>
<translation>打开 URL</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="111"/>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="121"/>
<source>Cannot open URL %1.</source>
<translation>无法打开 URL %1.</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="198"/>
<source>Copy</source>
<translation>复制</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="204"/>
<source>Paste</source>
<translation>粘贴</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="210"/>
<source>Select All</source>
<translation>全选</translation>
</message>
<message>
<location filename="../src/internalcommandwindow/internalcommandwindow.cpp" line="216"/>
<source>Find</source>
<translation>查找</translation>
</message>
</context>
<context>
<name>Konsole::Session</name>
<message>
Expand Down Expand Up @@ -2732,6 +2787,14 @@ If you need to use another shell, please create a session through [quick-connect
<translation>网络扫描</translation>
</message>
</context>
<context>
<name>NotifictionWidget</name>
<message>
<location filename="../src/notifictionwidget/notifictionwidget.ui" line="44"/>
<source>No notifiction</source>
<translation>无通知</translation>
</message>
</context>
<context>
<name>PluginInfoWindow</name>
<message>
Expand All @@ -2740,7 +2803,12 @@ If you need to use another shell, please create a session through [quick-connect
<translation>插件信息</translation>
</message>
<message>
<location filename="../src/plugininfowindow/plugininfowindow.ui" line="34"/>
<location filename="../src/plugininfowindow/plugininfowindow.ui" line="22"/>
<source>Plugins Path</source>
<translation>插件路径</translation>
</message>
<message>
<location filename="../src/plugininfowindow/plugininfowindow.ui" line="38"/>
<source>API version</source>
<translation>API版本</translation>
</message>
Expand Down Expand Up @@ -2784,6 +2852,11 @@ If you need to use another shell, please create a session through [quick-connect
<source>Website</source>
<translation>网站</translation>
</message>
<message>
<location filename="../src/plugininfowindow/plugininfowindow.cpp" line="107"/>
<source>Unknown</source>
<translation>未知</translation>
</message>
</context>
<context>
<name>PluginViewerHomeWidget</name>
Expand Down
1 change: 1 addition & 0 deletions res/resource.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="/icons">
<file>../icons/fontawesome-webfont.ttf</file>
<file>../icons/about.png</file>
<file>../icons/about2.png</file>
<file>../icons/aboutqt.png</file>
</qresource>
<qresource prefix="/lang">
Expand Down
95 changes: 75 additions & 20 deletions src/internalcommandwindow/internalcommandprocess.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <QMutexLocker>
#include <QMap>
#include <QSysInfo>
#include "internalcommandprocess.h"
#include "mainwindow.h"
#include "globalsetting.h"

InternalCommandProcess::InternalCommandProcess(QObject *parent)
: QThread(parent) {
Expand All @@ -16,6 +18,7 @@ InternalCommandProcess::~InternalCommandProcess() {

void InternalCommandProcess::run(void) {
sendString("Welcome to the QuardCRT command window.\r\n");
sendString("Please type 'help' or '?' to get a list of available commands.\r\n");
sendPrompt();
while (!exit) {
mutex.lock();
Expand All @@ -39,21 +42,17 @@ void InternalCommandProcess::run(void) {
}
}

void InternalCommandProcess::processLine(const QString &line) {
const QMap<QString, QString> commands = {
{"help", "help - show this help message"},
{"exit", "exit - exit the program"},
{"quit", "quit - exit the program"},
{"clear", "clear - clear the screen"},
{"cls", "cls - clear the screen"},
{"echo", "echo - echo the arguments"},
{"version", "version - show the version of the program"},
{"about", "about - show the about message of the program"},
{"license", "license - show the license of the program"},
{"authors", "authors - show the authors of the program"},
{"credits", "credits - show the credits of the program"},
{"copying", "copying - show the copying of the program"},
};
void InternalCommandProcess::processLine(const QString &sline) {
QString line = sline;
int index = 0;
while ((index = line.indexOf('\b', index)) != -1) {
if (index > 0) {
line.remove(index - 1, 2);
index--;
} else {
line.remove(index, 1);
}
}
QStringList pargs = line.split(' ', Qt::SkipEmptyParts);
if(pargs.isEmpty()) {
return;
Expand All @@ -63,17 +62,32 @@ void InternalCommandProcess::processLine(const QString &line) {
args.append(arg.trimmed());
}
QString command = args.takeFirst();
if(command == "help") {

const QMap<QString, QString> commands = {
{"help", "show this help message"},
{"?", "show this help message"},
{"exit", "exit the QuardCRT"},
{"quit", "exit the QuardCRT"},
{"clear", "clear the screen"},
{"cls", "clear the screen"},
{"version", "show the version of the QuardCRT"},
{"about", "how the about message of the QuardCRT"},
{"license", "show the license of the QuardCRT"},
{"authors", "show the authors of the QuardCRT"},
{"credits", "show the credits of the QuardCRT"},
{"copying", "show the copying of the QuardCRT"},
{"echo", "echo the arguments"},
{"state", "show states of the QuardCRT"},
};
if(command == "help" || command == "?") {
sendString("Available commands:\r\n");
foreach(const QString &key, commands.keys()) {
sendString(" " + commands[key] + "\r\n");
sendString(" " + key + " - " + commands[key] + "\r\n");
}
} else if(command == "exit" || command == "quit") {
qApp->exit();
} else if(command == "clear" || command == "cls") {
sendString("\033[2J\033[1;1H");
} else if(command == "echo") {
sendString(args.join(' ') + "\r\n");
} else if(command == "version") {
sendString(QString("QuardCRT version %0\r\n").arg(VERSION));
} else if(command == "about") {
Expand All @@ -90,6 +104,42 @@ void InternalCommandProcess::processLine(const QString &line) {
sendString("Thank you use QuardCRT, Have a nice day!\r\n");
} else if(command == "AskQuardShow") {
emit showString("QuardCRT", "Thank you use QuardCRT, Have a nice day!\r\n");
} else if(command == "QuardSOnly") {
emit showEasterEggs();
} else if(command == "echo") {
sendString(args.join(' ') + "\r\n");
} else if(command == "state") {
GlobalSetting settings;
bool debugMode = settings.value("Debug/DebugMode",false).toBool();
QString debugLogFile = settings.value("Debug/DebugLogFile","").toString();
QtMsgType debugLevel = settings.value("Debug/DebugLevel",QtInfoMsg).value<QtMsgType>();
sendString(QString("debugMode : %0\r\n").arg(debugLevel));
sendString(QString("debugLogFile : %0\r\n").arg(debugLogFile));
sendString(QString("debugLevel : %0\r\n").arg(debugLevel));
sendString(QString("Version : %0\r\n").arg(VERSION));
sendString(QString("GitTag : %0\r\n").arg(GIT_TAG));
sendString(QString("BuildDate : %0\r\n").arg(DATE_TAG));
sendString(QString("os : %0\r\n").arg(QSysInfo::prettyProductName()));
sendString(QString("bootUniqueId : %0\r\n").arg(QSysInfo::bootUniqueId()));
sendString(QString("buildAbi : %0\r\n").arg(QSysInfo::buildAbi()));
sendString(QString("buildCpuArchitecture : %0\r\n").arg(QSysInfo::buildCpuArchitecture()));
sendString(QString("currentCpuArchitecture : %0\r\n").arg(QSysInfo::currentCpuArchitecture()));
sendString(QString("kernelType : %0\r\n").arg(QSysInfo::kernelType()));
sendString(QString("kernelVersion : %0\r\n").arg(QSysInfo::kernelVersion()));
sendString(QString("machineHostName : %0\r\n").arg(QSysInfo::machineHostName()));
sendString(QString("machineUniqueId : %0\r\n").arg(QSysInfo::machineUniqueId()));
sendString(QString("productType : %0\r\n").arg(QSysInfo::productType()));
sendString(QString("productVersion : %0\r\n").arg(QSysInfo::productVersion()));
sendString(QString("osVersion : %0\r\n").arg(QOperatingSystemVersion::current().name()));
#if defined(Q_CC_MSVC)
sendString(QString("compiler : MSVC %0\r\n").arg(Q_CC_MSVC));
#elif defined(Q_CC_CLANG)
sendString(QString("compiler : CLANG %0\r\n").arg(Q_CC_CLANG));
#elif defined(Q_CC_GNU)
sendString(QString("compiler : GCC %0\r\n").arg(Q_CC_GNU));
#else
sendString(QString("compiler : unknown\r\n"));
#endif
} else {
if(command.isEmpty()) {
return;
Expand All @@ -101,9 +151,14 @@ void InternalCommandProcess::processLine(const QString &line) {
void InternalCommandProcess::recvData(const QByteArray &data) {
QMutexLocker locker(&mutex);
QByteArray sdata = data;
sdata.replace("\x1B[A", "");
sdata.replace("\x1B[B", "");
sdata.replace("\x1B[C", "");
sdata.replace("\x1B[D", "");
sdata.replace('\r', "\r\n");
emit sendData(sdata);
buffer.append(sdata);
sdata.replace("\b", "\x08\x1B[J");
emit sendData(sdata);
condition.wakeOne();
}

Expand Down
1 change: 1 addition & 0 deletions src/internalcommandwindow/internalcommandprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class InternalCommandProcess : public QThread
signals:
void sendData(const QByteArray &data);
void showString(const QString &name, const QString &str);
void showEasterEggs(void);

protected:
void run(void);
Expand Down
Loading

0 comments on commit 330a52e

Please sign in to comment.