1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | #include <vector> |
25 | #include <string> |
26 | #include <iomanip> |
27 | #include <sstream> |
28 | |
29 | #include "menu_blacklists.h" |
30 | #include "epgsearchtools.h" |
31 | #include "menu_blacklistedit.h" |
32 | #include "epgsearchcfg.h" |
33 | #include "menu_searchresults.h" |
34 | |
35 | using namespace std; |
36 | |
37 | |
38 | class cMenuBlacklistsItem : public cOsdItem { |
39 | private: |
40 | public: |
41 | cBlacklist* blacklist; |
42 | cMenuBlacklistsItem(cBlacklist* Blacklist); |
43 | int Compare(const cListObject &ListObject) const; |
44 | void Set(void); |
45 | }; |
46 | |
47 | cMenuBlacklistsItem::cMenuBlacklistsItem(cBlacklist* Blacklist) |
48 | { |
49 | blacklist = Blacklist; |
50 | Set(); |
| 1 | Calling 'cMenuBlacklistsItem::Set' | |
|
51 | } |
52 | |
53 | void cMenuBlacklistsItem::Set(void) |
54 | { |
55 | ostringstream line; |
56 | |
57 | if (blacklist->isGlobal != 0) |
| |
58 | line << setiosflags(ios::left) << "G"; |
59 | line << "\t"; |
60 | |
61 | if (blacklist->search && strlen(blacklist->search) > 0) |
| |
62 | line << setiosflags(ios::left) << string(blacklist->search); |
63 | else |
64 | line << setiosflags(ios::left) << "*"; |
65 | |
66 | line << "\t"; |
67 | if (blacklist->useChannel == 1) |
| |
68 | { |
69 | if (blacklist->channelMin != blacklist->channelMax) |
70 | line << setiosflags(ios::left) << blacklist->channelMin->Number() << " - " << blacklist->channelMax->Number(); |
71 | else |
72 | line << setiosflags(ios::left) << setw(11) << (blacklist->useChannel?CHANNELNAME(blacklist->channelMin)(blacklist->channelMin ? blacklist->channelMin->ShortName (true) : ""):""); |
73 | } |
74 | else if (blacklist->useChannel == 2) |
| |
75 | line << setiosflags(ios::left) << setw(11) << blacklist->channelGroup; |
76 | |
77 | line << "\t"; |
78 | if (blacklist->useTime) |
| |
79 | { |
80 | ostringstream timeline; |
81 | timeline << setfill('0') << setw(2) << blacklist->startTime / 100 << ":" << setw(2) << blacklist->startTime % 100; |
82 | timeline << "\t"; |
83 | timeline << setfill('0') << setw(2) << blacklist->stopTime / 100 << ":" << setw(2) << blacklist->stopTime % 100; |
84 | line << timeline.str(); |
85 | } |
86 | else |
87 | line << "--:--\t--:--"; |
88 | |
89 | SetText(strdup(line.str().c_str()), false); |
| |
90 | } |
| |
91 | |
92 | int cMenuBlacklistsItem::Compare(const cListObject &ListObject) const |
93 | { |
94 | cMenuBlacklistsItem *p = (cMenuBlacklistsItem *)&ListObject; |
95 | return strcasecmp(blacklist->search, p->blacklist->search); |
96 | } |
97 | |
98 | |
99 | cMenuBlacklists::cMenuBlacklists() |
100 | :cOsdMenu(tr("Blacklists")I18nTranslate("Blacklists", "vdr-" "epgsearch"), 3, 20, 11, 6, 5) |
101 | { |
102 | #if VDRVERSNUM20005 >= 10734 |
103 | SetMenuCategory(mcSetupPlugins); |
104 | #endif |
105 | cMutexLock BlacklistLock(&Blacklists); |
106 | cBlacklist *Blacklist = Blacklists.First(); |
107 | while (Blacklist) { |
108 | Add(new cMenuBlacklistsItem(Blacklist)); |
109 | Blacklist = Blacklists.Next(Blacklist); |
110 | } |
111 | SetHelp(trVDR("Button$Edit")I18nTranslate("Button$Edit"), trVDR("Button$New")I18nTranslate("Button$New"), trVDR("Button$Delete")I18nTranslate("Button$Delete"), NULL__null); |
112 | Sort(); |
113 | Display(); |
114 | |
115 | } |
116 | |
117 | cBlacklist *cMenuBlacklists::CurrentBlacklist(void) |
118 | { |
119 | cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(Current()); |
120 | if (item && Blacklists.Exists(item->blacklist)) |
121 | return item->blacklist; |
122 | return NULL__null; |
123 | } |
124 | |
125 | eOSState cMenuBlacklists::New(void) |
126 | { |
127 | if (HasSubMenu()) |
128 | return osContinue; |
129 | return AddSubMenu(new cMenuBlacklistEdit(new cBlacklist, true)); |
130 | } |
131 | |
132 | eOSState cMenuBlacklists::Delete(void) |
133 | { |
134 | cBlacklist *curBlacklist = CurrentBlacklist(); |
135 | if (curBlacklist) { |
136 | if (Interface->Confirm(tr("Edit$Delete blacklist?")I18nTranslate("Edit$Delete blacklist?", "vdr-" "epgsearch"))) { |
137 | LogFile.Log(1,"blacklist %s (%d) deleted", curBlacklist->search, curBlacklist->ID); |
138 | SearchExts.RemoveBlacklistID(curBlacklist->ID); |
139 | cMutexLock BlacklistLock(&Blacklists); |
140 | Blacklists.Del(curBlacklist); |
141 | Blacklists.Save(); |
142 | cOsdMenu::Del(Current()); |
143 | Display(); |
144 | } |
145 | } |
146 | return osContinue; |
147 | } |
148 | |
149 | eOSState cMenuBlacklists::ProcessKey(eKeys Key) |
150 | { |
151 | int BlacklistNumber = HasSubMenu() ? Count() : -1; |
152 | eOSState state = cOsdMenu::ProcessKey(Key); |
153 | if (state == osUnknown) { |
154 | if (HasSubMenu()) |
155 | return osContinue; |
156 | switch (Key) { |
157 | case kOk: |
158 | return AddSubMenu(new cMenuSearchResultsForBlacklist(CurrentBlacklist())); |
159 | break; |
160 | case kRed: |
161 | if (CurrentBlacklist()) |
162 | state = AddSubMenu(new cMenuBlacklistEdit(CurrentBlacklist())); |
163 | else |
164 | state = osContinue; |
165 | break; |
166 | case kGreen: state = New(); break; |
167 | case kYellow: state = Delete(); break; |
168 | default: break; |
169 | } |
170 | } |
171 | if (BlacklistNumber >= 0 && !HasSubMenu()) |
172 | { |
173 | cMutexLock BlacklistLock(&Blacklists); |
174 | cBlacklist* Blacklist = Blacklists.Get(BlacklistNumber); |
175 | if (Blacklist) |
176 | Add(new cMenuBlacklistsItem(Blacklist)); |
177 | |
178 | Sort(); |
179 | for(int i=0; i<Count(); i++) |
180 | { |
181 | cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(i); |
182 | if (item) |
183 | { |
184 | item->Set(); |
185 | if (item->blacklist == Blacklist) |
186 | SetCurrent(item); |
187 | } |
188 | } |
189 | Display(); |
190 | } |
191 | |
192 | return state; |
193 | } |