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_searchtemplate.h" |
30 | #include "epgsearchtools.h" |
31 | #include "epgsearchcfg.h" |
32 | #include "recdone.h" |
33 | #include "menu_templateedit.h" |
34 | #include "menu_searchactions.h" |
35 | |
36 | using namespace std; |
37 | |
38 | |
39 | class cMenuSearchTemplateItem : public cOsdItem { |
40 | private: |
41 | public: |
42 | cSearchExt* searchExt; |
43 | cMenuSearchTemplateItem(cSearchExt* SearchExt); |
44 | int Compare(const cListObject &ListObject) const; |
45 | void Set(void); |
46 | }; |
47 | |
48 | cMenuSearchTemplateItem::cMenuSearchTemplateItem(cSearchExt* SearchExt) |
49 | { |
50 | searchExt = SearchExt; |
51 | Set(); |
| 1 | Calling 'cMenuSearchTemplateItem::Set' | |
|
52 | } |
53 | |
54 | void cMenuSearchTemplateItem::Set(void) |
55 | { |
56 | ostringstream line; |
57 | |
58 | if (searchExt->ID == EPGSearchConfig.DefSearchTemplateID) |
| |
59 | line << "*"; |
60 | else if (searchExt->useAsSearchTimer) |
| |
61 | { |
62 | if (searchExt->IsActiveAt(time(NULL__null))) |
63 | line << ">"; |
64 | else |
65 | line << "!"; |
66 | } |
67 | |
68 | line << "\t"; |
69 | if (searchExt->search && strlen(searchExt->search) > 0) |
| |
70 | line << setiosflags(ios::left) << string(searchExt->search); |
71 | else |
72 | line << setiosflags(ios::left) << "*"; |
73 | |
74 | line << "\t"; |
75 | if (searchExt->useChannel == 1) |
| |
76 | { |
77 | if (searchExt->channelMin != searchExt->channelMax) |
78 | line << setiosflags(ios::left) << searchExt->channelMin->Number() << " - " << searchExt->channelMax->Number(); |
79 | else |
80 | line << setiosflags(ios::left) << setw(11) << (searchExt->useChannel?CHANNELNAME(searchExt->channelMin)(searchExt->channelMin ? searchExt->channelMin->ShortName (true) : ""):""); |
81 | } |
82 | else if (searchExt->useChannel == 2) |
| |
83 | line << setiosflags(ios::left) << setw(11) << searchExt->channelGroup; |
84 | |
85 | line << "\t"; |
86 | if (searchExt->useTime) |
| |
87 | { |
88 | ostringstream timeline; |
89 | timeline << setfill('0') << setw(2) << searchExt->startTime / 100 << ":" << setw(2) << searchExt->startTime % 100; |
90 | timeline << "\t"; |
91 | timeline << setfill('0') << setw(2) << searchExt->stopTime / 100 << ":" << setw(2) << searchExt->stopTime % 100; |
92 | line << timeline.str(); |
93 | } |
94 | else |
95 | line << "--:--\t--:--"; |
96 | |
97 | SetText(strdup(line.str().c_str()), false); |
| |
98 | } |
| |
99 | |
100 | int cMenuSearchTemplateItem::Compare(const cListObject &ListObject) const |
101 | { |
102 | cMenuSearchTemplateItem *p = (cMenuSearchTemplateItem *)&ListObject; |
103 | return strcasecmp(searchExt->search, p->searchExt->search); |
104 | } |
105 | |
106 | |
107 | cMenuEPGSearchTemplate::cMenuEPGSearchTemplate(cSearchExt* Search, cBlacklist* Blacklist, bool New) |
108 | :cOsdMenu(tr("Search templates")I18nTranslate("Search templates", "vdr-" "epgsearch"), 2, 20, 11, 6, 5) |
109 | { |
110 | #if VDRVERSNUM20005 >= 10728 |
111 | SetMenuCategory(mcPlugin); |
112 | #endif |
113 | search = Search; |
114 | blacklist = Blacklist; |
115 | newSearch = New; |
116 | cMutexLock SearchTemplatesLock(&SearchTemplates); |
117 | cSearchExt *SearchExt = SearchTemplates.First(); |
118 | while (SearchExt) { |
119 | Add(new cMenuSearchTemplateItem(SearchExt)); |
120 | SearchExt = SearchTemplates.Next(SearchExt); |
121 | } |
122 | SetHelp(trVDR("Button$Edit")I18nTranslate("Button$Edit"), trVDR("Button$New")I18nTranslate("Button$New"), trVDR("Button$Delete")I18nTranslate("Button$Delete"), tr("Button$Default")I18nTranslate("Button$Default", "vdr-" "epgsearch")); |
123 | Sort(); |
124 | Display(); |
125 | |
126 | } |
127 | |
128 | cSearchExt *cMenuEPGSearchTemplate::CurrentSearchTemplate(void) |
129 | { |
130 | cMenuSearchTemplateItem *item = (cMenuSearchTemplateItem *)Get(Current()); |
131 | return item ? item->searchExt : NULL__null; |
132 | } |
133 | |
134 | eOSState cMenuEPGSearchTemplate::New(void) |
135 | { |
136 | if (HasSubMenu()) |
137 | return osContinue; |
138 | return AddSubMenu(new cMenuEditTemplate(new cSearchExt, true)); |
139 | } |
140 | |
141 | eOSState cMenuEPGSearchTemplate::Delete(void) |
142 | { |
143 | cSearchExt *curSearchExt = CurrentSearchTemplate(); |
144 | if (curSearchExt) { |
145 | if (Interface->Confirm(tr("Edit$Delete template?")I18nTranslate("Edit$Delete template?", "vdr-" "epgsearch"))) { |
146 | cMutexLock SearchTemplatesLock(&SearchTemplates); |
147 | SearchTemplates.Del(curSearchExt); |
148 | SearchTemplates.Save(); |
149 | cOsdMenu::Del(Current()); |
150 | Display(); |
151 | } |
152 | } |
153 | return osContinue; |
154 | } |
155 | |
156 | eOSState cMenuEPGSearchTemplate::DefaultTemplate(void) |
157 | { |
158 | if (HasSubMenu()) |
159 | return osContinue; |
160 | cSearchExt *curSearchExt = CurrentSearchTemplate(); |
161 | |
162 | int current = Current(); |
163 | cMenuSearchTemplateItem *oldDefaultTemplateItem = NULL__null; |
164 | for(int i=0; i<Count(); i++) |
165 | { |
166 | cMenuSearchTemplateItem *item = (cMenuSearchTemplateItem *)Get(i); |
167 | if (item && item->searchExt && item->searchExt->ID == EPGSearchConfig.DefSearchTemplateID) |
168 | oldDefaultTemplateItem = item; |
169 | } |
170 | |
171 | if (curSearchExt) |
172 | { |
173 | if (EPGSearchConfig.DefSearchTemplateID == curSearchExt->ID) |
174 | EPGSearchConfig.DefSearchTemplateID = -1; |
175 | else |
176 | EPGSearchConfig.DefSearchTemplateID = curSearchExt->ID; |
177 | cPluginManager::GetPlugin("epgsearch")->SetupStore("DefSearchTemplateID", EPGSearchConfig.DefSearchTemplateID); |
178 | |
179 | SetCurrent(oldDefaultTemplateItem); |
180 | RefreshCurrent(); |
181 | DisplayCurrent(true); |
182 | |
183 | SetCurrent(Get(current)); |
184 | RefreshCurrent(); |
185 | DisplayCurrent(true); |
186 | |
187 | Display(); |
188 | } |
189 | return osContinue; |
190 | } |
191 | |
192 | eOSState cMenuEPGSearchTemplate::ProcessKey(eKeys Key) |
193 | { |
194 | int SearchNumber = HasSubMenu() ? Count() : -1; |
195 | eOSState state = cOsdMenu::ProcessKey(Key); |
196 | if (state == osUnknown) { |
197 | if (HasSubMenu()) |
198 | return osContinue; |
199 | switch (Key) { |
200 | case kOk: |
201 | { |
202 | if (search) |
203 | { |
204 | if (!newSearch && !Interface->Confirm(tr("Overwrite existing entries?")I18nTranslate("Overwrite existing entries?", "vdr-" "epgsearch" ))) |
205 | return osBack; |
206 | |
207 | cSearchExt* t =CurrentSearchTemplate(); |
208 | if (!t) return osContinue; |
209 | |
210 | search->CopyFromTemplate(t); |
211 | } |
212 | if (blacklist) |
213 | { |
214 | if (!newSearch && !Interface->Confirm(tr("Overwrite existing entries?")I18nTranslate("Overwrite existing entries?", "vdr-" "epgsearch" ))) |
215 | return osBack; |
216 | |
217 | cSearchExt* t =CurrentSearchTemplate(); |
218 | if (!t) return osContinue; |
219 | |
220 | blacklist->CopyFromTemplate(t); |
221 | } |
222 | return osBack; |
223 | } |
224 | case kRed: |
225 | if (CurrentSearchTemplate()) |
226 | state = AddSubMenu(new cMenuEditTemplate(CurrentSearchTemplate())); |
227 | else |
228 | state = osContinue; |
229 | break; |
230 | case kGreen: state = New(); break; |
231 | case kYellow: state = Delete(); break; |
232 | case kBlue: state = DefaultTemplate(); break; |
233 | default: break; |
234 | } |
235 | } |
236 | if (SearchNumber >= 0 && !HasSubMenu()) |
237 | { |
238 | cSearchExt* search = SearchTemplates.Get(SearchNumber); |
239 | if (search) |
240 | Add(new cMenuSearchTemplateItem(search)); |
241 | else |
242 | search = CurrentSearchTemplate(); |
243 | |
244 | Sort(); |
245 | for(int i=0; i<Count(); i++) |
246 | { |
247 | cMenuSearchTemplateItem *item = (cMenuSearchTemplateItem *)Get(i); |
248 | if (item) |
249 | { |
250 | item->Set(); |
251 | if (item->searchExt == search) |
252 | SetCurrent(item); |
253 | } |
254 | } |
255 | Display(); |
256 | } |
257 | |
258 | return state; |
259 | } |