#include <QCryptographicHash>
#include <QFile>
+#include <QInputDialog>
#include <mlt++/Mlt.h>
const double DOCUMENTVERSION = 0.83;
-KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, const QString &profileName, const QPoint tracks, Render *render, MainWindow *parent) :
+KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, const QPoint tracks, Render *render, MainWindow *parent) :
QObject(parent),
m_autosave(NULL),
m_url(url),
success = validator.validate(DOCUMENTVERSION);
if (success) { // Let the validator handle error messages
setModified(validator.isModified());
- QDomNode infoXmlNode = m_document.elementsByTagName("kdenlivedoc").at(0);
- QDomElement infoXml = infoXmlNode.toElement();
- QDomNode mlt = m_document.elementsByTagName("mlt").at(0);
+ QDomElement mlt = m_document.firstChildElement("mlt");
+ QDomElement infoXml = mlt.firstChildElement("kdenlivedoc");
- QString profilePath = infoXml.attribute("profile");
+ profileName = infoXml.attribute("profile");
m_projectFolder = infoXml.attribute("projectfolder");
m_startPos = infoXml.attribute("position").toInt();
// Build tracks
QDomElement e;
- QDomNode tracksinfo = m_document.elementsByTagName("tracksinfo").at(0);
+ QDomElement tracksinfo = infoXml.firstChildElement("tracksinfo");
TrackInfo projectTrack;
if (!tracksinfo.isNull()) {
QDomNodeList trackslist = tracksinfo.childNodes();
setProfilePath(KdenliveSettings::default_profile());
m_clipManager->clear();
} else {
- QDomNode markers = m_document.elementsByTagName("markers").at(0);
+ QDomElement markers = infoXml.firstChildElement("markers");
if (!markers.isNull()) {
QDomNodeList markerslist = markers.childNodes();
int maxchild = markerslist.count();
m_clipManager->getClipById(e.attribute("id"))->addSnapMarker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"));
}
}
- mlt.removeChild(markers);
+ infoXml.removeChild(markers);
}
- m_document.removeChild(infoXmlNode);
+ setProfilePath(profileName);
kDebug() << "Reading file: " << url.path() << ", found clips: " << producers.count();
}
}
}
}
}
- }
+ } else setProfilePath(profileName);
// Something went wrong, or a new file was requested: create a new project
if (!success) {
}
// Set the video profile (empty == default)
- setProfilePath(profileName);
// Make sure the project folder is usable
if (m_projectFolder.isEmpty() || !KIO::NetAccess::exists(m_projectFolder.path(), KIO::NetAccess::DestinationSide, parent)) {
delete m_clipManager;
delete m_autoSaveTimer;
if (m_autosave) {
- m_autosave->remove();
+ if (!m_autosave->fileName().isEmpty()) m_autosave->remove();
delete m_autosave;
}
}
{
QDomDocument sceneList;
sceneList.setContent(scene, true);
- QDomNode mlt = sceneList.elementsByTagName("mlt").at(0);
+ QDomElement mlt = sceneList.firstChildElement("mlt");
QDomElement addedXml = sceneList.createElement("kdenlivedoc");
mlt.appendChild(addedXml);
addedXml.setAttribute("projectfolder", m_projectFolder.path());
addedXml.setAttribute("zoom", m_zoom);
+ // Add profile info
+ QDomElement profileinfo = sceneList.createElement("profileinfo");
+ profileinfo.setAttribute("description", m_profile.description);
+ profileinfo.setAttribute("frame_rate_num", m_profile.frame_rate_num);
+ profileinfo.setAttribute("frame_rate_den", m_profile.frame_rate_den);
+ profileinfo.setAttribute("width", m_profile.width);
+ profileinfo.setAttribute("height", m_profile.height);
+ profileinfo.setAttribute("progressive", m_profile.progressive);
+ profileinfo.setAttribute("sample_aspect_num", m_profile.sample_aspect_num);
+ profileinfo.setAttribute("sample_aspect_den", m_profile.sample_aspect_den);
+ profileinfo.setAttribute("display_aspect_num", m_profile.display_aspect_num);
+ profileinfo.setAttribute("display_aspect_den", m_profile.display_aspect_den);
+ addedXml.appendChild(profileinfo);
+
// tracks info
QDomElement tracksinfo = sceneList.createElement("tracksinfo");
foreach(const TrackInfo &info, m_tracksList) {
if (path.isEmpty()) path = KdenliveSettings::default_profile();
if (path.isEmpty()) path = "dv_pal";
m_profile = ProfilesDialog::getVideoProfile(path);
+ if (m_profile.path.isEmpty()) {
+ // Profile not found, use embedded profile
+ QDomElement profileInfo = m_document.elementsByTagName("profileinfo").at(0).toElement();
+ if (profileInfo.isNull()) {
+ KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, using default profile."), i18n("Missing Profile"));
+ m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
+ } else {
+ m_profile.description = profileInfo.attribute("description");
+ m_profile.frame_rate_num = profileInfo.attribute("frame_rate_num").toInt();
+ m_profile.frame_rate_den = profileInfo.attribute("frame_rate_den").toInt();
+ m_profile.width = profileInfo.attribute("width").toInt();
+ m_profile.height = profileInfo.attribute("height").toInt();
+ m_profile.progressive = profileInfo.attribute("progressive").toInt();
+ m_profile.sample_aspect_num = profileInfo.attribute("sample_aspect_num").toInt();
+ m_profile.sample_aspect_den = profileInfo.attribute("sample_aspect_den").toInt();
+ m_profile.display_aspect_num = profileInfo.attribute("display_aspect_num").toInt();
+ m_profile.display_aspect_den = profileInfo.attribute("display_aspect_den").toInt();
+ QString existing = ProfilesDialog::existingProfile(m_profile);
+ if (!existing.isEmpty()) {
+ m_profile = ProfilesDialog::getVideoProfile(existing);
+ KMessageBox::information(kapp->activeWindow(), i18n("Project profile not found, replacing with existing one: %1", m_profile.description), i18n("Missing Profile"));
+ } else {
+ QString newDesc = m_profile.description;
+ bool ok = true;
+ while (ok && (newDesc.isEmpty() || ProfilesDialog::existingProfileDescription(newDesc))) {
+ newDesc = QInputDialog::getText(kapp->activeWindow(), i18n("Existing Profile"), i18n("Your project uses an unknown profile.\nIt uses an existing profile name: %1.\nPlease choose a new name to save it", newDesc), QLineEdit::Normal, newDesc, &ok);
+ }
+ if (ok == false) {
+ // User canceled, use default profile
+ m_profile = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile());
+ } else {
+ if (newDesc != m_profile.description) {
+ // Profile description existed, was replaced by new one
+ m_profile.description = newDesc;
+ } else {
+ KMessageBox::information(kapp->activeWindow(), i18n("Project profile was not found, it will be added to your system now."), i18n("Missing Profile"));
+ }
+ ProfilesDialog::saveProfile(m_profile);
+ }
+ }
+ setModified(true);
+ }
+ }
+
KdenliveSettings::setProject_display_ratio((double) m_profile.display_aspect_num / m_profile.display_aspect_den);
m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
KdenliveSettings::setProject_fps(m_fps);
return m_clipManager->getClipById(clipId);
}
-void KdenliveDoc::slotCreateTextClip(QString /*group*/, const QString &/*groupId*/)
+void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId)
{
QString titlesFolder = projectFolder().path() + "/titles/";
KStandardDirs::makeDir(titlesFolder);
QImage pix = dia_ui->renderedPixmap();
pix.save(titleInfo.at(1));
//dia_ui->saveTitle(path + ".kdenlivetitle");
- m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), QString(), QString());
+ m_clipManager->slotAddTextClipFile(titleInfo.at(0), titleInfo.at(1), dia_ui->xml().toString(), group, groupId);
setModified(true);
}
delete dia_ui;
}
+void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &groupId)
+{
+ KUrl titlesFolder = KUrl(projectFolder().path() + "/titles/");
+ KUrl path = KFileDialog::getOpenUrl(titlesFolder, "*.kdenlivetitle", kapp->activeWindow(), i18n("Enter Template Path"));
+ if (path.isEmpty()) return;
+
+ QStringList titleInfo = TitleWidget::getFreeTitleInfo(projectFolder());
+
+ TitleWidget *dia_ui = new TitleWidget(path, titlesFolder.path(), m_render, kapp->activeWindow());
+ QImage pix = dia_ui->renderedPixmap();
+ pix.save(titleInfo.at(1));
+ delete dia_ui;
+ m_clipManager->slotAddTextTemplateClip(titleInfo.at(0), titleInfo.at(1), path, group, groupId);
+ setModified(true);
+}
+
int KdenliveDoc::tracksCount() const
{
return m_tracksList.count();