[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / filesystem / VTPDirectory.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "VTPDirectory.h"
22 #include "VTPSession.h"
23 #include "URL.h"
24 #include "utils/URIUtils.h"
25 #include "FileItem.h"
26
27
28 using namespace std;
29 using namespace XFILE;
30
31 CVTPDirectory::CVTPDirectory()
32 {
33   m_session = new CVTPSession();
34 }
35
36 CVTPDirectory::~CVTPDirectory()
37 {
38   delete m_session;
39 }
40
41 bool CVTPDirectory::GetChannels(const CStdString& base, CFileItemList &items)
42 {
43   vector<CVTPSession::Channel> channels;
44   if(!m_session->GetChannels(channels))
45     return false;
46
47   vector<CVTPSession::Channel>::iterator it;
48   for(it = channels.begin(); it != channels.end(); it++)
49   {
50     CStdString buffer;
51     CFileItemPtr item(new CFileItem("", false));
52
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);
58
59     items.Add(item);
60   }
61   return true;
62 }
63
64 bool CVTPDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
65 {
66   CURL url(strPath);
67
68   if(url.GetHostName() == "")
69     url.SetHostName("localhost");
70
71   CStdString base = url.Get();
72   URIUtils::RemoveSlashAtEnd(base);
73
74   // add port after, it changes the structure
75   // and breaks CUtil::GetMatchingSource
76   if(url.GetPort() == 0)
77     url.SetPort(2004);
78
79   if(!m_session->Open(url.GetHostName(), url.GetPort()))
80     return false;
81
82   if(url.GetFileName().IsEmpty())
83   {
84     CFileItemPtr item;
85
86     item.reset(new CFileItem(base + "/channels/", true));
87     item->SetLabel("Live Channels");
88     item->SetLabelPreformated(true);
89     items.Add(item);
90     return true;
91   }
92   else if(url.GetFileName() == "channels/")
93     return GetChannels(base, items);
94   else
95     return false;
96 }
97