X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=1c876f1492469ef6fedb808016df59afeb2d5fa8;hb=059d57d43c93efb5a862ae150425922678810ad7;hp=e0666e3dabf3def82db8db24add97e53dc8249b6;hpb=59fc347313511ad63560b7c1a32b5c34c9b940f8;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index e0666e3d..1c876f14 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -49,6 +49,8 @@ #include #include #include +#include + #ifdef NEPOMUK #include #include @@ -63,6 +65,7 @@ #include #include #include +#include ProjectList::ProjectList(QWidget *parent) : QWidget(parent), @@ -80,7 +83,7 @@ ProjectList::ProjectList(QWidget *parent) : QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - + qRegisterMetaType("QDomElement"); // setup toolbar QFrame *frame = new QFrame; frame->setFrameStyle(QFrame::NoFrame); @@ -115,13 +118,7 @@ ProjectList::ProjectList(QWidget *parent) : m_proxyAction->setCheckable(true); m_proxyAction->setChecked(false); connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool))); - - - m_queueTimer.setInterval(100); - connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue())); - m_queueTimer.setSingleShot(true); - - + connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail())); connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified())); connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected())); connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected())); @@ -234,7 +231,8 @@ void ProjectList::updateProjectFormat(Timecode t) void ProjectList::slotEditClip() { QList list = m_listView->selectedItems(); - if (list.count() > 1) { + if (list.isEmpty()) return; + if (list.count() > 1 || list.at(0)->type() == PROJECTFOLDERTYPE) { editClipSelection(list); return; } @@ -266,15 +264,23 @@ void ProjectList::editClipSelection(QList list) commonproperties.insert("audio_index", "-"); commonproperties.insert("force_colorspace", "-"); commonproperties.insert("full_luma", "-"); + QString transparency = "-"; bool allowDurationChange = true; int commonDuration = -1; + bool hasImages = false;; ProjectItem *item; for (int i = 0; i < list.count(); i++) { item = NULL; - if (list.at(i)->type() == PROJECTFOLDERTYPE) + if (list.at(i)->type() == PROJECTFOLDERTYPE) { + // Add folder items to the list + int ct = list.at(i)->childCount(); + for (int j = 0; j < ct; j++) { + list.append(list.at(i)->child(j)); + } continue; - if (list.at(i)->type() == PROJECTSUBCLIPTYPE) + } + else if (list.at(i)->type() == PROJECTSUBCLIPTYPE) item = static_cast (list.at(i)->parent()); else item = static_cast (list.at(i)); @@ -284,6 +290,29 @@ void ProjectList::editClipSelection(QList list) // check properties DocClipBase *clip = item->referencedClip(); if (clipList.contains(clip)) continue; + if (clip->clipType() == IMAGE) { + hasImages = true; + if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) { + if (transparency == "-") { + // first non transparent image + transparency = "0"; + } + else if (transparency == "1") { + // we have transparent and non transparent clips + transparency = "-1"; + } + } + else { + if (transparency == "-") { + // first transparent image + transparency = "1"; + } + else if (transparency == "0") { + // we have transparent and non transparent clips + transparency = "-1"; + } + } + } if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT) allowDurationChange = false; if (allowDurationChange && commonDuration != 0) { @@ -311,11 +340,13 @@ void ProjectList::editClipSelection(QList list) } if (allowDurationChange) commonproperties.insert("out", QString::number(commonDuration)); - QMapIterator p(commonproperties); + if (hasImages) + commonproperties.insert("transparency", transparency); + /*QMapIterator p(commonproperties); while (p.hasNext()) { p.next(); kDebug() << "Result: " << p.key() << " = " << p.value(); - } + }*/ emit showClipProperties(clipList, commonproperties); } @@ -440,11 +471,9 @@ void ProjectList::slotReloadClip(const QString &id) int length = QString(item->referencedClip()->producerProperty("length")).toInt(); if (length > 0 && !e.hasAttribute("length")) { e.setAttribute("length", length); - e.setAttribute("out", length - 1); } - } - - emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); + } + emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false); } } } @@ -471,10 +500,31 @@ void ProjectList::slotMissingClip(const QString &id) ProjectItem *item = getItemById(id); if (item) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); + int height = m_listView->iconSize().height(); + int width = (int)(height * m_render->dar()); + QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); + if (pixmap.isNull()) { + pixmap = QPixmap(width, height); + pixmap.fill(Qt::transparent); + } + KIcon icon("dialog-close"); + QPainter p(&pixmap); + p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6)); + p.end(); + item->setData(0, Qt::DecorationRole, pixmap); if (item->referencedClip()) { item->referencedClip()->setPlaceHolder(true); - if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR"; - item->referencedClip()->setProducer(m_render->invalidProducer(id), true); + if (m_render == NULL) { + kDebug() << "********* ERROR, NULL RENDR"; + return; + } + Mlt::Producer *newProd = m_render->invalidProducer(id); + if (item->referencedClip()->producer()) { + Mlt::Properties props(newProd->get_properties()); + Mlt::Properties src_props(item->referencedClip()->producer()->get_properties()); + props.inherit(src_props); + } + item->referencedClip()->setProducer(newProd, true); item->slotSetToolTip(); emit clipNeedsReload(id, true); } @@ -528,7 +578,7 @@ void ProjectList::slotClipSelected() if (m_listView->currentItem()) { if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { emit clipSelected(NULL); - m_editButton->defaultAction()->setEnabled(false); + m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0); m_deleteButton->defaultAction()->setEnabled(true); m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); @@ -547,7 +597,7 @@ void ProjectList::slotClipSelected() return; } clip = static_cast (m_listView->currentItem()); - if (clip) + if (clip && clip->referencedClip()) emit clipSelected(clip->referencedClip()); m_editButton->defaultAction()->setEnabled(true); m_deleteButton->defaultAction()->setEnabled(true); @@ -579,12 +629,14 @@ void ProjectList::slotClipSelected() void ProjectList::adjustProxyActions(ProjectItem *clip) const { - if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) { + if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) { m_proxyAction->setEnabled(false); return; } - m_proxyAction->setEnabled(true); + m_proxyAction->setEnabled(useProxy()); + m_proxyAction->blockSignals(true); m_proxyAction->setChecked(clip->hasProxy()); + m_proxyAction->blockSignals(false); } void ProjectList::adjustTranscodeActions(ProjectItem *clip) const @@ -629,9 +681,9 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap setProperties(properties); if (properties.contains("name")) { - m_listView->blockSignals(true); + monitorItemEditing(false); clip->setText(0, properties.value("name")); - m_listView->blockSignals(false); + monitorItemEditing(true); emit clipNameChanged(clip->clipId(), properties.value("name")); } if (properties.contains("description")) { CLIPTYPE type = clip->clipType(); - m_listView->blockSignals(true); + monitorItemEditing(false); clip->setText(1, properties.value("description")); - m_listView->blockSignals(false); + monitorItemEditing(true); #ifdef NEPOMUK if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) { // Use Nepomuk system to store clip description @@ -716,11 +768,13 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) QMap oldprops; QMap newprops; oldprops["name"] = clip->referencedClip()->getProperty("name"); - newprops["name"] = item->text(0); - slotUpdateClipProperties(clip, newprops); - emit projectModified(); - EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); - m_commandStack->push(command); + if (oldprops.value("name") != item->text(0)) { + newprops["name"] = item->text(0); + slotUpdateClipProperties(clip, newprops); + emit projectModified(); + EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); + m_commandStack->push(command); + } } } } @@ -812,6 +866,7 @@ void ProjectList::updateButtons() const { if (m_listView->topLevelItemCount() == 0) { m_deleteButton->defaultAction()->setEnabled(false); + m_editButton->defaultAction()->setEnabled(false); } else { m_deleteButton->defaultAction()->setEnabled(true); if (!m_listView->currentItem()) @@ -822,12 +877,14 @@ void ProjectList::updateButtons() const m_openAction->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - m_proxyAction->setEnabled(true); + m_proxyAction->setEnabled(useProxy()); return; } + else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) { + m_editButton->defaultAction()->setEnabled(true); + } + else m_editButton->defaultAction()->setEnabled(false); } - - m_editButton->defaultAction()->setEnabled(false); m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); @@ -930,15 +987,16 @@ void ProjectList::deleteProjectFolder(QMap map) i.next(); new AddFolderCommand(this, i.key(), i.value(), false, delCommand); } - m_commandStack->push(delCommand); + if (delCommand->childCount() > 0) m_commandStack->push(delCommand); + else delete delCommand; } void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) { m_listView->setEnabled(false); - if (getProperties) m_listView->blockSignals(true); const QString parent = clip->getProperty("groupid"); ProjectItem *item = NULL; + monitorItemEditing(false); if (!parent.isEmpty()) { FolderProjectItem *parentitem = getFolderItemById(parent); if (!parentitem) { @@ -953,38 +1011,20 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) if (parentitem) item = new ProjectItem(parentitem, clip); } - if (item == NULL) + if (item == NULL) { item = new ProjectItem(m_listView, clip); + } if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading")); + 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) { - m_listView->blockSignals(true); - m_refreshed = false; - - // Proxy clips - CLIPTYPE t = clip->clipType(); - if ((t == VIDEO || t == AV || t == UNKNOWN) && KdenliveSettings::enableproxy()) { - if (clip->getProperty("proxy").isEmpty()) { - connect(clip, SIGNAL(proxyReady(const QString, bool)), this, SLOT(slotGotProxy(const QString, bool))); - item->setProxyStatus(1); - clip->generateProxy(m_doc->projectFolder()); - } - else { - // Proxy clip already created - item->setProxyStatus(2); - QDomElement e = clip->toXML().cloneNode().toElement(); - e.removeAttribute("file_hash"); - m_infoQueue.insert(clip->getId(), e); - - } - } - else { - // We don't use proxies - // remove file_hash so that we load all properties for the clip - QDomElement e = clip->toXML().cloneNode().toElement(); - e.removeAttribute("file_hash"); - m_infoQueue.insert(clip->getId(), e); - } - //m_render->getFileProperties(clip->toXML(), clip->getId(), true); + m_listView->processLayout(); + QDomElement e = clip->toXML().cloneNode().toElement(); + e.removeAttribute("file_hash"); + m_infoQueue.insert(clip->getId(), e); + } + else if (item->hasProxy() && !item->isProxyRunning()) { + slotCreateProxy(clip->getId()); } clip->askForAudioThumbs(); @@ -1023,34 +1063,50 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) } } } + monitorItemEditing(true); if (m_listView->isEnabled()) { updateButtons(); - if (getProperties) - m_listView->blockSignals(false); } - if (getProperties && !m_queueTimer.isActive()) - slotProcessNextClipInQueue(); + if (getProperties && m_processingClips.isEmpty()) + m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } -void ProjectList::slotGotProxy(const QString id, bool success) +void ProjectList::slotGotProxy(const QString &proxyPath) { - ProjectItem *item = getItemById(id); - if (item) { - disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int))); - if (success) { - // Proxy clip successfully created - item->setProxyStatus(2); - QDomElement e = item->referencedClip()->toXML().cloneNode().toElement(); - e.removeAttribute("file_hash"); - e.setAttribute("replace", 1); - m_infoQueue.insert(id, e); - if (!m_queueTimer.isActive()) slotProcessNextClipInQueue(); + if (proxyPath.isEmpty()) return; + QTreeWidgetItemIterator it(m_listView); + ProjectItem *item; + + while (*it) { + if ((*it)->type() == PROJECTCLIPTYPE) { + item = static_cast (*it); + if (item->referencedClip()->getProperty("proxy") == proxyPath) + slotGotProxy(item); + } + ++it; + } +} + +void ProjectList::slotGotProxy(ProjectItem *item) +{ + if (item == NULL) return; + DocClipBase *clip = item->referencedClip(); + // Proxy clip successfully created + QDomElement e = clip->toXML().cloneNode().toElement(); + kDebug()<<"// QUERYING CLIP, proxy: "<clipType(); + if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) { + int length = QString(clip->producerProperty("length")).toInt(); + if (length > 0 && !e.hasAttribute("length")) { + e.setAttribute("length", length); } - else item->setProxyStatus(0); - connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int))); - update(); } + e.setAttribute("replace", 1); + m_infoQueue.insert(clip->getId(), e); + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } void ProjectList::slotResetProjectList() @@ -1064,7 +1120,6 @@ void ProjectList::slotResetProjectList() void ProjectList::requestClipInfo(const QDomElement xml, const QString id) { - m_refreshed = false; m_infoQueue.insert(id, xml); //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue())); } @@ -1072,7 +1127,7 @@ void ProjectList::requestClipInfo(const QDomElement xml, const QString id) void ProjectList::slotProcessNextClipInQueue() { if (m_infoQueue.isEmpty()) { - slotProcessNextThumbnail(); + emit processNextThumbnail(); return; } @@ -1080,40 +1135,51 @@ void ProjectList::slotProcessNextClipInQueue() if (j != m_infoQueue.constEnd()) { QDomElement dom = j.value(); const QString id = j.key(); - m_infoQueue.remove(j.key()); + m_infoQueue.remove(id); + m_processingClips.append(id); bool replace; if (dom.hasAttribute("replace")) { + // Proxy action was enabled / disabled and we want to replace current producer dom.removeAttribute("replace"); replace = true; } else replace = false; - emit getFileProperties(dom, id, m_listView->iconSize().height(), replace); + bool selectClip = !replace; + if (m_infoQueue.count() > 1) selectClip = false; + emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip); } - if (!m_infoQueue.isEmpty()) m_queueTimer.start(); } void ProjectList::slotUpdateClip(const QString &id) { ProjectItem *item = getItemById(id); - m_listView->blockSignals(true); + monitorItemEditing(false); if (item) item->setData(0, UsageRole, QString::number(item->numReferences())); - m_listView->blockSignals(false); + monitorItemEditing(true); } -void ProjectList::updateAllClips() +void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) { m_listView->setSortingEnabled(false); - kDebug() << "// UPDATE ALL CLPY"; QTreeWidgetItemIterator it(m_listView); DocClipBase *clip; ProjectItem *item; - m_listView->blockSignals(true); + monitorItemEditing(false); + int height = m_listView->iconSize().height(); + int width = (int)(height * m_render->dar()); + QPixmap missingPixmap = QPixmap(width, height); + missingPixmap.fill(Qt::transparent); + KIcon icon("dialog-close"); + QPainter p(&missingPixmap); + p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6)); + p.end(); + while (*it) { if ((*it)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (*it); - if (sub->data(0, Qt::DecorationRole).isNull()) { + if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) { item = static_cast ((*it)->parent()); requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); } @@ -1127,28 +1193,58 @@ void ProjectList::updateAllClips() item = static_cast (*it); clip = item->referencedClip(); if (item->referencedClip()->producer() == NULL) { - if (clip->isPlaceHolder() == false) - requestClipInfo(clip->toXML(), clip->getId()); - else if (!clip->isPlaceHolder()) + if (clip->isPlaceHolder() == false) { + QDomElement xml = clip->toXML(); + if (fpsChanged) { + xml.removeAttribute("out"); + xml.removeAttribute("file_hash"); + xml.removeAttribute("proxy_out"); + } + requestClipInfo(xml, clip->getId()); + } + else { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); + if (item->data(0, Qt::DecorationRole).isNull()) { + item->setData(0, Qt::DecorationRole, missingPixmap); + } + else { + QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); + QPainter p(&pixmap); + p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6)); + p.end(); + item->setData(0, Qt::DecorationRole, pixmap); + } + } } else { - if (item->data(0, Qt::DecorationRole).isNull()) + if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull()) requestClipThumbnail(clip->getId()); - if (item->data(0, DurationRole).toString().isEmpty()) + if (item->data(0, DurationRole).toString().isEmpty()) { item->changeDuration(item->referencedClip()->producer()->get_playtime()); + } + if (clip->isPlaceHolder()) { + QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); + if (pixmap.isNull()) { + pixmap = QPixmap(width, height); + pixmap.fill(Qt::transparent); + } + QPainter p(&pixmap); + p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6)); + p.end(); + item->setData(0, Qt::DecorationRole, pixmap); + } } item->setData(0, UsageRole, QString::number(item->numReferences())); } - //qApp->processEvents(); ++it; } - if (!m_queueTimer.isActive()) - m_queueTimer.start(); + + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); if (m_listView->isEnabled()) - m_listView->blockSignals(false); + monitorItemEditing(true); m_listView->setSortingEnabled(true); - if (m_infoQueue.isEmpty()) - slotProcessNextThumbnail(); + if (m_infoQueue.isEmpty()) { + slotProcessNextThumbnail(); + } } // static @@ -1157,7 +1253,7 @@ QString ProjectList::getExtensions() // Build list of mime types QStringList mimeTypes = QStringList() << "application/x-kdenlive" << "application/x-kdenlivetitle" << "video/mlt-playlist" << "text/plain" << "video/x-flv" << "application/vnd.rn-realmedia" << "video/x-dv" << "video/dv" << "video/x-msvideo" << "video/x-matroska" << "video/mpeg" << "video/ogg" << "video/x-ms-wmv" << "video/mp4" << "video/quicktime" << "video/webm" - << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash" + << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "audio/x-aiff" << "audio/aiff" << "application/ogg" << "application/mxf" << "application/x-shockwave-flash" << "image/gif" << "image/jpeg" << "image/png" << "image/x-tga" << "image/x-bmp" << "image/svg+xml" << "image/tiff" << "image/x-xcf" << "image/x-xcf-gimp" << "image/x-vnd.adobe.photoshop" << "image/x-pcx" << "image/x-exr"; QString allExtensions; @@ -1182,10 +1278,21 @@ void ProjectList::slotAddClip(const QList givenList, const QString &group const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files"); QCheckBox *b = new QCheckBox(i18n("Import image sequence")); b->setChecked(KdenliveSettings::autoimagesequence()); - KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b); + QCheckBox *c = new QCheckBox(i18n("Transparent background for images")); + c->setChecked(KdenliveSettings::autoimagetransparency()); + QFrame *f = new QFrame; + f->setFrameShape(QFrame::NoFrame); + QHBoxLayout *l = new QHBoxLayout; + l->addWidget(b); + l->addWidget(c); + l->addStretch(5); + f->setLayout(l); + KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f); d->setOperationMode(KFileDialog::Opening); d->setMode(KFile::Files); - d->exec(); + if (d->exec() == QDialog::Accepted) { + KdenliveSettings::setAutoimagetransparency(c->isChecked()); + } list = d->selectedUrls(); if (b->isChecked() && list.count() == 1) { // Check for image sequence @@ -1245,7 +1352,8 @@ void ProjectList::slotAddClip(const QList givenList, const QString &group void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace) { ProjectItem *item = getItemById(id); - QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue())); + m_processingClips.removeAll(id); + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); if (item) { const QString path = item->referencedClip()->fileURL().path(); if (item->referencedClip()->isPlaceHolder()) replace = false; @@ -1260,6 +1368,27 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace) } } +void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) +{ + ProjectItem *item = getItemById(id); + if (item) { + if (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); + QString path = item->referencedClip()->getProperty("proxy"); + KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"); + + //Security check: make sure the invalid proxy file is in the proxy folder + if (proxyFolder.isParentOf(KUrl(path))) { + QFile::remove(path); + } + } + m_processingClips.removeAll(id); + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); +} + void ProjectList::slotAddColorClip() { if (!m_commandStack) @@ -1367,6 +1496,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) { m_listView->blockSignals(true); m_listView->clear(); + m_processingClips.clear(); m_listView->setSortingEnabled(false); emit clipSelected(NULL); m_thumbnailQueue.clear(); @@ -1378,10 +1508,12 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_doc = doc; QMap flist = doc->clipManager()->documentFolderList(); + QStringList openedFolders = doc->getExpandedFolders(); QMapIterator f(flist); while (f.hasNext()) { f.next(); - (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key()); + FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key()); + folder->setExpanded(openedFolders.contains(f.key())); } QList list = doc->clipManager()->documentClipList(); @@ -1393,7 +1525,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &))); connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &))); connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &))); - connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips())); + connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool))); } QList ProjectList::documentClipList() const @@ -1425,7 +1557,7 @@ QDomElement ProjectList::producersList() void ProjectList::slotCheckForEmptyQueue() { - if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { + if (!m_refreshed && m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { m_refreshed = true; emit loadingIsOver(); emit displayMessage(QString(), -1); @@ -1437,21 +1569,6 @@ void ProjectList::slotCheckForEmptyQueue() } } -void ProjectList::reloadClipThumbnails() -{ - m_thumbnailQueue.clear(); - QTreeWidgetItemIterator it(m_listView); - while (*it) { - if ((*it)->type() != PROJECTCLIPTYPE) { - // subitem - ++it; - continue; - } - m_thumbnailQueue << ((ProjectItem *)(*it))->clipId(); - ++it; - } - QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail())); -} void ProjectList::requestClipThumbnail(const QString id) { @@ -1480,8 +1597,9 @@ void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) QTreeWidgetItem *item = getAnyItemById(clipId); if (item) slotRefreshClipThumbnail(item, update); - else + else { slotProcessNextThumbnail(); + } } void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) @@ -1514,13 +1632,13 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height)); else - pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height); + pix = item->referencedClip()->extractImage(frame, width, height); if (!pix.isNull()) { - m_listView->blockSignals(true); + monitorItemEditing(false); it->setData(0, Qt::DecorationRole, pix); - if (m_listView->isEnabled()) - m_listView->blockSignals(false); + monitorItemEditing(true); + if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix); else @@ -1528,69 +1646,95 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } if (update) emit projectModified(); - slotProcessNextThumbnail(); } } -void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace) +void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip) { QString toReload; ProjectItem *item = getItemById(clipId); + if (!m_refreshed) { + // we are still finishing to load the document + selectClip = false; + } + m_processingClips.removeAll(clipId); + if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true); + if (item && producer) { - m_listView->blockSignals(true); + //m_listView->blockSignals(true); + monitorItemEditing(false); + DocClipBase *clip = item->referencedClip(); item->setProperties(properties, metadata); - if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) { - item->referencedClip()->setValid(); + if (clip->isPlaceHolder() && producer->is_valid()) { + clip->setValid(); item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); toReload = clipId; } - if (item->referencedClip()->getProperty("proxy").isEmpty()) item->setProxyStatus(0); - item->referencedClip()->setProducer(producer, replace); - item->referencedClip()->askForAudioThumbs(); + // 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->isProxyRunning()) { + // proxy video and image clips + int maxSize; + CLIPTYPE t = item->clipType(); + if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt(); + else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt(); + if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) { + if (clip->getProperty("proxy").isEmpty()) { + KUrl proxyPath = m_doc->projectFolder(); + proxyPath.addPath("proxy/"); + proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"))); + QMap newProps; + // insert required duration for proxy + if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out")); + newProps.insert("proxy", proxyPath.path()); + QMap oldProps = clip->properties(); + oldProps.insert("proxy", QString()); + EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true); + m_doc->commandStack()->push(command); + } + } + } + clip->setProducer(producer, replace); + clip->askForAudioThumbs(); + if (!replace && item->data(0, Qt::DecorationRole).isNull()) requestClipThumbnail(clipId); if (!toReload.isEmpty()) item->slotSetToolTip(); - if (m_listView->isEnabled() && replace) { + if (m_listView->isEnabled()) + monitorItemEditing(true); + } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; + if (selectClip && m_infoQueue.isEmpty()) { + if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { + m_listView->setCurrentItem(item); + bool updatedProfile = false; + if (item->parent()) { + if (item->parent()->type() == PROJECTFOLDERTYPE) + static_cast (item->parent())->switchIcon(); + } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) { + // this is the first clip loaded in project, check if we want to adjust project settings to the clip + updatedProfile = adjustProjectProfileToItem(item); + } + if (updatedProfile == false) emit clipSelected(item->referencedClip()); + } else { + int max = m_doc->clipManager()->clipsCount(); + emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max)); + } + } + if (item && m_listView->isEnabled() && replace) { // update clip in clip monitor - emit clipSelected(NULL); emit clipSelected(item->referencedClip()); //TODO: Make sure the line below has no side effect toReload = clipId; } - /*else { - // Check if duration changed. - emit receivedClipDuration(clipId); - delete producer; - }*/ - if (m_listView->isEnabled()) - m_listView->blockSignals(false); - /*if (item->icon(0).isNull()) { - requestClipThumbnail(clipId); - }*/ - } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; - if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { - m_listView->setCurrentItem(item); - bool updatedProfile = false; - if (item->parent()) { - if (item->parent()->type() == PROJECTFOLDERTYPE) - static_cast (item->parent())->switchIcon(); - } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) { - // this is the first clip loaded in project, check if we want to adjust project settings to the clip - updatedProfile = adjustProjectProfileToItem(item); - } - if (updatedProfile == false) emit clipSelected(item->referencedClip()); - } else { - int max = m_doc->clipManager()->clipsCount(); - emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max)); - } if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true); - qApp->processEvents(); - slotProcessNextClipInQueue(); + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) @@ -1652,12 +1796,33 @@ bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) return profileUpdated; } +QString ProjectList::getDocumentProperty(const QString &key) const +{ + return m_doc->getDocumentProperty(key); +} + +bool ProjectList::useProxy() const +{ + return m_doc->getDocumentProperty("enableproxy").toInt(); +} + +bool ProjectList::generateProxy() const +{ + return m_doc->getDocumentProperty("generateproxy").toInt(); +} + +bool ProjectList::generateImageProxy() const +{ + return m_doc->getDocumentProperty("generateimageproxy").toInt(); +} + void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) { ProjectItem *item = getItemById(clipId); if (item && !pix.isNull()) { - m_listView->blockSignals(true); + monitorItemEditing(false); item->setData(0, Qt::DecorationRole, pix); + monitorItemEditing(true); m_doc->cachePixmap(item->getClipHash(), pix); if (m_listView->isEnabled()) m_listView->blockSignals(false); @@ -1705,7 +1870,7 @@ ProjectItem *ProjectList::getItemById(const QString &id) QTreeWidgetItemIterator it(m_listView); while (*it) { if ((*it)->type() != PROJECTCLIPTYPE) { - // subitem + // subitem or folder ++it; continue; } @@ -1742,7 +1907,7 @@ void ProjectList::slotSelectClip(const QString &ix) m_deleteButton->defaultAction()->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - m_proxyAction->setEnabled(true); + m_proxyAction->setEnabled(useProxy()); if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); @@ -1850,7 +2015,7 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d if (clip) { DocClipBase *base = clip->referencedClip(); base->addCutZone(in, out); - m_listView->blockSignals(true); + monitorItemEditing(false); SubProjectItem *sub = new SubProjectItem(clip, in, out, desc); if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) { if (!clip->isExpanded()) @@ -1858,10 +2023,10 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d m_listView->scrollToItem(sub); m_listView->editItem(sub, 1); } - QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); + QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); sub->setData(0, Qt::DecorationRole, p); m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p); - m_listView->blockSignals(false); + monitorItemEditing(true); } emit projectModified(); } @@ -1874,9 +2039,9 @@ void ProjectList::removeClipCut(const QString &id, int in, int out) base->removeCutZone(in, out); SubProjectItem *sub = getSubItem(clip, QPoint(in, out)); if (sub) { - m_listView->blockSignals(true); + monitorItemEditing(false); delete sub; - m_listView->blockSignals(false); + monitorItemEditing(true); } } emit projectModified(); @@ -1918,10 +2083,10 @@ void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const return; DocClipBase *base = clip->referencedClip(); base->updateCutZone(oldzone.x(), oldzone.y(), zone.x(), zone.y(), comment); - m_listView->blockSignals(true); + monitorItemEditing(false); sub->setZone(zone); sub->setDescription(comment); - m_listView->blockSignals(false); + monitorItemEditing(true); emit projectModified(); } @@ -1975,70 +2140,417 @@ QMap ProjectList::getProxies() } item = static_cast(*it); if (item && item->referencedClip() != NULL) { - QString proxy = item->referencedClip()->getProperty("proxy"); - if (!proxy.isEmpty()) list.insert(proxy, item->clipUrl().path()); + 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 || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return; + QString path = item->referencedClip()->getProperty("proxy"); + if (path.isEmpty()) { + setProxyStatus(path, PROXYCRASHED); + return; + } + setProxyStatus(path, PROXYWAITING); + if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path); + if (m_processingProxy.contains(path)) { + // Proxy is already being generated + return; + } + if (QFile::exists(path)) { + // Proxy already created + setProxyStatus(path, PROXYDONE); + slotGotProxy(path); + return; + } + m_processingProxy.append(path); + QtConcurrent::run(this, &ProjectList::slotGenerateProxy, path, item->clipUrl().path(), item->clipType(), QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt()); +} + +void ProjectList::slotAbortProxy(const QString id, const QString path) +{ + QTreeWidgetItemIterator it(m_listView); + ProjectItem *item = getItemById(id); + setProxyStatus(item, NOPROXY); + slotGotProxy(item); + if (!path.isEmpty() && m_processingProxy.contains(path)) { + m_abortProxy << path; + setProxyStatus(path, NOPROXY); + } +} + +void ProjectList::slotGenerateProxy(const QString destPath, const QString sourcePath, int clipType, int exif_orientation) +{ + emit projectModified(); + // Make sure proxy path is writable + QFile file(destPath); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + setProxyStatus(destPath, PROXYCRASHED); + return; + } + file.close(); + QFile::remove(destPath); + + setProxyStatus(destPath, CREATINGPROXY); + + // Special case: playlist clips (.mlt or .kdenlive project files) + if (clipType == PLAYLIST) { + // change FFmpeg params to MLT format + QStringList parameters; + parameters << sourcePath; + parameters << "-consumer" << "avformat:" + destPath; + 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(sourcePath); + parameters << "aspect=" + QString::number(display_ratio); + + //kDebug()<<"TRANSCOD: "< i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth()); + else proxy = i.scaledToHeight(m_render->renderHeight()); + if (exif_orientation > 1) { + // Rotate image according to exif data + QImage processed; + QMatrix matrix; + + switch ( exif_orientation ) { + 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(destPath); + } + else proxy.save(destPath); + setProxyStatus(destPath, PROXYDONE); + slotGotProxy(destPath); + m_abortProxy.removeAll(destPath); + m_processingProxy.removeAll(destPath); + return; + } + + QStringList parameters; + parameters << "-i" << sourcePath; + 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 << destPath; + kDebug()<<"// STARTING PROXY GEN: "<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(*it); - if (item && item->referencedClip() != NULL) { - if (KdenliveSettings::enableproxy()) { + if (item == NULL) { + ++it; + continue; + } + CLIPTYPE t = item->clipType(); + if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) { + if (generateProxy() && useProxy() && !item->isProxyRunning()) { DocClipBase *clip = item->referencedClip(); - connect(clip, SIGNAL(proxyReady(const QString, bool)), this, SLOT(slotGotProxy(const QString, bool))); - item->setProxyStatus(1); - clip->generateProxy(m_doc->projectFolder()); + 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 oldProps = clip->properties(); + oldProps.insert("proxy", QString()); + QMap 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 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()->properties(), 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 oldProps = clip->properties(); + oldProps.insert("proxy", QString()); + QMap newProps; + newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png"); + new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command); + } + } } - else if (!item->referencedClip()->getProperty("proxy").isEmpty()) { + else if (item->hasProxy()) { // remove proxy - item->referencedClip()->clearProperty("proxy"); - QDomElement e = item->toXml().cloneNode().toElement(); - e.removeAttribute("file_hash"); - e.setAttribute("replace", 1); - m_infoQueue.insert(item->clipId(), e); + QMap newProps; + newProps.insert("proxy", QString()); + newProps.insert("replace", "1"); + new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command); } } ++it; } - if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start(); - + if (command->childCount() > 0) m_doc->commandStack()->push(command); + else delete command; + if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } void ProjectList::slotProxyCurrentItem(bool doProxy) { - if (m_listView->currentItem()) { - if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) { - ProjectItem *item = static_cast (m_listView->currentItem()); - if (item->referencedClip()) { + QList list = m_listView->selectedItems(); + QTreeWidgetItem *listItem; + QUndoCommand *command = new QUndoCommand(); + if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count())); + else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count())); + + // Make sure the proxy folder exists + QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; + KStandardDirs::makeDir(proxydir); + + QMap newProps; + QMap oldProps; + if (!doProxy) newProps.insert("proxy", "-"); + 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 (!list.contains(sub)) list.append(sub); + } + } + if (listItem->type() == PROJECTCLIPTYPE) { + ProjectItem *item = static_cast (listItem); + CLIPTYPE t = item->clipType(); + if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) { + oldProps = item->referencedClip()->properties(); if (doProxy) { - DocClipBase *clip = item->referencedClip(); - connect(clip, SIGNAL(proxyReady(const QString, bool)), this, SLOT(slotGotProxy(const QString, bool))); - item->setProxyStatus(1); - clip->generateProxy(m_doc->projectFolder()); - } - else if (!item->referencedClip()->getProperty("proxy").isEmpty()) { - // remove proxy - item->referencedClip()->clearProperty("proxy"); - QDomElement e = item->toXml().cloneNode().toElement(); - e.removeAttribute("file_hash"); - e.setAttribute("replace", 1); - m_infoQueue.insert(item->clipId(), e); + newProps.clear(); + QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")); + // insert required duration for proxy + newProps.insert("proxy_out", item->referencedClip()->producerProperty("out")); + newProps.insert("proxy", path); + // We need to insert empty proxy so that undo will work + oldProps.insert("proxy", QString()); } + new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command); + } + } + } + if (command->childCount() > 0) { + m_doc->commandStack()->push(command); + } + else delete command; + //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); +} + + +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 (*it); + if (item->referencedClip()->getProperty("proxy") == proxyPath) { + QMap props; + props.insert("proxy", QString()); + new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand); + + } + } + ++it; + } + if (proxyCommand->childCount() == 0) + delete proxyCommand; + else + m_commandStack->push(proxyCommand); + QFile::remove(proxyPath); +} + +void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status) +{ + if (proxyPath.isEmpty()) return; + QTreeWidgetItemIterator it(m_listView); + ProjectItem *item; + while (*it) { + if ((*it)->type() == PROJECTCLIPTYPE) { + item = static_cast (*it); + if (item->referencedClip()->getProperty("proxy") == proxyPath) { + setProxyStatus(item, status); } - if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start(); } + ++it; } } +void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status) +{ + if (item == NULL) return; + monitorItemEditing(false); + item->setProxyStatus(status); + 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(*it); + result.append(item->clipId()); + } + ++it; + } + return result; +} + #include "projectlist.moc"