+void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
+{
+ if (item->hasProxy()) {
+ QPainter p(&pix);
+ QColor c(220, 220, 10, 200);
+ QRect r(0, 0, 12, 12);
+ p.fillRect(r, c);
+ QFont font = p.font();
+ font.setBold(true);
+ p.setFont(font);
+ p.setPen(Qt::black);
+ p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
+ }
+}
+
+void ProjectList::slotCancelJobs()
+{
+ m_abortAllJobs = true;
+ for (int i = 0; i < m_jobList.count(); i++) {
+ m_jobList.at(i)->setStatus(JOBABORTED);
+ }
+ 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++) {
+ DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
+ if (!currentClip) continue;
+ QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
+ if (newProps.isEmpty()) continue;
+ QMap <QString, QString> oldProps = currentClip->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_jobList.clear();
+ m_abortAllJobs = false;
+ m_infoLabel->slotSetJobCount(0);
+}
+
+void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
+{
+ if (newProps.isEmpty() || m_closing) return;
+ DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
+ if (!currentClip) return;
+ QMap <QString, QString> oldProps = currentClip->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::hasPendingJob(ProjectItem *item, JOBTYPE type)
+{
+ 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 == type && (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_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)
+ QList<QAction *> actions = m_infoMessage->actions();
+ if (m_infoMessage->isHidden()) {
+ m_infoMessage->setText(label);
+ m_infoMessage->setWordWrap(m_infoMessage->text().length() > 35);
+ m_infoMessage->setMessageType(KMessageWidget::Warning);
+ }
+
+ 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 && !actions.contains(action)) m_infoMessage->addAction(action);
+ }
+ if (!details.isEmpty()) {
+ m_errorLog.append(details);
+ if (!actions.contains(m_logAction)) m_infoMessage->addAction(m_logAction);
+ }
+ m_infoMessage->animatedShow();
+#else
+ // warning for KDE < 4.7
+ KPassivePopup *passivePop = new KPassivePopup( this );
+ passivePop->setAutoDelete(true);
+ connect(passivePop, SIGNAL(clicked()), this, SLOT(slotClosePopup()));
+ m_errorLog.append(details);
+ KVBox *vb = new KVBox( passivePop );
+ KHBox *vh1 = new KHBox( vb );
+ KIcon icon("dialog-warning");
+ QLabel *iconLabel = new QLabel(vh1);
+ iconLabel->setPixmap(icon.pixmap(m_listView->iconSize()));
+ (void) new QLabel( label, vh1);
+ KHBox *box = new KHBox( vb );
+ QPushButton *but = new QPushButton( "Show log", box );
+ connect(but, SIGNAL(clicked(bool)), this, SLOT(slotShowJobLog()));
+
+ passivePop->setView( vb );
+ passivePop->show();
+
+#endif
+}
+
+void ProjectList::slotShowJobLog()
+{
+ KDialog d(this);
+ d.setButtons(KDialog::Close);
+ QTextEdit t(&d);
+ for (int i = 0; i < m_errorLog.count(); i++) {
+ if (i > 0) t.insertHtml("<br><hr /><br>");
+ t.insertPlainText(m_errorLog.at(i));
+ }
+ t.setReadOnly(true);
+ d.setMainWidget(&t);
+ d.exec();
+}
+
+QStringList ProjectList::getPendingJobs(const QString &id)
+{
+ QStringList result;
+ QMutexLocker lock(&m_jobMutex);
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
+ // discard this job
+ result << m_jobList.at(i)->description;
+ }
+ }
+ return result;
+}
+
+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 || type == NOJOBTYPE)) {
+ // discard this job
+ m_jobList.at(i)->setStatus(JOBABORTED);
+ }
+ }
+}
+
+void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item) return;
+ QStringList jobParams;
+ jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
+ jobParams << QString() << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
+ MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
+ if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+ delete job;
+ return;
+ }
+ job->description = i18n("Filter %1", finalFilterName);
+ m_jobList.append(job);
+ setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+ slotCheckJobProcess();
+}
+
+void ProjectList::startClipFilterJob(const QString &filterName, const QString &condition)
+{
+ QStringList ids = getConditionalIds(condition);
+ QString destination;
+ ProjectItem *item = getItemById(ids.at(0));
+ if (!item) {
+ emit displayMessage(i18n("Cannot find clip to process filter %1", filterName), -2);
+ return;
+ }
+ if (ids.count() == 1) {
+ destination = item->clipUrl().path();
+ }
+ else {
+ destination = item->clipUrl().directory();
+ }
+ QPointer<ClipStabilize> d = new ClipStabilize(destination, ids.count(), filterName);
+ if (d->exec() == QDialog::Accepted) {
+ processClipJob(ids, d->destination(), d->autoAddClip(), d->params(), d->desc());
+ }
+ delete d;
+}
+
+void ProjectList::processClipJob(QStringList ids, const QString&destination, bool autoAdd, QStringList jobParams, const QString &description)
+{
+ QStringList preParams;
+ // in and out
+ preParams << QString::number(0) << QString::number(-1);
+ // producer params
+ preParams << jobParams.takeFirst();
+ // filter name
+ preParams << jobParams.takeFirst();
+ // filter params
+ preParams << jobParams.takeFirst();
+ // consumer
+ QString consumer = jobParams.takeFirst();
+
+ foreach(const QString&id, ids) {
+ ProjectItem *item = getItemById(id);
+ if (!item) continue;
+ if (ids.count() == 1) {
+ consumer += ':' + destination;
+ }
+ else {
+ consumer += ':' + destination + item->clipUrl().fileName() + ".mlt";
+ }
+ preParams << consumer << jobParams;
+
+ MeltJob *job = new MeltJob(item->clipType(), id, preParams);
+ if (autoAdd) {
+ job->setAddClipToProject(true);
+ kDebug()<<"// ADDING TRUE";
+ }
+ else kDebug()<<"// ADDING FALSE!!!";
+ if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+ delete job;
+ return;
+ }
+ job->description = description;
+ m_jobList.append(job);
+ setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+ }
+ slotCheckJobProcess();
+}
+
+void ProjectList::slotPrepareJobsMenu()
+{
+ ProjectItem *item;
+ if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
+ return;
+ if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
+ item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
+ else
+ item = static_cast <ProjectItem*>(m_listView->currentItem());
+ if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
+ QString id = item->clipId();
+ m_discardCurrentClipJobs->setData(id);
+ QStringList jobs = getPendingJobs(id);
+ m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
+ } else {
+ m_discardCurrentClipJobs->setData(QString());
+ m_discardCurrentClipJobs->setEnabled(false);
+ }
+}
+
+void ProjectList::slotDiscardClipJobs()
+{
+ QString id = m_discardCurrentClipJobs->data().toString();
+ if (id.isEmpty()) return;
+ discardJobs(id);
+}
+
+void ProjectList::updatePalette()
+{
+ m_infoLabel->setStyleSheet(SmallInfoLabel::getStyleSheet(QApplication::palette()));
+ m_listView->updateStyleSheet();
+}
+
+void ProjectList::slotResetInfoMessage()
+{
+#if KDE_IS_VERSION(4,7,0)
+ m_errorLog.clear();
+ QList<QAction *> actions = m_infoMessage->actions();
+ for (int i = 0; i < actions.count(); i++) {
+ m_infoMessage->removeAction(actions.at(i));
+ }
+#endif
+}
+
+void ProjectList::slotClosePopup()
+{
+ m_errorLog.clear();
+}
+