refactoring

This commit is contained in:
fourtf
2017-04-12 17:46:44 +02:00
parent 8ef492d7ae
commit 96db82e867
114 changed files with 5554 additions and 3703 deletions
+6 -12
View File
@@ -14,12 +14,10 @@ Channel::Channel(const QString &_channelName, const QString &_baseDirectory)
{
QDateTime now = QDateTime::currentDateTime();
this->fileName =
this->channelName + "-" + now.toString("yyyy-MM-dd") + ".log";
this->fileName = this->channelName + "-" + now.toString("yyyy-MM-dd") + ".log";
// Open file handle to log file of current date
this->fileHandle.setFileName(this->baseDirectory + QDir::separator() +
this->fileName);
this->fileHandle.setFileName(this->baseDirectory + QDir::separator() + this->fileName);
this->fileHandle.open(QIODevice::Append);
this->appendLine(this->generateOpeningString(now));
@@ -31,8 +29,7 @@ Channel::~Channel()
this->fileHandle.close();
}
void
Channel::append(std::shared_ptr<messages::Message> message)
void Channel::append(std::shared_ptr<messages::Message> message)
{
QDateTime now = QDateTime::currentDateTime();
@@ -47,8 +44,7 @@ Channel::append(std::shared_ptr<messages::Message> message)
this->appendLine(str);
}
QString
Channel::generateOpeningString(const QDateTime &now) const
QString Channel::generateOpeningString(const QDateTime &now) const
{
QString ret = QLatin1Literal("# Start logging at ");
@@ -59,8 +55,7 @@ Channel::generateOpeningString(const QDateTime &now) const
return ret;
}
QString
Channel::generateClosingString(const QDateTime &now) const
QString Channel::generateClosingString(const QDateTime &now) const
{
QString ret = QLatin1Literal("# Stop logging at ");
@@ -71,8 +66,7 @@ Channel::generateClosingString(const QDateTime &now) const
return ret;
}
void
Channel::appendLine(const QString &line)
void Channel::appendLine(const QString &line)
{
this->fileHandle.write(line.toUtf8());
this->fileHandle.flush();
+3 -6
View File
@@ -15,17 +15,14 @@ namespace logging {
class Channel
{
public:
explicit Channel(const QString &_channelName,
const QString &_baseDirectory);
explicit Channel(const QString &_channelName, const QString &_baseDirectory);
~Channel();
void append(std::shared_ptr<messages::Message> message);
private:
QString generateOpeningString(
const QDateTime &now = QDateTime::currentDateTime()) const;
QString generateClosingString(
const QDateTime &now = QDateTime::currentDateTime()) const;
QString generateOpeningString(const QDateTime &now = QDateTime::currentDateTime()) const;
QString generateClosingString(const QDateTime &now = QDateTime::currentDateTime()) const;
void appendLine(const QString &line);
+5 -9
View File
@@ -15,13 +15,11 @@ static QString mentionsBasePath;
std::unordered_map<std::string, std::weak_ptr<Channel>> channels;
void
init()
void init()
{
// Make sure all folders are properly created
logBasePath =
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
QDir::separator() + "Logs";
logBasePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
QDir::separator() + "Logs";
channelBasePath = logBasePath + QDir::separator() + "Channels";
whispersBasePath = logBasePath + QDir::separator() + "Whispers";
mentionsBasePath = logBasePath + QDir::separator() + "Mentions";
@@ -55,8 +53,7 @@ init()
}
}
static const QString &
getBaseDirectory(const QString &channelName)
static const QString &getBaseDirectory(const QString &channelName)
{
if (channelName == "/whispers") {
return whispersBasePath;
@@ -67,8 +64,7 @@ getBaseDirectory(const QString &channelName)
}
}
std::shared_ptr<Channel>
get(const QString &channelName)
std::shared_ptr<Channel> get(const QString &channelName)
{
if (channelName.isEmpty()) {
return nullptr;