#include "titlewidget.h"
#include "mainwindow.h"
-KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0) {
+
+KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new KUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(4) {
kDebug() << "// init profile, ratnum: " << profile.frame_rate_num << ", " << profile.frame_rate_num << ", width: " << profile.width;
m_clipManager = new ClipManager(this);
+ KdenliveSettings::setProject_fps(m_fps);
if (!url.isEmpty()) {
QString tmpFile;
if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
QDomElement infoXml = infoXmlNode.toElement();
QString profilePath = infoXml.attribute("profile");
m_startPos = infoXml.attribute("position").toInt();
+ m_zoom = infoXml.attribute("zoom").toInt();
if (!profilePath.isEmpty()) setProfilePath(profilePath);
double version = infoXml.attribute("version").toDouble();
if (version < 0.7) convertDocument(version);
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);
+
+ m_autoSaveTimer = new QTimer(this);
+ m_autoSaveTimer->setSingleShot(true);
+ QString directory = m_url.directory();
+ QString fileName = m_url.fileName();
+ m_recoveryUrl.setDirectory(directory);
+ m_recoveryUrl.setFileName("~" + fileName);
+ connect(m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
}
KdenliveDoc::~KdenliveDoc() {
delete m_commandStack;
delete m_clipManager;
+ delete m_autoSaveTimer;
+ if (!m_url.isEmpty()) {
+ // remove backup file
+ if (KIO::NetAccess::exists(m_recoveryUrl, KIO::NetAccess::SourceSide, NULL))
+ KIO::NetAccess::del(m_recoveryUrl, NULL);
+ }
+}
+
+void KdenliveDoc::syncGuides(QList <Guide *> guides) {
+ QDomDocument doc;
+ QDomElement e;
+ m_guidesXml.clear();
+ m_guidesXml = doc.createElement("guides");
+ for (int i = 0; i < guides.count(); i++) {
+ e = doc.createElement("guide");
+ e.setAttribute("time", guides.at(i)->position().ms() / 1000);
+ e.setAttribute("comment", guides.at(i)->label());
+ m_guidesXml.appendChild(e);
+ }
+}
+
+void KdenliveDoc::slotAutoSave() {
+ if (m_render)
+ m_render->saveSceneList(m_recoveryUrl.path(), documentInfoXml());
+
+}
+
+void KdenliveDoc::setZoom(int factor) {
+ m_zoom = factor;
+}
+
+int KdenliveDoc::zoom() const {
+ return m_zoom;
}
void KdenliveDoc::convertDocument(double version) {
//kDebug() << "///////////////// END CONVERTEDĀ DOC:";
}
-QDomElement KdenliveDoc::documentInfoXml(QDomElement timelineInfo) {
+QDomElement KdenliveDoc::documentInfoXml() {
QDomDocument doc;
QDomElement e;
QDomElement addedXml = doc.createElement("kdenlivedoc");
addedXml.setAttribute("version", "0.7");
addedXml.setAttribute("profile", profilePath());
addedXml.setAttribute("position", m_render->seekPosition().frames(m_fps));
+ addedXml.setAttribute("zoom", m_zoom);
QList <DocClipBase*> list = m_clipManager->documentClipList();
for (int i = 0; i < list.count(); i++) {
e = list.at(i)->toXML();
}
}
addedXml.appendChild(markers);
- addedXml.appendChild(doc.importNode(timelineInfo, true));
+ if (!m_guidesXml.isNull()) addedXml.appendChild(doc.importNode(m_guidesXml, true));
//kDebug() << m_document.toString();
return addedXml;
}
m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
m_width = m_profile.width;
m_height = m_profile.height;
+ KdenliveSettings::setProject_fps(m_fps);
kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps;
if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
else m_timecode.setFormat((int) m_fps);
emit updateClipDisplay(id);
}
+void KdenliveDoc::updateAllProjectClips() {
+ QList <DocClipBase*> list = m_clipManager->documentClipList();
+ for (int i = 0; i < list.count(); i++)
+ emit updateClipDisplay(list.at(i)->getId());
+}
+
int KdenliveDoc::getFramePos(QString duration) {
return m_timecode.getFrameCount(duration, m_fps);
}
void KdenliveDoc::setUrl(KUrl url) {
m_url = url;
+ QString directory = m_url.directory();
+ QString fileName = m_url.fileName();
+ m_recoveryUrl.setDirectory(directory);
+ m_recoveryUrl.setFileName("~" + fileName);
}
void KdenliveDoc::setModified(bool mod) {
+ if (!m_url.isEmpty() && mod && KdenliveSettings::crashrecovery()) {
+ m_autoSaveTimer->start(3000);
+ }
if (mod == m_modified) return;
m_modified = mod;
emit docModified(m_modified);
setModified(true);
}
-void KdenliveDoc::slotAddTextClipFile(const QString path, const QString group, const int groupId) {
+void KdenliveDoc::slotAddTextClipFile(const QString path, const QString xml, const QString group, const int groupId) {
kDebug() << "///////// DOCUM, ADD TXT CLP: " << path;
- m_clipManager->slotAddTextClipFile(path, group, groupId);
+ m_clipManager->slotAddTextClipFile(path, xml, group, groupId);
setModified(true);
}
}
QPixmap pix = dia_ui->renderedPixmap();
pix.save(path + ".png");
- dia_ui->saveTitle(path + ".kdenlivetitle");
- slotAddTextClipFile(path, QString(), -1);
+ //dia_ui->saveTitle(path + ".kdenlivetitle");
+ slotAddTextClipFile(path, dia_ui->xml().toString(), QString(), -1);
}
delete dia_ui;
}
void KdenliveDoc::editTextClip(QString path, int id) {
- TitleWidget *dia_ui = new TitleWidget(KUrl(path + ".kdenlivetitle"), path, m_render, kapp->activeWindow());
+ DocClipBase *clip = m_clipManager->getClipById(id);
+ if (!clip) return;
+ TitleWidget *dia_ui = new TitleWidget(KUrl()/*path + ".kdenlivetitle")*/, path, m_render, kapp->activeWindow());
+ QDomDocument doc;
+ doc.setContent(clip->getProperty("xmldata"));
+ dia_ui->setXml(doc);
if (dia_ui->exec() == QDialog::Accepted) {
QPixmap pix = dia_ui->renderedPixmap();
pix.save(path + ".png");
- dia_ui->saveTitle(path + ".kdenlivetitle");
+ //dia_ui->saveTitle(path + ".kdenlivetitle");
//slotAddClipFile(KUrl("/tmp/kdenlivetitle.png"), QString(), -1);
emit refreshClipThumbnail(id);
}