22// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors
33#include " generalconf.h"
44#include " src/core/flameshot.h"
5+ #include " src/utils/abstractlogger.h"
56#include " src/utils/confighandler.h"
7+ #include " src/utils/logfile.h"
68#include < QCheckBox>
79#include < QComboBox>
810#include < QFile>
@@ -56,6 +58,7 @@ GeneralConf::GeneralConf(QWidget* parent)
5658 initAntialiasingPinZoom ();
5759 initUndoLimit ();
5860 initInsecurePixelate ();
61+ initLogToFile ();
5962#ifdef ENABLE_IMGUR
6063 initCopyAndCloseAfterUpload ();
6164 initUploadWithoutConfirmation ();
@@ -121,6 +124,9 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
121124 if (allowEmptySavePath || !config.savePath ().isEmpty ()) {
122125 m_savePath->setText (config.savePath ());
123126 }
127+ m_logToFile->setChecked (config.logToFile ());
128+ m_logFilePath->setText (config.logFilePath ());
129+
124130#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
125131 m_showTray->setChecked (!config.disabledTrayIcon ());
126132#endif
@@ -244,6 +250,7 @@ void GeneralConf::resetConfiguration()
244250 if (reply == QMessageBox::Yes) {
245251 m_savePath->setText (
246252 QStandardPaths::writableLocation (QStandardPaths::PicturesLocation));
253+ m_logFilePath->setText (LogFile::defaultLogFilePath ());
247254 ConfigHandler ().setDefaultSettings ();
248255 _updateComponents (true );
249256 }
@@ -706,6 +713,33 @@ void GeneralConf::changeSavePath()
706713 }
707714}
708715
716+ void GeneralConf::changeLogFilePath ()
717+ {
718+ QString path = ConfigHandler ().logFilePath ();
719+
720+ if (path.isEmpty ()) {
721+ path = LogFile::defaultLogFilePath ();
722+ }
723+
724+ path = QFileDialog::getExistingDirectory (
725+ this ,
726+ tr (" Choose a Folder" ),
727+ path,
728+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
729+
730+ if (!QFileInfo (path).isWritable ()) {
731+ QMessageBox::about (
732+ this , tr (" Error" ), tr (" Unable to write to directory." ));
733+ path = QString ();
734+ }
735+
736+ if (!path.isEmpty ()) {
737+ m_logFilePath->setText (path);
738+ ConfigHandler ().setLogFilePath (path);
739+ LogFile::resetLogFile ();
740+ }
741+ }
742+
709743void GeneralConf::initCopyPathAfterSave ()
710744{
711745 m_copyPathAfterSave = new QCheckBox (tr (" Copy file path after save" ), this );
@@ -880,7 +914,7 @@ void GeneralConf::initInsecurePixelate()
880914{
881915 m_insecurePixelate = new QCheckBox (tr (" Insecure Pixelate" ), this );
882916 m_insecurePixelate->setToolTip (
883- tr (" Draw the pixelation effect in an insecure but more asethetic way." ));
917+ tr (" Draw the pixelation effect in an insecure but more aesthetic way." ));
884918 m_insecurePixelate->setChecked (ConfigHandler ().insecurePixelate ());
885919 m_scrollAreaLayout->addWidget (m_insecurePixelate);
886920
@@ -890,6 +924,70 @@ void GeneralConf::initInsecurePixelate()
890924 &GeneralConf::setInsecurePixelate);
891925}
892926
927+ void GeneralConf::initLogToFile ()
928+ {
929+ auto * box = new QGroupBox (tr (" Logging" ));
930+ box->setFlat (true );
931+ m_layout->addWidget (box);
932+
933+ auto * vboxLayout = new QVBoxLayout ();
934+ box->setLayout (vboxLayout);
935+
936+ m_logToFile = new QCheckBox (tr (" Log to file" ), this );
937+ m_logToFile->setToolTip (
938+ tr (" Save all log messages produced by flameshot to a file" ));
939+ m_logToFile->setChecked (ConfigHandler ().logToFile ());
940+
941+ connect (m_logToFile, &QCheckBox::clicked, this , &GeneralConf::setLogToFile);
942+ vboxLayout->addWidget (m_logToFile);
943+
944+ auto * pathLayout = new QHBoxLayout ();
945+
946+ QString path = ConfigHandler ().logFilePath ();
947+ m_logFilePath = new QLineEdit (path, this );
948+ m_logFilePath->setToolTip (
949+ tr (" The directory where log files will be saved" ));
950+ m_logFilePath->setDisabled (true );
951+ QString foreground = this ->palette ().windowText ().color ().name ();
952+ m_logFilePath->setStyleSheet (QStringLiteral (" color:%1" ).arg (foreground));
953+ pathLayout->addWidget (m_logFilePath);
954+
955+ m_changeLogFilePathButton = new QPushButton (tr (" Change..." ), this );
956+ pathLayout->addWidget (m_changeLogFilePathButton);
957+ connect (m_changeLogFilePathButton,
958+ &QPushButton::clicked,
959+ this ,
960+ &GeneralConf::changeLogFilePath);
961+
962+ vboxLayout->addLayout (pathLayout);
963+
964+ auto * levelLayout = new QHBoxLayout ();
965+ auto * levelLabel = new QLabel (tr (" Minimum Log Level" ));
966+ levelLabel->setToolTip (
967+ tr (" Specify the minimum severity level of log messages that "
968+ " should be saved to disk" ));
969+ levelLayout->addWidget (levelLabel);
970+
971+ m_logFileLevel = new QComboBox (this );
972+
973+ m_logFileLevel->addItem (tr (" Info (All Log Messages)" ),
974+ AbstractLogger::Channel::Info);
975+ m_logFileLevel->addItem (tr (" Warnings and Errors" ),
976+ AbstractLogger::Channel::Warning);
977+ m_logFileLevel->addItem (tr (" Errors" ), AbstractLogger::Channel::Error);
978+
979+ auto level = ConfigHandler ().value (" logFileLevel" ).toInt ();
980+ m_logFileLevel->setCurrentIndex (m_logFileLevel->findData (level));
981+
982+ connect (
983+ m_logFileLevel,
984+ static_cast <void (QComboBox::*)(int )>(&QComboBox::currentIndexChanged),
985+ this ,
986+ &GeneralConf::setLogFileLevel);
987+ levelLayout->addWidget (m_logFileLevel);
988+ vboxLayout->addLayout (levelLayout);
989+ }
990+
893991void GeneralConf::setSelGeoHideTime (int v)
894992{
895993 ConfigHandler ().setValue (" showSelectionGeometryHideTime" , v);
@@ -929,4 +1027,14 @@ void GeneralConf::setReverseArrow(bool checked)
9291027void GeneralConf::setInsecurePixelate (bool checked)
9301028{
9311029 ConfigHandler ().setInsecurePixelate (checked);
932- }
1030+ }
1031+
1032+ void GeneralConf::setLogToFile (bool checked)
1033+ {
1034+ ConfigHandler ().setLogToFile (checked);
1035+ }
1036+
1037+ void GeneralConf::setLogFileLevel (int index)
1038+ {
1039+ ConfigHandler ().setValue (" logFileLevel" , m_logFileLevel->itemData (index));
1040+ }
0 commit comments