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>
# 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/preferencesdialog.h"
# include "gui/aboutdialog.h"
# include "gui/rollupwidget.h"
# include "dsp/dspengine.h"
# include "dsp/spectrumvis.h"
2015-07-28 17:54:17 -04:00
# include "dsp/filesink.h"
2014-05-18 11:52:39 -04:00
# include "dsp/dspcommands.h"
# include "plugin/plugingui.h"
# include "plugin/pluginapi.h"
# include "plugin/plugingui.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 ( ) ) ,
2014-05-18 11:52:39 -04:00
m_lastEngineState ( ( DSPEngine : : State ) - 1 ) ,
m_startOsmoSDRUpdateAfterStop ( false ) ,
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-29 16:42:58 -04:00
m_pluginManager = new PluginManager ( this , m_dspEngine ) ;
2015-08-12 03:03:02 -04:00
connect ( m_dspEngine - > getOutputMessageQueue ( ) , SIGNAL ( messageEnqueued ( ) ) , this , SLOT ( handleDSPMessages ( ) ) , Qt : : QueuedConnection ) ;
2015-08-08 22:09:05 -04:00
m_dspEngine - > start ( ) ;
2014-05-18 11:52:39 -04:00
ui - > setupUi ( this ) ;
delete ui - > mainToolBar ;
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
removeDockWidget ( ui - > inputDock ) ;
removeDockWidget ( ui - > processingDock ) ;
removeDockWidget ( ui - > presetDock ) ;
removeDockWidget ( ui - > channelDock ) ;
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > inputDock ) ;
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > processingDock ) ;
addDockWidget ( Qt : : LeftDockWidgetArea , ui - > presetDock ) ;
addDockWidget ( Qt : : RightDockWidgetArea , ui - > channelDock ) ;
2015-08-18 03:24:56 -04:00
2014-05-18 11:52:39 -04:00
ui - > inputDock - > show ( ) ;
ui - > processingDock - > show ( ) ;
ui - > presetDock - > show ( ) ;
ui - > channelDock - > show ( ) ;
ui - > menu_Window - > addAction ( ui - > inputDock - > toggleViewAction ( ) ) ;
ui - > menu_Window - > addAction ( ui - > processingDock - > toggleViewAction ( ) ) ;
ui - > menu_Window - > addAction ( ui - > presetDock - > toggleViewAction ( ) ) ;
ui - > menu_Window - > addAction ( ui - > channelDock - > toggleViewAction ( ) ) ;
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
2014-05-18 11:52:39 -04:00
connect ( & m_statusTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( updateStatus ( ) ) ) ;
m_statusTimer . start ( 500 ) ;
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 ... " ;
2014-05-18 11:52:39 -04:00
m_pluginManager - > loadPlugins ( ) ;
2015-08-08 22:09:05 -04:00
2014-05-18 11:52:39 -04:00
bool sampleSourceSignalsBlocked = ui - > sampleSource - > blockSignals ( true ) ;
m_pluginManager - > fillSampleSourceSelector ( ui - > sampleSource ) ;
ui - > sampleSource - > blockSignals ( sampleSourceSignalsBlocked ) ;
m_spectrumVis = new SpectrumVis ( ui - > glSpectrum ) ;
2015-08-23 18:51:27 -04:00
ui - > glSpectrum - > connectTimer ( m_masterTimer ) ;
ui - > glSpectrumGUI - > setBuddies ( m_spectrumVis - > getInputMessageQueue ( ) , m_spectrumVis , ui - > glSpectrum ) ;
2014-05-18 11:52:39 -04:00
m_dspEngine - > addSink ( m_spectrumVis ) ;
2015-07-28 17:54:17 -04:00
m_fileSink = new FileSink ( ) ;
m_dspEngine - > addSink ( m_fileSink ) ;
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
2014-05-18 11:52:39 -04:00
int sampleSourceIndex = m_pluginManager - > selectSampleSource ( m_settings . getCurrent ( ) - > getSource ( ) ) ; // select SampleSource from settings
2015-08-18 03:24:56 -04:00
if ( sampleSourceIndex > = 0 )
{
2014-05-18 11:52:39 -04:00
bool sampleSourceSignalsBlocked = ui - > sampleSource - > blockSignals ( true ) ;
ui - > sampleSource - > setCurrentIndex ( sampleSourceIndex ) ;
ui - > sampleSource - > blockSignals ( sampleSourceSignalsBlocked ) ;
}
2015-08-23 18:51:27 -04:00
qDebug ( ) < < " MainWindow::MainWindow: load current preset settings... " ;
2015-08-18 03:24:56 -04:00
2015-08-23 18:51:27 -04:00
loadPresetSettings ( m_settings . getCurrent ( ) ) ;
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 " ;
2014-05-18 11:52:39 -04:00
}
MainWindow : : ~ MainWindow ( )
{
m_dspEngine - > stopAcquistion ( ) ;
saveSettings ( ) ;
m_pluginManager - > freeAll ( ) ;
2015-07-28 17:54:17 -04:00
m_dspEngine - > removeSink ( m_fileSink ) ;
2014-05-18 11:52:39 -04:00
m_dspEngine - > removeSink ( m_spectrumVis ) ;
2015-07-28 17:54:17 -04:00
delete m_fileSink ;
2014-05-18 11:52:39 -04:00
delete m_spectrumVis ;
delete m_pluginManager ;
m_dspEngine - > stop ( ) ;
delete ui ;
}
void MainWindow : : addChannelCreateAction ( QAction * action )
{
ui - > menu_Channels - > addAction ( action ) ;
}
void MainWindow : : addChannelRollup ( QWidget * widget )
{
( ( ChannelWindow * ) ui - > channelDock - > widget ( ) ) - > addRollupWidget ( widget ) ;
ui - > channelDock - > show ( ) ;
ui - > channelDock - > raise ( ) ;
}
void MainWindow : : addViewAction ( QAction * action )
{
ui - > menu_Window - > addAction ( action ) ;
}
void MainWindow : : addChannelMarker ( ChannelMarker * channelMarker )
{
ui - > glSpectrum - > addChannelMarker ( channelMarker ) ;
}
void MainWindow : : removeChannelMarker ( ChannelMarker * channelMarker )
{
ui - > glSpectrum - > removeChannelMarker ( channelMarker ) ;
}
void MainWindow : : setInputGUI ( QWidget * gui )
{
2015-05-09 04:51:02 -04:00
if ( m_inputGUI ! = 0 )
2014-05-18 11:52:39 -04:00
ui - > inputDock - > widget ( ) - > layout ( ) - > removeWidget ( m_inputGUI ) ;
2015-05-09 04:51:02 -04:00
if ( gui ! = 0 )
2014-05-18 11:52:39 -04:00
ui - > inputDock - > widget ( ) - > layout ( ) - > addWidget ( gui ) ;
m_inputGUI = gui ;
}
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-08-23 18:51:27 -04:00
void MainWindow : : loadPresetSettings ( const Preset * preset )
2014-05-18 11:52:39 -04:00
{
2015-08-23 18:51:27 -04:00
qDebug ( ) < < " MainWindow::loadPresetSettings: preset: " < < preset - > getSource ( ) . toStdString ( ) . c_str ( ) ;
2015-06-06 21:30:28 -04:00
2014-05-18 11:52:39 -04:00
ui - > glSpectrumGUI - > deserialize ( preset - > getSpectrumConfig ( ) ) ;
ui - > dcOffset - > setChecked ( preset - > getDCOffsetCorrection ( ) ) ;
ui - > iqImbalance - > setChecked ( preset - > getIQImbalanceCorrection ( ) ) ;
m_pluginManager - > loadSettings ( preset ) ;
// 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-08-23 18:51:27 -04:00
savePresetSettings ( m_settings . getCurrent ( ) ) ;
2014-05-18 11:52:39 -04:00
m_settings . save ( ) ;
2015-06-06 21:30:28 -04:00
2014-05-18 11:52:39 -04:00
}
2015-08-23 18:51:27 -04:00
void MainWindow : : savePresetSettings ( Preset * preset )
2014-05-18 11:52:39 -04:00
{
2015-08-23 18:51:27 -04:00
qDebug ( ) < < " MainWindow::savePresetSettings: preset: " < < preset - > getSource ( ) . toStdString ( ) . c_str ( ) ;
2015-06-06 21:30:28 -04:00
2014-05-18 11:52:39 -04:00
preset - > setSpectrumConfig ( ui - > glSpectrumGUI - > serialize ( ) ) ;
2015-06-06 21:30:28 -04:00
preset - > clearChannels ( ) ;
m_pluginManager - > saveSettings ( 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 ( )
{
m_sampleRateWidget = new QLabel ( tr ( " Rate: 0 kHz " ) , this ) ;
m_sampleRateWidget - > setToolTip ( tr ( " Sample Rate " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_sampleRateWidget ) ;
2015-07-28 17:54:17 -04:00
m_recording = new Indicator ( tr ( " Rec " ) , this ) ;
m_recording - > setToolTip ( tr ( " Recording " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_recording ) ;
2014-05-18 11:52:39 -04:00
m_engineIdle = new Indicator ( tr ( " Idle " ) , this ) ;
m_engineIdle - > setToolTip ( tr ( " DSP engine is idle " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_engineIdle ) ;
m_engineRunning = new Indicator ( tr ( " Run " ) , this ) ;
m_engineRunning - > setToolTip ( tr ( " DSP engine is running " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_engineRunning ) ;
m_engineError = new Indicator ( tr ( " Err " ) , this ) ;
m_engineError - > setToolTip ( tr ( " DSP engine failed " ) ) ;
statusBar ( ) - > addPermanentWidget ( m_engineError ) ;
}
void MainWindow : : closeEvent ( QCloseEvent * )
{
}
void MainWindow : : updateCenterFreqDisplay ( )
{
ui - > glSpectrum - > setCenterFrequency ( m_centerFrequency ) ;
}
void MainWindow : : updateSampleRate ( )
{
ui - > glSpectrum - > setSampleRate ( m_sampleRate ) ;
m_sampleRateWidget - > setText ( tr ( " Rate: %1 kHz " ) . arg ( ( float ) m_sampleRate / 1000 ) ) ;
}
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 ;
2014-05-18 11:52:39 -04:00
for ( int i = 0 ; i < ui - > presetTree - > topLevelItemCount ( ) ; i + + ) {
if ( ui - > presetTree - > topLevelItem ( i ) - > text ( 0 ) = = preset - > getGroup ( ) ) {
group = ui - > presetTree - > topLevelItem ( i ) ;
break ;
}
}
2015-05-09 04:51:02 -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 ) ;
}
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 ( )
{
updateCenterFreqDisplay ( ) ;
updateSampleRate ( ) ;
}
2015-08-08 22:09:05 -04:00
void MainWindow : : handleDSPMessages ( )
2014-05-18 11:52:39 -04:00
{
Message * message ;
2015-08-08 22:09:05 -04:00
2015-08-13 23:00:28 -04:00
while ( ( message = m_dspEngine - > getOutputMessageQueue ( ) - > pop ( ) ) ! = 0 )
2015-08-08 22:09:05 -04:00
{
2014-05-21 06:27:55 -04:00
qDebug ( " Message: %s " , message - > getIdentifier ( ) ) ;
2015-08-08 22:09:05 -04:00
std : : cerr < < " MainWindow::handleDSPMessages: " < < message - > getIdentifier ( ) < < std : : endl ;
2015-08-19 03:24:44 -04:00
if ( DSPSignalNotification : : match ( * message ) )
2015-08-08 22:09:05 -04:00
{
2015-08-19 03:24:44 -04:00
DSPSignalNotification * notif = ( DSPSignalNotification * ) message ;
m_sampleRate = notif - > getSampleRate ( ) ;
2015-08-19 16:12:52 -04:00
m_centerFrequency = notif - > getCenterFrequency ( ) ;
qDebug ( " SampleRate:%d, CenterFrequency:%llu " , notif - > getSampleRate ( ) , notif - > getCenterFrequency ( ) ) ;
2014-05-18 11:52:39 -04:00
updateCenterFreqDisplay ( ) ;
updateSampleRate ( ) ;
2015-08-19 03:24:44 -04:00
qDebug ( ) < < " MainWindow::handleDSPMessages: forward to file sink " ;
m_fileSink - > handleMessage ( * notif ) ;
2015-08-13 23:00:28 -04:00
2015-08-25 20:03:20 -04:00
delete message ;
}
2015-08-08 22:09:05 -04:00
}
}
void MainWindow : : handleMessages ( )
{
Message * message ;
2015-08-17 20:47:14 -04:00
while ( ( message = m_inputMessageQueue . pop ( ) ) ! = 0 )
2015-08-08 22:09:05 -04:00
{
qDebug ( " Message: %s " , message - > getIdentifier ( ) ) ;
std : : cerr < < " MainWindow::handleMessages: " < < message - > getIdentifier ( ) < < std : : endl ;
2015-08-17 02:29:34 -04:00
if ( ! m_pluginManager - > handleMessage ( * message ) )
2015-08-13 23:00:28 -04:00
{
delete message ;
2014-05-18 11:52:39 -04:00
}
}
}
void MainWindow : : updateStatus ( )
{
int state = m_dspEngine - > state ( ) ;
if ( m_lastEngineState ! = state ) {
switch ( state ) {
case DSPEngine : : StNotStarted :
m_engineIdle - > setColor ( Qt : : gray ) ;
m_engineRunning - > setColor ( Qt : : gray ) ;
m_engineError - > setColor ( Qt : : gray ) ;
statusBar ( ) - > clearMessage ( ) ;
break ;
case DSPEngine : : StIdle :
m_engineIdle - > setColor ( Qt : : cyan ) ;
m_engineRunning - > setColor ( Qt : : gray ) ;
m_engineError - > setColor ( Qt : : gray ) ;
statusBar ( ) - > clearMessage ( ) ;
break ;
case DSPEngine : : StRunning :
m_engineIdle - > setColor ( Qt : : gray ) ;
m_engineRunning - > setColor ( Qt : : green ) ;
m_engineError - > setColor ( Qt : : gray ) ;
2015-08-12 03:03:02 -04:00
statusBar ( ) - > showMessage ( tr ( " Sampling from %1 " ) . arg ( m_dspEngine - > sourceDeviceDescription ( ) ) ) ;
2014-05-18 11:52:39 -04:00
break ;
case DSPEngine : : StError :
m_engineIdle - > setColor ( Qt : : gray ) ;
m_engineRunning - > setColor ( Qt : : gray ) ;
m_engineError - > setColor ( Qt : : red ) ;
statusBar ( ) - > showMessage ( tr ( " Error: %1 " ) . arg ( m_dspEngine - > errorMessage ( ) ) ) ;
break ;
}
m_lastEngineState = state ;
}
}
void MainWindow : : on_action_Start_triggered ( )
{
2015-08-12 03:03:02 -04:00
if ( m_dspEngine - > initAcquisition ( ) )
{
m_dspEngine - > startAcquisition ( ) ;
}
2014-05-18 11:52:39 -04:00
}
void MainWindow : : on_action_Stop_triggered ( )
{
m_dspEngine - > stopAcquistion ( ) ;
}
2015-07-28 17:54:17 -04:00
void MainWindow : : on_action_Start_Recording_triggered ( )
{
m_recording - > setColor ( Qt : : red ) ;
m_fileSink - > startRecording ( ) ;
}
void MainWindow : : on_action_Stop_Recording_triggered ( )
{
m_recording - > setColor ( Qt : : gray ) ;
m_fileSink - > stopRecording ( ) ;
}
2014-05-18 11:52:39 -04:00
void MainWindow : : on_dcOffset_toggled ( bool checked )
{
m_settings . getCurrent ( ) - > setDCOffsetCorrection ( checked ) ;
m_dspEngine - > configureCorrections ( m_settings . getCurrent ( ) - > getDCOffsetCorrection ( ) , m_settings . getCurrent ( ) - > getIQImbalanceCorrection ( ) ) ;
}
void MainWindow : : on_iqImbalance_toggled ( bool checked )
{
m_settings . getCurrent ( ) - > setIQImbalanceCorrection ( checked ) ;
m_dspEngine - > configureCorrections ( m_settings . getCurrent ( ) - > getDCOffsetCorrection ( ) , m_settings . getCurrent ( ) - > getIQImbalanceCorrection ( ) ) ;
}
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 ( ) ;
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
}
}
}
}
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-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
2014-05-18 11:52:39 -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 )
{
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 ( ) ;
}
void MainWindow : : on_action_Loaded_Plugins_triggered ( )
{
PluginsDialog pluginsDialog ( m_pluginManager , this ) ;
pluginsDialog . exec ( ) ;
}
void MainWindow : : on_action_Preferences_triggered ( )
{
PreferencesDialog preferencesDialog ( m_audioDeviceInfo , this ) ;
preferencesDialog . exec ( ) ;
}
void MainWindow : : on_sampleSource_currentIndexChanged ( int index )
{
m_pluginManager - > selectSampleSource ( ui - > sampleSource - > currentIndex ( ) ) ;
}
void MainWindow : : on_action_About_triggered ( )
{
AboutDialog dlg ( this ) ;
dlg . exec ( ) ;
}