From: Jean-Baptiste M. <jb...@kd...> - 2013-01-29 12:31:46
|
Git commit 7f874349bc98d2bd5ef2c7894dc2f0dfec443832 by Jean-Baptiste Mardelle. Committed on 29/01/2013 at 13:31. Pushed by mardelle into branch 'refactoring'. Allow startup with empty doc without crashing M +4 -2 src/core/bin/bin.cpp M +4 -0 src/core/mainwindow.cpp M +1 -1 src/core/project/project.cpp M +31 -15 src/core/project/timeline.cpp M +3 -2 src/core/project/timeline.h M +1 -1 src/core/timelineview/positionitem.cpp M +1 -1 src/core/timelineview/timelinepositionbar.cpp http://commits.kde.org/kdenlive/7f874349bc98d2bd5ef2c7894dc2f0dfec443832 diff --git a/src/core/bin/bin.cpp b/src/core/bin/bin.cpp index c73f2d6..4ae520e 100644 --- a/src/core/bin/bin.cpp +++ b/src/core/bin/bin.cpp @@ -69,12 +69,14 @@ void Bin::setProject(Project* project) { if (m_itemView) { delete m_itemView; + m_itemView = NULL; } if (m_itemModel) { delete m_itemModel; } - + m_itemModel = new ProjectItemModel(project->bin(), this); + slotInitView(NULL); } @@ -96,7 +98,7 @@ void Bin::slotInitView(QAction *action) if (m_itemView) { delete m_itemView; } - + switch (m_listType) { case BinIconView: m_itemView = new QListView(this); diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index d154acd..90f9fa3 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -53,6 +53,10 @@ MainWindow::MainWindow(const QString &mltPath, const KUrl &url, const QString & if (!url.isEmpty() && url.isValid()) { pCore->projectManager()->openProject(url); } + else { + // Start with new project + pCore->projectManager()->openProject(KUrl()); + } } MainWindow::~MainWindow() diff --git a/src/core/project/project.cpp b/src/core/project/project.cpp index 1785ad4..df2b8be 100644 --- a/src/core/project/project.cpp +++ b/src/core/project/project.cpp @@ -141,7 +141,7 @@ void Project::openFile() void Project::openNew() { - m_timeline = new Timeline(this); + m_timeline = new Timeline(QString(), this); m_timecodeFormatter = new TimecodeFormatter(Fraction(profile()->frame_rate_num(), profile()->frame_rate_den())); m_bin = new BinModel(this); } diff --git a/src/core/project/timeline.cpp b/src/core/project/timeline.cpp index 358d662..2d4c350 100644 --- a/src/core/project/timeline.cpp +++ b/src/core/project/timeline.cpp @@ -25,7 +25,15 @@ Timeline::Timeline(const QString& document, Project* parent) : { // profile we set doesn't matter, it will be overwritten anyways with the info in the profile tag m_profile = new Mlt::Profile(KdenliveSettings::default_profile().toUtf8().constData()); - m_producer = new ProducerWrapper(*m_profile, document, "xml-string"); + if (document.isEmpty()) { + // Creating blank project + QString blankDocument = getBlankDocument(); + m_producer = new ProducerWrapper(*m_profile, blankDocument, "xml-string"); + + } + else { + m_producer = new ProducerWrapper(*m_profile, document, "xml-string"); + } // this shouldn't be an assert Q_ASSERT(m_producer && m_producer->is_valid()); @@ -43,20 +51,6 @@ Timeline::Timeline(const QString& document, Project* parent) : m_producerChangeEvent = m_producer->listen("producer-changed", this, (mlt_listener)producer_change); } -Timeline::Timeline(Project* parent) : - QObject(parent), - m_parent(parent), - m_producerChangeEvent(0) -{ - m_profile = new Mlt::Profile(KdenliveSettings::default_profile().toUtf8().constData()); - m_tractor = new Mlt::Tractor(); - m_producer = 0; - -// m_producer = m_tractor->parent().producer(); - -// Q_ASSERT(m_producer && m_producer->is_valid()); -} - Timeline::~Timeline() { qDeleteAll(m_tracks); @@ -65,6 +59,28 @@ Timeline::~Timeline() delete m_profile; } +QString Timeline::getBlankDocument() const +{ + // Generate an empty project xml + QString playlist; + Mlt::Consumer xmlConsumer(*m_profile, "xml:kdenlive_playlist"); + if (!xmlConsumer.is_valid()) return QString(); + Mlt::Tractor tractor; + Mlt::Playlist playlist1(*m_profile); + Mlt::Playlist playlist2(*m_profile); + + //TODO: proper number of tracks, etc... + tractor.set_track(playlist1, 0); + tractor.set_track(playlist2, 1); + xmlConsumer.set("terminate_on_pause", 1); + Mlt::Producer prod(tractor.get_producer()); + if (!prod.is_valid()) return QString(); + xmlConsumer.connect(prod); + xmlConsumer.run(); + playlist = QString::fromUtf8(xmlConsumer.get("kdenlive_playlist")); + return playlist; +} + QString Timeline::toXml() const { Mlt::Consumer xmlConsumer(*m_profile, "xml:kdenlive_playlist"); diff --git a/src/core/project/timeline.h b/src/core/project/timeline.h index 2e691ca..1c73351 100644 --- a/src/core/project/timeline.h +++ b/src/core/project/timeline.h @@ -44,9 +44,10 @@ public: * @param parent project this timeline belongs to */ Timeline(const QString &document, Project* parent); - /** @brief Creates an empty timeline */ - Timeline(Project *parent); virtual ~Timeline(); + + /** @brief Create empty xml doc. */ + QString getBlankDocument() const; QString toXml() const; diff --git a/src/core/timelineview/positionitem.cpp b/src/core/timelineview/positionitem.cpp index a6c9e6f..fddf568 100644 --- a/src/core/timelineview/positionitem.cpp +++ b/src/core/timelineview/positionitem.cpp @@ -17,7 +17,7 @@ the Free Software Foundation, either version 3 of the License, or PositionItem::PositionItem(TimelineScene* scene) : QGraphicsLineItem() { - int position = scene->timeline()->monitor()->position(); + int position = scene->timeline()->monitor() == NULL ? 0 : scene->timeline()->monitor()->position(); setLine(position, 0, position, scene->height()); connect(scene, SIGNAL(heightChanged(int)), this, SLOT(setHeight(int))); diff --git a/src/core/timelineview/timelinepositionbar.cpp b/src/core/timelineview/timelinepositionbar.cpp index a2f3e7f..5f9d15d 100644 --- a/src/core/timelineview/timelinepositionbar.cpp +++ b/src/core/timelineview/timelinepositionbar.cpp @@ -78,7 +78,7 @@ void TimelinePositionBar::setProject(Project* project) connect(m_timecodeFormatter, SIGNAL(framerateChanged()), this, SLOT(onFramerateChange())); connect(m_timecodeFormatter, SIGNAL(defaultFormatChanged()), this, SLOT(update())); - m_playbackPosition = project->timelineMonitor()->position(); + m_playbackPosition = project->timelineMonitor() == NULL ? 0 : project->timelineMonitor()->position(); connect(project->timelineMonitor(), SIGNAL(positionChanged(int)), this, SLOT(setCursorPosition(int))); connect(this, SIGNAL(positionChanged(int)), project->timelineMonitor(), SLOT(setPosition(int))); |