#include <KLocale>
#include <KFileDialog>
#include <KIO/NetAccess>
+#include <KIO/CopyJob>
#include <KApplication>
QDomNode westley = m_document.elementsByTagName("westley").at(0);
if (!infoXmlNode.isNull()) {
QDomElement infoXml = infoXmlNode.toElement();
+ double version = infoXml.attribute("version").toDouble();
+
+ // Upgrade old Kdenlive documents to current version
+ convertDocument(version);
+ /*
+ * read again <kdenlivedoc> and <westley> to get all the new
+ * stuff (convertDocument() can now do anything without breaking
+ * document loading)
+ */
+ infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
+ infoXml = infoXmlNode.toElement();
+ version = infoXml.attribute("version").toDouble();
+ westley = m_document.elementsByTagName("westley").at(0);
+
QString profilePath = infoXml.attribute("profile");
+ QString projectFolderPath = infoXml.attribute("projectfolder");
+ if (!projectFolderPath.isEmpty()) m_projectFolder = KUrl(projectFolderPath);
+ if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
m_startPos = infoXml.attribute("position").toInt();
m_zoom = infoXml.attribute("zoom", "7").toInt();
setProfilePath(profilePath);
- double version = infoXml.attribute("version").toDouble();
- if (version < 0.8) convertDocument(version);
- else {
- //delete all mlt producers and instead, use Kdenlive saved producers
- /*QDomNodeList prods = m_document.elementsByTagName("producer");
- int maxprod = prods.count();
- int pos = 0;
- for (int i = 0; i < maxprod; i++) {
- QDomNode m = prods.at(pos);
- QString prodId = m.toElement().attribute("id");
- if (prodId == "black" || prodId.startsWith("slowmotion"))
- pos++;
- else westley.removeChild(m);
- }*/
- /*prods = m_document.elementsByTagName("kdenlive_producer");
- maxprod = prods.count();
- for (int i = 0; i < maxprod; i++) {
- prods.at(0).toElement().setTagName("producer");
- westley.insertBefore(prods.at(0), QDomNode());
- }*/
+
+ // Build tracks
+ QString tracks = infoXml.attribute("tracks");
+ TrackInfo videoTrack;
+ videoTrack.type = VIDEOTRACK;
+ videoTrack.isMute = false;
+ videoTrack.isBlind = false;
+
+ TrackInfo audioTrack;
+ audioTrack.type = AUDIOTRACK;
+ audioTrack.isMute = false;
+ audioTrack.isBlind = true;
+ for (int i = 0; i < tracks.size(); i++) {
+ if (tracks.data()[i] == 'v') m_tracksList.append(videoTrack);
+ else m_tracksList.append(audioTrack);
}
+
+
QDomElement e;
QDomNodeList producers = m_document.elementsByTagName("producer");
QDomNodeList infoproducers = m_document.elementsByTagName("kdenlive_producer");
m_document = createEmptyDocument(tracks.x(), tracks.y());
setProfilePath(profileName);
}
+ if (m_projectFolder.isEmpty()) m_projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
+
+ // make sure that the necessary folders exist
+ KStandardDirs::makeDir(m_projectFolder.path() + "/titles/");
+ KStandardDirs::makeDir(m_projectFolder.path() + "/thumbs/");
+
m_scenelist = m_document.toString();
kDebug() << "KDEnnlive document, init timecode: " << m_fps;
if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
else m_timecode.setFormat((int) m_fps);
-
connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
}
QDomElement westley = doc.createElement("westley");
doc.appendChild(westley);
+
+ TrackInfo videoTrack;
+ videoTrack.type = VIDEOTRACK;
+ videoTrack.isMute = false;
+ videoTrack.isBlind = false;
+
+ TrackInfo audioTrack;
+ audioTrack.type = AUDIOTRACK;
+ audioTrack.isMute = false;
+ audioTrack.isBlind = true;
+
QDomElement tractor = doc.createElement("tractor");
tractor.setAttribute("id", "maintractor");
QDomElement multitrack = doc.createElement("multitrack");
track.setAttribute("producer", "playlist" + QString::number(i));
track.setAttribute("hide", "video");
tractor.appendChild(track);
+ m_tracksList.append(audioTrack);
}
// create video tracks
QDomElement track = doc.createElement("track");
track.setAttribute("producer", "playlist" + QString::number(i));
tractor.appendChild(track);
+ m_tracksList.append(videoTrack);
}
for (uint i = 2; i < total ; i++) {
void KdenliveDoc::convertDocument(double version) {
kDebug() << "Opening a document with version " << version;
+ if (version == 0.8) {
+ // Add the tracks information
+ QString tracksOrder;
+ QDomNodeList tracks = m_document.elementsByTagName("track");
+ int max = tracks.count();
+ for (int i = 0; i < max; i++) {
+ QDomElement t = tracks.at(i).toElement();
+ if (t.attribute("hide") == "video") tracksOrder.append('a');
+ else tracksOrder.append('v');
+ }
+ QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
+ QDomElement infoXml = kdenlivedoc.toElement();
+ QString currentTrackOrder = infoXml.attribute("tracks");
+ if (currentTrackOrder.isEmpty()) infoXml.setAttribute("tracks", tracksOrder);
+
+ return;
+ }
+
// Opening a old Kdenlive document
if (version == 0.7) {
kDebug() << "Unable to open document with version " << version;
// TODO: convert 0.7 files to the new document format.
return;
}
+
+ QString tracksOrder;
QDomNode westley = m_document.elementsByTagName("westley").at(1);
QDomNode tractor = m_document.elementsByTagName("tractor").at(0);
QDomNode kdenlivedoc = m_document.elementsByTagName("kdenlivedoc").at(0);
QString profile = props.toElement().attribute("videoprofile");
m_startPos = props.toElement().attribute("timeline_position").toInt();
if (profile == "dv_wide") profile = "dv_pal_wide";
- setProfilePath(profile);
+ //setProfilePath(profile);
// move playlists outside of tractor and add the tracks instead
int max = playlists.count();
QDomElement pl = n.toElement();
QDomElement track = m_document.createElement("track");
QString trackType = pl.attribute("hide");
- if (!trackType.isEmpty()) track.setAttribute("hide", trackType);
+ if (!trackType.isEmpty()) {
+ track.setAttribute("hide", trackType);
+ if (trackType == "video") tracksOrder.append('a');
+ else tracksOrder.append('v');
+ } else tracksOrder.append('v');
QString playlist_id = pl.attribute("id");
if (playlist_id.isEmpty()) {
playlist_id = "black_track";
westley0.removeChild(kdenlivedoc);
QDomElement kdenlivedoc_new = m_document.createElement("kdenlivedoc");
kdenlivedoc_new.setAttribute("profile", profile);
+ kdenlivedoc_new.setAttribute("tracks", tracksOrder);
// Add all the producers that has a ressource in westley
QDomElement westley_element = westley0.toElement();
if (westley_element.isNull()) {
addedXml.setAttribute("version", "0.8");
addedXml.setAttribute("profile", profilePath());
addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
+ addedXml.setAttribute("projectfolder", m_projectFolder.path());
addedXml.setAttribute("tracks", getTracksInfo());
addedXml.setAttribute("zoom", m_zoom);
}
KUrl KdenliveDoc::projectFolder() const {
- if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
+ //if (m_projectFolder.isEmpty()) return KUrl(KStandardDirs::locateLocal("appdata", "/projects/"));
return m_projectFolder;
}
+void KdenliveDoc::setProjectFolder(KUrl url) {
+ if (url == m_projectFolder) return;
+ setModified(true);
+ KStandardDirs::makeDir(url.path());
+ KStandardDirs::makeDir(url.path() + "/titles/");
+ KStandardDirs::makeDir(url.path() + "/thumbs/");
+ if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("You have changed the project folder. Do you want to copy the cached data from %1 to the new folder %2 ?").arg(m_projectFolder.path(), url.path())) == KMessageBox::Yes) moveProjectData(url);
+ m_projectFolder = url;
+}
+
+void KdenliveDoc::moveProjectData(KUrl url) {
+ QList <DocClipBase*> list = m_clipManager->documentClipList();
+ for (int i = 0; i < list.count(); i++) {
+ DocClipBase *clip = list.at(i);
+ if (clip->clipType() == TEXT) {
+ // the image for title clip must be moved
+ KUrl oldUrl = clip->fileURL();
+ KUrl newUrl = KUrl(url.path() + "/titles/" + oldUrl.fileName());
+ KIO::Job *job = KIO::copy(oldUrl, newUrl);
+ if (KIO::NetAccess::synchronousRun(job, 0)) clip->setProperty("resource", newUrl.path());
+ }
+ QString hash = clip->getClipHash();
+ KUrl oldVideoThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".png");
+ KUrl oldAudioThumbUrl = KUrl(m_projectFolder.path() + "/thumbs/" + hash + ".thumb");
+ if (KIO::NetAccess::exists(oldVideoThumbUrl, KIO::NetAccess::SourceSide, 0)) {
+ KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".png");
+ KIO::Job *job = KIO::copy(oldVideoThumbUrl, newUrl);
+ KIO::NetAccess::synchronousRun(job, 0);
+ }
+ if (KIO::NetAccess::exists(oldAudioThumbUrl, KIO::NetAccess::SourceSide, 0)) {
+ KUrl newUrl = KUrl(url.path() + "/thumbs/" + hash + ".thumb");
+ KIO::Job *job = KIO::copy(oldAudioThumbUrl, newUrl);
+ if (KIO::NetAccess::synchronousRun(job, 0)) clip->refreshThumbUrl();
+ }
+ }
+}
+
QString KdenliveDoc::profilePath() const {
return m_profile.path;
}
//qApp->processEvents();
if (m_render) {
m_render->setSceneList(m_document.toString(), m_startPos);
+ kDebug() << "// SETTING SCENE LIST:\n\n" << m_document.toString();
checkProjectClips();
}
emit progressInfo(QString(), -1);
id = prods.at(i)->get("id");
prodId = id.section('_', 0, 0);
prodTrack = id.section('_', 1, 1);
- kDebug() << "CHECK PRO CLIP, ID: " << id;
DocClipBase *clip = m_clipManager->getClipById(prodId);
if (clip) clip->setProducer(prods.at(i));
- kDebug() << "CHECK PRO CLIP, ID: " << id << " DONE";
if (clip && clip->clipType() == TEXT && !QFile::exists(clip->fileURL().path())) {
// regenerate text clip image if required
kDebug() << "// TITLE: " << clip->getProperty("titlename") << " Preview file: " << clip->getProperty("resource") << " DOES NOT EXIST";
kDebug() << attrname << " = " << attributes.item(i).nodeValue();
}
clip->setProperties(properties);
- emit addProjectClip(clip);
+ emit addProjectClip(clip, false);
}
}
return m_tracksList.at(ix);
}
+void KdenliveDoc::switchTrackAudio(int ix, bool hide) {
+ m_tracksList[ix].isMute = hide; // !m_tracksList.at(ix).isMute;
+}
+
+void KdenliveDoc::switchTrackVideo(int ix, bool hide) {
+ m_tracksList[ix].isBlind = hide; // !m_tracksList.at(ix).isBlind;
+}
+
void KdenliveDoc::insertTrack(int ix, TrackInfo type) {
if (ix == -1) m_tracksList << type;
else m_tracksList.insert(ix, type);
m_tracksList.removeAt(ix);
}
+void KdenliveDoc::setTrackType(int ix, TrackInfo type) {
+ m_tracksList[ix].type = type.type;
+ m_tracksList[ix].isMute = type.isMute;
+ m_tracksList[ix].isBlind = type.isBlind;
+}
+
const QList <TrackInfo> KdenliveDoc::tracksList() const {
return m_tracksList;
}
return result;
}
+void KdenliveDoc::cachePixmap(const QString &fileId, const QPixmap &pix) const {
+ pix.save(m_projectFolder.path() + "/thumbs/" + fileId + ".png");
+}
+
#include "kdenlivedoc.moc"