Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Extract file format UI code into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
pstavirs committed Nov 16, 2023
1 parent 7143586 commit 8f89c57
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 24 deletions.
3 changes: 2 additions & 1 deletion client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion client/port.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions common/fileformatoptions.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
41 changes: 41 additions & 0 deletions common/fileformatoptions.h
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions common/ostfile.pro
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ HEADERS = \
streamfileformat.h

HEADERS += \
fileformatoptions.h \
pcapoptionsdialog.h

SOURCES += \
Expand All @@ -43,6 +44,7 @@ SOURCES += \
spinboxdelegate.cpp

SOURCES += \
fileformatoptions.cpp \
pcapoptionsdialog.cpp

SOURCES += \
Expand Down
4 changes: 2 additions & 2 deletions common/pcapfileformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ bool PcapFileFormat::save(const OstProto::StreamConfigList streams,
return isOk;
}

QDialog* PcapFileFormat::openOptionsDialog()
QVariantMap* PcapFileFormat::options()
{
return new PcapImportOptionsDialog(&importOptions_);
return &importOptions_;
}

bool PcapFileFormat::isMyFileFormat(const QString /*fileName*/)
Expand Down
2 changes: 1 addition & 1 deletion common/pcapfileformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PcapFileFormat : public StreamFileFormat
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);
Expand Down
2 changes: 2 additions & 0 deletions common/pcapoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions common/sessionfileformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ SessionFileFormat::~SessionFileFormat()
{
}

QDialog* SessionFileFormat::openOptionsDialog()
{
return NULL;
}

QDialog* SessionFileFormat::saveOptionsDialog()
QVariantMap* SessionFileFormat::options()
{
return NULL;
}
Expand Down
8 changes: 3 additions & 5 deletions common/sessionfileformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -42,8 +41,7 @@ class SessionFileFormat : public QThread
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);
Expand Down
7 changes: 1 addition & 6 deletions common/streamfileformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ StreamFileFormat::~StreamFileFormat()
{
}

QDialog* StreamFileFormat::openOptionsDialog()
{
return NULL;
}

QDialog* StreamFileFormat::saveOptionsDialog()
QVariantMap* StreamFileFormat::options()
{
return NULL;
}
Expand Down
3 changes: 1 addition & 2 deletions common/streamfileformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class StreamFileFormat : public QThread
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);
Expand Down

0 comments on commit 8f89c57

Please sign in to comment.