aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Op den Kamp <lars@opdenkamp.eu>2011-01-08 17:25:45 +0100
committerLars Op den Kamp <lars@opdenkamp.eu>2011-01-08 17:25:45 +0100
commit0b485bb315c5b0b1e287b43ba3484b8ddd195f12 (patch)
tree097cc50a57cd48a0d87fd4da532a969bc0fb9e59
parent10a6b75077b342577a34268234f0c483c385bf8b (diff)
pvr: add channels to channelgroups
-rw-r--r--xbmc/pvr/PVRChannel.cpp16
-rw-r--r--xbmc/pvr/PVRChannelGroup.cpp52
-rw-r--r--xbmc/pvr/PVRChannelGroup.h7
-rw-r--r--xbmc/pvr/PVRChannelGroups.cpp19
-rw-r--r--xbmc/pvr/PVRChannelGroups.h1
5 files changed, 94 insertions, 1 deletions
diff --git a/xbmc/pvr/PVRChannel.cpp b/xbmc/pvr/PVRChannel.cpp
index f753485dd3..9ee16f75b4 100644
--- a/xbmc/pvr/PVRChannel.cpp
+++ b/xbmc/pvr/PVRChannel.cpp
@@ -26,6 +26,8 @@
#include "FileSystem/File.h"
#include "MusicInfoTag.h"
+#include "PVRChannelGroups.h"
+#include "PVRChannelGroup.h"
#include "PVRChannel.h"
#include "PVREpgs.h"
#include "PVREpg.h"
@@ -168,10 +170,24 @@ bool CPVRChannel::SetChannelNumber(int iChannelNumber, bool bSaveInDb /* = false
bool CPVRChannel::SetGroupID(int iChannelGroupId, bool bSaveInDb /* = false */)
{
+ bool bRemoveFromOldGroup = true; // TODO support multiple groups and make this a parameter
bool bReturn = false;
if (m_iChannelGroupId != iChannelGroupId)
{
+ CPVRChannelGroups *groups = (IsRadio() ? &PVRChannelGroupsRadio : &PVRChannelGroupsTV);
+
+ if (bRemoveFromOldGroup)
+ {
+ CPVRChannelGroup *oldGroup = groups->GetGroupById(m_iChannelGroupId);
+ if (oldGroup)
+ oldGroup->RemoveFromGroup(this);
+ }
+
+ CPVRChannelGroup *newGroup = groups->GetGroupById(iChannelGroupId);
+ if (newGroup)
+ newGroup->AddToGroup(this);
+
/* update the group id */
m_iChannelGroupId = iChannelGroupId;
SetChanged();
diff --git a/xbmc/pvr/PVRChannelGroup.cpp b/xbmc/pvr/PVRChannelGroup.cpp
index 3dcb8a5636..acd3606031 100644
--- a/xbmc/pvr/PVRChannelGroup.cpp
+++ b/xbmc/pvr/PVRChannelGroup.cpp
@@ -20,9 +20,61 @@
*/
#include "PVRChannelGroup.h"
+#include "PVRChannel.h"
CPVRChannelGroup::CPVRChannelGroup(void)
{
m_iGroupID = 0;
m_GroupName = "";
}
+
+CPVRChannelGroup::~CPVRChannelGroup(void)
+{
+ erase(begin(), end());
+}
+
+bool CPVRChannelGroup::RemoveFromGroup(const CPVRChannel *channel)
+{
+ bool bReturn = false;
+
+ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++)
+ {
+ if (*channel == *at(iChannelPtr))
+ {
+ erase(begin() + iChannelPtr);
+ bReturn = true;
+ break;
+ }
+ }
+
+ return bReturn;
+}
+
+bool CPVRChannelGroup::AddToGroup(CPVRChannel *channel)
+{
+ bool bReturn = false;
+
+ if (!IsGroupMember(channel))
+ {
+ push_back(channel);
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+bool CPVRChannelGroup::IsGroupMember(const CPVRChannel *channel)
+{
+ bool bReturn = false;
+
+ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++)
+ {
+ if (*channel == *at(iChannelPtr))
+ {
+ bReturn = true;
+ break;
+ }
+ }
+
+ return bReturn;
+}
diff --git a/xbmc/pvr/PVRChannelGroup.h b/xbmc/pvr/PVRChannelGroup.h
index 477401fec1..a28cdf3b06 100644
--- a/xbmc/pvr/PVRChannelGroup.h
+++ b/xbmc/pvr/PVRChannelGroup.h
@@ -26,7 +26,7 @@
#include "FileItem.h"
#include "../addons/include/xbmc_pvr_types.h"
-class CPVRChannelGroup
+class CPVRChannelGroup : public std::vector<CPVRChannel *>
{
private:
unsigned long m_iGroupID;
@@ -35,6 +35,11 @@ private:
public:
CPVRChannelGroup(void);
+ virtual ~CPVRChannelGroup(void);
+
+ bool RemoveFromGroup(const CPVRChannel *channel);
+ bool AddToGroup(CPVRChannel *channel);
+ bool IsGroupMember(const CPVRChannel *channel);
long GroupID(void) const { return m_iGroupID; }
void SetGroupID(long group) { m_iGroupID = group; }
diff --git a/xbmc/pvr/PVRChannelGroups.cpp b/xbmc/pvr/PVRChannelGroups.cpp
index 658b39589a..5a61d52159 100644
--- a/xbmc/pvr/PVRChannelGroups.cpp
+++ b/xbmc/pvr/PVRChannelGroups.cpp
@@ -78,6 +78,25 @@ int CPVRChannelGroups::GetGroupList(CFileItemList* results)
return size();
}
+CPVRChannelGroup *CPVRChannelGroups::GetGroupById(int iGroupId)
+{
+ CPVRChannelGroup *group = NULL;
+
+ if (iGroupId == -1)
+ return group;
+
+ for (int iGroupPtr = 0; iGroupPtr < size(); iGroupPtr++)
+ {
+ if (at(iGroupPtr).GroupID() == iGroupId)
+ {
+ group = &at(iGroupPtr);
+ break;
+ }
+ }
+
+ return group;
+}
+
int CPVRChannelGroups::GetFirstChannelForGroupID(int GroupId)
{
if (GroupId == -1)
diff --git a/xbmc/pvr/PVRChannelGroups.h b/xbmc/pvr/PVRChannelGroups.h
index 68237bd362..d8ea89fc90 100644
--- a/xbmc/pvr/PVRChannelGroups.h
+++ b/xbmc/pvr/PVRChannelGroups.h
@@ -40,6 +40,7 @@ public:
void Unload();
int GetGroupList(CFileItemList* results);
+ CPVRChannelGroup *GetGroupById(int iGroupId);
int GetFirstChannelForGroupID(int GroupId);
int GetPrevGroupID(int current_group_id);
int GetNextGroupID(int current_group_id);