2021-11-03 10:38:26 -05:00
|
|
|
/*
|
|
|
|
Copyright (C) 2010 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/>
|
|
|
|
*/
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
#include "streamswidget.h"
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
#include "clipboardhelper.h"
|
2021-11-26 11:00:45 -06:00
|
|
|
#include "findreplace.h"
|
2021-11-05 04:57:37 -05:00
|
|
|
#include "portgrouplist.h"
|
2021-11-03 10:38:26 -05:00
|
|
|
#include "streamconfigdialog.h"
|
|
|
|
#include "streamfileformat.h"
|
|
|
|
#include "streamlistdelegate.h"
|
|
|
|
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QItemSelectionModel>
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
|
|
extern ClipboardHelper *clipboardHelper;
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
StreamsWidget::StreamsWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
2021-11-05 04:57:37 -05:00
|
|
|
setupUi(this);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
delegate = new StreamListDelegate;
|
|
|
|
tvStreamList->setItemDelegate(delegate);
|
|
|
|
|
|
|
|
tvStreamList->verticalHeader()->setDefaultSectionSize(
|
|
|
|
tvStreamList->verticalHeader()->minimumSectionSize());
|
|
|
|
|
|
|
|
// Populate StreamList Context Menu Actions
|
|
|
|
tvStreamList->addAction(actionNew_Stream);
|
|
|
|
tvStreamList->addAction(actionEdit_Stream);
|
|
|
|
tvStreamList->addAction(actionDuplicate_Stream);
|
|
|
|
tvStreamList->addAction(actionDelete_Stream);
|
|
|
|
|
|
|
|
QAction *sep2 = new QAction(this);
|
|
|
|
sep2->setSeparator(true);
|
|
|
|
tvStreamList->addAction(sep2);
|
|
|
|
|
2021-11-26 11:00:45 -06:00
|
|
|
tvStreamList->addAction(actionFind_Replace);
|
|
|
|
|
|
|
|
QAction *sep3 = new QAction(this);
|
|
|
|
sep3->setSeparator(true);
|
|
|
|
tvStreamList->addAction(sep3);
|
|
|
|
|
2021-11-03 10:38:26 -05:00
|
|
|
tvStreamList->addAction(actionOpen_Streams);
|
|
|
|
tvStreamList->addAction(actionSave_Streams);
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
// StreamWidget's actions is an aggegate of all sub-widget's actions
|
2021-11-03 10:38:26 -05:00
|
|
|
addActions(tvStreamList->actions());
|
|
|
|
|
|
|
|
// Add the clipboard actions to the context menu of streamList
|
2021-11-05 04:57:37 -05:00
|
|
|
// but not to StreamsWidget's actions since they are already available
|
2021-11-03 10:38:26 -05:00
|
|
|
// in the global Edit Menu
|
2021-11-26 11:00:45 -06:00
|
|
|
QAction *sep4 = new QAction("Clipboard", this);
|
|
|
|
sep4->setSeparator(true);
|
|
|
|
tvStreamList->insertAction(sep2, sep4);
|
2021-11-03 10:38:26 -05:00
|
|
|
tvStreamList->insertActions(sep2, clipboardHelper->actions());
|
2021-11-05 04:57:37 -05:00
|
|
|
}
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::setPortGroupList(PortGroupList *portGroups)
|
|
|
|
{
|
|
|
|
plm = portGroups;
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
tvStreamList->setModel(plm->getStreamModel());
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
connect(plm->getStreamModel(), SIGNAL(rowsInserted(QModelIndex, int, int)),
|
|
|
|
SLOT(updateStreamViewActions()));
|
|
|
|
connect(plm->getStreamModel(), SIGNAL(rowsRemoved(QModelIndex, int, int)),
|
|
|
|
SLOT(updateStreamViewActions()));
|
|
|
|
|
|
|
|
connect(tvStreamList->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
SLOT(updateStreamViewActions()));
|
|
|
|
connect(tvStreamList->selectionModel(),
|
|
|
|
SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
|
|
|
|
SLOT(updateStreamViewActions()));
|
|
|
|
|
|
|
|
tvStreamList->resizeColumnToContents(StreamModel::StreamIcon);
|
|
|
|
tvStreamList->resizeColumnToContents(StreamModel::StreamStatus);
|
|
|
|
|
|
|
|
updateStreamViewActions();
|
|
|
|
|
|
|
|
connect(plm->getStreamModel(),
|
|
|
|
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT(streamModelDataChanged()));
|
|
|
|
connect(plm->getStreamModel(),
|
|
|
|
SIGNAL(modelReset()),
|
|
|
|
this, SLOT(streamModelDataChanged()));
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::streamModelDataChanged()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
2021-11-05 04:57:37 -05:00
|
|
|
if (plm->isPort(currentPortIndex_))
|
|
|
|
plm->port(currentPortIndex_).recalculateAverageRates();
|
2021-11-03 10:38:26 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
StreamsWidget::~StreamsWidget()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
delete delegate;
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_tvStreamList_activated(const QModelIndex & index)
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
qDebug("%s: invalid index", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug("stream list activated\n");
|
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
Port &curPort = plm->port(currentPortIndex_);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
QList<Stream*> streams;
|
|
|
|
streams.append(curPort.mutableStreamByIndex(index.row(), false));
|
|
|
|
|
|
|
|
StreamConfigDialog scd(streams, curPort, this);
|
|
|
|
if (scd.exec() == QDialog::Accepted) {
|
|
|
|
curPort.recalculateAverageRates();
|
|
|
|
curPort.setLocalConfigChanged(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::setCurrentPortIndex(const QModelIndex &portIndex)
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
2021-11-05 04:57:37 -05:00
|
|
|
if (!plm)
|
|
|
|
return;
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
// XXX: We assume portIndex corresponds to sourceModel, not proxyModel;
|
|
|
|
// caller should ensure this
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
qDebug("In %s", __PRETTY_FUNCTION__);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
currentPortIndex_ = portIndex;
|
|
|
|
plm->getStreamModel()->setCurrentPortIndex(portIndex);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
updateStreamViewActions();
|
2021-11-03 10:38:26 -05:00
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::updateStreamViewActions()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
// For some reason hasSelection() returns true even if selection size is 0
|
|
|
|
// so additional check for size introduced
|
|
|
|
if (tvStreamList->selectionModel()->hasSelection() &&
|
|
|
|
(tvStreamList->selectionModel()->selection().size() > 0))
|
|
|
|
{
|
|
|
|
qDebug("Has selection %d",
|
|
|
|
tvStreamList->selectionModel()->selection().size());
|
|
|
|
|
|
|
|
// If more than one non-contiguous ranges selected,
|
|
|
|
// disable "New" and "Edit"
|
|
|
|
if (tvStreamList->selectionModel()->selection().size() > 1)
|
|
|
|
{
|
|
|
|
actionNew_Stream->setDisabled(true);
|
|
|
|
actionEdit_Stream->setDisabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
actionNew_Stream->setEnabled(true);
|
|
|
|
actionEdit_Stream->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duplicate/Delete are always enabled as long as we have a selection
|
|
|
|
actionDuplicate_Stream->setEnabled(true);
|
|
|
|
actionDelete_Stream->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("No selection");
|
2021-11-05 04:57:37 -05:00
|
|
|
if (plm->isPort(currentPortIndex_))
|
2021-11-03 10:38:26 -05:00
|
|
|
actionNew_Stream->setEnabled(true);
|
|
|
|
else
|
|
|
|
actionNew_Stream->setDisabled(true);
|
|
|
|
actionEdit_Stream->setDisabled(true);
|
|
|
|
actionDuplicate_Stream->setDisabled(true);
|
|
|
|
actionDelete_Stream->setDisabled(true);
|
|
|
|
}
|
2021-11-26 11:00:45 -06:00
|
|
|
|
|
|
|
actionFind_Replace->setEnabled(tvStreamList->model()->rowCount() > 0);
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
actionOpen_Streams->setEnabled(plm->isPort(currentPortIndex_));
|
2021-11-03 10:38:26 -05:00
|
|
|
actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0);
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionNew_Stream_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
qDebug("New Stream Action");
|
|
|
|
|
|
|
|
QItemSelectionModel* selectionModel = tvStreamList->selectionModel();
|
|
|
|
if (selectionModel->selection().size() > 1) {
|
|
|
|
qDebug("%s: Unexpected selection size %d, can't add", __FUNCTION__,
|
|
|
|
selectionModel->selection().size());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case nothing is selected, insert 1 row at the end
|
|
|
|
StreamModel *streamModel = plm->getStreamModel();
|
|
|
|
int row = streamModel->rowCount(), count = 1;
|
|
|
|
|
|
|
|
// In case we have a single range selected; insert as many rows as
|
|
|
|
// in the singe selected range before the top of the selected range
|
|
|
|
if (selectionModel->selection().size() == 1)
|
|
|
|
{
|
|
|
|
row = selectionModel->selection().at(0).top();
|
|
|
|
count = selectionModel->selection().at(0).height();
|
|
|
|
}
|
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
Port &curPort = plm->port(currentPortIndex_);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
QList<Stream*> streams;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
streams.append(new Stream);
|
|
|
|
|
|
|
|
StreamConfigDialog scd(streams, curPort, this);
|
|
|
|
scd.setWindowTitle(tr("Add Stream"));
|
|
|
|
if (scd.exec() == QDialog::Accepted)
|
|
|
|
streamModel->insert(row, streams);
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionEdit_Stream_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
qDebug("Edit Stream Action");
|
|
|
|
|
|
|
|
QItemSelectionModel* streamModel = tvStreamList->selectionModel();
|
|
|
|
if (!streamModel->hasSelection())
|
|
|
|
return;
|
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
Port &curPort = plm->port(currentPortIndex_);
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
QList<Stream*> streams;
|
|
|
|
foreach(QModelIndex index, streamModel->selectedRows())
|
|
|
|
streams.append(curPort.mutableStreamByIndex(index.row(), false));
|
|
|
|
|
|
|
|
StreamConfigDialog scd(streams, curPort, this);
|
|
|
|
if (scd.exec() == QDialog::Accepted) {
|
|
|
|
curPort.recalculateAverageRates();
|
|
|
|
curPort.setLocalConfigChanged(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionDuplicate_Stream_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
QItemSelectionModel* model = tvStreamList->selectionModel();
|
|
|
|
|
|
|
|
qDebug("Duplicate Stream Action");
|
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
|
|
|
|
2021-11-03 10:38:26 -05:00
|
|
|
if (model->hasSelection())
|
|
|
|
{
|
|
|
|
bool isOk;
|
|
|
|
int count = QInputDialog::getInt(this, "Duplicate Streams",
|
|
|
|
"Count", 1, 1, 9999, 1, &isOk);
|
|
|
|
|
|
|
|
if (!isOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QList<int> list;
|
|
|
|
foreach(QModelIndex index, model->selectedRows())
|
|
|
|
list.append(index.row());
|
2021-11-05 04:57:37 -05:00
|
|
|
plm->port(currentPortIndex_).duplicateStreams(list, count);
|
2021-11-03 10:38:26 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
qDebug("No selection");
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionDelete_Stream_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
qDebug("Delete Stream Action");
|
|
|
|
|
|
|
|
QModelIndex index;
|
|
|
|
|
|
|
|
if (tvStreamList->selectionModel()->hasSelection())
|
|
|
|
{
|
|
|
|
qDebug("SelectedIndexes %d",
|
|
|
|
tvStreamList->selectionModel()->selectedRows().size());
|
|
|
|
while(tvStreamList->selectionModel()->selectedRows().size())
|
|
|
|
{
|
|
|
|
index = tvStreamList->selectionModel()->selectedRows().at(0);
|
|
|
|
plm->getStreamModel()->removeRows(index.row(), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
qDebug("No selection");
|
|
|
|
}
|
|
|
|
|
2021-11-26 11:00:45 -06:00
|
|
|
void StreamsWidget::on_actionFind_Replace_triggered()
|
|
|
|
{
|
|
|
|
qDebug("Find & Replace Action");
|
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
|
|
|
|
2021-11-27 10:43:55 -06:00
|
|
|
QItemSelectionModel* selectionModel = tvStreamList->selectionModel();
|
|
|
|
FindReplaceDialog::Action action;
|
|
|
|
|
|
|
|
action.selectedStreamsOnly = selectionModel->selection().size() > 0 ?
|
|
|
|
true : false;
|
|
|
|
|
|
|
|
FindReplaceDialog findReplace(&action, this);
|
2021-11-26 11:00:45 -06:00
|
|
|
if (findReplace.exec() == QDialog::Accepted) {
|
2021-12-11 01:06:33 -06:00
|
|
|
QProgressDialog progress(this);
|
|
|
|
progress.setLabelText(tr("Replacing %1 ...").arg(action.protocolField));
|
|
|
|
progress.setWindowModality(Qt::WindowModal);
|
2021-12-08 22:44:47 -06:00
|
|
|
int c, fc = 0, sc = 0; // replace counts
|
2021-11-27 10:43:55 -06:00
|
|
|
Port &port = plm->port(currentPortIndex_);
|
|
|
|
if (action.selectedStreamsOnly) {
|
2021-12-11 01:06:33 -06:00
|
|
|
QModelIndexList selected = selectionModel->selectedRows();
|
|
|
|
int count = selected.size();
|
|
|
|
progress.setMaximum(count);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
QModelIndex index = selected.at(i);
|
2021-11-27 10:43:55 -06:00
|
|
|
Stream *stream = port.mutableStreamByIndex(index.row(), false);
|
2021-12-08 22:44:47 -06:00
|
|
|
c = stream->protocolFieldReplace(action.protocolNumber,
|
2021-12-03 07:31:32 -06:00
|
|
|
action.fieldIndex,
|
|
|
|
action.fieldBitSize,
|
|
|
|
action.findValue,
|
|
|
|
action.findMask,
|
|
|
|
action.replaceValue,
|
2021-12-08 22:44:47 -06:00
|
|
|
action.replaceMask);
|
|
|
|
if (c) {
|
|
|
|
fc += c;
|
|
|
|
sc++;
|
|
|
|
}
|
2021-12-11 01:06:33 -06:00
|
|
|
progress.setValue(i+1);
|
|
|
|
if (progress.wasCanceled())
|
|
|
|
break;
|
2021-11-27 10:43:55 -06:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int count = tvStreamList->model()->rowCount();
|
2021-12-11 01:06:33 -06:00
|
|
|
progress.setMaximum(count);
|
2021-11-27 10:43:55 -06:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
Stream *stream = port.mutableStreamByIndex(i, false);
|
2021-12-08 22:44:47 -06:00
|
|
|
c = stream->protocolFieldReplace(action.protocolNumber,
|
2021-12-03 07:31:32 -06:00
|
|
|
action.fieldIndex,
|
|
|
|
action.fieldBitSize,
|
|
|
|
action.findValue,
|
|
|
|
action.findMask,
|
|
|
|
action.replaceValue,
|
2021-12-08 22:44:47 -06:00
|
|
|
action.replaceMask);
|
|
|
|
if (c) {
|
|
|
|
fc += c;
|
|
|
|
sc++;
|
|
|
|
}
|
2021-12-11 01:06:33 -06:00
|
|
|
progress.setValue(i+1);
|
|
|
|
if (progress.wasCanceled())
|
|
|
|
break;
|
2021-11-27 10:43:55 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 22:44:47 -06:00
|
|
|
if (fc)
|
2021-11-27 10:43:55 -06:00
|
|
|
port.setLocalConfigChanged(true);
|
2021-12-03 07:31:32 -06:00
|
|
|
|
|
|
|
QMessageBox::information(this, tr("Find & Replace"),
|
2021-12-08 22:44:47 -06:00
|
|
|
tr("%1 fields replaced in %2 streams").arg(fc).arg(sc));
|
2021-12-03 07:31:32 -06:00
|
|
|
|
2021-11-26 11:00:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionOpen_Streams_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
qDebug("Open Streams Action");
|
|
|
|
|
|
|
|
QStringList fileTypes = StreamFileFormat::supportedFileTypes(
|
|
|
|
StreamFileFormat::kOpenFile);
|
|
|
|
QString fileType;
|
|
|
|
static QString dirName;
|
|
|
|
QString fileName;
|
|
|
|
QString errorStr;
|
|
|
|
bool append = true;
|
|
|
|
bool ret;
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
|
|
|
fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"),
|
|
|
|
dirName, fileTypes.join(";;"), &fileType);
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if (tvStreamList->model()->rowCount())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox(QMessageBox::Question, qApp->applicationName(),
|
|
|
|
tr("Append to existing streams? Or overwrite?"),
|
|
|
|
QMessageBox::NoButton, this);
|
|
|
|
QPushButton *appendBtn = msgBox.addButton(tr("Append"),
|
|
|
|
QMessageBox::ActionRole);
|
|
|
|
QPushButton *overwriteBtn = msgBox.addButton(tr("Overwrite"),
|
|
|
|
QMessageBox::ActionRole);
|
|
|
|
QPushButton *cancelBtn = msgBox.addButton(QMessageBox::Cancel);
|
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
if (msgBox.clickedButton() == cancelBtn)
|
|
|
|
goto _exit;
|
|
|
|
else if (msgBox.clickedButton() == appendBtn)
|
|
|
|
append = true;
|
|
|
|
else if (msgBox.clickedButton() == overwriteBtn)
|
|
|
|
append = false;
|
|
|
|
else
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
ret = plm->port(currentPortIndex_).openStreams(fileName, append, errorStr);
|
2021-11-03 10:38:26 -05:00
|
|
|
if (!ret || !errorStr.isEmpty())
|
|
|
|
{
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
QStringList str = errorStr.split("\n\n\n\n");
|
|
|
|
|
|
|
|
msgBox.setIcon(ret ? QMessageBox::Warning : QMessageBox::Critical);
|
|
|
|
msgBox.setWindowTitle(qApp->applicationName());
|
|
|
|
msgBox.setText(str.at(0));
|
|
|
|
if (str.size() > 1)
|
|
|
|
msgBox.setDetailedText(str.at(1));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
}
|
|
|
|
dirName = QFileInfo(fileName).absolutePath();
|
2021-11-05 04:57:37 -05:00
|
|
|
updateStreamViewActions();
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
void StreamsWidget::on_actionSave_Streams_triggered()
|
2021-11-03 10:38:26 -05:00
|
|
|
{
|
|
|
|
qDebug("Save Streams Action");
|
|
|
|
|
|
|
|
static QString fileName;
|
|
|
|
QStringList fileTypes = StreamFileFormat::supportedFileTypes(
|
|
|
|
StreamFileFormat::kSaveFile);
|
|
|
|
QString fileType;
|
|
|
|
QString errorStr;
|
|
|
|
QFileDialog::Options options;
|
|
|
|
|
|
|
|
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
|
|
|
// which we need
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
options |= QFileDialog::DontUseNativeDialog;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
Q_ASSERT(plm->isPort(currentPortIndex_));
|
2021-11-03 10:38:26 -05:00
|
|
|
|
|
|
|
_retry:
|
|
|
|
fileName = QFileDialog::getSaveFileName(this, tr("Save Streams"),
|
|
|
|
fileName, fileTypes.join(";;"), &fileType, options);
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
if (QFileInfo(fileName).suffix().isEmpty()) {
|
|
|
|
QString fileExt = fileType.section(QRegExp("[\\*\\)]"), 1, 1);
|
|
|
|
qDebug("Adding extension '%s' to '%s'",
|
|
|
|
qPrintable(fileExt), qPrintable(fileName));
|
|
|
|
fileName.append(fileExt);
|
|
|
|
if (QFileInfo(fileName).exists()) {
|
|
|
|
if (QMessageBox::warning(this, tr("Overwrite File?"),
|
|
|
|
QString("The file \"%1\" already exists.\n\n"
|
|
|
|
"Do you wish to overwrite it?")
|
|
|
|
.arg(QFileInfo(fileName).fileName()),
|
|
|
|
QMessageBox::Yes|QMessageBox::No,
|
|
|
|
QMessageBox::No) != QMessageBox::Yes)
|
|
|
|
goto _retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileType = fileType.remove(QRegExp("\\(.*\\)")).trimmed();
|
|
|
|
if (!fileType.startsWith("Ostinato")
|
|
|
|
&& !fileType.startsWith("Python"))
|
|
|
|
{
|
|
|
|
if (QMessageBox::warning(this, tr("Ostinato"),
|
|
|
|
QString("You have chosen to save in %1 format. All stream "
|
|
|
|
"attributes may not be saved in this format.\n\n"
|
|
|
|
"It is recommended to save in native Ostinato format.\n\n"
|
|
|
|
"Continue to save in %2 format?").arg(fileType).arg(fileType),
|
|
|
|
QMessageBox::Yes|QMessageBox::No,
|
|
|
|
QMessageBox::No) != QMessageBox::Yes)
|
|
|
|
goto _retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: all or selected?
|
|
|
|
|
2021-11-05 04:57:37 -05:00
|
|
|
if (!plm->port(currentPortIndex_).saveStreams(fileName, fileType, errorStr))
|
2021-11-03 10:38:26 -05:00
|
|
|
QMessageBox::critical(this, qApp->applicationName(), errorStr);
|
|
|
|
else if (!errorStr.isEmpty())
|
|
|
|
QMessageBox::warning(this, qApp->applicationName(), errorStr);
|
|
|
|
|
|
|
|
fileName = QFileInfo(fileName).absolutePath();
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|