X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fkdenlivedoc.cpp;h=01cd32e3397d052a6e9bfd9e69ee155975b8156a;hb=de93dc84bc5f050272e4e736c3afa6ad5f3c6654;hp=d648261df1fdea58bd293f825b0c5df66e3e27a2;hpb=ba6cfa6067b821c9dd26c8ebc9c41b0e10efe386;p=kdenlive diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index d648261d..01cd32e3 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -50,6 +50,9 @@ #include #include #include +#include +#include +#include #include @@ -125,7 +128,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup systemLocale.setNumberOptions(QLocale::OmitGroupSeparator); QLocale::setDefault(systemLocale); // locale conversion might need to be redone - initEffects::parseEffectFiles(setlocale(LC_NUMERIC, NULL)); + initEffects::parseEffectFiles(setlocale(LC_NUMERIC, NULL)); } *openBackup = false; @@ -143,50 +146,50 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup else { QFile file(tmpFile); QString errorMsg; - int line; - int col; + int line; + int col; QDomImplementation::setInvalidDataPolicy(QDomImplementation::DropInvalidChars); success = m_document.setContent(&file, false, &errorMsg, &line, &col); - file.close(); + file.close(); if (!success) { // It is corrupted - int answer = KMessageBox::warningYesNoCancel (parent, i18n("Cannot open the project file, error is:\n%1 (line %2, col %3)\nDo you want to open a backup file?", errorMsg, line, col), i18n("Error opening file"), KGuiItem(i18n("Open Backup")), KGuiItem(i18n("Recover"))); + int answer = KMessageBox::warningYesNoCancel (parent, i18n("Cannot open the project file, error is:\n%1 (line %2, col %3)\nDo you want to open a backup file?", errorMsg, line, col), i18n("Error opening file"), KGuiItem(i18n("Open Backup")), KGuiItem(i18n("Recover"))); if (answer == KMessageBox::Yes) { - *openBackup = true; - } - else if (answer == KMessageBox::No) { - // Try to recover broken file produced by Kdenlive 0.9.4 - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - int correction = 0; - QString playlist = file.readAll(); - while (!success && correction < 2) { - int errorPos = 0; - line--; - col = col - 2; - for (int j = 0; j < line && errorPos < playlist.length(); j++) { - errorPos = playlist.indexOf("\n", errorPos); - errorPos++; - } - errorPos += col; - if (errorPos >= playlist.length()) break; - playlist.remove(errorPos, 1); - line = 0; - col = 0; - success = m_document.setContent(playlist, false, &errorMsg, &line, &col); - correction++; - } - if (!success) { - KMessageBox::sorry(parent, i18n("Cannot recover this project file")); - } - else { - // Document was modified, ask for backup - QDomElement mlt = m_document.documentElement(); - QDomElement info = mlt.firstChildElement("kdenlivedoc"); - if (!info.isNull()) info.setAttribute("modified", 1); - } - } - } + *openBackup = true; + } + else if (answer == KMessageBox::No) { + // Try to recover broken file produced by Kdenlive 0.9.4 + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { + int correction = 0; + QString playlist = file.readAll(); + while (!success && correction < 2) { + int errorPos = 0; + line--; + col = col - 2; + for (int j = 0; j < line && errorPos < playlist.length(); j++) { + errorPos = playlist.indexOf("\n", errorPos); + errorPos++; + } + errorPos += col; + if (errorPos >= playlist.length()) break; + playlist.remove(errorPos, 1); + line = 0; + col = 0; + success = m_document.setContent(playlist, false, &errorMsg, &line, &col); + correction++; + } + if (!success) { + KMessageBox::sorry(parent, i18n("Cannot recover this project file")); + } + else { + // Document was modified, ask for backup + QDomElement mlt = m_document.documentElement(); + QDomElement info = mlt.firstChildElement("kdenlivedoc"); + if (!info.isNull()) info.setAttribute("modified", 1); + } + } + } } if (success) { parent->slotGotProgressInfo(i18n("Validating"), 0); @@ -250,7 +253,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup projectTrack.isBlind = e.attribute("blind").toInt(); projectTrack.isLocked = e.attribute("locked").toInt(); projectTrack.trackName = e.attribute("trackname"); - projectTrack.effectsList = EffectsList(true); + projectTrack.effectsList = EffectsList(true); m_tracksList.append(projectTrack); } } @@ -316,11 +319,11 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup for (int k = 0; k < maxchild; k++) { e = markerslist.at(k).toElement(); if (e.tagName() == "marker") { - CommentedTime marker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"), e.attribute("type").toInt()); - DocClipBase *baseClip = m_clipManager->getClipById(e.attribute("id")); + CommentedTime marker(GenTime(e.attribute("time").toDouble()), e.attribute("comment"), e.attribute("type").toInt()); + DocClipBase *baseClip = m_clipManager->getClipById(e.attribute("id")); if (baseClip) baseClip->addSnapMarker(marker); - else kDebug()<< " / / Warning, missing clip: "<< e.attribute("id"); - } + else kDebug()<< " / / Warning, missing clip: "<< e.attribute("id"); + } } infoXml.removeChild(markers); } @@ -425,7 +428,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks) audioTrack.isLocked = false; audioTrack.trackName = QString("Audio ") + QString::number(audiotracks - i); audioTrack.duration = 0; - audioTrack.effectsList = EffectsList(true); + audioTrack.effectsList = EffectsList(true); m_tracksList.append(audioTrack); } @@ -437,13 +440,13 @@ QDomDocument KdenliveDoc::createEmptyDocument(int videotracks, int audiotracks) videoTrack.isLocked = false; videoTrack.trackName = QString("Video ") + QString::number(videotracks - i); videoTrack.duration = 0; - videoTrack.effectsList = EffectsList(true); + videoTrack.effectsList = EffectsList(true); m_tracksList.append(videoTrack); } return createEmptyDocument(m_tracksList); } -QDomDocument KdenliveDoc::createEmptyDocument(QList tracks) +QDomDocument KdenliveDoc::createEmptyDocument(const QList &tracks) { // Creating new document QDomDocument doc; @@ -500,7 +503,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(QList tracks) QDomElement tractor = doc.createElement("tractor"); tractor.setAttribute("id", "maintractor"); - QDomElement multitrack = doc.createElement("multitrack"); + //QDomElement multitrack = doc.createElement("multitrack"); QDomElement playlist = doc.createElement("playlist"); playlist.setAttribute("id", "black_track"); mlt.appendChild(playlist); @@ -577,7 +580,7 @@ QDomDocument KdenliveDoc::createEmptyDocument(QList tracks) } -void KdenliveDoc::syncGuides(QList guides) +void KdenliveDoc::syncGuides(const QList &guides) { m_guidesXml.clear(); QDomElement guideNode = m_guidesXml.createElement("guides"); @@ -763,7 +766,7 @@ QDomDocument KdenliveDoc::xmlSceneList(const QString &scene, const QStringList & marker.setAttribute("time", marks.at(j).time().ms() / 1000); marker.setAttribute("comment", marks.at(j).comment()); marker.setAttribute("id", e.attribute("id")); - marker.setAttribute("type", marks.at(j).markerType()); + marker.setAttribute("type", marks.at(j).markerType()); markers.appendChild(marker); } } @@ -808,7 +811,7 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene, const if (!autosave) { cleanupBackupFiles(); QFileInfo info(file); - QString fileName = KUrl(path).fileName().section('.', 0, -2); + QString fileName = KUrl(path).fileName().section('.', 0, -2); fileName.append('-' + m_documentProperties.value("documentid")); fileName.append(info.lastModified().toString("-yyyy-MM-dd-hh-mm")); fileName.append(".kdenlive.png"); @@ -844,7 +847,7 @@ void KdenliveDoc::setProjectFolder(KUrl url) updateProjectFolderPlacesEntry(); } -void KdenliveDoc::moveProjectData(KUrl url) +void KdenliveDoc::moveProjectData(const KUrl &url) { QList list = m_clipManager->documentClipList(); KUrl::List cacheUrls; @@ -886,8 +889,10 @@ MltVideoProfile KdenliveDoc::mltProfile() const bool KdenliveDoc::setProfilePath(QString path) { - if (path.isEmpty()) path = KdenliveSettings::default_profile(); - if (path.isEmpty()) path = "dv_pal"; + if (path.isEmpty()) + path = KdenliveSettings::default_profile(); + if (path.isEmpty()) + path = QLatin1String("dv_pal"); m_profile = ProfilesDialog::getVideoProfile(path); double current_fps = m_fps; if (m_profile.path.isEmpty()) { @@ -990,7 +995,7 @@ void KdenliveDoc::updateClip(const QString &id) emit updateClipDisplay(id); } -int KdenliveDoc::getFramePos(QString duration) +int KdenliveDoc::getFramePos(const QString &duration) { return m_timecode.getFrameCount(duration); } @@ -1054,7 +1059,7 @@ KUrl KdenliveDoc::url() const return m_url; } -void KdenliveDoc::setUrl(KUrl url) +void KdenliveDoc::setUrl(const KUrl &url) { m_url = url; } @@ -1082,7 +1087,7 @@ const QString KdenliveDoc::description() const return m_url.fileName() + " / " + m_profile.description; } -bool KdenliveDoc::addClip(QDomElement elem, QString clipId, bool createClipItem) +bool KdenliveDoc::addClip(QDomElement elem, const QString &clipId, bool createClipItem) { const QString producerId = clipId.section('_', 0, 0); DocClipBase *clip = m_clipManager->getClipById(producerId); @@ -1215,7 +1220,7 @@ QString KdenliveDoc::searchFileRecursively(const QDir &dir, const QString &match return foundFileName; } -bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId) +bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, const QString &clipId) { DocClipBase *clip = m_clipManager->getClipById(clipId); if (clip == NULL) { @@ -1226,7 +1231,7 @@ bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId QDomNamedNodeMap attributes = elem.attributes(); for (int i = 0; i < attributes.count(); ++i) { QString attrname = attributes.item(i).nodeName(); - if (attrname != "resource") + if (attrname != "resource") properties.insert(attrname, attributes.item(i).nodeValue()); //kDebug() << attrname << " = " << attributes.item(i).nodeValue(); } @@ -1238,9 +1243,9 @@ bool KdenliveDoc::addClipInfo(QDomElement elem, QDomElement orig, QString clipId for (QDomNode m = orig.firstChild(); !m.isNull(); m = m.nextSibling()) { QString name = m.toElement().attribute("name"); if (name.startsWith("meta.attr")) { - if (name.endsWith(".markup")) name = name.section('.', 0, -2); + if (name.endsWith(".markup")) name = name.section('.', 0, -2); meta.insert(name.section('.', 2, -1), m.firstChild().nodeValue()); - } + } } if (!meta.isEmpty()) { if (clip == NULL) @@ -1258,7 +1263,7 @@ void KdenliveDoc::deleteClip(const QString &clipId) emit signalDeleteProjectClip(clipId); } -void KdenliveDoc::slotAddClipList(const KUrl::List urls, stringMap data) +void KdenliveDoc::slotAddClipList(const KUrl::List &urls, const stringMap &data) { m_clipManager->slotAddClipList(urls, data); //emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); @@ -1266,7 +1271,7 @@ void KdenliveDoc::slotAddClipList(const KUrl::List urls, stringMap data) } -void KdenliveDoc::slotAddClipFile(const KUrl &url, stringMap data) +void KdenliveDoc::slotAddClipFile(const KUrl &url, const stringMap &data) { m_clipManager->slotAddClipFile(url, data); emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); @@ -1283,21 +1288,21 @@ DocClipBase *KdenliveDoc::getBaseClip(const QString &clipId) return m_clipManager->getClipById(clipId); } -void KdenliveDoc::slotCreateXmlClip(const QString &name, const QDomElement xml, QString group, const QString &groupId) +void KdenliveDoc::slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId) { m_clipManager->slotAddXmlClipFile(name, xml, group, groupId); setModified(true); emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); } -void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, QString group, const QString &groupId) +void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId) { m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId); setModified(true); emit selectLastAddedClip(QString::number(m_clipManager->lastClipId())); } -void KdenliveDoc::slotCreateSlideshowClipFile(QMap properties, QString group, const QString &groupId) +void KdenliveDoc::slotCreateSlideshowClipFile(const QMap &properties, const QString &group, const QString &groupId) { m_clipManager->slotAddSlideshowClipFile(properties, group, groupId); setModified(true); @@ -1317,7 +1322,7 @@ void KdenliveDoc::slotCreateTextClip(QString group, const QString &groupId, cons delete dia_ui; } -void KdenliveDoc::slotCreateTextTemplateClip(QString group, const QString &groupId, KUrl path) +void KdenliveDoc::slotCreateTextTemplateClip(const QString &group, const QString &groupId, KUrl path) { QString titlesFolder = projectFolder().path(KUrl::AddTrailingSlash) + "titles/"; if (path.isEmpty()) { @@ -1384,7 +1389,7 @@ void KdenliveDoc::switchTrackVideo(int ix, bool hide) int KdenliveDoc::trackDuration(int ix) { - return m_tracksList.at(ix).duration; + return m_tracksList.at(ix).duration; } void KdenliveDoc::setTrackDuration(int ix, int duration) @@ -1392,7 +1397,7 @@ void KdenliveDoc::setTrackDuration(int ix, int duration) m_tracksList[ix].duration = duration; } -void KdenliveDoc::insertTrack(int ix, TrackInfo type) +void KdenliveDoc::insertTrack(int ix, const TrackInfo &type) { if (ix == -1) m_tracksList << type; else m_tracksList.insert(ix, type); @@ -1407,7 +1412,7 @@ void KdenliveDoc::deleteTrack(int ix) m_tracksList.removeAt(ix); } -void KdenliveDoc::setTrackType(int ix, TrackInfo type) +void KdenliveDoc::setTrackType(int ix, const TrackInfo &type) { if (ix < 0 || ix >= m_tracksList.count()) { kWarning() << "SET Track Type outisde of range"; @@ -1541,7 +1546,7 @@ void KdenliveDoc::addTrackEffect(int ix, QDomElement effect) m_tracksList[ix].effectsList.append(effect); } -void KdenliveDoc::removeTrackEffect(int ix, QDomElement effect) +void KdenliveDoc::removeTrackEffect(int ix, const QDomElement &effect) { if (ix < 0 || ix >= m_tracksList.count()) { kWarning() << "Remove Track effect outisde of range"; @@ -1574,7 +1579,7 @@ void KdenliveDoc::setTrackEffect(int trackIndex, int effectIndex, QDomElement ef //m_tracksList[trackIndex].effectsList.updateEffect(effect); } -void KdenliveDoc::enableTrackEffects(int trackIndex, QList effectIndexes, bool disable) +void KdenliveDoc::enableTrackEffects(int trackIndex, const QList &effectIndexes, bool disable) { if (trackIndex < 0 || trackIndex >= m_tracksList.count()) { kWarning() << "Set Track effect outisde of range"; @@ -1583,8 +1588,8 @@ void KdenliveDoc::enableTrackEffects(int trackIndex, QList effectIndexes, EffectsList list = m_tracksList.at(trackIndex).effectsList; QDomElement effect; for (int i = 0; i < effectIndexes.count(); ++i) { - effect = list.itemFromIndex(effectIndexes.at(i)); - if (!effect.isNull()) effect.setAttribute("disable", (int) disable); + effect = list.itemFromIndex(effectIndexes.at(i)); + if (!effect.isNull()) effect.setAttribute("disable", (int) disable); } } @@ -1618,15 +1623,15 @@ int KdenliveDoc::hasTrackEffect(int trackIndex, const QString &tag, const QStrin return list.hasEffect(tag, id); } -bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects) +bool KdenliveDoc::saveCustomEffects(const QDomNodeList &customeffects) { QDomElement e; QStringList importedEffects; int maxchild = customeffects.count(); for (int i = 0; i < maxchild; ++i) { e = customeffects.at(i).toElement(); - QString id = e.attribute("id"); - QString tag = e.attribute("tag"); + const QString id = e.attribute("id"); + const QString tag = e.attribute("tag"); if (!id.isEmpty()) { // Check if effect exists or save it if (MainWindow::customEffects.hasEffect(tag, id) == -1) { @@ -1645,7 +1650,8 @@ bool KdenliveDoc::saveCustomEffects(QDomNodeList customeffects) } } } - if (!importedEffects.isEmpty()) KMessageBox::informationList(kapp->activeWindow(), i18n("The following effects were imported from the project:"), importedEffects); + if (!importedEffects.isEmpty()) + KMessageBox::informationList(kapp->activeWindow(), i18n("The following effects were imported from the project:"), importedEffects); return (!importedEffects.isEmpty()); } @@ -1746,7 +1752,7 @@ void KdenliveDoc::backupLastSavedVersion(const QString &path) if (!QFile::copy(path, backupFile.path())) { KMessageBox::information(kapp->activeWindow(), i18n("Cannot create backup copy:\n%1", backupFile.path())); } - } + } } void KdenliveDoc::cleanupBackupFiles()