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)
connect(clip, SIGNAL(abortProxy(const QString)), this, SLOT(slotAbortProxy(const QString)));
if (getProperties) {
m_listView->processLayout();
- m_refreshed = false;
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());
+ slotCreateProxy(clip->getId(), false);
}
clip->askForAudioThumbs();
// Proxy clip successfully created
QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();
//e.removeAttribute("file_hash");
+
+ // Make sure we get the correct producer length if it was adjusted in timeline
+ CLIPTYPE t = item->clipType();
+ if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
+ int length = QString(item->referencedClip()->producerProperty("length")).toInt();
+ if (length > 0 && !e.hasAttribute("length")) {
+ e.setAttribute("length", length);
+ }
+ }
e.setAttribute("replace", 1);
m_infoQueue.insert(id, e);
if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
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()));
}
} else {
if (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());
+ }
}
item->setData(0, UsageRole, QString::number(item->numReferences()));
}
}
}
-void ProjectList::slotRemoveInvalidProxy(const QString &id)
+void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
{
ProjectItem *item = getItemById(id);
if (item) {
+ //TODO: use durationError to display correct message to user after 0.8 release
+ if (durationError) kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
item->setProxyStatus(PROXYCRASHED);
QString path = item->referencedClip()->getProperty("proxy");
KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
m_proxyList.clear();
QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
+ QStringList openedFolders = doc->getExpandedFolders();
QMapIterator<QString, QString> 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 <DocClipBase*> list = doc->clipManager()->documentClipList();
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);
{
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) {
DocClipBase *clip = item->referencedClip();
if (!useProxy() && item->referencedClip()->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
if (useProxy() && generateProxy() && item->referencedClip()->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY);
- else if (useProxy() && !item->isProxyRunning() && (item->clipType() == AV || item->clipType() == VIDEO) && generateProxy() && size.section('x', 0, 0).toInt() > proxyMinSize()) {
+ else if (useProxy() && !item->isProxyRunning() && (item->clipType() == AV || item->clipType() == VIDEO) && generateProxy() && size.section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
if (clip->getProperty("proxy").isEmpty()) {
QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
- clip->setProperty("proxy", proxydir + item->referencedClip()->getClipHash() + ".avi");
+ QMap <QString, QString> newProps;
+ newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
+ // insert required duration for proxy
+ newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+ QMap <QString, QString> oldProps = clip->properties();
+ oldProps.insert("proxy", QString());
+ EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
+ m_doc->commandStack()->push(command);
}
}
return profileUpdated;
}
+QString ProjectList::getDocumentProperty(const QString &key) const
+{
+ return m_doc->getDocumentProperty(key);
+}
+
bool ProjectList::useProxy() const
{
return m_doc->getDocumentProperty("enableproxy").toInt();
return m_doc->getDocumentProperty("generateproxy").toInt();
}
-int ProjectList::proxyMinSize() const
+bool ProjectList::generateImageProxy() const
{
- return m_doc->getDocumentProperty("proxyminsize").toInt();
-}
-
-QString ProjectList::proxyParams() const
-{
- return m_doc->getDocumentProperty("proxyparams").simplified();
+ return m_doc->getDocumentProperty("generateimageproxy").toInt();
}
void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
return list;
}
-void ProjectList::slotCreateProxy(const QString id)
+void ProjectList::slotCreateProxy(const QString id, bool createProducer)
{
ProjectItem *item = getItemById(id);
if (!item || item->isProxyRunning()) return;
+
+ // If proxy producer already exists, skip creation
+ if (!createProducer) {
+ setProxyStatus(id, PROXYDONE);
+ return;
+ }
setProxyStatus(id, PROXYWAITING);
if (m_abortProxyId.contains(id)) m_abortProxyId.removeAll(id);
+ emit projectModified();
QtConcurrent::run(this, &ProjectList::slotGenerateProxy, id);
}
if (m_proxyList.contains(id)) m_proxyList.removeAll(id);
ProjectItem *item = getItemById(id);
if (item) {
+ emit projectModified();
if (item->isProxyReady()) slotGotProxy(id);
else if (item->isProxyRunning()) m_abortProxyId << id;
setProxyStatus(id, NOPROXY);
file.close();
QFile::remove(path);
}
+ if (item->clipType() == IMAGE) {
+ // Image proxy
+ QImage i(url);
+ if (i.isNull()) {
+ // Cannot load image
+ setProxyStatus(id, PROXYCRASHED);
+ return;
+ }
+ QImage proxy;
+ // Images are scaled to profile size.
+ //TODO: Make it be configurable?
+ if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
+ else proxy = i.scaledToHeight(m_render->renderHeight());
+ int exif_orientation = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
+ 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(path);
+ }
+ else proxy.save(path);
+ setProxyStatus(id, PROXYDONE);
+ slotGotProxy(id);
+ return;
+ }
QStringList parameters;
parameters << "-i" << url;
- QString params = proxyParams();
+ QString params = m_doc->getDocumentProperty("proxyparams").simplified();
foreach(QString s, params.split(' '))
parameters << s;
{
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;
if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
if (generateProxy() && useProxy() && !item->isProxyRunning()) {
DocClipBase *clip = item->referencedClip();
- if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > proxyMinSize()) {
+ if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
if (clip->getProperty("proxy").isEmpty()) {
- QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/";
- clip->setProperty("proxy", proxydir + item->referencedClip()->getClipHash() + ".avi");
+ // 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
- 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 <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()->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 <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;
if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
}
QList<QTreeWidgetItem *> list = m_listView->selectedItems();
QTreeWidgetItem *listItem;
QUndoCommand *command = new QUndoCommand();
- command->setText(i18np("Edit clip", "Edit clips", list.count()));
+ 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 <QString, QString> newProps;
+ QMap <QString, QString> oldProps;
if (!doProxy) newProps.insert("proxy", "-");
for (int i = 0; i < list.count(); i++) {
listItem = list.at(i);
if (listItem->type() == PROJECTCLIPTYPE) {
ProjectItem *item = static_cast <ProjectItem*>(listItem);
CLIPTYPE t = item->clipType();
- if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip()) {
+ if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE) && item->referencedClip()) {
+ oldProps = item->referencedClip()->properties();
if (doProxy) {
newProps.clear();
- QString path = proxydir + item->referencedClip()->getClipHash() + ".avi";
+ QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
newProps.insert("proxy", path);
+ // insert required duration for proxy
+ newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+ // We need to insert empty proxy so that undo will work
+ oldProps.insert("proxy", QString());
}
- new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
+ new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
}
}
}
- m_doc->commandStack()->push(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);
}
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;
+}
+
#include "projectlist.moc"