forked from Ivasoft/DSView
Log options dailog
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include "pv/appcontrol.h"
|
||||
#include "pv/log.h"
|
||||
#include "pv/ui/langresource.h"
|
||||
#include <QDateTime>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
@@ -199,7 +201,7 @@ bool bHighScale = true;
|
||||
LangResource::Instance()->Load(app._frameOptions.language);
|
||||
|
||||
if (app._appOptions.ableSaveLog){
|
||||
dsv_log_enalbe_logfile(false);
|
||||
dsv_log_enalbe_logfile(app._appOptions.appendLogMode);
|
||||
|
||||
if (app._appOptions.logLevel >= logLevel){
|
||||
dsv_log_level(app._appOptions.logLevel);
|
||||
@@ -209,6 +211,10 @@ bool bHighScale = true;
|
||||
//----------------------run
|
||||
dsv_info("----------------- version: %s-----------------", DS_VERSION_STRING);
|
||||
dsv_info("Qt:%s", QT_VERSION_STR);
|
||||
|
||||
QDateTime dateTime = QDateTime::currentDateTime();
|
||||
std::string strTime = dateTime .toString("yyyy-MM-dd hh:mm:ss").toStdString();
|
||||
dsv_info("%s", strTime.c_str());
|
||||
|
||||
//init core
|
||||
if (!control->Init()){
|
||||
|
||||
@@ -95,6 +95,7 @@ void _loadApp(AppOptions &o, QSettings &st){
|
||||
getFiled("warnofMultiTrig", st, o.warnofMultiTrig, true);
|
||||
getFiled("originalData", st, o.originalData, false);
|
||||
getFiled("ableSaveLog", st, o.ableSaveLog, false);
|
||||
getFiled("appendLogMode", st, o.appendLogMode, false);
|
||||
getFiled("logLevel", st, o.logLevel, 3);
|
||||
getFiled("transDecoderDlg", st, o.transDecoderDlg, true);
|
||||
|
||||
@@ -113,6 +114,7 @@ void _saveApp(AppOptions &o, QSettings &st){
|
||||
setFiled("warnofMultiTrig", st, o.warnofMultiTrig);
|
||||
setFiled("originalData", st, o.originalData);
|
||||
setFiled("ableSaveLog", st, o.ableSaveLog);
|
||||
setFiled("appendLogMode", st, o.appendLogMode);
|
||||
setFiled("logLevel", st, o.logLevel);
|
||||
setFiled("transDecoderDlg", st, o.transDecoderDlg);
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ struct AppOptions
|
||||
bool warnofMultiTrig;
|
||||
bool originalData;
|
||||
bool ableSaveLog;
|
||||
bool appendLogMode;
|
||||
int logLevel;
|
||||
bool transDecoderDlg;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
xlog_writer *dsv_log = nullptr;
|
||||
static xlog_context *log_ctx = nullptr;
|
||||
static bool b_logfile = false;
|
||||
static int log_file_index = -1;
|
||||
static int log_file_index = -1;
|
||||
|
||||
void dsv_log_init()
|
||||
{
|
||||
@@ -61,16 +61,10 @@ void dsv_log_level(int l)
|
||||
void dsv_log_enalbe_logfile(bool append)
|
||||
{
|
||||
if (!b_logfile && log_ctx){
|
||||
b_logfile = true;
|
||||
b_logfile = true;
|
||||
|
||||
QString lf = get_dsv_log_path();
|
||||
|
||||
QString lf;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
lf = QDir::homePath() + "/DSView.log";
|
||||
#else
|
||||
lf = GetAppDataDir() + "/DSView.log";
|
||||
#endif
|
||||
|
||||
dsv_info("%s\"%s\"", "Store log to file: ", lf.toUtf8().data());
|
||||
|
||||
std::string log_file = pv::path::ToUnicodePath(lf);
|
||||
@@ -82,11 +76,36 @@ void dsv_log_enalbe_logfile(bool append)
|
||||
}
|
||||
}
|
||||
|
||||
void dsv_clear_log_file()
|
||||
{
|
||||
QString lf = get_dsv_log_path();
|
||||
std::string log_file = pv::path::ToUnicodePath(lf);
|
||||
int ret = xlog_reset_log_file(log_ctx, log_file_index, log_file.c_str());
|
||||
|
||||
if (ret != 0){
|
||||
dsv_err("%s", "Clear log file error!");
|
||||
}
|
||||
}
|
||||
|
||||
void dsv_remove_log_file()
|
||||
{
|
||||
if (b_logfile && log_ctx)
|
||||
{
|
||||
b_logfile = false;
|
||||
xlog_remove_receiver_by_index(log_ctx, log_file_index);
|
||||
log_file_index = -1;
|
||||
}
|
||||
}
|
||||
|
||||
QString get_dsv_log_path()
|
||||
{
|
||||
QString lf;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
lf = QDir::homePath() + "/DSView.log";
|
||||
#else
|
||||
lf = GetAppDataDir() + "/DSView.log";
|
||||
#endif
|
||||
|
||||
return lf;
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
#define _DSV_LOG_H_
|
||||
|
||||
#include <log/xlog.h>
|
||||
#include <QString>
|
||||
|
||||
extern xlog_writer *dsv_log;
|
||||
|
||||
@@ -34,6 +35,9 @@ void dsv_log_level(int l);
|
||||
|
||||
void dsv_log_enalbe_logfile(bool append);
|
||||
void dsv_remove_log_file();
|
||||
void dsv_clear_log_file();
|
||||
|
||||
QString get_dsv_log_path();
|
||||
|
||||
#define LOG_PREFIX ""
|
||||
#define dsv_err(fmt, args...) xlog_err(dsv_log, LOG_PREFIX fmt, ## args)
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
#include <QFormLayout>
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QFile>
|
||||
#include <QLabel>
|
||||
|
||||
#include "logobar.h"
|
||||
#include "../dialogs/about.h"
|
||||
@@ -41,6 +46,7 @@
|
||||
#include "../appcontrol.h"
|
||||
#include "../log.h"
|
||||
#include "../ui/langresource.h"
|
||||
#include "../ui/msgbox.h"
|
||||
|
||||
|
||||
namespace pv {
|
||||
@@ -228,7 +234,7 @@ void LogoBar::on_action_setting_log()
|
||||
auto *topWind = AppControl::Instance()->GetTopWindow();
|
||||
dialogs::DSDialog dlg(topWind, false, true);
|
||||
dlg.setTitle(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_LOG_OPTIONS), "Log Options"));
|
||||
dlg.setMinimumSize(260, 120);
|
||||
dlg.setMinimumSize(460, 300);
|
||||
QWidget *panel = new QWidget(&dlg);
|
||||
dlg.layout()->addWidget(panel);
|
||||
panel->setMinimumSize(250, 110);
|
||||
@@ -245,19 +251,49 @@ void LogoBar::on_action_setting_log()
|
||||
}
|
||||
cbBox->setCurrentIndex(app._appOptions.logLevel);
|
||||
|
||||
QCheckBox *ckBox = new QCheckBox();
|
||||
ckBox->setChecked(app._appOptions.ableSaveLog);
|
||||
lay->addRow(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SAVE_FILE), "Save To File"), ckBox);
|
||||
QCheckBox *ckSave = new QCheckBox();
|
||||
ckSave->setChecked(app._appOptions.ableSaveLog);
|
||||
lay->addRow(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_SAVE_FILE), "Save To File"), ckSave);
|
||||
|
||||
QCheckBox *ckRebuild = new QCheckBox();
|
||||
ckRebuild->setChecked(app._appOptions.appendLogMode);
|
||||
lay->addRow(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_APPEND_MODE), "Append mode"), ckRebuild);
|
||||
|
||||
QLineEdit *etPath = new QLineEdit();
|
||||
etPath->setReadOnly(true);
|
||||
etPath->setText(get_dsv_log_path());
|
||||
lay->addRow(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_LOG_PATH), "File Path"), etPath);
|
||||
|
||||
QPushButton *btOpen = new QPushButton();
|
||||
btOpen->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_OPEN), "Open"));
|
||||
connect(btOpen, SIGNAL(released()), this, SLOT(on_open_log_file()));
|
||||
|
||||
QPushButton *btClear = new QPushButton();
|
||||
btClear->setText(L_S(STR_PAGE_DLG, S_ID(IDS_DLG_CLEARE), "Clear"));
|
||||
connect(btClear, SIGNAL(released()), this, SLOT(on_clear_log_file()));
|
||||
|
||||
QWidget *btWid = new QWidget();
|
||||
QHBoxLayout *btLay = new QHBoxLayout();
|
||||
btWid->setLayout(btLay);
|
||||
btLay->setSpacing(10);
|
||||
btLay->addWidget(btOpen);
|
||||
btLay->addWidget(btClear);
|
||||
|
||||
lay->addRow("", btWid);
|
||||
|
||||
dlg.exec();
|
||||
|
||||
if (dlg.IsClickYes()){
|
||||
bool ableSave = ckBox->isChecked();
|
||||
bool ableSave = ckSave->isChecked();
|
||||
int level = cbBox->currentIndex();
|
||||
bool appendLogMode = ckRebuild->isChecked();
|
||||
|
||||
if (ableSave != app._appOptions.ableSaveLog || level != app._appOptions.logLevel){
|
||||
if (ableSave != app._appOptions.ableSaveLog
|
||||
|| level != app._appOptions.logLevel
|
||||
|| appendLogMode != app._appOptions.appendLogMode){
|
||||
app._appOptions.ableSaveLog = ableSave;
|
||||
app._appOptions.logLevel = level;
|
||||
app._appOptions.appendLogMode = appendLogMode;
|
||||
app.SaveApp();
|
||||
|
||||
dsv_log_level(level);
|
||||
@@ -270,5 +306,32 @@ void LogoBar::on_action_setting_log()
|
||||
}
|
||||
}
|
||||
|
||||
void LogoBar::on_open_log_file()
|
||||
{
|
||||
QFile qf(get_dsv_log_path());
|
||||
if (qf.exists()){
|
||||
QDesktopServices::openUrl( QUrl("file:///" + get_dsv_log_path()));
|
||||
}
|
||||
else{
|
||||
QString strMsg(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_FILE_NOT_EXIST), "Not exist!"));
|
||||
MsgBox::Show(strMsg);
|
||||
}
|
||||
}
|
||||
|
||||
void LogoBar::on_clear_log_file()
|
||||
{
|
||||
QFile qf(get_dsv_log_path());
|
||||
if (qf.exists()){
|
||||
QString strMsg(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_TO_CLEAR_LOG), "Confirm!"));
|
||||
if (MsgBox::Confirm(strMsg)){
|
||||
dsv_clear_log_file();
|
||||
}
|
||||
}
|
||||
else{
|
||||
QString strMsg(L_S(STR_PAGE_MSG, S_ID(IDS_MSG_FILE_NOT_EXIST), "Not exist!"));
|
||||
MsgBox::Show(strMsg);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace toolbars
|
||||
} // namespace pv
|
||||
|
||||
@@ -71,6 +71,8 @@ private slots:
|
||||
void on_actionIssue_triggered();
|
||||
void on_action_update();
|
||||
void on_action_setting_log();
|
||||
void on_open_log_file();
|
||||
void on_clear_log_file();
|
||||
|
||||
private:
|
||||
bool _enable;
|
||||
|
||||
@@ -300,6 +300,43 @@ XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_pat
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the log file, and reopen from the path.
|
||||
*/
|
||||
XLOG_API int xlog_reset_log_file(xlog_context* ctx, int receiver_index, const char *file_path)
|
||||
{
|
||||
FILE *fh = NULL;
|
||||
int ret = 0;
|
||||
|
||||
if (ctx == NULL || file_path == NULL || *file_path == 0){
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&ctx->_mutext);
|
||||
|
||||
if (receiver_index < ctx->_count && ctx->_receivers[receiver_index]._file != NULL)
|
||||
{
|
||||
fclose(ctx->_receivers[receiver_index]._file);
|
||||
ctx->_receivers[receiver_index]._file = NULL;
|
||||
|
||||
fh = fopen(file_path, "w+");
|
||||
|
||||
if (fh == NULL){
|
||||
strcpy(ctx->_error, "open file error");
|
||||
ret = -1;
|
||||
}
|
||||
else{
|
||||
ctx->_receivers[receiver_index]._file = fh;
|
||||
}
|
||||
}
|
||||
else{
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&ctx->_mutext);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a log data receiver,return 0 if success.
|
||||
*/
|
||||
|
||||
@@ -92,6 +92,11 @@ XLOG_API int xlog_add_receiver(xlog_context* ctx, xlog_receive_callback rev, int
|
||||
*/
|
||||
XLOG_API int xlog_add_receiver_from_file(xlog_context* ctx, const char *file_path, int *out_index, int bAppend);
|
||||
|
||||
/**
|
||||
* Clear the log file, and reopen from the path.
|
||||
*/
|
||||
XLOG_API int xlog_reset_log_file(xlog_context* ctx, int receiver_index, const char *file_path);
|
||||
|
||||
/**
|
||||
* remove a log data receiver,return 0 if success.
|
||||
*/
|
||||
|
||||
@@ -666,5 +666,21 @@
|
||||
{
|
||||
"id": "IDS_DLG_DECODER_IF_TRANS",
|
||||
"text": "翻译参数名称"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_LOG_PATH",
|
||||
"text": "文件位置"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_OPEN",
|
||||
"text": "打开"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_CLEARE",
|
||||
"text": "清除"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_APPEND_MODE",
|
||||
"text": "追加模式"
|
||||
}
|
||||
]
|
||||
@@ -357,5 +357,13 @@
|
||||
{
|
||||
"id": "IDS_MSG_NO_ENABLED_CHANNEL",
|
||||
"text": "未启用通道!"
|
||||
},
|
||||
{
|
||||
"id": "IDS_MSG_FILE_NOT_EXIST",
|
||||
"text": "文件不存在!"
|
||||
},
|
||||
{
|
||||
"id": "IDS_MSG_TO_CLEAR_LOG",
|
||||
"text": "您确定要清除日志文件?"
|
||||
}
|
||||
]
|
||||
@@ -666,5 +666,21 @@
|
||||
{
|
||||
"id": "IDS_DLG_DECODER_IF_TRANS",
|
||||
"text": "Translate param names"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_LOG_PATH",
|
||||
"text": "File Path"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_OPEN",
|
||||
"text": "Open"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_CLEARE",
|
||||
"text": "Clear"
|
||||
},
|
||||
{
|
||||
"id": "IDS_DLG_APPEND_MODE",
|
||||
"text": "Append mode"
|
||||
}
|
||||
]
|
||||
@@ -358,5 +358,13 @@
|
||||
{
|
||||
"id": "IDS_MSG_NO_ENABLED_CHANNEL",
|
||||
"text": "No channels enabled!"
|
||||
},
|
||||
{
|
||||
"id": "IDS_MSG_FILE_NOT_EXIST",
|
||||
"text": "File does not exist!"
|
||||
},
|
||||
{
|
||||
"id": "IDS_MSG_TO_CLEAR_LOG",
|
||||
"text": "Are you sure to clear log file?"
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user