OSDN Git Service

Implemented support for using 32-Bit Avisynth with 64-Bit x264.
[x264-launcher/x264-launcher.git] / src / model_logFile.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "model_logFile.h"
23 #include "thread_encode.h"
24
25 #include <QIcon>
26 #include <QApplication>
27 #include <QClipboard>
28
29 LogFileModel::LogFileModel(void)
30 {
31         m_lines << "Job not started yet.";
32         m_firstLine = true;
33 }
34
35 LogFileModel::~LogFileModel(void)
36 {
37 }
38
39 ///////////////////////////////////////////////////////////////////////////////
40 // Model interface
41 ///////////////////////////////////////////////////////////////////////////////
42
43 int LogFileModel::columnCount(const QModelIndex &parent) const
44 {
45         return 1;
46 }
47
48 int LogFileModel::rowCount(const QModelIndex &parent) const
49 {
50         return m_lines.count();
51 }
52
53 QVariant LogFileModel::headerData(int section, Qt::Orientation orientation, int role) const 
54 {
55         return QVariant();
56 }
57
58 QModelIndex LogFileModel::index(int row, int column, const QModelIndex &parent) const
59 {
60         return createIndex(row, column, NULL);
61 }
62
63 QModelIndex LogFileModel::parent(const QModelIndex &index) const
64 {
65         return QModelIndex();
66 }
67
68 QVariant LogFileModel::data(const QModelIndex &index, int role) const
69 {
70         if((role == Qt::DisplayRole) || (role == Qt::ToolTipRole))
71         {
72                 if(index.row() >= 0 && index.row() < m_lines.count() && index.column() == 0)
73                 {
74                         return m_lines.at(index.row());
75                 }
76         }
77
78         return QVariant();
79 }
80
81 ///////////////////////////////////////////////////////////////////////////////
82 // Public API
83 ///////////////////////////////////////////////////////////////////////////////
84
85 void LogFileModel::copyToClipboard(void)
86 {
87         QClipboard *clipboard = QApplication::clipboard();
88         clipboard->setText(m_lines.join("\r\n"));
89 }
90
91 ///////////////////////////////////////////////////////////////////////////////
92 // Slots
93 ///////////////////////////////////////////////////////////////////////////////
94
95 void LogFileModel::addLogMessage(const QUuid &jobId, const QString &text)
96 {
97         beginInsertRows(QModelIndex(), m_lines.count(), m_lines.count());
98
99         if(m_firstLine)
100         {
101                 m_firstLine = false;
102                 m_lines.clear();
103         }
104
105         QStringList lines = text.split("\n");
106         for(int i = 0; i < lines.count(); i++)
107         {
108                 m_lines.append(lines.at(i));
109         }
110
111         endInsertRows();
112 }