X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=2e4bfac0db01a90537f1ea98d5a10672f6894b06;hb=fd65780a125fea8029fe416e515f5000b63476f5;hp=0618aaf5a3211bf8bb6e294a4f30f877774a7303;hpb=b71bbe0b32508be57fd6d2314daf3ab5f36b47e1;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 0618aaf5..2e4bfac0 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -20,6 +20,7 @@ #include "projectlist.h" #include "projectitem.h" #include "commands/addfoldercommand.h" +#include "projecttree/proxyclipjob.h" #include "kdenlivesettings.h" #include "slideshowclip.h" #include "ui_colorclip_ui.h" @@ -50,6 +51,7 @@ #include #include #include +#include #ifdef NEPOMUK #include @@ -68,6 +70,89 @@ #include #include +SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent) +{ + setFixedWidth(0); + setFlat(true); + + /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px; + border-radius: 5px;border-color: beige;}";*/ + KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme())); + QColor bg = scheme.background(KColorScheme::LinkBackground).color(); + QColor fg = scheme.foreground(KColorScheme::LinkText).color(); + QString style = QString("QPushButton {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue()); + + bg = scheme.background(KColorScheme::ActiveBackground).color(); + fg = scheme.foreground(KColorScheme::ActiveText).color(); + style.append(QString("\nQPushButton:hover {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue())); + + setStyleSheet(style); + m_timeLine = new QTimeLine(500, this); + QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal))); + QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished())); + hide(); +} + +void SmallInfoLabel::slotTimeLineChanged(qreal value) +{ + setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width()); + update(); +} + +void SmallInfoLabel::slotTimeLineFinished() +{ + if (m_timeLine->direction() == QTimeLine::Forward) { + // Show + show(); + } else { + // Hide + hide(); + setText(QString()); + } +} + +void SmallInfoLabel::slotSetJobCount(int jobCount) +{ + if (jobCount > 0) { + // prepare animation + setText(i18np("%1 job", "%1 jobs", jobCount)); + setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount)); + + if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) { + show(); + return; + } + + if (isVisible()) { + setFixedWidth(sizeHint().width()); + update(); + return; + } + + setFixedWidth(0); + show(); + int wantedWidth = sizeHint().width(); + setGeometry(-wantedWidth, 0, wantedWidth, height()); + m_timeLine->setDirection(QTimeLine::Forward); + if (m_timeLine->state() == QTimeLine::NotRunning) { + m_timeLine->start(); + } + } + else { + if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) { + hide(); + return; + } + // hide + m_timeLine->setDirection(QTimeLine::Backward); + if (m_timeLine->state() == QTimeLine::NotRunning) { + m_timeLine->start(); + } + } + +} + + InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent) { setCaption(caption); @@ -118,9 +203,11 @@ ProjectList::ProjectList(QWidget *parent) : m_refreshed(false), m_allClipsProcessed(false), m_thumbnailQueue(), - m_abortAllProxies(false), + m_abortAllJobs(false), + m_closing(false), m_invalidClipDialog(NULL) { + qRegisterMetaType ("stringMap"); QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); @@ -129,23 +216,39 @@ ProjectList::ProjectList(QWidget *parent) : QFrame *frame = new QFrame; frame->setFrameStyle(QFrame::NoFrame); QHBoxLayout *box = new QHBoxLayout; + box->setContentsMargins(0, 0, 0, 0); + KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine; - box->addWidget(searchView); - //int s = style()->pixelMetric(QStyle::PM_SmallIconSize); - //m_toolbar->setIconSize(QSize(s, s)); + + // small info button for pending jobs + m_infoLabel = new SmallInfoLabel(this); + connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int))); + m_jobsMenu = new QMenu(this); + QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this); + cancelJobs->setCheckable(false); + connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs())); + m_jobsMenu->addAction(cancelJobs); + m_infoLabel->setMenu(m_jobsMenu); + box->addWidget(m_infoLabel); + + int size = style()->pixelMetric(QStyle::PM_SmallIconSize); + QSize iconSize(size, size); m_addButton = new QToolButton; m_addButton->setPopupMode(QToolButton::MenuButtonPopup); m_addButton->setAutoRaise(true); + m_addButton->setIconSize(iconSize); box->addWidget(m_addButton); m_editButton = new QToolButton; m_editButton->setAutoRaise(true); + m_editButton->setIconSize(iconSize); box->addWidget(m_editButton); m_deleteButton = new QToolButton; m_deleteButton->setAutoRaise(true); + m_deleteButton->setIconSize(iconSize); box->addWidget(m_deleteButton); frame->setLayout(box); layout->addWidget(frame); @@ -166,6 +269,8 @@ ProjectList::ProjectList(QWidget *parent) : connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int))); connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int))); connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *))); + + connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap))); m_listViewDelegate = new ItemDelegate(m_listView); m_listView->setItemDelegate(m_listViewDelegate); @@ -182,8 +287,11 @@ ProjectList::ProjectList(QWidget *parent) : ProjectList::~ProjectList() { - m_abortAllProxies = true; + m_abortAllJobs = true; + m_closing = true; m_thumbnailQueue.clear(); + if (!m_jobList.isEmpty()) qDeleteAll(m_jobList); + m_jobList.clear(); delete m_menu; m_listView->blockSignals(true); m_listView->clear(); @@ -770,7 +878,6 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap referencedClip(), item->referencedClip()->zone(), true); } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) { emit refreshClip(id, false); } @@ -782,6 +889,10 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap setProperties(properties); + if (properties.contains("proxy")) { + if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty()) + clip->setProxyStatus(NOJOB); + } if (properties.contains("name")) { monitorItemEditing(false); clip->setText(0, properties.value("name")); @@ -1113,8 +1224,6 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) item = new ProjectItem(m_listView, clip); } if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading")); - QString proxy = clip->getProperty("proxy"); - if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId()); connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &))); connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString))); if (getProperties) { @@ -1129,9 +1238,10 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) resetThumbsProducer(clip); m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } - else if (item->hasProxy() && !item->isProxyRunning()) { + // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases? + /*else if (item->hasProxy() && !item->isProxyRunning()) { slotCreateProxy(clip->getId()); - } + }*/ KUrl url = clip->fileURL(); #ifdef NEPOMUK @@ -1172,11 +1282,11 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) void ProjectList::slotGotProxy(const QString &proxyPath) { - if (proxyPath.isEmpty() || m_abortAllProxies) return; + if (proxyPath.isEmpty() || m_abortAllJobs) return; QTreeWidgetItemIterator it(m_listView); ProjectItem *item; - while (*it && !m_abortAllProxies) { + while (*it && !m_abortAllJobs) { if ((*it)->type() == PROJECTCLIPTYPE) { item = static_cast (*it); if (item->referencedClip()->getProperty("proxy") == proxyPath) @@ -1214,16 +1324,20 @@ void ProjectList::slotGotProxy(ProjectItem *item) void ProjectList::slotResetProjectList() { m_listView->blockSignals(true); - m_abortAllProxies = true; + m_abortAllJobs = true; + m_closing = true; m_proxyThreads.waitForFinished(); m_proxyThreads.clearFutures(); m_thumbnailQueue.clear(); + if (!m_jobList.isEmpty()) qDeleteAll(m_jobList); + m_jobList.clear(); m_listView->clear(); m_listView->setEnabled(true); emit clipSelected(NULL); m_refreshed = false; m_allClipsProcessed = false; - m_abortAllProxies = false; + m_abortAllJobs = false; + m_closing = false; m_listView->blockSignals(false); } @@ -1247,7 +1361,10 @@ void ProjectList::getCachedThumbnail(ProjectItem *item) KIO::NetAccess::del(KUrl(cachedPixmap), this); requestClipThumbnail(item->clipId()); } - else item->setData(0, Qt::DecorationRole, pix); + else { + processThumbOverlays(item, pix); + item->setData(0, Qt::DecorationRole, pix); + } } else { requestClipThumbnail(item->clipId()); @@ -1320,7 +1437,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->setProxyStatus(NOPROXY); + item->setProxyStatus(NOJOB); clip->setProperty("proxy", "-"); replace = true; } @@ -1332,7 +1449,9 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr xml.removeAttribute("proxy_out"); } if (!replace) replace = xml.attribute("replace") == "1"; - if (replace) resetThumbsProducer(clip); + if (replace) { + resetThumbsProducer(clip); + } m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace); } else if (clip->isPlaceHolder()) { @@ -1349,8 +1468,9 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr } } } else { - if (displayRatioChanged) + if (displayRatioChanged) { requestClipThumbnail(clip->getId()); + } else if (item->data(0, Qt::DecorationRole).isNull()) { getCachedThumbnail(item); } @@ -1529,7 +1649,7 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) kDebug() << "Proxy duration is wrong, try changing transcoding parameters."; emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2); } - item->setProxyStatus(PROXYCRASHED); + item->setProxyStatus(JOBCRASHED); QString path = item->referencedClip()->getProperty("proxy"); KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"); @@ -1655,7 +1775,8 @@ QStringList ProjectList::getGroup() const void ProjectList::setDocument(KdenliveDoc *doc) { m_listView->blockSignals(true); - m_abortAllProxies = true; + m_abortAllJobs = true; + m_closing = true; m_proxyThreads.waitForFinished(); m_proxyThreads.clearFutures(); m_thumbnailQueue.clear(); @@ -1670,7 +1791,8 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); m_doc = doc; - m_abortAllProxies = false; + m_abortAllJobs = false; + m_closing = false; QMap flist = doc->clipManager()->documentFolderList(); QStringList openedFolders = doc->getExpandedFolders(); @@ -1816,7 +1938,10 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) if (!pix.isNull() || !img.isNull()) { monitorItemEditing(false); - if (!img.isNull()) pix = QPixmap::fromImage(img); + if (!img.isNull()) { + pix = QPixmap::fromImage(img); + processThumbOverlays(item, pix); + } it->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); @@ -1856,8 +1981,8 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce // Proxy stuff QString size = properties.value("frame_size"); - if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); - if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY); + if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOJOB); + if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOJOB); else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) { // proxy video and image clips int maxSize; @@ -2003,6 +2128,7 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img) ProjectItem *item = getItemById(clipId); if (item && !img.isNull()) { QPixmap pix = QPixmap::fromImage(img); + processThumbOverlays(item, pix); monitorItemEditing(false); item->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); @@ -2349,10 +2475,10 @@ void ProjectList::slotCreateProxy(const QString id) if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return; QString path = item->referencedClip()->getProperty("proxy"); if (path.isEmpty()) { - setProxyStatus(item, PROXYCRASHED); + setProxyStatus(item, JOBCRASHED); return; } - setProxyStatus(item, PROXYWAITING); + setProxyStatus(item, JOBWAITING); if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path); if (m_processingProxy.contains(path)) { // Proxy is already being generated @@ -2360,18 +2486,20 @@ void ProjectList::slotCreateProxy(const QString id) } if (QFileInfo(path).size() > 0) { // Proxy already created - setProxyStatus(item, PROXYDONE); + setProxyStatus(item, JOBDONE); slotGotProxy(path); return; } m_processingProxy.append(path); - PROXYINFO info; + /*PROXYINFO info; info.dest = path; info.src = item->clipUrl().path(); info.type = item->clipType(); - info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt(); - m_proxyList.append(info); + info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();*/ + ProxyJob *job = new ProxyJob(PROXYJOB, item->clipType(), item->clipId(), 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); + int ct = 0; if (!m_proxyThreads.futures().isEmpty()) { // Remove inactive threads QList > futures = m_proxyThreads.futures(); @@ -2379,8 +2507,11 @@ void ProjectList::slotCreateProxy(const QString id) for (int i = 0; i < futures.count(); i++) if (!futures.at(i).isFinished()) { m_proxyThreads.addFuture(futures.at(i)); + ct++; } } + emit jobCount(ct + m_jobList.count()); + if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy)); } @@ -2388,259 +2519,151 @@ 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; - setProxyStatus(item, NOPROXY); } else { - setProxyStatus(item, NOPROXY); - slotGotProxy(item); + // Should only be done if we were already using a proxy producer + if (!item->isProxyRunning()) slotGotProxy(item); } } void ProjectList::slotGenerateProxy() { - while (!m_proxyList.isEmpty() && !m_abortAllProxies) { + while (!m_jobList.isEmpty() && !m_abortAllJobs) { emit projectModified(); - PROXYINFO info = m_proxyList.takeFirst(); - if (m_abortProxy.contains(info.dest)) { - m_abortProxy.removeAll(info.dest); - continue; + 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; + } } + // Get the list of clips that will need to get progress info QTreeWidgetItemIterator it(m_listView); QList processingItems; - while (*it && !m_abortAllProxies) { + ProjectItem *item = getItemById(job->clipId()); + processingItems.append(item); + + /*while (*it && !m_abortAllJobs) { if ((*it)->type() == PROJECTCLIPTYPE) { ProjectItem *item = static_cast (*it); - if (item->referencedClip()->getProperty("proxy") == info.dest) { + if (item->referencedClip()->getProperty("proxy") == job->destination()) { processingItems.append(item); } } ++it; - } + }*/ // Make sure proxy path is writable - QFile file(info.dest); + QFile file(job->destination()); if (!file.open(QIODevice::WriteOnly)) { for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), PROXYCRASHED); - m_processingProxy.removeAll(info.dest); + setProxyStatus(processingItems.at(i), JOBCRASHED); + m_processingProxy.removeAll(job->destination()); + delete job; continue; } file.close(); - QFile::remove(info.dest); + QFile::remove(job->destination()); for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), CREATINGPROXY); - - // Special case: playlist clips (.mlt or .kdenlive project files) - if (info.type == PLAYLIST) { - // change FFmpeg params to MLT format - QStringList parameters; - parameters << info.src; - parameters << "-consumer" << "avformat:" + info.dest; - QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts); - - foreach(QString s, params) { - s = s.simplified(); - if (s.count(' ') == 0) { - s.append("=1"); - } - else s.replace(' ', '='); - parameters << s; - } - - parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads())); - - //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy - double display_ratio = KdenliveDoc::getDisplayRatio(info.src); - parameters << "aspect=" + QString::number(display_ratio); - - //kDebug()<<"TRANSCOD: "<description); + bool success; + QProcess *jobProcess = job->startJob(&success); + + int result = -1; + if (jobProcess == NULL) { + // job is finished + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), success ? JOBDONE : JOBCRASHED); + if (success) { + slotGotProxy(job->destination()); } - QImage proxy; - // Images are scaled to profile size. - //TODO: Make it be configurable? - if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth()); - else proxy = i.scaledToHeight(m_render->renderHeight()); - if (info.exif > 1) { - // Rotate image according to exif data - QImage processed; - QMatrix matrix; - - switch ( info.exif ) { - case 2: - matrix.scale( -1, 1 ); - break; - case 3: - matrix.rotate( 180 ); - break; - case 4: - matrix.scale( 1, -1 ); - break; - case 5: - matrix.rotate( 270 ); - matrix.scale( -1, 1 ); - break; - case 6: - matrix.rotate( 90 ); - break; - case 7: - matrix.rotate( 90 ); - matrix.scale( -1, 1 ); - break; - case 8: - matrix.rotate( 270 ); - break; - } - processed = proxy.transformed( matrix ); - processed.save(info.dest); + else { + QFile::remove(job->destination()); } - else proxy.save(info.dest); - for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), PROXYDONE); - slotGotProxy(info.dest); - m_abortProxy.removeAll(info.dest); - m_processingProxy.removeAll(info.dest); + m_abortProxy.removeAll(job->destination()); + m_processingProxy.removeAll(job->destination()); + delete job; continue; } - - QStringList parameters; - parameters << "-i" << info.src; - QString params = m_doc->getDocumentProperty("proxyparams").simplified(); - foreach(QString s, params.split(' ')) - parameters << s; - - // Make sure we don't block when proxy file already exists - parameters << "-y"; - parameters << info.dest; - QProcess myProcess; - myProcess.setProcessChannelMode(QProcess::MergedChannels); - myProcess.start("ffmpeg", parameters); - myProcess.waitForStarted(); - int result = -1; - int duration = 0; - - while (myProcess.state() != QProcess::NotRunning) { + else while (jobProcess->state() != QProcess::NotRunning) { // building proxy file - if (m_abortProxy.contains(info.dest) || m_abortAllProxies) { - myProcess.close(); - myProcess.waitForFinished(); - m_abortProxy.removeAll(info.dest); - m_processingProxy.removeAll(info.dest); - QFile::remove(info.dest); - if (!m_abortAllProxies) { - for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), NOPROXY); + if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) { + jobProcess->close(); + jobProcess->waitForFinished(); + QFile::remove(job->destination()); + m_abortProxy.removeAll(job->destination()); + m_processingProxy.removeAll(job->destination()); + if (!m_closing) { + emit cancelRunningJob(job->clipId(), job->cancelProperties()); + /*for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), NOJOB);*/ } else continue; result = -2; } else { - QString log = QString(myProcess.readAll()); - processLogInfo(processingItems, &duration, log); + int progress = job->processLogInfo(); + if (progress > -1) processLogInfo(processingItems, progress); } - myProcess.waitForFinished(500); - } - myProcess.waitForFinished(); - m_abortProxy.removeAll(info.dest); - m_processingProxy.removeAll(info.dest); - if (result == -1) { - result = myProcess.exitStatus(); + jobProcess->waitForFinished(500); } + jobProcess->waitForFinished(); + m_processingProxy.removeAll(job->destination()); + if (result == -1) result = jobProcess->exitStatus(); - // FFmpeg process terminated normally, but make sure proxy clip exists - if (result != -2 && QFileInfo(info.dest).size() == 0) { + if (result != -2 && QFileInfo(job->destination()).size() == 0) { result = QProcess::CrashExit; } - + if (result == QProcess::NormalExit) { // proxy successfully created for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), PROXYDONE); - slotGotProxy(info.dest); + setProxyStatus(processingItems.at(i), JOBDONE); + slotGotProxy(job->destination()); } else if (result == QProcess::CrashExit) { // Proxy process crashed - QFile::remove(info.dest); + QFile::remove(job->destination()); for (int i = 0; i < processingItems.count(); i++) - setProxyStatus(processingItems.at(i), PROXYCRASHED); + setProxyStatus(processingItems.at(i), 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++; + } + emit jobCount(ct + m_jobList.count()); } -void ProjectList::processLogInfo(QList items, int *duration, const QString &log) +void ProjectList::processLogInfo(QList items, int progress) { - int progress; - if (*duration == 0) { - if (log.contains("Duration:")) { - QString data = log.section("Duration:", 1, 1).section(',', 0, 0).simplified(); - QStringList numbers = data.split(':'); - *duration = (int) (numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble()); - } - } - else if (log.contains("time=")) { - QString time = log.section("time=", 1, 1).simplified().section(' ', 0, 0); - if (time.contains(':')) { - QStringList numbers = time.split(':'); - progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble(); - } - else progress = (int) time.toDouble(); - for (int i = 0; i < items.count(); i++) - setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration))); - } + for (int i = 0; i < items.count(); i++) + setProxyStatus(items.at(i), CREATINGJOB, progress); } void ProjectList::updateProxyConfig() @@ -2682,7 +2705,7 @@ void ProjectList::updateProxyConfig() newProps.insert("replace", "1"); // insert required duration for proxy newProps.insert("proxy_out", item->referencedClip()->producerProperty("out")); - new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command); + new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command); } } else if (t == IMAGE && item->referencedClip() != NULL) { @@ -2767,7 +2790,7 @@ void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy) continue; } - oldProps = clip->properties(); + //oldProps = clip->properties(); if (doProxy) { newProps.clear(); QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")); @@ -2775,13 +2798,16 @@ void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy) newProps.insert("proxy_out", clip->producerProperty("out")); newProps.insert("proxy", path); // We need to insert empty proxy so that undo will work - oldProps.insert("proxy", QString()); + //oldProps.insert("proxy", QString()); } else if (item->referencedClip()->getProducer() == NULL) { // Force clip reload kDebug()<<"// CLIP HAD NULL PROD------------"; newProps.insert("resource", item->referencedClip()->getProperty("resource")); } + // We need to insert empty proxy so that undo will work + oldProps = clip->currentProperties(newProps); + if (doProxy) oldProps.insert("proxy", "-"); new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command); } } @@ -2805,7 +2831,7 @@ void ProjectList::slotDeleteProxy(const QString proxyPath) if (item->referencedClip()->getProperty("proxy") == proxyPath) { QMap props; props.insert("proxy", QString()); - new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand); + new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand); } } @@ -2818,12 +2844,12 @@ void ProjectList::slotDeleteProxy(const QString proxyPath) QFile::remove(proxyPath); } -void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress) +void ProjectList::setProxyStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress) { - if (item == NULL || m_abortAllProxies) return; + if (item == NULL || m_abortAllJobs) return; monitorItemEditing(false); item->setProxyStatus(status, progress); - if (status == PROXYCRASHED) { + if (status == JOBCRASHED) { DocClipBase *clip = item->referencedClip(); if (!clip) { kDebug()<<"// PROXY CRASHED"; @@ -2867,4 +2893,58 @@ QStringList ProjectList::expandedFolders() const return result; } +void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix) +{ + if (item->hasProxy()) { + QPainter p(&pix); + QColor c = QPalette().base().color(); + c.setAlpha(160); + QBrush br(c); + p.setBrush(br); + p.setPen(Qt::NoPen); + QRect r(1, 1, 10, 10); + p.drawRect(r); + p.setPen(QPalette().text().color()); + p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P")); + } +} + +void ProjectList::slotCancelJobs() +{ + m_abortAllJobs = true; + m_proxyThreads.waitForFinished(); + m_proxyThreads.clearFutures(); + QUndoCommand *command = new QUndoCommand(); + command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count())); + for (int i = 0; i < m_jobList.count(); i++) { + ProjectItem *item = getItemById(m_jobList.at(i)->clipId()); + if (!item || !item->referencedClip()) continue; + QMap newProps = m_jobList.at(i)->cancelProperties(); + if (newProps.isEmpty()) continue; + QMap oldProps = item->referencedClip()->currentProperties(newProps); + new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command); + } + if (command->childCount() > 0) { + m_doc->commandStack()->push(command); + } + else delete command; + if (!m_jobList.isEmpty()) qDeleteAll(m_jobList); + m_processingProxy.clear(); + m_jobList.clear(); + m_abortAllJobs = false; + m_infoLabel->slotSetJobCount(0); +} + +void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps) +{ + if (newProps.isEmpty()) return; + ProjectItem *item = getItemById(id); + if (!item || !item->referencedClip()) return; + QMap oldProps = item->referencedClip()->currentProperties(newProps); + if (newProps == oldProps) return; + QMapIterator i(oldProps); + EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true); + m_commandStack->push(command); +} + #include "projectlist.moc"