-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
763 lines (660 loc) · 21.8 KB
/
mainwindow.cpp
File metadata and controls
763 lines (660 loc) · 21.8 KB
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
#include "config.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "bonjourservicebrowser.h"
#include "bonjourserviceresolver.h"
#include "torrentstream.h"
#include "hlsvideo.h"
#include "airplay.h"
#include "moovfaststart.h"
#include <QMainWindow>
#include <QHostInfo>
#include <QTimer>
#include <QTcpSocket>
#include <QDropEvent>
#include <QMimeData>
#include <QFileDialog>
#include <QWidgetAction>
#include <QtCore/qmath.h>
#include <QDesktopServices>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
torrentStream(), httpVideo(), hlsVideo(), airplay(), bonjourResolver(), header(), devicesActGrp()
{
ui->setupUi(this);
setAcceptDrops(true);
// init
loadingSubtitles = false;
srtFile = "";
// setup ui elements
spinner.setFileName(":/MainWindow/images/spinner.gif");
spinner.start();
menuDevices = new QMenu(ui->toolButton);
ui->toolButton->setPopupMode(QToolButton::InstantPopup);
ui->toolButton->setMenu(menuDevices);
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(10000);
ui->progressBar->setValue(0);
setState(STATE_INIT);
stateLoop();
// load prefs
prefs = new Preferences(this);
connect(prefs, SIGNAL(recentFilesUpdated()), this, SLOT(updateRecentFiles()));
prefs->recentlyOpenedFiles(); // trigger signal
prefDialog = new PreferencesDialog(prefs,this);
connect(prefDialog, SIGNAL(importLicense(QString)), this, SLOT(loadLicense(QString)));
if (prefs->ch())
setWindowTitle("StreamPlay");
// check for updates
#ifdef Q_OS_MAC
#ifdef QT_NO_DEBUG
updater = new SparkleAutoUpdater(CONFIG_UPDATE_URL);
updater->checkForUpdates();
#endif
#endif
// clear stream dir
QDir(prefs->streamPath()).removeRecursively();
// ensure directories exist
QDir().mkpath(prefs->savePath());
QDir().mkpath(prefs->streamPath());
qDebug() << "save path" << prefs->savePath();
qDebug() << "stream path" << prefs->streamPath();
// setup device browsers
atvBrowser = new BonjourServiceBrowser(this);
connect(atvBrowser, SIGNAL(currentBonjourBrowseRecordsChanged(const QList<BonjourBrowseRecord> &)),
this, SLOT(updateDevices(const QList<BonjourBrowseRecord> &)));
// start torrent client
try {
torrentStream = new TorrentStream(prefs->savePath(), prefs->bittorrentPort(), this);
}
catch (int e) {
//mb("error starting torrent client");
return;
}
// start app state machine loop
connect(&timerStateLoop, SIGNAL(timeout()), this, SLOT(stateLoop()));
timerStateLoop.start(1000);
}
void MainWindow::stateLoop()
{
TorrentStream::Stats s;
QString subText;
int prg;
switch (appState)
{
case STATE_INIT:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Starting services");
ui->lblSubStatus->setText("");
if (timerStateLoop.isActive())
setState(STATE_FINDING_DEVICES);
break;
case STATE_FINDING_DEVICES:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Searching for devices");
//ui->lblSubStatus->setText("Please wait...");
if (menuDevices->actions().length() > 0)
setState(STATE_WAITING_TORRENT);
break;
case STATE_WAITING_TORRENT:
ui->lblAction->setPixmap(QPixmap(":/MainWindow/images/drop.png"));
ui->lblStatus->setText("Drop Media Here");
break;
case STATE_ADDING_TORRENT:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Adding Torrent");
ui->lblSubStatus->setText(fileInput.path);
if (torrentStream->getStatus() == TorrentStream::STATE_RETRIEVING_METADATA)
setState(STATE_GETTING_TORRENT_INFO);
break;
case STATE_GETTING_TORRENT_INFO:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Getting Torrent Info");
ui->lblSubStatus->setText(fileInput.path);
if (torrentStream->getStatus() == TorrentStream::STATE_BUFFERING)
setState(STATE_BUFFERING);
break;
case STATE_BUFFERING:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Buffering");
subText = s.name;
if (fileInput.type == TYPE_VIDEO)
{
subText = QFileInfo(fileInput.path).fileName();
}
else
{
s = torrentStream->getStats();
subText = s.name + "\n";
subText.append(QString::number(s.dSpeed / 1000, 'g', 4) + "kbps");
}
ui->lblSubStatus->setText(subText);
ui->progressBar->setValue(2500);
if (checkHeader() && !loadingSubtitles)
setState(STATE_PREPARING_STREAM);
break;
case STATE_PREPARING_STREAM:
ui->lblAction->setMovie(&spinner);
ui->lblStatus->setText("Buffering");
if (fileInput.type != TYPE_VIDEO)
{
s = torrentStream->getStats();
subText = s.name + "\n";
subText.append(QString::number(s.dSpeed / 1000, 'g', 4) + "kbps");
ui->lblSubStatus->setText(subText);
}
flushBuffer();
prg = 2500 + ((qMax(hlsVideo->getCurrentSegment(), 0)+1)*2500);
ui->progressBar->setValue(prg);
if (hlsVideo && hlsVideo->isReadyForStreaming())
setState(STATE_CONNECTING_DEVICE);
break;
case STATE_CONNECTING_DEVICE:
if (!ui->lblAction->movie())
{
ui->lblAction->clear();
ui->lblAction->setMovie(&spinner);
}
ui->lblStatus->setText("Connecting Device");
if (fileInput.type != TYPE_VIDEO)
{
s = torrentStream->getStats();
subText = s.name;
ui->lblSubStatus->setText(subText);
}
flushBuffer();
ui->progressBar->setValue(0);
if (airplay && airplay->getStatus() == AirPlay::CONNECTED)
setState(STATE_STREAMING);
break;
case STATE_STREAMING:
ui->toolButton->setIcon(QIcon(":/MainWindow/images/airplay-on.png"));
ui->lblAction->setPixmap(QPixmap(":/MainWindow/images/stream.png"));
ui->lblStatus->setText("Streaming");
flushBuffer();
prg = qCeil((float)hlsVideo->getCurrentSegment() / (float)(hlsVideo->getTotalSegments() - 1) * 10000.0);
ui->progressBar->setValue(prg);
if (streamingElapsed.hasExpired(900000) && !prefs->ch())
{
airplay->pause();
prefDialog->disableTabs();
prefDialog->showLicenseTab();
if (!prefDialog->isVisible())
{
prefDialog->show();
prefDialog->activateWindow();
prefDialog->raise();
prefDialog->setFocus();
}
}
break;
}
}
void MainWindow::setState(state s)
{
switch (s)
{
case STATE_INIT:
break;
case STATE_FINDING_DEVICES:
// browse for devices
atvBrowser->browseForServiceType(QLatin1String("_airplay._tcp"));
//gcBrowser->browseForServiceType(QLatin1String("_googlecast._tcp"));
break;
case STATE_WAITING_TORRENT:
// do nothing
break;
case STATE_ADDING_TORRENT:
// add torrent
torrentStream->start(fileInput.path);
break;
case STATE_GETTING_TORRENT_INFO:
// do nothing
break;
case STATE_BUFFERING:
// reset states
ui->progressBar->setValue(0);
currentPiece = 0;
bufferFlushed = false;
header.clear();
checkHeaderState = CH_STATE_WAITING_START;
// record recent
if (fileInput.type != TYPE_VIDEO) {
fileInput.storagePath = torrentStream->getFilePath();
prefs->addRecentlyOpenedFile(torrentStream->getStats().name, fileInput.path);
}
else {
prefs->addRecentlyOpenedFile(QFileInfo(fileInput.storagePath).fileName(), fileInput.path);
}
break;
case STATE_PREPARING_STREAM:
// start hls transcoding server
hlsVideo = new HlsVideo(prefs->streamPath(), this);
hlsVideo->start(fileInput.storagePath, srtFile, 8888);
break;
case STATE_CONNECTING_DEVICE:
// resolve & connect to airplay
if (devicesActGrp->checkedAction() == 0) return;
if (airplay) {
delete airplay;
airplay = NULL;
}
ui->toolButton->setIcon(QIcon(":/MainWindow/images/airplay-off.png"));
// setup resolver
if (bonjourResolver) delete bonjourResolver;
bonjourResolver = new BonjourServiceResolver(0);
connect(bonjourResolver, SIGNAL(bonjourRecordResolved(const QHostInfo &, int, const QString)),
this, SLOT(deviceResolved(const QHostInfo &, int, const QString)));
bonjourResolver->resolveBonjourRecord(devicesActGrp->checkedAction()->data().value<BonjourBrowseRecord>());
break;
case STATE_STREAMING:
airplay->play("http://"+airplay->getLocalIp().toString()+":8888/a.m3u8");
srtFile = ""; // clear loaded subtitles
streamingElapsed.restart();
break;
}
appStatePrev = appState;
appState = s;
}
void MainWindow::updateRecentFiles()
{
ui->menuOpen_Recent->clear();
QVector<Preferences::RecentFile> *recentFiles = prefs->recentlyOpenedFiles();
for (QVector<Preferences::RecentFile>::iterator it = recentFiles->begin(); it != recentFiles->end(); ++it)
{
QAction *action = new QAction(this);
action->setText(it->name);
action->setData(it->path);
connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
ui->menuOpen_Recent->addAction(action);
}
ui->menuOpen_Recent->setEnabled( (recentFiles->length() > 0) );
// add clear recent button
ui->menuOpen_Recent->addSeparator();
QAction *clearAction = new QAction(this);
clearAction->setText("Clear Recent");
connect(clearAction, SIGNAL(triggered()), this, SLOT(menuClearRecentFiles()));
ui->menuOpen_Recent->addAction(clearAction);
}
void MainWindow::dragEnterEvent(QDragEnterEvent *e)
{
if (appState != STATE_INIT && appState != STATE_FINDING_DEVICES)
e->acceptProposedAction();
}
void MainWindow::dropEvent(QDropEvent *de)
{
QString dr = de->mimeData()->text().toLatin1().data();
if (dr.startsWith("file://")) dr.remove(0, 7);
fileInput.path = dr;
loadInput();
}
void MainWindow::menuAbout()
{
aboutDialog.show();
}
void MainWindow::menuHelp()
{
QDesktopServices::openUrl(QUrl(CONFIG_HELP_URL));
}
void MainWindow::menuReportAProblem()
{
QDesktopServices::openUrl(QUrl(CONFIG_PROBLEM_URL));
}
void MainWindow::menuLoadSubtitles()
{
loadingSubtitles = true;
srtFile = QFileDialog::getOpenFileName(this, "Load Subtitles", QDir::homePath(),
"Subtitles (*.srt)");
qDebug() << srtFile;
loadingSubtitles = false;
}
void MainWindow::menuOpenFile()
{
fileInput.path = QFileDialog::getOpenFileName(this, "Load Media", QDir::homePath(),
"Videos (*.mov *.avi *.mp4 *.mkv *.m4a *.ts *.wmv);;Torrents (*.torrent)");
if (fileInput.path.length() > 0)
loadInput();
}
void MainWindow::openRecentFile()
{
QAction *action = (QAction *)sender();
fileInput.path = action->data().toString();
loadInput();
}
void MainWindow::menuClearRecentFiles()
{
prefs->clearRecentlyOpenedFiles();
}
void MainWindow::menuCheckForUpdates()
{
#ifdef Q_OS_MAC
#ifdef QT_NO_DEBUG
updater->checkForUpdates();
#endif
#endif
}
void MainWindow::menuPreferences()
{
prefDialog->setModal(false);
prefDialog->show();
}
void MainWindow::loadInput()
{
prefs->ch2();
if (fileInput.path.length() == 0)
return;
// stop current stream
if (airplay) {
delete airplay;
airplay = NULL;
}
if (hlsVideo) {
delete hlsVideo;
hlsVideo = NULL;
}
ui->toolButton->setIcon(QIcon(":/MainWindow/images/airplay-off.png"));
ui->lblAction->clear();
ui->lblAction->setMovie(&spinner);
// set start state
if (fileInput.path.endsWith(".torrent"))
{
fileInput.type = TYPE_TORRENT;
setState(STATE_ADDING_TORRENT);
}
else if (fileInput.path.startsWith("http") || fileInput.path.startsWith("magnet"))
{
fileInput.type = TYPE_URL;
setState(STATE_ADDING_TORRENT);
}
else
{
fileInput.type = TYPE_VIDEO;
fileInput.storagePath = fileInput.path;
setState(STATE_BUFFERING);
}
}
void MainWindow::flushBuffer()
{
if (!hlsVideo || !hlsVideo->isReadyForInput() || bufferFlushed) return;
QFile f(fileInput.storagePath);
if(!f.open(QIODevice::ReadOnly)) return;
if (fileInput.type == TYPE_VIDEO)
{
quint64 startByte = 0;
if (header.length() > 0)
{
hlsVideo->encode(&header);
header.clear();
startByte = atoms.first().size;
}
f.seek(startByte);
QByteArray data = f.read(f.size() - startByte);
hlsVideo->encode(&data);
bufferFlushed = true;
}
else // torrent
{
if (header.length() > 0)
{
qDebug() << "writing header";
hlsVideo->encode(&header);
header.clear();
// write remainder of the first piece
f.seek(atoms.first().size);
int sz = torrentStream->getPieceLength() - atoms.first().size;
QByteArray data = f.read(sz);
hlsVideo->encode(&data);
currentPiece = 1;
}
int pieceOffset = torrentStream->getFileOffset() / torrentStream->getPieceLength();
int startPiece = currentPiece;
while (torrentStream->hasPiece(currentPiece + pieceOffset) && ((currentPiece - startPiece) < 10))
currentPiece++;
currentPiece--;
if (currentPiece <= startPiece)
{
currentPiece = startPiece;
return;
}
// seek to st
quint64 st = ((quint64)startPiece * torrentStream->getPieceLength());
if (st >= torrentStream->getFileSize())
{
qDebug() << "here 1" << startPiece << st << torrentStream->getPieceLength() << torrentStream->getFileSize();
bufferFlushed = true;
return;
}
f.seek(st);
// read sz bytes
quint64 sz = ((quint64)(currentPiece - startPiece) * torrentStream->getPieceLength());
if (st + sz > torrentStream->getFileSize())
{
qDebug() << "here 2" << st+sz << torrentStream->getFileSize();
sz = torrentStream->getFileSize() - st;
bufferFlushed = true;
}
QByteArray data = f.read(sz);
qDebug() << "writing" << (currentPiece - startPiece) << "pieces." << "current piece" << currentPiece;
//qDebug() << "start" << st << "size" << sz;
// encode
hlsVideo->encode(&data);
}
f.close();
}
bool MainWindow::checkHeader()
{
switch (checkHeaderState)
{
case CH_STATE_WAITING_START:
if (fileInput.type != TYPE_VIDEO
&& !torrentStream->hasBytes(0, 8))
return false;
atoms.clear();
checkHeaderState = CH_STATE_CHECK_TYP;
break;
case CH_STATE_CHECK_TYP:
{
QFile f(fileInput.storagePath);
if (!f.open(QIODevice::ReadOnly))
return false;
qDebug() << "checking header";
// read first 8 bytes from file
quint32 b1, b2;
QDataStream ds(&f);
ds >> b1;
ds >> b2;
// check for mp4
if (b2 == 0x66747970) // "ftyp"
{
chAtom.index = 0;
chAtom.pos = 0;
chAtom.name = b2;
if (b1 == 1)
ds >> chAtom.size;
else
chAtom.size = b1;
atoms.push_back(chAtom);
checkHeaderState = CH_STATE_GET_NEXT_ATOM;
qDebug() << "ftyp found";
}
else if (b1 == 0x52494646) // "RIFF"
{
checkHeaderState = CH_STATE_WAIT_RIFF;
qDebug() << "RIFF found";
}
else
{
checkHeaderState = CH_STATE_DONE;
qDebug() << "no special header found" << hex << b1 << b2;
}
f.close();
break;
}
case CH_STATE_WAIT_RIFF:
{
// wait for first 10kb
if (fileInput.type != TYPE_VIDEO
&& !torrentStream->hasBytes(0, 10000))
return false;
checkHeaderState = CH_STATE_DONE;
break;
}
case CH_STATE_GET_NEXT_ATOM:
{
if (fileInput.type != TYPE_VIDEO
&& !torrentStream->hasBytes(chAtom.pos + chAtom.size, 16))
{
torrentStream->prioritizeBytes(chAtom.pos + chAtom.size, 16);
return false;
}
QFile f(fileInput.storagePath);
if (!f.open(QIODevice::ReadOnly))
return false;
quint64 fileSize = 0;
if (fileInput.type != TYPE_VIDEO)
fileSize = torrentStream->getFileSize() - chAtom.pos;
else
fileSize = f.size();
// read from file
quint32 sz, typ;
QDataStream ds(&f);
ds.device()->seek(chAtom.pos + chAtom.size);
ds >> sz;
ds >> typ;
chAtom.index += 1;
chAtom.pos += chAtom.size;
chAtom.name = typ;
if (sz == 1) // 64-bit (wide) atom
ds >> chAtom.size;
else if (sz == 0) // atom spans to end of file
chAtom.size = fileSize - chAtom.pos;
else // size ok
chAtom.size = sz;
atoms.push_back(chAtom);
qDebug() << "found atom " << hex << chAtom.name << "at" << chAtom.pos << "sz" << chAtom.size;
if (chAtom.name == 0x6D6F6F76) // moov
{
if (chAtom.index == 1)
checkHeaderState = CH_STATE_DONE;
else
checkHeaderState = CH_STATE_GET_MOOV;
qDebug() << "moov atom found at index " << chAtom.index;
}
else
{
if (sz == 0 || chAtom.pos + chAtom.size >= fileSize)
{
qDebug() << "Could not find moov atom!";
checkHeaderState = CH_STATE_DONE;
}
}
f.close();
break;
}
case CH_STATE_GET_MOOV:
{
if (fileInput.type != TYPE_VIDEO
&& !torrentStream->hasBytes(chAtom.pos, chAtom.size))
{
qDebug() << "prioritizing bytes " << hex << chAtom.pos << chAtom.size;
torrentStream->prioritizeBytes(chAtom.pos, chAtom.size);
return false;
}
QFile f(fileInput.storagePath);
if (!f.open(QIODevice::ReadOnly))
return false;
qDebug() << "retrieved moov atom";
// read ftyp
f.seek(atoms.first().pos);
QByteArray ftyp = f.read(atoms.first().size);
// read moov
f.seek(chAtom.pos);
QByteArray moov = f.read(chAtom.size);
f.close();
moovFastStart fs(&moov, this);
fs.offsetStcos();
// build header
header.clear();
header.append(ftyp);
header.append(moov);
checkHeaderState = CH_STATE_DONE;
break;
}
case CH_STATE_DONE:
return true;
}
return false;
}
void MainWindow::deviceResolved(const QHostInfo &hostInfo, int port, QString txtRecord)
{
const QList<QHostAddress> &addresses = hostInfo.addresses();
if (addresses.isEmpty())
return;
// send wake-on-lan
int s = txtRecord.indexOf("deviceid=");
if (s > -1)
{
QString mac = txtRecord.mid(s+9, 17);
QByteArray macDst = mac.replace(":", "").toStdString().c_str();
QByteArray magic = QByteArray::fromHex("ffffffffffff");
for (int i = 0; i < 16; i++) magic.append(QByteArray::fromHex(macDst));
qDebug() << "sending wol";
udp.writeDatagram(magic.data(), magic.size(), QHostAddress::Broadcast, 7);
udp.writeDatagram(magic.data(), magic.size(), QHostAddress::Broadcast, 9);
}
// connect
airplay = new AirPlay(addresses.first().toString(), port, this);
}
void MainWindow::updateDevices(const QList<BonjourBrowseRecord> &list)
{
BonjourBrowseRecord current;
if (devicesActGrp && devicesActGrp->checkedAction() != 0)
current = devicesActGrp->checkedAction()->data().value<BonjourBrowseRecord>();
menuDevices->clear();
devicesActGrp = new QActionGroup(menuDevices);
foreach (BonjourBrowseRecord record, list) {
QVariant variant;
variant.setValue(record);
QAction *action = new QAction(devicesActGrp);
action->setText(record.serviceName);
action->setData(variant);
action->setCheckable(true);
action->setChecked(current == record); // select current
connect(action, SIGNAL(triggered()), this, SLOT(deviceClicked()));
menuDevices->addAction(action);
}
// select first
if (devicesActGrp->checkedAction() == 0 && menuDevices->actions().length() > 0)
menuDevices->actions().first()->setChecked(true);
}
void MainWindow::deviceClicked()
{
if (appState == STATE_STREAMING || appState == STATE_CONNECTING_DEVICE)
setState(STATE_CONNECTING_DEVICE);
}
void MainWindow::loadLicense(QString fileName)
{
if (prefs->loadLicense(fileName))
{
setWindowTitle("StreamPlay");
prefDialog->enableTabs();
prefDialog->setRegState();
prefDialog->showLicenseTab();
prefDialog->show();
prefDialog->activateWindow();
prefDialog->raise();
prefDialog->setFocus();
// resume playback
if (airplay && airplay->getStatus() != AirPlay::CONNECTING)
airplay->resume();
}
}
MainWindow::~MainWindow()
{
timerStateLoop.stop();
if (hlsVideo) hlsVideo->stop();
if (airplay) airplay->stop(); // stop play nicely
if (bonjourResolver) delete bonjourResolver;
delete ui;
}