1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2021 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "model_logFile.h"
23 #include "thread_encode.h"
26 #include <QApplication>
29 #include <QTextStream>
32 static const QLatin1String
FMT_TIMESTAMP("[yyyy-MM-dd][HH:mm:ss] ");
34 LogFileModel::LogFileModel(const QString
&sourceName
, const QString
&outputName
, const QString
&configName
)
36 const qint64 timeStamp
= QDateTime::currentMSecsSinceEpoch();
37 m_lines
<< qMakePair(timeStamp
, QString("Job not started yet."));
38 m_lines
<< qMakePair(timeStamp
, QString());
39 m_lines
<< qMakePair(timeStamp
, QString("Scheduled source: %1").arg(QDir::toNativeSeparators(sourceName
)));
40 m_lines
<< qMakePair(timeStamp
, QString("Scheduled output: %1").arg(QDir::toNativeSeparators(outputName
)));
41 m_lines
<< qMakePair(timeStamp
, QString("Scheduled config: %1").arg(configName
));
45 LogFileModel::~LogFileModel(void)
49 ///////////////////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////////////////
53 int LogFileModel::columnCount(const QModelIndex
&parent
) const
58 int LogFileModel::rowCount(const QModelIndex
&parent
) const
60 return m_lines
.count();
63 QVariant
LogFileModel::headerData(int section
, Qt::Orientation orientation
, int role
) const
68 QModelIndex
LogFileModel::index(int row
, int column
, const QModelIndex
&parent
) const
70 return createIndex(row
, column
, NULL
);
73 QModelIndex
LogFileModel::parent(const QModelIndex
&index
) const
78 QVariant
LogFileModel::data(const QModelIndex
&index
, int role
) const
80 if((role
== Qt::DisplayRole
) || (role
== Qt::ToolTipRole
))
82 if(index
.row() >= 0 && index
.row() < m_lines
.count() && index
.column() == 0)
84 if (role
== Qt::ToolTipRole
)
86 const LogEntry
&entry
= m_lines
.at(index
.row());
87 const QString timeStamp
= QDateTime::fromMSecsSinceEpoch(entry
.first
).toString(FMT_TIMESTAMP
);
88 return timeStamp
+ entry
.second
;
92 return m_lines
.at(index
.row()).second
;
100 ///////////////////////////////////////////////////////////////////////////////
102 ///////////////////////////////////////////////////////////////////////////////
104 void LogFileModel::copyToClipboard(void) const
106 QClipboard
*const clipboard
= QApplication::clipboard();
108 for (QList
<LogEntry
>::ConstIterator iter
= m_lines
.constBegin(); iter
!= m_lines
.constEnd(); iter
++)
110 const QString timeStamp
= QDateTime::fromMSecsSinceEpoch(iter
->first
).toString(FMT_TIMESTAMP
);
111 buffer
<< (timeStamp
+ iter
->second
);
113 clipboard
->setText(buffer
.join("\r\n"));
116 bool LogFileModel::saveToLocalFile(const QString
&fileName
) const
118 QFile
file(fileName
);
119 if(!file
.open(QIODevice::WriteOnly
| QIODevice::Truncate
))
124 QTextStream
stream(&file
);
125 stream
.setCodec("UTF-8");
126 stream
.setGenerateByteOrderMark(true);
128 for(QList
<LogEntry
>::ConstIterator iter
= m_lines
.constBegin(); iter
!= m_lines
.constEnd(); iter
++)
130 const QString timeStamp
= QDateTime::fromMSecsSinceEpoch(iter
->first
).toString(FMT_TIMESTAMP
);
131 stream
<< timeStamp
<< iter
->second
<< QLatin1String("\r\n");
132 if(stream
.status() != QTextStream::Status::Ok
)
140 if(stream
.status() != QTextStream::Status::Ok
)
150 ///////////////////////////////////////////////////////////////////////////////
152 ///////////////////////////////////////////////////////////////////////////////
154 void LogFileModel::addLogMessage(const QUuid
&jobId
, const qint64
&timeStamp
, const QString
&text
)
156 beginInsertRows(QModelIndex(), m_lines
.count(), m_lines
.count());
164 const QStringList lines
= text
.split("\n");
165 for(QStringList::ConstIterator iter
= lines
.constBegin(); iter
!= lines
.constEnd(); iter
++)
167 m_lines
<< qMakePair(timeStamp
, (*iter
));