2015-04-16 11:50:07 -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/>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portswindow.h"
|
|
|
|
|
2019-02-22 07:28:13 -06:00
|
|
|
#include "applymsg.h"
|
2016-03-13 09:21:32 -05:00
|
|
|
#include "deviceswidget.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
#include "portconfigdialog.h"
|
2015-05-03 11:48:54 -05:00
|
|
|
#include "settings.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
#include "streamconfigdialog.h"
|
2016-05-19 11:24:28 -05:00
|
|
|
#include "streamfileformat.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
#include "streamlistdelegate.h"
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
#include "fileformat.pb.h"
|
|
|
|
|
2018-09-15 01:10:11 -05:00
|
|
|
#include "xqlocale.h"
|
2018-09-14 09:54:30 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QItemSelectionModel>
|
2016-04-13 21:14:07 -05:00
|
|
|
#include <QMainWindow>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QMessageBox>
|
2015-05-03 11:48:54 -05:00
|
|
|
#include <QSortFilterProxyModel>
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
extern QMainWindow *mainWindow;
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
PortsWindow::PortsWindow(PortGroupList *pgl, QWidget *parent)
|
2015-05-03 11:48:54 -05:00
|
|
|
: QWidget(parent), proxyPortModel(NULL)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
|
|
|
QAction *sep;
|
|
|
|
|
|
|
|
delegate = new StreamListDelegate;
|
2015-05-03 11:48:54 -05:00
|
|
|
proxyPortModel = new QSortFilterProxyModel(this);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
//slm = new StreamListModel();
|
|
|
|
//plm = new PortGroupList();
|
|
|
|
plm = pgl;
|
|
|
|
|
|
|
|
setupUi(this);
|
2019-02-22 07:28:13 -06:00
|
|
|
applyMsg_ = new ApplyMessage();
|
2016-03-13 09:21:32 -05:00
|
|
|
devicesWidget->setPortGroupList(plm);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
tvPortList->header()->hide();
|
|
|
|
|
|
|
|
tvStreamList->setItemDelegate(delegate);
|
|
|
|
|
|
|
|
tvStreamList->verticalHeader()->setDefaultSectionSize(
|
|
|
|
tvStreamList->verticalHeader()->minimumSectionSize());
|
|
|
|
|
|
|
|
// Populate PortList Context Menu Actions
|
|
|
|
tvPortList->addAction(actionNew_Port_Group);
|
|
|
|
tvPortList->addAction(actionDelete_Port_Group);
|
|
|
|
tvPortList->addAction(actionConnect_Port_Group);
|
|
|
|
tvPortList->addAction(actionDisconnect_Port_Group);
|
|
|
|
|
|
|
|
tvPortList->addAction(actionExclusive_Control);
|
|
|
|
tvPortList->addAction(actionPort_Configuration);
|
|
|
|
|
2016-03-13 09:21:32 -05:00
|
|
|
// Populate StreamList Context Menu Actions
|
2015-04-16 11:50:07 -05:00
|
|
|
tvStreamList->addAction(actionNew_Stream);
|
|
|
|
tvStreamList->addAction(actionEdit_Stream);
|
|
|
|
tvStreamList->addAction(actionDuplicate_Stream);
|
|
|
|
tvStreamList->addAction(actionDelete_Stream);
|
|
|
|
|
|
|
|
sep = new QAction(this);
|
|
|
|
sep->setSeparator(true);
|
|
|
|
tvStreamList->addAction(sep);
|
|
|
|
|
|
|
|
tvStreamList->addAction(actionOpen_Streams);
|
|
|
|
tvStreamList->addAction(actionSave_Streams);
|
|
|
|
|
2016-03-13 09:21:32 -05:00
|
|
|
// PortList, StreamList, DeviceWidget actions combined
|
2016-02-22 07:17:51 -06:00
|
|
|
// make this window's actions
|
2015-04-16 11:50:07 -05:00
|
|
|
addActions(tvPortList->actions());
|
|
|
|
sep = new QAction(this);
|
|
|
|
sep->setSeparator(true);
|
|
|
|
addAction(sep);
|
|
|
|
addActions(tvStreamList->actions());
|
2016-02-22 07:17:51 -06:00
|
|
|
sep = new QAction(this);
|
|
|
|
sep->setSeparator(true);
|
|
|
|
addAction(sep);
|
2016-03-13 09:21:32 -05:00
|
|
|
addActions(devicesWidget->actions());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
tvStreamList->setModel(plm->getStreamModel());
|
2015-05-03 11:48:54 -05:00
|
|
|
|
|
|
|
// XXX: It would be ideal if we only needed to do the below to
|
|
|
|
// get the proxy model to do its magic. However, the QModelIndex
|
|
|
|
// used by the source model and the proxy model are different
|
|
|
|
// i.e. the row, column, internalId/internalPtr used by both
|
|
|
|
// will be different. Since our domain objects - PortGroupList,
|
|
|
|
// PortGroup, Port etc. use these attributes, we need to map the
|
|
|
|
// proxy's index to the source's index before invoking any domain
|
|
|
|
// object methods
|
|
|
|
// TODO: research if we can skip the mapping when the domain
|
|
|
|
// objects' design is reviewed
|
|
|
|
if (proxyPortModel) {
|
|
|
|
proxyPortModel->setSourceModel(plm->getPortModel());
|
|
|
|
tvPortList->setModel(proxyPortModel);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tvPortList->setModel(plm->getPortModel());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
connect( plm->getPortModel(),
|
|
|
|
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT(when_portModel_dataChanged(const QModelIndex&,
|
|
|
|
const QModelIndex&)));
|
|
|
|
|
|
|
|
connect(plm->getPortModel(), SIGNAL(modelReset()),
|
|
|
|
SLOT(when_portModel_reset()));
|
|
|
|
|
|
|
|
connect( tvPortList->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT(when_portView_currentChanged(const QModelIndex&,
|
|
|
|
const QModelIndex&)));
|
2016-03-13 09:21:32 -05:00
|
|
|
connect(this,
|
|
|
|
SIGNAL(currentPortChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
devicesWidget, SLOT(setCurrentPortIndex(const QModelIndex&)));
|
2015-04-16 11:50:07 -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);
|
|
|
|
|
2016-02-22 08:49:33 -06:00
|
|
|
// Initially we don't have any ports/streams/devices
|
|
|
|
// - so send signal triggers
|
2015-04-16 11:50:07 -05:00
|
|
|
when_portView_currentChanged(QModelIndex(), QModelIndex());
|
|
|
|
updateStreamViewActions();
|
|
|
|
|
|
|
|
connect(plm->getStreamModel(),
|
|
|
|
SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
|
|
|
|
this, SLOT(streamModelDataChanged()));
|
|
|
|
connect(plm->getStreamModel(),
|
|
|
|
SIGNAL(modelReset()),
|
|
|
|
this, SLOT(streamModelDataChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::streamModelDataChanged()
|
|
|
|
{
|
2015-05-03 11:48:54 -05:00
|
|
|
QModelIndex current = tvPortList->currentIndex();
|
|
|
|
|
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
|
|
|
if (plm->isPort(current))
|
|
|
|
plm->port(current).recalculateAverageRates();
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
PortsWindow::~PortsWindow()
|
|
|
|
{
|
|
|
|
delete delegate;
|
2015-05-03 11:48:54 -05:00
|
|
|
delete proxyPortModel;
|
2019-02-22 07:28:13 -06:00
|
|
|
delete applyMsg_;
|
2015-05-03 11:48:54 -05:00
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
int PortsWindow::portGroupCount()
|
|
|
|
{
|
|
|
|
return plm->numPortGroups();
|
|
|
|
}
|
|
|
|
|
2016-05-06 10:54:36 -05:00
|
|
|
int PortsWindow::reservedPortCount()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
int n = portGroupCount();
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
count += plm->portGroupByIndex(i).numReservedPorts();
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
//! Always return true
|
|
|
|
bool PortsWindow::openSession(
|
|
|
|
const OstProto::SessionContent *session,
|
2016-06-01 10:21:29 -05:00
|
|
|
QString & /*error*/)
|
2016-04-13 21:14:07 -05:00
|
|
|
{
|
|
|
|
QProgressDialog progress("Opening Session", NULL,
|
|
|
|
0, session->port_groups_size(), mainWindow);
|
|
|
|
progress.show();
|
|
|
|
progress.setEnabled(true); // since parent (mainWindow) is disabled
|
|
|
|
|
|
|
|
plm->removeAllPortGroups();
|
|
|
|
|
|
|
|
for (int i = 0; i < session->port_groups_size(); i++) {
|
|
|
|
const OstProto::PortGroupContent &pgc = session->port_groups(i);
|
|
|
|
PortGroup *pg = new PortGroup(QString::fromStdString(
|
|
|
|
pgc.server_name()),
|
|
|
|
quint16(pgc.server_port()));
|
|
|
|
pg->setConfigAtConnect(&pgc);
|
|
|
|
plm->addPortGroup(*pg);
|
|
|
|
progress.setValue(i+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Prepare content to be saved for a session
|
|
|
|
*
|
2016-05-06 10:54:36 -05:00
|
|
|
* If port reservation is in use, saves only 'my' reserved ports
|
|
|
|
*
|
2016-04-13 21:14:07 -05:00
|
|
|
* Returns false, if user cancels op; true, otherwise
|
|
|
|
*/
|
|
|
|
bool PortsWindow::saveSession(
|
|
|
|
OstProto::SessionContent *session, // OUT param
|
2016-06-01 10:21:29 -05:00
|
|
|
QString & /*error*/,
|
2016-04-13 21:14:07 -05:00
|
|
|
QProgressDialog *progress)
|
|
|
|
{
|
|
|
|
int n = portGroupCount();
|
2016-05-06 10:54:36 -05:00
|
|
|
QString myself;
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
if (progress) {
|
|
|
|
progress->setLabelText("Preparing Ports and PortGroups ...");
|
|
|
|
progress->setRange(0, n);
|
|
|
|
}
|
|
|
|
|
2016-05-06 10:54:36 -05:00
|
|
|
if (reservedPortCount())
|
|
|
|
myself = appSettings->value(kUserKey, kUserDefaultValue).toString();
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
for (int i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
PortGroup &pg = plm->portGroupByIndex(i);
|
2016-04-15 08:33:52 -05:00
|
|
|
OstProto::PortGroupContent *pgc = session->add_port_groups();
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
pgc->set_server_name(pg.serverName().toStdString());
|
|
|
|
pgc->set_server_port(pg.serverPort());
|
|
|
|
|
2016-04-15 08:33:52 -05:00
|
|
|
for (int j = 0; j < pg.numPorts(); j++)
|
|
|
|
{
|
2016-05-06 10:54:36 -05:00
|
|
|
if (myself != pg.mPorts.at(j)->userName())
|
|
|
|
continue;
|
|
|
|
|
2016-04-15 08:33:52 -05:00
|
|
|
OstProto::PortContent *pc = pgc->add_ports();
|
|
|
|
OstProto::Port *p = pc->mutable_port_config();
|
|
|
|
|
|
|
|
// XXX: We save the entire OstProto::Port even though some
|
|
|
|
// fields may be ephemeral; while opening we use only relevant
|
|
|
|
// fields
|
|
|
|
pg.mPorts.at(j)->protoDataCopyInto(p);
|
|
|
|
|
|
|
|
for (int k = 0; k < pg.mPorts.at(j)->numStreams(); k++)
|
|
|
|
{
|
|
|
|
OstProto::Stream *s = pc->add_streams();
|
|
|
|
pg.mPorts.at(j)->streamByIndex(k)->protoDataCopyInto(*s);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int k = 0; k < pg.mPorts.at(j)->numDeviceGroups(); k++)
|
|
|
|
{
|
|
|
|
OstProto::DeviceGroup *dg = pc->add_device_groups();
|
|
|
|
dg->CopyFrom(*(pg.mPorts.at(j)->deviceGroupByIndex(k)));
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
if (progress) {
|
|
|
|
if (progress->wasCanceled())
|
|
|
|
return false;
|
|
|
|
progress->setValue(i);
|
|
|
|
}
|
|
|
|
if (i % 2 == 0)
|
|
|
|
qApp->processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
void PortsWindow::showMyReservedPortsOnly(bool enabled)
|
|
|
|
{
|
|
|
|
if (!proxyPortModel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (enabled) {
|
2015-05-06 11:17:46 -05:00
|
|
|
QString rx = "Port Group|\\["
|
|
|
|
+ QRegExp::escape(appSettings->value(kUserKey,
|
|
|
|
kUserDefaultValue).toString())
|
|
|
|
+ "\\]";
|
2015-05-03 11:48:54 -05:00
|
|
|
qDebug("%s: regexp: <%s>", __FUNCTION__, qPrintable(rx));
|
|
|
|
proxyPortModel->setFilterRegExp(QRegExp(rx));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
proxyPortModel->setFilterRegExp(QRegExp(""));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_tvStreamList_activated(const QModelIndex & index)
|
|
|
|
{
|
|
|
|
if (!index.isValid())
|
|
|
|
{
|
|
|
|
qDebug("%s: invalid index", __FUNCTION__);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-16 02:00:00 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
qDebug("stream list activated\n");
|
|
|
|
|
2017-09-17 02:48:44 -05:00
|
|
|
Port &curPort = plm->port(proxyPortModel ?
|
|
|
|
proxyPortModel->mapToSource(tvPortList->currentIndex()) :
|
|
|
|
tvPortList->currentIndex());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2017-09-17 02:48:44 -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);
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
void PortsWindow::when_portView_currentChanged(const QModelIndex& currentIndex,
|
|
|
|
const QModelIndex& previousIndex)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2015-05-03 11:48:54 -05:00
|
|
|
QModelIndex current = currentIndex;
|
|
|
|
QModelIndex previous = previousIndex;
|
|
|
|
|
|
|
|
if (proxyPortModel) {
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
previous = proxyPortModel->mapToSource(previous);
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
plm->getStreamModel()->setCurrentPortIndex(current);
|
2015-05-03 11:48:54 -05:00
|
|
|
updatePortViewActions(currentIndex);
|
2015-04-16 11:50:07 -05:00
|
|
|
updateStreamViewActions();
|
|
|
|
|
|
|
|
qDebug("In %s", __FUNCTION__);
|
|
|
|
|
|
|
|
if (previous.isValid() && plm->isPort(previous))
|
|
|
|
{
|
|
|
|
disconnect(&(plm->port(previous)), SIGNAL(portRateChanged(int, int)),
|
|
|
|
this, SLOT(updatePortRates()));
|
2017-09-16 01:42:43 -05:00
|
|
|
disconnect(&(plm->port(previous)),
|
|
|
|
SIGNAL(localConfigChanged(int, int, bool)),
|
|
|
|
this,
|
|
|
|
SLOT(updateApplyHint(int, int, bool)));
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!current.isValid())
|
|
|
|
{
|
2017-09-07 10:15:43 -05:00
|
|
|
qDebug("setting stacked widget to welcome page");
|
|
|
|
swDetail->setCurrentIndex(0); // welcome page
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (plm->isPortGroup(current))
|
|
|
|
{
|
|
|
|
swDetail->setCurrentIndex(1); // portGroup detail page
|
|
|
|
}
|
|
|
|
else if (plm->isPort(current))
|
|
|
|
{
|
2017-09-07 10:15:43 -05:00
|
|
|
swDetail->setCurrentIndex(2); // port detail page
|
2015-04-16 11:50:07 -05:00
|
|
|
updatePortRates();
|
|
|
|
connect(&(plm->port(current)), SIGNAL(portRateChanged(int, int)),
|
|
|
|
SLOT(updatePortRates()));
|
2017-09-16 01:42:43 -05:00
|
|
|
connect(&(plm->port(current)),
|
|
|
|
SIGNAL(localConfigChanged(int, int, bool)),
|
|
|
|
SLOT(updateApplyHint(int, int, bool)));
|
2017-09-14 10:08:13 -05:00
|
|
|
if (plm->port(current).isDirty())
|
2017-09-16 01:42:43 -05:00
|
|
|
updateApplyHint(plm->port(current).portGroupId(),
|
|
|
|
plm->port(current).id(), true);
|
2017-09-14 10:08:13 -05:00
|
|
|
else if (plm->port(current).numStreams())
|
|
|
|
applyHint->setText("Use the Statistics window to transmit "
|
|
|
|
"packets");
|
|
|
|
else
|
|
|
|
applyHint->setText("");
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-13 09:21:32 -05:00
|
|
|
|
|
|
|
emit currentPortChanged(current, previous);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::when_portModel_dataChanged(const QModelIndex& topLeft,
|
|
|
|
const QModelIndex& bottomRight)
|
|
|
|
{
|
2017-09-09 02:43:52 -05:00
|
|
|
qDebug("In %s %d:(%d, %d) - %d:(%d, %d)", __FUNCTION__,
|
|
|
|
topLeft.parent().isValid(), topLeft.row(), topLeft.column(),
|
|
|
|
bottomRight.parent().isValid(), bottomRight.row(), bottomRight.column());
|
|
|
|
|
|
|
|
if (!topLeft.isValid() || !bottomRight.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (topLeft.parent() != bottomRight.parent())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If a port has changed, expand the port group
|
|
|
|
if (topLeft.parent().isValid())
|
|
|
|
tvPortList->expand(proxyPortModel ?
|
|
|
|
proxyPortModel->mapFromSource(topLeft.parent()) :
|
|
|
|
topLeft.parent());
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
#if 0 // not sure why the >= <= operators are not overloaded in QModelIndex
|
|
|
|
if ((tvPortList->currentIndex() >= topLeft) &&
|
|
|
|
(tvPortList->currentIndex() <= bottomRight))
|
|
|
|
#endif
|
|
|
|
if (((topLeft < tvPortList->currentIndex()) ||
|
|
|
|
(topLeft == tvPortList->currentIndex())) &&
|
|
|
|
(((tvPortList->currentIndex() < bottomRight)) ||
|
|
|
|
(tvPortList->currentIndex() == bottomRight)))
|
|
|
|
{
|
|
|
|
// Update UI to reflect potential change in exclusive mode,
|
|
|
|
// transmit mode et al
|
|
|
|
when_portView_currentChanged(tvPortList->currentIndex(),
|
|
|
|
tvPortList->currentIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::when_portModel_reset()
|
|
|
|
{
|
|
|
|
when_portView_currentChanged(QModelIndex(), tvPortList->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_averagePacketsPerSec_editingFinished()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(plm->isPort(current));
|
|
|
|
|
|
|
|
bool isOk;
|
2018-09-14 09:54:30 -05:00
|
|
|
double pps = XLocale().toDouble(averagePacketsPerSec->text(), &isOk);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
plm->port(current).setAveragePacketRate(pps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_averageBitsPerSec_editingFinished()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(plm->isPort(current));
|
|
|
|
|
|
|
|
bool isOk;
|
2018-09-14 09:54:30 -05:00
|
|
|
double bps = XLocale().toDouble(averageBitsPerSec->text(), &isOk);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
plm->port(current).setAverageBitRate(bps);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::updatePortRates()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (!current.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!plm->isPort(current))
|
|
|
|
return;
|
|
|
|
|
|
|
|
averagePacketsPerSec->setText(QString("%L1")
|
|
|
|
.arg(plm->port(current).averagePacketRate(), 0, 'f', 4));
|
|
|
|
averageBitsPerSec->setText(QString("%L1")
|
|
|
|
.arg(plm->port(current).averageBitRate(), 0, 'f', 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::updateStreamViewActions()
|
|
|
|
{
|
2015-05-03 11:48:54 -05:00
|
|
|
QModelIndex current = tvPortList->currentIndex();
|
|
|
|
|
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -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);
|
2017-09-17 02:48:44 -05:00
|
|
|
actionEdit_Stream->setEnabled(true);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Duplicate/Delete are always enabled as long as we have a selection
|
|
|
|
actionDuplicate_Stream->setEnabled(true);
|
|
|
|
actionDelete_Stream->setEnabled(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug("No selection");
|
2015-05-03 11:48:54 -05:00
|
|
|
if (plm->isPort(current))
|
2015-04-16 11:50:07 -05:00
|
|
|
actionNew_Stream->setEnabled(true);
|
|
|
|
else
|
|
|
|
actionNew_Stream->setDisabled(true);
|
|
|
|
actionEdit_Stream->setDisabled(true);
|
|
|
|
actionDuplicate_Stream->setDisabled(true);
|
|
|
|
actionDelete_Stream->setDisabled(true);
|
|
|
|
}
|
2015-05-03 11:48:54 -05:00
|
|
|
actionOpen_Streams->setEnabled(plm->isPort(current));
|
2015-04-16 11:50:07 -05:00
|
|
|
actionSave_Streams->setEnabled(tvStreamList->model()->rowCount() > 0);
|
|
|
|
}
|
|
|
|
|
2017-09-16 01:42:43 -05:00
|
|
|
void PortsWindow::updateApplyHint(int /*portGroupId*/, int /*portId*/,
|
|
|
|
bool configChanged)
|
2017-09-14 10:08:13 -05:00
|
|
|
{
|
|
|
|
if (configChanged)
|
2017-10-05 09:34:23 -05:00
|
|
|
applyHint->setText("Configuration has changed - "
|
|
|
|
"<font color='red'><b>click Apply</b></font> "
|
2017-09-14 10:08:13 -05:00
|
|
|
"to activate the changes");
|
|
|
|
else
|
|
|
|
applyHint->setText("Configuration activated. Use the Statistics "
|
|
|
|
"window to transmit packets");
|
|
|
|
}
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
void PortsWindow::updatePortViewActions(const QModelIndex& currentIndex)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2015-05-03 11:48:54 -05:00
|
|
|
QModelIndex current = currentIndex;
|
|
|
|
|
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (!current.isValid())
|
|
|
|
{
|
|
|
|
qDebug("current is now invalid");
|
|
|
|
actionDelete_Port_Group->setDisabled(true);
|
|
|
|
actionConnect_Port_Group->setDisabled(true);
|
|
|
|
actionDisconnect_Port_Group->setDisabled(true);
|
|
|
|
|
|
|
|
actionExclusive_Control->setDisabled(true);
|
|
|
|
actionPort_Configuration->setDisabled(true);
|
|
|
|
|
|
|
|
goto _EXIT;
|
|
|
|
}
|
|
|
|
|
2018-04-20 10:20:51 -05:00
|
|
|
qDebug("currentChanged %p", (void*)current.internalId());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
if (plm->isPortGroup(current))
|
|
|
|
{
|
|
|
|
actionDelete_Port_Group->setEnabled(true);
|
|
|
|
|
|
|
|
actionExclusive_Control->setDisabled(true);
|
|
|
|
actionPort_Configuration->setDisabled(true);
|
|
|
|
|
|
|
|
switch(plm->portGroup(current).state())
|
|
|
|
{
|
|
|
|
case QAbstractSocket::UnconnectedState:
|
|
|
|
case QAbstractSocket::ClosingState:
|
|
|
|
qDebug("state = unconnected|closing");
|
|
|
|
actionConnect_Port_Group->setEnabled(true);
|
|
|
|
actionDisconnect_Port_Group->setDisabled(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QAbstractSocket::HostLookupState:
|
|
|
|
case QAbstractSocket::ConnectingState:
|
|
|
|
case QAbstractSocket::ConnectedState:
|
|
|
|
qDebug("state = lookup|connecting|connected");
|
|
|
|
actionConnect_Port_Group->setDisabled(true);
|
|
|
|
actionDisconnect_Port_Group->setEnabled(true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case QAbstractSocket::BoundState:
|
|
|
|
case QAbstractSocket::ListeningState:
|
|
|
|
default:
|
|
|
|
// FIXME(LOW): indicate error
|
|
|
|
qDebug("unexpected state");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (plm->isPort(current))
|
|
|
|
{
|
|
|
|
actionDelete_Port_Group->setDisabled(true);
|
|
|
|
actionConnect_Port_Group->setDisabled(true);
|
|
|
|
actionDisconnect_Port_Group->setDisabled(true);
|
|
|
|
|
|
|
|
actionExclusive_Control->setEnabled(true);
|
|
|
|
if (plm->port(current).hasExclusiveControl())
|
|
|
|
actionExclusive_Control->setChecked(true);
|
|
|
|
else
|
|
|
|
actionExclusive_Control->setChecked(false);
|
|
|
|
actionPort_Configuration->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
_EXIT:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_pbApply_clicked()
|
|
|
|
{
|
|
|
|
QModelIndex curPort;
|
|
|
|
QModelIndex curPortGroup;
|
|
|
|
|
|
|
|
curPort = tvPortList->selectionModel()->currentIndex();
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
curPort = proxyPortModel->mapToSource(curPort);
|
2015-04-16 11:50:07 -05:00
|
|
|
if (!curPort.isValid())
|
|
|
|
{
|
|
|
|
qDebug("%s: curPort is invalid", __FUNCTION__);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!plm->isPort(curPort))
|
|
|
|
{
|
|
|
|
qDebug("%s: curPort is not a port", __FUNCTION__);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plm->port(curPort).getStats().state().is_transmit_on())
|
|
|
|
{
|
|
|
|
QMessageBox::information(0, "Configuration Change",
|
|
|
|
"Please stop transmit on the port before applying any changes");
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
curPortGroup = plm->getPortModel()->parent(curPort);
|
|
|
|
if (!curPortGroup.isValid())
|
|
|
|
{
|
|
|
|
qDebug("%s: curPortGroup is invalid", __FUNCTION__);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
if (!plm->isPortGroup(curPortGroup))
|
|
|
|
{
|
|
|
|
qDebug("%s: curPortGroup is not a portGroup", __FUNCTION__);
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2019-02-22 07:28:13 -06:00
|
|
|
disconnect(applyMsg_);
|
|
|
|
connect(&(plm->portGroup(curPortGroup)), SIGNAL(applyFinished()),
|
|
|
|
applyMsg_, SLOT(hide()));
|
|
|
|
applyMsg_->show();
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
// FIXME(HI): shd this be a signal?
|
|
|
|
//portGroup.when_configApply(port);
|
|
|
|
// FIXME(MED): mixing port id and index!!!
|
|
|
|
plm->portGroup(curPortGroup).when_configApply(plm->port(curPort).id());
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
// TODO (LOW): This block is for testing only
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
|
|
|
if (current.isValid())
|
|
|
|
qDebug("current = %llx", current.internalId());
|
|
|
|
else
|
|
|
|
qDebug("current is invalid");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionNew_Port_Group_triggered()
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
QString text = QInputDialog::getText(this,
|
2015-11-06 07:27:07 -06:00
|
|
|
"Add Port Group", "Port Group Address (HostName[:Port])",
|
2015-04-16 11:50:07 -05:00
|
|
|
QLineEdit::Normal, lastNewPortGroup, &ok);
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
QStringList addr = text.split(":");
|
2015-11-06 07:27:07 -06:00
|
|
|
quint16 port = DEFAULT_SERVER_PORT;
|
|
|
|
|
|
|
|
if (addr.size() > 2) { // IPv6 Address
|
|
|
|
// IPv6 addresses with port number SHOULD be specified as
|
|
|
|
// [2001:db8::1]:80 (RFC5952 Sec6) to avoid ambiguity due to ':'
|
|
|
|
addr = text.split("]:");
|
|
|
|
if (addr.size() > 1)
|
|
|
|
port = addr[1].toUShort();
|
|
|
|
}
|
|
|
|
else if (addr.size() == 2) // Hostname/IPv4 + Port specified
|
|
|
|
port = addr[1].toUShort();
|
|
|
|
|
|
|
|
// Play nice and remove square brackets irrespective of addr type
|
|
|
|
addr[0].remove(QChar('['));
|
|
|
|
addr[0].remove(QChar(']'));
|
|
|
|
|
|
|
|
PortGroup *pg = new PortGroup(addr[0], port);
|
2015-04-16 11:50:07 -05:00
|
|
|
plm->addPortGroup(*pg);
|
|
|
|
lastNewPortGroup = text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionDelete_Port_Group_triggered()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (current.isValid())
|
|
|
|
plm->removePortGroup(plm->portGroup(current));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionConnect_Port_Group_triggered()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (current.isValid())
|
|
|
|
plm->portGroup(current).connectToHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionDisconnect_Port_Group_triggered()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (current.isValid())
|
|
|
|
plm->portGroup(current).disconnectFromHost();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionExclusive_Control_triggered(bool checked)
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (plm->isPort(current))
|
|
|
|
{
|
|
|
|
OstProto::Port config;
|
|
|
|
|
|
|
|
config.set_is_exclusive_control(checked);
|
|
|
|
plm->portGroup(current.parent()).modifyPort(current.row(), config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionPort_Configuration_triggered()
|
|
|
|
{
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (!plm->isPort(current))
|
|
|
|
return;
|
|
|
|
|
2016-10-28 07:57:24 -05:00
|
|
|
Port &port = plm->port(current);
|
2015-04-16 11:50:07 -05:00
|
|
|
OstProto::Port config;
|
2016-10-23 06:54:23 -05:00
|
|
|
// XXX: we don't call Port::protoDataCopyInto() to get config b'coz
|
|
|
|
// we want only the modifiable fields populated to send to Drone
|
|
|
|
// TODO: extend Port::protoDataCopyInto() to accept an optional param
|
|
|
|
// which says copy only modifiable fields
|
2016-10-27 11:18:18 -05:00
|
|
|
//plm->port(current).protoDataCopyInto(&config);
|
2016-10-28 07:57:24 -05:00
|
|
|
config.set_transmit_mode(port.transmitMode());
|
2017-12-02 23:56:09 -06:00
|
|
|
config.set_is_tracking_stream_stats(port.trackStreamStats());
|
2016-10-28 07:57:24 -05:00
|
|
|
config.set_is_exclusive_control(port.hasExclusiveControl());
|
|
|
|
config.set_user_name(port.userName().toStdString());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2016-10-28 07:57:24 -05:00
|
|
|
PortConfigDialog dialog(config, port.getStats().state(), this);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
if (dialog.exec() == QDialog::Accepted)
|
|
|
|
plm->portGroup(current.parent()).modifyPort(current.row(), config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionNew_Stream_triggered()
|
|
|
|
{
|
|
|
|
qDebug("New Stream Action");
|
|
|
|
|
2017-09-20 11:30:47 -05:00
|
|
|
QItemSelectionModel* selectionModel = tvStreamList->selectionModel();
|
|
|
|
if (selectionModel->selection().size() > 1) {
|
2017-09-21 10:20:24 -05:00
|
|
|
qDebug("%s: Unexpected selection size %d, can't add", __FUNCTION__,
|
2017-09-20 11:30:47 -05:00
|
|
|
selectionModel->selection().size());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-14 10:31:56 -05:00
|
|
|
// In case nothing is selected, insert 1 row at the end
|
2017-09-20 11:30:47 -05:00
|
|
|
StreamModel *streamModel = plm->getStreamModel();
|
|
|
|
int row = streamModel->rowCount(), count = 1;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
// 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
|
2017-09-20 11:30:47 -05:00
|
|
|
if (selectionModel->selection().size() == 1)
|
2015-04-16 11:50:07 -05:00
|
|
|
{
|
2017-09-20 11:30:47 -05:00
|
|
|
row = selectionModel->selection().at(0).top();
|
|
|
|
count = selectionModel->selection().at(0).height();
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2017-09-20 11:30:47 -05:00
|
|
|
Port &curPort = plm->port(proxyPortModel ?
|
|
|
|
proxyPortModel->mapToSource(tvPortList->currentIndex()) :
|
|
|
|
tvPortList->currentIndex());
|
|
|
|
|
|
|
|
QList<Stream*> streams;
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
streams.append(new Stream);
|
|
|
|
|
|
|
|
StreamConfigDialog scd(streams, curPort, this);
|
2017-09-22 10:15:42 -05:00
|
|
|
scd.setWindowTitle(tr("Add Stream"));
|
2017-09-20 11:30:47 -05:00
|
|
|
if (scd.exec() == QDialog::Accepted)
|
|
|
|
streamModel->insert(row, streams);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionEdit_Stream_triggered()
|
|
|
|
{
|
|
|
|
qDebug("Edit Stream Action");
|
|
|
|
|
2017-09-17 02:48:44 -05:00
|
|
|
QItemSelectionModel* streamModel = tvStreamList->selectionModel();
|
|
|
|
if (!streamModel->hasSelection())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Port &curPort = plm->port(proxyPortModel ?
|
|
|
|
proxyPortModel->mapToSource(tvPortList->currentIndex()) :
|
|
|
|
tvPortList->currentIndex());
|
|
|
|
|
|
|
|
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);
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionDuplicate_Stream_triggered()
|
|
|
|
{
|
|
|
|
QItemSelectionModel* model = tvStreamList->selectionModel();
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
2015-05-03 11:48:54 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
qDebug("Duplicate Stream Action");
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
if (model->hasSelection())
|
|
|
|
{
|
|
|
|
bool isOk;
|
2018-03-14 11:28:56 -05:00
|
|
|
int count = QInputDialog::getInt(this, "Duplicate Streams",
|
2015-04-16 11:50:07 -05:00
|
|
|
"Count", 1, 1, 9999, 1, &isOk);
|
|
|
|
|
|
|
|
if (!isOk)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QList<int> list;
|
|
|
|
foreach(QModelIndex index, model->selectedRows())
|
|
|
|
list.append(index.row());
|
|
|
|
plm->port(current).duplicateStreams(list, count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
qDebug("No selection");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionDelete_Stream_triggered()
|
|
|
|
{
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionOpen_Streams_triggered()
|
|
|
|
{
|
|
|
|
qDebug("Open Streams Action");
|
|
|
|
|
2016-05-19 11:24:28 -05:00
|
|
|
QStringList fileTypes = StreamFileFormat::supportedFileTypes(
|
|
|
|
StreamFileFormat::kOpenFile);
|
2016-05-18 11:03:26 -05:00
|
|
|
QString fileType;
|
2015-04-16 11:50:07 -05:00
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
static QString dirName;
|
|
|
|
QString fileName;
|
|
|
|
QString errorStr;
|
|
|
|
bool append = true;
|
|
|
|
bool ret;
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
Q_ASSERT(plm->isPort(current));
|
|
|
|
|
2016-05-18 11:03:26 -05:00
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
|
|
|
fileName = QFileDialog::getOpenFileName(this, tr("Open Streams"),
|
|
|
|
dirName, fileTypes.join(";;"), &fileType);
|
2015-04-16 11:50:07 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = plm->port(current).openStreams(fileName, append, errorStr);
|
|
|
|
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();
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PortsWindow::on_actionSave_Streams_triggered()
|
|
|
|
{
|
|
|
|
qDebug("Save Streams Action");
|
|
|
|
|
|
|
|
QModelIndex current = tvPortList->selectionModel()->currentIndex();
|
|
|
|
static QString fileName;
|
2016-05-19 11:24:28 -05:00
|
|
|
QStringList fileTypes = StreamFileFormat::supportedFileTypes(
|
|
|
|
StreamFileFormat::kSaveFile);
|
2015-04-16 11:50:07 -05:00
|
|
|
QString fileType;
|
|
|
|
QString errorStr;
|
|
|
|
QFileDialog::Options options;
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
if (proxyPortModel)
|
|
|
|
current = proxyPortModel->mapToSource(current);
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
2016-06-14 08:24:13 -05:00
|
|
|
// which we need
|
|
|
|
#if defined(Q_OS_MAC)
|
2015-04-16 11:50:07 -05:00
|
|
|
options |= QFileDialog::DontUseNativeDialog;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
|
|
|
Q_ASSERT(plm->isPort(current));
|
|
|
|
|
|
|
|
_retry:
|
|
|
|
fileName = QFileDialog::getSaveFileName(this, tr("Save Streams"),
|
|
|
|
fileName, fileTypes.join(";;"), &fileType, options);
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
goto _exit;
|
|
|
|
|
2016-06-14 08:24:13 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
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?
|
|
|
|
|
|
|
|
if (!plm->port(current).saveStreams(fileName, fileType, errorStr))
|
|
|
|
QMessageBox::critical(this, qApp->applicationName(), errorStr);
|
|
|
|
else if (!errorStr.isEmpty())
|
|
|
|
QMessageBox::warning(this, qApp->applicationName(), errorStr);
|
|
|
|
|
|
|
|
fileName = QFileInfo(fileName).absolutePath();
|
|
|
|
_exit:
|
|
|
|
return;
|
|
|
|
}
|
2016-02-17 09:43:30 -06:00
|
|
|
|
2016-03-04 07:11:36 -06:00
|
|
|
|