Save/Open Session - Implemented OssnFileFormat; code to build SessionContent still pending

This commit is contained in:
Srivats P 2016-03-29 18:55:22 +05:30
parent c98104f078
commit 2a77f73e9c
4 changed files with 59 additions and 11 deletions

View File

@ -19,28 +19,73 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "ossnfileformat.h" #include "ossnfileformat.h"
OssnFileFormat ossnFileFormat;
OssnFileFormat::OssnFileFormat()
: SessionFileFormat(), NativeFileFormat()
{
// Do Nothing
}
bool OssnFileFormat::open(const QString fileName, bool OssnFileFormat::open(const QString fileName,
OstProto::SessionContent &session, QString &error) OstProto::SessionContent &session, QString &error)
{ {
// TODO OstProto::FileMeta meta;
OstProto::FileContent content;
bool ret = NativeFileFormat::open(fileName, meta, content, error);
if (!ret)
goto _exit;
if (!content.matter().has_session())
goto _missing_session;
postParseFixup(meta.data(), content);
session.CopyFrom(content.matter().streams());
return true;
_missing_session:
error = QString(tr("%1 does not contain a session")).arg(fileName);
goto _fail;
_fail:
qDebug("%s", error.toAscii().constData());
_exit:
return false; return false;
} }
bool OssnFileFormat::save(const OstProto::SessionContent &session, bool OssnFileFormat::save(const OstProto::SessionContent &session,
const QString fileName, QString &error) const QString fileName, QString &error)
{ {
// TODO OstProto::FileContent content;
if (!session.IsInitialized())
goto _session_not_init;
content.mutable_matter()->mutable_session()->CopyFrom(session);
Q_ASSERT(content.IsInitialized());
return NativeFileFormat::save(OstProto::kSessionFileType, content,
fileName, error);
_session_not_init:
error = QString(tr("Internal Error: Session not initialized\n%1\n%2"))
.arg(QString().fromStdString(
session.InitializationErrorString()))
.arg(QString().fromStdString(session.DebugString()));
goto _fail;
_fail:
qDebug("%s", error.toAscii().constData());
return false; return false;
} }
bool OssnFileFormat::isMyFileFormat(const QString fileName) bool OssnFileFormat::isMyFileFormat(const QString fileName)
{ {
// TODO return isNativeFileFormat(fileName, OstProto::kSessionFileType);
return true;
} }
bool OssnFileFormat::isMyFileType(const QString fileType) bool OssnFileFormat::isMyFileType(const QString fileType)
{ {
// TODO return fileType.contains("(*.ossn)") ? true : false;
return true;
} }

View File

@ -20,11 +20,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifndef _OSSN_FILE_FORMAT_H #ifndef _OSSN_FILE_FORMAT_H
#define _OSSN_FILE_FORMAT_H #define _OSSN_FILE_FORMAT_H
#include "nativefileformat.h"
#include "sessionfileformat.h" #include "sessionfileformat.h"
class OssnFileFormat : public SessionFileFormat class OssnFileFormat : public SessionFileFormat, public NativeFileFormat
{ {
public: public:
OssnFileFormat();
virtual bool open(const QString fileName, virtual bool open(const QString fileName,
OstProto::SessionContent &session, QString &error); OstProto::SessionContent &session, QString &error);
virtual bool save(const OstProto::SessionContent &session, virtual bool save(const OstProto::SessionContent &session,

View File

@ -48,7 +48,7 @@ QStringList SessionFileFormat::supportedFileTypes()
<< "Ostinato Session (*.ossn)"; << "Ostinato Session (*.ossn)";
} }
void SessionFileFormat::openOffline(const QString fileName, void SessionFileFormat::openAsync(const QString fileName,
OstProto::SessionContent &session, QString &error) OstProto::SessionContent &session, QString &error)
{ {
fileName_ = fileName; fileName_ = fileName;
@ -60,7 +60,7 @@ void SessionFileFormat::openOffline(const QString fileName,
start(); start();
} }
void SessionFileFormat::saveOffline( void SessionFileFormat::saveAsync(
const OstProto::SessionContent &session, const OstProto::SessionContent &session,
const QString fileName, QString &error) const QString fileName, QString &error)
{ {

View File

@ -43,9 +43,9 @@ public:
virtual QDialog* openOptionsDialog(); virtual QDialog* openOptionsDialog();
virtual QDialog* saveOptionsDialog(); virtual QDialog* saveOptionsDialog();
void openOffline(const QString fileName, void openAsync(const QString fileName,
OstProto::SessionContent &session, QString &error); OstProto::SessionContent &session, QString &error);
void saveOffline(const OstProto::SessionContent &session, void saveAsync(const OstProto::SessionContent &session,
const QString fileName, QString &error); const QString fileName, QString &error);
bool result(); bool result();