From 404218e947fc9bf275b436720d5f1203d46884ea Mon Sep 17 00:00:00 2001 From: lordmulder Date: Mon, 23 Mar 2015 22:05:58 +0100 Subject: [PATCH] Some code simplification. --- src/model_logFile.cpp | 14 ++++++++------ src/version.h | 2 +- src/win_main.cpp | 16 +--------------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/model_logFile.cpp b/src/model_logFile.cpp index b0a50aa..edc942f 100644 --- a/src/model_logFile.cpp +++ b/src/model_logFile.cpp @@ -101,20 +101,22 @@ bool LogFileModel::saveToLocalFile(const QString &fileName) return false; } - QTextStream out(&file); - out.setCodec("UTF-8"); + QTextStream stream(&file); + stream.setCodec("UTF-8"); + stream.setGenerateByteOrderMark(true); + for(QStringList::ConstIterator iter = m_lines.constBegin(); iter != m_lines.constEnd(); iter++) { - out << (*iter) << QLatin1String("\r\n"); - if(out.status() != QTextStream::Status::Ok) + stream << (*iter) << QLatin1String("\r\n"); + if(stream.status() != QTextStream::Status::Ok) { file.close(); return false; } } - out.flush(); - if(out.status() != QTextStream::Status::Ok) + stream.flush(); + if(stream.status() != QTextStream::Status::Ok) { file.close(); return false; diff --git a/src/version.h b/src/version.h index 45298cd..efc3b4f 100644 --- a/src/version.h +++ b/src/version.h @@ -26,7 +26,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 5 #define VER_X264_PATCH 0 -#define VER_X264_BUILD 944 +#define VER_X264_BUILD 945 #define VER_X264_PORTABLE_EDITION (0) diff --git a/src/win_main.cpp b/src/win_main.cpp index 3ecb53a..ed71e38 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -690,21 +690,7 @@ void MainWindow::saveLogFile(const QModelIndex &index) { QDir(QString("%1/logs").arg(x264_data_path())).mkpath("."); QString logFilePath = QString("%1/logs/LOG.%2.%3.txt").arg(x264_data_path(), QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString(Qt::ISODate).replace(':', "-")); - QFile outFile(logFilePath); - if(outFile.open(QIODevice::WriteOnly)) - { - QTextStream outStream(&outFile); - outStream.setCodec("UTF-8"); - outStream.setGenerateByteOrderMark(true); - - const int rows = log->rowCount(QModelIndex()); - for(int i = 0; i < rows; i++) - { - outStream << log->data(log->index(i, 0, QModelIndex()), Qt::DisplayRole).toString() << QLatin1String("\r\n"); - } - outFile.close(); - } - else + if(!log->saveToLocalFile(logFilePath)) { qWarning("Failed to open log file for writing:\n%s", logFilePath.toUtf8().constData()); }