Auto-generate proxy clips if they match criteria, correctly en/disable...

Auto-generate proxy clips if they match criteria, correctly en/disable depending on project settings
CCBUG: 357207
parent 196e0c94
......@@ -869,7 +869,7 @@ void Bin::setDocument(KdenliveDoc* project)
m_jobManager = new JobManager(this);
m_rootFolder = new ProjectFolder(this);
setEnabled(true);
connect(this, SIGNAL(producerReady(QString)), m_doc->renderer(), SLOT(slotProcessingDone(QString)), Qt::UniqueConnection);
connect(this, SIGNAL(producerReady(QString)), m_doc->renderer(), SLOT(slotProcessingDone(QString)), Qt::DirectConnection);
connect(m_jobManager, SIGNAL(addClip(QString)), this, SLOT(slotAddUrl(QString)));
connect(m_proxyAction, SIGNAL(toggled(bool)), m_doc, SLOT(slotProxyCurrentItem(bool)));
connect(m_jobManager, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
......@@ -1674,12 +1674,26 @@ void Bin::slotProducerReady(requestClipInfo info, ClipController *controller)
ProjectClip *clip = m_rootFolder->clip(info.clipId);
if (clip) {
if (clip->setProducer(controller, info.replaceProducer) && !clip->hasProxy()) {
emit producerReady(info.clipId);
// Check for file modifications
ClipType t = clip->clipType();
if (t == AV || t == Audio || t == Image || t == Video || t == Playlist) {
m_doc->watchFile(clip->url());
}
}
if (m_doc->useProxy()) {
if (t == AV || t == Video || t == Playlist) {
int width = clip->getProducerIntProperty(QStringLiteral("meta.media.width"));
if (m_doc->autoGenerateProxy(width)) {
// Start proxy
m_doc->slotProxyCurrentItem(true, QList <ProjectClip *>() << clip);
}
}
else if (t == Image && m_doc->autoGenerateImageProxy(clip->getProducerIntProperty(QStringLiteral("meta.media.width")))) {
// Start proxy
m_doc->slotProxyCurrentItem(true, QList <ProjectClip *>() << clip);
}
}
} else emit producerReady(info.clipId);
QString currentClip = m_monitor->activeClipId();
if (currentClip.isEmpty()) {
//No clip displayed in monitor, check if item is selected
......@@ -1717,13 +1731,13 @@ void Bin::slotProducerReady(requestClipInfo info, ClipController *controller)
else parentFolder = m_rootFolder;
//FIXME(style): constructor actually adds the new pointer to parent's children
ProjectClip *clip = new ProjectClip(info.clipId, m_blankThumb, controller, parentFolder);
emit producerReady(info.clipId);
ClipType t = clip->clipType();
if (t == AV || t == Audio || t == Image || t == Video || t == Playlist) {
m_doc->watchFile(clip->url());
}
if (info.clipId.toInt() >= m_clipCounter) m_clipCounter = info.clipId.toInt() + 1;
}
emit producerReady(info.clipId);
}
void Bin::slotOpenCurrent()
......@@ -2952,3 +2966,31 @@ void Bin::slotRenameFolder()
}
}
}
void Bin::refreshProxySettings()
{
QList <ProjectClip*> clipList = m_rootFolder->childClips();
if (!m_doc->useProxy()) {
// Disable all proxies
m_doc->slotProxyCurrentItem(false, clipList);
} else {
QList <ProjectClip*> toProxy;
foreach (ProjectClip *clp, clipList) {
ClipType t = clp->clipType();
if (t == AV || t == Video || t == Playlist) {
int width = clp->getProducerIntProperty(QStringLiteral("meta.media.width"));
if (m_doc->autoGenerateProxy(width)) {
// Start proxy
toProxy << clp;
continue;
}
else if (t == Image && m_doc->autoGenerateImageProxy(clp->getProducerIntProperty(QStringLiteral("meta.media.width")))) {
// Start proxy
toProxy << clp;
continue;
}
}
}
if (!toProxy.isEmpty()) m_doc->slotProxyCurrentItem(true, toProxy);
}
}
......@@ -463,6 +463,8 @@ public:
void setBinEffectsDisabledStatus(bool disabled);
void requestAudioThumbs(const QString &id);
/** @brief Proxy status for the project changed, update. */
void refreshProxySettings();
private slots:
void slotAddClip();
......
......@@ -69,6 +69,21 @@ ProjectClip* ProjectFolder::clip(const QString &id)
return NULL;
}
QList <ProjectClip *> ProjectFolder::childClips()
{
QList <ProjectClip *> allChildren;
for (int i = 0; i < count(); ++i) {
AbstractProjectItem *child = at(i);
if (child->itemType() == ClipItem) {
allChildren << (ProjectClip *) child;
}
else if (child->itemType() == FolderItem) {
allChildren << ((ProjectFolder *) child)->childClips();
}
}
return allChildren;
}
QString ProjectFolder::getToolTip() const
{
return QString(i18np("%1 clip", "%1 clips", size()));
......
......@@ -82,6 +82,8 @@ public:
QDomElement toXml(QDomDocument &document);
virtual QString getToolTip() const;
virtual bool rename(const QString &name, int column);
/** @brief Returns a list of all children and sub-children clips. */
QList <ProjectClip *> childClips();
private:
Bin *m_bin;
......
......@@ -533,6 +533,15 @@ bool KdenliveDoc::useProxy() const
return m_documentProperties.value("enableproxy").toInt();
}
bool KdenliveDoc::autoGenerateProxy(int width) const
{
return m_documentProperties.value(QStringLiteral("generateproxy")).toInt() && width > m_documentProperties.value(QStringLiteral("proxyminsize")).toInt();
}
bool KdenliveDoc::autoGenerateImageProxy(int width) const
{
return m_documentProperties.value(QStringLiteral("generateimageproxy")).toInt() && width > m_documentProperties.value(QStringLiteral("proxyimageminsize")).toInt();
}
void KdenliveDoc::slotAutoSave()
{
......@@ -1393,9 +1402,9 @@ void KdenliveDoc::setMetadata(const QMap<QString, QString> &meta)
m_documentMetadata = meta;
}
void KdenliveDoc::slotProxyCurrentItem(bool doProxy)
void KdenliveDoc::slotProxyCurrentItem(bool doProxy, QList<ProjectClip *> clipList)
{
QList<ProjectClip *> clipList = pCore->bin()->selectedClips();
if (clipList.isEmpty()) clipList = pCore->bin()->selectedClips();
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()));
......@@ -1414,7 +1423,6 @@ void KdenliveDoc::slotProxyCurrentItem(bool doProxy)
for (int i = 0; i < clipList.count(); ++i) {
ProjectClip *item = clipList.at(i);
ClipType t = item->clipType();
// Only allow proxy on some clip types
if ((t == Video || t == AV || t == Unknown || t == Image || t == Playlist) && item->isReady()) {
if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && pCore->binController()->hasClip(item->clipId()))) continue;
......
......@@ -150,6 +150,8 @@ public:
/** @brief Get all document properties that need to be saved */
const QMap <QString, QString> documentProperties();
bool useProxy() const;
bool autoGenerateProxy(int width) const;
bool autoGenerateImageProxy(int width) const;
QString documentNotes() const;
/** @brief Saves effects embedded in project file. */
void saveCustomEffects(const QDomNodeList &customeffects);
......@@ -206,7 +208,7 @@ public slots:
* Emits docModified conected to MainWindow::slotUpdateDocumentState \n
* @param mod (optional) true if the document has to be saved */
void setModified(bool mod = true);
void slotProxyCurrentItem(bool doProxy);
void slotProxyCurrentItem(bool doProxy, QList<ProjectClip *> clipList = QList<ProjectClip *>());
/** @brief Saves the current project at the autosave location.
* @description The autosave files are in ~/.kde/data/stalefiles/kdenlive/ */
void slotAutoSave();
......
......@@ -3189,8 +3189,7 @@ void MainWindow::slotUpdateProxySettings()
QDir dir(pCore->projectManager()->current()->projectFolder().path());
dir.mkdir("proxy");
}
//TODO
//m_projectList->updateProxyConfig();
pCore->bin()->refreshProxySettings();
}
void MainWindow::slotArchiveProject()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment