Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app log category #304

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QTextLayout>
#include <QTime>
#include <QFontMetrics>

#include <QLoggingCategory>
#include <sys/utsname.h>

QHash<QString, QPixmap> Utils::m_imgCacheHash;
Expand All @@ -45,6 +45,12 @@ Utils::~Utils()
{
}

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(LogCommon,"log.terminal.common.work")
#else
Q_LOGGING_CATEGORY(LogCommon,"log.terminal.common.work",QtInfoMsg)
#endif

QString Utils::getQssContent(const QString &filePath)
{
QFile file(filePath);
Expand Down Expand Up @@ -330,7 +336,7 @@ void Utils::parseCommandLine(QStringList arguments, TermProperties &Properties,
// 解析参数
Properties[KeepOpen] = false;
if (!parser.parse(arguments))
qInfo() << "parser error:" << parser.errorText();
qCInfo(LogCommon) << "parser error:" << parser.errorText();

if (parser.isSet(optExecute)) {
/************************ Add by sunchengxi 2020-09-15:Bug#42864 无法同时打开多个终端 Begin************************/
Expand Down Expand Up @@ -371,11 +377,11 @@ void Utils::parseCommandLine(QStringList arguments, TermProperties &Properties,
// 处理相应参数,当遇到-v -h参数的时候,这里进程会退出。
parser.process(arguments);
} else {
qInfo() << "Command line input args:" << qPrintable(arguments.join(" "));
qInfo() << "The work directory :" << parser.value(optWorkDirectory);
qInfo() << QString("Execute %1 command in the terminal").arg(Properties[Execute].toStringList().join(" "));
qInfo() << "Run in quake mode :" << parser.isSet(optQuakeMode);
qInfo() << "Set the window mode on starting :" << parser.isSet(optWindowState);
qCInfo(LogCommon) << "Command line input args:" << qPrintable(arguments.join(" "));
qCInfo(LogCommon) << "The work directory :" << parser.value(optWorkDirectory);
qCInfo(LogCommon) << QString("Execute %1 command in the terminal").arg(Properties[Execute].toStringList().join(" "));
qCInfo(LogCommon) << "Run in quake mode :" << parser.isSet(optQuakeMode);
qCInfo(LogCommon) << "Set the window mode on starting :" << parser.isSet(optWindowState);
// 这个位置参数解析出来是无法匹配的,可是不带前面标识符,无法准确使用。
}
return;
Expand Down Expand Up @@ -431,7 +437,7 @@ QStringList Utils::parseExecutePara(QStringList &arguments)
}
arguments.removeOne("-e");
arguments.removeOne("--execute");
qInfo() << "Remove the arguments after '-e',the arguments :" << arguments;
qCInfo(LogCommon) << "Remove the arguments after '-e',the arguments :" << arguments;
}

return paraList;
Expand All @@ -455,7 +461,7 @@ QStringList Utils::parseNestedQString(QString str)
//对路径带空格的脚本,右键执行时不进行拆分处理, //./deepin-terminal "-e" "/home/lx777/Desktop/a b/PerfTools_1.9.sh"
QFileInfo fi(str);
if (fi.isFile()) {
qWarning() << "this is file,not split.";
qCWarning(LogCommon) << "this is file,not split.";
paraList.append(str);
return paraList;
}
Expand Down Expand Up @@ -522,7 +528,7 @@ QList<QByteArray> Utils::encodeList()
}
}
if (!bFind)
qWarning() << "encode (name :" << name << ") not find!";
qCWarning(LogCommon) << "encode (name :" << name << ") not find!";
else
encodeList << encodename;

Expand Down Expand Up @@ -593,12 +599,12 @@ bool Utils::isLoongarch()
if(m_Arch.isEmpty()) {
utsname utsbuf;
if (uname(&utsbuf) == -1) {
qWarning() << "get Arch error";
qCWarning(LogCommon) << "get Arch error";
return false;
}
m_Arch = QString::fromLocal8Bit(utsbuf.machine);
}
qInfo() << "Current system architecture:" << m_Arch;
qCInfo(LogCommon) << "Current system architecture:" << m_Arch;
return "mips64" == m_Arch || "loongarch64" == m_Arch;
}

Expand Down Expand Up @@ -627,7 +633,7 @@ void Utils::insertToDefaultConfigJson(QVariant &jsonVar, const QString &groups_k
obj = objArrayFind(obj, "groups", "key", groups_key2);
obj = objArrayFind(obj, "options", "key", options_key);
if(!obj) {
qWarning() << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
qCWarning(LogCommon) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
return;
}
obj->insert(key, value);
Expand All @@ -643,7 +649,7 @@ QVariant Utils::getValueInDefaultConfigJson(QVariant &jsonVar, const QString &gr
obj = objArrayFind(obj, "groups", "key", groups_key2);
obj = objArrayFind(obj, "options", "key", options_key);
if(!obj) {
qWarning() << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
qCWarning(LogCommon) << QString("cannot find path %1/%2/%3").arg(groups_key).arg(groups_key2).arg(options_key);
return QVariant();
}
return obj->value(key);
Expand Down Expand Up @@ -672,9 +678,9 @@ MainWindow *Utils::getMainWindow(QWidget *currWidget)
MainWindow *main = nullptr;
QWidget *pWidget = currWidget->parentWidget();
while (pWidget != nullptr) {
qInfo() << "Current Window Class Name :" << pWidget->metaObject()->className();
qCInfo(LogCommon) << "Current Window Class Name :" << pWidget->metaObject()->className();
if (("NormalWindow" == pWidget->objectName()) || ("QuakeWindow" == pWidget->objectName())) {
qInfo() << "has find MainWindow";
qCInfo(LogCommon) << "has find MainWindow";
main = static_cast<MainWindow *>(pWidget);
break;
}
Expand Down Expand Up @@ -717,7 +723,7 @@ void FontFilter::handleWidthFont()
m_thread->start();
return;
}
//qInfo() << "m_thread is Running";
//qCInfo(LogCommon) << "m_thread is Running";
}

void FontFilter::setStop(bool stop)
Expand Down Expand Up @@ -804,7 +810,7 @@ void FontFilter::compareWhiteList()
else
Blacklist.append(sfont);
}
qInfo() << "Font whitelist obtained through the dbus interface :" << DBUSWhitelist;
qInfo() << "Whitelist of real available fonts :" << Whitelist;
qCInfo(LogCommon) << "Font whitelist obtained through the dbus interface :" << DBUSWhitelist;
qCInfo(LogCommon) << "Whitelist of real available fonts :" << Whitelist;
}
/******** Add by ut001000 renfeixiang 2020-06-15:增加 处理等宽字体的类 End***************/
38 changes: 22 additions & 16 deletions src/customcommand/customcommandoptdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
#include <QApplication>
#include <QClipboard>

#ifdef QT_DEBUG
Q_LOGGING_CATEGORY(LogCustomCommand,"log.terminal.customcommand.work")
#else
Q_LOGGING_CATEGORY(LogCustomCommand,"log.terminal.customcommand.work",QtInfoMsg)
#endif

CustomCommandOptDlg::CustomCommandOptDlg(CustomCmdOptType type, CustomCommandData *currItemData, QWidget *parent)
: DAbstractDialog(parent)
, m_type(type)
Expand Down Expand Up @@ -222,14 +228,14 @@
{
//删除
if ("Backspace" == sequence.toString()) {
qInfo() << "The KeySequenceE is Backspace";
qCInfo(LogCustomCommand) << "The KeySequenceE is Backspace";
m_shortCutLineEdit->clear();
m_lastCmdShortcut = "";
return;
}
// 取消
if ("Esc" == sequence.toString()) {
qInfo() << "The KeySequenceE is Esc";
qCInfo(LogCustomCommand) << "The KeySequenceE is Esc";
m_shortCutLineEdit->clear();
m_shortCutLineEdit->setKeySequence(QKeySequence(m_lastCmdShortcut));
/***add by ut001121 zhangmeng 20200521 在快捷键编辑框中按下ESC键时退出窗口 修复BUG27554***/
Expand All @@ -243,10 +249,10 @@
QString reason;
// 判断快捷键是否冲突
if (!ShortcutManager::instance()->checkShortcutValid(checkName, sequence.toString(), reason)) {
qWarning() << "Shortcut key conflict";
qCWarning(LogCustomCommand) << "Shortcut key conflict";
// 冲突
if (sequence.toString() != "Esc") {
qWarning() << "The current shortcut key is not Esc! ("<< sequence <<")";
qCWarning(LogCustomCommand) << "The current shortcut key is not Esc! ("<< sequence <<")";
showShortcutConflictMsgbox(reason);
}
m_shortCutLineEdit->clear();
Expand Down Expand Up @@ -375,21 +381,21 @@

strName = strName.trimmed();//空格的名称是无效的,剔除名称前后的空格
if (strName.isEmpty()) {
qWarning() << "The name of the user-defined command is empty!";
qCWarning(LogCustomCommand) << "The name of the user-defined command is empty!";
m_nameLineEdit->showAlertMessage(tr("Please enter a name"), m_nameLineEdit->parentWidget());
return;
}

/***add begin by ut001121 zhangmeng 20200615 限制名称字符长度 修复BUG31286***/
if (strName.length() > MAX_NAME_LEN) {
qWarning() << "The name should be no more than 32 characters";
qCWarning(LogCustomCommand) << "The name should be no more than 32 characters";
m_nameLineEdit->showAlertMessage(QObject::tr("The name should be no more than 32 characters"), m_nameLineEdit->parentWidget());
return;
}
/***add end by ut001121***/
QString strCommandtemp = strCommand.trimmed();//空格的命令是无效的
if (strCommandtemp.isEmpty()) {
qWarning() << "The custom command is empty";
qCWarning(LogCustomCommand) << "The custom command is empty";
m_commandLineEdit->showAlertMessage(tr("Please enter a command"), m_commandLineEdit->parentWidget());
return;
}
Expand All @@ -404,28 +410,28 @@
QAction *existAction = nullptr;
int icount = 0;
if (CCT_MODIFY == m_type) {
qInfo() << "It is the modify type of custom command operation";
qCInfo(LogCustomCommand) << "It is the modify type of custom command operation";
if (m_bRefreshCheck) {
qInfo() << "CustomCommand was refreshed";
qCInfo(LogCustomCommand) << "CustomCommand was refreshed";
QAction *refreshExitAction = nullptr;
refreshExitAction = ShortcutManager::instance()->checkActionIsExist(*m_newAction);
if (refreshExitAction) {
qWarning() << "The custom command already exists";
qCWarning(LogCustomCommand) << "The custom command already exists";
accept();
return;
}
}

if (strName == m_currItemData->m_cmdName && strCommand == m_currItemData->m_cmdText && keytmp == QKeySequence(m_currItemData->m_cmdShortcut)) {
qInfo() << "The custom command don't need to save again.";
qCInfo(LogCustomCommand) << "The custom command don't need to save again.";
accept();
return;
}

existAction = ShortcutManager::instance()->checkActionIsExistForModify(*m_newAction);

if (strName != m_currItemData->m_cmdName) {
qInfo() << "Custom commands have been changed.";
qCInfo(LogCustomCommand) << "Custom commands have been changed.";
QList<QAction *> &customCommandActionList = ShortcutManager::instance()->getCustomCommandActionList();
for (int i = 0; i < customCommandActionList.size(); i++) {
QAction *curAction = customCommandActionList[i];
Expand All @@ -435,12 +441,12 @@
}
}
} else {
qInfo() << "It is the add type of custom command operation";
qCInfo(LogCustomCommand) << "It is the add type of custom command operation";
existAction = ShortcutManager::instance()->checkActionIsExist(*m_newAction);
}

if (nullptr != existAction || icount) {
qInfo() << "The name already exists";
qCInfo(LogCustomCommand) << "The name already exists";
QString strFistLine = tr("The name already exists,");
QString strSecondeLine = tr("please input another one.");
Utils::showSameNameDialog(this, strFistLine, strSecondeLine);
Expand Down Expand Up @@ -701,10 +707,10 @@
Q_EMIT closed();
}

void CustomCommandOptDlg::slotRefreshData(QString oldCmdName, QString newCmdName)

Check warning on line 710 in src/customcommand/customcommandoptdlg.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'oldCmdName' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
if (CCT_ADD == m_type) {
qWarning() << "Currently is the add operation interface";
qCWarning(LogCustomCommand) << "Currently is the add operation interface";
return;
}
//不进行刷新操作
Expand All @@ -716,7 +722,7 @@
return;
}
m_bRefreshCheck = true;
qInfo() << "Refresh custom command data.Curren command name is " << m_nameLineEdit->text();
qCInfo(LogCustomCommand) << "Refresh custom command data.Curren command name is " << m_nameLineEdit->text();

QAction *currAction = new QAction(ShortcutManager::instance());
currAction->setText(newCmdName);
Expand Down
12 changes: 7 additions & 5 deletions src/customcommand/customcommandpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <QParallelAnimationGroup>
#include <QPropertyAnimation>

Q_DECLARE_LOGGING_CATEGORY(LogCustomCommand)

CustomCommandPanel::CustomCommandPanel(QWidget *parent) : CommonPanel(parent)
{
Utils::set_Object_Name(this);
Expand All @@ -44,10 +46,10 @@ void CustomCommandPanel::showCurSearchResult()
void CustomCommandPanel::showAddCustomCommandDlg()
{
if (m_pushButton->hasFocus()) {
qInfo() << "The Add command button has focus to click on!";
qCInfo(LogCustomCommand) << "The Add command button has focus to click on!";
m_bpushButtonHaveFocus = true;
} else {
qInfo() << "The Add command button has no focus to prohibit clicking!";
qCInfo(LogCustomCommand) << "The Add command button has no focus to prohibit clicking!";
m_bpushButtonHaveFocus = false;
}

Expand Down Expand Up @@ -84,13 +86,13 @@ void CustomCommandPanel::onFocusOut(Qt::FocusReason type)
// 下一个 或 列表为空, 焦点定位到添加按钮上
m_pushButton->setFocus();
m_cmdListWidget->clearIndex();
qInfo() << "Set the focus to the Add command button";
qCInfo(LogCustomCommand) << "Set the focus to the Add command button";
} else if (Qt::BacktabFocusReason == type) {
// 判断是否可见,可见设置焦点
if (m_searchEdit->isVisible()) {
m_searchEdit->lineEdit()->setFocus();
m_cmdListWidget->clearIndex();
qInfo() << "Set the focus to the Search edit";
qCInfo(LogCustomCommand) << "Set the focus to the Search edit";
}
}
}
Expand Down Expand Up @@ -171,7 +173,7 @@ void CustomCommandPanel::setFocusInPanel()
// 添加按钮下
m_pushButton->setFocus();
} else {
qWarning() << "focus error unkown reason";
qCWarning(LogCustomCommand) << "focus error unkown reason";
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/customcommand/customcommandplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

//qt
#include <QDebug>
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(LogCustomCommand)

CustomCommandPlugin::CustomCommandPlugin(QObject *parent) : MainWindowPluginInterface(parent)
{
Expand Down Expand Up @@ -76,7 +78,7 @@ void CustomCommandPlugin::doShowPlugin(const QString name, bool bSetFocus)
if (MainWindow::PLUGIN_TYPE_CUSTOMCOMMAND != name) {
// 若插件已经显示,则隐藏
if (m_isShow) {
qWarning() << "Command top panel hide";
qCWarning(LogCustomCommand) << "Command top panel hide";
getCustomCommandTopPanel()->hideAnim();
m_isShow = false;
}
Expand Down
10 changes: 6 additions & 4 deletions src/customcommand/customcommandsearchrstpanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <QCoreApplication>
#include <QTimer>
#include <QDebug>
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(LogCustomCommand)

CustomCommandSearchRstPanel::CustomCommandSearchRstPanel(QWidget *parent)
: CommonPanel(parent)
Expand Down Expand Up @@ -103,7 +105,7 @@ inline void CustomCommandSearchRstPanel::handleIconButtonFocusOut(Qt::FocusReaso
// tab 进入 +
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Tab, Qt::MetaModifier);
QApplication::sendEvent(Utils::getMainWindow(this), &keyPress);
qInfo() << "search panel focus to '+'";
qCInfo(LogCustomCommand) << "search panel focus to '+'";
}
}

Expand All @@ -114,13 +116,13 @@ inline void CustomCommandSearchRstPanel::handleListViewFocusOut(Qt::FocusReason
// tab 进入 +
QKeyEvent keyPress(QEvent::KeyPress, Qt::Key_Tab, Qt::MetaModifier);
QApplication::sendEvent(Utils::getMainWindow(this), &keyPress);
qInfo() << "search panel focus on '+'";
qCInfo(LogCustomCommand) << "search panel focus on '+'";
m_cmdListWidget->clearIndex();
} else if (Qt::BacktabFocusReason == type || Qt::NoFocusReason == type) {
// shift + tab 返回 返回键 // 列表为空,也返回到返回键上
m_rebackButton->setFocus();
m_cmdListWidget->clearIndex();
qInfo() << "search panel type (" << type << ")";
qCInfo(LogCustomCommand) << "search panel type (" << type << ")";
}
}

Expand All @@ -144,7 +146,7 @@ void CustomCommandSearchRstPanel::refreshData(const QString &strFilter)

void CustomCommandSearchRstPanel::doCustomCommand(const QString &strKey)
{
qInfo() << "Search for the current custom commonds based on the key (" << strKey << ")";
qCInfo(LogCustomCommand) << "Search for the current custom commonds based on the key (" << strKey << ")";
QAction *item = ShortcutManager::instance()->findActionByKey(strKey);
QString strCommand = item ? item->data().toString() : "";
if (!strCommand.endsWith('\n'))
Expand Down
Loading