-
Notifications
You must be signed in to change notification settings - Fork 343
/
customedit.cpp
879 lines (739 loc) · 29.8 KB
/
customedit.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
#include "customedit.h"
// QT
#include <QSqlError>
// libmythbase
#include "mythdb.h"
// libmyth
#include "mythcorecontext.h"
// libmythui
#include "mythuibuttonlist.h"
#include "mythuitextedit.h"
#include "mythuibutton.h"
#include "mythdialogbox.h"
// libmythtv
#include "recordingrule.h"
// mythfrontend
#include "scheduleeditor.h"
#include "proglist.h"
CustomEdit::CustomEdit(MythScreenStack *parent, ProgramInfo *pginfo)
: MythScreenType(parent, "CustomEdit")
{
if (pginfo)
m_pginfo = new ProgramInfo(*pginfo);
else
m_pginfo = new ProgramInfo();
m_baseTitle = m_pginfo->GetTitle();
m_baseTitle.remove(QRegExp(" \\(.*\\)$"));
m_maxex = 0;
m_seSuffix = QString(" (%1)").arg(tr("stored search"));
m_exSuffix = QString(" (%1)").arg(tr("stored example"));
gCoreContext->addListener(this);
}
CustomEdit::~CustomEdit(void)
{
delete m_pginfo;
gCoreContext->removeListener(this);
}
bool CustomEdit::Create()
{
if (!LoadWindowFromXML("schedule-ui.xml", "customedit", this))
return false;
bool err = false;
UIUtilE::Assign(this, m_ruleList, "rules", &err);
UIUtilE::Assign(this, m_clauseList, "clauses", &err);
UIUtilE::Assign(this, m_titleEdit, "title", &err);
UIUtilE::Assign(this, m_subtitleEdit, "subtitle", &err);
UIUtilE::Assign(this, m_descriptionEdit, "description", &err);
UIUtilE::Assign(this, m_clauseText, "clausetext", &err);
UIUtilE::Assign(this, m_testButton, "test", &err);
UIUtilE::Assign(this, m_recordButton, "record", &err);
UIUtilE::Assign(this, m_storeButton, "store", &err);
UIUtilE::Assign(this, m_cancelButton, "cancel", &err);
if (err)
{
LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'customedit'");
return false;
}
connect(m_ruleList, SIGNAL(itemSelected(MythUIButtonListItem *)),
SLOT(ruleChanged(MythUIButtonListItem *)));
connect(m_titleEdit, SIGNAL(valueChanged(void)), this,
SLOT(textChanged(void)));
m_titleEdit->SetMaxLength(128);
m_subtitleEdit->SetMaxLength(128);
connect(m_descriptionEdit, SIGNAL(valueChanged(void)), this,
SLOT(textChanged(void)));
m_descriptionEdit->SetMaxLength(0);
connect(m_clauseList, SIGNAL(itemSelected(MythUIButtonListItem *)),
SLOT(clauseChanged(MythUIButtonListItem *)));
connect(m_clauseList, SIGNAL(itemClicked(MythUIButtonListItem *)),
SLOT(clauseClicked(MythUIButtonListItem *)));
connect(m_testButton, SIGNAL(Clicked()), SLOT(testClicked()));
connect(m_recordButton, SIGNAL(Clicked()), SLOT(recordClicked()));
connect(m_storeButton, SIGNAL(Clicked()), SLOT(storeClicked()));
connect(m_cancelButton, SIGNAL(Clicked()), SLOT(Close()));
loadData();
BuildFocusList();
return true;
}
void CustomEdit::loadData(void)
{
CustomRuleInfo rule;
// New Rule defaults
rule.recordid = '0';
rule.title = m_baseTitle;
if (!m_baseTitle.isEmpty())
{
QString quoteTitle = m_baseTitle;
quoteTitle.replace("\'","\'\'");
rule.description = QString("program.title = '%1' ").arg(quoteTitle);
}
new MythUIButtonListItem(m_ruleList, tr("<New rule>"),
qVariantFromValue(rule));
MSqlQuery result(MSqlQuery::InitCon());
result.prepare("SELECT recordid, title, subtitle, description "
"FROM record WHERE search = :SEARCH ORDER BY title;");
result.bindValue(":SEARCH", kPowerSearch);
if (result.exec())
{
while (result.next())
{
QString trimTitle = result.value(1).toString();
trimTitle.remove(QRegExp(" \\(.*\\)$"));
rule.recordid = result.value(0).toString();
rule.title = trimTitle;
rule.subtitle = result.value(2).toString();
rule.description = result.value(3).toString();
MythUIButtonListItem *item =
new MythUIButtonListItem(m_ruleList, rule.title,
qVariantFromValue(rule));
if (trimTitle == m_baseTitle ||
result.value(0).toUInt() == m_pginfo->GetRecordingRuleID())
m_ruleList->SetItemCurrent(item);
}
}
else
MythDB::DBError("Get power search rules query", result);
loadClauses();
textChanged();
}
void CustomEdit::loadClauses()
{
QString quoteTitle = m_baseTitle;
quoteTitle.replace("\'","\'\'");
CustomRuleInfo rule;
rule.title = tr("Match an exact title");
if (!m_baseTitle.isEmpty())
rule.description = QString("program.title = '%1' ").arg(quoteTitle);
else
rule.description = "program.title = 'Nova' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
if (!m_pginfo->GetSeriesID().isEmpty())
{
rule.title = tr("Match this series");
rule.subtitle.clear();
rule.description = QString("program.seriesid = '%1' ")
.arg(m_pginfo->GetSeriesID());
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
}
rule.title = tr("Match words in the title");
rule.subtitle.clear();
if (!m_pginfo->GetTitle().isEmpty())
rule.description = QString("program.title LIKE '%%1%' ")
.arg(quoteTitle);
else
rule.description = "program.title LIKE 'CSI: %' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Match words in the subtitle");
rule.subtitle.clear();
if (!m_pginfo->GetSubtitle().isEmpty())
{
QString subt = m_pginfo->GetSubtitle();
subt.replace("\'","\'\'");
rule.description = QString("program.subtitle LIKE '%%1%' ")
.arg(subt);
}
else
rule.description = "program.subtitle LIKE '%Las Vegas%' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
if (!m_pginfo->GetProgramID().isEmpty())
{
rule.title = tr("Match this episode");
rule.subtitle.clear();
rule.description = QString("program.programid = '%1' ")
.arg(m_pginfo->GetProgramID());
}
else if (!m_pginfo->GetSubtitle().isEmpty())
{
rule.title = tr("Match this episode");
rule.subtitle.clear();
rule.description = QString("program.subtitle = '%1' \n"
"AND program.description = '%2' ")
.arg(m_pginfo->GetSubtitle().replace("\'","\'\'"))
.arg(m_pginfo->GetDescription().replace("\'","\'\'"));
}
else
{
rule.title = tr("Match an exact episode");
rule.subtitle.clear();
rule.description = QString("program.title = 'Seinfeld' \n"
"AND program.subtitle = 'The Soup' ");
}
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Match in any descriptive field");
rule.subtitle.clear();
rule.description = QString("(program.title LIKE '%Japan%' \n"
" OR program.subtitle LIKE '%Japan%' \n"
" OR program.description LIKE '%Japan%') ");
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("New episodes only");
rule.subtitle.clear();
rule.description = "program.previouslyshown = 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Exclude unidentified episodes");
rule.subtitle.clear();
rule.description = "program.generic = 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("First showing of each episode");
rule.subtitle.clear();
rule.description = "program.first > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Last showing of each episode");
rule.subtitle.clear();
rule.description = "program.last > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Anytime on a specific day of the week");
rule.subtitle.clear();
rule.description = QString("DAYNAME(program.starttime) = '%1' ")
.arg(m_pginfo->GetScheduledStartTime().toString("dddd"));
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only on weekdays (Monday through Friday)");
rule.subtitle.clear();
rule.description = "WEEKDAY(program.starttime) < 5 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only on weekends");
rule.subtitle.clear();
rule.description = "WEEKDAY(program.starttime) >= 5 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only in primetime");
rule.subtitle.clear();
rule.description = QString("HOUR(program.starttime) >= 19 \n"
"AND HOUR(program.starttime) < 23 ");
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Not in primetime");
rule.subtitle.clear();
rule.description = QString("(HOUR(program.starttime) < 19 \n"
" OR HOUR(program.starttime) >= 23) ");
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only on a specific station");
rule.subtitle.clear();
if (!m_pginfo->GetChannelSchedulingID().isEmpty())
rule.description = QString("channel.callsign = '%1' ")
.arg(m_pginfo->GetChannelSchedulingID());
else
rule.description = "channel.callsign = 'ESPN' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Exclude one station");
rule.subtitle.clear();
rule.description = "channel.callsign != 'GOLF' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Match related callsigns");
rule.subtitle.clear();
rule.description = "channel.callsign LIKE 'HBO%' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only channels from the Favorites group");
rule.subtitle = ", channelgroup cg, channelgroupnames cgn";
rule.description = "cgn.name = 'Favorites' \n"
"AND cg.grpid = cgn.grpid \n"
"AND program.chanid = cg.chanid ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only channels from a specific video source");
rule.subtitle.clear();
rule.description = "channel.sourceid = 2 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only channels marked as commercial free");
rule.subtitle.clear();
rule.description = QString("channel.commmethod = %1 ")
.arg(COMM_DETECT_COMMFREE);
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only shows marked as HDTV");
rule.subtitle.clear();
rule.description = "program.hdtv > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only shows marked as widescreen");
rule.subtitle.clear();
rule.description = "FIND_IN_SET('WIDESCREEN', program.videoprop) > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Exclude H.264 encoded streams (EIT only)");
rule.subtitle.clear();
rule.description = "FIND_IN_SET('AVC', program.videoprop) = 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only shows with in-vision signing");
rule.subtitle.clear();
rule.description = "FIND_IN_SET('SIGNED', program.subtitletypes) > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Only shows with in-vision subtitles");
rule.subtitle.clear();
rule.description = "FIND_IN_SET('ONSCREEN', program.subtitletypes) > 0 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Limit by category");
rule.subtitle.clear();
if (!m_pginfo->GetCategory().isEmpty())
rule.description = QString("program.category = '%1' ")
.arg(m_pginfo->GetCategory());
else
rule.description = "program.category = 'Reality' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("All matches for a genre (Data Direct)");
rule.subtitle = "LEFT JOIN programgenres ON "
"program.chanid = programgenres.chanid AND "
"program.starttime = programgenres.starttime ";
if (!m_pginfo->GetCategory().isEmpty())
rule.description = QString("programgenres.genre = '%1' ")
.arg(m_pginfo->GetCategory());
else
rule.description = "programgenres.genre = 'Reality' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Limit by MPAA or VCHIP rating (Data Direct)");
rule.subtitle = "LEFT JOIN programrating ON "
"program.chanid = programrating.chanid AND "
"program.starttime = programrating.starttime ";
rule.description = "(programrating.rating = 'G' OR programrating.rating "
"LIKE 'TV-Y%') ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = QString(tr("Category type") +
" ('movie', 'series', 'sports' " + tr("or") + " 'tvshow')");
rule.subtitle.clear();
rule.description = "program.category_type = 'sports' ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Limit movies by the year of release");
rule.subtitle.clear();
rule.description = "program.category_type = 'movie' AND "
"program.airdate >= 2000 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Minimum star rating (0.0 to 1.0 for movies only)");
rule.subtitle.clear();
rule.description = "program.stars >= 0.75 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Person named in the credits (Data Direct)");
rule.subtitle = ", people, credits";
rule.description = "people.name = 'Tom Hanks' \n"
"AND credits.person = people.person \n"
"AND program.chanid = credits.chanid \n"
"AND program.starttime = credits.starttime ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
/* This shows how to use oldprogram but is a bad idea in practice.
This would match all future showings until the day after the first
showing when all future showing are no longer 'new' titles.
rule.title = tr("Only titles from the New Titles list");
rule.subtitle = "LEFT JOIN oldprogram"
" ON oldprogram.oldtitle = program.title ";
rule.description = "oldprogram.oldtitle IS NULL ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
*/
rule.title = tr("Re-record SDTV in HDTV (disable duplicate matching)");
rule.subtitle = ", recordedprogram rp1 LEFT OUTER JOIN recordedprogram rp2"
" ON rp1.programid = rp2.programid AND rp2.hdtv = 1";
rule.description = "program.programid = rp1.programid \n"
"AND rp1.hdtv = 0 \n"
"AND program.hdtv = 1 \n"
"AND rp2.starttime IS NULL ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Multiple sports teams (complete example)");
rule.subtitle.clear();
rule.description = "program.title = 'NBA Basketball' \n"
"AND program.subtitle REGEXP '(Miami|Cavaliers|Lakers)' \n"
"AND program.first > 0 \n";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Sci-fi B-movies (complete example)");
rule.subtitle.clear();
rule.description = "program.category_type='movie' \n"
"AND program.category='Science fiction' \n"
"AND program.stars <= 0.5 AND program.airdate < 1970 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title =
tr("SportsCenter Overnight (complete example - use FindDaily)");
rule.subtitle.clear();
rule.description = "program.title = 'SportsCenter' \n"
"AND HOUR(program.starttime) >= 2 \n"
"AND HOUR(program.starttime) <= 6 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("Movie of the Week (complete example - use FindWeekly)");
rule.subtitle.clear();
rule.description = "program.category_type='movie' \n"
"AND program.stars >= 1.0 AND program.airdate >= 1965 \n"
"AND DAYNAME(program.starttime) = 'Friday' \n"
"AND HOUR(program.starttime) >= 12 ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
rule.title = tr("First Episodes (complete example for Data Direct)");
rule.subtitle.clear();
rule.description = "program.first > 0 \n"
"AND program.programid LIKE 'EP%0001' \n"
"AND program.originalairdate = DATE(program.starttime) ";
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
m_maxex = m_clauseList->GetCount();
MSqlQuery result(MSqlQuery::InitCon());
result.prepare("SELECT rulename,fromclause,whereclause,search "
"FROM customexample;");
if (result.exec())
{
while (result.next())
{
QString str = result.value(0).toString();
if (result.value(3).toInt() > 0)
str += m_seSuffix;
else
str += m_exSuffix;
rule.title = str;
rule.subtitle = result.value(1).toString();
rule.description = result.value(2).toString();
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
}
}
}
void CustomEdit::ruleChanged(MythUIButtonListItem *item)
{
if (!item)
return;
CustomRuleInfo rule = qVariantValue<CustomRuleInfo>(item->GetData());
m_titleEdit->SetText(rule.title);
m_descriptionEdit->SetText(rule.description);
m_subtitleEdit->SetText(rule.subtitle);
textChanged();
}
void CustomEdit::textChanged(void)
{
bool hastitle = !m_titleEdit->GetText().isEmpty();
bool hasdesc = !m_descriptionEdit->GetText().isEmpty();
m_testButton->SetEnabled(hasdesc);
m_recordButton->SetEnabled(hastitle && hasdesc);
m_storeButton->SetEnabled(m_clauseList->GetCurrentPos() >= m_maxex ||
(hastitle && hasdesc));
}
void CustomEdit::clauseChanged(MythUIButtonListItem *item)
{
if (!item)
return;
CustomRuleInfo rule = qVariantValue<CustomRuleInfo>(item->GetData());
QString msg = rule.description;
msg.replace('\n', ' ');
msg.replace(QRegExp(" [ ]*"), " ");
msg = QString("\"%1\"").arg(msg);
m_clauseText->SetText(msg);
bool hastitle = !m_titleEdit->GetText().isEmpty();
bool hasdesc = !m_descriptionEdit->GetText().isEmpty();
m_storeButton->SetEnabled(m_clauseList->GetCurrentPos() >= m_maxex ||
(hastitle && hasdesc));
}
void CustomEdit::clauseClicked(MythUIButtonListItem *item)
{
if (!item)
return;
CustomRuleInfo rule = qVariantValue<CustomRuleInfo>(item->GetData());
QString clause;
QString desc = m_descriptionEdit->GetText();
if (desc.contains(QRegExp("\\S")))
clause = "AND ";
clause += rule.description;
m_descriptionEdit->SetText(desc.append(clause));
QString sub = m_subtitleEdit->GetText();
m_subtitleEdit->SetText(sub.append(rule.subtitle));
}
void CustomEdit::testClicked(void)
{
if (!checkSyntax())
{
return;
}
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
ProgLister *pl = new ProgLister(mainStack, plSQLSearch,
m_descriptionEdit->GetText(),
m_subtitleEdit->GetText());
if (pl->Create())
{
mainStack->AddScreen(pl);
}
else
delete pl;
}
void CustomEdit::recordClicked(void)
{
if (!checkSyntax())
return;
RecordingRule *record = new RecordingRule();
MythUIButtonListItem* item = m_ruleList->GetItemCurrent();
CustomRuleInfo rule = qVariantValue<CustomRuleInfo>(item->GetData());
int cur_recid = rule.recordid.toInt();
if (cur_recid > 0)
{
record->ModifyPowerSearchByID(cur_recid, m_titleEdit->GetText(),
m_descriptionEdit->GetText(),
m_subtitleEdit->GetText());
}
else
{
record->LoadBySearch(kPowerSearch, m_titleEdit->GetText(),
m_descriptionEdit->GetText(),
m_subtitleEdit->GetText());
}
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
ScheduleEditor *schededit = new ScheduleEditor(mainStack, record);
if (schededit->Create())
{
mainStack->AddScreen(schededit);
connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleCreated(int)));
}
else
delete schededit;
}
void CustomEdit::scheduleCreated(int ruleID)
{
if (ruleID > 0)
Close();
}
void CustomEdit::storeClicked(void)
{
bool exampleExists = false;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("SELECT rulename,whereclause FROM customexample "
"WHERE rulename = :RULE;");
query.bindValue(":RULE", m_titleEdit->GetText());
if (query.exec() && query.next())
exampleExists = true;
QString msg = QString("%1: %2\n\n").arg(tr("Current Example"))
.arg(m_titleEdit->GetText());
if (m_subtitleEdit->GetText().length())
msg += m_subtitleEdit->GetText() + "\n\n";
msg += m_descriptionEdit->GetText();
MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
MythDialogBox *storediag = new MythDialogBox(msg, mainStack,
"storePopup", true);
storediag->SetReturnEvent(this, "storeruledialog");
if (storediag->Create())
{
if (!m_titleEdit->GetText().isEmpty())
{
QString str;
// Keep strings whole for translation!
if (exampleExists)
str = tr("Replace as a search");
else
str = tr("Store as a search");
storediag->AddButton(str);
if (exampleExists)
str = tr("Replace as an example");
else
str = tr("Store as an example");
storediag->AddButton(str);
}
if (m_clauseList->GetCurrentPos() >= m_maxex)
{
MythUIButtonListItem* item = m_clauseList->GetItemCurrent();
QString str = QString("%1 \"%2\"").arg(tr("Delete"))
.arg(item->GetText());
storediag->AddButton(str);
}
mainStack->AddScreen(storediag);
}
else
delete storediag;
}
bool CustomEdit::checkSyntax(void)
{
bool ret = false;
QString msg;
QString desc = m_descriptionEdit->GetText();
QString from = m_subtitleEdit->GetText();
if (desc.contains(QRegExp("^\\s*AND\\s", Qt::CaseInsensitive)))
{
msg = tr("Power Search rules no longer require a leading \"AND\".");
}
else if (desc.contains(';'))
{
msg = tr("Power Search rules cannot include semicolon ( ; ) ");
msg += tr("statement terminators.");
}
else
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(QString("SELECT NULL FROM (program,channel) "
"%1 WHERE\n%2").arg(from).arg(desc));
if (query.exec())
{
ret = true;
}
else
{
msg = tr("An error was found when checking") + ":\n\n";
msg += query.executedQuery();
msg += "\n\n" + tr("The database error was") + ":\n";
msg += query.lastError().databaseText();
}
}
if (!msg.isEmpty())
{
MythScreenStack *popupStack = GetMythMainWindow()->
GetStack("popup stack");
MythConfirmationDialog *checkSyntaxPopup =
new MythConfirmationDialog(popupStack, msg, false);
if (checkSyntaxPopup->Create())
{
checkSyntaxPopup->SetReturnEvent(this, "checkSyntaxPopup");
popupStack->AddScreen(checkSyntaxPopup);
}
else
{
delete checkSyntaxPopup;
}
ret = false;
}
return ret;
}
void CustomEdit::storeRule(bool is_search, bool is_new)
{
CustomRuleInfo rule;
rule.recordid = '0';
rule.title = m_titleEdit->GetText();
rule.subtitle = m_subtitleEdit->GetText();
rule.description = m_descriptionEdit->GetText();
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("REPLACE INTO customexample "
"(rulename,fromclause,whereclause,search) "
"VALUES(:RULE,:FROMC,:WHEREC,:SEARCH);");
query.bindValue(":RULE", rule.title);
query.bindValue(":FROMC", rule.subtitle);
query.bindValue(":WHEREC", rule.description);
query.bindValue(":SEARCH", is_search);
if (is_search)
rule.title += m_seSuffix;
else
rule.title += m_exSuffix;
if (!query.exec())
MythDB::DBError("Store custom example", query);
else if (is_new)
{
new MythUIButtonListItem(m_clauseList, rule.title,
qVariantFromValue(rule));
}
else
{
/* Modify the existing entry. We know one exists from the database
search but do not know its position in the clause list. It may
or may not be the current item. */
for (int i = m_maxex; i < m_clauseList->GetCount(); i++)
{
MythUIButtonListItem* item = m_clauseList->GetItemAt(i);
QString removedStr = item->GetText().remove(m_seSuffix)
.remove(m_exSuffix);
if (m_titleEdit->GetText() == removedStr)
{
item->SetData(qVariantFromValue(rule));
clauseChanged(item);
break;
}
}
}
}
void CustomEdit::deleteRule(void)
{
MythUIButtonListItem* item = m_clauseList->GetItemCurrent();
if (!item || m_clauseList->GetCurrentPos() < m_maxex)
return;
MSqlQuery query(MSqlQuery::InitCon());
query.prepare("DELETE FROM customexample "
"WHERE rulename = :RULE;");
query.bindValue(":RULE", item->GetText().remove(m_seSuffix)
.remove(m_exSuffix));
if (!query.exec())
MythDB::DBError("Delete custom example", query);
else
{
m_clauseList->RemoveItem(item);
}
}
void CustomEdit::customEvent(QEvent *event)
{
if (event->type() == DialogCompletionEvent::kEventType)
{
DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);
QString resultid = dce->GetId();
QString resulttext = dce->GetResultText();
if (resultid == "storeruledialog")
{
if (resulttext.startsWith(tr("Delete")))
{
deleteRule();
}
else if (!resulttext.isEmpty())
{
storeRule(resulttext.contains(tr("as a search")),
!resulttext.startsWith(tr("Replace")));
}
}
}
}
bool CustomEdit::keyPressEvent(QKeyEvent *event)
{
if (GetFocusWidget()->keyPressEvent(event))
return true;
bool handled = false;
QStringList actions;
handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
handled = true;
if (action == "DELETE")
{
if (GetFocusWidget() == m_clauseList)
deleteRule();
// else if (GetFocusWidget() == m_ruleList)
// deleteRecordingRule();
}
else
handled = false;
}
if (!handled && MythScreenType::keyPressEvent(event))
handled = true;
return handled;
}