Implement file logger.

This commit is contained in:
sledgehammer999 2016-01-25 01:06:06 +02:00
parent 73832a5ed8
commit 1058572c8a
10 changed files with 566 additions and 6 deletions

View file

@ -167,6 +167,16 @@ options_imp::options_imp(QWidget *parent)
connect(checkAssociateTorrents, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkAssociateMagnetLinks, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
#endif
connect(checkFileLog, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(textFileLogPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(checkFileLogBackup, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkFileLogBackup, SIGNAL(toggled(bool)), spinFileLogSize, SLOT(setEnabled(bool)));
connect(checkFileLogDelete, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
connect(checkFileLogDelete, SIGNAL(toggled(bool)), spinFileLogAge, SLOT(setEnabled(bool)));
connect(checkFileLogDelete, SIGNAL(toggled(bool)), comboFileLogAgeType, SLOT(setEnabled(bool)));
connect(spinFileLogSize, SIGNAL(valueChanged(int)), this, SLOT(enableApplyButton()));
connect(spinFileLogAge, SIGNAL(valueChanged(int)), this, SLOT(enableApplyButton()));
connect(comboFileLogAgeType, SIGNAL(currentIndexChanged(int)), this, SLOT(enableApplyButton()));
// Downloads tab
connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton()));
connect(radioBtnEnableSubcategories, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton()));
@ -434,6 +444,13 @@ void options_imp::saveOptions()
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
}
#endif
pref->setFileLogEnabled(checkFileLog->isChecked());
pref->setFileLogPath(Utils::Fs::fromNativePath(textFileLogPath->text()));
pref->setFileLogBackup(checkFileLogBackup->isChecked());
pref->setFileLogMaxSize(spinFileLogSize->value());
pref->setFileLogDeleteOld(checkFileLogDelete->isChecked());
pref->setFileLogAge(spinFileLogAge->value());
pref->setFileLogAgeType(comboFileLogAgeType->currentIndex());
// End General preferences
auto session = BitTorrent::Session::instance();
@ -588,6 +605,8 @@ void options_imp::loadOptions()
int intValue;
qreal floatValue;
QString strValue;
bool fileLogBackup = true;
bool fileLogDelete = true;
const Preferences* const pref = Preferences::instance();
// General preferences
@ -621,6 +640,19 @@ void options_imp::loadOptions()
checkAssociateMagnetLinks->setChecked(Preferences::isMagnetLinkAssocSet());
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
#endif
checkFileLog->setChecked(pref->fileLogEnabled());
textFileLogPath->setText(Utils::Fs::toNativePath(pref->fileLogPath()));
fileLogBackup = pref->fileLogBackup();
checkFileLogBackup->setChecked(fileLogBackup);
spinFileLogSize->setEnabled(fileLogBackup);
fileLogDelete = pref->fileLogDeleteOld();
checkFileLogDelete->setChecked(fileLogDelete);
spinFileLogAge->setEnabled(fileLogDelete);
comboFileLogAgeType->setEnabled(fileLogDelete);
spinFileLogSize->setValue(pref->fileLogMaxSize());
spinFileLogAge->setValue(pref->fileLogAge());
comboFileLogAgeType->setCurrentIndex(pref->fileLogAgeType());
// End General preferences
auto session = BitTorrent::Session::instance();
@ -1293,6 +1325,19 @@ QString options_imp::askForExportDir(const QString& currentExportPath)
return dir;
}
void options_imp::on_browseFileLogDir_clicked()
{
const QString path = Utils::Fs::expandPathAbs(Utils::Fs::fromNativePath(textFileLogPath->text()));
QDir pathDir(path);
QString dir;
if (!path.isEmpty() && pathDir.exists())
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), pathDir.absolutePath());
else
dir = QFileDialog::getExistingDirectory(this, tr("Choose a save directory"), QDir::homePath());
if (!dir.isNull())
textFileLogPath->setText(Utils::Fs::toNativePath(dir));
}
void options_imp::on_browseExportDirButton_clicked()
{
const QString newExportDir = askForExportDir(textExportDir->text());