@@ -59,12 +59,16 @@ CIqTool::CIqTool(QWidget *parent) :
59
59
60
60
timer = new QTimer (this );
61
61
connect (timer, SIGNAL (timeout ()), this , SLOT (timeoutFunction ()));
62
+
63
+ recdirWatcher = new QFileSystemWatcher (this );
64
+ connect (recdirWatcher, SIGNAL (directoryChanged (const QString)), this , SLOT (directoryChanged (const QString)));
62
65
}
63
66
64
67
CIqTool::~CIqTool ()
65
68
{
66
69
timer->stop ();
67
70
delete timer;
71
+ delete recdirWatcher;
68
72
delete ui;
69
73
delete recdir;
70
74
delete error_palette;
@@ -104,8 +108,6 @@ void CIqTool::on_listWidget_currentTextChanged(const QString ¤tText)
104
108
/* ! \brief Start/stop playback */
105
109
void CIqTool::on_playButton_clicked (bool checked)
106
110
{
107
- is_playing = checked;
108
-
109
111
if (checked)
110
112
{
111
113
if (current_file.isEmpty ())
@@ -130,11 +132,15 @@ void CIqTool::on_playButton_clicked(bool checked)
130
132
ui->recButton ->setEnabled (false );
131
133
emit startPlayback (recdir->absoluteFilePath (current_file),
132
134
(float )sample_rate, center_freq);
135
+ is_playing = true ;
136
+ timer->start (1000 );
133
137
}
134
138
}
135
139
else
136
140
{
137
141
emit stopPlayback ();
142
+ is_playing = false ;
143
+ timer->stop ();
138
144
ui->listWidget ->setEnabled (true );
139
145
ui->recButton ->setEnabled (true );
140
146
ui->slider ->setValue (0 );
@@ -153,6 +159,7 @@ void CIqTool::cancelPlayback()
153
159
ui->listWidget ->setEnabled (true );
154
160
ui->recButton ->setEnabled (true );
155
161
is_playing = false ;
162
+ timer->stop ();
156
163
}
157
164
158
165
@@ -175,12 +182,14 @@ void CIqTool::on_recButton_clicked(bool checked)
175
182
{
176
183
ui->playButton ->setEnabled (false );
177
184
emit startRecording (recdir->path ());
185
+ timer->start (1000 );
178
186
179
187
refreshDir ();
180
188
ui->listWidget ->setCurrentRow (ui->listWidget ->count ()-1 );
181
189
}
182
190
else
183
191
{
192
+ timer->stop ();
184
193
ui->playButton ->setEnabled (true );
185
194
emit stopRecording ();
186
195
}
@@ -199,6 +208,7 @@ void CIqTool::cancelRecording()
199
208
ui->recButton ->setChecked (false );
200
209
ui->playButton ->setEnabled (true );
201
210
is_recording = false ;
211
+ timer->stop ();
202
212
}
203
213
204
214
/* ! \brief Catch window close events.
@@ -209,6 +219,7 @@ void CIqTool::cancelRecording()
209
219
*/
210
220
void CIqTool::closeEvent (QCloseEvent *event)
211
221
{
222
+ recdirWatcher->removePath (recdir->path ());
212
223
timer->stop ();
213
224
hide ();
214
225
event->ignore ();
@@ -220,7 +231,10 @@ void CIqTool::showEvent(QShowEvent * event)
220
231
Q_UNUSED (event);
221
232
refreshDir ();
222
233
refreshTimeWidgets ();
223
- timer->start (1000 );
234
+ if (is_playing || is_recording) {
235
+ timer->start (1000 );
236
+ }
237
+ recdirWatcher->addPath (recdir->path ());
224
238
}
225
239
226
240
@@ -281,8 +295,6 @@ void CIqTool::on_recDirButton_clicked()
281
295
282
296
void CIqTool::timeoutFunction (void )
283
297
{
284
- refreshDir ();
285
-
286
298
if (is_playing)
287
299
{
288
300
// advance slider with one second
@@ -295,8 +307,14 @@ void CIqTool::timeoutFunction(void)
295
307
refreshTimeWidgets ();
296
308
}
297
309
}
298
- if (is_recording)
310
+ if (is_recording) {
299
311
refreshTimeWidgets ();
312
+
313
+ // update rec_len; if the file being recorded is the one selected
314
+ // in the list, the length will update periodically
315
+ QFileInfo info (*recdir, current_file);
316
+ rec_len = (int )(info.size () / (sample_rate * bytes_per_sample));
317
+ }
300
318
}
301
319
302
320
/* ! \brief Refresh list of files in current working directory. */
@@ -315,14 +333,6 @@ void CIqTool::refreshDir()
315
333
ui->listWidget ->setCurrentRow (selection);
316
334
sc->setSliderPosition (lastScroll);
317
335
ui->listWidget ->blockSignals (false );
318
-
319
- if (is_recording)
320
- {
321
- // update rec_len; if the file being recorded is the one selected
322
- // in the list, the length will update periodically
323
- QFileInfo info (*recdir, current_file);
324
- rec_len = (int )(info.size () / (sample_rate * bytes_per_sample));
325
- }
326
336
}
327
337
328
338
/* ! \brief Refresh time labels and slider position
0 commit comments