From 10d1bb96853f69dc99d8c3c85b1f51510a56baed Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Thu, 22 Dec 2011 12:01:14 +0100 Subject: [PATCH] Some improvements in clip jobs --- src/definitions.h | 2 +- src/projectitem.cpp | 20 ++- src/projectitem.h | 6 +- src/projectlist.cpp | 237 +++++++++++++++------------- src/projectlist.h | 11 +- src/projecttree/abstractclipjob.cpp | 8 +- src/projecttree/abstractclipjob.h | 7 +- src/projecttree/cutclipjob.cpp | 9 +- src/projecttree/cutclipjob.h | 2 +- src/projecttree/proxyclipjob.cpp | 9 +- src/projecttree/proxyclipjob.h | 2 +- 11 files changed, 175 insertions(+), 138 deletions(-) diff --git a/src/definitions.h b/src/definitions.h index e2635fa9..9c69a485 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -57,7 +57,7 @@ enum MessageType { enum TRACKTYPE { AUDIOTRACK = 0, VIDEOTRACK = 1 }; -enum CLIPJOBSTATUS { NOJOB = 0, JOBWAITING = -1, CREATINGJOB = -2, JOBDONE = -3, JOBCRASHED = -4}; +enum CLIPJOBSTATUS { NOJOB = 0, JOBWAITING = -1, JOBWORKING = -2, JOBDONE = -3, JOBCRASHED = -4, JOBABORTED = -5}; struct TrackInfo { TRACKTYPE type; diff --git a/src/projectitem.cpp b/src/projectitem.cpp index 949daf76..65312c03 100644 --- a/src/projectitem.cpp +++ b/src/projectitem.cpp @@ -262,17 +262,27 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con } } -void ProjectItem::setJobStatus(CLIPJOBSTATUS status, int progress, JOBTYPE jobType, const QString &statusMessage) +void ProjectItem::setJobStatus(CLIPJOBSTATUS status, int progress, JOBTYPE jobType) { setData(0, JobTypeRole, jobType); if (progress > 0) setData(0, JobProgressRole, progress); else { setData(0, JobProgressRole, status); - setData(0, JobStatusMessage, statusMessage); - slotSetToolTip(); } } +void ProjectItem::setJobInfo(const QString &statusMessage) +{ + setData(0, JobStatusMessage, statusMessage); + slotSetToolTip(); +} + +void ProjectItem::setConditionalJobStatus(CLIPJOBSTATUS status, JOBTYPE requestedJobType) +{ + if (data(0, JobTypeRole).toInt() == requestedJobType) + setData(0, JobProgressRole, status); +} + bool ProjectItem::hasProxy() const { if (m_clip == NULL) return false; @@ -288,14 +298,14 @@ bool ProjectItem::isProxyReady() const bool ProjectItem::isJobRunning() const { int s = data(0, JobProgressRole).toInt(); - if (s == JOBWAITING || s == CREATINGJOB || s > 0) return true; + if (s == JOBWAITING || s == JOBWORKING || s > 0) return true; return false; } bool ProjectItem::isProxyRunning() const { int s = data(0, JobProgressRole).toInt(); - if ((s == CREATINGJOB || s > 0) && data(0, JobTypeRole).toInt() == (int) PROXYJOB) return true; + if ((s == JOBWORKING || s > 0) && data(0, JobTypeRole).toInt() == (int) PROXYJOB) return true; return false; } diff --git a/src/projectitem.h b/src/projectitem.h index af849bce..2c44d7cb 100644 --- a/src/projectitem.h +++ b/src/projectitem.h @@ -66,7 +66,11 @@ public: static int itemDefaultHeight(); void slotSetToolTip(); /** \brief Set the status of the clip job. */ - void setJobStatus(CLIPJOBSTATUS status, int progress = 0, JOBTYPE jobType = NOJOBTYPE, const QString &statusMessage = QString()); + void setJobStatus(CLIPJOBSTATUS status, int progress = 0, JOBTYPE jobType = NOJOBTYPE); + /** \brief Set the info string for this clip job. */ + void setJobInfo(const QString &statusMessage); + /** \brief Set the status of a clip job if it is of the specified job type. */ + void setConditionalJobStatus(CLIPJOBSTATUS status, JOBTYPE requestedJobType); /** \brief Returns the proxy status for this clip (true means there is a proxy clip). */ bool hasProxy() const; /** \brief Returns true if the proxy for this clip is ready. */ diff --git a/src/projectlist.cpp b/src/projectlist.cpp index e8c5eec9..5cff2f90 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -292,8 +292,8 @@ ProjectList::ProjectList(QWidget *parent) : connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap))); connect(this, SIGNAL(processLog(ProjectItem *, int , int)), this, SLOT(slotProcessLog(ProjectItem *, int , int))); - connect(this, SIGNAL(jobCrashed(ProjectItem *, const QString &, const QString &, const QString)), this, SLOT(slotJobCrashed(ProjectItem *, const QString &, const QString &, const QString))); - + connect(this, SIGNAL(jobCrashed(const QString &, const QString &, const QString &, const QString)), this, SLOT(slotJobCrashed(const QString &, const QString &, const QString &, const QString))); + m_listViewDelegate = new ItemDelegate(m_listView); m_listView->setItemDelegate(m_listViewDelegate); #ifdef NEPOMUK @@ -312,6 +312,8 @@ ProjectList::~ProjectList() m_abortAllJobs = true; m_closing = true; m_thumbnailQueue.clear(); + m_jobThreads.waitForFinished(); + m_jobThreads.clearFutures(); if (!m_jobList.isEmpty()) qDeleteAll(m_jobList); m_jobList.clear(); delete m_menu; @@ -916,7 +918,8 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap setProperties(properties); if (properties.contains("proxy")) { if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty()) - clip->setJobStatus(NOJOB); + // this should only apply to proxy jobs + clip->setConditionalJobStatus(NOJOB, PROXYJOB); } if (properties.contains("name")) { monitorItemEditing(false); @@ -1138,7 +1141,6 @@ void ProjectList::slotDeleteClip(const QString &clipId) return; } deleteJobsForClip(clipId); - if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy")); m_listView->blockSignals(true); QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item); if (!newSelectedItem) @@ -1312,7 +1314,7 @@ void ProjectList::slotGotProxy(const QString &proxyPath) QTreeWidgetItemIterator it(m_listView); ProjectItem *item; - while (*it && !m_abortAllJobs) { + while (*it && !(m_abortAllJobs && m_closing)) { if ((*it)->type() == PROJECTCLIPTYPE) { item = static_cast (*it); if (item->referencedClip()->getProperty("proxy") == proxyPath) @@ -1352,8 +1354,8 @@ void ProjectList::slotResetProjectList() m_listView->blockSignals(true); m_abortAllJobs = true; m_closing = true; - m_proxyThreads.waitForFinished(); - m_proxyThreads.clearFutures(); + m_jobThreads.waitForFinished(); + m_jobThreads.clearFutures(); m_thumbnailQueue.clear(); if (!m_jobList.isEmpty()) qDeleteAll(m_jobList); m_jobList.clear(); @@ -1463,7 +1465,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr bool replace = false; if (brokenClips.contains(item->clipId())) { // if this is a proxy clip, disable proxy - item->setJobStatus(NOJOB); + discardJobs(item->clipId(), PROXYJOB); clip->setProperty("proxy", "-"); replace = true; } @@ -1811,8 +1813,8 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_listView->blockSignals(true); m_abortAllJobs = true; m_closing = true; - m_proxyThreads.waitForFinished(); - m_proxyThreads.clearFutures(); + m_jobThreads.waitForFinished(); + m_jobThreads.clearFutures(); m_thumbnailQueue.clear(); m_listView->clear(); m_processingClips.clear(); @@ -2015,8 +2017,12 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce // Proxy stuff QString size = properties.value("frame_size"); - if (!useProxy() && clip->getProperty("proxy").isEmpty()) setJobStatus(item, NOJOB); - if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setJobStatus(item, NOJOB); + if (!useProxy() && clip->getProperty("proxy").isEmpty()) { + discardJobs(clipId, PROXYJOB); + } + if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") { + discardJobs(clipId, PROXYJOB); + } else if (useProxy() && !item->hasProxy() && !hasPendingProxy(item)) { // proxy video and image clips int maxSize; @@ -2509,11 +2515,10 @@ void ProjectList::slotCreateProxy(const QString id) if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return; QString path = item->referencedClip()->getProperty("proxy"); if (path.isEmpty()) { - jobCrashed(item, i18n("Failed to create proxy, empty path.")); + slotJobCrashed(item, i18n("Failed to create proxy, empty path.")); return; } - if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path); if (m_processingProxy.contains(path)) { // Proxy is already being generated return; @@ -2528,8 +2533,7 @@ void ProjectList::slotCreateProxy(const QString id) ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight())); m_jobList.append(job); - if (!item->isJobRunning()) setJobStatus(item, JOBWAITING, 0, job->jobType, job->statusMessage(JOBWAITING)); - + setJobStatus(item, JOBWAITING); startJobProcess(); } @@ -2595,28 +2599,37 @@ void ProjectList::slotCutClipJob(const QString &id, QPoint zone) if (!extraParams.isEmpty()) jobParams << extraParams; CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams); m_jobList.append(job); - if (!item->isJobRunning()) setJobStatus(item, JOBWAITING, 0, job->jobType, job->statusMessage(JOBWAITING)); - + setJobStatus(item, JOBWAITING); + startJobProcess(); } void ProjectList::startJobProcess() -{ - int ct = 0; - if (!m_proxyThreads.futures().isEmpty()) { +{ + if (!m_jobThreads.futures().isEmpty()) { // Remove inactive threads - QList > futures = m_proxyThreads.futures(); - m_proxyThreads.clearFutures(); + QList > futures = m_jobThreads.futures(); + m_jobThreads.clearFutures(); for (int i = 0; i < futures.count(); i++) if (!futures.at(i).isFinished()) { - m_proxyThreads.addFuture(futures.at(i)); - ct++; + m_jobThreads.addFuture(futures.at(i)); } } - emit jobCount(ct + m_jobList.count()); + int count = 0; + for (int i = 0; i < m_jobList.count(); i++) { + if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING) + count ++; + else { + // remove finished jobs + AbstractClipJob *job = m_jobList.takeAt(i); + delete job; + i--; + } + } + emit jobCount(count); - if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs)); + if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs)); } void ProjectList::slotAbortProxy(const QString id, const QString path) @@ -2624,107 +2637,85 @@ void ProjectList::slotAbortProxy(const QString id, const QString path) QTreeWidgetItemIterator it(m_listView); ProjectItem *item = getItemById(id); if (!item) return; - if (!path.isEmpty() && m_processingProxy.contains(path)) { - m_abortProxy << path; - } - else { - // Should only be done if we were already using a proxy producer - if (!item->isProxyRunning()) slotGotProxy(item); - } + if (!item->isProxyRunning()) slotGotProxy(item); + discardJobs(id, PROXYJOB); } void ProjectList::slotProcessJobs() { while (!m_jobList.isEmpty() && !m_abortAllJobs) { emit projectModified(); - AbstractClipJob *job = m_jobList.takeFirst(); - // Get jobs count - int ct = 0; - QList > futures = m_proxyThreads.futures(); - for (int i = 0; i < futures.count(); i++) - if (futures.at(i).isRunning()) { - ct++; - } - emit jobCount(ct + m_jobList.count()); - - if (job->jobType == PROXYJOB) { - //ProxyJob *pjob = static_cast (job); - kDebug()<<"// STARTING JOB: "<destination(); - if (m_abortProxy.contains(job->destination())) { - m_abortProxy.removeAll(job->destination()); - m_processingProxy.removeAll(job->destination()); - emit cancelRunningJob(job->clipId(), job->cancelProperties()); - delete job; - continue; + AbstractClipJob *job = NULL; + int count = 0; + for (int i = 0; i < m_jobList.count(); i++) { + if (job == NULL && m_jobList.at(i)->jobStatus == JOBWAITING) { + m_jobList.at(i)->jobStatus = JOBWORKING; + job = m_jobList.at(i); + count++; } + else if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING) + count ++; } - + // Set jobs count + emit jobCount(count); + if (job == NULL) { + break; + } + QString destination = job->destination(); + // Get the list of clips that will need to get progress info ProjectItem *processingItem = getItemById(job->clipId()); if (processingItem == NULL) { - delete job; + job->setStatus(JOBDONE); continue; } - - /*while (*it && !m_abortAllJobs) { - if ((*it)->type() == PROJECTCLIPTYPE) { - ProjectItem *item = static_cast (*it); - if (item->referencedClip()->getProperty("proxy") == job->destination()) { - processingItems.append(item); - } - } - ++it; - }*/ // Make sure destination path is writable - QFile file(job->destination()); + QFile file(destination); if (!file.open(QIODevice::WriteOnly)) { - emit jobCrashed(processingItem, i18n("Cannot write to path: %1", job->destination())); - m_processingProxy.removeAll(job->destination()); - delete job; + emit jobCrashed(processingItem->clipId(), i18n("Cannot write to path: %1", destination)); + m_processingProxy.removeAll(destination); + job->setStatus(JOBCRASHED); continue; } file.close(); - QFile::remove(job->destination()); + QFile::remove(destination); - setJobStatus(processingItem, CREATINGJOB, 0, job->jobType, job->statusMessage(CREATINGJOB)); + //setJobStatus(processingItem, JOBWORKING, 0, job->jobType, job->statusMessage()); bool success; QProcess *jobProcess = job->startJob(&success); - int result = -1; if (jobProcess == NULL) { // job is finished if (success) { setJobStatus(processingItem, JOBDONE); - if (job->jobType == PROXYJOB) slotGotProxy(job->destination()); + if (job->jobType == PROXYJOB) slotGotProxy(destination); //TODO: set folder for transcoded clips - else if (job->jobType == CUTJOB) emit addClip(job->destination(), QString(), QString()); + else if (job->jobType == CUTJOB) emit addClip(destination, QString(), QString()); + job->setStatus(JOBDONE); } else { - QFile::remove(job->destination()); - emit jobCrashed(processingItem, job->errorMessage()); + QFile::remove(destination); + emit jobCrashed(processingItem->clipId(), job->errorMessage()); + job->setStatus(JOBCRASHED); } - m_abortProxy.removeAll(job->destination()); - m_processingProxy.removeAll(job->destination()); - delete job; + m_processingProxy.removeAll(destination); continue; } else while (jobProcess->state() != QProcess::NotRunning) { // building proxy file - if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) { + if (m_abortAllJobs || job->jobStatus == JOBABORTED) { + job->jobStatus = JOBABORTED; jobProcess->close(); jobProcess->waitForFinished(); - QFile::remove(job->destination()); - m_abortProxy.removeAll(job->destination()); - m_processingProxy.removeAll(job->destination()); + QFile::remove(destination); + m_processingProxy.removeAll(destination); if (!m_closing) { emit cancelRunningJob(job->clipId(), job->cancelProperties()); - /*for (int i = 0; i < processingItems.count(); i++) - setJobStatus(processingItems.at(i), NOJOB);*/ } - else continue; result = -2; + continue; } else { int progress = job->processLogInfo(); @@ -2733,41 +2724,48 @@ void ProjectList::slotProcessJobs() jobProcess->waitForFinished(500); } jobProcess->waitForFinished(); - m_processingProxy.removeAll(job->destination()); + m_processingProxy.removeAll(destination); if (result == -1) result = jobProcess->exitStatus(); - if (result != -2 && QFileInfo(job->destination()).size() == 0) { + if (result != -2 && QFileInfo(destination).size() == 0) { job->processLogInfo(); - emit jobCrashed(processingItem, i18n("Failed to create file"), QString(), job->errorMessage()); + emit jobCrashed(processingItem->clipId(), i18n("Failed to create file"), QString(), job->errorMessage()); + job->setStatus(JOBCRASHED); result = -2; } - if (result == QProcess::NormalExit) { // proxy successfully created setJobStatus(processingItem, JOBDONE); - if (job->jobType == PROXYJOB) slotGotProxy(job->destination()); + if (job->jobType == PROXYJOB) slotGotProxy(destination); //TODO: set folder for transcoded clips else if (job->jobType == CUTJOB) { CutClipJob *cutJob = static_cast(job); - if (cutJob->addClipToProject) emit addClip(job->destination(), QString(), QString()); + if (cutJob->addClipToProject) emit addClip(destination, QString(), QString()); } + job->setStatus(JOBDONE); } else if (result == QProcess::CrashExit) { // Proxy process crashed - QFile::remove(job->destination()); - emit jobCrashed(processingItem, i18n("Job crashed"), QString(), job->errorMessage()); + QFile::remove(destination); + emit jobCrashed(processingItem->clipId(), i18n("Job crashed"), QString(), job->errorMessage()); + job->setStatus(JOBCRASHED); } - delete job; continue; } - // Thread finished, update count - int ct = -1; // -1 because we don't want to count this terminating thread - QList > futures = m_proxyThreads.futures(); - for (int i = 0; i < futures.count(); i++) - if (futures.at(i).isRunning()) { - ct++; + // Thread finished, cleanup & update count + int count = 0; + for (int i = 0; i < m_jobList.count(); i++) { + if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING) { + count ++; } - emit jobCount(ct + m_jobList.count()); + else { + AbstractClipJob *job = m_jobList.takeAt(i); + delete job; + i--; + } + } + // Set jobs count + emit jobCount(count); } @@ -2844,7 +2842,8 @@ void ProjectList::updateProxyConfig() void ProjectList::slotProcessLog(ProjectItem *item, int progress, int type) { - setJobStatus(item, CREATINGJOB, progress, (JOBTYPE) type); + kDebug()<<"// SET STATUS: "<setJobStatus(status, progress, jobType, statusMessage); + item->setJobStatus(status, progress, jobType); if (status == JOBCRASHED) { DocClipBase *clip = item->referencedClip(); if (!clip) { @@ -3022,8 +3021,8 @@ void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix) void ProjectList::slotCancelJobs() { m_abortAllJobs = true; - m_proxyThreads.waitForFinished(); - m_proxyThreads.clearFutures(); + m_jobThreads.waitForFinished(); + m_jobThreads.clearFutures(); QUndoCommand *command = new QUndoCommand(); command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count())); for (int i = 0; i < m_jobList.count(); i++) { @@ -3070,22 +3069,26 @@ bool ProjectList::hasPendingProxy(ProjectItem *item) void ProjectList::deleteJobsForClip(const QString &clipId) { - QList jobsToDelete; for (int i = 0; i < m_jobList.count(); i++) { if (m_abortAllJobs) break; if (m_jobList.at(i)->clipId() == clipId) { - AbstractClipJob *job = m_jobList.takeAt(i); - delete job; - i--; + m_jobList.at(i)->setStatus(JOBABORTED); } } } +void ProjectList::slotJobCrashed(const QString &id, const QString &label, const QString &actionName, const QString details) +{ + ProjectItem *item = getItemById(id); + if (!item) return; + slotJobCrashed(item, label, actionName, details); + +} + void ProjectList::slotJobCrashed(ProjectItem *item, const QString &label, const QString &actionName, const QString details) { #if KDE_IS_VERSION(4,7,0) m_infoMessage->animatedHide(); - item->setJobStatus(NOJOB); m_errorLog.clear(); m_infoMessage->setText(label); m_infoMessage->setWordWrap(label.length() > 35); @@ -3128,4 +3131,14 @@ void ProjectList::slotShowJobLog() #endif } +void ProjectList::discardJobs(const QString &id, JOBTYPE type) { + for (int i = 0; i < m_jobList.count(); i++) { + if (m_jobList.at(i)->clipId() == id && m_jobList.at(i)->jobType == type) { + // discard this job + m_jobList.at(i)->setStatus(JOBABORTED); + } + } +} + + #include "projectlist.moc" diff --git a/src/projectlist.h b/src/projectlist.h index 3d25bc71..eeb635df 100644 --- a/src/projectlist.h +++ b/src/projectlist.h @@ -329,8 +329,6 @@ private: QList m_thumbnailQueue; QAction *m_proxyAction; QStringList m_processingClips; - /** @brief Holds a list of proxy urls that should be aborted. */ - QStringList m_abortProxy; /** @brief Holds a list of proxy urls that are currently being created. */ QStringList m_processingProxy; QMutex m_mutex; @@ -338,7 +336,7 @@ private: /** @brief We are cleaning up the project list, so stop processing signals. */ bool m_closing; QList m_jobList; - QFutureSynchronizer m_proxyThreads; + QFutureSynchronizer m_jobThreads; InvalidDialog *m_invalidClipDialog; QMenu *m_jobsMenu; SmallInfoLabel *m_infoLabel; @@ -389,6 +387,8 @@ private: bool hasPendingProxy(ProjectItem *item); /** @brief Delete pending jobs for a clip. */ void deleteJobsForClip(const QString &clipId); + /** @brief Discard specific job type for a clip. */ + void discardJobs(const QString &id, JOBTYPE type); private slots: void slotClipSelected(); @@ -435,7 +435,8 @@ private slots: void slotCancelRunningJob(const QString id, stringMap); /** @brief Update a clip's job status. */ void slotProcessLog(ProjectItem *item, int progress, int); - /** @brief A clip fob crashed, inform user. */ + /** @brief A clip job crashed, inform user. */ + void slotJobCrashed(const QString &id, const QString &label, const QString &actionName, const QString details); void slotJobCrashed(ProjectItem *item, const QString &label, const QString &actionName = QString(), const QString details = QString()); /** @brief Display error log for last failed job. */ void slotShowJobLog(); @@ -467,7 +468,7 @@ signals: void cancelRunningJob(const QString, stringMap); void processLog(ProjectItem *, int , int); void addClip(const QString, const QString &, const QString &); - void jobCrashed(ProjectItem *item, const QString &label, const QString &actionName = QString(), const QString details = QString()); + void jobCrashed(const QString, const QString &label, const QString &actionName = QString(), const QString details = QString()); }; #endif diff --git a/src/projecttree/abstractclipjob.cpp b/src/projecttree/abstractclipjob.cpp index df432cfe..81441db2 100644 --- a/src/projecttree/abstractclipjob.cpp +++ b/src/projecttree/abstractclipjob.cpp @@ -30,6 +30,7 @@ AbstractClipJob::AbstractClipJob(JOBTYPE type, CLIPTYPE cType, const QString &id QObject(), clipType(cType), jobType(type), + jobStatus(NOJOB), m_clipId(id), m_jobProcess(NULL) { @@ -39,6 +40,11 @@ AbstractClipJob::~AbstractClipJob() { } +void AbstractClipJob::setStatus(CLIPJOBSTATUS status) +{ + jobStatus = status; +} + const QString AbstractClipJob::clipId() const { return m_clipId; @@ -69,7 +75,7 @@ int AbstractClipJob::processLogInfo() return -1; } -const QString AbstractClipJob::statusMessage(CLIPJOBSTATUS status) +const QString AbstractClipJob::statusMessage() { return QString(); } diff --git a/src/projecttree/abstractclipjob.h b/src/projecttree/abstractclipjob.h index 88461685..7292e38b 100644 --- a/src/projecttree/abstractclipjob.h +++ b/src/projecttree/abstractclipjob.h @@ -33,19 +33,20 @@ class AbstractClipJob : public QObject Q_OBJECT public: - AbstractClipJob(JOBTYPE type, CLIPTYPE cType, const QString &id, QStringList parameters); - virtual ~ AbstractClipJob(); + AbstractClipJob(JOBTYPE type, CLIPTYPE cType, const QString &id, QStringList parameters); virtual ~ AbstractClipJob(); CLIPTYPE clipType; + CLIPJOBSTATUS jobStatus; JOBTYPE jobType; QString m_clipId; QString description; const QString clipId() const; const QString errorMessage() const; + void setStatus(CLIPJOBSTATUS status); virtual const QString destination() const; virtual QProcess *startJob(bool */*ok*/); virtual stringMap cancelProperties(); virtual int processLogInfo(); - virtual const QString statusMessage(CLIPJOBSTATUS status); + virtual const QString statusMessage(); protected: QString m_errorMessage; diff --git a/src/projecttree/cutclipjob.cpp b/src/projecttree/cutclipjob.cpp index bd247c5d..006b8232 100644 --- a/src/projecttree/cutclipjob.cpp +++ b/src/projecttree/cutclipjob.cpp @@ -27,6 +27,7 @@ CutClipJob::CutClipJob(CLIPTYPE cType, const QString &id, QStringList parameters) : AbstractClipJob(CUTJOB, cType, id, parameters) { + jobStatus = JOBWAITING; description = i18n("clip cut"); m_dest = parameters.at(0); m_src = parameters.at(1); @@ -69,7 +70,7 @@ QProcess *CutClipJob::startJob(bool *ok) int CutClipJob::processLogInfo() { - if (!m_jobProcess || m_jobDuration == 0) return -1; + if (!m_jobProcess || m_jobDuration == 0 || jobStatus == JOBABORTED) return JOBABORTED; QString log = m_jobProcess->readAll(); if (!log.isEmpty()) m_errorMessage.append(log + '\n'); int progress; @@ -107,11 +108,11 @@ stringMap CutClipJob::cancelProperties() return props; } -const QString CutClipJob::statusMessage(CLIPJOBSTATUS status) +const QString CutClipJob::statusMessage() { QString statusInfo; - switch (status) { - case CREATINGJOB: + switch (jobStatus) { + case JOBWORKING: statusInfo = i18n("Extracting clip cut"); break; case JOBWAITING: diff --git a/src/projecttree/cutclipjob.h b/src/projecttree/cutclipjob.h index 8af9b0d9..16765317 100644 --- a/src/projecttree/cutclipjob.h +++ b/src/projecttree/cutclipjob.h @@ -39,7 +39,7 @@ public: stringMap cancelProperties(); int processLogInfo(); bool addClipToProject; - const QString statusMessage(CLIPJOBSTATUS status); + const QString statusMessage(); private: QString m_dest; diff --git a/src/projecttree/proxyclipjob.cpp b/src/projecttree/proxyclipjob.cpp index d7c88011..36e9342a 100644 --- a/src/projecttree/proxyclipjob.cpp +++ b/src/projecttree/proxyclipjob.cpp @@ -29,6 +29,7 @@ ProxyJob::ProxyJob(CLIPTYPE cType, const QString &id, QStringList parameters) : m_jobDuration(0), m_isFfmpegJob(true) { + jobStatus = JOBWAITING; description = i18n("proxy"); m_dest = parameters.at(0); m_src = parameters.at(1); @@ -148,7 +149,7 @@ QProcess *ProxyJob::startJob(bool *ok) int ProxyJob::processLogInfo() { - if (!m_jobProcess) return -1; + if (!m_jobProcess || jobStatus == JOBABORTED) return JOBABORTED; QString log = m_jobProcess->readAll(); if (!log.isEmpty()) m_errorMessage.append(log + '\n'); int progress; @@ -197,11 +198,11 @@ stringMap ProxyJob::cancelProperties() return props; } -const QString ProxyJob::statusMessage(CLIPJOBSTATUS status) +const QString ProxyJob::statusMessage() { QString statusInfo; - switch (status) { - case CREATINGJOB: + switch (jobStatus) { + case JOBWORKING: statusInfo = i18n("Creating proxy"); break; case JOBWAITING: diff --git a/src/projecttree/proxyclipjob.h b/src/projecttree/proxyclipjob.h index 591ea613..6a524630 100644 --- a/src/projecttree/proxyclipjob.h +++ b/src/projecttree/proxyclipjob.h @@ -38,7 +38,7 @@ public: QProcess *startJob(bool *ok); stringMap cancelProperties(); int processLogInfo(); - const QString statusMessage(CLIPJOBSTATUS status); + const QString statusMessage(); private: QString m_dest; -- 2.39.5