Skip to content

Commit

Permalink
Refactor saveXML("string") into MltController::XML().
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Jan 3, 2015
1 parent 2fbce77 commit 90d9dce
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 35 deletions.
28 changes: 14 additions & 14 deletions src/docks/playlistdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void PlaylistDock::on_actionInsertCut_triggered()
{
if (MLT.isClip() || MLT.savedProducer()) {
QMimeData mimeData;
mimeData.setData(Mlt::XmlMimeType, MLT.saveXML("string",
mimeData.setData(Mlt::XmlMimeType, MLT.XML(
MLT.isClip()? 0 : MLT.savedProducer()).toUtf8());
onDropped(&mimeData, ui->tableView->currentIndex().row());
}
Expand All @@ -184,15 +184,15 @@ void PlaylistDock::on_actionAppendCut_triggered()
if (!MLT.isClip())
emit showStatusMessage(tr("You cannot insert a playlist into a playlist!"));
else if (MLT.isSeekable())
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.saveXML("string")));
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.XML()));
else {
DurationDialog dialog(this);
dialog.setDuration(MLT.profile().fps() * 5);
if (dialog.exec() == QDialog::Accepted) {
MLT.producer()->set_in_and_out(0, dialog.duration() - 1);
if (MLT.producer()->get("mlt_service") && !strcmp(MLT.producer()->get("mlt_service"), "avformat"))
MLT.producer()->set("mlt_service", "avformat-novalidate");
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.saveXML("string")));
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.XML()));
}
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ void PlaylistDock::on_actionUpdate_triggered()
if (info->resource && MLT.producer()->get("resource")
&& !strcmp(info->resource, MLT.producer()->get("resource"))) {
if (MLT.isSeekable()) {
MAIN.undoStack()->push(new Playlist::UpdateCommand(m_model, MLT.saveXML("string"), index.row()));
MAIN.undoStack()->push(new Playlist::UpdateCommand(m_model, MLT.XML(), index.row()));
}
else {
// change the duration
Expand All @@ -241,7 +241,7 @@ void PlaylistDock::on_actionUpdate_triggered()
MLT.producer()->set_in_and_out(0, dialog.duration() - 1);
if (MLT.producer()->get("mlt_service") && !strcmp(MLT.producer()->get("mlt_service"), "avformat"))
MLT.producer()->set("mlt_service", "avformat-novalidate");
MAIN.undoStack()->push(new Playlist::UpdateCommand(m_model, MLT.saveXML("string"), index.row()));
MAIN.undoStack()->push(new Playlist::UpdateCommand(m_model, MLT.XML(), index.row()));
}
}
}
Expand Down Expand Up @@ -272,7 +272,7 @@ void PlaylistDock::on_actionOpen_triggered()
if (!index.isValid() || !m_model.playlist()) return;
Mlt::ClipInfo* i = m_model.playlist()->clip_info(index.row());
if (i) {
QString xml = MLT.saveXML("string", i->producer);
QString xml = MLT.XML(i->producer);
Mlt::Producer* p = new Mlt::Producer(MLT.profile(), "xml-string", xml.toUtf8().constData());
QString service = p->get("mlt_service");
if (service == "pixbuf" || service == "qimage")
Expand Down Expand Up @@ -312,7 +312,7 @@ void PlaylistDock::on_tableView_doubleClicked(const QModelIndex &index)
if (qApp->keyboardModifiers() == Qt::ShiftModifier) {
emit itemActivated(i->start);
} else {
QString xml = MLT.saveXML("string", i->producer);
QString xml = MLT.XML(i->producer);
Mlt::Producer* p = new Mlt::Producer(MLT.profile(), "xml-string", xml.toUtf8().constData());
QString service = p->get("mlt_service");
if (service == "pixbuf" || service == "qimage")
Expand Down Expand Up @@ -373,9 +373,9 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
Mlt::Producer p(MLT.profile(), url.path().toUtf8().constData());
if (p.is_valid()) {
if (row == -1)
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.saveXML("string", &p)));
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.XML(&p)));
else
MAIN.undoStack()->push(new Playlist::InsertCommand(m_model, MLT.saveXML("string", &p), row));
MAIN.undoStack()->push(new Playlist::InsertCommand(m_model, MLT.XML(&p), row));
}
}
}
Expand All @@ -396,9 +396,9 @@ void PlaylistDock::onDropped(const QMimeData *data, int row)
if (MLT.producer()->get("mlt_service") && !strcmp(MLT.producer()->get("mlt_service"), "avformat"))
MLT.producer()->set("mlt_service", "avformat-novalidate");
if (row == -1)
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.saveXML("string")));
MAIN.undoStack()->push(new Playlist::AppendCommand(m_model, MLT.XML()));
else
MAIN.undoStack()->push(new Playlist::InsertCommand(m_model, MLT.saveXML("string"), row));
MAIN.undoStack()->push(new Playlist::InsertCommand(m_model, MLT.XML(), row));
}
}
}
Expand Down Expand Up @@ -470,7 +470,7 @@ UpdateCommand::UpdateCommand(PlaylistModel& model, const QString& xml, int row,
, m_row(row)
{
setText(QObject::tr("Update playlist item %1").arg(row + 1));
m_oldXml = MLT.saveXML("string", m_model.playlist()->get_clip(m_row));
m_oldXml = MLT.XML(m_model.playlist()->get_clip(m_row));
}

void UpdateCommand::redo()
Expand All @@ -490,7 +490,7 @@ RemoveCommand::RemoveCommand(PlaylistModel& model, int row, QUndoCommand *parent
, m_model(model)
, m_row(row)
{
m_xml = MLT.saveXML("string", m_model.playlist()->get_clip(m_row));
m_xml = MLT.XML(m_model.playlist()->get_clip(m_row));
setText(QObject::tr("Remove playlist item %1").arg(row + 1));
}

Expand All @@ -509,7 +509,7 @@ ClearCommand::ClearCommand(PlaylistModel& model, QUndoCommand *parent)
: QUndoCommand(parent)
, m_model(model)
{
m_xml = MLT.saveXML("string", m_model.playlist());
m_xml = MLT.XML(m_model.playlist());
setText(QObject::tr("Clear playlist"));
}

Expand Down
12 changes: 6 additions & 6 deletions src/docks/timelinedock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void TimelineDock::append(int trackIndex)
trackIndex = m_quickView.rootObject()->property("currentTrack").toInt();
MAIN.undoStack()->push(
new Timeline::AppendCommand(m_model, trackIndex,
MLT.saveXML("string", MLT.isClip()? 0 : MLT.savedProducer())));
MLT.XML(MLT.isClip()? 0 : MLT.savedProducer())));
}
}

Expand All @@ -194,7 +194,7 @@ void TimelineDock::remove(int trackIndex, int clipIndex)
clipIndex = m_quickView.rootObject()->property("currentClip").toInt();
Mlt::Producer* clip = getClip(trackIndex, clipIndex);
if (clip) {
QString xml = MLT.saveXML("string", clip);
QString xml = MLT.XML(clip);
delete clip;
QModelIndex idx = m_model.index(clipIndex, 0, m_model.index(trackIndex));
int position = m_model.data(idx, MultitrackModel::StartRole).toInt();
Expand All @@ -211,7 +211,7 @@ void TimelineDock::lift(int trackIndex, int clipIndex)
clipIndex = m_quickView.rootObject()->property("currentClip").toInt();
Mlt::Producer* clip = getClip(trackIndex, clipIndex);
if (clip) {
QString xml = MLT.saveXML("string", clip);
QString xml = MLT.XML(clip);
delete clip;
QModelIndex idx = m_model.index(clipIndex, 0, m_model.index(trackIndex));
int position = m_model.data(idx, MultitrackModel::StartRole).toInt();
Expand Down Expand Up @@ -261,7 +261,7 @@ void TimelineDock::openClip(int trackIndex, int clipIndex)
clipIndex = m_quickView.rootObject()->property("currentClip").toInt();
QScopedPointer<Mlt::ClipInfo> info(getClipInfo(trackIndex, clipIndex));
if (info) {
QString xml = MLT.saveXML("string", info->producer);
QString xml = MLT.XML(info->producer);
Mlt::Producer* p = new Mlt::Producer(MLT.profile(), "xml-string", xml.toUtf8().constData());
QString service = p->get("mlt_service");
if (service == "pixbuf" || service == "qimage")
Expand Down Expand Up @@ -364,7 +364,7 @@ void TimelineDock::insert(int trackIndex, int position, const QString &xml)
{
if (MLT.isSeekableClip() || MLT.savedProducer() || !xml.isEmpty()) {
QString xmlToUse = !xml.isEmpty()? xml
: MLT.saveXML("string", MLT.isClip()? 0 : MLT.savedProducer());
: MLT.XML(MLT.isClip()? 0 : MLT.savedProducer());
if (trackIndex < 0)
trackIndex = m_quickView.rootObject()->property("currentTrack").toInt();
if (position < 0)
Expand All @@ -378,7 +378,7 @@ void TimelineDock::overwrite(int trackIndex, int position, const QString &xml)
{
if (MLT.isSeekableClip() || MLT.savedProducer() || !xml.isEmpty()) {
QString xmlToUse = !xml.isEmpty()? xml
: MLT.saveXML("string", MLT.isClip()? 0 : MLT.savedProducer());
: MLT.XML(MLT.isClip()? 0 : MLT.savedProducer());
if (trackIndex < 0)
trackIndex = m_quickView.rootObject()->property("currentTrack").toInt();
if (position < 0)
Expand Down
2 changes: 1 addition & 1 deletion src/glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent* event)
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
mimeData->setData(Mlt::XmlMimeType, MLT.saveXML("string").toUtf8());
mimeData->setData(Mlt::XmlMimeType, MLT.XML().toUtf8());
drag->setMimeData(mimeData);
mimeData->setText(QString::number(MLT.producer()->get_playtime()));
m_mutex.lock();
Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ class AppendTask : public QRunnable
p.set("length", qRound(MLT.profile().fps() * 600));
p.set("out", qRound(MLT.profile().fps() * Settings.imageDuration()) - 1);
}
MAIN.undoStack()->push(new Playlist::AppendCommand(*model, MLT.saveXML("string", &p)));
MAIN.undoStack()->push(new Playlist::AppendCommand(*model, MLT.XML(&p)));
}
}
}
Expand Down
32 changes: 24 additions & 8 deletions src/mltcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,27 +390,43 @@ void Controller::refreshConsumer()
m_consumer->set("refresh", 1);
}

QString Controller::saveXML(const QString& filename, Service* service)
void Controller::saveXML(const QString& filename, Service* service)
{
Consumer c(profile(), "xml", filename.toUtf8().constData());
Service s(service? service->get_service() : m_producer->get_service());
if (s.is_valid()) {
int ignore = s.get_int("ignore_points");
if (ignore)
s.set("ignore_points", 0);
c.set("time_format", "clock");
c.set("no_meta", 1);
c.set("store", "shotcut");
c.set("no_root", 1);
c.set("root", QFileInfo(filename).absolutePath().toUtf8().constData());
c.connect(s);
c.start();
if (ignore)
s.set("ignore_points", ignore);
}
}

QString Controller::XML(Service* service)
{
static const char* propertyName = "string";
Consumer c(profile(), "xml", propertyName);
Service s(service? service->get_service() : m_producer->get_service());
if (!s.is_valid())
return "";
int ignore = s.get_int("ignore_points");
if (ignore)
s.set("ignore_points", 0);
c.set("time_format", "clock");
c.set("no_meta", 1);
c.set("store", "shotcut");
if (filename != "string") {
c.set("no_root", 1);
c.set("root", QFileInfo(filename).absolutePath().toUtf8().constData());
}
c.connect(s);
c.start();
if (ignore)
s.set("ignore_points", ignore);
return QString::fromUtf8(c.get(filename.toUtf8().constData()));
return QString::fromUtf8(c.get(propertyName));
}

int Controller::consumerChanged()
Expand Down Expand Up @@ -598,7 +614,7 @@ void Controller::restart()
if (m_producer && m_producer->is_valid() && Settings.playerGPU()) {
const char* position = m_consumer->frames_to_time(m_consumer->position());
double speed = m_producer->get_speed();
QString xml = saveXML("string");
QString xml = XML();
close();
if (!setProducer(new Mlt::Producer(profile(), "xml-string", xml.toUtf8().constData()))) {
m_producer->seek(position);
Expand Down
3 changes: 2 additions & 1 deletion src/mltcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class Controller
void onWindowResize();
virtual void seek(int position);
void refreshConsumer();
QString saveXML(const QString& filename, Service* service = 0);
void saveXML(const QString& filename, Service* service = 0);
QString XML(Service* service = 0);
int consumerChanged();
void setProfile(const QString& profile_name);
QString resource() const;
Expand Down
6 changes: 3 additions & 3 deletions src/models/multitrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ QString MultitrackModel::overwrite(int trackIndex, Mlt::Producer& clip, int posi
emit modified();
emit seeked(playlist.clip_start(targetIndex) + playlist.clip_length(targetIndex));
}
return MLT.saveXML("string", &result);
return MLT.XML(&result);
}

int MultitrackModel::insertClip(int trackIndex, Mlt::Producer &clip, int position)
Expand Down Expand Up @@ -1011,7 +1011,7 @@ int MultitrackModel::insertClip(int trackIndex, Mlt::Producer &clip, int positio
endInsertRows();
result = playlist.count() - 1;
} else {
// qDebug() << __FUNCTION__ << "inserting" << position << MLT.saveXML("string", &clip);
// qDebug() << __FUNCTION__ << "inserting" << position << MLT.XML(&clip);
int targetIndex = playlist.get_clip_index_at(position);

if (position > playlist.clip_start(targetIndex)) {
Expand Down Expand Up @@ -1146,7 +1146,7 @@ void MultitrackModel::splitClip(int trackIndex, int clipIndex, int position)

// Make copy of clip.
Mlt::Producer producer(MLT.profile(), "xml-string",
MLT.saveXML("string", &clip->parent()).toUtf8().constData());
MLT.XML(&clip->parent()).toUtf8().constData());
int in = clip->get_in();
int out = clip->get_out();
int duration = position - playlist.clip_start(clipIndex);
Expand Down
2 changes: 1 addition & 1 deletion src/models/playlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ QMimeData *PlaylistModel::mimeData(const QModelIndexList &indexes) const
if (info) {
Mlt::Producer* producer = info->producer;
producer->set_in_and_out(info->frame_in, info->frame_out);
mimeData->setData(Mlt::XmlMimeType, MLT.saveXML("string", producer).toUtf8());
mimeData->setData(Mlt::XmlMimeType, MLT.XML(producer).toUtf8());
producer->set_in_and_out(0, -1);
delete info;
}
Expand Down

0 comments on commit 90d9dce

Please sign in to comment.