]> git.sesse.net Git - kdenlive/blobdiff - src/trackview.cpp
Fix broken producer incorrectly handled when using proxy, corrupting project:
[kdenlive] / src / trackview.cpp
index badcd4dc7283220a8114ab5f3c586d87625d6e62..31de534abcdc6209c72f20bfb4344ec20083a628 100644 (file)
@@ -271,7 +271,7 @@ void TrackView::parseDocument(QDomDocument doc)
                 m_doc->switchTrackAudio(i - 1, true);
             }
 
-            trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1));
+            trackduration = slotAddProjectTrack(pos, p, m_doc->isTrackLocked(i - 1), producers);
             pos--;
             //kDebug() << " PRO DUR: " << trackduration << ", TRACK DUR: " << duration;
             if (trackduration > duration) duration = trackduration;
@@ -384,7 +384,7 @@ void TrackView::parseDocument(QDomDocument doc)
                                         QString factor = e.attribute("factor", "1");
                                         if (factor != "1") {
                                             double fact;
-                                            if (factor.startsWith('%')) {
+                                            if (factor.contains('%')) {
                                                 fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
                                             } else fact = factor.toDouble();
                                             double val = paramValue.toDouble() * fact;
@@ -452,7 +452,7 @@ void TrackView::parseDocument(QDomDocument doc)
 
     slotRebuildTrackHeaders();
     if (!m_documentErrors.isNull()) KMessageBox::sorry(this, m_documentErrors);
-    if (infoXml.hasAttribute("upgraded")) {
+    if (infoXml.hasAttribute("upgraded") || infoXml.hasAttribute("modified")) {
         // Our document was upgraded, create a backup copy just in case
         QString baseFile = m_doc->url().path().section(".kdenlive", 0, 0);
         int ct = 0;
@@ -461,8 +461,13 @@ void TrackView::parseDocument(QDomDocument doc)
             ct++;
             backupFile = baseFile + "_backup" + QString::number(ct) + ".kdenlive";
         }
+        QString message;
+        if (infoXml.hasAttribute("upgraded"))
+            message = i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
+        else
+            message = i18n("Your project file was modified by Kdenlive.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile);
         if (KIO::NetAccess::file_copy(m_doc->url(), KUrl(backupFile), this))
-            KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version.\nTo make sure you don't lose data, a backup copy called %1 was created.", backupFile));
+            KMessageBox::information(this, message);
         else
             KMessageBox::information(this, i18n("Your project file was upgraded to the latest Kdenlive document version, but it was not possible to create a backup copy.", backupFile));
     }
@@ -586,7 +591,7 @@ void TrackView::adjustTrackHeaders()
     }
 }
 
-int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
+int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked, QDomNodeList producers)
 {
     // parse track
     int position = 0;
@@ -630,18 +635,37 @@ int TrackView::slotAddProjectTrack(int ix, QDomElement xml, bool locked)
                     QDomDocument doc;
                     QDomElement producerXml = doc.createElement("producer");
                     doc.appendChild(producerXml);
-                    producerXml.setAttribute("colour", "0xff0000ff");
-                    producerXml.setAttribute("mlt_service", "colour");
-                    producerXml.setAttribute("length", "15000");
-                    producerXml.setAttribute("name", "INVALID");
-                    producerXml.setAttribute("type", COLOR);
-                    producerXml.setAttribute("id", id);
-                    clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
-                    xml.insertBefore(producerXml, QDomNode());
-                    nodeindex++;
-                    m_doc->clipManager()->addClip(clip);
-
-                    m_documentErrors.append(i18n("Broken clip producer %1", id) + '\n');
+                    bool foundMltProd = false;
+                    for (int i = 0; i < producers.count(); i++) {
+                        QDomElement prod = producers.at(i).toElement();
+                        if (prod.attribute("id") == id) {
+                            QString service = EffectsList::property(prod, "mlt_service");
+                            QString type = EffectsList::property(prod, "mlt_type");
+                            QString resource = EffectsList::property(prod, "resource");
+                            QString length = EffectsList::property(prod, "length");
+                            producerXml.setAttribute("mlt_service", service);
+                            producerXml.setAttribute("mlt_type", type);
+                            producerXml.setAttribute("resource", resource);
+                            producerXml.setAttribute("duration", length);
+                            if (service == "colour") producerXml.setAttribute("type", COLOR);
+                            else if (service == "qimage" || service == "pixbuf") producerXml.setAttribute("type", IMAGE);
+                            else if (service == "kdenlivetitle") producerXml.setAttribute("type", TEXT);
+                            else producerXml.setAttribute("type", AV);
+                            clip = new DocClipBase(m_doc->clipManager(), doc.documentElement(), id);
+                            m_doc->clipManager()->addClip(clip);
+                            m_documentErrors.append(i18n("Broken clip producer %1, recreated base clip: %2", id, resource) + '\n');
+                            foundMltProd = true;
+                            break;
+                        }
+                    }
+                    if (!foundMltProd) {
+                        // Cannot recover, replace with blank
+                        int duration = elem.attribute("out").toInt() - elem.attribute("in").toInt();
+                        elem.setAttribute("length", duration);
+                        elem.setTagName("blank");
+                        m_documentErrors.append(i18n("Broken clip producer %1, removed from project", id) + '\n');
+                    }
+
                 } else {
                     // Found correct producer
                     m_documentErrors.append(i18n("Replaced wrong clip producer %1 with %2", id, clip->getId()) + '\n');
@@ -764,7 +788,7 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                 double endvalue = 0;
                 double fact;
                 if (factor.isEmpty()) fact = 1;
-                else if (factor.startsWith('%')) {
+                else if (factor.contains('%')) {
                     fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
                 } else fact = factor.toDouble();
                 for (QDomNode n3 = effect.firstChild(); !n3.isNull(); n3 = n3.nextSibling()) {
@@ -839,14 +863,15 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                 for (int k = 0; k < clipeffectparams.count(); k++) {
                     e = clipeffectparams.item(k).toElement();
                     if (!e.isNull() && e.tagName() == "parameter" && e.attribute("name") == paramname) {
+                        QString type = e.attribute("type");
                         QString factor = e.attribute("factor", "1");
                         double fact;
-                        if (factor.startsWith('%')) {
+                        if (factor.contains('%')) {
                             fact = ProfilesDialog::getStringEval(m_doc->mltProfile(), factor);
                         } else {
                             fact = factor.toDouble();
                         }
-                        if (e.attribute("type") == "simplekeyframe") {
+                        if (type == "simplekeyframe") {
                             QStringList kfrs = paramvalue.split(";");
                             for (int l = 0; l < kfrs.count(); l++) {
                                 QString fr = kfrs.at(l).section('=', 0, 0);
@@ -854,11 +879,13 @@ void TrackView::slotAddProjectEffects(QDomNodeList effects, QDomElement parentNo
                                 kfrs[l] = fr + ":" + QString::number((int)(val * fact));
                             }
                             e.setAttribute("keyframes", kfrs.join(";"));
-                        } else {
+                        } else if (type == "double" || type == "constant") {
                             bool ok;
                             e.setAttribute("value", paramvalue.toDouble(&ok) * fact);
                             if (!ok)
                                 e.setAttribute("value", paramvalue);
+                        } else {
+                            e.setAttribute("value", paramvalue);
                         }
                         break;
                     }
@@ -1026,4 +1053,19 @@ void TrackView::slotUpdateTrackEffectState(int ix)
     widgets.at(m_doc->tracksCount() - ix - 1)->updateEffectLabel(m_doc->trackInfoAt(ix).effectsList.effectNames());
 }
 
+void TrackView::slotSaveTimelinePreview(const QString path)
+{
+    QImage img(width(), height(), QImage::Format_ARGB32_Premultiplied);
+    img.fill(palette().base().color().rgb());
+    QPainter painter(&img);
+    render(&painter);
+    painter.end();
+    img = img.scaledToWidth(600, Qt::SmoothTransformation);
+    img.save(path);
+}
+
+
 #include "trackview.moc"
+
+
+