#include "projectlist.h"
#include "projectitem.h"
#include "commands/addfoldercommand.h"
+#include "projecttree/proxyclipjob.h"
+#include "projecttree/cutclipjob.h"
#include "kdenlivesettings.h"
#include "slideshowclip.h"
#include "ui_colorclip_ui.h"
#include "commands/addclipcutcommand.h"
#include "ui_templateclip_ui.h"
+#include "ui_cutjobdialog_ui.h"
#include <KDebug>
#include <KAction>
#include <KFileItem>
#include <KApplication>
#include <KStandardDirs>
+#include <KColorScheme>
+#include <KActionCollection>
+#include <KUrlRequester>
#ifdef NEPOMUK
#include <nepomuk/global.h>
#include <QtConcurrentRun>
#include <QVBoxLayout>
+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)) {
+ setFixedWidth(sizeHint().width());
+ 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)) {
+ setFixedWidth(0);
+ 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);
m_refreshed(false),
m_allClipsProcessed(false),
m_thumbnailQueue(),
- m_abortAllProxies(false),
+ m_abortAllJobs(false),
+ m_closing(false),
m_invalidClipDialog(NULL)
{
+ qRegisterMetaType<stringMap> ("stringMap");
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
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);
m_listView = new ProjectListView;
layout->addWidget(m_listView);
+
+#if KDE_IS_VERSION(4,7,0)
+ m_infoMessage = new KMessageWidget;
+ layout->addWidget(m_infoMessage);
+ m_infoMessage->setCloseButtonVisible(true);
+ //m_infoMessage->setWordWrap(true);
+ m_infoMessage->hide();
+ m_logAction = new QAction(i18n("Show Log"), this);
+ m_logAction->setCheckable(false);
+ connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
+#endif
+
setLayout(layout);
searchView->setTreeWidget(m_listView);
connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
+ connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
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)));
+ 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)));
m_listViewDelegate = new ItemDelegate(m_listView);
m_listView->setItemDelegate(m_listViewDelegate);
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();
delete m_listViewDelegate;
+#if KDE_IS_VERSION(4,7,0)
+ delete m_infoMessage;
+#endif
}
void ProjectList::focusTree() const
continue;
}
item = static_cast <ProjectItem *>(selected.at(i));
- if (item && !item->isProxyRunning()) {
+ if (item && !hasPendingProxy(item)) {
DocClipBase *clip = item->referencedClip();
if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
if (item) {
slotUpdateClipProperties(item, properties);
if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) {
- kDebug()<<"/// ARGH FORCE RELOAD";
slotReloadClip(id);
} else if (properties.contains("colour") ||
properties.contains("xmldata") ||
if (!clip)
return;
clip->setProperties(properties);
+ if (properties.contains("proxy")) {
+ if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
+ clip->setJobStatus(NOJOB);
+ }
if (properties.contains("name")) {
monitorItemEditing(false);
clip->setText(0, properties.value("name"));
kDebug() << "/// Cannot find clip to delete";
return;
}
+ deleteJobsForClip(clipId);
if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
m_listView->blockSignals(true);
QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
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) {
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->isJobRunning()) {
slotCreateProxy(clip->getId());
- }
+ }*/
KUrl url = clip->fileURL();
#ifdef NEPOMUK
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 <ProjectItem *>(*it);
if (item->referencedClip()->getProperty("proxy") == proxyPath)
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);
}
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());
bool replace = false;
if (brokenClips.contains(item->clipId())) {
// if this is a proxy clip, disable proxy
- item->setProxyStatus(NOPROXY);
+ item->setJobStatus(NOJOB);
clip->setProperty("proxy", "-");
replace = true;
}
- if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
+ if (clip->isPlaceHolder() == false && !hasPendingProxy(item)) {
QDomElement xml = clip->toXML();
if (fpsChanged) {
xml.removeAttribute("out");
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()) {
}
}
} else {
- if (displayRatioChanged)
+ if (displayRatioChanged) {
requestClipThumbnail(clip->getId());
+ }
else if (item->data(0, Qt::DecorationRole).isNull()) {
getCachedThumbnail(item);
}
return allExtensions.simplified();
}
+void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
+{
+ kDebug()<<"// Adding clip: "<<url;
+ QList <QUrl> list;
+ list.append(url);
+ slotAddClip(list, groupName, groupId);
+}
+
void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
{
if (!m_commandStack)
kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
}
- item->setProxyStatus(PROXYCRASHED);
+ slotJobCrashed(item, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
QString path = item->referencedClip()->getProperty("proxy");
KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
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();
m_timecode = doc->timecode();
m_commandStack = doc->commandStack();
m_doc = doc;
- m_abortAllProxies = false;
+ m_abortAllJobs = false;
+ m_closing = false;
QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
QStringList openedFolders = doc->getExpandedFolders();
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);
}
item->setProperties(properties, metadata);
clip->setProducer(producer, replace);
- clip->getAudioThumbs();
// 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);
- else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
+ if (!useProxy() && clip->getProperty("proxy").isEmpty()) setJobStatus(item, NOJOB);
+ if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setJobStatus(item, NOJOB);
+ else if (useProxy() && !item->hasProxy() && !hasPendingProxy(item)) {
// proxy video and image clips
int maxSize;
CLIPTYPE t = item->clipType();
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);
void ProjectList::slotCreateProxy(const QString id)
{
ProjectItem *item = getItemById(id);
- if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
+ if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return;
QString path = item->referencedClip()->getProperty("proxy");
if (path.isEmpty()) {
- setProxyStatus(item, PROXYCRASHED);
+ jobCrashed(item, i18n("Failed to create proxy, empty path."));
return;
}
- setProxyStatus(item, PROXYWAITING);
+
if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
if (m_processingProxy.contains(path)) {
// Proxy is already being generated
}
if (QFileInfo(path).size() > 0) {
// Proxy already created
- setProxyStatus(item, PROXYDONE);
+ setJobStatus(item, JOBDONE);
slotGotProxy(path);
return;
}
m_processingProxy.append(path);
- 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);
+ 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));
+
+ startJobProcess();
+}
+
+void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item|| item->referencedClip()->isPlaceHolder()) return;
+ QString source = item->clipUrl().path();
+ QString ext = source.section('.', -1);
+ QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
+
+ double clipFps = item->referencedClip()->getProperty("fps").toDouble();
+ if (clipFps == 0) clipFps = m_fps;
+ // if clip and project have different frame rate, adjust in and out
+ int in = zone.x();
+ int out = zone.y();
+ in = GenTime(in, m_timecode.fps()).frames(clipFps);
+ out = GenTime(out, m_timecode.fps()).frames(clipFps);
+ int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
+ int duration = out - in + 1;
+ QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
+ QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
+
+ QDialog *d = new QDialog(this);
+ Ui::CutJobDialog_UI ui;
+ ui.setupUi(d);
+ ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
+ ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
+ ui.file_url->setUrl(KUrl(dest));
+ QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
+ ui.info_label->setText(mess);
+ if (d->exec() != QDialog::Accepted) {
+ delete d;
+ return;
+ }
+ dest = ui.file_url->url().path();
+ bool acceptPath = dest != source;
+ if (acceptPath && QFileInfo(dest).size() > 0) {
+ // destination file olready exists, overwrite?
+ acceptPath = false;
+ }
+ while (!acceptPath) {
+ // Do not allow to save over original clip
+ if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
+ else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
+ if (d->exec() != QDialog::Accepted) {
+ delete d;
+ return;
+ }
+ dest = ui.file_url->url().path();
+ acceptPath = dest != source;
+ if (acceptPath && QFileInfo(dest).size() > 0) {
+ acceptPath = false;
+ }
+ }
+ QString extraParams = ui.extra_params->toPlainText().simplified();
+ KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
+ delete d;
+
+ m_processingProxy.append(dest);
+ QStringList jobParams;
+ jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
+ 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));
+
+ startJobProcess();
+}
+
+
+void ProjectList::startJobProcess()
+{
+ int ct = 0;
if (!m_proxyThreads.futures().isEmpty()) {
// Remove inactive threads
QList <QFuture<void> > futures = m_proxyThreads.futures();
for (int i = 0; i < futures.count(); i++)
if (!futures.at(i).isFinished()) {
m_proxyThreads.addFuture(futures.at(i));
+ ct++;
}
}
- if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
+ emit jobCount(ct + m_jobList.count());
+
+ if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
}
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()
+void ProjectList::slotProcessJobs()
{
- 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 <QFuture<void> > 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<ProxyJob *> (job);
+ kDebug()<<"// STARTING JOB: "<<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 <ProjectItem *> processingItems;
- while (*it && !m_abortAllProxies) {
+ ProjectItem *processingItem = getItemById(job->clipId());
+ if (processingItem == NULL) {
+ delete job;
+ continue;
+ }
+
+ /*while (*it && !m_abortAllJobs) {
if ((*it)->type() == PROJECTCLIPTYPE) {
ProjectItem *item = static_cast <ProjectItem *>(*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);
+ // Make sure destination path is writable
+ 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);
+ emit jobCrashed(processingItem, i18n("Cannot write to path: %1", job->destination()));
+ 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: "<<parameters;
- QProcess myProcess;
- myProcess.setProcessChannelMode(QProcess::MergedChannels);
- myProcess.start(KdenliveSettings::rendererpath(), parameters);
- myProcess.waitForStarted();
- int result = -1;
- int duration = 0;
- while (myProcess.state() != QProcess::NotRunning) {
- // building proxy file
- if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
- myProcess.close();
- myProcess.waitForFinished();
- QFile::remove(info.dest);
- m_abortProxy.removeAll(info.dest);
- m_processingProxy.removeAll(info.dest);
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), NOPROXY);
- result = -2;
- }
- else {
- QString log = QString(myProcess.readAll());
- processLogInfo(processingItems, &duration, log);
- }
- myProcess.waitForFinished(500);
- }
- myProcess.waitForFinished();
- m_processingProxy.removeAll(info.dest);
- if (result == -1) result = myProcess.exitStatus();
- if (result == 0) {
- // proxy successfully created
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), PROXYDONE);
- slotGotProxy(info.dest);
- }
- else if (result == 1) {
- // Proxy process crashed
- QFile::remove(info.dest);
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), PROXYCRASHED);
- }
- continue;
- }
-
- if (info.type == IMAGE) {
- // Image proxy
- QImage i(info.src);
- if (i.isNull()) {
- // Cannot load image
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), PROXYCRASHED);
- continue;
+ setJobStatus(processingItem, CREATINGJOB, 0, job->jobType, job->statusMessage(CREATINGJOB));
+
+ 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());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) emit addClip(job->destination(), QString(), QString());
}
- 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());
+ emit jobCrashed(processingItem, job->errorMessage());
}
- 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++)
+ setJobStatus(processingItems.at(i), NOJOB);*/
}
else continue;
result = -2;
}
else {
- QString log = QString(myProcess.readAll());
- processLogInfo(processingItems, &duration, log);
+ int progress = job->processLogInfo();
+ if (progress > 0) emit processLog(processingItem, progress, job->jobType);
}
- 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) {
- result = QProcess::CrashExit;
+ if (result != -2 && QFileInfo(job->destination()).size() == 0) {
+ job->processLogInfo();
+ emit jobCrashed(processingItem, i18n("Failed to create file"), QString(), job->errorMessage());
+ result = -2;
}
-
+
if (result == QProcess::NormalExit) {
// proxy successfully created
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), PROXYDONE);
- slotGotProxy(info.dest);
+ setJobStatus(processingItem, JOBDONE);
+ if (job->jobType == PROXYJOB) slotGotProxy(job->destination());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) {
+ CutClipJob *cutJob = static_cast<CutClipJob *>(job);
+ if (cutJob->addClipToProject) emit addClip(job->destination(), QString(), QString());
+ }
}
else if (result == QProcess::CrashExit) {
// Proxy process crashed
- QFile::remove(info.dest);
- for (int i = 0; i < processingItems.count(); i++)
- setProxyStatus(processingItems.at(i), PROXYCRASHED);
+ QFile::remove(job->destination());
+ emit jobCrashed(processingItem, i18n("Job crashed"), QString(), job->errorMessage());
}
+ delete job;
+ continue;
}
-}
-
-
-void ProjectList::processLogInfo(QList <ProjectItem *>items, int *duration, const QString &log)
-{
- 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();
+ // Thread finished, update count
+ int ct = -1; // -1 because we don't want to count this terminating thread
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ for (int i = 0; i < futures.count(); i++)
+ if (futures.at(i).isRunning()) {
+ ct++;
}
- else progress = (int) time.toDouble();
- for (int i = 0; i < items.count(); i++)
- setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration)));
- }
+ emit jobCount(ct + m_jobList.count());
}
+
void ProjectList::updateProxyConfig()
{
ProjectItem *item;
}
CLIPTYPE t = item->clipType();
if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
- if (generateProxy() && useProxy() && !item->isProxyRunning()) {
+ if (generateProxy() && useProxy() && !hasPendingProxy(item)) {
DocClipBase *clip = item->referencedClip();
if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
if (clip->getProperty("proxy").isEmpty()) {
else delete command;
}
+void ProjectList::slotProcessLog(ProjectItem *item, int progress, int type)
+{
+ setJobStatus(item, CREATINGJOB, progress, (JOBTYPE) type);
+}
+
void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
{
QList<QTreeWidgetItem *> list;
continue;
}
- oldProps = clip->properties();
+ //oldProps = clip->properties();
if (doProxy) {
newProps.clear();
QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
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);
}
}
QFile::remove(proxyPath);
}
-void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress)
+void ProjectList::setJobStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress, JOBTYPE jobType, const QString &statusMessage)
{
- if (item == NULL || m_abortAllProxies) return;
+ if (item == NULL || m_abortAllJobs) return;
monitorItemEditing(false);
- item->setProxyStatus(status, progress);
- if (status == PROXYCRASHED) {
+ item->setJobStatus(status, progress, jobType, statusMessage);
+ if (status == JOBCRASHED) {
DocClipBase *clip = item->referencedClip();
if (!clip) {
kDebug()<<"// PROXY CRASHED";
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 <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
+ if (newProps.isEmpty()) continue;
+ QMap <QString, QString> 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 <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
+ if (newProps == oldProps) return;
+ QMapIterator<QString, QString> i(oldProps);
+ EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
+ m_commandStack->push(command);
+}
+
+bool ProjectList::hasPendingProxy(ProjectItem *item)
+{
+ if (!item || !item->referencedClip() || m_abortAllJobs) return false;
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_abortAllJobs) break;
+ if (m_jobList.at(i)->clipId() == item->clipId() && m_jobList.at(i)->jobType == PROXYJOB) return true;
+ }
+ if (item->isProxyRunning()) return true;
+ return false;
+}
+
+void ProjectList::deleteJobsForClip(const QString &clipId)
+{
+ QList <AbstractClipJob *> 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--;
+ }
+ }
+}
+
+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);
+ m_infoMessage->setMessageType(KMessageWidget::Warning);
+ QList<QAction *> actions = m_infoMessage->actions();
+ for (int i = 0; i < actions.count(); i++) {
+ m_infoMessage->removeAction(actions.at(i));
+ }
+
+ if (!actionName.isEmpty()) {
+ QAction *action;
+ QList< KActionCollection * > collections = KActionCollection::allCollections();
+ for (int i = 0; i < collections.count(); i++) {
+ KActionCollection *coll = collections.at(i);
+ action = coll->action(actionName);
+ if (action) break;
+ }
+ if (action) m_infoMessage->addAction(action);
+ }
+ if (!details.isEmpty()) {
+ m_errorLog = details;
+ m_infoMessage->addAction(m_logAction);
+ }
+ m_infoMessage->animatedShow();
+#else
+ item->setJobStatus(JOBCRASHED);
+#endif
+}
+
+void ProjectList::slotShowJobLog()
+{
+#if KDE_IS_VERSION(4,7,0)
+ KDialog d(this);
+ d.setButtons(KDialog::Close);
+ QTextEdit t(&d);
+ t.setPlainText(m_errorLog);
+ t.setReadOnly(true);
+ d.setMainWidget(&t);
+ d.exec();
+#endif
+}
+
#include "projectlist.moc"