2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "VTPDirectory.h"
22 #include "VTPSession.h"
24 #include "utils/URIUtils.h"
29 using namespace XFILE;
31 CVTPDirectory::CVTPDirectory()
33 m_session = new CVTPSession();
36 CVTPDirectory::~CVTPDirectory()
41 bool CVTPDirectory::GetChannels(const CStdString& base, CFileItemList &items)
43 vector<CVTPSession::Channel> channels;
44 if(!m_session->GetChannels(channels))
47 vector<CVTPSession::Channel>::iterator it;
48 for(it = channels.begin(); it != channels.end(); it++)
51 CFileItemPtr item(new CFileItem("", false));
53 buffer.Format("%s/%d.ts", base.c_str(), it->index);
54 item->SetPath(buffer);
55 item->m_strTitle = it->name;
56 buffer.Format("%d - %s", it->index, it->name);
57 item->SetLabel(buffer);
64 bool CVTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
68 if(url.GetHostName() == "")
69 url.SetHostName("localhost");
71 CStdString base = url.Get();
72 URIUtils::RemoveSlashAtEnd(base);
74 // add port after, it changes the structure
75 // and breaks CUtil::GetMatchingSource
76 if(url.GetPort() == 0)
79 if(!m_session->Open(url.GetHostName(), url.GetPort()))
82 if(url.GetFileName().IsEmpty())
86 item.reset(new CFileItem(base + "/channels/", true));
87 item->SetLabel("Live Channels");
88 item->SetLabelPreformated(true);
92 else if(url.GetFileName() == "channels/")
93 return GetChannels(base, items);