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 "mainwindow.h"
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#include "dbgthread.h"
|
|
|
|
#endif
|
|
|
|
|
2020-03-14 10:43:24 -05:00
|
|
|
#include "clipboardhelper.h"
|
2017-10-10 11:06:06 -05:00
|
|
|
#include "jumpurl.h"
|
2018-08-17 08:25:58 -05:00
|
|
|
#include "logsmodel.h"
|
|
|
|
#include "logswindow.h"
|
2016-10-13 08:20:33 -05:00
|
|
|
#include "params.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
#include "portgrouplist.h"
|
|
|
|
#include "portstatswindow.h"
|
|
|
|
#include "portswindow.h"
|
|
|
|
#include "preferences.h"
|
2016-04-13 21:14:07 -05:00
|
|
|
#include "sessionfileformat.h"
|
2015-04-16 11:50:07 -05:00
|
|
|
#include "settings.h"
|
|
|
|
#include "ui_about.h"
|
|
|
|
#include "updater.h"
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
#include "fileformat.pb.h"
|
|
|
|
|
2019-05-22 08:15:06 -05:00
|
|
|
#include <QDate>
|
2016-06-23 08:22:50 -05:00
|
|
|
#include <QDesktopServices>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QDockWidget>
|
2016-04-13 21:14:07 -05:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QMessageBox>
|
2015-04-16 11:50:07 -05:00
|
|
|
#include <QProcess>
|
2016-04-13 21:14:07 -05:00
|
|
|
#include <QProgressDialog>
|
2017-09-23 08:23:12 -05:00
|
|
|
#include <QTimer>
|
2016-06-23 08:22:50 -05:00
|
|
|
#include <QUrl>
|
2015-04-16 11:50:07 -05:00
|
|
|
|
2017-09-04 12:27:45 -05:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include <windows.h>
|
|
|
|
#undef WIN32_NO_STATUS
|
|
|
|
#include <ntstatus.h>
|
|
|
|
#endif
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
extern const char* version;
|
|
|
|
extern const char* revision;
|
|
|
|
|
|
|
|
PortGroupList *pgl;
|
2018-08-17 08:25:58 -05:00
|
|
|
LogsModel *appLogs;
|
2020-03-14 10:43:24 -05:00
|
|
|
ClipboardHelper *clipboardHelper;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
MainWindow::MainWindow(QWidget *parent)
|
|
|
|
: QMainWindow (parent)
|
|
|
|
{
|
|
|
|
Updater *updater = new Updater();
|
|
|
|
|
2016-10-13 08:20:33 -05:00
|
|
|
if (appParams.optLocalDrone()) {
|
|
|
|
QString serverApp = QCoreApplication::applicationDirPath();
|
2015-04-16 11:50:07 -05:00
|
|
|
#ifdef Q_OS_MAC
|
2016-10-13 08:20:33 -05:00
|
|
|
// applicationDirPath() does not return bundle,
|
|
|
|
// but executable inside bundle
|
|
|
|
serverApp.replace("Ostinato.app", "drone.app");
|
2015-04-16 11:50:07 -05:00
|
|
|
#endif
|
|
|
|
#ifdef Q_OS_WIN32
|
2016-10-13 08:20:33 -05:00
|
|
|
serverApp.append("/drone.exe");
|
2015-04-16 11:50:07 -05:00
|
|
|
#else
|
2016-10-13 08:20:33 -05:00
|
|
|
serverApp.append("/drone");
|
2015-04-16 11:50:07 -05:00
|
|
|
#endif
|
|
|
|
|
2016-10-13 08:20:33 -05:00
|
|
|
qDebug("staring local server - %s", qPrintable(serverApp));
|
|
|
|
localServer_ = new QProcess(this);
|
2017-09-26 09:29:49 -05:00
|
|
|
connect(localServer_, SIGNAL(finished(int, QProcess::ExitStatus)),
|
|
|
|
SLOT(onLocalServerFinished(int, QProcess::ExitStatus)));
|
2022-09-30 10:03:25 -05:00
|
|
|
|
|
|
|
#if QT_VERSION >= 0x050600
|
|
|
|
connect(localServer_, SIGNAL(errorOccurred(QProcess::ProcessError)),
|
|
|
|
SLOT(onLocalServerError(QProcess::ProcessError)));
|
|
|
|
#else
|
2017-09-04 12:27:45 -05:00
|
|
|
connect(localServer_, SIGNAL(error(QProcess::ProcessError)),
|
|
|
|
SLOT(onLocalServerError(QProcess::ProcessError)));
|
2022-09-30 10:03:25 -05:00
|
|
|
#endif
|
2016-10-13 08:20:33 -05:00
|
|
|
localServer_->setProcessChannelMode(QProcess::ForwardedChannels);
|
|
|
|
localServer_->start(serverApp, QStringList());
|
2017-09-26 09:29:49 -05:00
|
|
|
QTimer::singleShot(5000, this, SLOT(stopLocalServerMonitor()));
|
2016-10-13 08:20:33 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
localServer_ = NULL;
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
pgl = new PortGroupList;
|
2018-08-17 08:25:58 -05:00
|
|
|
appLogs = new LogsModel(this);
|
2020-03-14 10:43:24 -05:00
|
|
|
clipboardHelper = new ClipboardHelper(this);
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
portsWindow = new PortsWindow(pgl, this);
|
|
|
|
statsWindow = new PortStatsWindow(pgl, this);
|
2018-08-17 08:25:58 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
portsDock = new QDockWidget(tr("Ports and Streams"), this);
|
|
|
|
portsDock->setObjectName("portsDock");
|
|
|
|
portsDock->setFeatures(
|
|
|
|
portsDock->features() & ~QDockWidget::DockWidgetClosable);
|
2018-08-17 08:25:58 -05:00
|
|
|
|
2016-11-24 10:14:38 -06:00
|
|
|
statsDock = new QDockWidget(tr("Port Statistics"), this);
|
2015-04-16 11:50:07 -05:00
|
|
|
statsDock->setObjectName("statsDock");
|
|
|
|
statsDock->setFeatures(
|
|
|
|
statsDock->features() & ~QDockWidget::DockWidgetClosable);
|
|
|
|
|
2018-08-17 08:25:58 -05:00
|
|
|
logsDock_ = new QDockWidget(tr("Logs"), this);
|
|
|
|
logsDock_->setObjectName("logsDock");
|
|
|
|
logsDock_->setFeatures(
|
|
|
|
logsDock_->features() & ~QDockWidget::DockWidgetClosable);
|
2018-08-23 12:53:07 -05:00
|
|
|
logsWindow_ = new LogsWindow(appLogs, logsDock_);
|
2018-08-17 08:25:58 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
setupUi(this);
|
|
|
|
|
2022-02-11 06:39:30 -06:00
|
|
|
menuFile->insertActions(menuFile->actions().at(3),
|
|
|
|
portsWindow->portActions());
|
2020-03-14 10:43:24 -05:00
|
|
|
menuEdit->addActions(clipboardHelper->actions());
|
2022-02-11 06:39:30 -06:00
|
|
|
menuStreams->addActions(portsWindow->streamActions());
|
|
|
|
menuDevices->addActions(portsWindow->deviceActions());
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
statsDock->setWidget(statsWindow);
|
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, statsDock);
|
2018-08-17 08:25:58 -05:00
|
|
|
logsDock_->setWidget(logsWindow_);
|
|
|
|
addDockWidget(Qt::BottomDockWidgetArea, logsDock_);
|
|
|
|
tabifyDockWidget(statsDock, logsDock_);
|
|
|
|
statsDock->show();
|
|
|
|
statsDock->raise();
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
portsDock->setWidget(portsWindow);
|
|
|
|
addDockWidget(Qt::TopDockWidgetArea, portsDock);
|
|
|
|
|
2020-05-06 07:31:44 -05:00
|
|
|
#if QT_VERSION >= 0x050600
|
|
|
|
// Set top and bottom docks to equal height
|
|
|
|
resizeDocks({portsDock, statsDock}, {height()/2, height()/2}, Qt::Vertical);
|
|
|
|
#endif
|
|
|
|
|
2020-05-07 08:10:31 -05:00
|
|
|
portsWindow->setFocus();
|
|
|
|
|
2015-05-03 13:14:35 -05:00
|
|
|
// Save the default window geometry and layout ...
|
|
|
|
defaultGeometry_ = geometry();
|
|
|
|
defaultLayout_ = saveState(0);
|
|
|
|
|
|
|
|
// ... before restoring the last used settings
|
2015-04-16 11:50:07 -05:00
|
|
|
QRect geom = appSettings->value(kApplicationWindowGeometryKey).toRect();
|
|
|
|
if (!geom.isNull())
|
|
|
|
setGeometry(geom);
|
|
|
|
QByteArray layout = appSettings->value(kApplicationWindowLayout)
|
|
|
|
.toByteArray();
|
|
|
|
if (layout.size())
|
|
|
|
restoreState(layout, 0);
|
|
|
|
|
|
|
|
connect(actionFileExit, SIGNAL(triggered()), this, SLOT(close()));
|
|
|
|
connect(actionAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
|
|
|
|
|
2015-05-03 11:48:54 -05:00
|
|
|
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
|
|
|
portsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
2015-05-06 11:10:55 -05:00
|
|
|
connect(actionViewShowMyReservedPortsOnly, SIGNAL(toggled(bool)),
|
|
|
|
statsWindow, SLOT(showMyReservedPortsOnly(bool)));
|
2015-05-03 11:48:54 -05:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
connect(updater, SIGNAL(newVersionAvailable(QString)),
|
|
|
|
this, SLOT(onNewVersion(QString)));
|
|
|
|
updater->checkForNewVersion();
|
2016-10-13 11:36:11 -05:00
|
|
|
|
2022-12-08 04:52:39 -06:00
|
|
|
// TODO: If session file specified (and valid?), don't add local drone PG
|
2019-02-22 09:04:59 -06:00
|
|
|
// Add the "Local" Port Group
|
|
|
|
if (appParams.optLocalDrone()) {
|
|
|
|
PortGroup *pg = new PortGroup;
|
|
|
|
pgl->addPortGroup(*pg);
|
|
|
|
}
|
|
|
|
|
2016-10-13 11:36:11 -05:00
|
|
|
if (appParams.argumentCount()) {
|
|
|
|
QString fileName = appParams.argument(0);
|
|
|
|
if (QFile::exists(fileName))
|
2019-02-26 06:42:18 -06:00
|
|
|
openSession(fileName);
|
2016-10-13 11:36:11 -05:00
|
|
|
else
|
|
|
|
QMessageBox::information(NULL, qApp->applicationName(),
|
|
|
|
QString("File not found: " + fileName));
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
DbgThread *dbg = new DbgThread(pgl);
|
|
|
|
dbg->start();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2017-09-26 09:29:49 -05:00
|
|
|
stopLocalServerMonitor();
|
2016-10-13 08:20:33 -05:00
|
|
|
if (localServer_) {
|
2015-04-16 11:50:07 -05:00
|
|
|
#ifdef Q_OS_WIN32
|
2016-10-13 08:20:33 -05:00
|
|
|
//! \todo - find a way to terminate cleanly
|
|
|
|
localServer_->kill();
|
2015-04-16 11:50:07 -05:00
|
|
|
#else
|
2016-10-13 08:20:33 -05:00
|
|
|
localServer_->terminate();
|
2015-04-16 11:50:07 -05:00
|
|
|
#endif
|
2016-10-13 08:20:33 -05:00
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
|
|
|
|
delete pgl;
|
|
|
|
|
2016-11-27 00:15:15 -06:00
|
|
|
// We don't want to save state for Stream Stats Docks - so delete them
|
2016-11-24 10:14:38 -06:00
|
|
|
QList<QDockWidget*> streamStatsDocks
|
|
|
|
= findChildren<QDockWidget*>("streamStatsDock");
|
|
|
|
foreach(QDockWidget *dock, streamStatsDocks)
|
2016-11-27 00:15:15 -06:00
|
|
|
delete dock;
|
|
|
|
Q_ASSERT(findChildren<QDockWidget*>("streamStatsDock").size() == 0);
|
2016-11-24 10:14:38 -06:00
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
QByteArray layout = saveState(0);
|
|
|
|
appSettings->setValue(kApplicationWindowLayout, layout);
|
|
|
|
appSettings->setValue(kApplicationWindowGeometryKey, geometry());
|
|
|
|
|
2016-10-13 08:20:33 -05:00
|
|
|
if (localServer_) {
|
|
|
|
localServer_->waitForFinished();
|
|
|
|
delete localServer_;
|
|
|
|
}
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
|
|
|
|
2019-02-26 06:42:18 -06:00
|
|
|
void MainWindow::openSession(QString fileName)
|
2016-04-13 21:14:07 -05:00
|
|
|
{
|
2016-10-13 11:36:11 -05:00
|
|
|
qDebug("Open Session Action (%s)", qPrintable(fileName));
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
static QString dirName;
|
2016-05-19 10:20:33 -05:00
|
|
|
QStringList fileTypes = SessionFileFormat::supportedFileTypes(
|
|
|
|
SessionFileFormat::kOpenFile);
|
2016-05-18 10:39:11 -05:00
|
|
|
QString fileType;
|
2016-04-13 21:14:07 -05:00
|
|
|
QString errorStr;
|
|
|
|
bool ret;
|
|
|
|
|
2016-10-13 11:36:11 -05:00
|
|
|
if (!fileName.isEmpty())
|
|
|
|
goto _skip_prompt;
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
if (portsWindow->portGroupCount()) {
|
|
|
|
if (QMessageBox::question(this,
|
|
|
|
tr("Open Session"),
|
|
|
|
tr("Existing session will be lost. Proceed?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::No) == QMessageBox::No)
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2016-05-19 09:58:04 -05:00
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
|
|
|
fileName = QFileDialog::getOpenFileName(this, tr("Open Session"),
|
|
|
|
dirName, fileTypes.join(";;"), &fileType);
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
goto _exit;
|
|
|
|
|
2016-10-13 11:36:11 -05:00
|
|
|
_skip_prompt:
|
2016-04-13 21:14:07 -05:00
|
|
|
ret = openSession(fileName, 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;
|
|
|
|
}
|
|
|
|
|
2019-02-26 06:42:18 -06:00
|
|
|
void MainWindow::on_actionOpenSession_triggered()
|
|
|
|
{
|
|
|
|
openSession();
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
void MainWindow::on_actionSaveSession_triggered()
|
|
|
|
{
|
|
|
|
qDebug("Save Session Action");
|
|
|
|
|
|
|
|
static QString fileName;
|
2016-05-19 10:20:33 -05:00
|
|
|
QStringList fileTypes = SessionFileFormat::supportedFileTypes(
|
|
|
|
SessionFileFormat::kSaveFile);
|
2016-04-13 21:14:07 -05:00
|
|
|
QString fileType;
|
|
|
|
QString errorStr;
|
|
|
|
QFileDialog::Options options;
|
|
|
|
|
2016-05-19 09:58:04 -05:00
|
|
|
if (portsWindow->reservedPortCount()) {
|
|
|
|
QString myself = appSettings->value(kUserKey, kUserDefaultValue)
|
|
|
|
.toString();
|
|
|
|
if (QMessageBox::question(this,
|
|
|
|
tr("Save Session"),
|
|
|
|
QString("Some ports are reserved!\n\nOnly ports reserved by %1 will be saved. Proceed?").arg(myself),
|
|
|
|
QMessageBox::Yes | QMessageBox::No,
|
|
|
|
QMessageBox::No) == QMessageBox::No)
|
|
|
|
goto _exit;
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType.
|
|
|
|
// Although currently there's only one supported file type, we may
|
|
|
|
// have more in the future
|
|
|
|
#if defined(Q_OS_MAC)
|
|
|
|
options |= QFileDialog::DontUseNativeDialog;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fileTypes.size())
|
|
|
|
fileType = fileTypes.at(0);
|
|
|
|
|
2016-06-14 08:24:13 -05:00
|
|
|
_retry:
|
2016-04-13 21:14:07 -05:00
|
|
|
fileName = QFileDialog::getSaveFileName(this, tr("Save Session"),
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 21:14:07 -05:00
|
|
|
if (!saveSession(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;
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void MainWindow::on_actionPreferences_triggered()
|
|
|
|
{
|
|
|
|
Preferences *preferences = new Preferences();
|
|
|
|
|
|
|
|
preferences->exec();
|
|
|
|
|
|
|
|
delete preferences;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:14:35 -05:00
|
|
|
void MainWindow::on_actionViewRestoreDefaults_triggered()
|
|
|
|
{
|
|
|
|
// Use the saved default geometry/layout, however keep the
|
|
|
|
// window location same
|
|
|
|
defaultGeometry_.moveTo(geometry().topLeft());
|
|
|
|
setGeometry(defaultGeometry_);
|
|
|
|
restoreState(defaultLayout_, 0);
|
|
|
|
|
2016-11-27 01:37:06 -06:00
|
|
|
// Add streamStats as tabs
|
|
|
|
QList<QDockWidget*> streamStatsDocks
|
|
|
|
= findChildren<QDockWidget*>("streamStatsDock");
|
|
|
|
foreach(QDockWidget *dock, streamStatsDocks) {
|
|
|
|
dock->setFloating(false);
|
|
|
|
tabifyDockWidget(statsDock, dock);
|
|
|
|
}
|
|
|
|
statsDock->show();
|
|
|
|
statsDock->raise();
|
|
|
|
|
2015-05-03 13:14:35 -05:00
|
|
|
actionViewShowMyReservedPortsOnly->setChecked(false);
|
2020-05-07 08:10:31 -05:00
|
|
|
|
|
|
|
portsWindow->clearCurrentSelection();
|
|
|
|
statsWindow->clearCurrentSelection();
|
|
|
|
logsWindow_->clearCurrentSelection();
|
2015-05-03 13:14:35 -05:00
|
|
|
}
|
|
|
|
|
2016-06-23 08:22:50 -05:00
|
|
|
void MainWindow::on_actionHelpOnline_triggered()
|
|
|
|
{
|
2017-10-10 11:06:06 -05:00
|
|
|
QDesktopServices::openUrl(QUrl(jumpUrl("help", "app", "menu")));
|
2016-06-23 08:22:50 -05:00
|
|
|
}
|
|
|
|
|
2018-12-18 08:06:21 -06:00
|
|
|
void MainWindow::on_actionDonate_triggered()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl(jumpUrl("donate", "app", "menu")));
|
|
|
|
}
|
|
|
|
|
2019-05-22 08:15:06 -05:00
|
|
|
void MainWindow::on_actionCheckForUpdates_triggered()
|
|
|
|
{
|
|
|
|
Updater *updater = new Updater();
|
|
|
|
connect(updater, SIGNAL(latestVersion(QString)),
|
|
|
|
this, SLOT(onLatestVersion(QString)));
|
|
|
|
updater->checkForNewVersion();
|
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void MainWindow::on_actionHelpAbout_triggered()
|
|
|
|
{
|
|
|
|
QDialog *aboutDialog = new QDialog;
|
|
|
|
|
|
|
|
Ui::About about;
|
|
|
|
about.setupUi(aboutDialog);
|
|
|
|
about.versionLabel->setText(
|
|
|
|
QString("Version: %1 Revision: %2").arg(version).arg(revision));
|
|
|
|
|
|
|
|
aboutDialog->exec();
|
|
|
|
|
|
|
|
delete aboutDialog;
|
|
|
|
}
|
|
|
|
|
2017-09-26 09:29:49 -05:00
|
|
|
void MainWindow::stopLocalServerMonitor()
|
2017-09-04 12:27:45 -05:00
|
|
|
{
|
|
|
|
// We are only interested in startup errors
|
2022-11-14 05:57:47 -06:00
|
|
|
#if QT_VERSION >= 0x050600
|
|
|
|
disconnect(localServer_, SIGNAL(errorOccurred(QProcess::ProcessError)),
|
|
|
|
this, SLOT(onLocalServerError(QProcess::ProcessError)));
|
|
|
|
#else
|
2017-09-04 12:27:45 -05:00
|
|
|
disconnect(localServer_, SIGNAL(error(QProcess::ProcessError)),
|
|
|
|
this, SLOT(onLocalServerError(QProcess::ProcessError)));
|
2022-11-14 05:57:47 -06:00
|
|
|
#endif
|
2017-09-26 09:29:49 -05:00
|
|
|
disconnect(localServer_, SIGNAL(finished(int, QProcess::ExitStatus)),
|
|
|
|
this, SLOT(onLocalServerFinished(int, QProcess::ExitStatus)));
|
2017-09-04 12:27:45 -05:00
|
|
|
}
|
|
|
|
|
2017-09-26 09:29:49 -05:00
|
|
|
void MainWindow::onLocalServerFinished(int exitCode,
|
|
|
|
QProcess::ExitStatus /*exitStatus*/)
|
|
|
|
{
|
|
|
|
if (exitCode)
|
|
|
|
reportLocalServerError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onLocalServerError(QProcess::ProcessError /*error*/)
|
|
|
|
{
|
|
|
|
reportLocalServerError();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::reportLocalServerError()
|
2017-09-04 12:27:45 -05:00
|
|
|
{
|
|
|
|
QMessageBox msgBox(this);
|
|
|
|
msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
msgBox.setTextFormat(Qt::RichText);
|
|
|
|
msgBox.setStyleSheet("messagebox-text-interaction-flags: 5"); // mouse copy
|
|
|
|
QString errorStr = tr("<p>Failed to start the local drone agent - "
|
2017-09-26 09:29:49 -05:00
|
|
|
"error 0x%1, exit status 0x%2 exit code 0x%3.</p>")
|
|
|
|
.arg(localServer_->error(), 0, 16)
|
|
|
|
.arg(localServer_->exitStatus(), 0, 16)
|
2017-09-04 12:27:45 -05:00
|
|
|
.arg(localServer_->exitCode(), 0, 16);
|
2017-09-26 09:29:49 -05:00
|
|
|
if (localServer_->error() == QProcess::FailedToStart)
|
2017-09-23 08:24:42 -05:00
|
|
|
errorStr.append(tr("<p>The drone program does not exist at %1 or you "
|
|
|
|
"don't have sufficient permissions to execute it."
|
|
|
|
"</p>")
|
|
|
|
.arg(QCoreApplication::applicationDirPath()));
|
2017-09-26 09:29:49 -05:00
|
|
|
if (localServer_->exitCode() == 1)
|
|
|
|
errorStr.append(tr("<p>The drone program was not able to bind to "
|
|
|
|
"TCP port 7878 - maybe a drone process is already "
|
|
|
|
"running?</p>"));
|
2017-09-04 12:27:45 -05:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
if (localServer_->exitCode() == STATUS_DLL_NOT_FOUND)
|
|
|
|
errorStr.append(tr("<p>This is most likely because Packet.dll "
|
|
|
|
"was not found - make sure you have "
|
2022-09-30 10:03:25 -05:00
|
|
|
"<a href='%1'>npcap installed and accessible</a>."
|
|
|
|
"</p>")
|
2017-10-10 11:06:06 -05:00
|
|
|
.arg(jumpUrl("winpcap")));
|
2017-09-04 12:27:45 -05:00
|
|
|
#endif
|
|
|
|
msgBox.setText(errorStr);
|
2017-09-23 08:24:42 -05:00
|
|
|
msgBox.setInformativeText(tr("Try running drone directly."));
|
2017-09-04 12:27:45 -05:00
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
QMessageBox::information(this, QString(),
|
|
|
|
tr("<p>If you have remote drone agents running, you can still add "
|
|
|
|
"and connect to them.</p>"
|
|
|
|
"<p>If you don't want to start the local drone agent at startup, "
|
2017-12-31 22:13:27 -06:00
|
|
|
"provide the <b>-c</b> option to Ostinato on the command line.</p>"
|
2017-09-23 08:24:42 -05:00
|
|
|
"<p>Learn about Ostinato's <a href='%1'>Controller-Agent "
|
2017-10-10 11:06:06 -05:00
|
|
|
"architecture</a></p>").arg(jumpUrl("arch")));
|
2017-09-04 12:27:45 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 11:50:07 -05:00
|
|
|
void MainWindow::onNewVersion(QString newVersion)
|
|
|
|
{
|
2019-05-22 08:15:06 -05:00
|
|
|
QDate today = QDate::currentDate();
|
|
|
|
QDate lastChecked = QDate::fromString(
|
|
|
|
appSettings->value(kLastUpdateCheck).toString(),
|
|
|
|
Qt::ISODate);
|
|
|
|
if (lastChecked.daysTo(today) >= 5) {
|
|
|
|
QMessageBox::information(this, tr("Update check"),
|
2019-05-15 08:10:09 -05:00
|
|
|
tr("<p><b>Ostinato version %1 is now available</b> (you have %2). "
|
|
|
|
"See <a href='%3'>change log</a>.</p>"
|
|
|
|
"<p>Visit <a href='%4'>ostinato.org</a> to download.</p>")
|
2017-10-10 11:06:06 -05:00
|
|
|
.arg(newVersion)
|
2019-05-15 08:10:09 -05:00
|
|
|
.arg(version)
|
|
|
|
.arg(jumpUrl("changelog", "app", "status", "update"))
|
2017-10-10 11:06:06 -05:00
|
|
|
.arg(jumpUrl("download", "app", "status", "update")));
|
2019-05-22 08:15:06 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
QLabel *msg = new QLabel(tr("New Ostinato version %1 available. Visit "
|
|
|
|
"<a href='%2'>ostinato.org</a> to download")
|
|
|
|
.arg(newVersion)
|
|
|
|
.arg(jumpUrl("download", "app", "status", "update")));
|
|
|
|
msg->setOpenExternalLinks(true);
|
|
|
|
statusBar()->addPermanentWidget(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
appSettings->setValue(kLastUpdateCheck, today.toString(Qt::ISODate));
|
|
|
|
sender()->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::onLatestVersion(QString latestVersion)
|
|
|
|
{
|
|
|
|
if (version != latestVersion) {
|
|
|
|
QMessageBox::information(this, tr("Update check"),
|
|
|
|
tr("<p><b>Ostinato version %1 is now available</b> (you have %2). "
|
|
|
|
"See <a href='%3'>change log</a>.</p>"
|
|
|
|
"<p>Visit <a href='%4'>ostinato.org</a> to download.</p>")
|
|
|
|
.arg(latestVersion)
|
|
|
|
.arg(version)
|
|
|
|
.arg(jumpUrl("changelog", "app", "status", "update"))
|
|
|
|
.arg(jumpUrl("download", "app", "status", "update")));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QMessageBox::information(this, tr("Update check"),
|
|
|
|
tr("You are already running the latest Ostinato version - %1")
|
|
|
|
.arg(version));
|
|
|
|
}
|
|
|
|
|
|
|
|
sender()->deleteLater();
|
2015-04-16 11:50:07 -05:00
|
|
|
}
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
//! Returns true on success (or user cancel) and false on failure
|
|
|
|
bool MainWindow::openSession(QString fileName, QString &error)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
QDialog *optDialog;
|
|
|
|
QProgressDialog progress("Opening Session", "Cancel", 0, 0, this);
|
|
|
|
OstProto::SessionContent session;
|
|
|
|
SessionFileFormat *fmt = SessionFileFormat::fileFormatFromFile(fileName);
|
|
|
|
|
2016-05-17 10:17:10 -05:00
|
|
|
if (fmt == NULL) {
|
|
|
|
error = tr("Unknown session file format");
|
2016-04-13 21:14:07 -05:00
|
|
|
goto _fail;
|
2016-05-17 10:17:10 -05:00
|
|
|
}
|
2016-04-13 21:14:07 -05:00
|
|
|
|
|
|
|
if ((optDialog = fmt->openOptionsDialog()))
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
optDialog->setParent(this, Qt::Dialog);
|
|
|
|
ret = optDialog->exec();
|
|
|
|
optDialog->setParent(0, Qt::Dialog);
|
|
|
|
if (ret == QDialog::Rejected)
|
|
|
|
goto _user_opt_cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
progress.setAutoReset(false);
|
|
|
|
progress.setAutoClose(false);
|
|
|
|
progress.setMinimumDuration(0);
|
|
|
|
progress.show();
|
|
|
|
|
|
|
|
setDisabled(true);
|
|
|
|
progress.setEnabled(true); // to override the mainWindow disable
|
|
|
|
|
|
|
|
connect(fmt, SIGNAL(status(QString)),&progress,SLOT(setLabelText(QString)));
|
|
|
|
connect(fmt, SIGNAL(target(int)), &progress, SLOT(setMaximum(int)));
|
|
|
|
connect(fmt, SIGNAL(progress(int)), &progress, SLOT(setValue(int)));
|
|
|
|
connect(&progress, SIGNAL(canceled()), fmt, SLOT(cancel()));
|
|
|
|
|
|
|
|
fmt->openAsync(fileName, session, error);
|
|
|
|
qDebug("after open async");
|
|
|
|
|
|
|
|
while (!fmt->isFinished())
|
|
|
|
qApp->processEvents();
|
|
|
|
qDebug("wait over for async operation");
|
|
|
|
|
|
|
|
if (!fmt->result())
|
|
|
|
goto _fail;
|
|
|
|
|
|
|
|
// process any remaining events posted from the thread
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
qApp->processEvents();
|
|
|
|
|
|
|
|
// XXX: user can't cancel operation from here on!
|
|
|
|
progress.close();
|
|
|
|
|
|
|
|
portsWindow->openSession(&session, error);
|
|
|
|
|
|
|
|
_user_opt_cancel:
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
_fail:
|
|
|
|
progress.close();
|
|
|
|
setEnabled(true);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::saveSession(QString fileName, QString fileType, QString &error)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
QProgressDialog progress("Saving Session", "Cancel", 0, 0, this);
|
|
|
|
SessionFileFormat *fmt = SessionFileFormat::fileFormatFromType(fileType);
|
|
|
|
OstProto::SessionContent session;
|
|
|
|
|
|
|
|
if (fmt == NULL)
|
|
|
|
goto _fail;
|
|
|
|
|
|
|
|
progress.setAutoReset(false);
|
|
|
|
progress.setAutoClose(false);
|
|
|
|
progress.setMinimumDuration(0);
|
|
|
|
progress.show();
|
|
|
|
|
|
|
|
setDisabled(true);
|
|
|
|
progress.setEnabled(true); // to override the mainWindow disable
|
|
|
|
|
|
|
|
// Fill in session
|
|
|
|
ret = portsWindow->saveSession(&session, error, &progress);
|
|
|
|
if (!ret)
|
|
|
|
goto _user_cancel;
|
|
|
|
|
|
|
|
connect(fmt, SIGNAL(status(QString)),&progress,SLOT(setLabelText(QString)));
|
|
|
|
connect(fmt, SIGNAL(target(int)), &progress, SLOT(setMaximum(int)));
|
|
|
|
connect(fmt, SIGNAL(progress(int)), &progress, SLOT(setValue(int)));
|
|
|
|
connect(&progress, SIGNAL(canceled()), fmt, SLOT(cancel()));
|
|
|
|
|
|
|
|
fmt->saveAsync(session, fileName, error);
|
|
|
|
qDebug("after save async");
|
|
|
|
|
|
|
|
while (!fmt->isFinished())
|
|
|
|
qApp->processEvents();
|
|
|
|
qDebug("wait over for async operation");
|
|
|
|
|
|
|
|
ret = fmt->result();
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
_user_cancel:
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
_fail:
|
|
|
|
error = QString("Unsupported File Type - %1").arg(fileType);
|
|
|
|
goto _exit;
|
|
|
|
|
|
|
|
_exit:
|
|
|
|
progress.close();
|
|
|
|
setEnabled(true);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|