Skip to content

Commit

Permalink
Add LogAddTime
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
QQxiaoming committed Oct 31, 2024
1 parent a8f32d8 commit ab3230b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/globaloptions/globaloptionsterminalwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>440</width>
<height>518</height>
<height>536</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -214,6 +214,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxLogAddTime">
<property name="text">
<string>Log add time</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
7 changes: 7 additions & 0 deletions src/globaloptions/globaloptionswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ GlobalOptionsWindow::GlobalOptionsWindow(QWidget *parent) :
globalOptionsTerminalWidget->ui->checkBoxConfirmMultilinePaste->setChecked(settings.value("ConfirmMultilinePaste", true).toBool());
globalOptionsTerminalWidget->ui->checkBoxTrimPastedTrailingNewlines->setChecked(settings.value("TrimPastedTrailingNewlines", true).toBool());
globalOptionsTerminalWidget->ui->checkBoxEcho->setChecked(settings.value("Echo", false).toBool());
globalOptionsTerminalWidget->ui->checkBoxLogAddTime->setChecked(settings.value("LogAddTime", false).toBool());
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
globalOptionsAdvancedWidget->ui->checkBoxEnableCtrlC->setChecked(settings.value("EnableCtrlC", false).toBool());
#endif
Expand Down Expand Up @@ -707,6 +708,10 @@ QColor GlobalOptionsWindow::getCursorColor(void)
}
}

bool GlobalOptionsWindow::getLogAddTime(void){
return globalOptionsTerminalWidget->ui->checkBoxLogAddTime->isChecked();
}

#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
bool GlobalOptionsWindow::getEnableCtrlC(void)
{
Expand Down Expand Up @@ -787,6 +792,7 @@ void GlobalOptionsWindow::buttonBoxAccepted(void)
settings.setValue("ConfirmMultilinePaste", globalOptionsTerminalWidget->ui->checkBoxConfirmMultilinePaste->isChecked());
settings.setValue("TrimPastedTrailingNewlines", globalOptionsTerminalWidget->ui->checkBoxTrimPastedTrailingNewlines->isChecked());
settings.setValue("Echo", globalOptionsTerminalWidget->ui->checkBoxEcho->isChecked());
settings.setValue("LogAddTime", globalOptionsTerminalWidget->ui->checkBoxLogAddTime->isChecked());
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
settings.setValue("EnableCtrlC", globalOptionsAdvancedWidget->ui->checkBoxEnableCtrlC->isChecked());
#endif
Expand Down Expand Up @@ -874,6 +880,7 @@ void GlobalOptionsWindow::buttonBoxRejected(void)
globalOptionsTerminalWidget->ui->checkBoxConfirmMultilinePaste->setChecked(settings.value("ConfirmMultilinePaste", true).toBool());
globalOptionsTerminalWidget->ui->checkBoxTrimPastedTrailingNewlines->setChecked(settings.value("TrimPastedTrailingNewlines", true).toBool());
globalOptionsTerminalWidget->ui->checkBoxEcho->setChecked(settings.value("Echo", false).toBool());
globalOptionsTerminalWidget->ui->checkBoxLogAddTime->setChecked(settings.value("LogAddTime", false).toBool());
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
globalOptionsAdvancedWidget->ui->checkBoxEnableCtrlC->setChecked(settings.value("EnableCtrlC", false).toBool());
#endif
Expand Down
1 change: 1 addition & 0 deletions src/globaloptions/globaloptionswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class GlobalOptionsWindow : public QDialog
bool getTrimPastedTrailingNewlines(void);
bool getEcho(void);
QColor getCursorColor(void);
bool getLogAddTime(void);
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
bool getEnableCtrlC(void);
#endif
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3813,6 +3813,7 @@ void CentralWidget::setGlobalOptions(SessionsWindow *window) {
window->setTrimPastedTrailingNewlines(globalOptionsWindow->getTrimPastedTrailingNewlines());
window->setEcho(globalOptionsWindow->getEcho());
window->setCursorColor(globalOptionsWindow->getCursorColor());
window->setLogAddTime(globalOptionsWindow->getLogAddTime());
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
window->setEnableHandleCtrlC(globalOptionsWindow->getEnableCtrlC());
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/sessionswindow/sessionswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,10 @@ int SessionsWindow::saveLog(const char *data, int size) {
if(enableLog) {
if(log_file_mutex.tryLock()) {
if(log_file != nullptr) {
if(add_time_on_each_line) {
QString lineText = QTime::currentTime().toString("hh:mm:ss - ");
log_file->write(lineText.toUtf8());
}
ret = log_file->write(data, size);
if(fflush_file) {
log_file->flush();
Expand Down
2 changes: 2 additions & 0 deletions src/sessionswindow/sessionswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class SessionsWindow : public QObject

int setLog(bool enable);
bool isLog(void) { return enableLog; }
void setLogAddTime(bool enable) {add_time_on_each_line = enable;};
QString getLogFileName(void);
int setRawLog(bool enable);
bool isRawLog(void) { return enableRawLog; }
Expand Down Expand Up @@ -490,6 +491,7 @@ class SessionsWindow : public QObject
QMutex recording_script_send_mutex;
QFile *log_file = nullptr;
QFile *raw_log_file = nullptr;
bool add_time_on_each_line = false;
bool fflush_file = true;
QByteArray password_hash;
bool locked = false;
Expand Down

0 comments on commit ab3230b

Please sign in to comment.