From: Till T. <ro...@tt...> - 2012-11-15 20:46:38
|
Git commit 033c9e02b1b69d65598a2d7e9008c586e5558be2 by Till Theato. Committed on 15/11/2012 at 21:45. Pushed by theato into branch 'refactoring'. Also save bin, project parts and project settings. M +15 -0 src/core/project/abstractprojectclip.cpp M +2 -0 src/core/project/abstractprojectclip.h M +3 -0 src/core/project/abstractprojectitem.h M +1 -1 src/core/project/abstractprojectpart.h M +9 -2 src/core/project/binmodel.cpp M +5 -2 src/core/project/binmodel.h M +52 -9 src/core/project/project.cpp M +7 -1 src/core/project/project.h M +12 -0 src/core/project/projectfolder.cpp M +2 -0 src/core/project/projectfolder.h M +3 -4 src/core/project/timeline.cpp M +1 -1 src/core/project/timeline.h M +6 -0 src/plugins/cliptypes/imageclip/imageprojectclip.cpp M +2 -0 src/plugins/cliptypes/imageclip/imageprojectclip.h M +3 -6 src/plugins/projectparts/notes/notesplugin.cpp M +1 -1 src/plugins/projectparts/notes/notesplugin.h http://commits.kde.org/kdenlive/033c9e02b1b69d65598a2d7e9008c586e5558be2 diff --git a/src/core/project/abstractprojectclip.cpp b/src/core/project/abstractprojectclip.cpp index 3831a0f..620dbf6 100644 --- a/src/core/project/abstractprojectclip.cpp +++ b/src/core/project/abstractprojectclip.cpp @@ -105,4 +105,19 @@ void AbstractProjectClip::setCurrent(bool current) } } +QDomElement AbstractProjectClip::toXml(QDomDocument& document) const +{ + QDomElement clip = document.createElement("clip"); + clip.setAttribute("id", id()); + clip.setAttribute("producer_type",m_baseProducer->get("mlt_service")); + clip.setAttribute("name", name()); + if (!description().isEmpty()) { + clip.setAttribute("description", description()); + } + if (!m_url.isEmpty()) { + clip.setAttribute("url", m_url.path()); + } + return clip; +} + #include "abstractprojectclip.moc" diff --git a/src/core/project/abstractprojectclip.h b/src/core/project/abstractprojectclip.h index 8d09ff1..bdcaeb7 100644 --- a/src/core/project/abstractprojectclip.h +++ b/src/core/project/abstractprojectclip.h @@ -77,6 +77,8 @@ public: /** @brief Calls AbstractProjectItem::setCurrent and sets the bin monitor to use the clip's producer. */ virtual void setCurrent(bool current); + virtual QDomElement toXml(QDomDocument &document) const; + protected: AbstractClipPlugin const *m_plugin; ProducerWrapper *m_baseProducer; diff --git a/src/core/project/abstractprojectitem.h b/src/core/project/abstractprojectitem.h index 2146223..b22f4fd 100644 --- a/src/core/project/abstractprojectitem.h +++ b/src/core/project/abstractprojectitem.h @@ -18,6 +18,7 @@ the Free Software Foundation, either version 3 of the License, or class AbstractProjectClip; class BinModel; class QDomElement; +class QDomDocument; /** @@ -116,6 +117,8 @@ public: virtual void setCurrent(bool current); // virtual bool isSelected(); + virtual QDomElement toXml(QDomDocument &document) const = 0; + signals: void childAdded(AbstractProjectItem *child); void aboutToRemoveChild(AbstractProjectItem *child); diff --git a/src/core/project/abstractprojectpart.h b/src/core/project/abstractprojectpart.h index 2fe63fe..f32eea0 100644 --- a/src/core/project/abstractprojectpart.h +++ b/src/core/project/abstractprojectpart.h @@ -43,7 +43,7 @@ public: QString name() const; /** @brief Called by the project to request the current data. */ - virtual QDomElement save() const = 0; + virtual void save(QDomDocument &document, QDomElement &element) const = 0; /** @brief Called upon project creation. */ virtual void load(const QDomElement &element) = 0; diff --git a/src/core/project/binmodel.cpp b/src/core/project/binmodel.cpp index d2ab358..d352fb4 100644 --- a/src/core/project/binmodel.cpp +++ b/src/core/project/binmodel.cpp @@ -26,12 +26,12 @@ BinModel::BinModel(Project* parent) : m_monitor = new MonitorModel(m_project->profile(), i18n("Bin"), this); } -BinModel::BinModel(const QDomElement&rootItem, Project* parent) : +BinModel::BinModel(const QDomElement&element, Project* parent) : QObject(parent), m_project(parent), m_currentItem(NULL) { - m_rootFolder = new ProjectFolder(rootItem, this); + m_rootFolder = new ProjectFolder(element.firstChildElement("folder"), this); m_monitor = new MonitorModel(m_project->profile(), i18n("Bin"), this); } @@ -73,6 +73,13 @@ void BinModel::setCurrentItem(AbstractProjectItem* item) } } +QDomElement BinModel::toXml(QDomDocument& document) const +{ + QDomElement bin = document.createElement("bin"); + bin.appendChild(m_rootFolder->toXml(document)); + return bin; +} + void BinModel::emitAboutToAddItem(AbstractProjectItem* item) { emit aboutToAddItem(item); diff --git a/src/core/project/binmodel.h b/src/core/project/binmodel.h index a753afe..412382d 100644 --- a/src/core/project/binmodel.h +++ b/src/core/project/binmodel.h @@ -20,6 +20,7 @@ class ProjectFolder; class AbstractProjectClip; class AbstractProjectItem; class QDomElement; +class QDomDocument; /** @@ -40,11 +41,11 @@ public: BinModel(Project *parent = 0); /** * @brief Creates monitor model and root folder and passes the supplied information on to it. - * @param rootItem element describing the bin contents (handled by the root folder) + * @param element element describing the bin contents * @param parent project this bin belongs to * */ - BinModel(const QDomElement &rootItem, Project* parent = 0); + BinModel(const QDomElement &element, Project* parent = 0); /** @brief Returns a pointer to the project this bin belongs to. */ Project *project(); @@ -68,6 +69,8 @@ public: */ void setCurrentItem(AbstractProjectItem *item); + QDomElement toXml(QDomDocument &document) const; + public slots: /** @brief emits aboutToAddItem. */ void emitAboutToAddItem(AbstractProjectItem *item); diff --git a/src/core/project/project.cpp b/src/core/project/project.cpp index 34da5b2..adc7792 100644 --- a/src/core/project/project.cpp +++ b/src/core/project/project.cpp @@ -125,9 +125,9 @@ void Project::openFile() if (success) { loadTimeline(document.toString()); QDomElement kdenliveDoc = document.documentElement().firstChildElement("kdenlivedoc"); - m_bin = new BinModel(kdenliveDoc.firstChildElement("project_items"), this); + m_bin = new BinModel(kdenliveDoc.firstChildElement("bin"), this); loadParts(kdenliveDoc); - loadSettings(kdenliveDoc.firstChildElement("settings")); + loadSettings(kdenliveDoc); m_timeline->loadTracks(); } else { kWarning() << "unable to load document" << m_url.path() << errorMessage; @@ -158,15 +158,62 @@ void Project::loadParts(const QDomElement& element) } } -void Project::loadSettings(const QDomElement& settings) +QList<QDomElement> Project::saveParts(QDomDocument& document) const { - QDomNamedNodeMap attributes = settings.attributes(); + QList<QDomElement> partElements; + QList<AbstractProjectPart*> parts = pCore->projectManager()->parts(); + for (int i = 0; i < parts.count(); ++i) { + QDomElement partElement = document.createElement(parts.at(i)->name()); + parts.at(i)->save(document, partElement); + partElements.append(partElement); + } + + return partElements; +} + +void Project::loadSettings(const QDomElement& kdenliveDoc) +{ + QDomNamedNodeMap attributes = kdenliveDoc.firstChildElement("settings").attributes(); for (int i = 0; i < attributes.length(); ++i) { QDomNode attribute = attributes.item(i); m_settings.insert(attribute.nodeName(), attribute.nodeValue()); } } +QDomElement Project::saveSettings(QDomDocument& document) const +{ + QDomElement settings = document.createElement("settings"); + + QHash<QString, QString>::const_iterator i = m_settings.constBegin(); + while (i != m_settings.constEnd()) { + settings.setAttribute(i.key(), i.value()); + ++i; + } + + return settings; +} + +QDomDocument Project::toXml() const +{ + QDomDocument document; + + document.setContent(m_timeline->toXml(), false); + + QDomElement kdenliveDoc = document.createElement("kdenlivedoc"); + + kdenliveDoc.appendChild(m_bin->toXml(document)); + kdenliveDoc.appendChild(saveSettings(document)); + + QList<QDomElement> parts = saveParts(document); + foreach (QDomElement part, parts) { + kdenliveDoc.appendChild(part); + } + + document.documentElement().appendChild(kdenliveDoc); + + return document; +} + void Project::save() { if (m_url.isEmpty()) { @@ -178,11 +225,7 @@ void Project::save() // TODO: warning return /*false*/; } - - QDomDocument document; - document.setContent(m_timeline->toXML(), false); - - file.write(document.toString().toUtf8()); + file.write(toXml().toString().toUtf8()); file.close(); } diff --git a/src/core/project/project.h b/src/core/project/project.h index b15620a..18e7ac8 100644 --- a/src/core/project/project.h +++ b/src/core/project/project.h @@ -19,6 +19,7 @@ class MonitorModel; class Timeline; class BinModel; class QDomElement; +class QDomDocument; class QUndoStack; namespace Mlt { @@ -83,6 +84,9 @@ public: */ void setSetting(const QString &name, const QString &value); + /** @brief Returns a DomDocument that describes this project. */ + QDomDocument toXml() const; + public slots: void save(); @@ -91,7 +95,9 @@ private: void openNew(); void loadTimeline(const QString &content); void loadParts(const QDomElement &element); - void loadSettings(const QDomElement &settings); + QList<QDomElement> saveParts(QDomDocument &document) const; + void loadSettings(const QDomElement &kdenliveDoc); + QDomElement saveSettings(QDomDocument &document) const; KUrl m_url; BinModel *m_bin; diff --git a/src/core/project/projectfolder.cpp b/src/core/project/projectfolder.cpp index 2953d5d..3bdd149 100644 --- a/src/core/project/projectfolder.cpp +++ b/src/core/project/projectfolder.cpp @@ -67,6 +67,18 @@ BinModel* ProjectFolder::bin() } } +QDomElement ProjectFolder::toXml(QDomDocument& document) const +{ + QDomElement folder = document.createElement("folder"); + folder.setAttribute("name", name()); + + for (int i = 0; i < count(); ++i) { + folder.appendChild(at(i)->toXml(document)); + } + + return folder; +} + void ProjectFolder::loadChildren(const QDomElement& description) { QDomNodeList childen = description.childNodes(); diff --git a/src/core/project/projectfolder.h b/src/core/project/projectfolder.h index 00dd76a..b612e28 100644 --- a/src/core/project/projectfolder.h +++ b/src/core/project/projectfolder.h @@ -53,6 +53,8 @@ public: /** @brief Returns a pointer to the bin model this folder belongs to. */ BinModel *bin(); + QDomElement toXml(QDomDocument &document) const; + private: void loadChildren(const QDomElement &description); diff --git a/src/core/project/timeline.cpp b/src/core/project/timeline.cpp index 3776933..ab81df7 100644 --- a/src/core/project/timeline.cpp +++ b/src/core/project/timeline.cpp @@ -65,9 +65,8 @@ Timeline::~Timeline() delete m_profile; } -QString Timeline::toXML() const +QString Timeline::toXml() const { - QString playlist; Mlt::Profile profile((mlt_profile) 0); Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist"); @@ -76,6 +75,7 @@ QString Timeline::toXML() const // m_producer->optimise(); xmlConsumer.set("terminate_on_pause", 1); + // makes the consumer also store properties we added (with the prefix "kdenlive") xmlConsumer.set("store", "kdenlive"); Mlt::Producer producer(m_producer->get_producer()); @@ -83,8 +83,7 @@ QString Timeline::toXML() const xmlConsumer.connect(producer); xmlConsumer.run(); - playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist")); - return playlist; + return QString::fromUtf8(xmlConsumer.get("kdenlive_playlist")); } int Timeline::duration() const diff --git a/src/core/project/timeline.h b/src/core/project/timeline.h index 6c5df50..2e691ca 100644 --- a/src/core/project/timeline.h +++ b/src/core/project/timeline.h @@ -48,7 +48,7 @@ public: Timeline(Project *parent); virtual ~Timeline(); - QString toXML() const; + QString toXml() const; /** @brief Returns the duration of the timeline. */ int duration() const; diff --git a/src/plugins/cliptypes/imageclip/imageprojectclip.cpp b/src/plugins/cliptypes/imageclip/imageprojectclip.cpp index 97e8f8e..560db90 100644 --- a/src/plugins/cliptypes/imageclip/imageprojectclip.cpp +++ b/src/plugins/cliptypes/imageclip/imageprojectclip.cpp @@ -63,6 +63,12 @@ AbstractTimelineClip* ImageProjectClip::addInstance(ProducerWrapper* producer, T return static_cast<AbstractTimelineClip *>(instance); } +QDomElement ImageProjectClip::toXml(QDomDocument& document) const +{ + QDomElement clip = AbstractProjectClip::toXml(document); + clip.setAttribute("duration", m_baseProducer->get_length()); + return clip; +} QPixmap ImageProjectClip::thumbnail() { diff --git a/src/plugins/cliptypes/imageclip/imageprojectclip.h b/src/plugins/cliptypes/imageclip/imageprojectclip.h index 5afa37a..b1cefb8 100644 --- a/src/plugins/cliptypes/imageclip/imageprojectclip.h +++ b/src/plugins/cliptypes/imageclip/imageprojectclip.h @@ -30,6 +30,8 @@ public: AbstractTimelineClip *addInstance(ProducerWrapper *producer, TimelineTrack *parent); + QDomElement toXml(QDomDocument &document) const; + QPixmap thumbnail(); private: diff --git a/src/plugins/projectparts/notes/notesplugin.cpp b/src/plugins/projectparts/notes/notesplugin.cpp index cb0914d..68e7074 100644 --- a/src/plugins/projectparts/notes/notesplugin.cpp +++ b/src/plugins/projectparts/notes/notesplugin.cpp @@ -42,13 +42,10 @@ void NotesPlugin::load(const QDomElement& element) } } -QDomElement NotesPlugin::save() const +void NotesPlugin::save(QDomDocument &document, QDomElement &element) const { -// QDomElement docnotes = sceneList.createElement("documentnotes"); -// QDomText value = sceneList.createTextNode(m_notesWidget->toHtml()); -// docnotes.appendChild(value); -// addedXml.appendChild(docnotes); - return QDomElement(); + QDomText value = document.createTextNode(m_widget->toHtml()); + element.appendChild(value); } void NotesPlugin::insertTimecode() diff --git a/src/plugins/projectparts/notes/notesplugin.h b/src/plugins/projectparts/notes/notesplugin.h index b82e0fe..0be31b1 100644 --- a/src/plugins/projectparts/notes/notesplugin.h +++ b/src/plugins/projectparts/notes/notesplugin.h @@ -24,7 +24,7 @@ class NotesPlugin : public AbstractProjectPart public: explicit NotesPlugin(QObject* parent, const QVariantList &args); - QDomElement save() const; + void save(QDomDocument &document, QDomElement &element) const; void load(const QDomElement &element); private slots: |