OSDN Git Service

Some more clean-up + moved some more functions to MUtilities library.
[x264-launcher/x264-launcher.git] / src / model_logFile.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2015 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 #include <QDir>
29
30 LogFileModel::LogFileModel(const QString &sourceName, const QString &outputName, const QString &configName)
31 {
32         m_lines << "Job not started yet." << QString();
33         m_lines << QString("Scheduled source: %1").arg(QDir::toNativeSeparators(sourceName));
34         m_lines << QString("Scheduled output: %1").arg(QDir::toNativeSeparators(outputName));
35         m_lines << QString("Scheduled config: %1").arg(configName);
36         m_firstLine = true;
37 }
38
39 LogFileModel::~LogFileModel(void)
40 {
41 }
42
43 ///////////////////////////////////////////////////////////////////////////////
44 // Model interface
45 ///////////////////////////////////////////////////////////////////////////////
46
47 int LogFileModel::columnCount(const QModelIndex &parent) const
48 {
49         return 1;
50 }
51
52 int LogFileModel::rowCount(const QModelIndex &parent) const
53 {
54         return m_lines.count();
55 }
56
57 QVariant LogFileModel::headerData(int section, Qt::Orientation orientation, int role) const 
58 {
59         return QVariant();
60 }
61
62 QModelIndex LogFileModel::index(int row, int column, const QModelIndex &parent) const
63 {
64         return createIndex(row, column, NULL);
65 }
66
67 QModelIndex LogFileModel::parent(const QModelIndex &index) const
68 {
69         return QModelIndex();
70 }
71
72 QVariant LogFileModel::data(const QModelIndex &index, int role) const
73 {
74         if((role == Qt::DisplayRole) || (role == Qt::ToolTipRole))
75         {
76                 if(index.row() >= 0 && index.row() < m_lines.count() && index.column() == 0)
77                 {
78                         return m_lines.at(index.row());
79                 }
80         }
81
82         return QVariant();
83 }
84
85 ///////////////////////////////////////////////////////////////////////////////
86 // Public API
87 ///////////////////////////////////////////////////////////////////////////////
88
89 void LogFileModel::copyToClipboard(void)
90 {
91         QClipboard *clipboard = QApplication::clipboard();
92         clipboard->setText(m_lines.join("\r\n"));
93 }
94
95 ///////////////////////////////////////////////////////////////////////////////
96 // Slots
97 ///////////////////////////////////////////////////////////////////////////////
98
99 void LogFileModel::addLogMessage(const QUuid &jobId, const QString &text)
100 {
101         beginInsertRows(QModelIndex(), m_lines.count(), m_lines.count());
102
103         if(m_firstLine)
104         {
105                 m_firstLine = false;
106                 m_lines.clear();
107         }
108
109         QStringList lines = text.split("\n");
110         for(int i = 0; i < lines.count(); i++)
111         {
112                 m_lines.append(lines.at(i));
113         }
114
115         endInsertRows();
116 }