Added log file support.

This commit is contained in:
Git User 2012-01-28 19:59:04 +01:00
parent 3007977f0b
commit 072242e14f
11 changed files with 269 additions and 17 deletions

View File

@ -2,7 +2,14 @@
<RCC version="1.0"> <RCC version="1.0">
<qresource> <qresource>
<file>icons/movie.ico</file> <file>icons/movie.ico</file>
<file>buttons/accept.png</file>
<file>buttons/add.png</file> <file>buttons/add.png</file>
<file>buttons/clock_pause.png</file>
<file>buttons/door_in.png</file> <file>buttons/door_in.png</file>
<file>buttons/error.png</file>
<file>buttons/exclamation.png</file>
<file>buttons/find.png</file>
<file>buttons/lightning.png</file>
<file>buttons/play.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -22,6 +22,8 @@
#include "model_jobList.h" #include "model_jobList.h"
#include "thread_encode.h" #include "thread_encode.h"
#include <QIcon>
JobListModel::JobListModel(void) JobListModel::JobListModel(void)
{ {
} }
@ -92,6 +94,9 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
case 1: case 1:
switch(m_status.value(m_jobs.at(index.row()))) switch(m_status.value(m_jobs.at(index.row())))
{ {
case EncodeThread::JobStatus_Enqueued:
return QVariant::fromValue<QString>(tr("Enqueued."));
break;
case EncodeThread::JobStatus_Starting: case EncodeThread::JobStatus_Starting:
return QVariant::fromValue<QString>(tr("Starting...")); return QVariant::fromValue<QString>(tr("Starting..."));
break; break;
@ -124,6 +129,39 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
} }
} }
} }
else if(role == Qt::DecorationRole)
{
if(index.row() >= 0 && index.row() < m_jobs.count() && index.column() == 0)
{
switch(m_status.value(m_jobs.at(index.row())))
{
case EncodeThread::JobStatus_Enqueued:
return QIcon(":/buttons/clock_pause.png");
break;
case EncodeThread::JobStatus_Starting:
return QIcon(":/buttons/lightning.png");
break;
case EncodeThread::JobStatus_Indexing:
return QIcon(":/buttons/find.png");
break;
case EncodeThread::JobStatus_Running:
return QIcon(":/buttons/play.png");
break;
case EncodeThread::JobStatus_Completed:
return QIcon(":/buttons/accept.png");
break;
case EncodeThread::JobStatus_Failed:
return QIcon(":/buttons/exclamation.png");
break;
case EncodeThread::JobStatus_Aborted:
return QIcon(":/buttons/error.png");
break;
default:
return QVariant();
break;
}
}
}
return QVariant(); return QVariant();
} }
@ -135,6 +173,7 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const
bool JobListModel::insertJob(EncodeThread *thread) bool JobListModel::insertJob(EncodeThread *thread)
{ {
QUuid id = thread->getId(); QUuid id = thread->getId();
LogFileModel *logFile = NULL;
if(m_jobs.contains(id)) if(m_jobs.contains(id))
{ {
@ -143,17 +182,27 @@ bool JobListModel::insertJob(EncodeThread *thread)
beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count()); beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count());
m_jobs.append(id); m_jobs.append(id);
m_status.insert(id, EncodeThread::JobStatus_Starting); m_status.insert(id, EncodeThread::JobStatus_Enqueued);
m_progress.insert(id, 0); m_progress.insert(id, 0);
m_threads.insert(id, thread); m_threads.insert(id, thread);
m_logFile.insert(id, (logFile = new LogFileModel));
endInsertRows(); endInsertRows();
connect(thread, SIGNAL(statusChanged(QUuid, EncodeThread::JobStatus)), this, SLOT(updateStatus(QUuid, EncodeThread::JobStatus)), Qt::QueuedConnection); connect(thread, SIGNAL(statusChanged(QUuid, EncodeThread::JobStatus)), this, SLOT(updateStatus(QUuid, EncodeThread::JobStatus)), Qt::QueuedConnection);
connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection); connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection);
connect(thread, SIGNAL(messageLogged(QUuid, QString)), logFile, SLOT(addLogMessage(QUuid, QString)), Qt::QueuedConnection);
return true; return true;
} }
LogFileModel *JobListModel::getLogFile(const QModelIndex &index)
{
if(index.isValid() && index.row() >= 0 && index.row() < m_jobs.count())
{
return m_logFile.value(m_jobs.at(index.row()));
}
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Slots // Slots
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -165,7 +214,7 @@ void JobListModel::updateStatus(const QUuid &jobId, EncodeThread::JobStatus newS
if((index = m_jobs.indexOf(jobId)) >= 0) if((index = m_jobs.indexOf(jobId)) >= 0)
{ {
m_status.insert(jobId, newStatus); m_status.insert(jobId, newStatus);
emit dataChanged(createIndex(index, 1), createIndex(index, 1)); emit dataChanged(createIndex(index, 0), createIndex(index, 1));
} }
} }
@ -179,7 +228,3 @@ void JobListModel::updateProgress(const QUuid &jobId, unsigned int newProgress)
emit dataChanged(createIndex(index, 2), createIndex(index, 2)); emit dataChanged(createIndex(index, 2), createIndex(index, 2));
} }
} }
void JobListModel::addLogMessage(const QUuid &jobId, const QString &text)
{
}

View File

@ -22,6 +22,7 @@
#pragma once #pragma once
#include "thread_encode.h" #include "thread_encode.h"
#include "model_logFile.h"
#include "QAbstractItemModel" #include "QAbstractItemModel"
#include <QUuid> #include <QUuid>
@ -44,15 +45,16 @@ public:
virtual QVariant data(const QModelIndex &index, int role) const; virtual QVariant data(const QModelIndex &index, int role) const;
bool JobListModel::insertJob(EncodeThread *thread); bool JobListModel::insertJob(EncodeThread *thread);
LogFileModel *getLogFile(const QModelIndex &index);
protected: protected:
QList<QUuid> m_jobs; QList<QUuid> m_jobs;
QMap<QUuid, EncodeThread*> m_threads; QMap<QUuid, EncodeThread*> m_threads;
QMap<QUuid, EncodeThread::JobStatus> m_status; QMap<QUuid, EncodeThread::JobStatus> m_status;
QMap<QUuid, unsigned int> m_progress; QMap<QUuid, unsigned int> m_progress;
QMap<QUuid, LogFileModel*> m_logFile;
public slots: public slots:
void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus); void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus);
void updateProgress(const QUuid &jobId, unsigned int newProgress); void updateProgress(const QUuid &jobId, unsigned int newProgress);
void addLogMessage(const QUuid &jobId, const QString &text);
}; };

86
src/model_logFile.cpp Normal file
View File

@ -0,0 +1,86 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#include "model_logFile.h"
#include "thread_encode.h"
#include <QIcon>
LogFileModel::LogFileModel(void)
{
}
LogFileModel::~LogFileModel(void)
{
}
///////////////////////////////////////////////////////////////////////////////
// Model interface
///////////////////////////////////////////////////////////////////////////////
int LogFileModel::columnCount(const QModelIndex &parent) const
{
return 1;
}
int LogFileModel::rowCount(const QModelIndex &parent) const
{
return m_lines.count();
}
QVariant LogFileModel::headerData(int section, Qt::Orientation orientation, int role) const
{
return QVariant();
}
QModelIndex LogFileModel::index(int row, int column, const QModelIndex &parent) const
{
return createIndex(row, column, NULL);
}
QModelIndex LogFileModel::parent(const QModelIndex &index) const
{
return QModelIndex();
}
QVariant LogFileModel::data(const QModelIndex &index, int role) const
{
if(role == Qt::DisplayRole)
{
if(index.row() >= 0 && index.row() < m_lines.count() && index.column() == 0)
{
return m_lines.at(index.row());
}
}
return QVariant();
}
///////////////////////////////////////////////////////////////////////////////
// Slots
///////////////////////////////////////////////////////////////////////////////
void LogFileModel::addLogMessage(const QUuid &jobId, const QString &text)
{
beginInsertRows(QModelIndex(), m_lines.count(), m_lines.count());
m_lines.append(text);
endInsertRows();
}

51
src/model_logFile.h Normal file
View File

@ -0,0 +1,51 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// http://www.gnu.org/licenses/gpl-2.0.txt
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include "thread_encode.h"
#include "QAbstractItemModel"
#include <QUuid>
#include <QStringList>
#include <QMap>
class LogFileModel : public QAbstractItemModel
{
Q_OBJECT
public:
LogFileModel(void);
~LogFileModel(void);
virtual int columnCount(const QModelIndex &parent) const;
virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
virtual QModelIndex parent (const QModelIndex &index) const;
virtual QVariant data(const QModelIndex &index, int role) const;
protected:
QStringList m_lines;
public slots:
void addLogMessage(const QUuid &jobId, const QString &text);
};

View File

@ -20,6 +20,7 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#include "thread_encode.h" #include "thread_encode.h"
#include "global.h"
EncodeThread::EncodeThread(void) EncodeThread::EncodeThread(void)
: :
@ -37,4 +38,33 @@ EncodeThread::~EncodeThread(void)
void EncodeThread::run(void) void EncodeThread::run(void)
{ {
try
{
encode();
}
catch(char *msg)
{
emit messageLogged(m_jobId, QString("EXCEPTION ERROR: ").append(QString::fromLatin1(msg)));
}
catch(...)
{
emit messageLogged(m_jobId, QString("EXCEPTION ERROR !!!"));
}
}
void EncodeThread::encode(void)
{
Sleep(1500);
for(int i = 0; i <= 100; i++)
{
emit progressChanged(m_jobId, i);
emit statusChanged(m_jobId, (i % 2) ? JobStatus_Indexing : JobStatus_Running);
Sleep(200);
emit messageLogged(m_jobId, QUuid::createUuid().toString());
}
Sleep(1500);
emit statusChanged(m_jobId, JobStatus_Completed);
} }

View File

@ -31,12 +31,13 @@ class EncodeThread : public QThread
public: public:
enum JobStatus enum JobStatus
{ {
JobStatus_Starting = 0, JobStatus_Enqueued = 0,
JobStatus_Indexing = 1, JobStatus_Starting = 1,
JobStatus_Running = 2, JobStatus_Indexing = 2,
JobStatus_Completed = 3, JobStatus_Running = 3,
JobStatus_Failed = 4, JobStatus_Completed = 4,
JobStatus_Aborted = 5 JobStatus_Failed = 5,
JobStatus_Aborted = 6
}; };
EncodeThread(void); EncodeThread(void);
@ -48,6 +49,7 @@ protected:
const QUuid m_jobId; const QUuid m_jobId;
virtual void run(void); virtual void run(void);
void encode(void);
signals: signals:
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus); void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);

View File

@ -25,6 +25,7 @@
#include "model_jobList.h" #include "model_jobList.h"
#include <QDate> #include <QDate>
#include <QTimer>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// Constructor & Destructor // Constructor & Destructor
@ -57,6 +58,7 @@ MainWindow::MainWindow(void)
jobsView->horizontalHeader()->resizeSection(1, 150); jobsView->horizontalHeader()->resizeSection(1, 150);
jobsView->horizontalHeader()->resizeSection(2, 90); jobsView->horizontalHeader()->resizeSection(2, 90);
jobsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); jobsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
connect(jobsView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(jobSelected(QModelIndex, QModelIndex)));
//Enable buttons //Enable buttons
connect(buttonAddJob, SIGNAL(clicked()), this, SLOT(addButtonPressed())); connect(buttonAddJob, SIGNAL(clicked()), this, SLOT(addButtonPressed()));
@ -72,8 +74,15 @@ MainWindow::~MainWindow(void)
void MainWindow::addButtonPressed(void) void MainWindow::addButtonPressed(void)
{ {
qWarning("Yeah!");
EncodeThread *thrd = new EncodeThread(); EncodeThread *thrd = new EncodeThread();
m_jobList->insertJob(thrd); m_jobList->insertJob(thrd);
QTimer::singleShot(2500, thrd, SLOT(start()));
}
void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & previous)
{
qDebug("Job selected: %d", current.row());
logView->setModel(m_jobList->getLogFile(current));
logView->scrollToBottom();
} }

View File

@ -38,4 +38,5 @@ private:
private slots: private slots:
void addButtonPressed(void); void addButtonPressed(void);
void jobSelected(const QModelIndex & current, const QModelIndex & previous);
}; };

View File

@ -129,6 +129,14 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
</CustomBuild> </CustomBuild>
<CustomBuild Include="src\model_logFile.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp"</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp"</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
</CustomBuild>
<ClInclude Include="src\targetver.h" /> <ClInclude Include="src\targetver.h" />
<ClInclude Include="src\version.h" /> <ClInclude Include="src\version.h" />
<CustomBuild Include="src\win_main.h"> <CustomBuild Include="src\win_main.h">
@ -142,11 +150,13 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\model_jobList.cpp" /> <ClCompile Include="src\model_jobList.cpp" />
<ClCompile Include="src\model_logFile.cpp" />
<ClCompile Include="src\thread_encode.cpp" /> <ClCompile Include="src\thread_encode.cpp" />
<ClCompile Include="src\global.cpp" /> <ClCompile Include="src\global.cpp" />
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="src\win_main.cpp" /> <ClCompile Include="src\win_main.cpp" />
<ClCompile Include="tmp\moc\moc_model_jobList.cpp" /> <ClCompile Include="tmp\moc\moc_model_jobList.cpp" />
<ClCompile Include="tmp\moc\moc_model_logFile.cpp" />
<ClCompile Include="tmp\moc\moc_thread_encode.cpp" /> <ClCompile Include="tmp\moc\moc_thread_encode.cpp" />
<ClCompile Include="tmp\moc\moc_win_main.cpp" /> <ClCompile Include="tmp\moc\moc_win_main.cpp" />
<ClCompile Include="tmp\qrc\qrc_resources.cpp" /> <ClCompile Include="tmp\qrc\qrc_resources.cpp" />

View File

@ -62,6 +62,12 @@
<ClCompile Include="tmp\moc\moc_model_jobList.cpp"> <ClCompile Include="tmp\moc\moc_model_jobList.cpp">
<Filter>Generated Files</Filter> <Filter>Generated Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\model_logFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tmp\moc\moc_model_logFile.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="gui\win_main.ui"> <CustomBuild Include="gui\win_main.ui">
@ -79,5 +85,8 @@
<CustomBuild Include="src\model_jobList.h"> <CustomBuild Include="src\model_jobList.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</CustomBuild> </CustomBuild>
<CustomBuild Include="src\model_logFile.h">
<Filter>Header Files</Filter>
</CustomBuild>
</ItemGroup> </ItemGroup>
</Project> </Project>