Extract file format UI code into separate files

This commit is contained in:
Srivats P 2022-11-16 16:24:08 +05:30
parent 71435869cf
commit 8f89c577ef
12 changed files with 105 additions and 24 deletions

View File

@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#endif
#include "clipboardhelper.h"
#include "fileformatoptions.h"
#include "jumpurl.h"
#include "logsmodel.h"
#include "logswindow.h"
@ -547,7 +548,7 @@ bool MainWindow::openSession(QString fileName, QString &error)
goto _fail;
}
if ((optDialog = fmt->openOptionsDialog()))
if ((optDialog = FileFormatOptions::openOptionsDialog(fmt)))
{
int ret;
optDialog->setParent(this, Qt::Dialog);

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "port.h"
#include "emulation.h"
#include "fileformatoptions.h"
#include "streamfileformat.h"
#include <QApplication>
@ -604,7 +605,7 @@ bool Port::openStreams(QString fileName, bool append, QString &error)
goto _fail;
}
if ((optDialog = fmt->openOptionsDialog()))
if ((optDialog = FileFormatOptions::openOptionsDialog(fmt)))
{
int ret;
optDialog->setParent(mainWindow, Qt::Dialog);

View File

@ -0,0 +1,47 @@
/*
Copyright (C) 2022 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/>
*/
#include "fileformatoptions.h"
#include "pcapfileformat.h"
#include "pcapoptionsdialog.h"
#include "streamfileformat.h"
QDialog* FileFormatOptions::openOptionsDialog(StreamFileFormat *fileFormat)
{
if (dynamic_cast<PcapFileFormat*>(fileFormat))
return new PcapImportOptionsDialog(fileFormat->options());
return NULL;
}
QDialog* FileFormatOptions::saveOptionsDialog(StreamFileFormat* /*fileFormat*/)
{
return NULL;
}
QDialog* FileFormatOptions::openOptionsDialog(SessionFileFormat* /*fileFormat*/)
{
return NULL;
}
QDialog* FileFormatOptions::saveOptionsDialog(SessionFileFormat* /*fileFormat*/)
{
return NULL;
}

View File

@ -0,0 +1,41 @@
/*
Copyright (C) 2022 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/>
*/
#ifndef _FILE_FORMAT_OPTIONS_H
#define _FILE_FORMAT_OPTIONS_H
#include <QObject>
class SessionFileFormat;
class StreamFileFormat;
class QDialog;
class FileFormatOptions : QObject
{
Q_OBJECT
public:
static QDialog* openOptionsDialog(StreamFileFormat *fileFormat);
static QDialog* saveOptionsDialog(StreamFileFormat *fileFormat);
static QDialog* openOptionsDialog(SessionFileFormat *fileFormat);
static QDialog* saveOptionsDialog(SessionFileFormat *fileFormat);
};
#endif

View File

@ -25,6 +25,7 @@ HEADERS = \
streamfileformat.h
HEADERS += \
fileformatoptions.h \
pcapoptionsdialog.h
SOURCES += \
@ -43,6 +44,7 @@ SOURCES += \
spinboxdelegate.cpp
SOURCES += \
fileformatoptions.cpp \
pcapoptionsdialog.cpp
SOURCES += \

View File

@ -701,9 +701,9 @@ _exit:
return isOk;
}
QDialog* PcapFileFormat::openOptionsDialog()
QVariantMap* PcapFileFormat::options()
{
return new PcapImportOptionsDialog(&importOptions_);
return &importOptions_;
}
bool PcapFileFormat::isMyFileFormat(const QString /*fileName*/)

View File

@ -38,7 +38,7 @@ public:
bool save(const OstProto::StreamConfigList streams,
const QString fileName, QString &error);
virtual QDialog* openOptionsDialog();
virtual QVariantMap* options();
bool isMyFileFormat(const QString fileName);
bool isMyFileType(const QString fileType);

View File

@ -22,6 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
PcapImportOptionsDialog::PcapImportOptionsDialog(QVariantMap *options)
: QDialog(NULL)
{
Q_ASSERT(options != NULL);
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
options_ = options;

View File

@ -32,12 +32,7 @@ SessionFileFormat::~SessionFileFormat()
{
}
QDialog* SessionFileFormat::openOptionsDialog()
{
return NULL;
}
QDialog* SessionFileFormat::saveOptionsDialog()
QVariantMap* SessionFileFormat::options()
{
return NULL;
}

View File

@ -23,10 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "fileformat.pb.h"
#include "protocol.pb.h"
#include <QThread>
#include <QString>
class QDialog;
#include <QThread>
#include <QVariantMap>
class SessionFileFormat : public QThread
{
@ -42,8 +41,7 @@ public:
virtual bool save(const OstProto::SessionContent &session,
const QString fileName, QString &error) = 0;
virtual QDialog* openOptionsDialog();
virtual QDialog* saveOptionsDialog();
virtual QVariantMap* options();
void openAsync(const QString fileName,
OstProto::SessionContent &session, QString &error);

View File

@ -35,12 +35,7 @@ StreamFileFormat::~StreamFileFormat()
{
}
QDialog* StreamFileFormat::openOptionsDialog()
{
return NULL;
}
QDialog* StreamFileFormat::saveOptionsDialog()
QVariantMap* StreamFileFormat::options()
{
return NULL;
}

View File

@ -41,8 +41,7 @@ public:
virtual bool save(const OstProto::StreamConfigList streams,
const QString fileName, QString &error) = 0;
virtual QDialog* openOptionsDialog();
virtual QDialog* saveOptionsDialog();
virtual QVariantMap* options();
void openAsync(const QString fileName,
OstProto::StreamConfigList &streams, QString &error);