X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=375a1c2c488f5261a0325fe2089f70946920eb52;hb=11a4d09164d3e0d7dcbe5891cb5ccc8c50c89e17;hp=f2b8e9af7061181012928efe292bf4394af57897;hpb=5bac38471d4c90a8a520d6ec32b90913b6f0dbcb;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index f2b8e9af..375a1c2c 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -48,6 +48,9 @@ #include #include #include +#include +#include + #ifdef NEPOMUK #include #include @@ -62,14 +65,13 @@ #include #include #include +#include ProjectList::ProjectList(QWidget *parent) : QWidget(parent), m_render(NULL), m_fps(-1), m_commandStack(NULL), - m_editAction(NULL), - m_deleteAction(NULL), m_openAction(NULL), m_reloadAction(NULL), m_transcodeAction(NULL), @@ -78,33 +80,45 @@ ProjectList::ProjectList(QWidget *parent) : m_infoQueue(), m_thumbnailQueue() { - - m_listView = new ProjectListView(this);; QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); - + qRegisterMetaType("QDomElement"); // setup toolbar - KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine(this); - m_toolbar = new QToolBar("projectToolBar", this); - m_toolbar->addWidget(searchView); - int s = style()->pixelMetric(QStyle::PM_SmallIconSize); - m_toolbar->setIconSize(QSize(s, s)); - searchView->setTreeWidget(m_listView); + QFrame *frame = new QFrame; + frame->setFrameStyle(QFrame::NoFrame); + QHBoxLayout *box = new QHBoxLayout; + KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine; - m_addButton = new QToolButton(m_toolbar); + box->addWidget(searchView); + //int s = style()->pixelMetric(QStyle::PM_SmallIconSize); + //m_toolbar->setIconSize(QSize(s, s)); + + m_addButton = new QToolButton; m_addButton->setPopupMode(QToolButton::MenuButtonPopup); - m_toolbar->addWidget(m_addButton); + m_addButton->setAutoRaise(true); + box->addWidget(m_addButton); - layout->addWidget(m_toolbar); - layout->addWidget(m_listView); - setLayout(layout); + m_editButton = new QToolButton; + m_editButton->setAutoRaise(true); + box->addWidget(m_editButton); - m_queueTimer.setInterval(100); - connect(&m_queueTimer, SIGNAL(timeout()), this, SLOT(slotProcessNextClipInQueue())); - m_queueTimer.setSingleShot(true); + m_deleteButton = new QToolButton; + m_deleteButton->setAutoRaise(true); + box->addWidget(m_deleteButton); + frame->setLayout(box); + layout->addWidget(frame); + m_listView = new ProjectListView; + layout->addWidget(m_listView); + setLayout(layout); + searchView->setTreeWidget(m_listView); + m_proxyAction = new QAction(i18n("Proxy clip"), this); + m_proxyAction->setCheckable(true); + m_proxyAction->setChecked(false); + connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool))); + 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())); @@ -119,9 +133,9 @@ ProjectList::ProjectList(QWidget *parent) : m_listViewDelegate = new ItemDelegate(m_listView); m_listView->setItemDelegate(m_listViewDelegate); #ifdef NEPOMUK - if(KdenliveSettings::activate_nepomuk()) { + if (KdenliveSettings::activate_nepomuk()) { Nepomuk::ResourceManager::instance()->init(); - if(!Nepomuk::ResourceManager::instance()->initialized()) { + if (!Nepomuk::ResourceManager::instance()->initialized()) { kDebug() << "Cannot communicate with Nepomuk, DISABLING it"; KdenliveSettings::setActivate_nepomuk(false); } @@ -132,7 +146,6 @@ ProjectList::ProjectList(QWidget *parent) : ProjectList::~ProjectList() { delete m_menu; - delete m_toolbar; m_listView->blockSignals(true); m_listView->clear(); delete m_listViewDelegate; @@ -146,22 +159,20 @@ void ProjectList::focusTree() const void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction) { QList actions = addMenu->actions(); - for(int i = 0; i < actions.count(); i++) { - if(actions.at(i)->data().toString() == "clip_properties") { - m_editAction = actions.at(i); - m_toolbar->addAction(m_editAction); + for (int i = 0; i < actions.count(); i++) { + if (actions.at(i)->data().toString() == "clip_properties") { + m_editButton->setDefaultAction(actions.at(i)); actions.removeAt(i); i--; - } else if(actions.at(i)->data().toString() == "delete_clip") { - m_deleteAction = actions.at(i); - m_toolbar->addAction(m_deleteAction); + } else if (actions.at(i)->data().toString() == "delete_clip") { + m_deleteButton->setDefaultAction(actions.at(i)); actions.removeAt(i); i--; - } else if(actions.at(i)->data().toString() == "edit_clip") { + } else if (actions.at(i)->data().toString() == "edit_clip") { m_openAction = actions.at(i); actions.removeAt(i); i--; - } else if(actions.at(i)->data().toString() == "reload_clip") { + } else if (actions.at(i)->data().toString() == "reload_clip") { m_reloadAction = actions.at(i); actions.removeAt(i); i--; @@ -178,26 +189,27 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction) void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu) { - if(!addMenu) + if (!addMenu) return; QMenu *menu = m_addButton->menu(); menu->addMenu(addMenu); m_addButton->setMenu(menu); m_menu->addMenu(addMenu); - if(addMenu->isEmpty()) + if (addMenu->isEmpty()) addMenu->setEnabled(false); m_menu->addMenu(transcodeMenu); - if(transcodeMenu->isEmpty()) + if (transcodeMenu->isEmpty()) transcodeMenu->setEnabled(false); m_transcodeAction = transcodeMenu; m_menu->addAction(m_reloadAction); + m_menu->addAction(m_proxyAction); m_menu->addMenu(inTimelineMenu); inTimelineMenu->setEnabled(false); - m_menu->addAction(m_editAction); + m_menu->addAction(m_editButton->defaultAction()); m_menu->addAction(m_openAction); - m_menu->addAction(m_deleteAction); - m_menu->insertSeparator(m_deleteAction); + m_menu->addAction(m_deleteButton->defaultAction()); + m_menu->insertSeparator(m_deleteButton->defaultAction()); } @@ -219,18 +231,19 @@ 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; } ProjectItem *item; - if(!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return; - if(m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) item = static_cast (m_listView->currentItem()->parent()); else item = static_cast (m_listView->currentItem()); - if(item && (item->flags() & Qt::ItemIsDragEnabled)) { + if (item && (item->flags() & Qt::ItemIsDragEnabled)) { emit clipSelected(item->referencedClip()); emit showClipProperties(item->referencedClip()); } @@ -241,48 +254,83 @@ void ProjectList::editClipSelection(QList list) // Gather all common properties QMap commonproperties; QList clipList; - commonproperties.insert("force_aspect_ratio", "-"); + commonproperties.insert("force_aspect_num", "-"); + commonproperties.insert("force_aspect_den", "-"); commonproperties.insert("force_fps", "-"); commonproperties.insert("force_progressive", "-"); + commonproperties.insert("force_tff", "-"); commonproperties.insert("threads", "-"); commonproperties.insert("video_index", "-"); 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++) { + 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)); - if(!(item->flags() & Qt::ItemIsDragEnabled)) + if (!(item->flags() & Qt::ItemIsDragEnabled)) continue; - if(item) { + if (item) { // check properties DocClipBase *clip = item->referencedClip(); - if(clipList.contains(clip)) continue; - if(clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT) + 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) { - if(commonDuration == -1) + if (allowDurationChange && commonDuration != 0) { + if (commonDuration == -1) commonDuration = clip->duration().frames(m_fps); - else if(commonDuration != clip->duration().frames(m_fps)) + else if (commonDuration != clip->duration().frames(m_fps)) commonDuration = 0; } clipList.append(clip); QMap clipprops = clip->properties(); QMapIterator p(commonproperties); - while(p.hasNext()) { + while (p.hasNext()) { p.next(); - if(p.value().isEmpty()) continue; - if(clipprops.contains(p.key())) { - if(p.value() == "-") + if (p.value().isEmpty()) continue; + if (clipprops.contains(p.key())) { + if (p.value() == "-") commonproperties.insert(p.key(), clipprops.value(p.key())); - else if(p.value() != clipprops.value(p.key())) + else if (p.value() != clipprops.value(p.key())) commonproperties.insert(p.key(), QString()); } else { commonproperties.insert(p.key(), QString()); @@ -290,35 +338,37 @@ void ProjectList::editClipSelection(QList list) } } } - if(allowDurationChange) + if (allowDurationChange) commonproperties.insert("out", QString::number(commonDuration)); - QMapIterator p(commonproperties); - while(p.hasNext()) { + if (hasImages) + commonproperties.insert("transparency", transparency); + /*QMapIterator p(commonproperties); + while (p.hasNext()) { p.next(); kDebug() << "Result: " << p.key() << " = " << p.value(); - } + }*/ emit showClipProperties(clipList, commonproperties); } void ProjectList::slotOpenClip() { ProjectItem *item; - if(!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return; - if(m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) + if (m_listView->currentItem()->type() == QTreeWidgetItem::UserType + 1) item = static_cast (m_listView->currentItem()->parent()); else item = static_cast (m_listView->currentItem()); - if(item) { - if(item->clipType() == IMAGE) { - if(KdenliveSettings::defaultimageapp().isEmpty()) - KMessageBox::sorry(this, i18n("Please set a default application to open images in the Settings dialog")); + if (item) { + if (item->clipType() == IMAGE) { + if (KdenliveSettings::defaultimageapp().isEmpty()) + KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open images in the Settings dialog")); else QProcess::startDetached(KdenliveSettings::defaultimageapp(), QStringList() << item->clipUrl().path()); } - if(item->clipType() == AUDIO) { - if(KdenliveSettings::defaultaudioapp().isEmpty()) - KMessageBox::sorry(this, i18n("Please set a default application to open audio files in the Settings dialog")); + if (item->clipType() == AUDIO) { + if (KdenliveSettings::defaultaudioapp().isEmpty()) + KMessageBox::sorry(kapp->activeWindow(), i18n("Please set a default application to open audio files in the Settings dialog")); else QProcess::startDetached(KdenliveSettings::defaultaudioapp(), QStringList() << item->clipUrl().path()); } @@ -330,13 +380,13 @@ void ProjectList::cleanup() m_listView->clearSelection(); QTreeWidgetItemIterator it(m_listView); ProjectItem *item; - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { it++; continue; } item = static_cast (*it); - if(item->numReferences() == 0) + if (item->numReferences() == 0) item->setSelected(true); it++; } @@ -349,16 +399,16 @@ void ProjectList::trashUnusedClips() ProjectItem *item; QStringList ids; QStringList urls; - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { it++; continue; } item = static_cast (*it); - if(item->numReferences() == 0) { + if (item->numReferences() == 0) { ids << item->clipId(); KUrl url = item->clipUrl(); - if(!url.isEmpty() && !urls.contains(url.path())) + if (!url.isEmpty() && !urls.contains(url.path())) urls << url.path(); } it++; @@ -366,54 +416,64 @@ void ProjectList::trashUnusedClips() // Check that we don't use the URL in another clip QTreeWidgetItemIterator it2(m_listView); - while(*it2) { - if((*it2)->type() != PROJECTCLIPTYPE) { + while (*it2) { + if ((*it2)->type() != PROJECTCLIPTYPE) { it2++; continue; } item = static_cast (*it2); - if(item->numReferences() > 0) { + if (item->numReferences() > 0) { KUrl url = item->clipUrl(); - if(!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path()); + if (!url.isEmpty() && urls.contains(url.path())) urls.removeAll(url.path()); } it2++; } emit deleteProjectClips(ids, QMap ()); - for(int i = 0; i < urls.count(); i++) + for (int i = 0; i < urls.count(); i++) KIO::NetAccess::del(KUrl(urls.at(i)), this); } void ProjectList::slotReloadClip(const QString &id) { QList selected; - if(id.isEmpty()) + if (id.isEmpty()) selected = m_listView->selectedItems(); - else - selected.append(getItemById(id)); + else { + ProjectItem *itemToReLoad = getItemById(id); + if (itemToReLoad) selected.append(itemToReLoad); + } ProjectItem *item; - for(int i = 0; i < selected.count(); i++) { - if(selected.at(i)->type() != PROJECTCLIPTYPE) { - if(selected.at(i)->type() == PROJECTFOLDERTYPE) { - for(int j = 0; j < selected.at(i)->childCount(); j++) + for (int i = 0; i < selected.count(); i++) { + if (selected.at(i)->type() != PROJECTCLIPTYPE) { + if (selected.at(i)->type() == PROJECTFOLDERTYPE) { + for (int j = 0; j < selected.at(i)->childCount(); j++) selected.append(selected.at(i)->child(j)); } continue; } item = static_cast (selected.at(i)); - if(item) { - if(item->clipType() == TEXT) { - if(!item->referencedClip()->getProperty("xmltemplate").isEmpty()) + if (item) { + CLIPTYPE t = item->clipType(); + if (t == TEXT) { + if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item); - } else if(item->clipType() != COLOR && item->clipType() != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) { + } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) { item->referencedClip()->setPlaceHolder(true); item->setProperty("file_hash", QString()); - } else if(item->clipType() == IMAGE) { + } else if (t == IMAGE) { item->referencedClip()->producer()->set("force_reload", 1); } - //requestClipInfo(item->toXml(), item->clipId(), true); - // Clear the file_hash value, which will cause a complete reload of the clip - emit getFileProperties(item->toXml(), item->clipId(), m_listView->iconSize().height(), true); + + 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(); + if (length > 0 && !e.hasAttribute("length")) { + e.setAttribute("length", length); + } + } + emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false); } } } @@ -421,9 +481,9 @@ void ProjectList::slotReloadClip(const QString &id) void ProjectList::slotModifiedClip(const QString &id) { ProjectItem *item = getItemById(id); - if(item) { + if (item) { QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); - if(!pixmap.isNull()) { + if (!pixmap.isNull()) { QPainter p(&pixmap); p.fillRect(0, 0, pixmap.width(), pixmap.height(), QColor(255, 255, 255, 200)); p.drawPixmap(0, 0, KIcon("view-refresh").pixmap(m_listView->iconSize())); @@ -438,11 +498,11 @@ void ProjectList::slotModifiedClip(const QString &id) void ProjectList::slotMissingClip(const QString &id) { ProjectItem *item = getItemById(id); - if(item) { + if (item) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); - if(item->referencedClip()) { + if (item->referencedClip()) { item->referencedClip()->setPlaceHolder(true); - if(m_render == NULL) kDebug() << "********* ERROR, NULL RENDR"; + if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR"; item->referencedClip()->setProducer(m_render->invalidProducer(id), true); item->slotSetToolTip(); emit clipNeedsReload(id, true); @@ -456,10 +516,10 @@ void ProjectList::slotMissingClip(const QString &id) void ProjectList::slotAvailableClip(const QString &id) { ProjectItem *item = getItemById(id); - if(item == NULL) + if (item == NULL) return; item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); - if(item->referencedClip()) { // && item->referencedClip()->checkHash() == false) { + if (item->referencedClip()) { // && item->referencedClip()->checkHash() == false) { item->setProperty("file_hash", QString()); slotReloadClip(id); } @@ -475,8 +535,8 @@ bool ProjectList::hasMissingClips() { bool missing = false; QTreeWidgetItemIterator it(m_listView); - while(*it) { - if((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) { + while (*it) { + if ((*it)->type() == PROJECTCLIPTYPE && !((*it)->flags() & Qt::ItemIsDragEnabled)) { missing = true; break; } @@ -493,38 +553,39 @@ void ProjectList::setRenderer(Render *projectRender) void ProjectList::slotClipSelected() { - if(!m_listView->isEnabled()) return; - if(m_listView->currentItem()) { - if(m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { + if (!m_listView->isEnabled()) return; + if (m_listView->currentItem()) { + if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { emit clipSelected(NULL); - m_editAction->setEnabled(false); - m_deleteAction->setEnabled(true); + m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->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 (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { // this is a sub item, use base clip - m_deleteAction->setEnabled(true); + m_deleteButton->defaultAction()->setEnabled(true); clip = static_cast (m_listView->currentItem()->parent()); - if(clip == NULL) kDebug() << "-----------ERROR"; + if (clip == NULL) kDebug() << "-----------ERROR"; SubProjectItem *sub = static_cast (m_listView->currentItem()); emit clipSelected(clip->referencedClip(), sub->zone()); m_transcodeAction->setEnabled(false); return; } clip = static_cast (m_listView->currentItem()); - if(clip) + if (clip && clip->referencedClip()) emit clipSelected(clip->referencedClip()); - m_editAction->setEnabled(true); - m_deleteAction->setEnabled(true); + m_editButton->defaultAction()->setEnabled(true); + m_deleteButton->defaultAction()->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - if(clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { + if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); - } else if(clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { + } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); m_openAction->setEnabled(true); } else { @@ -537,17 +598,29 @@ void ProjectList::slotClipSelected() } } else { emit clipSelected(NULL); - m_editAction->setEnabled(false); - m_deleteAction->setEnabled(false); + m_editButton->defaultAction()->setEnabled(false); + m_deleteButton->defaultAction()->setEnabled(false); m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); } } +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) { + m_proxyAction->setEnabled(false); + return; + } + m_proxyAction->setEnabled(useProxy()); + m_proxyAction->blockSignals(true); + m_proxyAction->setChecked(clip->hasProxy()); + m_proxyAction->blockSignals(false); +} + void ProjectList::adjustTranscodeActions(ProjectItem *clip) const { - if(clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) { + if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) { m_transcodeAction->setEnabled(false); return; } @@ -555,13 +628,13 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const QList transcodeActions = m_transcodeAction->actions(); QStringList data; QString condition; - for(int i = 0; i < transcodeActions.count(); i++) { + for (int i = 0; i < transcodeActions.count(); i++) { data = transcodeActions.at(i)->data().toStringList(); - if(data.count() > 2) { + if (data.count() > 2) { condition = data.at(2); - if(condition.startsWith("vcodec")) + if (condition.startsWith("vcodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1))); - else if(condition.startsWith("acodec")) + else if (condition.startsWith("acodec")) transcodeActions.at(i)->setEnabled(clip->referencedClip()->hasVideoCodec(condition.section('=', 1, 1))); } } @@ -570,42 +643,48 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const void ProjectList::slotPauseMonitor() { - if(m_render) + if (m_render) m_render->pause(); } void ProjectList::slotUpdateClipProperties(const QString &id, QMap properties) { ProjectItem *item = getItemById(id); - if(item) { + if (item) { slotUpdateClipProperties(item, properties); - if(properties.contains("out") || properties.contains("force_fps")) { + if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource")) { slotReloadClip(id); - } else if(properties.contains("colour") || properties.contains("resource") || properties.contains("xmldata") || properties.contains("force_aspect_ratio") || properties.contains("templatetext")) { + } else if (properties.contains("colour") || + properties.contains("xmldata") || + properties.contains("force_aspect_num") || + properties.contains("force_aspect_den") || + properties.contains("templatetext")) { slotRefreshClipThumbnail(item); - emit refreshClip(); + emit refreshClip(id, true); + } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) { + emit refreshClip(id, false); } } } void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap properties) { - if(!clip) + if (!clip) return; clip->setProperties(properties); - if(properties.contains("name")) { - m_listView->blockSignals(true); + if (properties.contains("name")) { + 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")) { + 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)) { + if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) { // Use Nepomuk system to store clip description Nepomuk::Resource f(clip->clipUrl().path()); f.setDescription(properties.value("description")); @@ -617,9 +696,9 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap type() == PROJECTSUBCLIPTYPE) { + if (item->type() == PROJECTSUBCLIPTYPE) { // this is a sub-item - if(column == 1) { + if (column == 1) { // user edited description SubProjectItem *sub = static_cast (item); ProjectItem *item = static_cast (sub->parent()); @@ -629,14 +708,14 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) } return; } - if(item->type() == PROJECTFOLDERTYPE) { - if(column == 0) { + if (item->type() == PROJECTFOLDERTYPE) { + if (column == 0) { FolderProjectItem *folder = static_cast (item); editFolder(item->text(0), folder->groupName(), folder->clipId()); folder->setGroupName(item->text(0)); m_doc->clipManager()->addFolder(folder->clipId(), item->text(0)); const int children = item->childCount(); - for(int i = 0; i < children; i++) { + for (int i = 0; i < children; i++) { ProjectItem *child = static_cast (item->child(i)); child->setProperty("groupname", item->text(0)); } @@ -645,14 +724,14 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) } ProjectItem *clip = static_cast (item); - if(column == 1) { - if(clip->referencedClip()) { + if (column == 1) { + if (clip->referencedClip()) { QMap oldprops; QMap newprops; oldprops["description"] = clip->referencedClip()->getProperty("description"); newprops["description"] = item->text(1); - if(clip->clipType() == TEXT) { + if (clip->clipType() == TEXT) { // This is a text template clip, update the image /*oldprops.insert("xmldata", clip->referencedClip()->getProperty("xmldata")); newprops.insert("xmldata", generateTemplateXml(clip->referencedClip()->getProperty("xmltemplate"), item->text(2)).toString());*/ @@ -663,16 +742,18 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) EditClipCommand *command = new EditClipCommand(this, clip->clipId(), oldprops, newprops, false); m_commandStack->push(command); } - } else if(column == 0) { - if(clip->referencedClip()) { + } else if (column == 0) { + if (clip->referencedClip()) { 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); + } } } } @@ -680,28 +761,29 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column) void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) { bool enable = item ? true : false; - m_editAction->setEnabled(enable); - m_deleteAction->setEnabled(enable); + m_editButton->defaultAction()->setEnabled(enable); + m_deleteButton->defaultAction()->setEnabled(enable); m_reloadAction->setEnabled(enable); m_transcodeAction->setEnabled(enable); - if(enable) { + if (enable) { ProjectItem *clip = NULL; - if(m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { clip = static_cast (item->parent()); m_transcodeAction->setEnabled(false); - } else if(m_listView->currentItem()->type() == PROJECTCLIPTYPE) { + } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) { clip = static_cast (item); // Display relevant transcoding actions only adjustTranscodeActions(clip); + adjustProxyActions(clip); // Display uses in timeline emit findInTimeline(clip->clipId()); } else { m_transcodeAction->setEnabled(false); } - if(clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { + if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); - } else if(clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { + } else if (clip && clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); m_openAction->setEnabled(true); } else { @@ -716,7 +798,7 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) void ProjectList::slotRemoveClip() { - if(!m_listView->currentItem()) + if (!m_listView->currentItem()) return; QStringList ids; QMap folderids; @@ -724,34 +806,35 @@ void ProjectList::slotRemoveClip() QUndoCommand *delCommand = new QUndoCommand(); delCommand->setText(i18n("Delete Clip Zone")); - - for(int i = 0; i < selected.count(); i++) { - if(selected.at(i)->type() == PROJECTSUBCLIPTYPE) { + for (int i = 0; i < selected.count(); i++) { + if (selected.at(i)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (selected.at(i)); ProjectItem *item = static_cast (sub->parent()); new AddClipCutCommand(this, item->clipId(), sub->zone().x(), sub->zone().y(), sub->description(), false, true, delCommand); - } else if(selected.at(i)->type() == PROJECTFOLDERTYPE) { + } else if (selected.at(i)->type() == PROJECTFOLDERTYPE) { // folder FolderProjectItem *folder = static_cast (selected.at(i)); folderids[folder->groupName()] = folder->clipId(); int children = folder->childCount(); - if(children > 0 && KMessageBox::questionYesNo(this, i18np("Delete folder %2?
This will also remove the clip in that folder", "Delete folder %2?
This will also remove the %1 clips in that folder", children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) + if (children > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete folder %2?
This will also remove the clip in that folder", "Delete folder %2?
This will also remove the %1 clips in that folder", children, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return; - for(int i = 0; i < children; ++i) { + for (int i = 0; i < children; ++i) { ProjectItem *child = static_cast (folder->child(i)); ids << child->clipId(); } } else { ProjectItem *item = static_cast (selected.at(i)); ids << item->clipId(); - if(item->numReferences() > 0 && KMessageBox::questionYesNo(this, i18np("Delete clip %2?
This will also remove the clip in timeline", "Delete clip %2?
This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) + if (item->numReferences() > 0 && KMessageBox::questionYesNo(kapp->activeWindow(), i18np("Delete clip %2?
This will also remove the clip in timeline", "Delete clip %2?
This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip"), KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteAll") == KMessageBox::No) { + KMessageBox::enableMessage("DeleteAll"); return; + } } } - - if(delCommand->childCount() == 0) + KMessageBox::enableMessage("DeleteAll"); + if (delCommand->childCount() == 0) delete delCommand; else m_commandStack->push(delCommand); @@ -760,32 +843,37 @@ void ProjectList::slotRemoveClip() void ProjectList::updateButtons() const { - if(m_listView->topLevelItemCount() == 0) { - m_deleteAction->setEnabled(false); + if (m_listView->topLevelItemCount() == 0) { + m_deleteButton->defaultAction()->setEnabled(false); + m_editButton->defaultAction()->setEnabled(false); } else { - m_deleteAction->setEnabled(true); - if(!m_listView->currentItem()) + m_deleteButton->defaultAction()->setEnabled(true); + if (!m_listView->currentItem()) m_listView->setCurrentItem(m_listView->topLevelItem(0)); QTreeWidgetItem *item = m_listView->currentItem(); - if(item && item->type() == PROJECTCLIPTYPE) { - m_editAction->setEnabled(true); + if (item && item->type() == PROJECTCLIPTYPE) { + m_editButton->defaultAction()->setEnabled(true); 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) { + m_editButton->defaultAction()->setEnabled(true); + } + else m_editButton->defaultAction()->setEnabled(false); } - - m_editAction->setEnabled(false); m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); + m_proxyAction->setEnabled(false); } void ProjectList::selectItemById(const QString &clipId) { ProjectItem *item = getItemById(clipId); - if(item) + if (item) m_listView->setCurrentItem(item); } @@ -793,18 +881,18 @@ void ProjectList::selectItemById(const QString &clipId) void ProjectList::slotDeleteClip(const QString &clipId) { ProjectItem *item = getItemById(clipId); - if(!item) { + if (!item) { kDebug() << "/// Cannot find clip to delete"; return; } m_listView->blockSignals(true); QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item); - if(!newSelectedItem) + if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item); delete item; m_doc->clipManager()->deleteClip(clipId); m_listView->blockSignals(false); - if(newSelectedItem) { + if (newSelectedItem) { m_listView->setCurrentItem(newSelectedItem); } else { updateButtons(); @@ -828,29 +916,29 @@ void ProjectList::slotAddFolder() void ProjectList::slotAddFolder(const QString foldername, const QString &clipId, bool remove, bool edit) { - if(remove) { + if (remove) { FolderProjectItem *item = getFolderItemById(clipId); - if(item) { + if (item) { m_doc->clipManager()->deleteFolder(clipId); QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item); - if(!newSelectedItem) + if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item); delete item; - if(newSelectedItem) + if (newSelectedItem) m_listView->setCurrentItem(newSelectedItem); else updateButtons(); } } else { - if(edit) { + if (edit) { FolderProjectItem *item = getFolderItemById(clipId); - if(item) { + if (item) { m_listView->blockSignals(true); item->setGroupName(foldername); m_listView->blockSignals(false); m_doc->clipManager()->addFolder(clipId, foldername); const int children = item->childCount(); - for(int i = 0; i < children; i++) { + for (int i = 0; i < children; i++) { ProjectItem *child = static_cast (item->child(i)); child->setProperty("groupname", foldername); } @@ -874,87 +962,115 @@ void ProjectList::deleteProjectFolder(QMap map) QMapIterator i(map); QUndoCommand *delCommand = new QUndoCommand(); delCommand->setText(i18n("Delete Folder")); - while(i.hasNext()) { + while (i.hasNext()) { 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); - m_refreshed = false; - // 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); - } - clip->askForAudioThumbs(); const QString parent = clip->getProperty("groupid"); ProjectItem *item = NULL; - if(!parent.isEmpty()) { + monitorItemEditing(false); + if (!parent.isEmpty()) { FolderProjectItem *parentitem = getFolderItemById(parent); - if(!parentitem) { + if (!parentitem) { QStringList text; QString groupName = clip->getProperty("groupname"); //kDebug() << "Adding clip to new group: " << groupName; - if(groupName.isEmpty()) groupName = i18n("Folder"); + if (groupName.isEmpty()) groupName = i18n("Folder"); text << groupName; parentitem = new FolderProjectItem(m_listView, text, parent); } - if(parentitem) + 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)), this, SLOT(slotAbortProxy(const QString))); + if (getProperties) { + 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(), false); + } + clip->askForAudioThumbs(); + KUrl url = clip->fileURL(); - - if(getProperties == false && !clip->getClipHash().isEmpty()) { + if (getProperties == false && !clip->getClipHash().isEmpty()) { QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png"; - if(QFile::exists(cachedPixmap)) { + if (QFile::exists(cachedPixmap)) { QPixmap pix(cachedPixmap); - if(pix.isNull()) + if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this); item->setData(0, Qt::DecorationRole, pix); } } #ifdef NEPOMUK - if(!url.isEmpty() && KdenliveSettings::activate_nepomuk()) { + if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) { // if file has Nepomuk comment, use it Nepomuk::Resource f(url.path()); QString annotation = f.description(); - if(!annotation.isEmpty()) item->setText(1, annotation); + if (!annotation.isEmpty()) item->setText(1, annotation); item->setText(2, QString::number(f.rating())); } #endif // Add cut zones QList cuts = clip->cutZones(); - if(!cuts.isEmpty()) { - for(int i = 0; i < cuts.count(); i++) { + if (!cuts.isEmpty()) { + for (int i = 0; i < cuts.count(); i++) { SubProjectItem *sub = new SubProjectItem(item, cuts.at(i).zone.x(), cuts.at(i).zone.y(), cuts.at(i).description); - if(!clip->getClipHash().isEmpty()) { + if (!clip->getClipHash().isEmpty()) { QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png"; - if(QFile::exists(cachedPixmap)) { + if (QFile::exists(cachedPixmap)) { QPixmap pix(cachedPixmap); - if(pix.isNull()) + if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this); sub->setData(0, Qt::DecorationRole, pix); } } } } - if(m_listView->isEnabled()) { + 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) +{ + ProjectItem *item = getItemById(id); + if (item) { + // 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::slotResetProjectList() @@ -968,34 +1084,42 @@ 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())); } void ProjectList::slotProcessNextClipInQueue() { - if(m_infoQueue.isEmpty()) { - slotProcessNextThumbnail(); + if (m_infoQueue.isEmpty()) { + emit processNextThumbnail(); return; } QMap::const_iterator j = m_infoQueue.constBegin(); - if(j != m_infoQueue.constEnd()) { - const QDomElement dom = j.value(); + if (j != m_infoQueue.constEnd()) { + QDomElement dom = j.value(); const QString id = j.key(); - m_infoQueue.remove(j.key()); - emit getFileProperties(dom, id, m_listView->iconSize().height(), false); + 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; + 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); - if(item) item->setData(0, UsageRole, QString::number(item->numReferences())); - m_listView->blockSignals(false); + monitorItemEditing(false); + if (item) item->setData(0, UsageRole, QString::number(item->numReferences())); + monitorItemEditing(true); } void ProjectList::updateAllClips() @@ -1006,46 +1130,47 @@ void ProjectList::updateAllClips() QTreeWidgetItemIterator it(m_listView); DocClipBase *clip; ProjectItem *item; - m_listView->blockSignals(true); - while(*it) { - if((*it)->type() == PROJECTSUBCLIPTYPE) { + monitorItemEditing(false); + while (*it) { + if ((*it)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (*it); - if(sub->data(0, Qt::DecorationRole).isNull()) { + if (sub->data(0, Qt::DecorationRole).isNull()) { item = static_cast ((*it)->parent()); requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); } ++it; continue; - } else if((*it)->type() == PROJECTFOLDERTYPE) { + } else if ((*it)->type() == PROJECTFOLDERTYPE) { // folder ++it; continue; } else { item = static_cast (*it); clip = item->referencedClip(); - if(item->referencedClip()->producer() == NULL) { - if(clip->isPlaceHolder() == false) + if (item->referencedClip()->producer() == NULL) { + if (clip->isPlaceHolder() == false) requestClipInfo(clip->toXML(), clip->getId()); - else if(!clip->isPlaceHolder()) + else if (!clip->isPlaceHolder()) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); } else { - if(item->data(0, Qt::DecorationRole).isNull()) + 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())); } //qApp->processEvents(); ++it; } - if(!m_queueTimer.isActive()) - m_queueTimer.start(); - if(m_listView->isEnabled()) - m_listView->blockSignals(false); + + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + if (m_listView->isEnabled()) + monitorItemEditing(true); m_listView->setSortingEnabled(true); - if(m_infoQueue.isEmpty()) + if (m_infoQueue.isEmpty()) slotProcessNextThumbnail(); } @@ -1054,14 +1179,14 @@ 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" - << "audio/x-flac" << "audio/x-matroska" << "audio/mp4" << "audio/mpeg" << "audio/x-mp3" << "audio/ogg" << "audio/x-wav" << "application/ogg" << "application/mxf" + << "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" << "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; foreach(const QString & mimeType, mimeTypes) { KMimeType::Ptr mime(KMimeType::mimeType(mimeType)); - if(mime) { + if (mime) { allExtensions.append(mime->patterns().join(" ")); allExtensions.append(' '); } @@ -1071,36 +1196,48 @@ QString ProjectList::getExtensions() void ProjectList::slotAddClip(const QList givenList, const QString &groupName, const QString &groupId) { - if(!m_commandStack) + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK"; KUrl::List list; - if(givenList.isEmpty()) { + if (givenList.isEmpty()) { QString allExtensions = getExtensions(); 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, this, 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) { + if (b->isChecked() && list.count() == 1) { // Check for image sequence KUrl url = list.at(0); QString fileName = url.fileName().section('.', 0, -2); - if(fileName.at(fileName.size() - 1).isDigit()) { + if (fileName.at(fileName.size() - 1).isDigit()) { KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); - if(item.mimetype().startsWith("image")) { - int count = 0; + if (item.mimetype().startsWith("image")) { // import as sequence if we found more than one image in the sequence - QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &count); - if(count > 1) { + QStringList list; + QString pattern = SlideshowClip::selectedPath(url.path(), false, QString(), &list); + int count = list.count(); + if (count > 1) { delete d; QStringList groupInfo = getGroup(); // get image sequence base name - while(fileName.at(fileName.size() - 1).isDigit()) { + while (fileName.at(fileName.size() - 1).isDigit()) { fileName.chop(1); } @@ -1115,23 +1252,23 @@ void ProjectList::slotAddClip(const QList givenList, const QString &group } delete d; } else { - for(int i = 0; i < givenList.count(); i++) + for (int i = 0; i < givenList.count(); i++) list << givenList.at(i); } foreach(const KUrl & file, list) { // Check there is no folder here KMimeType::Ptr type = KMimeType::findByUrl(file); - if(type->is("inode/directory")) { + if (type->is("inode/directory")) { // user dropped a folder list.removeAll(file); } } - if(list.isEmpty()) + if (list.isEmpty()) return; - if(givenList.isEmpty()) { + if (givenList.isEmpty()) { QStringList groupInfo = getGroup(); m_doc->slotAddClipList(list, groupInfo.at(0), groupInfo.at(1)); } else { @@ -1142,24 +1279,46 @@ 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())); - if(item) { + 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; - if(!path.isEmpty()) { - if(replace) - KMessageBox::sorry(this, i18n("Clip %1
is invalid, will be removed from project.", path)); - else if(KMessageBox::questionYesNo(this, i18n("Clip %1
is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) + if (item->referencedClip()->isPlaceHolder()) replace = false; + if (!path.isEmpty()) { + if (replace) + KMessageBox::sorry(kapp->activeWindow(), i18n("Clip %1
is invalid, will be removed from project.", path)); + else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip %1
is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true; } - if(replace) + if (replace) emit deleteProjectClips(QStringList() << id, QMap ()); } } +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) + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK"; QDialog *dia = new QDialog(this); @@ -1174,7 +1333,7 @@ void ProjectList::slotAddColorClip() dia_ui.clip_durationBox->addWidget(t); dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor()); - if(dia->exec() == QDialog::Accepted) { + if (dia->exec() == QDialog::Accepted) { QString color = dia_ui.clip_color->color().name(); KdenliveSettings::setColorclipcolor(color); color = color.replace(0, 1, "0x") + "ff"; @@ -1188,12 +1347,12 @@ void ProjectList::slotAddColorClip() void ProjectList::slotAddSlideshowClip() { - if(!m_commandStack) + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK"; SlideshowClip *dia = new SlideshowClip(m_timecode, this); - if(dia->exec() == QDialog::Accepted) { + if (dia->exec() == QDialog::Accepted) { QStringList groupInfo = getGroup(); m_doc->slotCreateSlideshowClipFile(dia->clipName(), dia->selectedPath(), dia->imageCount(), dia->clipDuration(), dia->loop(), dia->crop(), dia->fade(), @@ -1211,7 +1370,7 @@ void ProjectList::slotAddTitleClip() void ProjectList::slotAddTitleTemplateClip() { - if(!m_commandStack) + if (!m_commandStack) kDebug() << "!!!!!!!!!!!!!!!! NO CMD STK"; QStringList groupInfo = getGroup(); @@ -1225,19 +1384,19 @@ void ProjectList::slotAddTitleTemplateClip() QDialog *dia = new QDialog(this); Ui::TemplateClip_UI dia_ui; dia_ui.setupUi(dia); - for(int i = 0; i < templateFiles.size(); ++i) + for (int i = 0; i < templateFiles.size(); ++i) dia_ui.template_list->comboBox()->addItem(templateFiles.at(i), path + templateFiles.at(i)); - if(!templateFiles.isEmpty()) + if (!templateFiles.isEmpty()) dia_ui.buttonBox->button(QDialogButtonBox::Ok)->setFocus(); - dia_ui.template_list->fileDialog()->setFilter("*.kdenlivetitle"); + dia_ui.template_list->fileDialog()->setFilter("application/x-kdenlivetitle"); //warning: setting base directory doesn't work?? KUrl startDir(path); dia_ui.template_list->fileDialog()->setUrl(startDir); dia_ui.text_box->setHidden(true); - if(dia->exec() == QDialog::Accepted) { + if (dia->exec() == QDialog::Accepted) { QString textTemplate = dia_ui.template_list->comboBox()->itemData(dia_ui.template_list->comboBox()->currentIndex()).toString(); - if(textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText(); + if (textTemplate.isEmpty()) textTemplate = dia_ui.template_list->comboBox()->currentText(); // Create a cloned template clip m_doc->slotCreateTextTemplateClip(groupInfo.at(0), groupInfo.at(1), KUrl(textTemplate)); } @@ -1248,10 +1407,10 @@ QStringList ProjectList::getGroup() const { QStringList result; QTreeWidgetItem *item = m_listView->currentItem(); - while(item && item->type() != PROJECTFOLDERTYPE) + while (item && item->type() != PROJECTFOLDERTYPE) item = item->parent(); - if(item) { + if (item) { FolderProjectItem *folder = static_cast (item); result << folder->groupName() << folder->clipId(); } else { @@ -1264,6 +1423,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(); @@ -1273,20 +1433,22 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); m_doc = doc; + m_proxyList.clear(); QMap flist = doc->clipManager()->documentFolderList(); + QStringList openedFolders = doc->getExpandedFolders(); QMapIterator f(flist); - while(f.hasNext()) { + 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(); - for(int i = 0; i < list.count(); i++) + for (int i = 0; i < list.count(); i++) slotAddClip(list.at(i), false); m_listView->blockSignals(false); - m_toolbar->setEnabled(true); connect(m_doc->clipManager(), SIGNAL(reloadClip(const QString &)), this, SLOT(slotReloadClip(const QString &))); 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 &))); @@ -1296,7 +1458,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) QList ProjectList::documentClipList() const { - if(m_doc == NULL) + if (m_doc == NULL) return QList (); return m_doc->clipManager()->documentClipList(); @@ -1309,8 +1471,8 @@ QDomElement ProjectList::producersList() doc.appendChild(prods); kDebug() << "//////////// PRO LIST BUILD PRDSLIST "; QTreeWidgetItemIterator it(m_listView); - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; @@ -1323,25 +1485,24 @@ 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); m_listView->blockSignals(false); m_listView->setEnabled(true); updateButtons(); - } else if(!m_refreshed) { + } else if (!m_refreshed) { QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue())); } } void ProjectList::reloadClipThumbnails() { - kDebug() << "////////////// RELOAD CLIPS THUMBNAILS!!!"; m_thumbnailQueue.clear(); QTreeWidgetItemIterator it(m_listView); - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; @@ -1354,20 +1515,20 @@ void ProjectList::reloadClipThumbnails() void ProjectList::requestClipThumbnail(const QString id) { - if(!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id); + if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id); } void ProjectList::slotProcessNextThumbnail() { - if(m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { + if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { slotCheckForEmptyQueue(); return; } - if(!m_infoQueue.isEmpty()) { + if (!m_infoQueue.isEmpty()) { //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail())); return; } - if(m_thumbnailQueue.count() > 1) { + if (m_thumbnailQueue.count() > 1) { int max = m_doc->clipManager()->clipsCount(); emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max)); } @@ -1377,7 +1538,7 @@ void ProjectList::slotProcessNextThumbnail() void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) { QTreeWidgetItem *item = getAnyItemById(clipId); - if(item) + if (item) slotRefreshClipThumbnail(item, update); else slotProcessNextThumbnail(); @@ -1385,12 +1546,12 @@ void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) { - if(it == NULL) return; + if (it == NULL) return; ProjectItem *item = NULL; bool isSubItem = false; int frame; - if(it->type() == PROJECTFOLDERTYPE) return; - if(it->type() == PROJECTSUBCLIPTYPE) { + if (it->type() == PROJECTFOLDERTYPE) return; + if (it->type() == PROJECTSUBCLIPTYPE) { item = static_cast (it->parent()); frame = static_cast (it)->zone().x(); isSubItem = true; @@ -1399,63 +1560,97 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) frame = item->referencedClip()->getClipThumbFrame(); } - if(item) { + if (item) { DocClipBase *clip = item->referencedClip(); - if(!clip) { + if (!clip) { slotProcessNextThumbnail(); return; } QPixmap pix; int height = m_listView->iconSize().height(); int width = (int)(height * m_render->dar()); - if(clip->clipType() == AUDIO) + if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height)); - else if(clip->clipType() == IMAGE) + 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); - if(!pix.isNull()) { - m_listView->blockSignals(true); + if (!pix.isNull()) { + monitorItemEditing(false); it->setData(0, Qt::DecorationRole, pix); - if(m_listView->isEnabled()) - m_listView->blockSignals(false); - if(!isSubItem) + monitorItemEditing(true); + + if (!isSubItem) m_doc->cachePixmap(item->getClipHash(), pix); else m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix); } - if(update) + if (update) emit projectModified(); - QTimer::singleShot(30, this, SLOT(slotProcessNextThumbnail())); + + 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(item && producer) { - m_listView->blockSignals(true); + 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); + 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; } - //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1()); - item->referencedClip()->setProducer(producer, replace); - item->referencedClip()->askForAudioThumbs(); - if(!replace && item->data(0, Qt::DecorationRole).isNull()) + + // 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) && generateProxy() && size.section('x', 0, 0).toInt() > maxSize) || (t == IMAGE && generateImageProxy() && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize))) { + if (clip->getProperty("proxy").isEmpty()) { + QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; + QMap newProps; + QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")); + newProps.insert("proxy", path); + // insert required duration for proxy + if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out")); + 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()) + if (!toReload.isEmpty()) item->slotSetToolTip(); - //emit receivedClipDuration(clipId); - if(m_listView->isEnabled() && replace) { + if (m_listView->isEnabled() && replace) { // update clip in clip monitor emit clipSelected(NULL); - emit clipSelected(item->referencedClip()); + emit clipSelected(clip); //TODO: Make sure the line below has no side effect toReload = clipId; } @@ -1464,52 +1659,123 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce emit receivedClipDuration(clipId); delete producer; }*/ - if(m_listView->isEnabled()) - m_listView->blockSignals(false); + if (m_listView->isEnabled()) + monitorItemEditing(true); /*if (item->icon(0).isNull()) { requestClipThumbnail(clipId); }*/ } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; - int max = m_doc->clipManager()->clipsCount(); - if(item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { + if (selectClip && m_infoQueue.isEmpty()) { + if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { m_listView->setCurrentItem(item); - if(item->parent()) { - if(item->parent()->type() == PROJECTFOLDERTYPE) + bool updatedProfile = false; + if (item->parent()) { + if (item->parent()->type() == PROJECTFOLDERTYPE) static_cast (item->parent())->switchIcon(); - } else if(KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) { + } 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 - int width = properties.value("frame_size").section('x', 0, 0).toInt(); - int height = properties.value("frame_size").section('x', -1).toInt(); - double fps = properties.value("fps").toDouble(); - if(width != m_doc->width() || height != m_doc->width() || qAbs(fps - m_doc->fps()) > 0.5) { - QString suggestedProfile = ProfilesDialog::getPathFromProperties(width, height, fps); - if(!suggestedProfile.isEmpty()) { - QString description = ProfilesDialog::getSettingsFromFile(suggestedProfile).value("description"); - if(KMessageBox::questionYesNo(this, i18n("Your clip does not match current project's profile.\nDo you want to adjust the profile (clip size: %1, fps: %2)?\nSuggested profile is %3", properties.value("frame_size"), fps, description)) == KMessageBox::Yes) { - //Change project profile - emit updateProfile(suggestedProfile); - } - } else KMessageBox::information(this, i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2)?\n", properties.value("frame_size"), fps)); - } + updatedProfile = adjustProjectProfileToItem(item); } - emit clipSelected(item->referencedClip()); + 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()) + } + if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true); - // small delay so that the app can display the progress info - QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue())); + + if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); +} + +bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) +{ + if (item == NULL) { + if (m_listView->currentItem() && m_listView->currentItem()->type() != PROJECTFOLDERTYPE) + item = static_cast (m_listView->currentItem()); + } + if (item == NULL || item->referencedClip() == NULL) { + KMessageBox::information(kapp->activeWindow(), i18n("Cannot find profile from current clip")); + return false; + } + bool profileUpdated = false; + QString size = item->referencedClip()->getProperty("frame_size"); + int width = size.section('x', 0, 0).toInt(); + int height = size.section('x', -1).toInt(); + double fps = item->referencedClip()->getProperty("fps").toDouble(); + double par = item->referencedClip()->getProperty("aspect_ratio").toDouble(); + if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) { + if (ProfilesDialog::matchProfile(width, height, fps, par, item->clipType() == IMAGE, m_doc->mltProfile()) == false) { + // get a list of compatible profiles + QMap suggestedProfiles = ProfilesDialog::getProfilesFromProperties(width, height, fps, par, item->clipType() == IMAGE); + if (!suggestedProfiles.isEmpty()) { + KDialog *dialog = new KDialog(this); + dialog->setCaption(i18n("Change project profile")); + dialog->setButtons(KDialog::Ok | KDialog::Cancel); + + QWidget container; + QVBoxLayout *l = new QVBoxLayout; + QLabel *label = new QLabel(i18n("Your clip does not match current project's profile.\nDo you want to change the project profile?\n\nThe following profiles match the clip (size: %1, fps: %2)", size, fps)); + l->addWidget(label); + QListWidget *list = new QListWidget; + list->setAlternatingRowColors(true); + QMapIterator i(suggestedProfiles); + while (i.hasNext()) { + i.next(); + QListWidgetItem *item = new QListWidgetItem(i.value(), list); + item->setData(Qt::UserRole, i.key()); + item->setToolTip(i.key()); + } + list->setCurrentRow(0); + l->addWidget(list); + container.setLayout(l); + dialog->setButtonText(KDialog::Ok, i18n("Update profile")); + dialog->setMainWidget(&container); + if (dialog->exec() == QDialog::Accepted) { + //Change project profile + profileUpdated = true; + if (list->currentItem()) + emit updateProfile(list->currentItem()->data(Qt::UserRole).toString()); + } + delete list; + delete label; + } else if (fps > 0) { + KMessageBox::information(kapp->activeWindow(), i18n("Your clip does not match current project's profile.\nNo existing profile found to match the clip's properties.\nClip size: %1\nFps: %2\n", size, fps)); + } + } + } + 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); + if (item && !pix.isNull()) { + monitorItemEditing(false); item->setData(0, Qt::DecorationRole, pix); + monitorItemEditing(true); m_doc->cachePixmap(item->getClipHash(), pix); - if(m_listView->isEnabled()) + if (m_listView->isEnabled()) m_listView->blockSignals(false); } } @@ -1518,29 +1784,29 @@ QTreeWidgetItem *ProjectList::getAnyItemById(const QString &id) { QTreeWidgetItemIterator it(m_listView); QString lookId = id; - if(id.contains('#')) + if (id.contains('#')) lookId = id.section('#', 0, 0); ProjectItem *result = NULL; - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { // subitem ++it; continue; } ProjectItem *item = static_cast(*it); - if(item->clipId() == lookId) { + if (item->clipId() == lookId) { result = item; break; } ++it; } - if(result == NULL || !id.contains('#')) { + if (result == NULL || !id.contains('#')) { return result; } else { - for(int i = 0; i < result->childCount(); i++) { + for (int i = 0; i < result->childCount(); i++) { SubProjectItem *sub = static_cast (result->child(i)); - if(sub && sub->zone().x() == id.section('#', 1, 1).toInt()) + if (sub && sub->zone().x() == id.section('#', 1, 1).toInt()) return sub; } } @@ -1553,14 +1819,14 @@ ProjectItem *ProjectList::getItemById(const QString &id) { ProjectItem *item; QTreeWidgetItemIterator it(m_listView); - while(*it) { - if((*it)->type() != PROJECTCLIPTYPE) { - // subitem + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { + // subitem or folder ++it; continue; } item = static_cast(*it); - if(item->clipId() == id) + if (item->clipId() == id) return item; ++it; } @@ -1571,10 +1837,10 @@ FolderProjectItem *ProjectList::getFolderItemById(const QString &id) { FolderProjectItem *item; QTreeWidgetItemIterator it(m_listView); - while(*it) { - if((*it)->type() == PROJECTFOLDERTYPE) { + while (*it) { + if ((*it)->type() == PROJECTFOLDERTYPE) { item = static_cast(*it); - if(item->clipId() == id) + if (item->clipId() == id) return item; } ++it; @@ -1585,17 +1851,18 @@ FolderProjectItem *ProjectList::getFolderItemById(const QString &id) void ProjectList::slotSelectClip(const QString &ix) { ProjectItem *clip = getItemById(ix); - if(clip) { + if (clip) { m_listView->setCurrentItem(clip); m_listView->scrollToItem(clip); - m_editAction->setEnabled(true); - m_deleteAction->setEnabled(true); + m_editButton->defaultAction()->setEnabled(true); + m_deleteButton->defaultAction()->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - if(clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { + m_proxyAction->setEnabled(useProxy()); + if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); - } else if(clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { + } else if (clip->clipType() == AUDIO && !KdenliveSettings::defaultaudioapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultaudioapp())); m_openAction->setEnabled(true); } else { @@ -1607,14 +1874,14 @@ void ProjectList::slotSelectClip(const QString &ix) QString ProjectList::currentClipUrl() const { ProjectItem *item; - if(!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString(); - if(m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { + if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE) return QString(); + if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { // subitem item = static_cast (m_listView->currentItem()->parent()); } else { item = static_cast (m_listView->currentItem()); } - if(item == NULL) + if (item == NULL) return QString(); return item->clipUrl().path(); } @@ -1624,22 +1891,22 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const KUrl::List result; ProjectItem *item; QList list = m_listView->selectedItems(); - for(int i = 0; i < list.count(); i++) { - if(list.at(i)->type() == PROJECTFOLDERTYPE) + for (int i = 0; i < list.count(); i++) { + if (list.at(i)->type() == PROJECTFOLDERTYPE) continue; - if(list.at(i)->type() == PROJECTSUBCLIPTYPE) { + if (list.at(i)->type() == PROJECTSUBCLIPTYPE) { // subitem item = static_cast (list.at(i)->parent()); } else { item = static_cast (list.at(i)); } - if(item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT) + if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT) continue; DocClipBase *clip = item->referencedClip(); - if(!condition.isEmpty()) { - if(condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1))) + if (!condition.isEmpty()) { + if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1))) continue; - else if(condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1))) + else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1))) continue; } result.append(item->clipUrl()); @@ -1650,7 +1917,7 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const void ProjectList::regenerateTemplate(const QString &id) { ProjectItem *clip = getItemById(id); - if(clip) + if (clip) regenerateTemplate(clip); } @@ -1664,18 +1931,18 @@ QDomDocument ProjectList::generateTemplateXml(QString path, const QString &repla { QDomDocument doc; QFile file(path); - if(!file.open(QIODevice::ReadOnly)) { + if (!file.open(QIODevice::ReadOnly)) { kWarning() << "ERROR, CANNOT READ: " << path; return doc; } - if(!doc.setContent(&file)) { + if (!doc.setContent(&file)) { kWarning() << "ERROR, CANNOT READ: " << path; file.close(); return doc; } file.close(); QDomNodeList texts = doc.elementsByTagName("content"); - for(int i = 0; i < texts.count(); i++) { + for (int i = 0; i < texts.count(); i++) { QString data = texts.item(i).firstChild().nodeValue(); data.replace("%s", replaceString); texts.item(i).firstChild().setNodeValue(data); @@ -1687,7 +1954,7 @@ QDomDocument ProjectList::generateTemplateXml(QString path, const QString &repla void ProjectList::slotAddClipCut(const QString &id, int in, int out) { ProjectItem *clip = getItemById(id); - if(clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out))) + if (clip == NULL || clip->referencedClip()->hasCutZone(QPoint(in, out))) return; AddClipCutCommand *command = new AddClipCutCommand(this, id, in, out, QString(), true, false); m_commandStack->push(command); @@ -1696,13 +1963,13 @@ void ProjectList::slotAddClipCut(const QString &id, int in, int out) void ProjectList::addClipCut(const QString &id, int in, int out, const QString desc, bool newItem) { ProjectItem *clip = getItemById(id); - if(clip) { + 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()) + if (newItem && desc.isEmpty() && !m_listView->isColumnHidden(1)) { + if (!clip->isExpanded()) clip->setExpanded(true); m_listView->scrollToItem(sub); m_listView->editItem(sub, 1); @@ -1710,7 +1977,7 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d QPixmap p = clip->referencedClip()->thumbProducer()->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(); } @@ -1718,14 +1985,14 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d void ProjectList::removeClipCut(const QString &id, int in, int out) { ProjectItem *clip = getItemById(id); - if(clip) { + if (clip) { DocClipBase *base = clip->referencedClip(); base->removeCutZone(in, out); SubProjectItem *sub = getSubItem(clip, QPoint(in, out)); - if(sub) { - m_listView->blockSignals(true); + if (sub) { + monitorItemEditing(false); delete sub; - m_listView->blockSignals(false); + monitorItemEditing(true); } } emit projectModified(); @@ -1734,12 +2001,12 @@ void ProjectList::removeClipCut(const QString &id, int in, int out) SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone) { SubProjectItem *sub = NULL; - if(clip) { - for(int i = 0; i < clip->childCount(); i++) { + if (clip) { + for (int i = 0; i < clip->childCount(); i++) { QTreeWidgetItem *it = clip->child(i); - if(it->type() == PROJECTSUBCLIPTYPE) { + if (it->type() == PROJECTSUBCLIPTYPE) { sub = static_cast (it); - if(sub->zone() == zone) + if (sub->zone() == zone) break; else sub = NULL; @@ -1751,7 +2018,7 @@ SubProjectItem *ProjectList::getSubItem(ProjectItem *clip, QPoint zone) void ProjectList::slotUpdateClipCut(QPoint p) { - if(!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) + if (!m_listView->currentItem() || m_listView->currentItem()->type() != PROJECTSUBCLIPTYPE) return; SubProjectItem *sub = static_cast (m_listView->currentItem()); ProjectItem *item = static_cast (sub->parent()); @@ -1763,22 +2030,383 @@ void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const { ProjectItem *clip = getItemById(id); SubProjectItem *sub = getSubItem(clip, oldzone); - if(sub == NULL || clip == NULL) + if (sub == NULL || clip == NULL) 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(); } void ProjectList::slotForceProcessing(const QString &id) { - while(m_infoQueue.contains(id)) { + while (m_infoQueue.contains(id)) { slotProcessNextClipInQueue(); } } +void ProjectList::slotAddOrUpdateSequence(const QString frameName) +{ + QString fileName = KUrl(frameName).fileName().section('_', 0, -2); + QStringList list; + QString pattern = SlideshowClip::selectedPath(frameName, false, QString(), &list); + int count = list.count(); + if (count > 1) { + const QList existing = m_doc->clipManager()->getClipByResource(pattern); + if (!existing.isEmpty()) { + // Sequence already exists, update + QString id = existing.at(0)->getId(); + //ProjectItem *item = getItemById(id); + QMap oldprops; + QMap newprops; + int ttl = existing.at(0)->getProperty("ttl").toInt(); + oldprops["out"] = existing.at(0)->getProperty("out"); + newprops["out"] = QString::number(ttl * count - 1); + slotUpdateClipProperties(id, newprops); + EditClipCommand *command = new EditClipCommand(this, id, oldprops, newprops, false); + m_commandStack->push(command); + } else { + // Create sequence + QStringList groupInfo = getGroup(); + m_doc->slotCreateSlideshowClipFile(fileName, pattern, count, m_timecode.reformatSeparators(KdenliveSettings::sequence_duration()), + false, false, false, + m_timecode.getTimecodeFromFrames(int(ceil(m_timecode.fps()))), QString(), 0, + QString(), groupInfo.at(0), groupInfo.at(1)); + } + } else emit displayMessage(i18n("Sequence not found"), -2); +} + +QMap ProjectList::getProxies() +{ + QMap list; + ProjectItem *item; + QTreeWidgetItemIterator it(m_listView); + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { + ++it; + continue; + } + item = static_cast(*it); + if (item && item->referencedClip() != NULL) { + if (item->hasProxy()) { + QString proxy = item->referencedClip()->getProperty("proxy"); + list.insert(proxy, item->clipUrl().path()); + } + } + ++it; + } + return list; +} + +void ProjectList::slotCreateProxy(const QString id, 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); +} + +void ProjectList::slotAbortProxy(const QString 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); + } +} + +void ProjectList::slotGenerateProxy(const QString id) +{ + setProxyStatus(id, CREATINGPROXY); + ProjectItem *item = getItemById(id); + if (item == NULL) return; + QString path = item->referencedClip()->getProperty("proxy"); + if (path.isEmpty()) { + setProxyStatus(id, PROXYCRASHED); + return; + } + + QString url = item->clipUrl().path(); + + if (QFile::exists(path)) { + setProxyStatus(id, PROXYDONE); + slotGotProxy(id); + return; + } + else { + // Make sure proxy path is writable + QFile file(path); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { + setProxyStatus(id, PROXYCRASHED); + return; + } + 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 = 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 << path; + QProcess myProcess; + myProcess.start("ffmpeg", parameters); + myProcess.waitForStarted(); + int result = -1; + while (myProcess.state() != QProcess::NotRunning) { + // building proxy file + if (m_abortProxyId.contains(id)) { + myProcess.close(); + myProcess.waitForFinished(); + m_abortProxyId.removeAll(id); + QFile::remove(path); + setProxyStatus(id, NOPROXY); + result = -2; + + } + myProcess.waitForFinished(500); + } + myProcess.waitForFinished(); + if (result == -1) result = myProcess.exitStatus(); + if (result == 0) { + // proxy successfully created + setProxyStatus(id, PROXYDONE); + slotGotProxy(id); + } + else if (result == 1) { + // Proxy process crashed + QFile::remove(path); + setProxyStatus(id, PROXYCRASHED); + } +} + +void ProjectList::updateProxyConfig() +{ + ProjectItem *item; + QTreeWidgetItemIterator it(m_listView); + QUndoCommand *command = new QUndoCommand(); + command->setText(i18n("Update proxy settings")); + QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; + while (*it) { + if ((*it)->type() != PROJECTCLIPTYPE) { + ++it; + continue; + } + item = static_cast(*it); + 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(); + 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->hasProxy()) { + // remove proxy + QMap 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); +} + +void ProjectList::slotProxyCurrentItem(bool doProxy) +{ + 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) && item->referencedClip()) { + oldProps = item->referencedClip()->properties(); + if (doProxy) { + newProps.clear(); + 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(), 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::setProxyStatus(const QString id, PROXYSTATUS status) +{ + ProjectItem *item = getItemById(id); + setProxyStatus(item, status); +} + +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"