1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-23 04:54:18 +00:00

Remove excessive usage of pointer

This commit is contained in:
Chocobo1 2019-03-11 01:00:47 +08:00
parent a3019f56b0
commit 874bc84efc
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
2 changed files with 13 additions and 22 deletions

View File

@ -30,7 +30,6 @@
#include <QDateTime>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include "base/global.h"
@ -40,7 +39,6 @@
FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType)
: m_backup(backup)
, m_maxSize(maxSize)
, m_logFile(nullptr)
{
m_flusher.setInterval(0);
m_flusher.setSingleShot(true);
@ -59,9 +57,7 @@ FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize
FileLogger::~FileLogger()
{
if (!m_logFile) return;
closeLogFile();
delete m_logFile;
}
void FileLogger::changePath(const QString &newPath)
@ -73,11 +69,8 @@ void FileLogger::changePath(const QString &newPath)
if (tmpPath != m_path) {
m_path = tmpPath;
if (m_logFile) {
closeLogFile();
delete m_logFile;
}
m_logFile = new QFile(m_path);
closeLogFile();
m_logFile.setFileName(m_path);
openLogFile();
}
}
@ -119,9 +112,9 @@ void FileLogger::setMaxSize(const int value)
void FileLogger::addLogMessage(const Log::Msg &msg)
{
if (!m_logFile) return;
if (!m_logFile.isOpen()) return;
QTextStream str(m_logFile);
QTextStream str(&m_logFile);
switch (msg.type) {
case Log::INFO:
@ -139,7 +132,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl;
if (m_backup && (m_logFile->size() >= m_maxSize)) {
if (m_backup && (m_logFile.size() >= m_maxSize)) {
closeLogFile();
int counter = 0;
QString backupLogFilename = m_path + ".bak";
@ -159,16 +152,15 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
void FileLogger::flushLog()
{
if (m_logFile)
m_logFile->flush();
if (m_logFile.isOpen())
m_logFile.flush();
}
void FileLogger::openLogFile()
{
if (!m_logFile->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)
|| !m_logFile->setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
delete m_logFile;
m_logFile = nullptr;
if (!m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)
|| !m_logFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner)) {
m_logFile.close();
LogMsg(tr("An error occurred while trying to open the log file. Logging to file is disabled."), Log::CRITICAL);
}
}
@ -176,5 +168,5 @@ void FileLogger::openLogFile()
void FileLogger::closeLogFile()
{
m_flusher.stop();
m_logFile->close();
m_logFile.close();
}

View File

@ -29,11 +29,10 @@
#ifndef FILELOGGER_H
#define FILELOGGER_H
#include <QFile>
#include <QObject>
#include <QTimer>
class QFile;
namespace Log
{
struct Msg;
@ -71,7 +70,7 @@ private:
QString m_path;
bool m_backup;
int m_maxSize;
QFile *m_logFile;
QFile m_logFile;
QTimer m_flusher;
};