Ticket #9849: azselector.patch

File azselector.patch, 10.9 KB (added by tobias@…, 15 years ago)

Patch for playbackbox.cpp & .h

Line 
1diff -crB mythfrontend//playbackbox.cpp /daten/mythfrontend//playbackbox.cpp
2*** mythfrontend//playbackbox.cpp 2011-02-18 04:30:17.000000000 +0100
3--- /daten/mythfrontend//playbackbox.cpp 2011-06-17 00:55:40.324032891 +0200
4***************
5*** 35,40 ****
6--- 35,48 ----
7 #include "util.h"
8 #include "tv.h"
9
10+ // MythUI
11+ #include "mythuitext.h"
12+ #include "mythuibuttonlist.h"
13+ #include "mythuibutton.h"
14+ #include "mythuihelper.h"
15+ #include "mythscreenstack.h"
16+ #include "mythmainwindow.h"
17+
18 // Mythfrontend
19 #include "playbackboxlistitem.h"
20 #include "customedit.h"
21***************
22*** 356,362 ****
23 m_needUpdate(false),
24 // Other
25 m_player(NULL),
26! m_helper(this)
27 {
28 for (uint i = 0; i < sizeof(m_artImage) / sizeof(MythUIImage*); i++)
29 {
30--- 364,373 ----
31 m_needUpdate(false),
32 // Other
33 m_player(NULL),
34! m_helper(this),
35!
36! // A-Z Selector
37! m_alphabetList(NULL)
38 {
39 for (uint i = 0; i < sizeof(m_artImage) / sizeof(MythUIImage*); i++)
40 {
41***************
42*** 455,460 ****
43--- 466,488 ----
44 }
45 }
46
47+ void PlaybackBox::initAlphabetList(void)
48+ {
49+ // A-Z
50+ for (int charNum = 65; charNum < 91; ++charNum)
51+ {
52+ new MythUIButtonListItem(m_alphabetList, QString((char)charNum));
53+ }
54+ // 0-9
55+ for (int charNum = 48; charNum < 58; ++charNum)
56+ {
57+ new MythUIButtonListItem(m_alphabetList, QString((char)charNum));
58+ }
59+ // @
60+ new MythUIButtonListItem(m_alphabetList, QString('@'));
61+ }
62+
63+
64 bool PlaybackBox::Create()
65 {
66 if (m_type == kDeleteBox &&
67***************
68*** 464,469 ****
69--- 492,500 ----
70 if (!LoadWindowFromXML("recordings-ui.xml", "watchrecordings", this))
71 return false;
72
73+ // Add A-Z Selector
74+ // UIUtilE::Assign(this, m_alphabetList, "alphabet");
75+ m_alphabetList = dynamic_cast<MythUIButtonList *> (GetChild("alphabet"));
76 m_recgroupList = dynamic_cast<MythUIButtonList *> (GetChild("recgroups"));
77 m_groupList = dynamic_cast<MythUIButtonList *> (GetChild("groups"));
78 m_recordingList = dynamic_cast<MythUIButtonList *> (GetChild("recordings"));
79***************
80*** 495,500 ****
81--- 526,536 ----
82 SLOT(PlayFromBookmark(MythUIButtonListItem*)));
83 connect(m_recordingList, SIGNAL(itemVisible(MythUIButtonListItem*)),
84 SLOT(ItemVisible(MythUIButtonListItem*)));
85+
86+ connect(m_alphabetList, SIGNAL(itemSelected(MythUIButtonListItem*)),
87+ SLOT(UpdateUIGroupList(MythUIButtonListItem*)));
88+ connect(m_alphabetList, SIGNAL(itemClicked(MythUIButtonListItem*)),
89+ SLOT(SwitchList()));
90
91 // connect up timers...
92 connect(m_artTimer[kArtworkFan], SIGNAL(timeout()), SLOT(fanartLoad()));
93***************
94*** 537,542 ****
95--- 573,582 ----
96
97 if (!gCoreContext->GetNumSetting("PlaybackBoxStartInTitle", 0))
98 SetFocusWidget(m_recordingList);
99+
100+ // Init Alphabet
101+ initAlphabetList();
102+
103 }
104
105 void PlaybackBox::SwitchList()
106***************
107*** 545,550 ****
108--- 585,592 ----
109 SetFocusWidget(m_recordingList);
110 else if (GetFocusWidget() == m_recordingList)
111 SetFocusWidget(m_groupList);
112+ else if (GetFocusWidget() == m_alphabetList)
113+ SetFocusWidget(m_groupList);
114 }
115
116 void PlaybackBox::displayRecGroup(const QString &newRecGroup)
117***************
118*** 581,590 ****
119 }
120
121 void PlaybackBox::updateGroupInfo(const QString &groupname,
122! const QString &grouplabel)
123 {
124 InfoMap infoMap;
125 int countInGroup;
126
127 if (groupname.isEmpty())
128 {
129--- 623,635 ----
130 }
131
132 void PlaybackBox::updateGroupInfo(const QString &groupname,
133! const QString &grouplabel,
134! MythUIButtonListItem *sel_item)
135!
136 {
137 InfoMap infoMap;
138 int countInGroup;
139+ QString desc;
140
141 if (groupname.isEmpty())
142 {
143***************
144*** 595,605 ****
145 }
146 else
147 {
148! countInGroup = m_progLists[groupname].size();
149! infoMap["title"] = QString("%1 - %2").arg(m_groupDisplayName)
150! .arg(grouplabel);
151! infoMap["group"] = m_groupDisplayName;
152! infoMap["show"] = grouplabel;
153 }
154
155 if (m_artImage[kArtworkFan])
156--- 640,675 ----
157 }
158 else
159 {
160! if (GetFocusWidget() == m_alphabetList)
161! {
162! countInGroup = m_groupList->GetCount();
163! infoMap["title"] = "Display Group(s) with specific inital letter";
164! infoMap["group"] = "group";
165! infoMap["show"] = "show";
166!
167! QChar alphabetName = sel_item->GetText().at(0);
168! QString complete = "There is/are ";
169! QString temp2 = " display group(s) starting with ";
170! QString temp1;
171! temp1.setNum(countInGroup);
172! complete.append(temp1);
173! complete.append(temp2);
174! complete.append(alphabetName);
175!
176! desc = complete;
177!
178! }
179! else
180! {
181! countInGroup = m_progLists[groupname].size();
182! infoMap["title"] = QString("%1").arg(grouplabel);
183! infoMap["group"] = m_groupDisplayName;
184! infoMap["show"] = grouplabel;
185!
186! desc = tr("There is/are %n recording(s) in this display group", "", countInGroup);
187!
188!
189! }
190 }
191
192 if (m_artImage[kArtworkFan])
193***************
194*** 631,639 ****
195 }
196 }
197
198- QString desc = tr("There is/are %n recording(s) in this display group",
199- "", countInGroup);
200-
201 if (m_type == kDeleteBox && countInGroup > 1)
202 {
203 ProgramList group = m_progLists[groupname];
204--- 701,706 ----
205***************
206*** 1194,1202 ****
207
208 item->SetText(groupname, "name");
209 item->SetText(groupname);
210
211! int count = m_progLists[groupname.toLower()].size();
212! item->SetText(QString::number(count), "reccount");
213 }
214
215 m_needUpdate = true;
216--- 1261,1272 ----
217
218 item->SetText(groupname, "name");
219 item->SetText(groupname);
220+
221+ int count = m_progLists[groupname.toLower()].size();
222+ item->SetText(QString::number(count), "reccount");
223
224!
225!
226 }
227
228 m_needUpdate = true;
229***************
230*** 1208,1223 ****
231 updateRecList(m_groupList->GetItemCurrent());
232 }
233 }
234
235 void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item)
236 {
237! if (!sel_item)
238 return;
239
240 QString groupname = sel_item->GetData().toString();
241 QString grouplabel = sel_item->GetText();
242
243! updateGroupInfo(groupname, grouplabel);
244
245 if ((m_currentGroup == groupname) && !m_needUpdate)
246 return;
247--- 1278,1353 ----
248 updateRecList(m_groupList->GetItemCurrent());
249 }
250 }
251+ void PlaybackBox::UpdateUIGroupList(MythUIButtonListItem *sel_item)
252+ {
253+ m_groupList->Reset();
254+
255+ if (!m_titleList.isEmpty())
256+ {
257+ int best_pref = INT_MAX, sel_idx = 0;
258+ QStringList::iterator it;
259+ for (it = m_titleList.begin(); it != m_titleList.end(); ++it)
260+ {
261+ QString groupname = (*it).simplified();
262+
263+ // check if groupname begins with selected button (char)
264+ if (sel_item)
265+ {
266+ QString alphabetName = sel_item->GetText();
267+
268+ if (groupname.startsWith(alphabetName, Qt::CaseInsensitive))
269+ {
270+
271+ MythUIButtonListItem *item =
272+ new MythUIButtonListItem(
273+ m_groupList, "", qVariantFromValue(groupname.toLower()));
274+
275+ // int pref = groupPreferences.indexOf(groupname.toLower());
276+ // if ((pref >= 0) && (pref < best_pref))
277+ // {
278+ // best_pref = pref;
279+ // sel_idx = m_groupList->GetItemPos(item);
280+ // m_currentGroup = groupname.toLower();
281+ // }
282+
283+ if (groupname.isEmpty())
284+ groupname = m_groupDisplayName;
285+
286+ item->SetText(groupname, "name");
287+ item->SetText(groupname);
288+
289+ int count = m_progLists[groupname.toLower()].size();
290+ item->SetText(QString::number(count), "reccount");
291+ }
292+ }
293+ }
294+
295+ m_needUpdate = true;
296+ m_groupList->SetItemCurrent(sel_idx);
297+ // We need to explicitly call updateRecList in this case,
298+ // since 0 is selected by default, and we need updateRecList
299+ // to be called with m_needUpdate set.
300+ // if (!sel_idx)
301+ updateRecList(m_groupList->GetItemCurrent());
302+ }
303+ }
304
305 void PlaybackBox::updateRecList(MythUIButtonListItem *sel_item)
306 {
307! if (!sel_item)
308! {
309! InfoMap infoMap;
310! infoMap["description"] = "";
311! SetTextFromMap(infoMap);
312! m_recordingList->Reset();
313 return;
314+ }
315
316 QString groupname = sel_item->GetData().toString();
317 QString grouplabel = sel_item->GetText();
318
319! updateGroupInfo(groupname, grouplabel, sel_item);
320!
321
322 if ((m_currentGroup == groupname) && !m_needUpdate)
323 return;
324diff -crB mythfrontend//playbackbox.h /daten/mythfrontend//playbackbox.h
325*** mythfrontend//playbackbox.h 2011-02-18 04:30:17.000000000 +0100
326--- /daten/mythfrontend//playbackbox.h 2011-06-17 00:55:38.835120969 +0200
327***************
328*** 147,152 ****
329--- 147,155 ----
330 void deleteSelected(MythUIButtonListItem *item);
331
332 void SwitchList(void);
333+ void UpdateUIGroupList(MythUIButtonListItem *item);
334+ void UpdateUIGroupList(const QStringList &groupPreferences);
335+
336
337 void ShowGroupPopup(void);
338 void customEdit();
339***************
340*** 258,266 ****
341 void bannerLoad(void);
342 void coverartLoad(void);
343
344 private:
345 bool UpdateUILists(void);
346! void UpdateUIGroupList(const QStringList &groupPreferences);
347 void UpdateUIRecGroupList(void);
348
349 void UpdateProgressBar(void);
350--- 261,271 ----
351 void bannerLoad(void);
352 void coverartLoad(void);
353
354+ virtual void initAlphabetList(void);
355+
356 private:
357 bool UpdateUILists(void);
358!
359 void UpdateUIRecGroupList(void);
360
361 void UpdateProgressBar(void);
362***************
363*** 303,309 ****
364
365 void updateIcons(const ProgramInfo *pginfo = NULL);
366 void UpdateUsageUI(void);
367! void updateGroupInfo(const QString &groupname, const QString &grouplabel);
368
369 void SetItemIcons(MythUIButtonListItem *item, ProgramInfo* pginfo);
370 void UpdateUIListItem(
371--- 308,314 ----
372
373 void updateIcons(const ProgramInfo *pginfo = NULL);
374 void UpdateUsageUI(void);
375! void updateGroupInfo(const QString &groupname, const QString &grouplabel, MythUIButtonListItem *sel_item);
376
377 void SetItemIcons(MythUIButtonListItem *item, ProgramInfo* pginfo);
378 void UpdateUIListItem(
379***************
380*** 332,337 ****
381--- 337,343 ----
382 QRegExp m_prefixes; ///< prefixes to be ignored when sorting
383 QRegExp m_titleChaff; ///< stuff to remove for search rules
384
385+ MythUIButtonList *m_alphabetList;
386 MythUIButtonList *m_recgroupList;
387 MythUIButtonList *m_groupList;
388 MythUIButtonList *m_recordingList;