Skip to content
This repository
Browse code

Merge pull request #1880 from pieh/epggrid_container

fix crash when using Container.NumItems infolabel with epggrid control
  • Loading branch information...
commit 3a2c95973f12b47a3f7cedb350cfb305845d42d3 2 parents f884cfc + fb6799e
Michal Piechowiak authored December 05, 2012
12  xbmc/GUIInfoManager.cpp
@@ -1571,7 +1571,7 @@ CStdString CGUIInfoManager::GetLabel(int info, int contextWindow, CStdString *fa
1571 1571
       {
1572 1572
         const CGUIControl *control = window->GetControl(window->GetViewContainerID());
1573 1573
         if (control && control->IsContainer())
1574  
-          strLabel = ((CGUIBaseContainer *)control)->GetLabel();
  1574
+          strLabel = ((IGUIContainer *)control)->GetLabel();
1575 1575
       }
1576 1576
       break;
1577 1577
     }
@@ -2500,7 +2500,7 @@ bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, c
2500 2500
       {
2501 2501
         const CGUIControl *control = window->GetControl(data1);
2502 2502
         if (control && control->IsContainer())
2503  
-          item = ((CGUIBaseContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()).get();
  2503
+          item = ((IGUIContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()).get();
2504 2504
       }
2505 2505
     }
2506 2506
     if (item) // If we got a valid item, do the lookup
@@ -2784,7 +2784,7 @@ bool CGUIInfoManager::GetMultiInfoBool(const GUIInfo &info, int contextWindow, c
2784 2784
             const CGUIControl *control = window->GetControl(info.GetData1());
2785 2785
             if (control && control->IsContainer())
2786 2786
             {
2787  
-              CFileItemPtr item = boost::static_pointer_cast<CFileItem>(((CGUIBaseContainer *)control)->GetListItem(0));
  2787
+              CFileItemPtr item = boost::static_pointer_cast<CFileItem>(((IGUIContainer *)control)->GetListItem(0));
2788 2788
               if (item && item->m_iprogramCount == info.GetData2())  // programcount used to store item id
2789 2789
                 bReturn = true;
2790 2790
             }
@@ -2898,7 +2898,7 @@ bool CGUIInfoManager::GetMultiInfoInt(int &value, const GUIInfo &info, int conte
2898 2898
     {
2899 2899
       const CGUIControl *control = window->GetControl(data1);
2900 2900
       if (control && control->IsContainer())
2901  
-        item = boost::static_pointer_cast<CFileItem>(((CGUIBaseContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()));
  2901
+        item = boost::static_pointer_cast<CFileItem>(((IGUIContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()));
2902 2902
     }
2903 2903
 
2904 2904
     if (item) // If we got a valid item, do the lookup
@@ -2941,7 +2941,7 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
2941 2941
     {
2942 2942
       const CGUIControl *control = window->GetControl(data1);
2943 2943
       if (control && control->IsContainer())
2944  
-        item = boost::static_pointer_cast<CFileItem>(((CGUIBaseContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()));
  2944
+        item = boost::static_pointer_cast<CFileItem>(((IGUIContainer *)control)->GetListItem(info.GetData2(), info.GetInfoFlag()));
2945 2945
     }
2946 2946
 
2947 2947
     if (item) // If we got a valid item, do the lookup
@@ -3038,7 +3038,7 @@ CStdString CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextWi
3038 3038
     if (control)
3039 3039
     {
3040 3040
       if (control->IsContainer())
3041  
-        return ((CGUIBaseContainer *)control)->GetLabel(info.m_info);
  3041
+        return ((IGUIContainer *)control)->GetLabel(info.m_info);
3042 3042
       else if (control->GetControlType() == CGUIControl::GUICONTROL_TEXTBOX)
3043 3043
         return ((CGUITextBox *)control)->GetLabel(info.m_info);
3044 3044
     }
16  xbmc/GUIViewControl.cpp
@@ -125,7 +125,7 @@ void CGUIViewControl::SetCurrentView(int viewMode, bool bRefresh /* = false */)
125 125
 
126 126
   // Update our view control only if we are not in the TV Window
127 127
   if (m_parentWindow != WINDOW_PVR)
128  
-    UpdateViewAsControl(((CGUIBaseContainer *)pNewView)->GetLabel());
  128
+    UpdateViewAsControl(((IGUIContainer *)pNewView)->GetLabel());
129 129
 }
130 130
 
131 131
 void CGUIViewControl::SetItems(CFileItemList &items)
@@ -240,11 +240,11 @@ int CGUIViewControl::GetCurrentControl() const
240 240
 // returns the number-th view's viewmode (type and id)
241 241
 int CGUIViewControl::GetViewModeNumber(int number) const
242 242
 {
243  
-  CGUIBaseContainer *nextView = NULL;
  243
+  IGUIContainer *nextView = NULL;
244 244
   if (number >= 0 && number < (int)m_visibleViews.size())
245  
-    nextView = (CGUIBaseContainer *)m_visibleViews[number];
  245
+    nextView = (IGUIContainer *)m_visibleViews[number];
246 246
   else if (m_visibleViews.size())
247  
-    nextView = (CGUIBaseContainer *)m_visibleViews[0];
  247
+    nextView = (IGUIContainer *)m_visibleViews[0];
248 248
   if (nextView)
249 249
     return (nextView->GetType() << 16) | nextView->GetID();
250 250
   return 0;  // no view modes :(
@@ -254,7 +254,7 @@ int CGUIViewControl::GetViewModeByID(int id) const
254 254
 {
255 255
   for (unsigned int i = 0; i < m_visibleViews.size(); ++i)
256 256
   {
257  
-    CGUIBaseContainer *view = (CGUIBaseContainer *)m_visibleViews[i];
  257
+    IGUIContainer *view = (IGUIContainer *)m_visibleViews[i];
258 258
     if (view->GetID() == id)
259 259
       return (view->GetType() << 16) | view->GetID();
260 260
   }
@@ -269,7 +269,7 @@ int CGUIViewControl::GetNextViewMode(int direction) const
269 269
 
270 270
   int viewNumber = (m_currentView + direction) % (int)m_visibleViews.size();
271 271
   if (viewNumber < 0) viewNumber += m_visibleViews.size();
272  
-  CGUIBaseContainer *nextView = (CGUIBaseContainer *)m_visibleViews[viewNumber];
  272
+  IGUIContainer *nextView = (IGUIContainer *)m_visibleViews[viewNumber];
273 273
   return (nextView->GetType() << 16) | nextView->GetID();
274 274
 }
275 275
 
@@ -286,7 +286,7 @@ int CGUIViewControl::GetView(VIEW_TYPE type, int id) const
286 286
 {
287 287
   for (int i = 0; i < (int)m_visibleViews.size(); i++)
288 288
   {
289  
-    CGUIBaseContainer *view = (CGUIBaseContainer *)m_visibleViews[i];
  289
+    IGUIContainer *view = (IGUIContainer *)m_visibleViews[i];
290 290
     if ((type == VIEW_TYPE_NONE || type == view->GetType()) && (!id || view->GetID() == id))
291 291
       return i;
292 292
   }
@@ -300,7 +300,7 @@ void CGUIViewControl::UpdateViewAsControl(const CStdString &viewLabel)
300 300
   g_windowManager.SendMessage(msg);
301 301
   for (unsigned int i = 0; i < m_visibleViews.size(); i++)
302 302
   {
303  
-    CGUIBaseContainer *view = (CGUIBaseContainer *)m_visibleViews[i];
  303
+    IGUIContainer *view = (IGUIContainer *)m_visibleViews[i];
304 304
     CGUIMessage msg(GUI_MSG_LABEL_ADD, m_parentWindow, m_viewAsControl, i);
305 305
     CStdString label;
306 306
     label.Format(g_localizeStrings.Get(534).c_str(), view->GetLabel().c_str()); // View: %s
46  xbmc/epg/GUIEPGGridContainer.cpp
@@ -46,7 +46,7 @@ using namespace std;
46 46
 CGUIEPGGridContainer::CGUIEPGGridContainer(int parentID, int controlID, float posX, float posY, float width,
47 47
                                            float height, ORIENTATION orientation, int scrollTime,
48 48
                                            int preloadItems, int timeBlocks, int rulerUnit)
49  
-    : CGUIControl(parentID, controlID, posX, posY, width, height)
  49
+    : IGUIContainer(parentID, controlID, posX, posY, width, height)
50 50
 {
51 51
   ControlType             = GUICONTAINER_EPGGRID;
52 52
   m_blocksPerPage         = timeBlocks;
@@ -1322,12 +1322,50 @@ int CGUIEPGGridContainer::GetSelectedItem() const
1322 1322
   return 0;
1323 1323
 }
1324 1324
 
1325  
-CGUIListItemPtr CGUIEPGGridContainer::GetListItem(int offset) const
  1325
+CGUIListItemPtr CGUIEPGGridContainer::GetListItem(int offset, unsigned int flag) const
1326 1326
 {
1327  
-  if (!m_epgItemsPtr.size())
  1327
+  if (!m_channelItems.size())
1328 1328
     return CGUIListItemPtr();
1329 1329
 
1330  
-  return m_item->item;
  1330
+  int item = m_channelCursor + m_channelOffset + offset;
  1331
+  if (flag & INFOFLAG_LISTITEM_POSITION)
  1332
+    item = (int)(m_channelScrollOffset / m_channelLayout->Size(VERTICAL));
  1333
+
  1334
+  if (flag & INFOFLAG_LISTITEM_WRAP)
  1335
+  {
  1336
+    item %= (int)m_channelItems.size();
  1337
+    if (item < 0) item += m_channelItems.size();
  1338
+    return m_channelItems[item];
  1339
+  }
  1340
+  else
  1341
+  {
  1342
+    if (item >= 0 && item < (int)m_channelItems.size())
  1343
+      return m_channelItems[item];
  1344
+  }
  1345
+  return CGUIListItemPtr();
  1346
+}
  1347
+
  1348
+CStdString CGUIEPGGridContainer::GetLabel(int info) const
  1349
+{
  1350
+  CStdString label;
  1351
+  switch (info)
  1352
+  {
  1353
+  case CONTAINER_NUM_PAGES:
  1354
+    label.Format("%u", (m_channels + m_channelsPerPage - 1) / m_channelsPerPage);
  1355
+    break;
  1356
+  case CONTAINER_CURRENT_PAGE:
  1357
+    label.Format("%u", 1 + (m_channelCursor + m_channelOffset) / m_channelsPerPage );
  1358
+    break;
  1359
+  case CONTAINER_POSITION:
  1360
+    label.Format("%i", 1 + m_channelCursor + m_channelOffset);
  1361
+    break;
  1362
+  case CONTAINER_NUM_ITEMS:
  1363
+    label.Format("%u", m_channels);
  1364
+    break;
  1365
+  default:
  1366
+      break;
  1367
+  }
  1368
+  return label;
1331 1369
 }
1332 1370
 
1333 1371
 GridItemsPtr *CGUIEPGGridContainer::GetClosestItem(const int &channel)
7  xbmc/epg/GUIEPGGridContainer.h
@@ -24,6 +24,7 @@
24 24
 #include "FileItem.h"
25 25
 #include "guilib/GUIControl.h"
26 26
 #include "guilib/GUIListItemLayout.h"
  27
+#include "guilib/GUIBaseContainer.h"
27 28
 
28 29
 namespace PVR
29 30
 {
@@ -42,7 +43,7 @@ namespace EPG
42 43
     float height;
43 44
   };
44 45
 
45  
-  class CGUIEPGGridContainer : public CGUIControl
  46
+  class CGUIEPGGridContainer : public IGUIContainer
46 47
   {
47 48
   friend class PVR::CGUIWindowPVRGuide;
48 49
 
@@ -77,8 +78,8 @@ namespace EPG
77 78
     void LoadLayout(TiXmlElement *layout);
78 79
     void LoadContent(TiXmlElement *content);
79 80
 
80  
-    virtual bool IsContainer() const { return true; };
81  
-    CGUIListItemPtr GetListItem(int offset) const;
  81
+    virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
  82
+    virtual CStdString GetLabel(int info) const;
82 83
 
83 84
     virtual int  CorrectOffset(int offset, int cursor) const;
84 85
 
20  xbmc/guilib/GUIBaseContainer.cpp
@@ -39,8 +39,20 @@ using namespace std;
39 39
 #define SCROLLING_GAP   200U
40 40
 #define SCROLLING_THRESHOLD 300U
41 41
 
  42
+
  43
+IGUIContainer::IGUIContainer(int parentID, int controlID, float posX, float posY, float width, float height)
  44
+  : CGUIControl(parentID, controlID, posX, posY, width, height)
  45
+{
  46
+}
  47
+
  48
+void IGUIContainer::SetType(VIEW_TYPE type, const CStdString &label)
  49
+{
  50
+  m_type = type;
  51
+  m_label = label;
  52
+}
  53
+
42 54
 CGUIBaseContainer::CGUIBaseContainer(int parentID, int controlID, float posX, float posY, float width, float height, ORIENTATION orientation, const CScroller& scroller, int preloadItems)
43  
-    : CGUIControl(parentID, controlID, posX, posY, width, height)
  55
+    : IGUIContainer(parentID, controlID, posX, posY, width, height)
44 56
     , m_scroller(scroller)
45 57
 {
46 58
   m_cursor = 0;
@@ -1068,12 +1080,6 @@ void CGUIBaseContainer::SetRenderOffset(const CPoint &offset)
1068 1080
   m_renderOffset = offset;
1069 1081
 }
1070 1082
 
1071  
-void CGUIBaseContainer::SetType(VIEW_TYPE type, const CStdString &label)
1072  
-{
1073  
-  m_type = type;
1074  
-  m_label = label;
1075  
-}
1076  
-
1077 1083
 void CGUIBaseContainer::FreeMemory(int keepStart, int keepEnd)
1078 1084
 {
1079 1085
   if (keepStart < keepEnd)
31  xbmc/guilib/GUIBaseContainer.h
@@ -37,7 +37,24 @@ typedef boost::shared_ptr<CGUIListItem> CGUIListItemPtr;
37 37
  \brief
38 38
  */
39 39
 
40  
-class CGUIBaseContainer : public CGUIControl
  40
+class IGUIContainer : public CGUIControl
  41
+{
  42
+protected:
  43
+  VIEW_TYPE m_type;
  44
+  CStdString m_label;
  45
+public:
  46
+  IGUIContainer(int parentID, int controlID, float posX, float posY, float width, float height);
  47
+  virtual bool IsContainer() const { return true; };
  48
+
  49
+  VIEW_TYPE GetType() const { return m_type; };
  50
+  const CStdString &GetLabel() const { return m_label; };
  51
+  void SetType(VIEW_TYPE type, const CStdString &label);
  52
+
  53
+  virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const = 0;
  54
+  virtual CStdString GetLabel(int info) const                                  = 0;
  55
+};
  56
+
  57
+class CGUIBaseContainer : public IGUIContainer
41 58
 {
42 59
 public:
43 60
   CGUIBaseContainer(int parentID, int controlID, float posX, float posY, float width, float height, ORIENTATION orientation, const CScroller& scroller, int preloadItems);
@@ -74,15 +91,10 @@ class CGUIBaseContainer : public CGUIControl
74 91
   void LoadContent(TiXmlElement *content);
75 92
   void SetDefaultControl(int id, bool always) { m_staticDefaultItem = id; m_staticDefaultAlways = always; };
76 93
 
77  
-  VIEW_TYPE GetType() const { return m_type; };
78  
-  const CStdString &GetLabel() const { return m_label; };
79  
-  void SetType(VIEW_TYPE type, const CStdString &label);
80  
-
81  
-  virtual bool IsContainer() const { return true; };
82  
-  CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
  94
+  virtual CGUIListItemPtr GetListItem(int offset, unsigned int flag = 0) const;
83 95
 
84 96
   virtual bool GetCondition(int condition, int data) const;
85  
-  CStdString GetLabel(int info) const;
  97
+  virtual CStdString GetLabel(int info) const;
86 98
 
87 99
   void SetStaticContent(const std::vector<CGUIListItemPtr> &items, bool forceUpdate = true);
88 100
   
@@ -158,9 +170,6 @@ class CGUIBaseContainer : public CGUIControl
158 170
 
159 171
   CScroller m_scroller;
160 172
 
161  
-  VIEW_TYPE m_type;
162  
-  CStdString m_label;
163  
-
164 173
   bool m_staticContent;
165 174
   bool m_staticDefaultAlways;
166 175
   int  m_staticDefaultItem;
1  xbmc/guilib/GUIControlFactory.cpp
@@ -1247,6 +1247,7 @@ CGUIControl* CGUIControlFactory::Create(int parentID, const CRect &rect, TiXmlEl
1247 1247
     control = new CGUIEPGGridContainer(parentID, id, posX, posY, width, height, orientation, scrollTime, preloadItems, timeBlocks, rulerUnit);
1248 1248
     ((CGUIEPGGridContainer *)control)->LoadLayout(pControlNode);
1249 1249
     ((CGUIEPGGridContainer *)control)->SetRenderOffset(offset);
  1250
+    ((CGUIEPGGridContainer *)control)->SetType(viewType, viewLabel);
1250 1251
   }
1251 1252
   else if (type == CGUIControl::GUICONTAINER_FIXEDLIST)
1252 1253
   {
2  xbmc/settings/GUIWindowSettingsCategory.cpp
@@ -2766,7 +2766,7 @@ void CGUIWindowSettingsCategory::FillInViewModes(CSetting *pSetting, int windowI
2766 2766
     window->Initialize();
2767 2767
     for (int i = 50; i < 60; i++)
2768 2768
     {
2769  
-      CGUIBaseContainer *control = (CGUIBaseContainer *)window->GetControl(i);
  2769
+      IGUIContainer *control = (IGUIContainer *)window->GetControl(i);
2770 2770
       if (control)
2771 2771
       {
2772 2772
         int type = (control->GetType() << 16) | i;

0 notes on commit 3a2c959

Please sign in to comment.
Something went wrong with that request. Please try again.