diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp index 69dfd8d..2daffdd 100644 --- a/client/mainwindow.cpp +++ b/client/mainwindow.cpp @@ -24,6 +24,7 @@ along with this program. If not, see #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); diff --git a/client/port.cpp b/client/port.cpp index f51e20b..ec8847e 100644 --- a/client/port.cpp +++ b/client/port.cpp @@ -20,6 +20,7 @@ along with this program. If not, see #include "port.h" #include "emulation.h" +#include "fileformatoptions.h" #include "streamfileformat.h" #include @@ -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); diff --git a/common/fileformatoptions.cpp b/common/fileformatoptions.cpp new file mode 100644 index 0000000..4d35024 --- /dev/null +++ b/common/fileformatoptions.cpp @@ -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 +*/ + +#include "fileformatoptions.h" + +#include "pcapfileformat.h" +#include "pcapoptionsdialog.h" +#include "streamfileformat.h" + +QDialog* FileFormatOptions::openOptionsDialog(StreamFileFormat *fileFormat) +{ + if (dynamic_cast(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; +} diff --git a/common/fileformatoptions.h b/common/fileformatoptions.h new file mode 100644 index 0000000..610879b --- /dev/null +++ b/common/fileformatoptions.h @@ -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 +*/ + +#ifndef _FILE_FORMAT_OPTIONS_H +#define _FILE_FORMAT_OPTIONS_H + +#include + +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 + diff --git a/common/ostfile.pro b/common/ostfile.pro index ce5d3fc..72949dc 100644 --- a/common/ostfile.pro +++ b/common/ostfile.pro @@ -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 += \ diff --git a/common/pcapfileformat.cpp b/common/pcapfileformat.cpp index d2c0fb1..e3284c9 100644 --- a/common/pcapfileformat.cpp +++ b/common/pcapfileformat.cpp @@ -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*/) diff --git a/common/pcapfileformat.h b/common/pcapfileformat.h index 5b5bf6a..e5a9d8d 100644 --- a/common/pcapfileformat.h +++ b/common/pcapfileformat.h @@ -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); diff --git a/common/pcapoptionsdialog.cpp b/common/pcapoptionsdialog.cpp index a1b7566..55f600b 100644 --- a/common/pcapoptionsdialog.cpp +++ b/common/pcapoptionsdialog.cpp @@ -22,6 +22,8 @@ along with this program. If not, see PcapImportOptionsDialog::PcapImportOptionsDialog(QVariantMap *options) : QDialog(NULL) { + Q_ASSERT(options != NULL); + setupUi(this); setAttribute(Qt::WA_DeleteOnClose); options_ = options; diff --git a/common/sessionfileformat.cpp b/common/sessionfileformat.cpp index 9e14530..a5ee459 100644 --- a/common/sessionfileformat.cpp +++ b/common/sessionfileformat.cpp @@ -32,12 +32,7 @@ SessionFileFormat::~SessionFileFormat() { } -QDialog* SessionFileFormat::openOptionsDialog() -{ - return NULL; -} - -QDialog* SessionFileFormat::saveOptionsDialog() +QVariantMap* SessionFileFormat::options() { return NULL; } diff --git a/common/sessionfileformat.h b/common/sessionfileformat.h index 31fe16c..14f375f 100644 --- a/common/sessionfileformat.h +++ b/common/sessionfileformat.h @@ -23,10 +23,9 @@ along with this program. If not, see #include "fileformat.pb.h" #include "protocol.pb.h" -#include #include - -class QDialog; +#include +#include 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); diff --git a/common/streamfileformat.cpp b/common/streamfileformat.cpp index 4e79ff7..4cbd7d6 100644 --- a/common/streamfileformat.cpp +++ b/common/streamfileformat.cpp @@ -35,12 +35,7 @@ StreamFileFormat::~StreamFileFormat() { } -QDialog* StreamFileFormat::openOptionsDialog() -{ - return NULL; -} - -QDialog* StreamFileFormat::saveOptionsDialog() +QVariantMap* StreamFileFormat::options() { return NULL; } diff --git a/common/streamfileformat.h b/common/streamfileformat.h index 474ab09..c04fdb7 100644 --- a/common/streamfileformat.h +++ b/common/streamfileformat.h @@ -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);