-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
878 lines (653 loc) · 26.3 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFile>
#include <QProcess>
#include <QMessageBox>
#include <QDebug>
#include <QVector>
#include <QTextStream>
#include <QStringList>
#include <QThread>
#include <QDir>
#include <QInputDialog>
#include <QListWidgetItem>
#include <QCollator>
//#include <iostream>
//#include <algorithm>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//start mediaclient in case it did not...
QProcess::execute("/opt/bin/mediaclient --start");
QThread::msleep(3000);
ui->setupUi(this);
// start DAB default ##################################################################################################################
tgl_state = "DAB";
//qDebug() << "state: " << tgl_state;
//qDebug() << "button: " << ui->tgl_dab_fm->text();
QProcess::execute("/opt/bin/mediaclient -d /dev/dab0");
QProcess::execute("/opt/bin/mediaclient -m DAB -g off");
ui->ls_dab->setVisible(true);
ui->ls_fm->setVisible(false);
ui->btn_rename->setVisible(false);
ui->ln_man_tune->setVisible(false);
ui->label->setVisible(false);
ui->btn_add->setVisible(false);
ui->btn_man_tune->setVisible(false);
//disable tunebutton on start
ui->btn_tune->setDisabled(true);
MainWindow::fill_list();
MainWindow::dab_list();
//MainWindow::fill_list();
MainWindow::fm_list();
}
MainWindow::~MainWindow()
{
//kill mediaclient on close, else sound goes on...
QProcess::execute("/opt/bin/mediaclient -m DAB -g on");
QProcess::execute("/opt/bin/mediaclient -m RADIO -g on");
QProcess::execute("/opt/bin/mediaclient --shutdown");
delete ui;
}
void MainWindow::on_tgl_dab_fm_clicked()
{
if(ui->tgl_dab_fm->text() == "FM"){
ui->tgl_dab_fm->setText("DAB");
tgl_state = "FM";
ui->ls_dab->setVisible(false);
ui->ls_fm->setVisible(true);
ui->btn_rename->setVisible(true);
ui->ln_man_tune->setVisible(true);
ui->label->setVisible(true);
ui->btn_add->setVisible(true);
ui->btn_man_tune->setVisible(true);
} else {
ui->tgl_dab_fm->setText("FM");
tgl_state = "DAB";
ui->ls_dab->setVisible(true);
ui->ls_fm->setVisible(false);
ui->btn_rename->setVisible(false);
ui->ln_man_tune->setVisible(false);
ui->label->setVisible(false);
ui->btn_add->setVisible(false);
ui->btn_man_tune->setVisible(false);
}
//enable/disable tune button depending on station selected or not
int init_fm_list = ui->ls_fm->currentRow();
int init_dab_list = ui->ls_dab->currentRow();
if(init_fm_list == -1 && tgl_state == "FM"){
ui->btn_tune->setDisabled(true);
}
if(init_fm_list != -1 && tgl_state == "FM"){
ui->btn_tune->setDisabled(false);
}
if(init_dab_list == -1 && tgl_state == "DAB"){
ui->btn_tune->setDisabled(true);
}
if(init_dab_list != -1 && tgl_state == "DAB"){
ui->btn_tune->setDisabled(false);
}
}
void MainWindow::on_btn_scan_clicked()
{
//DAB scan
if (tgl_state == "DAB"){
//clear list
ui->ls_dab->clear();
//clear vectors
dab.clear();
//starte prozess scan dab frequenzen
QProcess process;
process.close();
process.start("/opt/bin/mediaclient --scandabfrequencies /dev/dab0");
process.waitForFinished();
//process.close();
//QByteArray scanned_dab(process.readAllStandardOutput());
QString scanned_dab(process.readAllStandardOutput());
process.close();
// output(process.readAllStandardOutput());
//QByteArray lock;
QList<QString> locked_dab; //list with linenumbers found above [LOCKED]
QList<QString> locked_freq_dab; //list with frequencies which were found above [LOCKED]
QList<QString> freq_avail; //list with cleaned frequencies
int k = 0;
//
QTextStream stream_dab(&scanned_dab);
QTextStream console_count_lines_freq_dab(&scanned_dab);
QString line_dab;
//QString line = stream_dab.readLine();
QString line_lock = stream_dab.readLine();
//int line_count = 0;
int line_count_dab = 0;
/*
while (!stream_dab.atEnd()) {
line_dab = stream_dab.readLine();
//ui->listScanOrg->addItem(line);
line_count++;
qDebug() << "line_count" << line_count;
}
*/
//zähle lines der gefundenen frequenzen
//austausch
// QString linea[100];
// QTextStream in(&scanned_dab);
// while (!in.atEnd()){
// linea[line_count] = in.readLine();
// line_count++;
// };
while (!console_count_lines_freq_dab.atEnd()) {
QString line_dab = console_count_lines_freq_dab.readLine();
line_count_dab++;
}
//QString lineb = QString::number(line_count);
//finde lines die LOCKED sind
for (int i = 0; i < line_count_dab; i++){
// austausch
line_lock = stream_dab.readLine();
locked_freq_dab.append(line_lock);
if (line_lock == "[LOCKED]"){
k = i-1;
locked_dab.append(QString::number(k));
//qDebug() <<"position locked" << locked_dab;
//lock.append(k);
//ui->listScan->addItem(QString::number(i));
//ui->listScan->addItem(lock);
// ui->lineEdit_2->setText(lock.indexOf(i));
}
//line_lock = stream_dab.readLine();
}
qDebug() <<"position locked" << locked_dab;
for (int i = 0; i < locked_dab.size(); i++){
//int tmp = (locked_freq_dab.at(i).toInt());
QString holder = locked_dab.at(i);
//int hold = holder.toInt;
QString fr = locked_freq_dab.at(holder.toInt());
QStringRef fr_part = fr.leftRef(4);
if(fr_part.contains(" ")){
fr = fr.remove(0, 3);
} else {
//untested, no freq here with more then 3 characters in front
fr = fr.remove(0, 4);
}
freq_avail.append(fr);
//ui->listScan->addItem(fr);
}
qDebug() << "freq avail:" << freq_avail;
//tune zu transponder
//open file and append found transponders
QFile file_dab(path_dab);
if(!file_dab.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
//ui->warn_no_dab_list->setVisible(true);
return;
}
//clear file before writing
//file_dab.resize(0);
QTextStream out(&file_dab);
//QString transponder = trans.at(0);
QStringList unsort_scan_dab;
for(int i = 0; i < freq_avail.size(); i++){
// QProcess::execute("/opt/bin/mediaclient -m DAB -f " + freq_avail.at(i));
// QThread::msleep(500);
//process tune to DAB frequency
QProcess process_dab_trans_1;
process_dab_trans_1.close();
process_dab_trans_1.start("/opt/bin/mediaclient -m DAB -f " + freq_avail.at(i));
process_dab_trans_1.waitForFinished();
QThread::msleep(3000); //important, else old frequency is scanned again
process_dab_trans_1.close();
//process scan transponders at frequency
QProcess process_dab_trans_2;
process_dab_trans_2.close();
process_dab_trans_2.start("/opt/bin/mediaclient -m DAB -f " + freq_avail.at(i) + " --scandabservices /dev/dab0");
process_dab_trans_2.waitForFinished();
QString output_dab_trans(process_dab_trans_2.readAllStandardOutput());
process_dab_trans_2.close();
QTextStream stream_dab_trans(&output_dab_trans);
//QStringList unsort_scan_dab;
//QString line_dab_trans;
while (!stream_dab_trans.atEnd()) {
QString line_dab_trans = stream_dab_trans.readLine();
if(!line_dab_trans.contains("Service Name")){
//"0 x char char char char"
QRegularExpression sid_re("[0][x][a-f0-9][a-f0-9][a-f0-9][a-f0-9]");
QRegularExpressionMatch match = sid_re.match(line_dab_trans);
QString matched;
if (match.hasMatch()) {
matched = match.captured(0);
}
QString service_name = line_dab_trans.left(line_dab_trans.indexOf(QLatin1String("0x")));
//QStringList unsort_scan_dab;
/*
QStringList one_line = line_dab_trans.split('\t');
QString one = one_line;
ui->listScan->addItem(one_line);
*/
//QString line = in.readLine();
//if(!line.contains(delete_marked, Qt::CaseSensitive)){
//QString outline = line;
//if(service_name != "Service Name"){
////out << freq_avail.at(i) << "," << service_name << "," << matched << "\n";
QString tmp = service_name + "," + freq_avail.at(i) + "," + matched;
unsort_scan_dab.append(tmp);
//qDebug() << freq_avail.at(i) << service_name << matched;
//}
//clear line_dab_trans at the end, else only transponders from frequency #0 aer listed
line_dab_trans.clear();
}
}
}
QStringList list {MainWindow::sort_list(unsort_scan_dab)};
foreach(QString dab_line_sort, list){
out << dab_line_sort << "\n";
}
file_dab.flush();
file_dab.close();
//nochmal prüfen ob notwendig...
if(!file_dab.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"no stationfile found","Please hit scan first!");
//ui->warn_no_dab_list->setVisible(true);
return;
}
QTextStream in_file(&file_dab);
QString text;
while (!in_file.atEnd()) {
text = in_file.readLine();
//qDebug() << text;
QStringList split_text = text.split(",");
//qDebug() << split_text;
QVector<QString> dab_row;
dab_row.push_back(split_text.at(0));
dab_row.push_back(split_text.at(1));
dab_row.push_back(split_text.at(2));
qDebug() << "dab row scan" << dab_row;
dab.push_back(dab_row);
qDebug() << "dab scan" << dab;
}
file_dab.close();
MainWindow::dab_list();
}
//FM scan #############################################################################################################################
if (tgl_state == "FM"){
//clear list
ui->ls_fm->clear();
//clear vectors
fm.clear();
qDebug() << "content vector fm:" << fm;
//start scanning fm ###############################################################################################################
QProcess process_fm;
process_fm.close();
process_fm.start("/opt/bin/mediaclient --scanfmfrequencies /dev/radio0");
process_fm.waitForFinished();
//process.close();
//QByteArray scanned_dab(process.readAllStandardOutput());
QString scanned_fm(process_fm.readAllStandardOutput());
process_fm.close();
QTextStream console_count_lines_fm(&scanned_fm);
QTextStream console_find_freq(&scanned_fm);
//QString line_fm;
QString line_lock = console_count_lines_fm.readLine();
int line_count_fm = 0;
while (!console_count_lines_fm.atEnd()) {
QString line_fm = console_count_lines_fm.readLine();
line_count_fm++;
}
QFile file_fm(path_fm);
if(!file_fm.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
//ui->warn_no_dab_list->setVisible(true);
return;
}
QTextStream out(&file_fm);
QStringList unsort_scan_fm;
for(int i = 0; i < line_count_fm; i++){
QString tmp = console_find_freq.readLine();
//if(tmp != "" && tmp != "Scan completed" && tmp != "SCAN SETUP"){
//QString match = "LOCKED";
if(tmp.contains("LOCKED")){
tmp.replace(" [LOCKED]", "000");
float mhz = tmp.toFloat() / 1000000;
//QString mhz_str = QString::number(mhz).right();
tmp = "Station " + QString::number(i-1) + " " + QString::number(mhz) + " MHz," + tmp;
//out << tmp << "\n";
unsort_scan_fm.append(tmp);
//qDebug() << "unsort list:" << unsort_scan_fm;
}
}
QStringList list {MainWindow::sort_list(unsort_scan_fm)};
foreach(QString fm_line_sort, list){
out << fm_line_sort << "\n";
}
file_fm.flush();
file_fm.close();
//read frequencies QVector ####################################################################################################
//QFile file_fm(path_fm);
if(!file_fm.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
//ui->warn_no_dab_list->setVisible(true);
return;
}
QTextStream in_file_fm(&file_fm);
while (!in_file_fm.atEnd()) {
QString text_fm = in_file_fm.readLine();
QStringList split_text_fm = text_fm.split(",");
//qDebug() << split_text_fm;
QVector<QString> fm_row;
fm_row.push_back(split_text_fm.at(0));
fm_row.push_back(split_text_fm.at(1));
fm.push_back(fm_row);
//qDebug() << "fm scan" << fm;
}
file_fm.close();
MainWindow::fm_list();
}
}
//#########################################################################################################################################
//Qt Widgets and buttons
void MainWindow::on_btn_tune_clicked()
{
MainWindow::tune();
}
void MainWindow::on_btn_kill_clicked()
{
QProcess::execute("/opt/bin/mediaclient --shutdown");
}
void MainWindow::on_btn_restart_clicked()
{
QProcess::execute("/opt/bin/mediaclient --start");
}
void MainWindow::on_ls_fm_itemSelectionChanged()
{
ui->btn_tune->setEnabled(true);
}
void MainWindow::on_ls_dab_itemSelectionChanged()
{
ui->btn_tune->setEnabled(true);
}
void MainWindow::on_btn_delete_clicked()
{
MainWindow::delete_line();
}
void MainWindow::on_btn_rename_clicked()
{
MainWindow::rename();
}
void MainWindow::on_btn_add_clicked()
{
MainWindow::add_station();
}
void MainWindow::on_btn_man_tune_clicked()
{
}
//#########################################################################################################################################
//functions
//void MainWindow::testfunction(){
// QMessageBox::warning(this,"no stationlist for DAB found","no stationlist for DAB found\nPlease hit scan in mode DAB first!");
//}
void MainWindow::fm_list(){
for(int i = 0; i < fm.size(); i++){
ui->ls_fm->addItem(fm[i][0]);
//ui->ls_fm->sortItems(Qt::AscendingOrder);
}
}
void MainWindow::dab_list(){
for(int i = 0; i < dab.size(); i++){
ui->ls_dab->addItem(dab[i][0]);
//ui->ls_dab->sortItems(Qt::AscendingOrder);
}
}
void MainWindow::tune(){
QString radio_dab_type;
//DAB #################################################################################################################################
if (tgl_state == "DAB"){
radio_dab_type = "DAB";
int ind_marked = ui->ls_dab->currentRow();
// if(ind_marked > -1){
freq = dab[ind_marked][1];
serv_id = dab[ind_marked][2];
// }
}
//FM ##################################################################################################################################
if (tgl_state == "FM"){
radio_dab_type = "RADIO";
int ind_marked = ui->ls_fm->currentRow();
//if(ind_marked > -1){
freq = fm[ind_marked][1];
//}
}
//start mediaclient in case it did not...
QProcess::execute("/opt/bin/mediaclient --start");
QProcess::execute("/opt/bin/mediaclient -m" + radio_dab_type + " -f" + freq);
if(tgl_state == "DAB"){
QProcess::execute("/opt/bin/mediaclient -m " + radio_dab_type + " -f " + freq + " --sid " + serv_id);
}
QProcess::execute("/opt/bin/mediaclient -m " + radio_dab_type + " -g off");
}
void MainWindow::delete_line(){
//DAB #################################################################################################################################
if (tgl_state == "DAB"){
QString delete_marked = ui->ls_dab->currentItem()->text();
QFile out_tmp("../tmp.txt");
QFile file_dab(path_dab);
if(!file_dab.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
if(!out_tmp.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in_file_dab(&file_dab);
QTextStream out(&out_tmp);
while(!in_file_dab.atEnd()){
QString line = in_file_dab.readLine();
if(!line.contains(delete_marked, Qt::CaseSensitive)){
QString outline = line;
out << outline << "\n";
}
}
file_dab.close();
out_tmp.flush();
out_tmp.close();
file_dab.remove();
out_tmp.rename(path_dab);
ui->ls_dab->clear();
//mute DAB stream, else deleted entry is still active
//todo, mute only if station to delete is played station
QProcess::execute("/opt/bin/mediaclient -m DAB -g on");
MainWindow::fill_list();
MainWindow::dab_list();
}
//FM ##################################################################################################################################
if (tgl_state == "FM"){
QString delete_marked = ui->ls_fm->currentItem()->text();
QFile out_tmp("../tmp.txt");
QFile file_fm(path_fm);
if(!file_fm.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
if(!out_tmp.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in_file_fm(&file_fm);
QTextStream out(&out_tmp);
while(!in_file_fm.atEnd()){
QString line = in_file_fm.readLine();
if(!line.contains(delete_marked, Qt::CaseSensitive)){
QString outline = line;
out << outline << "\n";
}
}
file_fm.close();
out_tmp.flush();
out_tmp.close();
file_fm.remove();
out_tmp.rename(path_fm);
ui->ls_fm->clear();
//mute RADIO stream, else deleted entry is still active
//todo, mute only if station to delete is played station
QProcess::execute("/opt/bin/mediaclient -m RADIO -g on");
MainWindow::fill_list();
MainWindow::fm_list();
}
}
void MainWindow::fill_list(){
//DAB #################################################################################################################################
QFile file_dab(path_dab);
if(!file_dab.open(QFile::ReadOnly | QFile::Text)){
QMessageBox::warning(this,"no stationlist for DAB found","no stationlist for DAB found\nPlease hit scan in mode DAB first!");
//ui->warn_no_dab_list->setVisible(true);
return;
}
dab.clear();
QTextStream in_file_dab(&file_dab);
QString text_dab;
while (!in_file_dab.atEnd()) {
text_dab = in_file_dab.readLine();
QStringList split_text_dab = text_dab.split(",");
QVector<QString> dab_row;
dab_row.push_back(split_text_dab.at(0));
dab_row.push_back(split_text_dab.at(1));
dab_row.push_back(split_text_dab.at(2));
dab.push_back(dab_row);
}
file_dab.close();
//FM ##################################################################################################################################
QFile file_fm(path_fm);
if(!file_fm.open(QFile::ReadOnly | QFile::Text)){
QMessageBox::warning(this,"no stationlist for FM found","no stationlist for FM found\nPlease hit scan in mode FM first!");
//ui->warn_no_dab_list->setVisible(true);
return;
}
fm.clear();
QTextStream in_file_fm(&file_fm);
QString text_fm;
while (!in_file_fm.atEnd()) {
text_fm = in_file_fm.readLine();
QStringList split_text_fm = text_fm.split(",");
QVector<QString> fm_row;
fm_row.push_back(split_text_fm.at(0));
fm_row.push_back(split_text_fm.at(1));
fm.push_back(fm_row);
}
file_fm.close();
}
void MainWindow::rename(){
//FM ##################################################################################################################################
if (tgl_state == "FM"){
ui->btn_rename->setVisible(true);
//int ind_marked = ui->ls_fm->currentRow();
//if(ind_marked > -1){
QString rename_marked = ui->ls_fm->currentItem()->text();
bool ok;
QString new_name = QInputDialog::getText(this, "enter new name", "new name: ",QLineEdit::Normal,rename_marked, &ok);
if(ok && !new_name.isEmpty()){
QFile out_tmp("../tmp.txt");
QFile file_fm(path_fm);
if(!file_fm.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
if(!out_tmp.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in_file_fm(&file_fm);
QTextStream out(&out_tmp);
QStringList unsort_rename_fm;
while(!in_file_fm.atEnd()){
QString line = in_file_fm.readLine();
QStringList line_split = line.split(",");
if(line_split.at(0) == rename_marked){
QString outline = new_name + "," + line_split.at(1);
unsort_rename_fm.append(outline);
} else {
QString outline = line;
unsort_rename_fm.append(outline);
}
}
QStringList list {MainWindow::sort_list(unsort_rename_fm)};
foreach(QString fm_line_sort, list){
out << fm_line_sort << "\n";
}
file_fm.close();
out_tmp.flush();
out_tmp.close();
file_fm.remove();
out_tmp.rename(path_fm);
ui->ls_fm->clear();
//mute RADIO stream, else deleted entry is still active
//QProcess::execute("/opt/bin/mediaclient -m RADIO -g on");
MainWindow::fill_list();
MainWindow::fm_list();
}
}
}
void MainWindow::add_station(){
//FM ##################################################################################################################################
if (tgl_state == "FM"){
ui->btn_rename->setVisible(true);
QString add_station = ui->ln_man_tune->text();
float add_station_float = add_station.toFloat();
int multi = add_station_float * 1000000;
QString station_conv_string = (QString::number(multi));
if(!add_station.isEmpty()){
QFile out_tmp("../tmp.txt");
QFile file_fm(path_fm);
if(!file_fm.open(QFile::ReadOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
if(!out_tmp.open(QFile::WriteOnly | QFile::Text)){
//QMessageBox::warning(this,"..","keine datei gefunden");
return;
}
QTextStream in_file_fm(&file_fm);
file_fm.resize(0);
QTextStream out(&out_tmp);
QStringList unsort_add_fm;
QCollator coll;
coll.setNumericMode(true);
while(!in_file_fm.atEnd()){
QString line = in_file_fm.readLine();
//if(!line.contains(delete_marked, Qt::CaseSensitive)){
//QStringList line_split = line.split(",");
QString outline = line;
//out << outline << "\n";
unsort_add_fm.append(outline);
}
if(add_station.contains(",")){
add_station = add_station.replace(",", ".");
}
if(!add_station.contains(".")){
add_station = add_station.append(".0");
}
//add new station at end of file
QString outline = "man station@ " + add_station + "MHz," + station_conv_string;
//out << outline << "\n";
unsort_add_fm.append(outline);
QStringList list {MainWindow::sort_list(unsort_add_fm)};
foreach(QString fm_line_sort, list){
out << fm_line_sort << "\n";
}
file_fm.close();
out_tmp.flush();
out_tmp.close();
file_fm.remove();
out_tmp.rename(path_fm);
ui->ls_fm->clear();
MainWindow::fill_list();
MainWindow::fm_list();
}
}
}
QStringList MainWindow::sort_list(QStringList list){
QCollator coll;
coll.setNumericMode(true);
std::sort(list.begin(), list.end(), [&](const QString& s1, const QString& s2){ return coll.compare(s1, s2) < 0; });
return list;
}