From 072242e14f9e136956698b8fb2e90b4b2f48ae6c Mon Sep 17 00:00:00 2001 From: Git User Date: Sat, 28 Jan 2012 19:59:04 +0100 Subject: [PATCH] Added log file support. --- res/resources.qrc | 7 ++++ src/model_jobList.cpp | 61 ++++++++++++++++++++++++++---- src/model_jobList.h | 4 +- src/model_logFile.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++ src/model_logFile.h | 51 +++++++++++++++++++++++++ src/thread_encode.cpp | 30 +++++++++++++++ src/thread_encode.h | 14 ++++--- src/win_main.cpp | 13 ++++++- src/win_main.h | 1 + x264_launcher.vcxproj | 10 +++++ x264_launcher.vcxproj.filters | 9 +++++ 11 files changed, 269 insertions(+), 17 deletions(-) create mode 100644 src/model_logFile.cpp create mode 100644 src/model_logFile.h diff --git a/res/resources.qrc b/res/resources.qrc index fb0898d..f2b9e50 100644 --- a/res/resources.qrc +++ b/res/resources.qrc @@ -2,7 +2,14 @@ icons/movie.ico + buttons/accept.png buttons/add.png + buttons/clock_pause.png buttons/door_in.png + buttons/error.png + buttons/exclamation.png + buttons/find.png + buttons/lightning.png + buttons/play.png diff --git a/src/model_jobList.cpp b/src/model_jobList.cpp index 5f456db..e1c9224 100644 --- a/src/model_jobList.cpp +++ b/src/model_jobList.cpp @@ -22,6 +22,8 @@ #include "model_jobList.h" #include "thread_encode.h" +#include + JobListModel::JobListModel(void) { } @@ -92,6 +94,9 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const case 1: switch(m_status.value(m_jobs.at(index.row()))) { + case EncodeThread::JobStatus_Enqueued: + return QVariant::fromValue(tr("Enqueued.")); + break; case EncodeThread::JobStatus_Starting: return QVariant::fromValue(tr("Starting...")); 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(); } @@ -135,25 +173,36 @@ QVariant JobListModel::data(const QModelIndex &index, int role) const bool JobListModel::insertJob(EncodeThread *thread) { QUuid id = thread->getId(); + LogFileModel *logFile = NULL; if(m_jobs.contains(id)) { return false; } - + beginInsertRows(QModelIndex(), m_jobs.count(), m_jobs.count()); m_jobs.append(id); - m_status.insert(id, EncodeThread::JobStatus_Starting); + m_status.insert(id, EncodeThread::JobStatus_Enqueued); m_progress.insert(id, 0); m_threads.insert(id, thread); + m_logFile.insert(id, (logFile = new LogFileModel)); endInsertRows(); 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(messageLogged(QUuid, QString)), logFile, SLOT(addLogMessage(QUuid, QString)), Qt::QueuedConnection); + 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 /////////////////////////////////////////////////////////////////////////////// @@ -165,7 +214,7 @@ void JobListModel::updateStatus(const QUuid &jobId, EncodeThread::JobStatus newS if((index = m_jobs.indexOf(jobId)) >= 0) { 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)); } } - -void JobListModel::addLogMessage(const QUuid &jobId, const QString &text) -{ -} diff --git a/src/model_jobList.h b/src/model_jobList.h index c4fbc27..bd41835 100644 --- a/src/model_jobList.h +++ b/src/model_jobList.h @@ -22,6 +22,7 @@ #pragma once #include "thread_encode.h" +#include "model_logFile.h" #include "QAbstractItemModel" #include @@ -44,15 +45,16 @@ public: virtual QVariant data(const QModelIndex &index, int role) const; bool JobListModel::insertJob(EncodeThread *thread); + LogFileModel *getLogFile(const QModelIndex &index); protected: QList m_jobs; QMap m_threads; QMap m_status; QMap m_progress; + QMap m_logFile; public slots: void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus); void updateProgress(const QUuid &jobId, unsigned int newProgress); - void addLogMessage(const QUuid &jobId, const QString &text); }; diff --git a/src/model_logFile.cpp b/src/model_logFile.cpp new file mode 100644 index 0000000..4d96bb3 --- /dev/null +++ b/src/model_logFile.cpp @@ -0,0 +1,86 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2012 LoRd_MuldeR +// +// 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 + +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(); +} diff --git a/src/model_logFile.h b/src/model_logFile.h new file mode 100644 index 0000000..3c3af17 --- /dev/null +++ b/src/model_logFile.h @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2012 LoRd_MuldeR +// +// 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 +#include +#include + +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); +}; diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index a0be231..ea2801e 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -20,6 +20,7 @@ /////////////////////////////////////////////////////////////////////////////// #include "thread_encode.h" +#include "global.h" EncodeThread::EncodeThread(void) : @@ -37,4 +38,33 @@ EncodeThread::~EncodeThread(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); } diff --git a/src/thread_encode.h b/src/thread_encode.h index 4932312..ce3a35a 100644 --- a/src/thread_encode.h +++ b/src/thread_encode.h @@ -31,12 +31,13 @@ class EncodeThread : public QThread public: enum JobStatus { - JobStatus_Starting = 0, - JobStatus_Indexing = 1, - JobStatus_Running = 2, - JobStatus_Completed = 3, - JobStatus_Failed = 4, - JobStatus_Aborted = 5 + JobStatus_Enqueued = 0, + JobStatus_Starting = 1, + JobStatus_Indexing = 2, + JobStatus_Running = 3, + JobStatus_Completed = 4, + JobStatus_Failed = 5, + JobStatus_Aborted = 6 }; EncodeThread(void); @@ -48,6 +49,7 @@ protected: const QUuid m_jobId; virtual void run(void); + void encode(void); signals: void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus); diff --git a/src/win_main.cpp b/src/win_main.cpp index f9c3520..fba097d 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -25,6 +25,7 @@ #include "model_jobList.h" #include +#include /////////////////////////////////////////////////////////////////////////////// // Constructor & Destructor @@ -57,6 +58,7 @@ MainWindow::MainWindow(void) jobsView->horizontalHeader()->resizeSection(1, 150); jobsView->horizontalHeader()->resizeSection(2, 90); jobsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); + connect(jobsView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(jobSelected(QModelIndex, QModelIndex))); //Enable buttons connect(buttonAddJob, SIGNAL(clicked()), this, SLOT(addButtonPressed())); @@ -72,8 +74,15 @@ MainWindow::~MainWindow(void) void MainWindow::addButtonPressed(void) { - qWarning("Yeah!"); - EncodeThread *thrd = new EncodeThread(); 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(); } diff --git a/src/win_main.h b/src/win_main.h index 3d4b9b8..715b9d9 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -38,4 +38,5 @@ private: private slots: void addButtonPressed(void); + void jobSelected(const QModelIndex & current, const QModelIndex & previous); }; diff --git a/x264_launcher.vcxproj b/x264_launcher.vcxproj index 5a37b87..32086ed 100644 --- a/x264_launcher.vcxproj +++ b/x264_launcher.vcxproj @@ -129,6 +129,14 @@ $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) + + "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)" + "$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)" + MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp" + MOC "$(SolutionDir)tmp\MOC_%(Filename).cpp" + $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) + $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) + @@ -142,11 +150,13 @@ + + diff --git a/x264_launcher.vcxproj.filters b/x264_launcher.vcxproj.filters index 110f120..6ae9124 100644 --- a/x264_launcher.vcxproj.filters +++ b/x264_launcher.vcxproj.filters @@ -62,6 +62,12 @@ Generated Files + + Source Files + + + Generated Files + @@ -79,5 +85,8 @@ Header Files + + Header Files + \ No newline at end of file -- 2.11.0