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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
|
/**
* GraphTFT plugin for the Video Disk Recorder
*
* theme.h - A plugin for the Video Disk Recorder
*
* (c) 2004 Lars Tegeler, Sascha Volkenandt
* (c) 2006-2013 Jörg Wendel
*
* This code is distributed under the terms and conditions of the
* GNU GENERAL PUBLIC LICENSE. See the file COPYING for details.
**/
#ifndef __GTFT_THEME_H
#define __GTFT_THEME_H
#include <errno.h>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <vdr/tools.h>
#include <vdr/config.h>
#include <common.h>
#include <renderer.h>
#include <string>
#define SECONDS(x) (((uint64_t)x)*1000)
using std::string;
using std::map;
class cDisplayItem;
class cGraphTFTDisplay;
class cThemeSection;
//***************************************************************************
// Variable Provider
//***************************************************************************
class VariableProvider
{
public:
VariableProvider() {};
virtual ~VariableProvider() {};
virtual string channelLogoPath(const char* channel,
const char* format = 0, int classic = yes);
virtual int variableOf(string& name, const char* expression, char*& e);
virtual int evaluate(string& buf, const char* var);
virtual const char* splitFormatValue(const char* data,
char* value, char* format);
virtual int lookupVariable(const char* name, string& value,
const char* fmt = 0) = 0;
int calcExpression(const char* expression);
int calc(const char* op, int left, int right);
};
//***************************************************************************
// Theme Service
//***************************************************************************
class cThemeService
{
public:
enum ReplayMode
{
rmUnknown = na,
rmPlay,
rmForward,
rmSpeed
};
enum ItemUnit
{
iuUnknown = na,
iuAbsolute,
iuRelative,
iuPercent
};
enum ConditionArgumentType
{
catUnknown,
catInteger,
catString
};
enum MenuItemType
{
itNormal,
itPartingLine
};
// groups
enum eThmeGroup
{
groupUnknown = 1,
groupChannel = 2,
groupVolume = 4,
groupButton = 8,
groupRecording = 16,
groupReplay = 32,
groupMessage = 64,
groupMenu = 128,
groupMusic = 256,
groupTextList = 512,
groupCalibrate = 1024,
groupVarFile = 2048,
groupAll = 0xFFFF
};
// items
enum ItemKind
{
itemUnknown = na,
itemSectionInclude, // = 0
itemTheme,
itemBegin, // = 2
itemText = itemBegin, // = 2
itemImage, // = 3
itemImageFile,
itemImageDir,
itemRectangle, // = 5
itemTimebar,
itemMessage,
itemVolumeMuteSymbol,
itemVolumebar,
itemMenu,
itemMenuSelected,
itemMenuButton,
itemMenuButtonRed = itemMenuButton, // =
itemMenuButtonGreen,
itemMenuButtonYellow,
itemMenuButtonBlue,
itemMenuButtonBackground, // =
itemMenuButtonBackgroundRed = itemMenuButtonBackground, // =
itemMenuButtonBackgroundGreen,
itemMenuButtonBackgroundYellow,
itemMenuButtonBackgroundBlue,
itemMenuImageMap, // =
itemSpectrumAnalyzer,
itemPartingLine, // =
itemSysinfo,
itemBackground,
itemTextList,
itemProgressbar,
itemClickArea,
itemMenuNavigationArea,
itemCalibrationCursor,
itemColumn,
itemColumnSelected,
itemEventColumn,
itemEventColumnSelected,
itemDefaults,
itemVarFile,
itemCount
};
enum Misc
{
maxPathCount = 10
};
enum Align
{
algLeft,
algCenter,
algRight
};
enum ScrollModes
{
smOff,
smMarquee,
smTicker
};
struct Translation
{
int denum;
const char* name;
};
static int toDenum(Translation t[], const char* value);
static Translation alignments[];
static Translation scrollmodes[];
static const char* toName(ItemKind aItem);
static ItemKind toItem(const char* aName);
static int isValid(ItemKind aItem)
{ return aItem > itemUnknown && aItem < itemCount; }
static const char* items[itemCount+1];
};
typedef cThemeService Ts;
//***************************************************************************
// Class cThemeItem
// - represents a theme item
//***************************************************************************
class cThemeItem : public cListObject, public cThemeService, public VariableProvider
{
public:
struct cPath
{
string configured; // configured path
// path can contain a range [0-9], [3-99], ...
// used to support images like thumbnail_1.jpg
// in this case the following members are set ...
int curNum;
string last; // last path
};
cThemeItem();
virtual ~cThemeItem();
bool Parse(const char *s);
int parseDirectives(string& toParse);
int parseVariable(string& toParse, cThemeSection* section = 0);
virtual int init() { return done; }
//
int lookupVariable(const char* name, string& value, const char* fmt = 0);
int setVariable(const char* name, int value);
// statics
static cDisplayItem* newDisplayItem(int item);
// temporary buffer used by the parser ::Parse()
static cThemeSection* currentSection;
static string lineBuffer;
static string condition;
protected:
// functions
int ParseText(string toParse);
int ParseVar(string toParse, string name, int* value);
int ParseVarTime(string toParse, string name, uint64_t* value);
int ParseVar(string toParse, string name, string* value);
int ParseVarExt(string toParse, string name, string* value);
int ParseVarExt(string toParse, string name, int* value);
int ParseDirective(string toParse, string name, string* value);
int ParseVar(string toParse, string name, int* value, Translation t[]);
int ParseVarColor(string toParse, string name, string* value);
// item properties
int _item;
string _id;
string _debug;
string _sectionInclude;
string _area;
string _x;
string _y;
string _width;
string _height;
string _start_line;
int _overlay, _lines, _line, _size, _switch;
int _menu_x, _menu_y, _menu_width, _menu_height;
int _bg_x, _bg_y, _bg_width, _bg_height;
int _stat_pic, _stat_x, _stat_y, _image_map;
int _stat_text, _stat_width, _stat_height;
int _align, _align_v, _count;
int _number;
int _index, _spacing, _yspacing, _bar_height, _bar_height_unit;
int _scroll, _scroll_count, _dots;
int _permanent, _factor, _aspect_ratio, _fit, _foreground;
int _rotate;
int _whipe_res;
uint64_t _delay; // delay in ms
string _color;
string _bg_color;
string _value;
string _total;
string _unit;
string _reference;
string _onClick;
string _onDblClick;
string _onUp;
string _onDown;
string _font;
string _path;
string _focus;
string _path2;
string _type;
string _format;
string _text;
string _condition;
int pathCount;
cPath pathList[maxPathCount];
cThemeSection* section; // my section
};
//***************************************************************************
// Display Items
//***************************************************************************
class cDisplayItem : public cThemeItem
{
public:
cDisplayItem();
virtual ~cDisplayItem();
// functions
virtual const char* nameOf() { return toName((ItemKind)_item); }
virtual int groupOf() { return groupUnknown; }
virtual int isOfGroup(int g) { return groupOf() & g; }
int useVarOf(const char* varPart)
{ return strstr(_text.c_str(), varPart) || strstr(_path.c_str(), varPart) || strstr(_condition.c_str(), varPart); }
virtual int draw();
virtual int refresh();
virtual int reset();
// virtual string channelLogoPath(const char* channel, int classic = yes);
virtual int drawText(const char* text, int y = 0,
int height = na, int clear = yes,
int skipLines = 0);
virtual int drawRectangle();
virtual int drawBackRect(int y = 0, int height = 0);
virtual int drawImage(const char* path = 0, int fit = na,
int aspectRatio = na, int noBack = no);
virtual int drawImageOnBack(const char* path, int fit = no, int height = na);
virtual int drawProgressBar(double current, double total,
string path, int y = na,
int height = na,
int withFrame = yes, int clear = yes);
virtual int drawPartingLine(string text, int y, int height);
virtual void setBackgroundItem(cDisplayItem* p) { backgroundItem = p; }
virtual void setNextDraw() { nextDraw = msNow(); }
virtual uint64_t getNextDraw() { return nextDraw; }
virtual int isForegroundItem() { return no; }
void scheduleDrawAt(uint64_t aTime);
void scheduleDrawIn(int aTime);
void scheduleDrawNextFullMinute();
void setSection(cThemeSection* s) { section = s; }
// statics
static void scheduleForce(uint64_t aTime);
static void clearSelectedItem() { selectedItem = 0; }
static void setForce(int flag) { forceDraw = flag; }
static int getForce() { return forceDraw; }
static void setRenderer(Renderer* aRender) { render = aRender; }
static void setVdrStatus(cGraphTFTDisplay* aVdrStatus) { vdrStatus = aVdrStatus; }
// Item getter/setter
int Item() { return _item; }
string Id() { return _id; }
string Area() { return _area; }
int Index(int value = na) { if (value != na) _index = value; return _index; }
int Changed() { return changed; }
void setStartLine(int value) { _start_line = Str::toStr(value); }
void setX(int value) { _x = Str::toStr(value); }
void setY(int value) { _y = Str::toStr(value); }
void setWidth(int value) { _width = Str::toStr(value); }
int Number(int value = na) { if (value != na) _number = value; return _number; }
int StartLine() { return optionVariable(_start_line.c_str()); }
int X() { return optionVariable(_x.c_str()); }
int Y() { return optionVariable(_y.c_str()); }
int Width() { return optionVariable(_width.c_str()); }
int Height() { return optionVariable(_height.c_str()); }
// item options
int BgX() { return _bg_x; }
int BgY() { return _bg_y; }
int BgWidth() { return _bg_width; }
int BgHeight() { return _bg_height; }
int ImageMap() { return _image_map; }
int StaticPicture() { return _stat_pic; }
int StaticText() { return _stat_text; }
int StaticWidth() { return _stat_width; }
int StaticHeight() { return _stat_height; }
int StaticX() { return _stat_x; }
int StaticY() { return _stat_y; }
int Overlay() { return _overlay; }
int Lines() { return _lines; }
int Line() { return _line; }
int Size() { return _size; }
int Switch() { return _switch; }
int Align() { return _align; }
int AlignV() { return _align_v; }
uint64_t Delay() { return _delay; }
int Foreground() { return _foreground; }
int Count() { return _count; }
int Spacing() { return _spacing; }
int YSpacing() { return _yspacing; }
int BarHeight() { return _bar_height; }
int BarHeightUnit() { return _bar_height_unit; }
int Fit() { return _fit; }
int AspectRatio() { return _aspect_ratio; }
int Scroll() { return _scroll; }
int MenuX() { return _menu_x; }
int MenuY() { return _menu_y; }
int MenuWidth() { return _menu_width; }
int MenuHeight() { return _menu_height; }
int WhipeRes() { return _whipe_res; }
string Color() { return _color; }
string BgColor() { return _bg_color; }
string Value() { return _value; }
string Total() { return _total; }
string Font() { return _font; }
string Focus() { return _focus; }
string Path() { return _path; }
string Path2() { return _path2; }
string Type() { return _type; }
string Format() { return _format; }
string Text() { return _text; }
string OnClick() { return _onClick; }
string OnDblClick() { return _onDblClick; }
string OnUp() { return _onUp; }
string OnDown() { return _onDown; }
string Condition() { return _condition; }
string SectionInclude() { return _sectionInclude; }
string Debug() { return _debug; }
//
int optionVariable(const char* expression)
{
string p;
string name;
int min = -32000;
char* buffer = strdup(expression);
char* v;
// evaluate variable
if ((v = strchr(buffer, '/')))
{
*v = 0;
v++;
min = atoi(buffer);
}
else
v = buffer;
if (evaluate(p, v) == success)
{
int res = calcExpression(p.c_str());
if (logLevel > 2 && strchr(v, '{'))
tell(3, "evaluated '%s' to '%s', res is (%d)", v, p.c_str(), res);
free(buffer);
return max(min, res);
}
free(buffer);
return 0;
}
int evaluateCondition(int recurse = no);
p_rgba evaluateColor(const char* var, p_rgba rgba);
string evaluatePath();
int lookupVariable(const char* name, string& value, const char* fmt = 0);
int lineCount() { return actLineCount; }
protected:
const char* variable(const char* name, const char* fmt, int& status);
const char* musicVariable(const char* group, const char* var, const char* fmt, int& status);
const char* formatDateTime(time_t time, const char* fmt, char* date, int len, int absolut = no);
const char* formatString(const char* str, const char* fmt, char* buffer, int len);
int replayModeValue(ReplayMode rm);
int condition(int left, int right, const char* op);
int condition(string* left, string* right, const char* op);
int haveBackgroundItem() { return backgroundItem && backgroundItem->Path() != ""; }
// data
int changed;
uint64_t nextDraw;
cDisplayItem* backgroundItem;
int visible;
// scroll mode
int marquee_active;
int marquee_left;
int marquee_idx;
int marquee_count;
int marquee_strip;
uint64_t nextAnimationAt;
int actLineCount;
int lastConditionState;
int lastX;
int lastY;
int lastWidth;
int lastHeight;
// statics
static int forceDraw;
static Renderer* render;
static cGraphTFTDisplay* vdrStatus;
static cDisplayItem* selectedItem;
static uint64_t nextForce;
};
//***************************************************************************
// Variable File
//***************************************************************************
class cVariableFile : public cDisplayItem
{
public:
cVariableFile() : cDisplayItem() { lastUpdate = 0; _delay = 60 * 1000; }
int hasName(const char* name) { return _path == name; }
const char* getName() { return _path.c_str(); }
int lookupVar(string var, string& value)
{
string::size_type p;
string name, ns;
value = "";
if ((p = var.find(".")) == string::npos)
return fail;
ns = var.substr(0, p);
name = var.substr(p+1);
tell(5, "lookup file variable '%s.%s' in file '%s'",
ns.c_str(), name.c_str(), _path.c_str());
if (_path != ns)
return fail;
map<string,string>::iterator iter = variables.find(name);
if (iter != variables.end())
{
value = iter->second.c_str();
return success;
}
return fail;
}
int parse()
{
int status = ignore;
FILE* fp;
char line[500+TB]; *line = 0;
char *c, *p, *name;
char* value;
if (time(0) < lastUpdate + (time_t)_delay/1000)
return ignore;
variables.clear();
if (!(fp = fopen(_path2.c_str(), "r")))
{
tell(0, "Can't open '%s', error was '%s'", _path2.c_str(), strerror(errno));
return ignore;
}
while ((c = fgets(line, 500, fp)))
{
line[strlen(line)] = 0; // cut linefeed
if ((p = strstr(line, "//"))) // cut comments
*p = 0;
if ((p = strstr(line, ";"))) // cut line end
*p = 0;
// skip empty lines
Str::allTrim(line);
if (Str::isEmpty(line))
continue;
// check line, search value
if (!(name = strstr(line, "var ")) || !(value = strchr(line, '=')) || name >= value)
{
tell(0, "Info: Ignoring invalid line [%s] in '%s'", line, _path2.c_str());
continue;
}
name += strlen("var ");
*value = 0;
value++;
Str::allTrim(name);
Str::allTrim(value);
tell(4, "append variable '%s' with value '%s'", name, value);
variables[name] = value;
status = success;
}
fclose(fp);
lastUpdate = time(0);
return status;
}
protected:
map<string,string> variables;
time_t lastUpdate;
};
//***************************************************************************
// Display Items
//***************************************************************************
class cDisplayText : public cDisplayItem
{
public:
cDisplayText() { lastText = ""; }
int groupOf()
{
int group = groupUnknown;
if (useVarOf("{replay"))
group |= groupReplay;
if (useVarOf("{recording"))
group |= groupRecording;
if (useVarOf("{actRecording"))
group |= groupRecording;
if (useVarOf("{event"))
group |= groupChannel;
if (useVarOf("{present"))
group |= groupChannel;
if (useVarOf("{following"))
group |= groupChannel;
if (useVarOf("{videoSize"))
group |= groupChannel;
if (useVarOf("{channel"))
group |= groupChannel;
if (useVarOf("{volume"))
group |= groupVolume;
if (useVarOf("{calibration"))
group |= groupCalibrate;
group |= groupVarFile;
return group;
}
int draw();
protected:
string lastText;
};
class cDisplayImage : public cDisplayItem
{
public:
int groupOf()
{
int group = groupUnknown;
if (useVarOf("{replay"))
group |= groupReplay;
if (useVarOf("{recording"))
group |= groupRecording;
if (useVarOf("{actRecording"))
group |= groupRecording;
if (useVarOf("{event"))
group |= groupChannel;
if (useVarOf("{present"))
group |= groupChannel;
if (useVarOf("{following"))
group |= groupChannel;
if (useVarOf("{videoSize"))
group |= groupChannel;
if (useVarOf("{channel"))
group |= groupChannel;
if (useVarOf("{volume"))
group |= groupVolume;
if (useVarOf("{calibration"))
group |= groupCalibrate;
return group;
}
int draw();
};
class cDisplayTextList : public cDisplayItem
{
public:
int groupOf()
{
int group = groupTextList;
if (useVarOf("{music"))
group |= groupMusic;
if (useVarOf("{actTimers"))
group |= groupRecording;
return group;
}
int draw();
};
class cDisplayRectangle : public cDisplayItem
{
public:
int draw();
};
class cDisplayBackground : public cDisplayImage
{
public:
int groupOf() { return groupUnknown; }
int draw();
};
class cDisplayImageFile : public cDisplayItem
{
public:
int groupOf() { return groupReplay; }
int draw();
};
class cDisplayImageDir : public cDisplayItem
{
public:
// int groupOf() { return groupReplay; }
int init();
int draw();
protected:
struct ImageFile
{
int initialized;
std::string path;
unsigned int width;
unsigned int height;
unsigned int orientation;
unsigned int landscape;
};
int getNext(std::vector<ImageFile>::iterator& it, ImageFile*& file);
int scanDir(const char* path, int level = 0);
std::vector<ImageFile> images;
std::vector<ImageFile>::iterator current;
};
class cDisplayCalibrationCursor : public cDisplayItem
{
public:
int groupOf() { return groupCalibrate; }
int draw();
};
class cDisplayMenuButton : public cDisplayItem
{
public:
int groupOf() { return groupButton; }
int draw();
};
class cDisplayMenuButtonBackground : public cDisplayItem
{
public:
int groupOf() { return groupButton; }
int draw();
};
class cDisplayMessage : public cDisplayItem
{
public:
cDisplayMessage() : cDisplayItem() { visible = no; }
int groupOf() { return groupMessage; }
int isForegroundItem() { return yes; }
int draw();
};
class cDisplayVolumeMuteSymbol : public cDisplayItem
{
public:
cDisplayVolumeMuteSymbol() : cDisplayItem() { visible = no; }
int groupOf() { return groupVolume; }
int isForegroundItem() { return yes; }
int draw();
};
class cDisplayVolumebar : public cDisplayItem
{
public:
cDisplayVolumebar() : cDisplayItem() { visible = no; }
int groupOf() { return groupVolume; }
int isForegroundItem() { return yes; }
int draw();
};
class cDisplayTimebar : public cDisplayItem
{
public:
int groupOf() { return groupChannel; }
int draw();
};
class cDisplayProgressBar : public cDisplayItem
{
public:
int draw();
};
class cDisplaySymbol : public cDisplayItem
{
public:
int groupOf() { return groupChannel; }
int draw();
};
class cDisplayMenu : public cDisplayItem
{
public:
int draw();
};
class cDisplayMenuSelected : public cDisplayItem
{
public:
int draw();
};
class cDisplayMenuColumn : public cDisplayItem
{
public:
int groupOf() { return groupMenu; }
int draw();
};
class cDisplayMenuColumnSelected : public cDisplayItem
{
public:
int groupOf() { return groupMenu; }
int draw();
};
class cDisplayMenuEventColumn : public cDisplayItem
{
public:
int groupOf() { return groupMenu; }
int draw();
};
class cDisplayMenuEventColumnSelected : public cDisplayItem
{
public:
int groupOf() { return groupMenu; }
int draw();
};
class cDisplayPartingLine : public cDisplayItem
{
public:
int draw() { return cDisplayItem::draw(); }
};
class cDisplaySpectrumAnalyzer : public cDisplayItem
{
public:
int draw();
};
class cDisplaySysinfo : public cDisplayItem
{
public:
int draw();
protected:
int lastCpuLoad;
unsigned long lastUsedMem;
unsigned long lastUsedDisk;
};
//***************************************************************************
// Lists
//***************************************************************************
//***************************************************************************
// Theme Items
//***************************************************************************
class cDisplayItems : public cList<cDisplayItem>
{
public:
cDisplayItem* getItemByKind(Ts::ItemKind k);
cDisplayItem* getItemById(const char* id);
};
//***************************************************************************
// Class cThemeSection
// - represents a section of a theme
//***************************************************************************
class cThemeSection : public cListObject, cThemeService
{
public:
cThemeSection(string aName = "unnamed") { name = aName; defaultsItem = 0; }
~cThemeSection() { if (defaultsItem) delete defaultsItem; }
string getName() { return name; }
cDisplayItems* getItems() { return &items; }
cDisplayItem* getItemByKind(ItemKind k) { return items.getItemByKind(k); }
cDisplayItem* getItemById(const char* id) { return items.getItemById(id); }
cDisplayItem* First() { return items.First(); }
cDisplayItem* Next(cDisplayItem* item) { return items.Next(item); }
void Ins(cDisplayItem* item, cDisplayItem* before = 0)
{ items.Ins(item, before); item->setSection(this); }
void Add(cDisplayItem* item, cDisplayItem* after = 0)
{ items.Add(item, after); }
cDisplayItem* getDefaultsItem() { return defaultsItem; }
void setDefaultsItem(cDisplayItem* item)
{
if (defaultsItem)
delete defaultsItem;
defaultsItem = item;
}
int lookupVar(string name, string& value)
{
value = "";
map<string,string>::iterator iter = variables.find(name);
if (iter != variables.end())
{
value = iter->second.c_str();
return success;
}
if (varFiles.size())
{
string::size_type p;
if ((p = name.find(".")) == string::npos)
return fail;
map<string,cVariableFile*>::iterator itFile = varFiles.find(name.substr(0, p));
if (itFile != varFiles.end())
{
if (itFile->second->lookupVar(name, value) == success)
return success;
}
}
return fail;
}
uint64_t getNextUpdateTime();
int reset();
int updateGroup(int group);
void addVarFile(cDisplayItem* p)
{
cVariableFile* pp = (cVariableFile*)p;
varFiles[pp->getName()] = pp;
}
int hasVarFile(const char* name)
{
return varFiles.find(name) != varFiles.end();
}
map<string,cVariableFile*>* getVarFiles()
{
return &varFiles;
}
int updateVariables();
map<string,string> variables;
protected:
string name;
cDisplayItems items;
cDisplayItem* defaultsItem; // Item holding default values
map<string,cVariableFile*> varFiles;
};
//***************************************************************************
// Class cThemeSections
// - holding all sections
//***************************************************************************
class cThemeSections : public cList<cThemeSection>
{
public:
cThemeSection* getSection(string name);
};
//***************************************************************************
// Class cGraphTFTTheme
// - holding all Items included in the theme configuration file
//***************************************************************************
class cGraphTFTTheme : public cConfig<cThemeItem>, public cListObject, cThemeService
{
public:
cGraphTFTTheme();
virtual ~cGraphTFTTheme() { exit(); }
// functions
int init();
int exit();
int activate(int fdInotify);
int deactivate(int fdInotify);
int check(const char* theVersion);
int load(const char* path);
int checkViewMode();
// get
string getName() { return name; }
string getThemeVersion() { return themeVersion; }
string getSyntaxVersion() { return syntaxVersion; }
string getDir() { return dir; }
string getStartImage() { return startImage; }
string getEndImage() { return endImage; }
int getWidth() { return width; }
int getHeight() { return height; }
string getFontPath() { return fontPath; }
int isInitialized() { return initialized; }
// set
void setName(string aValue) { name = aValue; }
void setThemeVersion(string aValue) { themeVersion = aValue; }
void setSyntaxVersion(string aValue) { syntaxVersion = aValue; }
void setDir(string aValue) { dir = aValue; }
void setStartImage(string aValue) { startImage = aValue; }
void setEndImage(string aValue) { endImage = aValue; }
void setWidth(int aValue) { width = aValue; }
void setHeight(int aValue) { height = aValue; }
void setFontPath(string aValue) { fontPath = aValue; }
void AddMapItem(cDisplayItem* item, cDisplayItem* after = 0)
{ mapSection.Add(item, after); }
//
void addNormalSection(string section);
const char* getNormalMode(const char* modeName);
const char* nextNormalMode(const char* modeName);
const char* prevNormalMode(const char* modeName);
char** getNormalSections() { return normalModes; }
int getNormalSectionsCount() { return normalModesCount; }
// the sections
cThemeSection* getSection(string name) { return sections.getSection(name); }
cThemeSections* getSections() { return §ions; }
cThemeSection* FirstSection()
{ return sections.First(); }
cThemeSection* NextSection(cThemeSection* sect)
{ return sections.Next(sect); }
string getPathFromImageMap(const char* name);
void resetDefines() { defineCount = 0; clearIfdefs();}
void clearIfdefs() { while (!skipContent.empty()) skipContent.pop(); }
int isSkipContent() { return !skipContent.empty() && skipContent.top(); }
int lookupVar(string name, string& value)
{
value = "";
map<string,string>::iterator iter;
iter = menuVariables.find(name);
if (iter != menuVariables.end())
{
value = iter->second.c_str();
return success;
}
iter = variables.find(name);
if (iter != variables.end())
{
value = iter->second.c_str();
return success;
}
return fail;
}
// data
string defines[100];
int defineCount;
std::stack<int> skipContent;
map<string, string> variables;
map<string, string> menuVariables;
map<int, cDisplayItem*> inotifies;
protected:
// data
int width;
int height;
string dir;
string name;
string themeVersion;
string syntaxVersion;
string startImage;
string endImage;
string fontPath;
int initialized;
cThemeSections sections;
cThemeSection mapSection;
char* normalModes[100];
int normalModesCount;
};
//***************************************************************************
// Class cGraphTFTThemes
// - holding all themes
//***************************************************************************
class cGraphTFTThemes : public cList<cGraphTFTTheme>
{
public:
cGraphTFTTheme* getTheme(string aTheme);
static cGraphTFTTheme* theTheme;
protected:
};
//***************************************************************************
//
//***************************************************************************
typedef cGraphTFTThemes Thms;
//***************************************************************************
// External
//***************************************************************************
extern cGraphTFTThemes themes;
//***************************************************************************
#endif //__GTFT_THEME_H
|