-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathctimerrec.cpp
994 lines (872 loc) · 28.8 KB
/
ctimerrec.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
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
/*********************** Information *************************\
| $HeadURL$
|
| Author: Jo2003
|
| Begin: 24.01.2010 / 15:41:34
|
| Last edited by: $Author$
|
| $Id$
\*************************************************************/
#include "ctimerrec.h"
#include "ui_ctimerrec.h"
#include <QFileInfo>
#include "externals_inc.h"
/* -----------------------------------------------------------------\
| Method: CTimerRec / constructor
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: create object, init values
|
| Parameters: pointer to parent window
|
| Returns: --
\----------------------------------------------------------------- */
CTimerRec::CTimerRec(QWidget *parent) : QDialog(parent), r_ui(new Ui::CTimerRec)
{
r_ui->setupUi(this);
iReqId = -1;
uiActId = 0;
uiEdtId = INVALID_ID;
pSettings = NULL;
pStreamLoader = NULL;
actJob.id = (uint)-1;
InitTab();
connect (&recTimer, SIGNAL(timeout()), this, SLOT(slotRecTimer()));
connect (this, SIGNAL(accepted()), this, SLOT(slotSaveRecordList()));
}
/* -----------------------------------------------------------------\
| Method: ~CTimerRec / destructor
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: clean on destruction
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
CTimerRec::~CTimerRec()
{
delete r_ui;
}
/* -----------------------------------------------------------------\
| Method: changeEvent
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: catch language change event
|
| Parameters: event pointer
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type())
{
case QEvent::LanguageChange:
r_ui->retranslateUi(this);
break;
default:
break;
}
}
/* -----------------------------------------------------------------\
| Method: SetStreamLoader
| Begin: 20.12.2010 / 10:10
| Author: Jo2003
| Description: set stream loader
|
| Parameters: pointer to stream loader class
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::SetStreamLoader(CStreamLoader *pLoader)
{
pStreamLoader = pLoader;
connect (pStreamLoader, SIGNAL(sigStreamDwnTimer(int,QString)), this,
SLOT(slotStreamReady(int,QString)));
}
//---------------------------------------------------------------------------
//
//! \brief is silent timer record active ... ?
//
//! \author Jo2003
//! \date 19.12.2013
//
//! \param --
//
//! \return true -> active; false -> not active ...
//---------------------------------------------------------------------------
bool CTimerRec::silentRec()
{
bool bSRAct = false;
// do we have marked an active job ... ?
if (actJob.id != (uint)-1)
{
// is timer record running in silent mode ?
if ((actJob.eState == rec::REC_RUNNING) && r_ui->checkRecMini->isChecked())
{
bSRAct = true;
}
}
return bSRAct;
}
/* -----------------------------------------------------------------\
| Method: StartTimer
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: start timer loop
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::StartTimer()
{
if (!recTimer.isActive())
{
// check time every 3 second ...
recTimer.start(3000);
}
}
/* -----------------------------------------------------------------\
| Method: SetSettings
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: set settings
|
| Parameters: pointer to settings
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::SetSettings(CSettingsDlg *pSet)
{
pSettings = pSet;
if (pSettings->GetShutdownCmd() == "")
{
r_ui->checkShutdown->setDisabled(true);
}
}
/* -----------------------------------------------------------------\
| Method: SetVlcCtrl
| Begin: 01.02.2010 / 11:05:00
| Author: Jo2003
| Description: set vlc control
|
| Parameters: pointer to vlc control class
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::SetVlcCtrl(CVlcCtrl *pCtrl)
{
pVlcCtrl = pCtrl;
}
/* -----------------------------------------------------------------\
| Method: SetRecInfo
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: fill in record info into dialog
|
| Parameters: start time, end time, channel id, program name
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::SetRecInfo (uint uiStart, uint uiEnd, int cid, const QString &name)
{
// check if timeshift is available for this channel ...
int iTs = pChanMap->timeShift(cid);
// we don't update ...
uiEdtId = INVALID_ID;
// helper ...
QString s = iTs ? QString::number(tmSync.timeShift()) : "0";
// set timeshift stuff ...
if (iTs)
{
uiStart = tmSync.gmtToTs(uiStart);
uiEnd = tmSync.gmtToTs(uiEnd);
}
QDateTime dtStart = QDateTime::fromTime_t(uiStart - TIMER_REC_OFFSET);
QDateTime dtEnd = QDateTime::fromTime_t(uiEnd + TIMER_REC_OFFSET);
r_ui->dtEdtStart->setDateTime(dtStart);
if (uiEnd > 1000000) // make sure there was a correct value set for end ...
{
r_ui->dtEdtEnd->setDateTime(dtEnd);
}
else
{
// if no end is given, set end time 1 hour later than start ...
r_ui->dtEdtEnd->setDateTime(dtStart.addSecs(3600));
}
r_ui->cbxChannel->setCurrentIndex(r_ui->cbxChannel->findData(QVariant(cid)));
r_ui->cbxTimeShift->setCurrentIndex(r_ui->cbxTimeShift->findText(s));
if (name != "")
{
r_ui->edtName->setText(QString("%1(%2)").arg(name)
.arg(dtStart.toString("yyyy-MM-dd__hh-mm")));
}
else
{
// set name ...
QMap<int, rec::SChanEntry>::const_iterator cit = ChanList.constFind(cid);
if (cit != ChanList.constEnd())
{
r_ui->edtName->setText(QString("%1-%2").arg((*cit).Name)
.arg(dtStart.toString("yyyy-MM-dd__hh-mm")));
}
else
{
r_ui->edtName->setText(dtStart.toString("yyyy-MM-dd, hh-mm"));
}
}
}
/* -----------------------------------------------------------------\
| Method: SetChanList
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: set channel list
|
| Parameters: ref. to channel list
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::SetChanList(const QVector<cparser::SChan> &chanList)
{
rec::SChanEntry entry;
QFileInfo fInfo;
ChanList.clear();
r_ui->cbxChannel->clear();
int iCount = 0;
for (int i = 0; i < chanList.size(); i++)
{
if (!chanList[i].bIsGroup)
{
iCount ++;
entry.cid = chanList[i].iId;
entry.Name = chanList[i].sName;
fInfo.setFile(chanList[i].sIcon);
r_ui->cbxChannel->insertItem(i,
QIcon(QString("%1/%2").arg(pFolders->getLogoDir()).arg(fInfo.fileName())),
QString("%1. %2").arg(iCount).arg(entry.Name),
QVariant(entry.cid));
ChanList[entry.cid] = entry;
}
}
}
/* -----------------------------------------------------------------\
| Method: slotSaveRecordList
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: save record list to xml file
|
| Parameters: --
|
| Returns: 0 ==> ok
| -1 ==> any error
\----------------------------------------------------------------- */
int CTimerRec::slotSaveRecordList()
{
int iRV = 0;
QSqlQuery query;
QString question;
// delete all stored entries from database ...
pDb->ask("DELETE FROM timerrec", query);
QMap<uint, rec::SRecEntry>::const_iterator cit;
for (cit = JobList.constBegin(); (cit != JobList.constEnd()) && !iRV; cit++)
{
question = QString("INSERT INTO timerrec "
"(cid, timeshift, recstart, recend, name)"
" VALUES (%1, %2, %3, %4, '%5')")
.arg((*cit).cid).arg((*cit).iTimeShift)
.arg((*cit).uiStart).arg((*cit).uiEnd)
.arg((*cit).sName);
iRV |= pDb->ask(question, query);
if (iRV)
{
QMessageBox::critical(NULL, tr("Error in %1").arg(__FUNCTION__),
tr("SQL Error String: %1").arg(pDb->sqlError()));
}
}
return iRV;
}
/* -----------------------------------------------------------------\
| Method: on_btnSet_clicked
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: insert entry into tab and joblist
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::on_btnSet_clicked()
{
// sanity check ...
if (!SanityCheck(r_ui->dtEdtStart->dateTime(), r_ui->dtEdtEnd->dateTime(), uiEdtId))
{
if (r_ui->edtName->text() != "")
{
// update or new entry ... ?
if (uiEdtId != INVALID_ID)
{
// update ...
// find entry to update ...
QMap<uint, rec::SRecEntry>::iterator it = JobList.find(uiEdtId);
// if found, update ...
if (it != JobList.end())
{
(*it).cid = r_ui->cbxChannel->itemData(r_ui->cbxChannel->currentIndex()).toInt();
(*it).iTimeShift = r_ui->cbxTimeShift->currentText().toInt();
(*it).uiStart = tmSync.tsToGmt(r_ui->dtEdtStart->dateTime().toTime_t(), (*it).iTimeShift);
(*it).uiEnd = tmSync.tsToGmt(r_ui->dtEdtEnd->dateTime().toTime_t(), (*it).iTimeShift);
(*it).sName = r_ui->edtName->text();
// leave id and record state untouched ...
// delete from job tab ...
DelRow(uiEdtId);
// add row to job tab ...
AddRow(*it);
}
// we're done ...
uiEdtId = INVALID_ID;
}
else
{
// new entry ...
rec::SRecEntry entry;
entry.cid = r_ui->cbxChannel->itemData(r_ui->cbxChannel->currentIndex()).toInt();
entry.iTimeShift = r_ui->cbxTimeShift->currentText().toInt();
entry.uiStart = tmSync.tsToGmt(r_ui->dtEdtStart->dateTime().toTime_t(), entry.iTimeShift);
entry.uiEnd = tmSync.tsToGmt(r_ui->dtEdtEnd->dateTime().toTime_t(), entry.iTimeShift);
entry.sName = r_ui->edtName->text();
entry.eState = rec::REC_READY;
// AddJob also adds the table row ...
AddJob (entry);
uiEdtId = INVALID_ID;
}
}
else
{
QMessageBox::warning(this, tr("Please Correct!"),
tr("Please insert a name!"));
}
}
else
{
QMessageBox::warning(this, tr("Please Correct!"),
tr("The entry you want to add overlapps with an existing entry\n"
"or start time is later than end time!"));
}
}
/* -----------------------------------------------------------------\
| Method: ReadRecordList
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: read old joblist from xml file
|
| Parameters: --
|
| Returns: -1 --> any error
| 0 --> ok
\----------------------------------------------------------------- */
int CTimerRec::ReadRecordList()
{
QSqlQuery query;
rec::SRecEntry entry;
int iRV = 0;
JobList.clear();
if (!pDb->ask("SELECT id, cid, timeshift, recstart, recend, name FROM timerrec", query))
{
while (query.next())
{
entry.dbId = query.value(0).toUInt();
entry.cid = query.value(1).toInt();
entry.iTimeShift = query.value(2).toInt();
entry.uiStart = query.value(3).toUInt();
entry.uiEnd = query.value(4).toUInt();
entry.sName = query.value(5).toString();
entry.eState = rec::REC_READY;
// AddJob also adds the table row ...
AddJob(entry);
}
}
else
{
QMessageBox::critical(NULL, tr("Error in %1").arg(__FUNCTION__),
tr("SQL Error String: %1").arg(pDb->sqlError()));
iRV = -1;
}
return iRV;
}
/* -----------------------------------------------------------------\
| Method: AddRow
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: add one row to job tab
|
| Parameters: ref. to job entry
|
| Returns: act table row
\----------------------------------------------------------------- */
int CTimerRec::AddRow(const rec::SRecEntry &entry)
{
QTableWidgetItem *pItem;
int iRows;
QDateTime when;
Qt::ItemFlags flags;
uint uiStart, uiEnd;
// convert times from GMT ...
uiStart = tmSync.gmtToTs(entry.uiStart, entry.iTimeShift);
uiEnd = tmSync.gmtToTs(entry.uiEnd , entry.iTimeShift);
// prepare cell flags ...
flags = Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled;
iRows = r_ui->tableRecordEntries->rowCount();
// one row more ...
r_ui->tableRecordEntries->setRowCount(iRows + 1);
// col 1: date ...
when = QDateTime::fromTime_t(uiStart);
pItem = new QTableWidgetItem (when.toString("dd.MM.yyyy"));
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 0, pItem);
// col 2: start time ...
pItem = new QTableWidgetItem (when.toString("hh:mm"));
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 1, pItem);
// col 3: end time ...
when = QDateTime::fromTime_t(uiEnd);
pItem = new QTableWidgetItem (when.toString("hh:mm"));
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 2, pItem);
// col 4: channel ...
pItem = new QTableWidgetItem (QIcon(QString("%1/%2.gif").arg(pFolders->getLogoDir()).arg(entry.cid)), "");
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 3, pItem);
// col. 5: timeshift ...
pItem = new QTableWidgetItem (QString::number(entry.iTimeShift));
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 4, pItem);
// col 6: name ...
pItem = new QTableWidgetItem (entry.sName);
pItem->setFlags(flags);
pItem->setData(Qt::UserRole, QVariant(entry.id));
r_ui->tableRecordEntries->setItem(iRows, 5, pItem);
r_ui->tableRecordEntries->setRowHeight(iRows, 26);
return iRows + 1;
}
/* -----------------------------------------------------------------\
| Method: InitTab
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: init table view
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::InitTab()
{
r_ui->tableRecordEntries->clearContents();
r_ui->tableRecordEntries->setIconSize(QSize(24, 24));
r_ui->tableRecordEntries->setColumnWidth(0, 80);
r_ui->tableRecordEntries->setColumnWidth(1, 70);
r_ui->tableRecordEntries->setColumnWidth(2, 70);
r_ui->tableRecordEntries->setColumnWidth(3, 40);
r_ui->tableRecordEntries->setColumnWidth(4, 25);
}
/* -----------------------------------------------------------------\
| Method: AddJob
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: add job to joblist
|
| Parameters: ref. to job entry
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::AddJob(rec::SRecEntry &entry)
{
mInfo(tr("Add Job #%1 (%2) to Joblist!").arg(uiActId).arg(entry.sName));
entry.id = uiActId;
JobList[entry.id] = entry;
AddRow(entry);
uiActId ++;
}
/* -----------------------------------------------------------------\
| Method: SanityCheck
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: check if we can add this job (check times)
|
| Parameters: start time, end time
|
| Returns: 0 ==> check ok
| -1 ==> check not passed
\----------------------------------------------------------------- */
int CTimerRec::SanityCheck(const QDateTime &start, const QDateTime &end, uint uiUpdId)
{
int iRV = 0;
if (start < end)
{
uint uiStart, uiEnd;
for (int i = 0; i < JobList.size(); i++)
{
if ((uiUpdId == INVALID_ID) || (uiUpdId != JobList[i].id))
{
uiStart = tmSync.gmtToTs(JobList[i].uiStart, JobList[i].iTimeShift);
uiEnd = tmSync.gmtToTs(JobList[i].uiEnd , JobList[i].iTimeShift);
// start this between start/end other ...
if (((start.toTime_t() >= uiStart) && (start.toTime_t() <= uiEnd))
// end this between start/end other ...
|| ((end.toTime_t() >= uiStart) && (end.toTime_t() <= uiEnd))
// start this before start other and end this after end other ...
|| ((start.toTime_t() < uiStart) && (end.toTime_t() > uiEnd)))
{
iRV = -1;
break;
}
}
else
{
// ignore id we try to update ...
mInfo(tr("Don't check ID %1 (it will be updated).").arg(uiUpdId));
}
}
}
else
{
// start later or equal end ...
iRV = -1;
}
return iRV;
}
/* -----------------------------------------------------------------\
| Method: on_tableRecordEntries_cellDoubleClicked
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: insert marked entry into edit fields
|
| Parameters: row, col
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::on_tableRecordEntries_cellDoubleClicked(int row, int column)
{
QTableWidgetItem *pItem = r_ui->tableRecordEntries->item(row, column);
if (pItem)
{
uint id = pItem->data(Qt::UserRole).toUInt();
uiEdtId = id;
QMap<uint, rec::SRecEntry>::const_iterator cit;
cit = JobList.constFind(id);
if (cit != JobList.constEnd())
{
uint when;
// start ...
when = tmSync.gmtToTs((*cit).uiStart, (*cit).iTimeShift);
r_ui->dtEdtStart->setDateTime(QDateTime::fromTime_t(when));
// end ...
when = tmSync.gmtToTs((*cit).uiEnd, (*cit).iTimeShift);
r_ui->dtEdtEnd->setDateTime(QDateTime::fromTime_t(when));
// channel ...
r_ui->cbxChannel->setCurrentIndex(r_ui->cbxChannel->findData(QVariant((*cit).cid)));
// timshift ...
r_ui->cbxTimeShift->setCurrentIndex(r_ui->cbxTimeShift->findText(QString::number((*cit).iTimeShift)));
// name ...
r_ui->edtName->setText((*cit).sName);
}
}
}
/* -----------------------------------------------------------------\
| Method: DelRow
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: del row from job tab
|
| Parameters: entry id
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::DelRow(uint uiId)
{
QTableWidgetItem *pItem;
for (int i = 0; i < r_ui->tableRecordEntries->rowCount(); i++)
{
pItem = r_ui->tableRecordEntries->item(i, 0);
if (pItem)
{
if (pItem->data(Qt::UserRole).toUInt() == uiId)
{
r_ui->tableRecordEntries->removeRow(i);
break;
}
}
}
}
/* -----------------------------------------------------------------\
| Method: delDbEntry
| Begin: 13.04.2011 / 10:45
| Author: Jo2003
| Description: del row from timerrec table
|
| Parameters: entry id
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::delDbEntry(int id)
{
QSqlQuery query;
query.prepare("DELETE FROM timerrec WHERE id=?");
query.addBindValue(id);
pDb->ask(query);
}
/* -----------------------------------------------------------------\
| Method: on_btnDel_clicked
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: del current job tab entry and matching joblist entry
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::on_btnDel_clicked()
{
QTableWidgetItem *pItem = r_ui->tableRecordEntries->currentItem();
if (pItem)
{
uint id = pItem->data(Qt::UserRole).toUInt();
JobList.remove(id);
r_ui->tableRecordEntries->removeRow(r_ui->tableRecordEntries->currentRow());
}
}
/* -----------------------------------------------------------------\
| Method: slotRecTimer
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: timer signal, check joblist if we should start
| a record job
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::slotRecTimer()
{
if (pApiClient)
{
if (JobList.isEmpty())
{
emit sigRecDone();
}
else
{
uint now = tmSync.syncronizedTime_t();
uint start, end;
QMap<uint, rec::SRecEntry>::iterator it = JobList.begin();
while (it != JobList.end())
{
start = tmSync.gmtToTs((*it).uiStart, (*it).iTimeShift);
end = tmSync.gmtToTs((*it).uiEnd , (*it).iTimeShift);
if (now >= end)
{
// mark active job as invalid ...
actJob.id = (uint)-1;
// was record active ... ?
if ((*it).eState != rec::REC_RUNNING)
{
// old record ... delete without sending signals ...
mInfo(tr("Delete old entry #%1 (%2) from Joblist.").arg((*it).id).arg((*it).sName));
DelRow((*it).id);
delDbEntry((*it).dbId);
it = JobList.erase(it);
}
else
{
// record was active ... is now done ...
mInfo(tr("Stopping timer record #%1 (%2). End time reached!").arg((*it).id).arg((*it).sName));
DelRow((*it).id);
it = JobList.erase(it);
// stop job (vlc) ...
if (pVlcCtrl->IsRunning())
{
pVlcCtrl->stop();
}
// if own downloader was used ...
if (pVlcCtrl->ownDwnld())
{
pStreamLoader->stopDownload(iReqId);
iReqId = -1;
}
emit sigRecDone();
// shut we shut down the system ... ?
if (JobList.isEmpty() // all done ...
&& r_ui->checkShutdown->isChecked()) // we want to shut down ...
{
ShutDown();
}
}
}
else
{
// should we set timer to stby ... ?
if (((start - TIMER_STBY_TIME) <= now) && ((*it).eState == rec::REC_READY))
{
// set timer to stby ...
emit sigRecActive((int)IncPlay::PS_TIMER_STBY);
(*it).eState = rec::REC_STBY;
// stop any running vlc ...
if (pVlcCtrl->IsRunning())
{
pVlcCtrl->stop();
}
mInfo(tr("Record #%1 (%2) starts soon. Set timer to standby!").arg((*it).id).arg((*it).sName));
// set timeshift ...
pApiClient->queueRequest(CIptvDefs::REQ_TIMESHIFT, (*it).iTimeShift);
}
else if ((start <= now) && ((*it).eState == rec::REC_STBY))
{
// start record ...
mInfo(tr("Start record #%1 (%2)!").arg((*it).id).arg((*it).sName));
emit sigRecActive((int)IncPlay::PS_TIMER_RECORD);
(*it).eState = rec::REC_RUNNING;
// save current entry ...
actJob = *it;
showInfo.cleanShowInfo();
showInfo.setChanId((*it).cid);
showInfo.setShowName((*it).sName);
showInfo.setShowType(ShowInfo::Live);
showInfo.setStartTime((*it).uiStart);
showInfo.setEndTime((*it).uiEnd);
showInfo.setPlayState(IncPlay::PS_TIMER_RECORD);
showInfo.setChanName(ChanList[(*it).cid].Name);
#ifdef RADIO_OFFSET
pApiClient->queueRequest(((*it).cid < RADIO_OFFSET) ? CIptvDefs::REQ_TIMERREC : CIptvDefs::REQ_RADIO_TIMERREC, (*it).cid);
#else
pApiClient->queueRequest(CIptvDefs::REQ_TIMERREC, (*it).cid);
#endif
}
it++;
}
}
}
}
}
/* -----------------------------------------------------------------\
| Method: slotTimerStreamUrl
| Begin: 26.01.2010 / 16:05:00
| Author: Jo2003
| Description: got stream url, start VLC
|
| Parameters: stream url
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::slotTimerStreamUrl(const QString &str)
{
QString sCmdLine;
Q_PID vlcpid = 0;
QString sUrl, sDst;
if (!pApiParser->parseUrl(str, sUrl))
{
sDst = QString("%1/%2").arg(pSettings->GetTargetDir()).arg(actJob.sName);
if (pVlcCtrl->ownDwnld())
{
// own downloader ...
pStreamLoader->downloadStream(sUrl, QString("%1.%2").arg(sDst).arg("ts"),
pSettings->GetBufferTime(), true);
}
else
{
if (r_ui->checkRecMini->isChecked())
{
// silent record ...
sCmdLine = pVlcCtrl->CreateClArgs(vlcctrl::VLC_REC_LIVE_SILENT,
pSettings->GetVLCPath(), sUrl,
pSettings->GetBufferTime(), sDst, "ts");
}
else
{
// normal record ...
sCmdLine = pVlcCtrl->CreateClArgs(vlcctrl::VLC_REC_LIVE,
pSettings->GetVLCPath(), sUrl,
pSettings->GetBufferTime(), sDst, "ts");
}
vlcpid = pVlcCtrl->start(sCmdLine, -1, false, IncPlay::PS_TIMER_RECORD);
// successfully started ?
if (!vlcpid)
{
QMessageBox::critical(this, tr("Error!"), tr("Can't start Player!"));
}
else
{
mInfo(tr("Started player with pid #%1!").arg((uint)vlcpid));
}
}
}
}
/* -----------------------------------------------------------------\
| Method: ShutDown
| Begin: 02.02.2010 / 15:05:00
| Author: Jo2003
| Description: shutdown system with user set command
|
| Parameters: --
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::ShutDown()
{
mInfo(tr("All records done. Shutdown system using command line:\n --> %1").arg(pSettings->GetShutdownCmd()));
QProcess::startDetached(pSettings->GetShutdownCmd());
emit sigShutdown();
}
/* -----------------------------------------------------------------\
| Method: slotStreamReady [slot]
| Begin: 20.12.2010 / 10:12
| Author: Jo2003
| Description: stream download started, stream can be used
|
| Parameters: request id, filename of stream stored in HD
|
| Returns: --
\----------------------------------------------------------------- */
void CTimerRec::slotStreamReady (int Id, QString sName)
{
iReqId = Id;
// on silent record there is no need to show the video ...
// so only store the request id here ...
// if no silent record, create command line and show
// recorded stream ...
if (!r_ui->checkRecMini->isChecked())
{
Q_PID vlcpid = 0;
QString sCmdLine, fileName, sExt;
QFileInfo info(sName);
fileName = QString ("%1/%2").arg(info.path()).arg(info.completeBaseName());
sExt = info.suffix();
sCmdLine = pVlcCtrl->CreateClArgs(vlcctrl::VLC_REC_LIVE, pSettings->GetVLCPath(),
"", pSettings->GetBufferTime(),
fileName, sExt);
// start player if we have a command line ...
if (sCmdLine != "")
{
vlcpid = pVlcCtrl->start(sCmdLine, -1, false, IncPlay::PS_TIMER_RECORD);
}
// successfully started ?
if (!vlcpid)
{
QMessageBox::critical(this, tr("Error!"), tr("Can't start Player!"));
}
else
{
mInfo(tr("Started player with pid #%1!").arg((uint)vlcpid));
}
}
}
/************************* History ***************************\
| $Log$
\*************************************************************/