From 36b5af3cb9ce8e5530c5bd9353a4e2f10da506b6 Mon Sep 17 00:00:00 2001 From: windrammer <31085911+likeawindrammer@users.noreply.github.com> Date: Fri, 31 Jul 2020 14:14:39 -0600 Subject: [PATCH] Add option for automatic logging (#203) Just so we're on the same page, this is enabled by default. Co-authored-by: Cents02 --- include/aoapplication.h | 3 +++ include/aooptionsdialog.h | 2 ++ src/aooptionsdialog.cpp | 16 +++++++++++++++- src/courtroom.cpp | 6 ++++-- src/packet_distribution.cpp | 17 ++++++++++------- src/text_file_functions.cpp | 6 ++++++ 6 files changed, 40 insertions(+), 10 deletions(-) diff --git a/include/aoapplication.h b/include/aoapplication.h index af357d0..f4685ec 100644 --- a/include/aoapplication.h +++ b/include/aoapplication.h @@ -427,6 +427,9 @@ public: // Get the message for the CM for casing alerts. QString get_casing_can_host_cases(); + // Get if automatic logging is enabled + bool get_auto_logging_enabled(); + // The file name of the log file in base/logs. QString log_filename; diff --git a/include/aooptionsdialog.h b/include/aooptionsdialog.h index 06684ef..2b8c879 100644 --- a/include/aooptionsdialog.h +++ b/include/aooptionsdialog.h @@ -131,6 +131,8 @@ private: QCheckBox *ui_casing_cm_cb; QLabel *ui_casing_cm_cases_lbl; QLineEdit *ui_casing_cm_cases_textbox; + QLabel *ui_log_lbl; + QCheckBox *ui_log_cb; bool needs_default_audiodev(); diff --git a/src/aooptionsdialog.cpp b/src/aooptionsdialog.cpp index 79f1d11..6cedee8 100644 --- a/src/aooptionsdialog.cpp +++ b/src/aooptionsdialog.cpp @@ -699,6 +699,20 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) ui_casing_layout->setWidget(row, QFormLayout::FieldRole, ui_casing_cm_cases_textbox); + //Check whether mass logging is enabled + row += 1; + ui_log_lbl = new QLabel(ui_casing_widget); + ui_log_lbl->setText(tr("Automatic Logging:")); + ui_log_lbl->setToolTip( + tr("If checked, all logs will be automatically written in the " + "/logs folder.")); + + ui_casing_layout->setWidget(row, QFormLayout::LabelRole, ui_log_lbl); + + ui_log_cb = new QCheckBox(ui_casing_widget); + ui_log_cb->setChecked(ao_app->get_auto_logging_enabled()); + + ui_casing_layout->setWidget(row, QFormLayout::FieldRole, ui_log_cb); // When we're done, we should continue the updates! setUpdatesEnabled(true); @@ -725,7 +739,7 @@ void AOOptionsDialog::save_pressed() configini->setValue("stickyeffects", ui_stickyeffects_cb->isChecked()); configini->setValue("stickypres", ui_stickypres_cb->isChecked()); configini->setValue("customchat", ui_customchat_cb->isChecked()); - + configini->setValue("automatic_logging_enabled", ui_log_cb->isChecked()); QFile *callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); if (callwordsini->open(QIODevice::WriteOnly | QIODevice::Truncate | diff --git a/src/courtroom.cpp b/src/courtroom.cpp index b203cf0..98b6a9c 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -1870,7 +1870,8 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) chatlogpiece *temp = new chatlogpiece(f_charname, f_showname, m_chatmessage[MESSAGE], false, m_chatmessage[TEXT_COLOR].toInt()); ic_chatlog_history.append(*temp); - ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); + if (ao_app->get_auto_logging_enabled()) + ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); while (ic_chatlog_history.size() > log_maximum_blocks && log_maximum_blocks > 0) { @@ -3175,7 +3176,8 @@ void Courtroom::handle_song(QStringList *p_contents) if (!mute_map.value(n_char)) { chatlogpiece *temp = new chatlogpiece(str_char, str_show, f_song, true, m_chatmessage[TEXT_COLOR].toInt()); ic_chatlog_history.append(*temp); - ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); + if (ao_app->get_auto_logging_enabled()) + ao_app->append_to_file(temp->get_full(), ao_app->log_filename, true); while (ic_chatlog_history.size() > log_maximum_blocks && log_maximum_blocks > 0) { diff --git a/src/packet_distribution.cpp b/src/packet_distribution.cpp index 669b954..b543cfb 100644 --- a/src/packet_distribution.cpp +++ b/src/packet_distribution.cpp @@ -292,13 +292,16 @@ void AOApplication::server_packet_received(AOPacket *p_packet) // Remove any characters not accepted in folder names for the server_name // here - this->log_filename = QDateTime::currentDateTime().toUTC().toString( - "'logs/" + server_name.remove(QRegExp("[\\\\/:*?\"<>|\']")) + - "/'ddd MMMM yyyy hh.mm.ss t'.log'"); - this->write_to_file("Joined server " + server_name + " on address " + - server_address + " on " + - QDateTime::currentDateTime().toUTC().toString(), - log_filename, true); + if (AOApplication::get_auto_logging_enabled()){ + this->log_filename = QDateTime::currentDateTime().toUTC().toString( + "'logs/" + server_name.remove(QRegExp("[\\\\/:*?\"<>|\']")) + + "/'ddd MMMM yyyy hh.mm.ss t'.log'"); + this->write_to_file("Joined server " + server_name + " on address " + + server_address + " on " + + QDateTime::currentDateTime().toUTC().toString(), + log_filename, true); + } + QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); hash.addData(server_address.toUtf8()); if (is_discord_enabled()) diff --git a/src/text_file_functions.cpp b/src/text_file_functions.cpp index 2340bd8..39754f3 100644 --- a/src/text_file_functions.cpp +++ b/src/text_file_functions.cpp @@ -1049,3 +1049,9 @@ QString AOApplication::get_casing_can_host_cases() .value(); return result; } +bool AOApplication::get_auto_logging_enabled() +{ + QString result = + configini->value("automatic_logging_enabled", "true").value(); + return result.startsWith("true"); +}