#include <QHeaderView>
#include <QInputDialog>
#include <QtConcurrentRun>
+#include <QVBoxLayout>
+
+InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
+{
+ setCaption(caption);
+ if (infoOnly) setButtons(KDialog::Ok);
+ else setButtons(KDialog::Yes | KDialog::No);
+ QWidget *w = new QWidget(this);
+ QVBoxLayout *l = new QVBoxLayout;
+ l->addWidget(new QLabel(message));
+ m_clipList = new QListWidget;
+ l->addWidget(m_clipList);
+ w->setLayout(l);
+ setMainWidget(w);
+}
+
+InvalidDialog::~InvalidDialog()
+{
+ delete m_clipList;
+}
+
+
+void InvalidDialog::addClip(const QString &id, const QString &path)
+{
+ QListWidgetItem *item = new QListWidgetItem(path);
+ item->setData(Qt::UserRole, id);
+ m_clipList->addItem(item);
+}
+
+QStringList InvalidDialog::getIds() const
+{
+ QStringList ids;
+ for (int i = 0; i < m_clipList->count(); i++) {
+ ids << m_clipList->item(i)->data(Qt::UserRole).toString();
+ }
+ return ids;
+}
+
ProjectList::ProjectList(QWidget *parent) :
QWidget(parent),
m_doc(NULL),
m_refreshed(false),
m_thumbnailQueue(),
- m_abortAllProxies(false)
+ m_abortAllProxies(false),
+ m_invalidClipDialog(NULL)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
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()));
+ connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
m_menu->insertSeparator(m_deleteButton->defaultAction());
}
+void ProjectList::clearSelection()
+{
+ m_listView->clearSelection();
+}
QByteArray ProjectList::headerInfo() const
{
continue;
}
item = static_cast <ProjectItem *>(selected.at(i));
- if (item) {
+ if (item && !item->isProxyRunning()) {
+ DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
+ continue;
+ }
CLIPTYPE t = item->clipType();
if (t == TEXT) {
- if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
+ if (clip && !clip->getProperty("xmltemplate").isEmpty())
regenerateTemplate(item);
- } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
+ } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
item->referencedClip()->setPlaceHolder(true);
item->setProperty("file_hash", QString());
} else if (t == IMAGE) {
- item->referencedClip()->producer()->set("force_reload", 1);
+ clip->getProducer()->set("force_reload", 1);
}
QDomElement e = item->toXml();
// Make sure we get the correct producer length if it was adjusted in timeline
if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
- int length = QString(item->referencedClip()->producerProperty("length")).toInt();
+ int length = QString(clip->producerProperty("length")).toInt();
if (length > 0 && !e.hasAttribute("length")) {
e.setAttribute("length", length);
}
- }
- emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
+ }
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
}
}
}
return;
}
Mlt::Producer *newProd = m_render->invalidProducer(id);
- if (item->referencedClip()->producer()) {
+ if (item->referencedClip()->getProducer()) {
Mlt::Properties props(newProd->get_properties());
- Mlt::Properties src_props(item->referencedClip()->producer()->get_properties());
+ Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
props.inherit(src_props);
}
item->referencedClip()->setProducer(newProd, true);
item->slotSetToolTip();
- emit clipNeedsReload(id, true);
+ emit clipNeedsReload(id);
}
}
update();
void ProjectList::slotClipSelected()
{
- if (!m_listView->isEnabled()) return;
- if (m_listView->currentItem()) {
- if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
+ QTreeWidgetItem *item = m_listView->currentItem();
+ ProjectItem *clip = NULL;
+ if (item) {
+ if (item->type() == PROJECTFOLDERTYPE) {
emit clipSelected(NULL);
- m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
+ m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
m_deleteButton->defaultAction()->setEnabled(true);
m_openAction->setEnabled(false);
m_reloadAction->setEnabled(false);
m_transcodeAction->setEnabled(false);
- m_proxyAction->setEnabled(false);
} else {
- ProjectItem *clip;
- if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
+ if (item->type() == PROJECTSUBCLIPTYPE) {
// this is a sub item, use base clip
m_deleteButton->defaultAction()->setEnabled(true);
- clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
+ clip = static_cast <ProjectItem*>(item->parent());
if (clip == NULL) kDebug() << "-----------ERROR";
- SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
+ SubProjectItem *sub = static_cast <SubProjectItem*>(item);
emit clipSelected(clip->referencedClip(), sub->zone());
m_transcodeAction->setEnabled(false);
+ m_reloadAction->setEnabled(false);
+ adjustProxyActions(clip);
return;
}
- clip = static_cast <ProjectItem*>(m_listView->currentItem());
+ clip = static_cast <ProjectItem*>(item);
if (clip && clip->referencedClip())
emit clipSelected(clip->referencedClip());
m_editButton->defaultAction()->setEnabled(true);
m_reloadAction->setEnabled(false);
m_transcodeAction->setEnabled(false);
}
+ adjustProxyActions(clip);
}
void ProjectList::adjustProxyActions(ProjectItem *clip) const
if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
clip = static_cast <ProjectItem*>(item->parent());
m_transcodeAction->setEnabled(false);
+ adjustProxyActions(clip);
} else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
clip = static_cast <ProjectItem*>(item);
// Display relevant transcoding actions only
m_openAction->setEnabled(true);
m_reloadAction->setEnabled(true);
m_transcodeAction->setEnabled(true);
- m_proxyAction->setEnabled(useProxy());
return;
}
else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
{
- m_listView->setEnabled(false);
+ //m_listView->setEnabled(false);
const QString parent = clip->getProperty("groupid");
ProjectItem *item = NULL;
monitorItemEditing(false);
m_listView->processLayout();
QDomElement e = clip->toXML().cloneNode().toElement();
e.removeAttribute("file_hash");
- emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
}
else if (item->hasProxy() && !item->isProxyRunning()) {
slotCreateProxy(clip->getId());
clip->askForAudioThumbs();
KUrl url = clip->fileURL();
- if (getProperties == false && !clip->getClipHash().isEmpty()) {
- QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
- if (QFile::exists(cachedPixmap)) {
- QPixmap pix(cachedPixmap);
- if (pix.isNull())
- KIO::NetAccess::del(KUrl(cachedPixmap), this);
- item->setData(0, Qt::DecorationRole, pix);
- }
- }
#ifdef NEPOMUK
if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
// if file has Nepomuk comment, use it
}
}
monitorItemEditing(true);
- if (m_listView->isEnabled()) {
- updateButtons();
- }
+ updateButtons();
}
void ProjectList::slotGotProxy(const QString &proxyPath)
{
if (item == NULL || !m_refreshed) return;
DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ // Clip is being reprocessed, abort
+ kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
+ return;
+ }
+
// Proxy clip successfully created
QDomElement e = clip->toXML().cloneNode().toElement();
e.setAttribute("length", length);
}
}
- emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
}
void ProjectList::slotResetProjectList()
monitorItemEditing(true);
}
+void ProjectList::getCachedThumbnail(ProjectItem *item)
+{
+ if (!item) return;
+ DocClipBase *clip = item->referencedClip();
+ if (!clip) return;
+ QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
+ if (QFile::exists(cachedPixmap)) {
+ QPixmap pix(cachedPixmap);
+ if (pix.isNull()) {
+ KIO::NetAccess::del(KUrl(cachedPixmap), this);
+ requestClipThumbnail(item->clipId());
+ }
+ else item->setData(0, Qt::DecorationRole, pix);
+ }
+ else requestClipThumbnail(item->clipId());
+}
+
+void ProjectList::getCachedThumbnail(SubProjectItem *item)
+{
+ if (!item) return;
+ ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
+ if (!parentItem) return;
+ DocClipBase *clip = parentItem->referencedClip();
+ if (!clip) return;
+ int pos = item->zone().x();
+ QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
+ if (QFile::exists(cachedPixmap)) {
+ QPixmap pix(cachedPixmap);
+ if (pix.isNull()) {
+ KIO::NetAccess::del(KUrl(cachedPixmap), this);
+ requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
+ }
+ else item->setData(0, Qt::DecorationRole, pix);
+ }
+ else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
+}
+
void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged)
{
m_listView->setSortingEnabled(false);
if ((*it)->type() == PROJECTSUBCLIPTYPE) {
// subitem
SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
- if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) {
+ if (displayRatioChanged) {
item = static_cast <ProjectItem *>((*it)->parent());
requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
}
+ else if (sub->data(0, Qt::DecorationRole).isNull()) {
+ getCachedThumbnail(sub);
+ }
++it;
continue;
} else if ((*it)->type() == PROJECTFOLDERTYPE) {
} else {
item = static_cast <ProjectItem *>(*it);
clip = item->referencedClip();
- if (item->referencedClip()->producer() == NULL) {
+ if (item->referencedClip()->getProducer() == NULL) {
if (clip->isPlaceHolder() == false) {
QDomElement xml = clip->toXML();
if (fpsChanged) {
xml.removeAttribute("file_hash");
xml.removeAttribute("proxy_out");
}
- emit getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), xml.attribute("replace") == "1");
+ bool replace = xml.attribute("replace") == "1";
+ if (replace) resetThumbsProducer(clip);
+ m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
}
else {
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
}
}
} else {
- if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull())
+ if (displayRatioChanged)
requestClipThumbnail(clip->getId());
+ else if (item->data(0, Qt::DecorationRole).isNull()) {
+ getCachedThumbnail(item);
+ }
if (item->data(0, DurationRole).toString().isEmpty()) {
- item->changeDuration(item->referencedClip()->producer()->get_playtime());
+ item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
}
if (clip->isPlaceHolder()) {
QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
}
++it;
}
-
- if (m_listView->isEnabled())
- monitorItemEditing(true);
+
m_listView->setSortingEnabled(true);
if (m_render->processingItems() == 0) {
+ monitorItemEditing(true);
slotProcessNextThumbnail();
}
}
const QString path = item->referencedClip()->fileURL().path();
if (item->referencedClip()->isPlaceHolder()) replace = false;
if (!path.isEmpty()) {
+ if (m_invalidClipDialog) {
+ m_invalidClipDialog->addClip(id, path);
+ return;
+ }
+ else {
+ if (replace)
+ m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
+ else {
+ m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
+ }
+ m_invalidClipDialog->addClip(id, path);
+ int result = m_invalidClipDialog->exec();
+ if (result == KDialog::Yes) replace = true;
+ }
+ }
+ if (m_invalidClipDialog) {
if (replace)
- KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
- else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
- replace = true;
+ emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
+ delete m_invalidClipDialog;
+ m_invalidClipDialog = NULL;
}
- if (replace)
- emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
+
}
}
emit displayMessage(QString(), -1);
m_refreshed = true;
}
- m_listView->blockSignals(false);
- m_listView->setEnabled(true);
updateButtons();
} else if (!m_refreshed) {
QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
slotProcessNextThumbnail();
}
+void ProjectList::resetThumbsProducer(DocClipBase *clip)
+{
+ if (!clip) return;
+ clip->clearThumbProducer();
+ QString id = clip->getId();
+ m_thumbnailQueue.removeAll(id);
+}
+
void ProjectList::slotProcessNextThumbnail()
{
if (m_render->processingItems() > 0) {
if (clip->clipType() == AUDIO)
pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
else if (clip->clipType() == IMAGE)
- pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, swidth, dwidth, height));
- else
+ pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height));
+ else {
pix = item->referencedClip()->extractImage(frame, dwidth, height);
+ }
if (!pix.isNull()) {
monitorItemEditing(false);
}
}
-void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail)
+
+void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
{
QString toReload;
ProjectItem *item = getItemById(clipId);
m_listView->setEnabled(true);
}
if (item && producer) {
- //m_listView->blockSignals(true);
monitorItemEditing(false);
DocClipBase *clip = item->referencedClip();
- item->setProperties(properties, metadata);
if (producer->is_valid()) {
if (clip->isPlaceHolder()) {
clip->setValid();
}
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
}
+ item->setProperties(properties, metadata);
clip->setProducer(producer, replace);
clip->askForAudioThumbs();
- if (refreshThumbnail) requestClipThumbnail(clipId);
+
// 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()) {
+ else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
// proxy video and image clips
int maxSize;
CLIPTYPE t = item->clipType();
}
}
- if (!replace && item->data(0, Qt::DecorationRole).isNull())
+ if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
requestClipThumbnail(clipId);
+ }
if (!toReload.isEmpty())
item->slotSetToolTip();
-
- if (m_listView->isEnabled())
- monitorItemEditing(true);
} else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
if (queue == 0) {
+ monitorItemEditing(true);
if (item && m_thumbnailQueue.isEmpty()) {
m_listView->setCurrentItem(item);
bool updatedProfile = false;
updatedProfile = adjustProjectProfileToItem(item);
}
if (updatedProfile == false) {
- emit clipSelected(item->referencedClip());
+ //emit clipSelected(item->referencedClip());
}
} else {
int max = m_doc->clipManager()->clipsCount();
}
processNextThumbnail();
}
- if (item && m_listView->isEnabled() && replace) {
- // update clip in clip monitor
- if (item->isSelected() && m_listView->selectedItems().count() == 1)
- emit clipSelected(item->referencedClip());
- //TODO: Make sure the line below has no side effect
- toReload = clipId;
- }
+ if (replace && item) {
+ toReload = clipId;
+ }
+ if (!item) {
+ // no item for producer, delete it
+ delete producer;
+ }
if (!toReload.isEmpty())
- emit clipNeedsReload(toReload, true);
+ emit clipNeedsReload(toReload);
}
bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
monitorItemEditing(true);
//update();
m_doc->cachePixmap(item->getClipHash(), pix);
- if (m_listView->isEnabled())
- m_listView->blockSignals(false);
}
}
m_deleteButton->defaultAction()->setEnabled(true);
m_reloadAction->setEnabled(true);
m_transcodeAction->setEnabled(true);
- m_proxyAction->setEnabled(useProxy());
if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
m_openAction->setEnabled(true);
void ProjectList::regenerateTemplate(ProjectItem *clip)
{
//TODO: remove this unused method, only force_reload is necessary
- clip->referencedClip()->producer()->set("force_reload", 1);
+ clip->referencedClip()->getProducer()->set("force_reload", 1);
}
QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
//kDebug()<<"TRANSCOD: "<<parameters;
QProcess myProcess;
+ myProcess.setProcessChannelMode(QProcess::MergedChannels);
myProcess.start(KdenliveSettings::rendererpath(), parameters);
myProcess.waitForStarted();
int result = -1;
result = -2;
}
else {
- QString log = QString(myProcess.readAllStandardOutput());
- log.append(QString(myProcess.readAllStandardError()));
+ QString log = QString(myProcess.readAll());
processLogInfo(info.dest, &duration, log);
}
myProcess.waitForFinished(500);
parameters << info.dest;
kDebug()<<"// STARTING PROXY GEN: "<<parameters;
QProcess myProcess;
+ myProcess.setProcessChannelMode(QProcess::MergedChannels);
myProcess.start("ffmpeg", parameters);
myProcess.waitForStarted();
int result = -1;
}
else {
- QString log = QString(myProcess.readAllStandardOutput());
- log.append(QString(myProcess.readAllStandardError()));
+ QString log = QString(myProcess.readAll());
processLogInfo(info.dest, &duration, log);
}
myProcess.waitForFinished(500);
if (!list.contains(sub)) list.append(sub);
}
}
- if (listItem->type() == PROJECTCLIPTYPE) {
+ else if (listItem->type() == PROJECTSUBCLIPTYPE) {
+ QTreeWidgetItem *sub = listItem->parent();
+ if (!list.contains(sub)) list.append(sub);
+ }
+ else if (listItem->type() == PROJECTCLIPTYPE) {
ProjectItem *item = static_cast <ProjectItem*>(listItem);
CLIPTYPE t = item->clipType();
if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
- oldProps = item->referencedClip()->properties();
+ if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy())) 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;
+ }
+
+ resetThumbsProducer(clip);
+ oldProps = clip->properties();
if (doProxy) {
newProps.clear();
- QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
+ QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
// insert required duration for proxy
- newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+ 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());