Skip to content

Commit

Permalink
Added logging information to the status bar
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn>
  • Loading branch information
QQxiaoming committed Aug 5, 2024
1 parent dcba91b commit 206df26
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ en-US:

- Add Python scripting engine for scripting feature [#31](https://github.com/QQxiaoming/quardCRT/pull/31)
- Add the feature of selecting end-of-line sequence
- Add logging information to the status bar

zh-CN:

- 为脚本功能添加Python脚本引擎 [#31](https://github.com/QQxiaoming/quardCRT/pull/31)
- 增加选择行尾序列功能
- 增加状态栏日志信息

## [[V0.4.8](https://github.com/QQxiaoming/quardCRT/releases/tag/V0.4.8)] - 2024-07-26

Expand Down
65 changes: 65 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,68 @@ CentralWidget::CentralWidget(QString dir, StartupUIMode mode, QLocale lang, bool
endOfLineSeqMenu->popup(QCursor::pos());
}
});
connect(statusBarWidget,&StatusBarWidget::logsTriggered,this,[&](){
QWidget *widget = findCurrentFocusWidget();
if(widget == nullptr) return;
SessionsWindow *sessionsWindow = widget->property("session").value<SessionsWindow *>();
if(!sessionsWindow->isLocked()) {
QMenu *logsMenu = new QMenu(tr("Logs"),this);
if(sessionsWindow->isLog()) {
QAction *openLogAction = new QAction(tr("Open Log"),this);
openLogAction->setToolTip(tr("Open log file"));
logsMenu->addAction(openLogAction);
connect(openLogAction,&QAction::triggered,this,[=](){
QString logFile = sessionsWindow->getLogFileName();
if(!logFile.isEmpty()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(logFile));
}
});
QAction *stopLogAction = new QAction(tr("Stop Log"),this);
stopLogAction->setToolTip(tr("Stop log to file"));
logsMenu->addAction(stopLogAction);
connect(stopLogAction,&QAction::triggered,this,[=](){
logSessionAction->setChecked(sessionsWindow->setLog(false) != 0);
});
} else {
QAction *startLogAction = new QAction(tr("Start Log"),this);
startLogAction->setToolTip(tr("Start log to file"));
logsMenu->addAction(startLogAction);
connect(startLogAction,&QAction::triggered,this,[=](){
logSessionAction->setChecked(sessionsWindow->setLog(true) == 0);
});
}
if(sessionsWindow->isRawLog()) {
QAction *openRawLogAction = new QAction(tr("Open Raw Log"),this);
openRawLogAction->setToolTip(tr("Open raw log file"));
logsMenu->addAction(openRawLogAction);
connect(openRawLogAction,&QAction::triggered,this,[=](){
QString logFile = sessionsWindow->getRawLogFileName();
if(!logFile.isEmpty()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(logFile));
}
});
QAction *stopRawLogAction = new QAction(tr("Stop Raw Log"),this);
stopRawLogAction->setToolTip(tr("Stop raw log to file"));
logsMenu->addAction(stopRawLogAction);
connect(stopRawLogAction,&QAction::triggered,this,[=](){
rawLogSessionAction->setChecked(sessionsWindow->setRawLog(false) != 0);
});
} else {
QAction *startRawLogAction = new QAction(tr("Start Raw Log"),this);
startRawLogAction->setToolTip(tr("Start raw log to file"));
logsMenu->addAction(startRawLogAction);
connect(startRawLogAction,&QAction::triggered,this,[=](){
rawLogSessionAction->setChecked(sessionsWindow->setRawLog(true) == 0);
});
}

if(logsMenu->isEmpty()) {
delete logsMenu;
return;
}
logsMenu->popup(QCursor::pos());
}
});

initSysEnv();

Expand Down Expand Up @@ -1309,6 +1371,7 @@ void CentralWidget::refreshStatusBar(void) {
statusBarWidget->setTransInfo(false);
statusBarWidget->setSpeedInfo(false);
statusBarWidget->setEndOfLine(false);
statusBarWidget->setLogs(false,false);
return;
}
SessionsWindow *sessionsWindow = widget->property("session").value<SessionsWindow *>();
Expand All @@ -1318,9 +1381,11 @@ void CentralWidget::refreshStatusBar(void) {
statusBarWidget->setTransInfo(false);
statusBarWidget->setSpeedInfo(false);
statusBarWidget->setEndOfLine(false);
statusBarWidget->setLogs(false,false);
return;
}
statusBarWidget->setCursorPosition(sessionsWindow->getCursorLineCount(),sessionsWindow->getCursorColumnCount());
statusBarWidget->setLogs(true,sessionsWindow->isLog() || sessionsWindow->isRawLog());
SessionsWindow::StateInfo stateInfo = sessionsWindow->getStateInfo();
switch(stateInfo.type) {
case SessionsWindow::LocalShell:
Expand Down
20 changes: 20 additions & 0 deletions src/sessionswindow/sessionswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,16 @@ int SessionsWindow::setLog(bool enable) {
return ret;
}

QString SessionsWindow::getLogFileName(void) {
QString ret;
log_file_mutex.lock();
if(log_file != nullptr) {
ret = log_file->fileName();
}
log_file_mutex.unlock();
return ret;
}

int SessionsWindow::setRawLog(bool enable) {
int ret = -1;
raw_log_file_mutex.lock();
Expand Down Expand Up @@ -1078,6 +1088,16 @@ int SessionsWindow::setRawLog(bool enable) {
return ret;
}

QString SessionsWindow::getRawLogFileName(void) {
QString ret;
raw_log_file_mutex.lock();
if(raw_log_file != nullptr) {
ret = raw_log_file->fileName();
}
raw_log_file_mutex.unlock();
return ret;
}

int SessionsWindow::saveLog(const char *data, int size) {
int ret = 0;
if(enableLog) {
Expand Down
2 changes: 2 additions & 0 deletions src/sessionswindow/sessionswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ class SessionsWindow : public QObject

int setLog(bool enable);
bool isLog(void) { return enableLog; }
QString getLogFileName(void);
int setRawLog(bool enable);
bool isRawLog(void) { return enableRawLog; }
QString getRawLogFileName(void);
void setInBroadCastList(bool enable);
bool isInBroadCastList() { return enableBroadCast; }
void setTagColor(bool enable, QColor color = QColor()) {
Expand Down
72 changes: 47 additions & 25 deletions src/statusbarwidget/statusbarwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ StatusBarWidget::StatusBarWidget(QWidget *parent)
statusBarSpeedTx = new StatusBarToolButton(this);
statusBarSpeedRx = new StatusBarToolButton(this);
statusBarEndOfLine = new StatusBarToolButton(this);
statusBarLogs = new StatusBarToolButton(this);
statusBarNotifiction = new StatusBarToolButton(this);
ui->horizontalLayout->addWidget(statusBarCursorInfo);
ui->horizontalLayout->addWidget(statusBarType);
Expand All @@ -47,6 +48,7 @@ StatusBarWidget::StatusBarWidget(QWidget *parent)
ui->horizontalLayout->addWidget(statusBarSpeedTx);
ui->horizontalLayout->addWidget(statusBarSpeedRx);
ui->horizontalLayout->addWidget(statusBarEndOfLine);
ui->horizontalLayout->addWidget(statusBarLogs);
ui->horizontalLayout->addWidget(statusBarNotifiction);

statusBarCursorInfo->setVisible(false);
Expand All @@ -63,35 +65,14 @@ StatusBarWidget::StatusBarWidget(QWidget *parent)
statusBarSpeedTx->setEnabled(false);
statusBarSpeedRx->setEnabled(false);
statusBarEndOfLine->setEnabled(false);

retranslateUi();

statusBarCursorInfo->setPopupMode(QToolButton::InstantPopup);
statusBarCursorInfo->setAutoRaise(true);
statusBarType->setPopupMode(QToolButton::InstantPopup);
statusBarType->setAutoRaise(true);
statusBarTransTx->setPopupMode(QToolButton::InstantPopup);
statusBarTransTx->setAutoRaise(true);
statusBarTransTx->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusBarTransRx->setPopupMode(QToolButton::InstantPopup);
statusBarTransRx->setAutoRaise(true);
statusBarTransRx->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusBarSpeedTx->setPopupMode(QToolButton::InstantPopup);
statusBarSpeedTx->setAutoRaise(true);
statusBarSpeedTx->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusBarSpeedRx->setPopupMode(QToolButton::InstantPopup);
statusBarSpeedRx->setAutoRaise(true);
statusBarSpeedRx->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusBarEndOfLine->setPopupMode(QToolButton::InstantPopup);
statusBarEndOfLine->setAutoRaise(true);
statusBarNotifiction->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
statusBarNotifiction->setPopupMode(QToolButton::InstantPopup);
statusBarNotifiction->setAutoRaise(true);
statusBarLogs->setEnabled(false);

QFont font = this->font();
font.setPixelSize(16);
setFont(font);

retranslateUi();

connect(statusBarCursorInfo,&StatusBarToolButton::clicked,this,[=](){
emit cursorInfoTriggered();
});
Expand All @@ -113,6 +94,9 @@ StatusBarWidget::StatusBarWidget(QWidget *parent)
connect(statusBarEndOfLine,&StatusBarToolButton::clicked,this,[=](){
emit endOfLineTriggered();
});
connect(statusBarLogs,&StatusBarToolButton::clicked,this,[=](){
emit logsTriggered();
});
connect(statusBarNotifiction,&StatusBarToolButton::clicked,this,[=](){
emit notifictionTriggered();
});
Expand Down Expand Up @@ -244,7 +228,30 @@ void StatusBarWidget::setEndOfLine(bool enable, SessionsWindow::EndOfLineSeq typ
}
if(!statusBarEndOfLine->isEnabled()) {
statusBarEndOfLine->setEnabled(true);
statusBarEndOfLine->setVisible(true);
GlobalSetting settings;
statusBarEndOfLine->setVisible(settings.value("Global/Statusbar/EndOfLineUI", true).toBool());
}
}

void StatusBarWidget::setLogs(bool enable, bool isLog) {
m_logs_show = enable;
m_logs = isLog;
if(isLog) {
statusBarLogs->setIcon(QFontIcon::icon(QChar(0xf0c8)));
statusBarLogs->setText(tr("Logging"));
} else {
statusBarLogs->setIcon(QFontIcon::icon(QChar(0xf040)));
statusBarLogs->setText(tr("No Logging"));
}
if(!enable) {
statusBarLogs->setEnabled(false);
statusBarLogs->setVisible(false);
return;
}
if(!statusBarLogs->isEnabled()) {
statusBarLogs->setEnabled(true);
GlobalSetting settings;
statusBarLogs->setVisible(settings.value("Global/Statusbar/LogsUI", true).toBool());
}
}

Expand Down Expand Up @@ -312,6 +319,18 @@ void StatusBarWidget::contextMenuEvent(QContextMenuEvent *event) {
menu->addAction(actionEndOfLine);
}

if(statusBarLogs->isEnabled()) {
QAction *actionLogs = new QAction(tr("Logs Info"), this);
actionLogs->setCheckable(true);
actionLogs->setChecked(statusBarLogs->isVisible());
connect(actionLogs, &QAction::triggered, [this](bool checked) {
GlobalSetting settings;
settings.setValue("Global/Statusbar/LogsUI", checked);
statusBarLogs->setVisible(checked);
});
menu->addAction(actionLogs);
}

if(menu->isEmpty()) {
delete menu;
return;
Expand All @@ -336,6 +355,7 @@ void StatusBarWidget::setFont(QFont &font) {
statusBarSpeedTx->setFont(font);
statusBarSpeedRx->setFont(font);
statusBarEndOfLine->setFont(font);
statusBarLogs->setFont(font);
statusBarNotifiction->setFont(font);
QWidget::setFont(font);
}
Expand All @@ -349,11 +369,13 @@ void StatusBarWidget::retranslateUi()
statusBarSpeedTx->setToolTip(tr("Upload Speed"));
statusBarSpeedRx->setToolTip(tr("Download Speed"));
statusBarEndOfLine->setToolTip(tr("End of line sequence"));
statusBarLogs->setToolTip(tr("Logs Info"));

statusBarTransTx->setIcon(QFontIcon::icon(QChar(0xf0ee)));
statusBarTransRx->setIcon(QFontIcon::icon(QChar(0xf0ed)));
statusBarSpeedTx->setIcon(QFontIcon::icon(QChar(0xf0aa)));
statusBarSpeedRx->setIcon(QFontIcon::icon(QChar(0xf0ab)));
setLogs(m_logs_show,m_logs);
setNotifiction(m_notifiction);

ui->retranslateUi(this);
Expand Down
8 changes: 8 additions & 0 deletions src/statusbarwidget/statusbarwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class StatusBarToolButton : public QToolButton
explicit StatusBarToolButton(QWidget *parent = nullptr)
: QToolButton(parent) {
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
setPopupMode(QToolButton::InstantPopup);
setAutoRaise(true);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
}
~StatusBarToolButton() {
}
Expand Down Expand Up @@ -121,6 +124,7 @@ class StatusBarWidget : public QWidget
void setTransInfo(bool enable, int64_t tx = -1, int64_t rx = -1);
void setSpeedInfo(bool enable, qreal tx = -1.0, qreal rx = -1.0);
void setEndOfLine(bool enable, SessionsWindow::EndOfLineSeq type = SessionsWindow::AUTO);
void setLogs(bool enable, bool isLogs = false);
void setNotifiction(bool enable);
void retranslateUi(void);
void setFont(QFont &font);
Expand All @@ -133,6 +137,7 @@ class StatusBarWidget : public QWidget
void speedTxTriggered(void);
void speedRxTriggered(void);
void endOfLineTriggered(void);
void logsTriggered(void);
void notifictionTriggered(void);

protected:
Expand All @@ -147,7 +152,10 @@ class StatusBarWidget : public QWidget
StatusBarToolButton *statusBarSpeedTx;
StatusBarToolButton *statusBarSpeedRx;
StatusBarToolButton *statusBarEndOfLine;
StatusBarToolButton *statusBarLogs;
StatusBarToolButton *statusBarNotifiction;
bool m_logs_show = false;
bool m_logs = false;
bool m_notifiction = false;
};

Expand Down

0 comments on commit 206df26

Please sign in to comment.