Refactor stream file supportedFileTypes() to accept operation - Open/Save and return fileTypes accordingly

This commit is contained in:
Srivats P 2016-05-19 21:05:32 +05:30
parent 822ee2a4b4
commit c8a31f3068
3 changed files with 24 additions and 20 deletions

View File

@ -812,7 +812,8 @@ void PortsWindow::on_actionOpen_Streams_triggered()
{
qDebug("Open Streams Action");
QStringList fileTypes = AbstractFileFormat::supportedFileTypes();
QStringList fileTypes = AbstractFileFormat::supportedFileTypes(
AbstractFileFormat::kOpenFile);
QString fileType;
QModelIndex current = tvPortList->selectionModel()->currentIndex();
static QString dirName;
@ -826,9 +827,6 @@ void PortsWindow::on_actionOpen_Streams_triggered()
Q_ASSERT(plm->isPort(current));
// cannot open Python Scripts
fileTypes.removeAt(fileTypes.indexOf("PythonScript (*.py)"));
fileTypes.append("All files (*)");
if (fileTypes.size())
fileType = fileTypes.at(0);
@ -887,7 +885,8 @@ void PortsWindow::on_actionSave_Streams_triggered()
QModelIndex current = tvPortList->selectionModel()->currentIndex();
static QString fileName;
QStringList fileTypes = AbstractFileFormat::supportedFileTypes();
QStringList fileTypes = AbstractFileFormat::supportedFileTypes(
AbstractFileFormat::kSaveFile);
QString fileType;
QString errorStr;
QFileDialog::Options options;

View File

@ -45,13 +45,21 @@ QDialog* AbstractFileFormat::saveOptionsDialog()
return NULL;
}
QStringList AbstractFileFormat::supportedFileTypes()
QStringList AbstractFileFormat::supportedFileTypes(Operation op)
{
return QStringList()
QStringList fileTypes;
fileTypes
<< "Ostinato (*.ostm)"
<< "PCAP (*)"
<< "PDML (*.pdml)"
<< "PythonScript (*.py)";
<< "PDML (*.pdml)";
if (op == kSaveFile)
fileTypes << "PythonScript (*.py)";
else if (op == kOpenFile)
fileTypes << "All files (*)";
return fileTypes;
}
void AbstractFileFormat::openStreamsOffline(const QString fileName,
@ -60,7 +68,7 @@ void AbstractFileFormat::openStreamsOffline(const QString fileName,
fileName_ = fileName;
openStreams_ = &streams;
error_ = &error;
op_ = kOpen;
op_ = kOpenFile;
stop_ = false;
start();
@ -73,7 +81,7 @@ void AbstractFileFormat::saveStreamsOffline(
saveStreams_ = streams;
fileName_ = fileName;
error_ = &error;
op_ = kSave;
op_ = kSaveFile;
stop_ = false;
start();
@ -125,8 +133,8 @@ void AbstractFileFormat::cancel()
void AbstractFileFormat::run()
{
if (op_ == kOpen)
if (op_ == kOpenFile)
result_ = openStreams(fileName_, *openStreams_, *error_);
else if (op_ == kSave)
else if (op_ == kSaveFile)
result_ = saveStreams(saveStreams_, fileName_, *error_);
}

View File

@ -31,6 +31,8 @@ class AbstractFileFormat : public QThread
{
Q_OBJECT
public:
enum Operation { kOpenFile, kSaveFile };
AbstractFileFormat();
virtual ~AbstractFileFormat();
@ -49,7 +51,7 @@ public:
bool result();
static QStringList supportedFileTypes();
static QStringList supportedFileTypes(Operation op);
static AbstractFileFormat* fileFormatFromFile(const QString fileName);
static AbstractFileFormat* fileFormatFromType(const QString fileType);
@ -73,16 +75,11 @@ protected:
bool stop_;
private:
enum kOp
{
kOpen,
kSave
};
QString fileName_;
OstProto::StreamConfigList *openStreams_;
OstProto::StreamConfigList saveStreams_;
QString *error_;
kOp op_;
Operation op_;
bool result_;
};