2014-05-18 11:52:39 -04:00
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// //
// This program 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 as version 3 of the License, or //
// //
// 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 V3 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 <QInputDialog>
# include <QMessageBox>
# include <QLabel>
2016-03-29 04:57:50 -04:00
# include <QFile>
2016-03-29 05:04:08 -04:00
# include <QFileInfo>
2016-03-29 04:57:50 -04:00
# include <QFileDialog>
# include <QTextStream>
2016-05-09 12:17:53 -04:00
# include <QMessageBox>
2016-05-12 13:06:38 -04:00
# include <QDateTime>
2016-05-12 13:28:04 -04:00
# include <QSysInfo>
2016-03-29 04:57:50 -04:00
2014-05-18 11:52:39 -04:00
# include "mainwindow.h"
# include "ui_mainwindow.h"
# include "audio/audiodeviceinfo.h"
# include "gui/indicator.h"
# include "gui/presetitem.h"
# include "gui/addpresetdialog.h"
# include "gui/pluginsdialog.h"
# include "gui/aboutdialog.h"
# include "gui/rollupwidget.h"
2015-10-07 20:40:31 -04:00
# include "gui/channelwindow.h"
2016-05-04 11:07:26 -04:00
# include "gui/audiodialog.h"
2016-05-14 08:12:57 -04:00
# include "gui/samplingdevicecontrol.h"
2014-05-18 11:52:39 -04:00
# include "dsp/dspengine.h"
# include "dsp/spectrumvis.h"
# include "dsp/dspcommands.h"
# include "plugin/plugingui.h"
# include "plugin/pluginapi.h"
2016-05-15 19:12:37 -04:00
# include "device/deviceapi.h"
2014-05-18 11:52:39 -04:00
# include "plugin/plugingui.h"
2015-10-06 21:53:25 -04:00
# include "gui/glspectrum.h"
# include "gui/glspectrumgui.h"
2015-07-28 17:54:17 -04:00
# include <string>
2015-08-09 04:33:04 -04:00
# include <QDebug>
2015-06-06 21:30:28 -04:00
2014-05-18 11:52:39 -04:00
MainWindow : : MainWindow ( QWidget * parent ) :
QMainWindow ( parent ) ,
ui ( new Ui : : MainWindow ) ,
m_audioDeviceInfo ( new AudioDeviceInfo ) ,
m_settings ( ) ,
2015-08-08 22:09:05 -04:00
m_dspEngine ( DSPEngine : : instance ( ) ) ,
2015-10-14 22:05:19 -04:00
m_lastEngineState ( ( DSPDeviceEngine : : State ) - 1 ) ,
2015-05-09 04:51:02 -04:00
m_inputGUI ( 0 ) ,
2014-05-18 11:52:39 -04:00
m_sampleRate ( 0 ) ,
m_centerFrequency ( 0 ) ,
2015-08-29 16:42:58 -04:00
m_sampleFileName ( std : : string ( " ./test.sdriq " ) )
2014-05-18 11:52:39 -04:00
{
2015-08-18 03:24:56 -04:00
qDebug ( ) < < " MainWindow::MainWindow: start " ;
2015-08-08 22:09:05 -04:00
2014-05-18 11:52:39 -04:00
ui - > setupUi ( this ) ;
createStatusBar ( ) ;
setCorner ( Qt : : TopLeftCorner , Qt : : LeftDockWidgetArea ) ;
setCorner ( Qt : : BottomLeftCorner , Qt : : LeftDockWidgetArea ) ;
setCorner ( Qt : : TopRightCorner , Qt : : RightDockWidgetArea ) ;
setCorner ( Qt : : BottomRightCorner , Qt : : RightDockWidgetArea ) ;
// work around broken Qt dock widget ordering
2016-05-13 21:15:03 -04:00
removeDockWidget ( ui - > inputSelectDock ) ;
removeDockWidget ( ui - > inputViewDock ) ;
2015-10-02 21:56:03 -04:00
removeDockWidget ( ui - > spectraDisplayDock ) ;
2014-05-18 11:52:39 -04:00
removeDockWidget ( ui - > presetDock ) ;
removeDockWidget ( ui - > channelDock ) ;
2016-05-13 21:15:03 -04:00
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > inputSelectDock ) ;
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > inputViewDock ) ;
2015-10-02 21:56:03 -04:00
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > spectraDisplayDock ) ;
2014-05-18 11:52:39 -04:00
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > presetDock ) ;
addDockWidget ( Qt : : RightDockWidgetArea , ui - > channelDock ) ;
2015-08-18 03:24:56 -04:00
2016-05-13 21:15:03 -04:00
ui - > inputSelectDock - > show ( ) ;
ui - > inputSelectDock - > show ( ) ;
2015-10-02 21:56:03 -04:00
ui - > spectraDisplayDock - > show ( ) ;
2014-05-18 11:52:39 -04:00
ui - > presetDock - > show ( ) ;
ui - > channelDock - > show ( ) ;
2016-05-13 21:15:03 -04:00
ui - > menu_Window - > addAction ( ui - > inputSelectDock - > toggleViewAction ( ) ) ;
ui - > menu_Window - > addAction ( ui - > inputViewDock - > toggleViewAction ( ) ) ;
2015-10-02 21:56:03 -04:00
ui - > menu_Window - > addAction ( ui - > spectraDisplayDock - > toggleViewAction ( ) ) ;
2014-05-18 11:52:39 -04:00
ui - > menu_Window - > addAction ( ui - > presetDock - > toggleViewAction ( ) ) ;
ui - > menu_Window - > addAction ( ui - > channelDock - > toggleViewAction ( ) ) ;
2016-05-16 04:18:22 -04:00
ui - > tabInputsView - > setStyleSheet ( " QWidget { background: rgb(50,50,50); } "
2016-05-14 22:38:37 -04:00
" QToolButton::checked { background: rgb(128,70,0); } "
2016-05-15 04:11:22 -04:00
" QComboBox::item:selected { color: rgb(255,140,0); } "
2016-05-16 04:18:22 -04:00
" QTabWidget::pane { border: 1px solid #C06900; } "
2016-05-15 04:11:22 -04:00
" QTabBar::tab:selected { background: rgb(128,70,0); } " ) ;
2016-05-16 04:18:22 -04:00
ui - > tabInputsSelect - > setStyleSheet ( " QWidget { background: rgb(50,50,50); } "
2016-05-14 22:38:37 -04:00
" QToolButton::checked { background: rgb(128,70,0); } "
2016-05-15 04:11:22 -04:00
" QComboBox::item:selected { color: rgb(255,140,0); } "
2016-05-16 04:18:22 -04:00
" QTabWidget::pane { border: 1px solid #C06900; } "
2016-05-15 04:11:22 -04:00
" QTabBar::tab:selected { background: rgb(128,70,0); } " ) ;
2016-05-13 18:49:18 -04:00
2015-08-17 20:47:14 -04:00
connect ( & m_inputMessageQueue , SIGNAL ( messageEnqueued ( ) ) , this , SLOT ( handleMessages ( ) ) , Qt : : QueuedConnection ) ;
2015-08-18 03:24:56 -04:00
2016-05-12 13:06:38 -04:00
connect ( & m_statusTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatus ( ) ) ) ;
m_statusTimer . start ( 1000 ) ;
2014-05-18 11:52:39 -04:00
2015-07-31 21:33:07 -04:00
m_masterTimer . start ( 50 ) ;
2015-08-25 20:03:20 -04:00
qDebug ( ) < < " MainWindow::MainWindow: m_pluginManager->loadPlugins ... " ;
2016-05-13 03:23:33 -04:00
addDevice ( ) ; // add the first device
// DSPDeviceEngine *dspDeviceEngine = m_dspEngine->addDeviceEngine();
// dspDeviceEngine->start();
//
// m_deviceUIs.push_back(new DeviceUISet(m_masterTimer));
//
// m_pluginManager = new PluginManager(this, dspDeviceEngine, m_deviceUIs.back()->m_spectrum);
// m_pluginManager->loadPlugins();
//
// ui->tabSpectra->addTab(m_deviceUIs.back()->m_spectrum, "X0");
// ui->tabSpectraGUI->addTab(m_deviceUIs.back()->m_spectrumGUI, "X0");
// dspDeviceEngine->addSink(m_deviceUIs.back()->m_spectrumVis);
// ui->tabChannels->addTab(m_deviceUIs.back()->m_channelWindow, "X0");
// bool sampleSourceSignalsBlocked = m_deviceUIs.back()->m_sampleSource->blockSignals(true);
// m_pluginManager->fillSampleSourceSelector(m_deviceUIs.back()->m_sampleSource);
// connect(m_deviceUIs.back()->m_sampleSource, SIGNAL(currentIndexChanged(int)), this, SLOT(on_sampleSource_currentIndexChanged(int)));
// m_deviceUIs.back()->m_sampleSource->blockSignals(sampleSourceSignalsBlocked);
2016-05-13 18:49:18 -04:00
// ui->tabInputsSelect->addTab(m_deviceUIs.back()->m_sampleSource, "X0");
2015-10-02 21:56:03 -04:00
2015-08-18 19:02:52 -04:00
qDebug ( ) < < " MainWindow::MainWindow: loadSettings... " ;
2015-08-18 03:24:56 -04:00
2014-05-18 11:52:39 -04:00
loadSettings ( ) ;
2015-08-18 19:02:52 -04:00
qDebug ( ) < < " MainWindow::MainWindow: select SampleSource from settings... " ;
2015-08-18 03:24:56 -04:00
2015-10-01 20:22:56 -04:00
int sampleSourceIndex = m_settings . getSourceIndex ( ) ;
2016-05-15 19:12:37 -04:00
sampleSourceIndex = m_deviceUIs . back ( ) - > m_pluginManager - > selectSampleSourceByIndex ( sampleSourceIndex , m_deviceUIs . back ( ) - > m_deviceAPI ) ;
2015-08-18 03:24:56 -04:00
2015-10-02 08:19:28 -04:00
if ( sampleSourceIndex > = 0 )
2015-08-18 03:24:56 -04:00
{
2016-05-14 08:12:57 -04:00
bool sampleSourceSignalsBlocked = m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) - > blockSignals ( true ) ;
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) - > setCurrentIndex ( sampleSourceIndex ) ;
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) - > blockSignals ( sampleSourceSignalsBlocked ) ;
2014-05-18 11:52:39 -04:00
}
2015-08-23 18:51:27 -04:00
qDebug ( ) < < " MainWindow::MainWindow: load current preset settings... " ;
2015-08-18 03:24:56 -04:00
2015-10-01 20:22:56 -04:00
loadPresetSettings ( m_settings . getWorkingPreset ( ) ) ;
2014-05-18 11:52:39 -04:00
2015-08-18 19:02:52 -04:00
qDebug ( ) < < " MainWindow::MainWindow: apply settings... " ;
2015-08-18 03:24:56 -04:00
2014-05-18 11:52:39 -04:00
applySettings ( ) ;
2015-08-18 03:24:56 -04:00
2015-08-23 18:51:27 -04:00
qDebug ( ) < < " MainWindow::MainWindow: update preset controls... " ;
2015-08-18 03:24:56 -04:00
2015-08-23 18:51:27 -04:00
updatePresetControls ( ) ;
2015-08-18 03:24:56 -04:00
qDebug ( ) < < " MainWindow::MainWindow: end " ;
2016-05-13 21:36:28 -04:00
connect ( ui - > tabInputsView , SIGNAL ( currentChanged ( int ) ) , this , SLOT ( tabInputViewIndexChanged ( ) ) ) ;
2014-05-18 11:52:39 -04:00
}
MainWindow : : ~ MainWindow ( )
{
2016-05-13 05:42:03 -04:00
saveSettings ( ) ;
2014-05-18 11:52:39 -04:00
2016-05-13 05:42:03 -04:00
while ( m_deviceUIs . size ( ) > 0 )
{
removeLastDevice ( ) ;
}
2014-05-18 11:52:39 -04:00
2016-05-12 13:28:04 -04:00
delete m_dateTimeWidget ;
delete m_showSystemWidget ;
2014-05-18 11:52:39 -04:00
delete ui ;
}
2016-05-13 03:23:33 -04:00
void MainWindow : : addDevice ( )
{
DSPDeviceEngine * dspDeviceEngine = m_dspEngine - > addDeviceEngine ( ) ;
dspDeviceEngine - > start ( ) ;
2016-05-13 05:42:03 -04:00
uint dspDeviceEngineUID = dspDeviceEngine - > getUID ( ) ;
2016-05-13 03:23:33 -04:00
char tabNameCStr [ 16 ] ;
2016-05-13 05:42:03 -04:00
sprintf ( tabNameCStr , " R%d " , dspDeviceEngineUID ) ;
2016-05-13 03:23:33 -04:00
m_deviceUIs . push_back ( new DeviceUISet ( m_masterTimer ) ) ;
2016-05-13 05:42:03 -04:00
m_deviceUIs . back ( ) - > m_deviceEngine = dspDeviceEngine ;
2016-05-13 03:23:33 -04:00
2016-05-16 10:02:55 -04:00
DeviceAPI * deviceAPI = new DeviceAPI ( this , m_deviceUIs . size ( ) - 1 , dspDeviceEngine , m_deviceUIs . back ( ) - > m_spectrum , m_deviceUIs . back ( ) - > m_channelWindow ) ;
2016-05-15 19:12:37 -04:00
m_deviceUIs . back ( ) - > m_deviceAPI = deviceAPI ;
// TODO: do not create one plugin manager per device. Use device API instead
2016-05-16 04:40:18 -04:00
PluginManager * pluginManager = new PluginManager ( this , m_deviceUIs . size ( ) - 1 , dspDeviceEngine ) ;
2016-05-13 05:42:03 -04:00
m_deviceUIs . back ( ) - > m_pluginManager = pluginManager ;
2016-05-15 19:12:37 -04:00
2016-05-13 05:42:03 -04:00
pluginManager - > loadPlugins ( ) ;
2016-05-13 03:23:33 -04:00
2016-05-15 21:21:21 -04:00
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > setDeviceAPI ( deviceAPI ) ;
2016-05-14 12:12:39 -04:00
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > setPluginManager ( pluginManager ) ;
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > populateChannelSelector ( ) ;
2016-05-13 05:42:03 -04:00
dspDeviceEngine - > addSink ( m_deviceUIs . back ( ) - > m_spectrumVis ) ;
2016-05-13 03:23:33 -04:00
ui - > tabSpectra - > addTab ( m_deviceUIs . back ( ) - > m_spectrum , tabNameCStr ) ;
ui - > tabSpectraGUI - > addTab ( m_deviceUIs . back ( ) - > m_spectrumGUI , tabNameCStr ) ;
ui - > tabChannels - > addTab ( m_deviceUIs . back ( ) - > m_channelWindow , tabNameCStr ) ;
2016-05-13 05:42:03 -04:00
2016-05-14 08:12:57 -04:00
bool sampleSourceSignalsBlocked = m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) - > blockSignals ( true ) ;
pluginManager - > fillSampleSourceSelector ( m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) ) ;
connect ( m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( on_sampleSource_currentIndexChanged ( int ) ) ) ;
m_deviceUIs . back ( ) - > m_samplingDeviceControl - > getDeviceSelector ( ) - > blockSignals ( sampleSourceSignalsBlocked ) ;
ui - > tabInputsSelect - > addTab ( m_deviceUIs . back ( ) - > m_samplingDeviceControl , tabNameCStr ) ;
2016-05-13 05:42:03 -04:00
}
void MainWindow : : removeLastDevice ( )
{
DSPDeviceEngine * lastDeviceEngine = m_deviceUIs . back ( ) - > m_deviceEngine ;
lastDeviceEngine - > stopAcquistion ( ) ;
lastDeviceEngine - > removeSink ( m_deviceUIs . back ( ) - > m_spectrumVis ) ;
ui - > tabChannels - > removeTab ( ui - > tabChannels - > count ( ) - 1 ) ;
ui - > tabSpectraGUI - > removeTab ( ui - > tabSpectraGUI - > count ( ) - 1 ) ;
ui - > tabSpectra - > removeTab ( ui - > tabSpectra - > count ( ) - 1 ) ;
// PluginManager destructor does freeAll() which does stopAcquistion() but stopAcquistion()
// can be done several times only the first is active so it is fine to do it here
// On the other hand freeAll() must be executed only once
delete m_deviceUIs . back ( ) - > m_pluginManager ;
//m_deviceUIs.back()->m_pluginManager->freeAll();
2016-05-15 19:12:37 -04:00
//delete m_deviceUIs.back()->m_deviceAPI; // TODO: reinstate when plugin manager is not created for each device
2016-05-13 05:42:03 -04:00
lastDeviceEngine - > stop ( ) ;
m_dspEngine - > removeLastDeviceEngine ( ) ;
2016-05-13 21:15:03 -04:00
if ( ui - > tabInputsView - > count ( ) = = ui - > tabInputsSelect - > count ( ) )
{
ui - > tabInputsView - > removeTab ( ui - > tabInputsView - > count ( ) - 1 ) ;
}
2016-05-13 18:49:18 -04:00
ui - > tabInputsSelect - > removeTab ( ui - > tabInputsSelect - > count ( ) - 1 ) ;
2016-05-13 05:42:03 -04:00
delete m_deviceUIs . back ( ) ;
m_deviceUIs . pop_back ( ) ;
2016-05-13 03:23:33 -04:00
}
2016-05-15 05:26:48 -04:00
void MainWindow : : addChannelRollup ( int deviceTabIndex , QWidget * widget )
2014-05-18 11:52:39 -04:00
{
2016-05-15 05:26:48 -04:00
if ( deviceTabIndex < ui - > tabInputsView - > count ( ) )
{
DeviceUISet * deviceUI = m_deviceUIs [ deviceTabIndex ] ;
deviceUI - > m_channelWindow - > addRollupWidget ( widget ) ;
ui - > channelDock - > show ( ) ;
ui - > channelDock - > raise ( ) ;
}
2014-05-18 11:52:39 -04:00
}
void MainWindow : : addViewAction ( QAction * action )
{
ui - > menu_Window - > addAction ( action ) ;
}
2016-05-14 22:38:37 -04:00
void MainWindow : : setInputGUI ( int deviceTabIndex , QWidget * gui , const QString & sourceDisplayName )
2014-05-18 11:52:39 -04:00
{
2016-05-13 18:49:18 -04:00
char tabNameCStr [ 16 ] ;
sprintf ( tabNameCStr , " R%d " , deviceTabIndex ) ;
if ( deviceTabIndex < ui - > tabInputsView - > count ( ) )
{
2016-05-14 22:38:37 -04:00
qDebug ( " MainWindow::setInputGUI: tab device index %d replace " , deviceTabIndex ) ;
2016-05-13 18:49:18 -04:00
ui - > tabInputsView - > removeTab ( deviceTabIndex ) ;
ui - > tabInputsView - > insertTab ( deviceTabIndex , gui , tabNameCStr ) ;
}
else
{
2016-05-14 22:38:37 -04:00
qDebug ( " MainWindow::setInputGUI: tab device index %d add " , deviceTabIndex ) ;
2016-05-13 18:49:18 -04:00
ui - > tabInputsView - > addTab ( gui , tabNameCStr ) ;
}
2016-05-14 22:38:37 -04:00
ui - > tabInputsView - > setTabToolTip ( deviceTabIndex , sourceDisplayName ) ;
2014-05-18 11:52:39 -04:00
}
void MainWindow : : loadSettings ( )
{
2015-08-09 04:33:04 -04:00
qDebug ( ) < < " MainWindow::loadSettings " ;
2015-08-18 03:24:56 -04:00
2015-06-06 21:30:28 -04:00
m_settings . load ( ) ;
2014-05-18 11:52:39 -04:00
2015-06-06 21:30:28 -04:00
for ( int i = 0 ; i < m_settings . getPresetCount ( ) ; + + i )
{
addPresetToTree ( m_settings . getPreset ( i ) ) ;
}
2014-05-18 11:52:39 -04:00
}
2015-10-01 22:04:38 -04:00
void MainWindow : : loadPresetSettings ( const Preset * preset )
2014-05-18 11:52:39 -04:00
{
2015-10-01 20:22:56 -04:00
qDebug ( " MainWindow::loadPresetSettings: preset [%s | %s] " ,
qPrintable ( preset - > getGroup ( ) ) ,
qPrintable ( preset - > getDescription ( ) ) ) ;
2014-05-18 11:52:39 -04:00
2016-05-13 09:45:42 -04:00
// Load into currently selected source tab
2016-05-13 21:15:03 -04:00
int currentSourceTabIndex = ui - > tabInputsView - > currentIndex ( ) ;
2016-05-13 09:45:42 -04:00
if ( currentSourceTabIndex > = 0 )
{
DeviceUISet * deviceUI = m_deviceUIs [ currentSourceTabIndex ] ;
2016-05-16 13:55:01 -04:00
PluginAPI pluginAPI ( deviceUI - > m_pluginManager , this ) ;
2016-05-13 09:45:42 -04:00
deviceUI - > m_spectrumGUI - > deserialize ( preset - > getSpectrumConfig ( ) ) ;
2016-05-16 13:55:01 -04:00
deviceUI - > m_deviceAPI - > loadChannelSettings ( preset , & pluginAPI ) ;
2016-05-16 11:47:22 -04:00
deviceUI - > m_deviceAPI - > loadSourceSettings ( preset ) ;
2016-05-13 09:45:42 -04:00
}
2014-05-18 11:52:39 -04:00
// has to be last step
restoreState ( preset - > getLayout ( ) ) ;
}
void MainWindow : : saveSettings ( )
{
2015-08-09 04:33:04 -04:00
qDebug ( ) < < " MainWindow::saveSettings " ;
2015-06-06 21:30:28 -04:00
2015-10-01 20:22:56 -04:00
savePresetSettings ( m_settings . getWorkingPreset ( ) ) ;
2014-05-18 11:52:39 -04:00
m_settings . save ( ) ;
}
2015-08-23 18:51:27 -04:00
void MainWindow : : savePresetSettings ( Preset * preset )
2014-05-18 11:52:39 -04:00
{
2015-10-01 20:22:56 -04:00
qDebug ( " MainWindow::savePresetSettings: preset [%s | %s] " ,
qPrintable ( preset - > getGroup ( ) ) ,
qPrintable ( preset - > getDescription ( ) ) ) ;
2015-06-06 21:30:28 -04:00
2016-05-13 09:45:42 -04:00
// Save from currently selected source tab
2016-05-13 21:15:03 -04:00
int currentSourceTabIndex = ui - > tabInputsView - > currentIndex ( ) ;
2016-05-15 04:34:48 -04:00
DeviceUISet * deviceUI = m_deviceUIs [ currentSourceTabIndex ] ;
2016-05-13 09:45:42 -04:00
2016-05-15 04:34:48 -04:00
preset - > setSpectrumConfig ( deviceUI - > m_spectrumGUI - > serialize ( ) ) ;
preset - > clearChannels ( ) ;
2016-05-16 13:55:01 -04:00
deviceUI - > m_deviceAPI - > saveChannelSettings ( preset ) ;
2016-05-16 11:47:22 -04:00
deviceUI - > m_deviceAPI - > saveSourceSettings ( preset ) ;
2014-05-18 11:52:39 -04:00
2015-06-06 21:30:28 -04:00
preset - > setLayout ( saveState ( ) ) ;
2014-05-18 11:52:39 -04:00
}
void MainWindow : : createStatusBar ( )
{
2016-05-14 22:51:34 -04:00
QString qtVersionStr = QString ( " Qt %1 " ) . arg ( QT_VERSION_STR ) ;
m_showSystemWidget = new QLabel ( " SDRangel v2.0.0 " + qtVersionStr + QSysInfo : : prettyProductName ( ) , this ) ;
2016-05-12 13:28:04 -04:00
statusBar ( ) - > addPermanentWidget ( m_showSystemWidget ) ;
2016-05-12 13:06:38 -04:00
m_dateTimeWidget = new QLabel ( tr ( " Date " ) , this ) ;
m_dateTimeWidget - > setToolTip ( tr ( " Current date/time " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_dateTimeWidget ) ;
2014-05-18 11:52:39 -04:00
}
void MainWindow : : closeEvent ( QCloseEvent * )
{
}
2015-08-23 18:51:27 -04:00
void MainWindow : : updatePresetControls ( )
2014-05-18 11:52:39 -04:00
{
ui - > presetTree - > resizeColumnToContents ( 0 ) ;
2015-08-23 18:51:27 -04:00
if ( ui - > presetTree - > currentItem ( ) ! = 0 )
{
2014-05-18 11:52:39 -04:00
ui - > presetDelete - > setEnabled ( true ) ;
ui - > presetLoad - > setEnabled ( true ) ;
2015-08-23 18:51:27 -04:00
}
else
{
2014-05-18 11:52:39 -04:00
ui - > presetDelete - > setEnabled ( false ) ;
ui - > presetLoad - > setEnabled ( false ) ;
}
}
QTreeWidgetItem * MainWindow : : addPresetToTree ( const Preset * preset )
{
2015-05-09 04:51:02 -04:00
QTreeWidgetItem * group = 0 ;
2015-10-08 19:50:09 -04:00
for ( int i = 0 ; i < ui - > presetTree - > topLevelItemCount ( ) ; i + + )
{
if ( ui - > presetTree - > topLevelItem ( i ) - > text ( 0 ) = = preset - > getGroup ( ) )
{
2014-05-18 11:52:39 -04:00
group = ui - > presetTree - > topLevelItem ( i ) ;
break ;
}
}
2015-10-08 19:50:09 -04:00
if ( group = = 0 )
{
2014-05-18 11:52:39 -04:00
QStringList sl ;
sl . append ( preset - > getGroup ( ) ) ;
group = new QTreeWidgetItem ( ui - > presetTree , sl , PGroup ) ;
group - > setFirstColumnSpanned ( true ) ;
group - > setExpanded ( true ) ;
ui - > presetTree - > sortByColumn ( 0 , Qt : : AscendingOrder ) ;
}
2015-10-08 19:50:09 -04:00
2014-05-18 11:52:39 -04:00
QStringList sl ;
sl . append ( QString ( " %1 kHz " ) . arg ( preset - > getCenterFrequency ( ) / 1000 ) ) ;
sl . append ( preset - > getDescription ( ) ) ;
PresetItem * item = new PresetItem ( group , sl , preset - > getCenterFrequency ( ) , PItem ) ;
item - > setTextAlignment ( 0 , Qt : : AlignRight ) ;
item - > setData ( 0 , Qt : : UserRole , qVariantFromValue ( preset ) ) ;
ui - > presetTree - > resizeColumnToContents ( 0 ) ;
2015-08-23 18:51:27 -04:00
updatePresetControls ( ) ;
2014-05-18 11:52:39 -04:00
return item ;
}
void MainWindow : : applySettings ( )
{
}
2015-08-08 22:09:05 -04:00
void MainWindow : : handleMessages ( )
{
Message * message ;
2015-08-30 17:22:18 -04:00
while ( ( message = m_inputMessageQueue . pop ( ) ) ! = 0 )
2015-08-08 22:09:05 -04:00
{
2016-05-12 04:31:57 -04:00
qDebug ( " MainWindow::handleMessages: message: %s " , message - > getIdentifier ( ) ) ;
2016-05-13 09:45:42 -04:00
delete message ;
//
// if (!m_pluginManager->handleMessage(*message))
// {
// delete message;
// }
2014-05-18 11:52:39 -04:00
}
}
void MainWindow : : on_action_View_Fullscreen_toggled ( bool checked )
{
if ( checked )
showFullScreen ( ) ;
else showNormal ( ) ;
}
void MainWindow : : on_presetSave_clicked ( )
{
QStringList groups ;
QString group ;
2015-05-09 04:51:02 -04:00
QString description = " " ;
2014-05-18 11:52:39 -04:00
for ( int i = 0 ; i < ui - > presetTree - > topLevelItemCount ( ) ; i + + )
groups . append ( ui - > presetTree - > topLevelItem ( i ) - > text ( 0 ) ) ;
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
2015-05-09 04:51:02 -04:00
if ( item ! = 0 ) {
2014-05-18 11:52:39 -04:00
if ( item - > type ( ) = = PGroup )
group = item - > text ( 0 ) ;
2015-05-09 04:51:02 -04:00
else if ( item - > type ( ) = = PItem ) {
2014-05-18 11:52:39 -04:00
group = item - > parent ( ) - > text ( 0 ) ;
2015-05-09 04:51:02 -04:00
description = item - > text ( 0 ) ;
}
2014-05-18 11:52:39 -04:00
}
AddPresetDialog dlg ( groups , group , this ) ;
2015-05-09 04:51:02 -04:00
if ( description . length ( ) > 0 ) {
dlg . setDescription ( description ) ;
}
2014-05-18 11:52:39 -04:00
if ( dlg . exec ( ) = = QDialog : : Accepted ) {
Preset * preset = m_settings . newPreset ( dlg . group ( ) , dlg . description ( ) ) ;
2015-08-23 18:51:27 -04:00
savePresetSettings ( preset ) ;
2014-05-18 11:52:39 -04:00
ui - > presetTree - > setCurrentItem ( addPresetToTree ( preset ) ) ;
}
}
2015-05-09 04:51:02 -04:00
void MainWindow : : on_presetUpdate_clicked ( )
{
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
2016-05-04 11:07:26 -04:00
2015-05-09 04:51:02 -04:00
if ( item ! = 0 ) {
if ( item - > type ( ) = = PItem ) {
const Preset * preset = qvariant_cast < const Preset * > ( item - > data ( 0 , Qt : : UserRole ) ) ;
if ( preset ! = 0 ) {
Preset * preset_mod = const_cast < Preset * > ( preset ) ;
2015-08-23 18:51:27 -04:00
savePresetSettings ( preset_mod ) ;
2015-05-09 04:51:02 -04:00
}
}
}
}
2016-03-29 04:57:50 -04:00
void MainWindow : : on_presetExport_clicked ( )
{
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
if ( item ! = 0 ) {
if ( item - > type ( ) = = PItem )
{
const Preset * preset = qvariant_cast < const Preset * > ( item - > data ( 0 , Qt : : UserRole ) ) ;
QString base64Str = preset - > serialize ( ) . toBase64 ( ) ;
QString fileName = QFileDialog : : getSaveFileName ( this ,
tr ( " Open preset export file " ) , " . " , tr ( " Preset export files (*.prex) " ) ) ;
if ( fileName ! = " " )
{
2016-03-29 05:04:08 -04:00
QFileInfo fileInfo ( fileName ) ;
if ( fileInfo . suffix ( ) ! = " prex " ) {
fileName + = " .prex " ;
}
2016-03-29 04:57:50 -04:00
QFile exportFile ( fileName ) ;
if ( exportFile . open ( QIODevice : : WriteOnly | QIODevice : : Text ) )
{
QTextStream outstream ( & exportFile ) ;
outstream < < base64Str ;
exportFile . close ( ) ;
}
else
{
QMessageBox : : information ( this , tr ( " Message " ) , tr ( " Cannot open file for writing " ) ) ;
}
}
}
}
}
void MainWindow : : on_presetImport_clicked ( )
{
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
if ( item ! = 0 )
{
QString group ;
if ( item - > type ( ) = = PGroup ) {
group = item - > text ( 0 ) ;
} else if ( item - > type ( ) = = PItem ) {
group = item - > parent ( ) - > text ( 0 ) ;
} else {
return ;
}
QString fileName = QFileDialog : : getOpenFileName ( this ,
tr ( " Open preset export file " ) , " . " , tr ( " Preset export files (*.prex) " ) ) ;
if ( fileName ! = " " )
{
QFile exportFile ( fileName ) ;
if ( exportFile . open ( QIODevice : : ReadOnly | QIODevice : : Text ) )
{
QByteArray base64Str ;
QTextStream instream ( & exportFile ) ;
instream > > base64Str ;
exportFile . close ( ) ;
2016-03-29 08:51:52 -04:00
Preset * preset = m_settings . newPreset ( " " , " " ) ;
2016-03-29 04:57:50 -04:00
preset - > deserialize ( QByteArray : : fromBase64 ( base64Str ) ) ;
2016-03-29 08:51:52 -04:00
preset - > setGroup ( group ) ; // override with current group
2016-03-29 04:57:50 -04:00
ui - > presetTree - > setCurrentItem ( addPresetToTree ( preset ) ) ;
}
else
{
QMessageBox : : information ( this , tr ( " Message " ) , tr ( " Cannot open file for reading " ) ) ;
}
}
}
}
2015-10-02 20:14:26 -04:00
void MainWindow : : on_settingsSave_clicked ( )
{
saveSettings ( ) ;
}
2014-05-18 11:52:39 -04:00
void MainWindow : : on_presetLoad_clicked ( )
{
2015-08-13 02:51:33 -04:00
qDebug ( ) < < " MainWindow::on_presetLoad_clicked " ;
2014-05-18 11:52:39 -04:00
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
2015-08-23 20:06:11 -04:00
if ( item = = 0 )
{
2015-10-01 22:04:38 -04:00
qDebug ( " MainWindow::on_presetLoad_clicked: item null " ) ;
2015-08-23 18:51:27 -04:00
updatePresetControls ( ) ;
2014-05-18 11:52:39 -04:00
return ;
}
2015-08-23 20:06:11 -04:00
2015-10-01 22:04:38 -04:00
const Preset * preset = qvariant_cast < const Preset * > ( item - > data ( 0 , Qt : : UserRole ) ) ;
2015-08-23 20:06:11 -04:00
if ( preset = = 0 )
{
2015-10-01 22:04:38 -04:00
qDebug ( " MainWindow::on_presetLoad_clicked: preset null " ) ;
2014-05-18 11:52:39 -04:00
return ;
2015-05-09 04:51:02 -04:00
}
2014-05-18 11:52:39 -04:00
2015-08-23 18:51:27 -04:00
loadPresetSettings ( preset ) ;
2014-05-18 11:52:39 -04:00
applySettings ( ) ;
}
void MainWindow : : on_presetDelete_clicked ( )
{
QTreeWidgetItem * item = ui - > presetTree - > currentItem ( ) ;
2015-05-09 04:51:02 -04:00
if ( item = = 0 ) {
2015-08-23 18:51:27 -04:00
updatePresetControls ( ) ;
2014-05-18 11:52:39 -04:00
return ;
}
const Preset * preset = qvariant_cast < const Preset * > ( item - > data ( 0 , Qt : : UserRole ) ) ;
2015-05-09 04:51:02 -04:00
if ( preset = = 0 )
2014-05-18 11:52:39 -04:00
return ;
if ( QMessageBox : : question ( this , tr ( " Delete Preset " ) , tr ( " Do you want to delete preset '%1'? " ) . arg ( preset - > getDescription ( ) ) , QMessageBox : : No | QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) {
delete item ;
m_settings . deletePreset ( preset ) ;
}
}
void MainWindow : : on_presetTree_currentItemChanged ( QTreeWidgetItem * current , QTreeWidgetItem * previous )
{
2015-08-23 18:51:27 -04:00
updatePresetControls ( ) ;
2014-05-18 11:52:39 -04:00
}
void MainWindow : : on_presetTree_itemActivated ( QTreeWidgetItem * item , int column )
{
on_presetLoad_clicked ( ) ;
}
2016-05-04 11:07:26 -04:00
void MainWindow : : on_action_Audio_triggered ( )
2014-05-18 11:52:39 -04:00
{
2016-05-04 11:07:26 -04:00
AudioDialog audioDialog ( m_audioDeviceInfo , this ) ;
audioDialog . exec ( ) ;
2014-05-18 11:52:39 -04:00
}
2016-05-08 00:00:37 -04:00
void MainWindow : : on_action_DV_Serial_triggered ( bool checked )
{
m_dspEngine - > setDVSerialSupport ( checked ) ;
2016-05-09 12:17:53 -04:00
if ( checked )
{
std : : vector < std : : string > deviceNames ;
m_dspEngine - > getDVSerialNames ( deviceNames ) ;
if ( deviceNames . size ( ) = = 0 )
{
QMessageBox : : information ( this , tr ( " Message " ) , tr ( " No DV serial devices found " ) ) ;
}
else
{
std : : vector < std : : string > : : iterator it = deviceNames . begin ( ) ;
std : : string deviceNamesStr = " DV Serial devices found: " ;
while ( it ! = deviceNames . end ( ) )
{
if ( it ! = deviceNames . begin ( ) ) {
deviceNamesStr + = " , " ;
}
deviceNamesStr + = * it ;
+ + it ;
}
QMessageBox : : information ( this , tr ( " Message " ) , tr ( deviceNamesStr . c_str ( ) ) ) ;
}
}
2016-05-08 00:00:37 -04:00
}
2014-05-18 11:52:39 -04:00
void MainWindow : : on_sampleSource_currentIndexChanged ( int index )
{
2016-05-13 09:45:42 -04:00
// Do it in the currently selected source tab
2016-05-13 18:49:18 -04:00
int currentSourceTabIndex = ui - > tabInputsSelect - > currentIndex ( ) ;
2016-05-13 09:45:42 -04:00
if ( currentSourceTabIndex > = 0 )
{
DeviceUISet * deviceUI = m_deviceUIs [ currentSourceTabIndex ] ;
2016-05-16 11:47:22 -04:00
deviceUI - > m_deviceAPI - > saveSourceSettings ( m_settings . getWorkingPreset ( ) ) ;
//deviceUI->m_pluginManager->saveSourceSettings(m_settings.getWorkingPreset());
2016-05-15 19:12:37 -04:00
deviceUI - > m_pluginManager - > selectSampleSourceByIndex ( deviceUI - > m_samplingDeviceControl - > getDeviceSelector ( ) - > currentIndex ( ) , deviceUI - > m_deviceAPI ) ;
2016-05-14 08:12:57 -04:00
m_settings . setSourceIndex ( deviceUI - > m_samplingDeviceControl - > getDeviceSelector ( ) - > currentIndex ( ) ) ;
2016-05-16 11:47:22 -04:00
//deviceUI->m_pluginManager->loadSourceSettings(m_settings.getWorkingPreset());
deviceUI - > m_deviceAPI - > loadSourceSettings ( m_settings . getWorkingPreset ( ) ) ;
2016-05-13 09:45:42 -04:00
}
2014-05-18 11:52:39 -04:00
}
void MainWindow : : on_action_About_triggered ( )
{
AboutDialog dlg ( this ) ;
dlg . exec ( ) ;
}
2015-10-07 03:27:44 -04:00
2016-05-13 05:42:03 -04:00
void MainWindow : : on_action_addDevice_triggered ( )
{
2016-05-14 22:38:37 -04:00
addDevice ( ) ;
2016-05-13 05:42:03 -04:00
}
void MainWindow : : on_action_removeDevice_triggered ( )
{
if ( m_deviceUIs . size ( ) > 1 )
{
removeLastDevice ( ) ;
}
}
2016-05-13 21:36:28 -04:00
void MainWindow : : tabInputViewIndexChanged ( )
{
int inputViewIndex = ui - > tabInputsView - > currentIndex ( ) ;
ui - > tabSpectra - > setCurrentIndex ( inputViewIndex ) ;
ui - > tabChannels - > setCurrentIndex ( inputViewIndex ) ;
ui - > tabInputsSelect - > setCurrentIndex ( inputViewIndex ) ;
ui - > tabSpectraGUI - > setCurrentIndex ( inputViewIndex ) ;
}
2016-05-12 13:06:38 -04:00
void MainWindow : : updateStatus ( )
{
2016-05-13 05:42:03 -04:00
m_dateTimeWidget - > setText ( QDateTime : : currentDateTime ( ) . toString ( " yyyy-MM-dd hh:mm:ss t " ) ) ;
2016-05-12 13:06:38 -04:00
}
2015-10-07 03:27:44 -04:00
MainWindow : : DeviceUISet : : DeviceUISet ( QTimer & timer )
{
m_spectrum = new GLSpectrum ;
m_spectrumVis = new SpectrumVis ( m_spectrum ) ;
m_spectrum - > connectTimer ( timer ) ;
m_spectrumGUI = new GLSpectrumGUI ;
m_spectrumGUI - > setBuddies ( m_spectrumVis - > getInputMessageQueue ( ) , m_spectrumVis , m_spectrum ) ;
m_channelWindow = new ChannelWindow ;
2016-05-14 08:12:57 -04:00
m_samplingDeviceControl = new SamplingDeviceControl ;
2016-05-11 14:02:45 -04:00
m_deviceEngine = 0 ;
2016-05-13 05:42:03 -04:00
m_pluginManager = 0 ;
2016-01-12 00:13:11 -05:00
// m_spectrum needs to have its font to be set since it cannot be inherited from the main window
QFont font ;
font . setFamily ( QStringLiteral ( " Sans Serif " ) ) ;
font . setPointSize ( 9 ) ;
m_spectrum - > setFont ( font ) ;
2015-10-07 03:27:44 -04:00
}
MainWindow : : DeviceUISet : : ~ DeviceUISet ( )
{
2016-05-14 08:12:57 -04:00
delete m_samplingDeviceControl ;
2015-10-07 03:27:44 -04:00
delete m_channelWindow ;
delete m_spectrumGUI ;
delete m_spectrumVis ;
delete m_spectrum ;
}