2015-04-16 11:50:07 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 Srivats P.
|
|
|
|
|
|
|
|
This file is part of "Ostinato"
|
|
|
|
|
|
|
|
This is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
#include "ostmfileformat.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
OstmFileFormat fileFormat;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
OstmFileFormat::OstmFileFormat()
|
|
|
|
: StreamFileFormat(), NativeFileFormat()
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2016-03-28 10:53:10 -05:00
|
|
|
// Do Nothing!
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-05-20 10:00:57 -05:00
|
|
|
bool OstmFileFormat::open(const QString fileName,
|
2015-04-16 11:50:07 -05:00
|
|
|
OstProto::StreamConfigList &streams, QString &error)
|
|
|
|
{
|
|
|
|
OstProto::FileMeta meta;
|
|
|
|
OstProto::FileContent content;
|
2016-04-13 21:14:07 -05:00
|
|
|
bool ret = NativeFileFormat::open(fileName, OstProto::kStreamsFileType,
|
|
|
|
meta, content, error);
|
2016-03-28 10:53:10 -05:00
|
|
|
if (!ret)
|
|
|
|
goto _fail;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
if (!content.matter().has_streams())
|
|
|
|
goto _missing_streams;
|
|
|
|
|
|
|
|
postParseFixup(meta.data(), content);
|
|
|
|
|
|
|
|
streams.CopyFrom(content.matter().streams());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
_missing_streams:
|
|
|
|
error = QString(tr("%1 does not contain any streams")).arg(fileName);
|
|
|
|
goto _fail;
|
|
|
|
_fail:
|
|
|
|
qDebug("%s", error.toAscii().constData());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-20 10:00:57 -05:00
|
|
|
bool OstmFileFormat::save(const OstProto::StreamConfigList streams,
|
2015-04-16 11:50:07 -05:00
|
|
|
const QString fileName, QString &error)
|
|
|
|
{
|
|
|
|
OstProto::FileContent content;
|
|
|
|
|
|
|
|
if (!streams.IsInitialized())
|
|
|
|
goto _stream_not_init;
|
|
|
|
|
|
|
|
content.mutable_matter()->mutable_streams()->CopyFrom(streams);
|
|
|
|
Q_ASSERT(content.IsInitialized());
|
|
|
|
|
2016-03-28 10:53:10 -05:00
|
|
|
return NativeFileFormat::save(OstProto::kStreamsFileType, content,
|
|
|
|
fileName, error);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
_stream_not_init:
|
|
|
|
error = QString(tr("Internal Error: Streams not initialized\n%1\n%2"))
|
|
|
|
.arg(QString().fromStdString(
|
|
|
|
streams.InitializationErrorString()))
|
|
|
|
.arg(QString().fromStdString(streams.DebugString()));
|
|
|
|
goto _fail;
|
|
|
|
_fail:
|
|
|
|
qDebug("%s", error.toAscii().constData());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
bool OstmFileFormat::isMyFileFormat(const QString fileName)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2016-03-28 10:53:10 -05:00
|
|
|
return isNativeFileFormat(fileName, OstProto::kStreamsFileType);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
bool OstmFileFormat::isMyFileType(const QString fileType)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
if (fileType.startsWith("Ostinato"))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|