#include "projectlist.h"
#include "projectitem.h"
-#include "addfoldercommand.h"
+#include "commands/addfoldercommand.h"
+#include "projecttree/proxyclipjob.h"
+#include "projecttree/cutclipjob.h"
#include "kdenlivesettings.h"
#include "slideshowclip.h"
#include "ui_colorclip_ui.h"
#include "projectlistview.h"
#include "timecodedisplay.h"
#include "profilesdialog.h"
-#include "editclipcommand.h"
-#include "editclipcutcommand.h"
-#include "editfoldercommand.h"
-#include "addclipcutcommand.h"
+#include "commands/editclipcommand.h"
+#include "commands/editclipcutcommand.h"
+#include "commands/editfoldercommand.h"
+#include "commands/addclipcutcommand.h"
#include "ui_templateclip_ui.h"
+#include "ui_cutjobdialog_ui.h"
#include <KDebug>
#include <KAction>
#include <KIO/NetAccess>
#include <KFileItem>
#include <KApplication>
+#include <KStandardDirs>
+#include <KColorScheme>
+#include <KActionCollection>
+#include <KUrlRequester>
+
#ifdef NEPOMUK
#include <nepomuk/global.h>
#include <nepomuk/resourcemanager.h>
#include <QHeaderView>
#include <QInputDialog>
#include <QtConcurrentRun>
+#include <QVBoxLayout>
+
+SmallInfoLabel::SmallInfoLabel(QWidget *parent) : QPushButton(parent)
+{
+ setFixedWidth(0);
+ setFlat(true);
+
+ /*QString style = "QToolButton {background-color: %1;border-style: outset;border-width: 2px;
+ border-radius: 5px;border-color: beige;}";*/
+ KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
+ QColor bg = scheme.background(KColorScheme::LinkBackground).color();
+ QColor fg = scheme.foreground(KColorScheme::LinkText).color();
+ QString style = QString("QPushButton {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue());
+
+ bg = scheme.background(KColorScheme::ActiveBackground).color();
+ fg = scheme.foreground(KColorScheme::ActiveText).color();
+ style.append(QString("\nQPushButton:hover {padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue()));
+
+ setStyleSheet(style);
+ m_timeLine = new QTimeLine(500, this);
+ QObject::connect(m_timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(slotTimeLineChanged(qreal)));
+ QObject::connect(m_timeLine, SIGNAL(finished()), this, SLOT(slotTimeLineFinished()));
+ hide();
+}
+
+void SmallInfoLabel::slotTimeLineChanged(qreal value)
+{
+ setFixedWidth(qMin(value * 2, qreal(1.0)) * sizeHint().width());
+ update();
+}
+
+void SmallInfoLabel::slotTimeLineFinished()
+{
+ if (m_timeLine->direction() == QTimeLine::Forward) {
+ // Show
+ show();
+ } else {
+ // Hide
+ hide();
+ setText(QString());
+ }
+}
+
+void SmallInfoLabel::slotSetJobCount(int jobCount)
+{
+ if (jobCount > 0) {
+ // prepare animation
+ setText(i18np("%1 job", "%1 jobs", jobCount));
+ setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
+
+ if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+ setFixedWidth(sizeHint().width());
+ show();
+ return;
+ }
+
+ if (isVisible()) {
+ setFixedWidth(sizeHint().width());
+ update();
+ return;
+ }
+
+ setFixedWidth(0);
+ show();
+ int wantedWidth = sizeHint().width();
+ setGeometry(-wantedWidth, 0, wantedWidth, height());
+ m_timeLine->setDirection(QTimeLine::Forward);
+ if (m_timeLine->state() == QTimeLine::NotRunning) {
+ m_timeLine->start();
+ }
+ }
+ else {
+ if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+ setFixedWidth(0);
+ hide();
+ return;
+ }
+ // hide
+ m_timeLine->setDirection(QTimeLine::Backward);
+ if (m_timeLine->state() == QTimeLine::NotRunning) {
+ m_timeLine->start();
+ }
+ }
+
+}
+
+
+InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent)
+{
+ setCaption(caption);
+ if (infoOnly) setButtons(KDialog::Ok);
+ else setButtons(KDialog::Yes | KDialog::No);
+ QWidget *w = new QWidget(this);
+ QVBoxLayout *l = new QVBoxLayout;
+ l->addWidget(new QLabel(message));
+ m_clipList = new QListWidget;
+ l->addWidget(m_clipList);
+ w->setLayout(l);
+ setMainWidget(w);
+}
+
+InvalidDialog::~InvalidDialog()
+{
+ delete m_clipList;
+}
+
+
+void InvalidDialog::addClip(const QString &id, const QString &path)
+{
+ QListWidgetItem *item = new QListWidgetItem(path);
+ item->setData(Qt::UserRole, id);
+ m_clipList->addItem(item);
+}
+
+QStringList InvalidDialog::getIds() const
+{
+ QStringList ids;
+ for (int i = 0; i < m_clipList->count(); i++) {
+ ids << m_clipList->item(i)->data(Qt::UserRole).toString();
+ }
+ return ids;
+}
+
ProjectList::ProjectList(QWidget *parent) :
QWidget(parent),
m_commandStack(NULL),
m_openAction(NULL),
m_reloadAction(NULL),
+ m_stabilizeAction(NULL),
m_transcodeAction(NULL),
m_doc(NULL),
m_refreshed(false),
- m_infoQueue(),
- m_thumbnailQueue()
+ m_allClipsProcessed(false),
+ m_thumbnailQueue(),
+ m_abortAllJobs(false),
+ m_closing(false),
+ m_invalidClipDialog(NULL)
{
+ qRegisterMetaType<stringMap> ("stringMap");
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
QFrame *frame = new QFrame;
frame->setFrameStyle(QFrame::NoFrame);
QHBoxLayout *box = new QHBoxLayout;
+ box->setContentsMargins(0, 0, 0, 0);
+
KTreeWidgetSearchLine *searchView = new KTreeWidgetSearchLine;
-
box->addWidget(searchView);
- //int s = style()->pixelMetric(QStyle::PM_SmallIconSize);
- //m_toolbar->setIconSize(QSize(s, s));
+
+ // small info button for pending jobs
+ m_infoLabel = new SmallInfoLabel(this);
+ connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
+ m_jobsMenu = new QMenu(this);
+ QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
+ cancelJobs->setCheckable(false);
+ connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
+ m_jobsMenu->addAction(cancelJobs);
+ m_infoLabel->setMenu(m_jobsMenu);
+ box->addWidget(m_infoLabel);
+
+ int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
+ QSize iconSize(size, size);
m_addButton = new QToolButton;
m_addButton->setPopupMode(QToolButton::MenuButtonPopup);
m_addButton->setAutoRaise(true);
+ m_addButton->setIconSize(iconSize);
box->addWidget(m_addButton);
m_editButton = new QToolButton;
m_editButton->setAutoRaise(true);
+ m_editButton->setIconSize(iconSize);
box->addWidget(m_editButton);
m_deleteButton = new QToolButton;
m_deleteButton->setAutoRaise(true);
+ m_deleteButton->setIconSize(iconSize);
box->addWidget(m_deleteButton);
frame->setLayout(box);
layout->addWidget(frame);
m_listView = new ProjectListView;
layout->addWidget(m_listView);
+
+#if KDE_IS_VERSION(4,7,0)
+ m_infoMessage = new KMessageWidget;
+ layout->addWidget(m_infoMessage);
+ m_infoMessage->setCloseButtonVisible(true);
+ //m_infoMessage->setWordWrap(true);
+ m_infoMessage->hide();
+ m_logAction = new QAction(i18n("Show Log"), this);
+ m_logAction->setCheckable(false);
+ connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
+#endif
+
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()));
+ connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor()));
connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor()));
connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
+ connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
+
+ connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
+ connect(this, SIGNAL(processLog(ProjectItem *, int , int)), this, SLOT(slotProcessLog(ProjectItem *, int , int)));
+
+ connect(this, SIGNAL(jobCrashed(ProjectItem *, const QString &, const QString &, const QString)), this, SLOT(slotJobCrashed(ProjectItem *, const QString &, const QString &, const QString)));
m_listViewDelegate = new ItemDelegate(m_listView);
m_listView->setItemDelegate(m_listViewDelegate);
ProjectList::~ProjectList()
{
+ m_abortAllJobs = true;
+ m_closing = true;
+ m_thumbnailQueue.clear();
+ if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
+ m_jobList.clear();
delete m_menu;
m_listView->blockSignals(true);
m_listView->clear();
delete m_listViewDelegate;
+#if KDE_IS_VERSION(4,7,0)
+ delete m_infoMessage;
+#endif
}
void ProjectList::focusTree() const
m_reloadAction = actions.at(i);
actions.removeAt(i);
i--;
+ } else if (actions.at(i)->data().toString() == "proxy_clip") {
+ m_proxyAction = actions.at(i);
+ actions.removeAt(i);
+ i--;
}
}
m_menu->addActions(addMenu->actions());
}
-void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu)
+void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
{
- if (!addMenu)
+ if (!menus.contains("addMenu") && ! menus.value("addMenu") )
return;
QMenu *menu = m_addButton->menu();
- menu->addMenu(addMenu);
- m_addButton->setMenu(menu);
-
- m_menu->addMenu(addMenu);
- if (addMenu->isEmpty())
- addMenu->setEnabled(false);
- m_menu->addMenu(transcodeMenu);
- if (transcodeMenu->isEmpty())
- transcodeMenu->setEnabled(false);
- m_transcodeAction = transcodeMenu;
+ if (menus.contains("addMenu") && menus.value("addMenu")){
+ QMenu* addMenu=menus.value("addMenu");
+ menu->addMenu(addMenu);
+ m_addButton->setMenu(menu);
+
+ m_menu->addMenu(addMenu);
+ if (addMenu->isEmpty())
+ addMenu->setEnabled(false);
+ }
+ if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
+ QMenu* transcodeMenu=menus.value("transcodeMenu");
+ m_menu->addMenu(transcodeMenu);
+ if (transcodeMenu->isEmpty())
+ transcodeMenu->setEnabled(false);
+ m_transcodeAction = transcodeMenu;
+ }
+ if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
+ QMenu* stabilizeMenu=menus.value("stabilizeMenu");
+ m_menu->addMenu(stabilizeMenu);
+ if (stabilizeMenu->isEmpty())
+ stabilizeMenu->setEnabled(false);
+ m_stabilizeAction=stabilizeMenu;
+
+ }
m_menu->addAction(m_reloadAction);
m_menu->addAction(m_proxyAction);
- m_menu->addMenu(inTimelineMenu);
- inTimelineMenu->setEnabled(false);
+ if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
+ QMenu* inTimelineMenu=menus.value("inTimelineMenu");
+ m_menu->addMenu(inTimelineMenu);
+ inTimelineMenu->setEnabled(false);
+ }
m_menu->addAction(m_editButton->defaultAction());
m_menu->addAction(m_openAction);
m_menu->addAction(m_deleteButton->defaultAction());
m_menu->insertSeparator(m_deleteButton->defaultAction());
}
+void ProjectList::clearSelection()
+{
+ m_listView->clearSelection();
+}
QByteArray ProjectList::headerInfo() const
{
commonproperties.insert("audio_index", "-");
commonproperties.insert("force_colorspace", "-");
commonproperties.insert("full_luma", "-");
+ QString transparency = "-";
bool allowDurationChange = true;
int commonDuration = -1;
+ bool hasImages = false;;
ProjectItem *item;
for (int i = 0; i < list.count(); i++) {
item = NULL;
// check properties
DocClipBase *clip = item->referencedClip();
if (clipList.contains(clip)) continue;
+ if (clip->clipType() == IMAGE) {
+ hasImages = true;
+ if (clip->getProperty("transparency").isEmpty() || clip->getProperty("transparency").toInt() == 0) {
+ if (transparency == "-") {
+ // first non transparent image
+ transparency = "0";
+ }
+ else if (transparency == "1") {
+ // we have transparent and non transparent clips
+ transparency = "-1";
+ }
+ }
+ else {
+ if (transparency == "-") {
+ // first transparent image
+ transparency = "1";
+ }
+ else if (transparency == "0") {
+ // we have transparent and non transparent clips
+ transparency = "-1";
+ }
+ }
+ }
if (clip->clipType() != COLOR && clip->clipType() != IMAGE && clip->clipType() != TEXT)
allowDurationChange = false;
if (allowDurationChange && commonDuration != 0) {
}
if (allowDurationChange)
commonproperties.insert("out", QString::number(commonDuration));
+ if (hasImages)
+ commonproperties.insert("transparency", transparency);
/*QMapIterator<QString, QString> p(commonproperties);
while (p.hasNext()) {
p.next();
continue;
}
item = static_cast <ProjectItem *>(selected.at(i));
- if (item) {
+ if (item && !hasPendingProxy(item)) {
+ DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
+ continue;
+ }
CLIPTYPE t = item->clipType();
if (t == TEXT) {
- if (!item->referencedClip()->getProperty("xmltemplate").isEmpty())
+ if (clip && !clip->getProperty("xmltemplate").isEmpty())
regenerateTemplate(item);
- } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) {
+ } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) {
item->referencedClip()->setPlaceHolder(true);
item->setProperty("file_hash", QString());
} else if (t == IMAGE) {
- item->referencedClip()->producer()->set("force_reload", 1);
+ clip->getProducer()->set("force_reload", 1);
}
QDomElement e = item->toXml();
// Make sure we get the correct producer length if it was adjusted in timeline
if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
- int length = QString(item->referencedClip()->producerProperty("length")).toInt();
+ int length = QString(clip->producerProperty("length")).toInt();
if (length > 0 && !e.hasAttribute("length")) {
e.setAttribute("length", length);
- e.setAttribute("out", length - 1);
}
}
-
- emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false);
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
}
}
}
ProjectItem *item = getItemById(id);
if (item) {
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
+ int height = m_listView->iconSize().height();
+ int width = (int)(height * m_render->dar());
+ QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+ if (pixmap.isNull()) {
+ pixmap = QPixmap(width, height);
+ pixmap.fill(Qt::transparent);
+ }
+ KIcon icon("dialog-close");
+ QPainter p(&pixmap);
+ p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
+ p.end();
+ item->setData(0, Qt::DecorationRole, pixmap);
if (item->referencedClip()) {
item->referencedClip()->setPlaceHolder(true);
- if (m_render == NULL) kDebug() << "********* ERROR, NULL RENDR";
- item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
+ if (m_render == NULL) {
+ kDebug() << "********* ERROR, NULL RENDR";
+ return;
+ }
+ Mlt::Producer *newProd = m_render->invalidProducer(id);
+ if (item->referencedClip()->getProducer()) {
+ Mlt::Properties props(newProd->get_properties());
+ Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties());
+ props.inherit(src_props);
+ }
+ item->referencedClip()->setProducer(newProd, true);
item->slotSetToolTip();
- emit clipNeedsReload(id, true);
+ emit clipNeedsReload(id);
}
}
update();
void ProjectList::slotClipSelected()
{
- if (!m_listView->isEnabled()) return;
- if (m_listView->currentItem()) {
- if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) {
+ QTreeWidgetItem *item = m_listView->currentItem();
+ ProjectItem *clip = NULL;
+ if (item) {
+ if (item->type() == PROJECTFOLDERTYPE) {
emit clipSelected(NULL);
- m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0);
+ m_editButton->defaultAction()->setEnabled(item->childCount() > 0);
m_deleteButton->defaultAction()->setEnabled(true);
m_openAction->setEnabled(false);
m_reloadAction->setEnabled(false);
m_transcodeAction->setEnabled(false);
- m_proxyAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
} else {
- ProjectItem *clip;
- if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
+ if (item->type() == PROJECTSUBCLIPTYPE) {
// this is a sub item, use base clip
m_deleteButton->defaultAction()->setEnabled(true);
- clip = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
+ clip = static_cast <ProjectItem*>(item->parent());
if (clip == NULL) kDebug() << "-----------ERROR";
- SubProjectItem *sub = static_cast <SubProjectItem*>(m_listView->currentItem());
+ SubProjectItem *sub = static_cast <SubProjectItem*>(item);
emit clipSelected(clip->referencedClip(), sub->zone());
m_transcodeAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
+ m_reloadAction->setEnabled(false);
+ adjustProxyActions(clip);
return;
}
- clip = static_cast <ProjectItem*>(m_listView->currentItem());
+ clip = static_cast <ProjectItem*>(item);
if (clip && clip->referencedClip())
emit clipSelected(clip->referencedClip());
m_editButton->defaultAction()->setEnabled(true);
m_deleteButton->defaultAction()->setEnabled(true);
m_reloadAction->setEnabled(true);
m_transcodeAction->setEnabled(true);
+ m_stabilizeAction->setEnabled(true);
if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
m_openAction->setEnabled(true);
}
// Display relevant transcoding actions only
adjustTranscodeActions(clip);
+ adjustStabilizeActions(clip);
// Display uses in timeline
emit findInTimeline(clip->clipId());
}
m_openAction->setEnabled(false);
m_reloadAction->setEnabled(false);
m_transcodeAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
}
+ adjustProxyActions(clip);
}
void ProjectList::adjustProxyActions(ProjectItem *clip) const
{
- if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
+ if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
m_proxyAction->setEnabled(false);
return;
}
- m_proxyAction->setEnabled(true);
+ m_proxyAction->setEnabled(useProxy());
m_proxyAction->blockSignals(true);
m_proxyAction->setChecked(clip->hasProxy());
m_proxyAction->blockSignals(false);
}
+void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
+{
+
+ if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
+ m_stabilizeAction->setEnabled(false);
+ return;
+ }
+ m_stabilizeAction->setEnabled(true);
+
+}
+
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)
return;
clip->setProperties(properties);
+ if (properties.contains("proxy")) {
+ if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
+ clip->setJobStatus(NOJOB);
+ }
if (properties.contains("name")) {
monitorItemEditing(false);
clip->setText(0, properties.value("name"));
QMap <QString, QString> oldprops;
QMap <QString, QString> 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);
+ }
}
}
}
m_deleteButton->defaultAction()->setEnabled(enable);
m_reloadAction->setEnabled(enable);
m_transcodeAction->setEnabled(enable);
+ m_stabilizeAction->setEnabled(enable);
if (enable) {
ProjectItem *clip = NULL;
if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
clip = static_cast <ProjectItem*>(item->parent());
m_transcodeAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
+ adjustProxyActions(clip);
} else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
clip = static_cast <ProjectItem*>(item);
// Display relevant transcoding actions only
adjustTranscodeActions(clip);
+ adjustStabilizeActions(clip);
adjustProxyActions(clip);
// Display uses in timeline
emit findInTimeline(clip->clipId());
} else {
m_transcodeAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
}
if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
m_openAction->setEnabled(true);
m_reloadAction->setEnabled(true);
m_transcodeAction->setEnabled(true);
- m_proxyAction->setEnabled(true);
+ m_stabilizeAction->setEnabled(true);
return;
}
else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
m_openAction->setEnabled(false);
m_reloadAction->setEnabled(false);
m_transcodeAction->setEnabled(false);
+ m_stabilizeAction->setEnabled(false);
m_proxyAction->setEnabled(false);
}
kDebug() << "/// Cannot find clip to delete";
return;
}
+ deleteJobsForClip(clipId);
+ if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
m_listView->blockSignals(true);
QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
if (!newSelectedItem)
newSelectedItem = m_listView->itemBelow(item);
delete item;
+ // Pause playing to prevent crash while deleting clip
+ slotPauseMonitor();
m_doc->clipManager()->deleteClip(clipId);
m_listView->blockSignals(false);
if (newSelectedItem) {
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);
+ //m_listView->setEnabled(false);
const QString parent = clip->getProperty("groupid");
ProjectItem *item = NULL;
monitorItemEditing(false);
if (parentitem)
item = new ProjectItem(parentitem, clip);
}
- if (item == NULL)
+ if (item == NULL) {
item = new ProjectItem(m_listView, clip);
+ }
if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
+ connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
+ connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
if (getProperties) {
- qApp->processEvents();
- m_refreshed = false;
- // Proxy clips
- CLIPTYPE t = clip->clipType();
- if ((t == VIDEO || t == AV || t == UNKNOWN) && useProxy()) {
- if (clip->getProperty("proxy").isEmpty()) {
- connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
- setProxyStatus(item, 1);
- clip->generateProxy(m_doc->projectFolder(), proxyParams());
- }
- else {
- // Proxy clip already created
- setProxyStatus(item, 2);
- QDomElement e = clip->toXML().cloneNode().toElement();
- e.removeAttribute("file_hash");
- m_infoQueue.insert(clip->getId(), e);
- }
- }
- else {
- // We don't use proxies
- // remove file_hash so that we load all properties for the clip
- QDomElement e = clip->toXML().cloneNode().toElement();
- e.removeAttribute("file_hash");
- m_infoQueue.insert(clip->getId(), e);
- }
- //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
- }
- else if (!clip->getProperty("proxy").isEmpty()) {
- connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
- setProxyStatus(item, 1);
- clip->generateProxy(m_doc->projectFolder(), proxyParams());
- }
- clip->askForAudioThumbs();
+ int height = m_listView->iconSize().height();
+ int width = (int)(height * m_render->dar());
+ QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height));
+ item->setData(0, Qt::DecorationRole, pix);
+ //item->setFlags(Qt::ItemIsSelectable);
+ m_listView->processLayout();
+ QDomElement e = clip->toXML().cloneNode().toElement();
+ e.removeAttribute("file_hash");
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
+ }
+ // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
+ /*else if (item->hasProxy() && !item->isJobRunning()) {
+ slotCreateProxy(clip->getId());
+ }*/
KUrl url = clip->fileURL();
- if (getProperties == false && !clip->getClipHash().isEmpty()) {
- QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
- if (QFile::exists(cachedPixmap)) {
- QPixmap pix(cachedPixmap);
- if (pix.isNull())
- KIO::NetAccess::del(KUrl(cachedPixmap), this);
- item->setData(0, Qt::DecorationRole, pix);
- }
- }
#ifdef NEPOMUK
if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
// if file has Nepomuk comment, use it
item->setText(2, QString::number(f.rating()));
}
#endif
+
+ // Add info to date column
+ QFileInfo fileInfo(url.path());
+ if (fileInfo.exists()) {
+ item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss")));
+ }
+
// Add cut zones
QList <CutZoneInfo> cuts = clip->cutZones();
if (!cuts.isEmpty()) {
}
}
monitorItemEditing(true);
- if (m_listView->isEnabled()) {
- updateButtons();
+ updateButtons();
+}
+
+void ProjectList::slotGotProxy(const QString &proxyPath)
+{
+ if (proxyPath.isEmpty() || m_abortAllJobs) return;
+ QTreeWidgetItemIterator it(m_listView);
+ ProjectItem *item;
+
+ while (*it && !m_abortAllJobs) {
+ if ((*it)->type() == PROJECTCLIPTYPE) {
+ item = static_cast <ProjectItem *>(*it);
+ if (item->referencedClip()->getProperty("proxy") == proxyPath)
+ slotGotProxy(item);
+ }
+ ++it;
}
-
- if (getProperties && m_processingClips.isEmpty())
- m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
}
-void ProjectList::slotGotProxy(const QString &id, bool success)
+void ProjectList::slotGotProxy(ProjectItem *item)
{
- ProjectItem *item = getItemById(id);
- if (item) {
- if (success) {
- // Proxy clip successfully created
- setProxyStatus(item, 2);
- QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();
- e.removeAttribute("file_hash");
- e.setAttribute("replace", 1);
- m_infoQueue.insert(id, e);
- if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+ if (item == NULL) return;
+ DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ // Clip is being reprocessed, abort
+ kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
+ return;
+ }
+
+ // Proxy clip successfully created
+ QDomElement e = clip->toXML().cloneNode().toElement();
+
+ // 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(clip->producerProperty("length")).toInt();
+ if (length > 0 && !e.hasAttribute("length")) {
+ e.setAttribute("length", length);
}
- else setProxyStatus(item, 0);
- update();
}
+ resetThumbsProducer(clip);
+ m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
}
void ProjectList::slotResetProjectList()
{
+ m_listView->blockSignals(true);
+ m_abortAllJobs = true;
+ m_closing = true;
+ m_proxyThreads.waitForFinished();
+ m_proxyThreads.clearFutures();
+ m_thumbnailQueue.clear();
+ if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
+ m_jobList.clear();
m_listView->clear();
+ m_listView->setEnabled(true);
emit clipSelected(NULL);
- m_thumbnailQueue.clear();
- m_infoQueue.clear();
m_refreshed = false;
+ m_allClipsProcessed = false;
+ m_abortAllJobs = false;
+ m_closing = false;
+ m_listView->blockSignals(false);
}
-void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
+void ProjectList::slotUpdateClip(const QString &id)
{
- m_refreshed = false;
- m_infoQueue.insert(id, xml);
- //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
+ ProjectItem *item = getItemById(id);
+ monitorItemEditing(false);
+ if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
+ monitorItemEditing(true);
}
-void ProjectList::slotProcessNextClipInQueue()
+void ProjectList::getCachedThumbnail(ProjectItem *item)
{
- if (m_infoQueue.isEmpty()) {
- emit processNextThumbnail();
- return;
- }
-
- QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
- if (j != m_infoQueue.constEnd()) {
- QDomElement dom = j.value();
- const QString id = j.key();
- m_infoQueue.remove(id);
- m_processingClips.append(id);
- bool replace;
- if (dom.hasAttribute("replace")) {
- // Proxy action was enabled / disabled and we want to replace current producer
- dom.removeAttribute("replace");
- replace = true;
+ if (!item) return;
+ DocClipBase *clip = item->referencedClip();
+ if (!clip) return;
+ QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
+ if (QFile::exists(cachedPixmap)) {
+ QPixmap pix(cachedPixmap);
+ if (pix.isNull()) {
+ KIO::NetAccess::del(KUrl(cachedPixmap), this);
+ requestClipThumbnail(item->clipId());
+ }
+ else {
+ processThumbOverlays(item, pix);
+ item->setData(0, Qt::DecorationRole, pix);
}
- else replace = false;
- bool selectClip = !replace;
- if (m_infoQueue.count() > 1) selectClip = false;
- emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip);
+ }
+ else {
+ requestClipThumbnail(item->clipId());
}
}
-void ProjectList::slotUpdateClip(const QString &id)
+void ProjectList::getCachedThumbnail(SubProjectItem *item)
{
- ProjectItem *item = getItemById(id);
- monitorItemEditing(false);
- if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
- monitorItemEditing(true);
+ if (!item) return;
+ ProjectItem *parentItem = static_cast <ProjectItem *>(item->parent());
+ if (!parentItem) return;
+ DocClipBase *clip = parentItem->referencedClip();
+ if (!clip) return;
+ int pos = item->zone().x();
+ QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png";
+ if (QFile::exists(cachedPixmap)) {
+ QPixmap pix(cachedPixmap);
+ if (pix.isNull()) {
+ KIO::NetAccess::del(KUrl(cachedPixmap), this);
+ requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
+ }
+ else item->setData(0, Qt::DecorationRole, pix);
+ }
+ else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos));
}
-void ProjectList::updateAllClips()
+void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips)
{
+ if (!m_allClipsProcessed) m_listView->setEnabled(false);
m_listView->setSortingEnabled(false);
- kDebug() << "// UPDATE ALL CLPY";
-
QTreeWidgetItemIterator it(m_listView);
DocClipBase *clip;
ProjectItem *item;
monitorItemEditing(false);
+ int height = m_listView->iconSize().height();
+ int width = (int)(height * m_render->dar());
+ QPixmap missingPixmap = QPixmap(width, height);
+ missingPixmap.fill(Qt::transparent);
+ KIcon icon("dialog-close");
+ QPainter p(&missingPixmap);
+ p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
+ p.end();
+
+ int max = m_doc->clipManager()->clipsCount();
+ max = qMax(1, max);
+ int ct = 0;
+
while (*it) {
+ emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max));
if ((*it)->type() == PROJECTSUBCLIPTYPE) {
// subitem
SubProjectItem *sub = static_cast <SubProjectItem *>(*it);
- if (sub->data(0, Qt::DecorationRole).isNull()) {
+ if (displayRatioChanged) {
item = static_cast <ProjectItem *>((*it)->parent());
requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x()));
}
+ else if (sub->data(0, Qt::DecorationRole).isNull()) {
+ getCachedThumbnail(sub);
+ }
++it;
continue;
} else if ((*it)->type() == PROJECTFOLDERTYPE) {
} else {
item = static_cast <ProjectItem *>(*it);
clip = item->referencedClip();
- if (item->referencedClip()->producer() == NULL) {
- if (clip->isPlaceHolder() == false)
- requestClipInfo(clip->toXML(), clip->getId());
- else if (!clip->isPlaceHolder())
+ if (item->referencedClip()->getProducer() == NULL) {
+ bool replace = false;
+ if (brokenClips.contains(item->clipId())) {
+ // if this is a proxy clip, disable proxy
+ item->setJobStatus(NOJOB);
+ clip->setProperty("proxy", "-");
+ replace = true;
+ }
+ if (clip->isPlaceHolder() == false && !hasPendingProxy(item)) {
+ QDomElement xml = clip->toXML();
+ if (fpsChanged) {
+ xml.removeAttribute("out");
+ xml.removeAttribute("file_hash");
+ xml.removeAttribute("proxy_out");
+ }
+ if (!replace) replace = xml.attribute("replace") == "1";
+ if (replace) {
+ resetThumbsProducer(clip);
+ }
+ m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
+ }
+ 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()) {
+ item->setData(0, Qt::DecorationRole, missingPixmap);
+ }
+ else {
+ QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+ QPainter p(&pixmap);
+ p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+ p.end();
+ item->setData(0, Qt::DecorationRole, pixmap);
+ }
+ }
+ } else {
+ if (displayRatioChanged) {
requestClipThumbnail(clip->getId());
- if (item->data(0, DurationRole).toString().isEmpty())
- item->changeDuration(item->referencedClip()->producer()->get_playtime());
+ }
+ else if (item->data(0, Qt::DecorationRole).isNull()) {
+ getCachedThumbnail(item);
+ }
+ if (item->data(0, DurationRole).toString().isEmpty()) {
+ item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
+ }
+ if (clip->isPlaceHolder()) {
+ QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+ if (pixmap.isNull()) {
+ pixmap = QPixmap(width, height);
+ pixmap.fill(Qt::transparent);
+ }
+ QPainter p(&pixmap);
+ p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+ p.end();
+ item->setData(0, Qt::DecorationRole, pixmap);
+ }
}
item->setData(0, UsageRole, QString::number(item->numReferences()));
}
- //qApp->processEvents();
++it;
}
- /*if (!m_queueTimer.isActive())
- m_queueTimer.start();*/
- if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
- if (m_listView->isEnabled())
- monitorItemEditing(true);
+
m_listView->setSortingEnabled(true);
- if (m_infoQueue.isEmpty())
- slotProcessNextThumbnail();
+ m_allClipsProcessed = true;
+ if (m_render->processingItems() == 0) {
+ monitorItemEditing(true);
+ slotProcessNextThumbnail();
+ }
}
// static
return allExtensions.simplified();
}
+void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
+{
+ kDebug()<<"// Adding clip: "<<url;
+ QList <QUrl> list;
+ list.append(url);
+ slotAddClip(list, groupName, groupId);
+}
+
void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
{
if (!m_commandStack)
const QString dialogFilter = allExtensions + ' ' + QLatin1Char('|') + i18n("All Supported Files") + "\n* " + QLatin1Char('|') + i18n("All Files");
QCheckBox *b = new QCheckBox(i18n("Import image sequence"));
b->setChecked(KdenliveSettings::autoimagesequence());
- KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), b);
+ QCheckBox *c = new QCheckBox(i18n("Transparent background for images"));
+ c->setChecked(KdenliveSettings::autoimagetransparency());
+ QFrame *f = new QFrame;
+ f->setFrameShape(QFrame::NoFrame);
+ QHBoxLayout *l = new QHBoxLayout;
+ l->addWidget(b);
+ l->addWidget(c);
+ l->addStretch(5);
+ f->setLayout(l);
+ KFileDialog *d = new KFileDialog(KUrl("kfiledialog:///clipfolder"), dialogFilter, kapp->activeWindow(), f);
d->setOperationMode(KFileDialog::Opening);
d->setMode(KFile::Files);
- d->exec();
+ if (d->exec() == QDialog::Accepted) {
+ KdenliveSettings::setAutoimagetransparency(c->isChecked());
+ }
list = d->selectedUrls();
if (b->isChecked() && list.count() == 1) {
// Check for image sequence
{
ProjectItem *item = getItemById(id);
m_processingClips.removeAll(id);
- if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+ m_thumbnailQueue.removeAll(id);
if (item) {
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
const QString path = item->referencedClip()->fileURL().path();
if (item->referencedClip()->isPlaceHolder()) replace = false;
if (!path.isEmpty()) {
+ if (m_invalidClipDialog) {
+ m_invalidClipDialog->addClip(id, path);
+ return;
+ }
+ else {
+ if (replace)
+ m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", QString()), replace, kapp->activeWindow());
+ else {
+ m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow());
+ }
+ m_invalidClipDialog->addClip(id, path);
+ int result = m_invalidClipDialog->exec();
+ if (result == KDialog::Yes) replace = true;
+ }
+ }
+ if (m_invalidClipDialog) {
if (replace)
- KMessageBox::sorry(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
- else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip <b>%1</b><br />is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes)
- replace = true;
+ emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap <QString, QString>());
+ delete m_invalidClipDialog;
+ m_invalidClipDialog = NULL;
+ }
+
+ }
+}
+
+void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
+{
+ ProjectItem *item = getItemById(id);
+ if (item) {
+ kDebug()<<"// Proxy for clip "<<id<<" is invalid, delete";
+ item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
+ if (durationError) {
+ kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
+ emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
+ }
+ slotJobCrashed(item, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
+ 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);
+ }
+ if (item->referencedClip()->getProducer() == NULL) {
+ // Clip has no valid producer, request it
+ slotProxyCurrentItem(false, item);
+ }
+ else {
+ // refresh thumbs producer
+ item->referencedClip()->reloadThumbProducer();
}
- if (replace)
- emit deleteProjectClips(QStringList() << id, QMap <QString, QString>());
}
+ m_processingClips.removeAll(id);
+ m_thumbnailQueue.removeAll(id);
}
void ProjectList::slotAddColorClip()
TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
t->setValue(KdenliveSettings::color_duration());
- t->setTimeCodeFormat(false);
dia_ui.clip_durationBox->addWidget(t);
dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
void ProjectList::setDocument(KdenliveDoc *doc)
{
m_listView->blockSignals(true);
+ m_abortAllJobs = true;
+ m_closing = true;
+ m_proxyThreads.waitForFinished();
+ m_proxyThreads.clearFutures();
+ m_thumbnailQueue.clear();
m_listView->clear();
m_processingClips.clear();
+
m_listView->setSortingEnabled(false);
emit clipSelected(NULL);
- m_thumbnailQueue.clear();
- m_infoQueue.clear();
m_refreshed = false;
+ m_allClipsProcessed = false;
m_fps = doc->fps();
m_timecode = doc->timecode();
m_commandStack = doc->commandStack();
m_doc = doc;
+ m_abortAllJobs = false;
+ m_closing = false;
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();
+ if (list.isEmpty()) {
+ // blank document
+ m_refreshed = true;
+ m_allClipsProcessed = true;
+ }
for (int i = 0; i < list.count(); i++)
slotAddClip(list.at(i), false);
connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
- connect(m_doc->clipManager(), SIGNAL(checkAllClips()), this, SLOT(updateAllClips()));
+ connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList)));
}
QList <DocClipBase*> ProjectList::documentClipList() const
QDomDocument doc;
QDomElement prods = doc.createElement("producerlist");
doc.appendChild(prods);
- kDebug() << "//////////// PRO LIST BUILD PRDSLIST ";
QTreeWidgetItemIterator it(m_listView);
while (*it) {
if ((*it)->type() != PROJECTCLIPTYPE) {
void ProjectList::slotCheckForEmptyQueue()
{
- if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
- m_refreshed = true;
- emit loadingIsOver();
- emit displayMessage(QString(), -1);
- m_listView->blockSignals(false);
- m_listView->setEnabled(true);
+ if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) {
+ if (!m_refreshed && m_allClipsProcessed) {
+ m_refreshed = true;
+ m_listView->setEnabled(true);
+ slotClipSelected();
+ QTimer::singleShot(500, this, SIGNAL(loadingIsOver()));
+ emit displayMessage(QString(), -1);
+ }
updateButtons();
} else if (!m_refreshed) {
QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
}
}
-void ProjectList::reloadClipThumbnails()
-{
- m_thumbnailQueue.clear();
- QTreeWidgetItemIterator it(m_listView);
- while (*it) {
- if ((*it)->type() != PROJECTCLIPTYPE) {
- // subitem
- ++it;
- continue;
- }
- m_thumbnailQueue << ((ProjectItem *)(*it))->clipId();
- ++it;
- }
- QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
-}
void ProjectList::requestClipThumbnail(const QString id)
{
if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id);
+ slotProcessNextThumbnail();
+}
+
+void ProjectList::resetThumbsProducer(DocClipBase *clip)
+{
+ if (!clip) return;
+ clip->clearThumbProducer();
+ QString id = clip->getId();
+ m_thumbnailQueue.removeAll(id);
}
void ProjectList::slotProcessNextThumbnail()
{
- if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
- slotCheckForEmptyQueue();
+ if (m_render->processingItems() > 0) {
return;
}
- if (!m_infoQueue.isEmpty()) {
- //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail()));
+ if (m_thumbnailQueue.isEmpty()) {
+ slotCheckForEmptyQueue();
return;
}
- if (m_thumbnailQueue.count() > 1) {
- int max = m_doc->clipManager()->clipsCount();
- emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
- }
+ int max = m_doc->clipManager()->clipsCount();
+ emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max));
slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
}
QTreeWidgetItem *item = getAnyItemById(clipId);
if (item)
slotRefreshClipThumbnail(item, update);
- else
+ else {
slotProcessNextThumbnail();
+ }
}
void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
return;
}
QPixmap pix;
+ QImage img;
int height = m_listView->iconSize().height();
- int width = (int)(height * m_render->dar());
+ int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
+ int dwidth = (int)(height * m_render->dar() + 0.5);
if (clip->clipType() == AUDIO)
- pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
+ pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
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);
+ img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height);
+ else {
+ img = item->referencedClip()->extractImage(frame, dwidth, height);
+ }
- if (!pix.isNull()) {
+ if (!pix.isNull() || !img.isNull()) {
monitorItemEditing(false);
+ if (!img.isNull()) {
+ pix = QPixmap::fromImage(img);
+ processThumbOverlays(item, pix);
+ }
it->setData(0, Qt::DecorationRole, pix);
monitorItemEditing(true);
-
- if (!isSubItem)
- m_doc->cachePixmap(item->getClipHash(), pix);
- else
- m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix);
+
+ QString hash = item->getClipHash();
+ if (!hash.isEmpty() && !img.isNull()) {
+ if (!isSubItem)
+ m_doc->cacheImage(hash, img);
+ else
+ m_doc->cacheImage(hash + '#' + QString::number(frame), img);
+ }
}
if (update)
emit projectModified();
-
slotProcessNextThumbnail();
}
}
-void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace, bool selectClip)
+
+void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
{
QString toReload;
ProjectItem *item = getItemById(clipId);
- m_processingClips.removeAll(clipId);
- if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true);
+
+ int queue = m_render->processingItems();
if (item && producer) {
- //m_listView->blockSignals(true);
monitorItemEditing(false);
- item->setProperties(properties, metadata);
- if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
- item->referencedClip()->setValid();
+ DocClipBase *clip = item->referencedClip();
+ if (producer->is_valid()) {
+ if (clip->isPlaceHolder()) {
+ clip->setValid();
+ toReload = clipId;
+ }
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
- toReload = clipId;
}
- if (item->referencedClip()->getProperty("proxy").isEmpty()) setProxyStatus(item, 0);
- item->referencedClip()->setProducer(producer, replace);
- item->referencedClip()->askForAudioThumbs();
- if (!replace && item->data(0, Qt::DecorationRole).isNull())
- requestClipThumbnail(clipId);
+ item->setProperties(properties, metadata);
+ clip->setProducer(producer, replace);
+
+ // Proxy stuff
+ QString size = properties.value("frame_size");
+ if (!useProxy() && clip->getProperty("proxy").isEmpty()) setJobStatus(item, NOJOB);
+ if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setJobStatus(item, NOJOB);
+ else if (useProxy() && !item->hasProxy() && !hasPendingProxy(item)) {
+ // proxy video and image clips
+ int maxSize;
+ CLIPTYPE t = item->clipType();
+ if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
+ else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
+ if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
+ if (clip->getProperty("proxy").isEmpty()) {
+ KUrl proxyPath = m_doc->projectFolder();
+ proxyPath.addPath("proxy/");
+ proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
+ QMap <QString, QString> newProps;
+ // insert required duration for proxy
+ if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
+ newProps.insert("proxy", proxyPath.path());
+ QMap <QString, QString> oldProps = clip->properties();
+ oldProps.insert("proxy", QString());
+ EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
+ m_doc->commandStack()->push(command);
+ }
+ }
+ }
+
+ if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) {
+ getCachedThumbnail(item);
+ }
if (!toReload.isEmpty())
item->slotSetToolTip();
-
- if (m_listView->isEnabled() && replace) {
- // update clip in clip monitor
- emit clipSelected(NULL);
- emit clipSelected(item->referencedClip());
- //TODO: Make sure the line below has no side effect
- toReload = clipId;
- }
- /*else {
- // Check if duration changed.
- emit receivedClipDuration(clipId);
- delete producer;
- }*/
- if (m_listView->isEnabled())
- monitorItemEditing(true);
- /*if (item->icon(0).isNull()) {
- requestClipThumbnail(clipId);
- }*/
} else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS...";
- if (selectClip && m_infoQueue.isEmpty()) {
- if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
- m_listView->setCurrentItem(item);
- bool updatedProfile = false;
- if (item->parent()) {
- if (item->parent()->type() == PROJECTFOLDERTYPE)
- static_cast <FolderProjectItem *>(item->parent())->switchIcon();
- } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1) {
- // this is the first clip loaded in project, check if we want to adjust project settings to the clip
- updatedProfile = adjustProjectProfileToItem(item);
- }
- if (updatedProfile == false) emit clipSelected(item->referencedClip());
- } else {
- int max = m_doc->clipManager()->clipsCount();
- emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
+ if (queue == 0) {
+ monitorItemEditing(true);
+ if (item && m_thumbnailQueue.isEmpty()) {
+ if (!item->hasProxy() || m_render->activeClipId() == item->clipId())
+ m_listView->setCurrentItem(item);
+ bool updatedProfile = false;
+ if (item->parent()) {
+ if (item->parent()->type() == PROJECTFOLDERTYPE)
+ static_cast <FolderProjectItem *>(item->parent())->switchIcon();
+ } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
+ // this is the first clip loaded in project, check if we want to adjust project settings to the clip
+ updatedProfile = adjustProjectProfileToItem(item);
+ }
+ if (updatedProfile == false) {
+ //emit clipSelected(item->referencedClip());
+ }
+ } else {
+ int max = m_doc->clipManager()->clipsCount();
+ if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max));
+ }
+ if (m_allClipsProcessed) emit processNextThumbnail();
}
+ if (!item) {
+ // no item for producer, delete it
+ delete producer;
+ return;
}
+ if (replace) toReload = clipId;
if (!toReload.isEmpty())
- emit clipNeedsReload(toReload, true);
-
- if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+ emit clipNeedsReload(toReload);
}
bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
return profileUpdated;
}
+QString ProjectList::getDocumentProperty(const QString &key) const
+{
+ return m_doc->getDocumentProperty(key);
+}
+
bool ProjectList::useProxy() const
{
return m_doc->getDocumentProperty("enableproxy").toInt();
}
-QString ProjectList::proxyParams() const
+bool ProjectList::generateProxy() const
{
- return m_doc->getDocumentProperty("proxyparams").simplified();
+ return m_doc->getDocumentProperty("generateproxy").toInt();
}
-void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
+bool ProjectList::generateImageProxy() const
+{
+ return m_doc->getDocumentProperty("generateimageproxy").toInt();
+}
+
+void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img)
{
ProjectItem *item = getItemById(clipId);
+ if (item && !img.isNull()) {
+ QPixmap pix = QPixmap::fromImage(img);
+ processThumbOverlays(item, pix);
+ monitorItemEditing(false);
+ item->setData(0, Qt::DecorationRole, pix);
+ monitorItemEditing(true);
+ QString hash = item->getClipHash();
+ if (!hash.isEmpty()) m_doc->cacheImage(hash, img);
+ }
+}
+
+void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height)
+{
+ // For clips that have a generic icon (like audio clips...)
+ ProjectItem *item = getItemById(clipId);
+ QPixmap pix = KIcon(name).pixmap(QSize(width, height));
if (item && !pix.isNull()) {
monitorItemEditing(false);
item->setData(0, Qt::DecorationRole, pix);
monitorItemEditing(true);
- m_doc->cachePixmap(item->getClipHash(), pix);
- if (m_listView->isEnabled())
- m_listView->blockSignals(false);
}
}
m_deleteButton->defaultAction()->setEnabled(true);
m_reloadAction->setEnabled(true);
m_transcodeAction->setEnabled(true);
- m_proxyAction->setEnabled(true);
+ m_stabilizeAction->setEnabled(true);
if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
m_openAction->setEnabled(true);
void ProjectList::regenerateTemplate(ProjectItem *clip)
{
//TODO: remove this unused method, only force_reload is necessary
- clip->referencedClip()->producer()->set("force_reload", 1);
+ clip->referencedClip()->getProducer()->set("force_reload", 1);
}
QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString)
m_listView->scrollToItem(sub);
m_listView->editItem(sub, 1);
}
- QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
- sub->setData(0, Qt::DecorationRole, p);
- m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
+ QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2);
+ sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img));
+ QString hash = clip->getClipHash();
+ if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img);
monitorItemEditing(true);
}
emit projectModified();
void ProjectList::slotForceProcessing(const QString &id)
{
- while (m_infoQueue.contains(id)) {
- slotProcessNextClipInQueue();
- }
+ m_render->forceProcessing(id);
}
void ProjectList::slotAddOrUpdateSequence(const QString frameName)
}
item = static_cast<ProjectItem *>(*it);
if (item && item->referencedClip() != NULL) {
- QString proxy = item->referencedClip()->getProperty("proxy");
- if (!proxy.isEmpty()) list.insert(proxy, item->clipUrl().path());
+ if (item->hasProxy()) {
+ QString proxy = item->referencedClip()->getProperty("proxy");
+ list.insert(proxy, item->clipUrl().path());
+ }
}
++it;
}
return list;
}
+void ProjectList::slotCreateProxy(const QString id)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return;
+ QString path = item->referencedClip()->getProperty("proxy");
+ if (path.isEmpty()) {
+ jobCrashed(item, i18n("Failed to create proxy, empty path."));
+ return;
+ }
+
+ if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
+ if (m_processingProxy.contains(path)) {
+ // Proxy is already being generated
+ return;
+ }
+ if (QFileInfo(path).size() > 0) {
+ // Proxy already created
+ setJobStatus(item, JOBDONE);
+ slotGotProxy(path);
+ return;
+ }
+ m_processingProxy.append(path);
+
+ ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
+ m_jobList.append(job);
+ if (!item->isJobRunning()) setJobStatus(item, JOBWAITING, 0, job->jobType, job->statusMessage(JOBWAITING));
+
+ startJobProcess();
+}
+
+void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item|| item->referencedClip()->isPlaceHolder()) return;
+ QString source = item->clipUrl().path();
+ QString ext = source.section('.', -1);
+ QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
+
+ double clipFps = item->referencedClip()->getProperty("fps").toDouble();
+ if (clipFps == 0) clipFps = m_fps;
+ // if clip and project have different frame rate, adjust in and out
+ int in = zone.x();
+ int out = zone.y();
+ in = GenTime(in, m_timecode.fps()).frames(clipFps);
+ out = GenTime(out, m_timecode.fps()).frames(clipFps);
+ int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
+ int duration = out - in + 1;
+ QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
+ QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
+
+ QDialog *d = new QDialog(this);
+ Ui::CutJobDialog_UI ui;
+ ui.setupUi(d);
+ ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
+ ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
+ ui.file_url->setUrl(KUrl(dest));
+ QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
+ ui.info_label->setText(mess);
+ if (d->exec() != QDialog::Accepted) {
+ delete d;
+ return;
+ }
+ dest = ui.file_url->url().path();
+ bool acceptPath = dest != source;
+ if (acceptPath && QFileInfo(dest).size() > 0) {
+ // destination file olready exists, overwrite?
+ acceptPath = false;
+ }
+ while (!acceptPath) {
+ // Do not allow to save over original clip
+ if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
+ else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
+ if (d->exec() != QDialog::Accepted) {
+ delete d;
+ return;
+ }
+ dest = ui.file_url->url().path();
+ acceptPath = dest != source;
+ if (acceptPath && QFileInfo(dest).size() > 0) {
+ acceptPath = false;
+ }
+ }
+ QString extraParams = ui.extra_params->toPlainText().simplified();
+ KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
+ delete d;
+
+ m_processingProxy.append(dest);
+ QStringList jobParams;
+ jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
+ if (!extraParams.isEmpty()) jobParams << extraParams;
+ CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
+ m_jobList.append(job);
+ if (!item->isJobRunning()) setJobStatus(item, JOBWAITING, 0, job->jobType, job->statusMessage(JOBWAITING));
+
+ startJobProcess();
+}
+
+
+void ProjectList::startJobProcess()
+{
+ int ct = 0;
+ if (!m_proxyThreads.futures().isEmpty()) {
+ // Remove inactive threads
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ m_proxyThreads.clearFutures();
+ for (int i = 0; i < futures.count(); i++)
+ if (!futures.at(i).isFinished()) {
+ m_proxyThreads.addFuture(futures.at(i));
+ ct++;
+ }
+ }
+ emit jobCount(ct + m_jobList.count());
+
+ if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
+}
+
+void ProjectList::slotAbortProxy(const QString id, const QString path)
+{
+ QTreeWidgetItemIterator it(m_listView);
+ ProjectItem *item = getItemById(id);
+ if (!item) return;
+ if (!path.isEmpty() && m_processingProxy.contains(path)) {
+ m_abortProxy << path;
+ }
+ else {
+ // Should only be done if we were already using a proxy producer
+ if (!item->isProxyRunning()) slotGotProxy(item);
+ }
+}
+
+void ProjectList::slotProcessJobs()
+{
+ while (!m_jobList.isEmpty() && !m_abortAllJobs) {
+ emit projectModified();
+ AbstractClipJob *job = m_jobList.takeFirst();
+ // Get jobs count
+ int ct = 0;
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ for (int i = 0; i < futures.count(); i++)
+ if (futures.at(i).isRunning()) {
+ ct++;
+ }
+ emit jobCount(ct + m_jobList.count());
+
+ if (job->jobType == PROXYJOB) {
+ //ProxyJob *pjob = static_cast<ProxyJob *> (job);
+ kDebug()<<"// STARTING JOB: "<<job->destination();
+ if (m_abortProxy.contains(job->destination())) {
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ emit cancelRunningJob(job->clipId(), job->cancelProperties());
+ delete job;
+ continue;
+ }
+ }
+
+ // Get the list of clips that will need to get progress info
+ ProjectItem *processingItem = getItemById(job->clipId());
+ if (processingItem == NULL) {
+ delete job;
+ continue;
+ }
+
+ /*while (*it && !m_abortAllJobs) {
+ if ((*it)->type() == PROJECTCLIPTYPE) {
+ ProjectItem *item = static_cast <ProjectItem *>(*it);
+ if (item->referencedClip()->getProperty("proxy") == job->destination()) {
+ processingItems.append(item);
+ }
+ }
+ ++it;
+ }*/
+
+ // Make sure destination path is writable
+ QFile file(job->destination());
+ if (!file.open(QIODevice::WriteOnly)) {
+ emit jobCrashed(processingItem, i18n("Cannot write to path: %1", job->destination()));
+ m_processingProxy.removeAll(job->destination());
+ delete job;
+ continue;
+ }
+ file.close();
+ QFile::remove(job->destination());
+
+ setJobStatus(processingItem, CREATINGJOB, 0, job->jobType, job->statusMessage(CREATINGJOB));
+
+ bool success;
+ QProcess *jobProcess = job->startJob(&success);
+
+ int result = -1;
+ if (jobProcess == NULL) {
+ // job is finished
+ if (success) {
+ setJobStatus(processingItem, JOBDONE);
+ if (job->jobType == PROXYJOB) slotGotProxy(job->destination());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) emit addClip(job->destination(), QString(), QString());
+ }
+ else {
+ QFile::remove(job->destination());
+ emit jobCrashed(processingItem, job->errorMessage());
+ }
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ delete job;
+ continue;
+ }
+ else while (jobProcess->state() != QProcess::NotRunning) {
+ // building proxy file
+ if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) {
+ jobProcess->close();
+ jobProcess->waitForFinished();
+ QFile::remove(job->destination());
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ if (!m_closing) {
+ emit cancelRunningJob(job->clipId(), job->cancelProperties());
+ /*for (int i = 0; i < processingItems.count(); i++)
+ setJobStatus(processingItems.at(i), NOJOB);*/
+ }
+ else continue;
+ result = -2;
+ }
+ else {
+ int progress = job->processLogInfo();
+ if (progress > 0) emit processLog(processingItem, progress, job->jobType);
+ }
+ jobProcess->waitForFinished(500);
+ }
+ jobProcess->waitForFinished();
+ m_processingProxy.removeAll(job->destination());
+ if (result == -1) result = jobProcess->exitStatus();
+
+ if (result != -2 && QFileInfo(job->destination()).size() == 0) {
+ job->processLogInfo();
+ emit jobCrashed(processingItem, i18n("Failed to create file"), QString(), job->errorMessage());
+ result = -2;
+ }
+
+ if (result == QProcess::NormalExit) {
+ // proxy successfully created
+ setJobStatus(processingItem, JOBDONE);
+ if (job->jobType == PROXYJOB) slotGotProxy(job->destination());
+ //TODO: set folder for transcoded clips
+ else if (job->jobType == CUTJOB) {
+ CutClipJob *cutJob = static_cast<CutClipJob *>(job);
+ if (cutJob->addClipToProject) emit addClip(job->destination(), QString(), QString());
+ }
+ }
+ else if (result == QProcess::CrashExit) {
+ // Proxy process crashed
+ QFile::remove(job->destination());
+ emit jobCrashed(processingItem, i18n("Job crashed"), QString(), job->errorMessage());
+ }
+ delete job;
+ continue;
+ }
+ // Thread finished, update count
+ int ct = -1; // -1 because we don't want to count this terminating thread
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ for (int i = 0; i < futures.count(); i++)
+ if (futures.at(i).isRunning()) {
+ ct++;
+ }
+ emit jobCount(ct + m_jobList.count());
+}
+
+
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;
}
CLIPTYPE t = item->clipType();
if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
- if (useProxy()) {
+ if (generateProxy() && useProxy() && !hasPendingProxy(item)) {
DocClipBase *clip = item->referencedClip();
- connect(clip, SIGNAL(proxyReady(const QString &, bool)), this, SLOT(slotGotProxy(const QString &, bool)));
- setProxyStatus(item, 1);
- clip->generateProxy(m_doc->projectFolder(), proxyParams());
+ 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 <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->referencedClip()->getProperty("proxy").isEmpty()) {
+ else if (item->hasProxy()) {
// remove proxy
- item->referencedClip()->clearProperty("proxy");
- QDomElement e = item->toXml().cloneNode().toElement();
- e.removeAttribute("file_hash");
- e.setAttribute("replace", 1);
- m_infoQueue.insert(item->clipId(), e);
+ QMap <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()->currentProperties(newProps), 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 (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+ if (command->childCount() > 0) m_doc->commandStack()->push(command);
+ else delete command;
}
-void ProjectList::slotProxyCurrentItem(bool doProxy)
+void ProjectList::slotProcessLog(ProjectItem *item, int progress, int type)
{
- QList<QTreeWidgetItem *> list = m_listView->selectedItems();
+ setJobStatus(item, CREATINGJOB, progress, (JOBTYPE) type);
+}
+
+void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
+{
+ QList<QTreeWidgetItem *> list;
+ if (itemToProxy == NULL) list = m_listView->selectedItems();
+ else list << itemToProxy;
+
+ // expand list (folders, subclips) to get real clips
QTreeWidgetItem *listItem;
+ QList<ProjectItem *> clipList;
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 (sub->type() == PROJECTCLIPTYPE) {
+ ProjectItem *item = static_cast <ProjectItem*>(sub);
+ if (!clipList.contains(item)) clipList.append(item);
+ }
}
}
- if (listItem->type() == PROJECTCLIPTYPE) {
+ else if (listItem->type() == PROJECTSUBCLIPTYPE) {
+ QTreeWidgetItem *sub = listItem->parent();
+ ProjectItem *item = static_cast <ProjectItem*>(sub);
+ if (!clipList.contains(item)) clipList.append(item);
+ }
+ else if (listItem->type() == PROJECTCLIPTYPE) {
ProjectItem *item = static_cast <ProjectItem*>(listItem);
- CLIPTYPE t = item->clipType();
- if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip()) {
- if (doProxy) {
- DocClipBase *clip = item->referencedClip();
- connect(clip, SIGNAL(proxyReady(const QString&, bool)), this, SLOT(slotGotProxy(const QString&, bool)));
- setProxyStatus(item, 1);
- clip->generateProxy(m_doc->projectFolder(), proxyParams());
- }
- else if (!item->referencedClip()->getProperty("proxy").isEmpty()) {
- // remove proxy
- if (!item->isProxyRunning()) {
- setProxyStatus(item, 0);
- QDomElement e = item->toXml().cloneNode().toElement();
- e.removeAttribute("file_hash");
- e.setAttribute("replace", 1);
- m_infoQueue.insert(item->clipId(), e);
- }
- else setProxyStatus(item, 0);
- }
+ if (!clipList.contains(item)) clipList.append(item);
+ }
+ }
+
+ QUndoCommand *command = new QUndoCommand();
+ if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count()));
+ else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.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 < clipList.count(); i++) {
+ ProjectItem *item = clipList.at(i);
+ CLIPTYPE t = item->clipType();
+ if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) {
+ if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue;
+ DocClipBase *clip = item->referencedClip();
+ if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
+ kDebug()<<"//// TRYING TO PROXY: "<<item->clipId()<<", but it is busy";
+ continue;
+ }
+
+ //oldProps = clip->properties();
+ if (doProxy) {
+ newProps.clear();
+ QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
+ // insert required duration for proxy
+ newProps.insert("proxy_out", clip->producerProperty("out"));
+ newProps.insert("proxy", path);
+ // We need to insert empty proxy so that undo will work
+ //oldProps.insert("proxy", QString());
}
+ else if (item->referencedClip()->getProducer() == NULL) {
+ // Force clip reload
+ kDebug()<<"// CLIP HAD NULL PROD------------";
+ newProps.insert("resource", item->referencedClip()->getProperty("resource"));
+ }
+ // We need to insert empty proxy so that undo will work
+ oldProps = clip->currentProperties(newProps);
+ if (doProxy) oldProps.insert("proxy", "-");
+ new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command);
}
}
- if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+ if (command->childCount() > 0) {
+ m_doc->commandStack()->push(command);
+ }
+ else delete command;
}
-void ProjectList::setProxyStatus(ProjectItem *item, int status)
+
+void ProjectList::slotDeleteProxy(const QString proxyPath)
{
+ if (proxyPath.isEmpty()) return;
+ QUndoCommand *proxyCommand = new QUndoCommand();
+ proxyCommand->setText(i18n("Remove Proxy"));
+ QTreeWidgetItemIterator it(m_listView);
+ ProjectItem *item;
+ while (*it) {
+ if ((*it)->type() == PROJECTCLIPTYPE) {
+ item = static_cast <ProjectItem *>(*it);
+ if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+ QMap <QString, QString> props;
+ props.insert("proxy", QString());
+ new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(props), props, true, proxyCommand);
+
+ }
+ }
+ ++it;
+ }
+ if (proxyCommand->childCount() == 0)
+ delete proxyCommand;
+ else
+ m_commandStack->push(proxyCommand);
+ QFile::remove(proxyPath);
+}
+
+void ProjectList::setJobStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress, JOBTYPE jobType, const QString &statusMessage)
+{
+ if (item == NULL || m_abortAllJobs) return;
monitorItemEditing(false);
- item->setProxyStatus(status);
+ item->setJobStatus(status, progress, jobType, statusMessage);
+ if (status == JOBCRASHED) {
+ DocClipBase *clip = item->referencedClip();
+ if (!clip) {
+ kDebug()<<"// PROXY CRASHED";
+ }
+ else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) {
+ // disable proxy and fetch real clip
+ clip->setProperty("proxy", "-");
+ QDomElement xml = clip->toXML();
+ m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true);
+ }
+ else {
+ // Disable proxy for this clip
+ clip->setProperty("proxy", "-");
+ }
+ }
monitorItemEditing(true);
}
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;
+}
+
+void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
+{
+ if (item->hasProxy()) {
+ QPainter p(&pix);
+ QColor c = QPalette().base().color();
+ c.setAlpha(160);
+ QBrush br(c);
+ p.setBrush(br);
+ p.setPen(Qt::NoPen);
+ QRect r(1, 1, 10, 10);
+ p.drawRect(r);
+ p.setPen(QPalette().text().color());
+ p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
+ }
+}
+
+void ProjectList::slotCancelJobs()
+{
+ m_abortAllJobs = true;
+ m_proxyThreads.waitForFinished();
+ m_proxyThreads.clearFutures();
+ QUndoCommand *command = new QUndoCommand();
+ command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
+ for (int i = 0; i < m_jobList.count(); i++) {
+ ProjectItem *item = getItemById(m_jobList.at(i)->clipId());
+ if (!item || !item->referencedClip()) continue;
+ QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
+ if (newProps.isEmpty()) continue;
+ QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
+ new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
+ }
+ if (command->childCount() > 0) {
+ m_doc->commandStack()->push(command);
+ }
+ else delete command;
+ if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
+ m_processingProxy.clear();
+ m_jobList.clear();
+ m_abortAllJobs = false;
+ m_infoLabel->slotSetJobCount(0);
+}
+
+void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
+{
+ if (newProps.isEmpty()) return;
+ ProjectItem *item = getItemById(id);
+ if (!item || !item->referencedClip()) return;
+ QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
+ if (newProps == oldProps) return;
+ QMapIterator<QString, QString> i(oldProps);
+ EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
+ m_commandStack->push(command);
+}
+
+bool ProjectList::hasPendingProxy(ProjectItem *item)
+{
+ if (!item || !item->referencedClip() || m_abortAllJobs) return false;
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_abortAllJobs) break;
+ if (m_jobList.at(i)->clipId() == item->clipId() && m_jobList.at(i)->jobType == PROXYJOB) return true;
+ }
+ if (item->isProxyRunning()) return true;
+ return false;
+}
+
+void ProjectList::deleteJobsForClip(const QString &clipId)
+{
+ QList <AbstractClipJob *> jobsToDelete;
+ for (int i = 0; i < m_jobList.count(); i++) {
+ if (m_abortAllJobs) break;
+ if (m_jobList.at(i)->clipId() == clipId) {
+ AbstractClipJob *job = m_jobList.takeAt(i);
+ delete job;
+ i--;
+ }
+ }
+}
+
+void ProjectList::slotJobCrashed(ProjectItem *item, const QString &label, const QString &actionName, const QString details)
+{
+#if KDE_IS_VERSION(4,7,0)
+ m_infoMessage->animatedHide();
+ item->setJobStatus(NOJOB);
+ m_errorLog.clear();
+ m_infoMessage->setText(label);
+ m_infoMessage->setWordWrap(label.length() > 35);
+ m_infoMessage->setMessageType(KMessageWidget::Warning);
+ QList<QAction *> actions = m_infoMessage->actions();
+ for (int i = 0; i < actions.count(); i++) {
+ m_infoMessage->removeAction(actions.at(i));
+ }
+
+ if (!actionName.isEmpty()) {
+ QAction *action;
+ QList< KActionCollection * > collections = KActionCollection::allCollections();
+ for (int i = 0; i < collections.count(); i++) {
+ KActionCollection *coll = collections.at(i);
+ action = coll->action(actionName);
+ if (action) break;
+ }
+ if (action) m_infoMessage->addAction(action);
+ }
+ if (!details.isEmpty()) {
+ m_errorLog = details;
+ m_infoMessage->addAction(m_logAction);
+ }
+ m_infoMessage->animatedShow();
+#else
+ item->setJobStatus(JOBCRASHED);
+#endif
+}
+
+void ProjectList::slotShowJobLog()
+{
+#if KDE_IS_VERSION(4,7,0)
+ KDialog d(this);
+ d.setButtons(KDialog::Close);
+ QTextEdit t(&d);
+ t.setPlainText(m_errorLog);
+ t.setReadOnly(true);
+ d.setMainWidget(&t);
+ d.exec();
+#endif
+}
+
#include "projectlist.moc"