+void ProjectList::slotForceProcessing(const QString &id)
+{
+ m_render->forceProcessing(id);
+}
+
+void ProjectList::slotAddOrUpdateSequence(const QString frameName)
+{
+ QString fileName = KUrl(frameName).fileName().section('_', 0, -2);
+ QStringList list;
+ QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list);
+ int count = list.count();
+ if (count > 1) {
+ const QList <DocClipBase *> existing = m_doc->clipManager()->getClipByResource(pattern);
+ if (!existing.isEmpty()) {
+ // Sequence already exists, update
+ QString id = existing.at(0)->getId();
+ //ProjectItem *item = getItemById(id);
+ QMap <QString, QString> oldprops;
+ QMap <QString, QString> newprops;
+ int ttl = existing.at(0)->getProperty("ttl").toInt();
+ oldprops["out"] = existing.at(0)->getProperty("out");
+ newprops["out"] = QString::number(ttl * count - 1);
+ slotUpdateClipProperties(id, newprops);
+ EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false);
+ m_commandStack->push(command);
+ } else {
+ // Create sequence
+ QStringList groupInfo = getGroup();
+ m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()),
+ false, false, false,
+ m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0,
+ QString(), groupInfo.at(0), groupInfo.at(1));
+ }
+ } else emit displayMessage(i18n("Sequence not found"), -2);
+}
+
+QMap <QString, QString> ProjectList::getProxies()
+{
+ QMap <QString, QString> list;
+ ProjectItem *item;
+ QTreeWidgetItemIterator it(m_listView);
+ while (*it) {
+ if ((*it)->type() != PROJECTCLIPTYPE) {
+ ++it;
+ continue;
+ }
+ item = static_cast<ProjectItem *>(*it);
+ if (item && item->referencedClip() != NULL) {
+ if (item->hasProxy()) {
+ QString proxy = item->referencedClip()->getProperty("proxy");
+ list.insert(proxy, item->clipUrl().path());
+ }
+ }
+ ++it;
+ }
+ return list;
+}
+
+void ProjectList::slotCreateProxy(const QString id)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return;
+ QString path = item->referencedClip()->getProperty("proxy");
+ if (path.isEmpty()) {
+ slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
+ return;
+ }
+
+ if (m_processingProxy.contains(path)) {
+ // Proxy is already being generated
+ return;
+ }
+ if (QFileInfo(path).size() > 0) {
+ // Proxy already created
+ setJobStatus(item, PROXYJOB, JOBDONE);
+ slotGotProxy(path);
+ return;
+ }
+ m_processingProxy.append(path);
+
+ 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);
+ setJobStatus(item, job->jobType, JOBWAITING);
+ slotCheckJobProcess();
+}
+
+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);
+ setJobStatus(item, job->jobType, JOBWAITING);
+
+ slotCheckJobProcess();
+}
+
+
+void ProjectList::slotCheckJobProcess()
+{
+ if (!m_jobThreads.futures().isEmpty()) {
+ // Remove inactive threads
+ QList <QFuture<void> > futures = m_jobThreads.futures();
+ m_jobThreads.clearFutures();
+ for (int i = 0; i < futures.count(); i++)
+ if (!futures.at(i).isFinished()) {
+ m_jobThreads.addFuture(futures.at(i));
+ }
+ }
+ if (m_jobList.isEmpty()) return;
+ int count = 0;
+ m_jobMutex.lock();
+ 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);
+ m_jobMutex.unlock();
+
+ 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)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item) return;
+ if (!item->isProxyRunning()) slotGotProxy(item);
+ item->setConditionalJobStatus(NOJOB, PROXYJOB);
+ discardJobs(id, PROXYJOB);
+}
+
+void ProjectList::slotProcessJobs()
+{
+ while (!m_jobList.isEmpty() && !m_abortAllJobs) {
+ emit projectModified();
+ AbstractClipJob *job = NULL;
+ int count = 0;
+ m_jobMutex.lock();
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_jobList.at(i)->jobStatus == JOBWAITING) {
+ if (job == NULL) {
+ m_jobList.at(i)->jobStatus = JOBWORKING;
+ job = m_jobList.at(i);
+ }
+ count++;
+ }
+ else if (m_jobList.at(i)->jobStatus == JOBWORKING)
+ count ++;
+ }
+ // Set jobs count
+ emit jobCount(count);
+ m_jobMutex.unlock();
+
+ 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) {
+ job->setStatus(JOBDONE);
+ continue;
+ }
+
+ // Make sure destination path is writable
+ QFile file(destination);
+ if (!file.open(QIODevice::WriteOnly)) {
+ emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
+ m_processingProxy.removeAll(destination);
+ job->setStatus(JOBCRASHED);
+ continue;
+ }
+ file.close();
+ QFile::remove(destination);
+
+ //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) {
+ emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
+ if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) emit addClip(destination, QString(), QString());
+ job->setStatus(JOBDONE);
+ }
+ else {
+ QFile::remove(destination);
+ emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, job->errorMessage());
+ job->setStatus(JOBCRASHED);
+ }
+ m_processingProxy.removeAll(destination);
+ continue;
+ }
+ else while (jobProcess->state() != QProcess::NotRunning) {
+ // building proxy file
+ if (m_abortAllJobs || job->jobStatus == JOBABORTED) {
+ job->jobStatus = JOBABORTED;
+ jobProcess->close();
+ jobProcess->waitForFinished();
+ QFile::remove(destination);
+ m_processingProxy.removeAll(destination);
+ if (!m_closing) {
+ emit cancelRunningJob(job->clipId(), job->cancelProperties());
+ }
+ result = -2;
+ continue;
+ }
+ else {
+ int progress = job->processLogInfo();
+ if (progress > 0) emit processLog(job->clipId(), progress, job->jobType);
+ }
+ jobProcess->waitForFinished(500);
+ }
+ jobProcess->waitForFinished();
+ m_processingProxy.removeAll(destination);
+ if (result == -1) result = jobProcess->exitStatus();
+
+ if (result != -2 && QFileInfo(destination).size() == 0) {
+ job->processLogInfo();
+ emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Failed to create file"), QString(), job->errorMessage());
+ job->setStatus(JOBCRASHED);
+ result = -2;
+ }
+ if (result == QProcess::NormalExit) {
+ // proxy successfully created
+ emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
+ if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) {
+ CutClipJob *cutJob = static_cast<CutClipJob *>(job);
+ if (cutJob->addClipToProject) emit addClip(destination, QString(), QString());
+ }
+ job->setStatus(JOBDONE);
+ }
+ else if (result == QProcess::CrashExit) {
+ // Proxy process crashed
+ QFile::remove(destination);
+ emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Job crashed"), QString(), job->errorMessage());
+ job->setStatus(JOBCRASHED);
+ }
+ continue;
+ }
+ // Thread finished, cleanup & update count
+ QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
+}
+
+
+void ProjectList::updateProxyConfig()
+{
+ ProjectItem *item;
+ QTreeWidgetItemIterator it(m_listView);
+ QUndoCommand *command = new QUndoCommand();
+ command->setText(i18n("Update proxy settings"));
+ QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
+ while (*it) {
+ if ((*it)->type() != PROJECTCLIPTYPE) {
+ ++it;
+ continue;
+ }
+ item = static_cast<ProjectItem *>(*it);
+ if (item == NULL) {
+ ++it;
+ continue;
+ }
+ CLIPTYPE t = item->clipType();
+ if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
+ 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()) {
+ // We need to insert empty proxy in old properties so that undo will work
+ QMap <QString, QString> oldProps;// = clip->properties();
+ oldProps.insert("proxy", QString());
+ QMap <QString, QString> newProps;
+ newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
+ new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
+ }
+ }
+ }
+ else if (item->hasProxy()) {
+ // remove proxy
+ QMap <QString, QString> newProps;
+ newProps.insert("proxy", QString());
+ newProps.insert("replace", "1");
+ // insert required duration for proxy
+ newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+ new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
+ }
+ }
+ else if (t == IMAGE && item->referencedClip() != NULL) {
+ if (generateImageProxy() && useProxy()) {
+ DocClipBase *clip = item->referencedClip();
+ int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
+ if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) {
+ if (clip->getProperty("proxy").isEmpty()) {
+ // We need to insert empty proxy in old properties so that undo will work
+ QMap <QString, QString> oldProps = clip->properties();
+ oldProps.insert("proxy", QString());
+ QMap <QString, QString> newProps;
+ newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png");
+ new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command);
+ }
+ }
+ }
+ else if (item->hasProxy()) {
+ // remove proxy
+ QMap <QString, QString> newProps;
+ newProps.insert("proxy", QString());
+ newProps.insert("replace", "1");
+ new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
+ }
+ }
+ ++it;
+ }
+ if (command->childCount() > 0) m_doc->commandStack()->push(command);
+ else delete command;
+}
+
+void ProjectList::slotProcessLog(const QString id, int progress, int type)
+{
+ ProjectItem *item = getItemById(id);
+ setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress);
+}
+
+void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
+{
+ QList<QTreeWidgetItem *> list;
+ if (itemToProxy == NULL) list = m_listView->selectedItems();
+ else list << itemToProxy;
+
+ // expand list (folders, subclips) to get real clips
+ QTreeWidgetItem *listItem;
+ QList<ProjectItem *> clipList;
+ for (int i = 0; i < list.count(); i++) {
+ listItem = list.at(i);
+ if (listItem->type() == PROJECTFOLDERTYPE) {
+ for (int j = 0; j < listItem->childCount(); j++) {
+ QTreeWidgetItem *sub = listItem->child(j);
+ if (sub->type() == PROJECTCLIPTYPE) {
+ ProjectItem *item = static_cast <ProjectItem*>(sub);
+ if (!clipList.contains(item)) clipList.append(item);
+ }
+ }
+ }
+ else if (listItem->type() == PROJECTSUBCLIPTYPE) {
+ QTreeWidgetItem *sub = listItem->parent();
+ ProjectItem *item = static_cast <ProjectItem*>(sub);
+ if (!clipList.contains(item)) clipList.append(item);
+ }
+ else if (listItem->type() == PROJECTCLIPTYPE) {
+ ProjectItem *item = static_cast <ProjectItem*>(listItem);
+ if (!clipList.contains(item)) clipList.append(item);
+ }
+ }
+
+ QUndoCommand *command = new QUndoCommand();
+ if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
+ else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count()));
+
+ // Make sure the proxy folder exists
+ QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
+ KStandardDirs::makeDir(proxydir);
+
+ QMap <QString, QString> newProps;
+ QMap <QString, QString> oldProps;
+ if (!doProxy) newProps.insert("proxy", "-");
+ for (int i = 0; i < clipList.count(); i++) {
+ ProjectItem *item = clipList.at(i);
+ CLIPTYPE t = item->clipType();
+ if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
+ if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
+ DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
+ continue;
+ }
+
+ //oldProps = clip->properties();
+ if (doProxy) {
+ newProps.clear();
+ QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
+ // insert required duration for proxy
+ 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());
+ }
+ 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);
+ }
+ }
+ if (command->childCount() > 0) {
+ m_doc->commandStack()->push(command);
+ }
+ else delete command;
+}
+
+
+void ProjectList::slotDeleteProxy(const QString proxyPath)
+{
+ if (proxyPath.isEmpty()) return;
+ QUndoCommand *proxyCommand = new QUndoCommand();
+ proxyCommand->setText(i18n("Remove Proxy"));
+ QTreeWidgetItemIterator it(m_listView);
+ ProjectItem *item;
+ while (*it) {
+ if ((*it)->type() == PROJECTCLIPTYPE) {
+ item = static_cast <ProjectItem *>(*it);
+ if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+ QMap <QString, QString> props;
+ props.insert("proxy", QString());
+ new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
+
+ }
+ }
+ ++it;
+ }
+ if (proxyCommand->childCount() == 0)
+ delete proxyCommand;
+ else
+ m_commandStack->push(proxyCommand);
+ QFile::remove(proxyPath);
+}
+
+void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
+{
+ if (item == NULL || (m_abortAllJobs && m_closing)) return;
+ monitorItemEditing(false);
+ item->setJobStatus(jobType, status, progress);
+ if (status == JOBCRASHED) {
+ DocClipBase *clip = item->referencedClip();
+ if (!clip) {
+ kDebug()<<"// PROXY CRASHED";
+ }
+ else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
+ // disable proxy and fetch real clip
+ clip->setProperty("proxy", "-");
+ QDomElement xml = clip->toXML();
+ m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
+ }
+ else {
+ // Disable proxy for this clip
+ clip->setProperty("proxy", "-");
+ }
+ }
+ monitorItemEditing(true);
+}
+
+void ProjectList::monitorItemEditing(bool enable)
+{
+ if (enable) connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
+ else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
+}
+
+QStringList ProjectList::expandedFolders() const
+{
+ QStringList result;
+ FolderProjectItem *item;
+ QTreeWidgetItemIterator it(m_listView);
+ while (*it) {
+ if ((*it)->type() != PROJECTFOLDERTYPE) {
+ ++it;
+ continue;
+ }
+ if ((*it)->isExpanded()) {
+ item = static_cast<FolderProjectItem *>(*it);
+ result.append(item->clipId());
+ }
+ ++it;
+ }
+ 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_jobThreads.waitForFinished();
+ m_jobThreads.clearFutures();
+ QUndoCommand *command = new QUndoCommand();
+ command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
+ m_jobMutex.lock();
+ 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);
+ }
+ m_jobMutex.unlock();
+ 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;
+ AbstractClipJob *job;
+ QMutexLocker lock(&m_jobMutex);
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_abortAllJobs) break;
+ job = m_jobList.at(i);
+ if (job->clipId() == item->clipId() && job->jobType == PROXYJOB && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
+ }
+
+ return false;
+}
+
+void ProjectList::deleteJobsForClip(const QString &clipId)
+{
+ QMutexLocker lock(&m_jobMutex);
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_abortAllJobs) break;
+ if (m_jobList.at(i)->clipId() == clipId) {
+ m_jobList.at(i)->setStatus(JOBABORTED);
+ }
+ }
+}
+
+void ProjectList::slotUpdateJobStatus(const QString &id, int type, int status, const QString &label, const QString &actionName, const QString details)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item) return;
+ slotUpdateJobStatus(item, type, status, label, actionName, details);
+
+}
+
+void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
+{
+ item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
+ if (status != JOBCRASHED) return;
+#if KDE_IS_VERSION(4,7,0)
+ m_infoMessage->animatedHide();
+ 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 = NULL;
+ 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();
+#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
+}
+
+void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
+ QMutexLocker lock(&m_jobMutex);
+ 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);
+ }
+ }
+}
+
+