Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / filesystem / PVRDirectory.cpp
1 /*
2  *      Copyright (C) 2012-2013 Team XBMC
3  *      http://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 "PVRDirectory.h"
22 #include "FileItem.h"
23 #include "Util.h"
24 #include "URL.h"
25 #include "utils/log.h"
26 #include "utils/URIUtils.h"
27 #include "guilib/LocalizeStrings.h"
28
29 #include "pvr/PVRManager.h"
30 #include "pvr/channels/PVRChannelGroupsContainer.h"
31 #include "pvr/channels/PVRChannelGroup.h"
32 #include "pvr/recordings/PVRRecordings.h"
33 #include "pvr/timers/PVRTimers.h"
34
35 using namespace std;
36 using namespace XFILE;
37 using namespace PVR;
38
39 CPVRDirectory::CPVRDirectory()
40 {
41 }
42
43 CPVRDirectory::~CPVRDirectory()
44 {
45 }
46
47 bool CPVRDirectory::Exists(const char* strPath)
48 {
49   CStdString directory(strPath);
50   if (directory.substr(0,17) == "pvr://recordings/")
51     return true;
52   else
53     return false;
54 }
55
56 bool CPVRDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
57 {
58   CStdString base(strPath);
59   URIUtils::RemoveSlashAtEnd(base);
60
61   CURL url(strPath);
62   CStdString fileName = url.GetFileName();
63   URIUtils::RemoveSlashAtEnd(fileName);
64   CLog::Log(LOGDEBUG, "CPVRDirectory::GetDirectory(%s)", base.c_str());
65   items.SetCacheToDisc(CFileItemList::CACHE_NEVER);
66
67   if (!g_PVRManager.IsStarted())
68     return false;
69
70   if (fileName == "")
71   {
72     CFileItemPtr item;
73
74     item.reset(new CFileItem(base + "/channels/", true));
75     item->SetLabel(g_localizeStrings.Get(19019));
76     item->SetLabelPreformated(true);
77     items.Add(item);
78
79     item.reset(new CFileItem(base + "/recordings/", true));
80     item->SetLabel(g_localizeStrings.Get(19017));
81     item->SetLabelPreformated(true);
82     items.Add(item);
83
84     item.reset(new CFileItem(base + "/timers/", true));
85     item->SetLabel(g_localizeStrings.Get(19040));
86     item->SetLabelPreformated(true);
87     items.Add(item);
88
89     item.reset(new CFileItem(base + "/guide/", true));
90     item->SetLabel(g_localizeStrings.Get(19029));
91     item->SetLabelPreformated(true);
92     items.Add(item);
93
94     // Sort by name only. Labels are preformated.
95     items.AddSortMethod(SortByLabel, 551 /* Name */, LABEL_MASKS("%L", "", "%L", ""));
96
97     return true;
98   }
99   else if (StringUtils::StartsWith(fileName, "recordings"))
100   {
101     return g_PVRRecordings->GetDirectory(strPath, items);
102   }
103   else if (StringUtils::StartsWith(fileName, "channels"))
104   {
105     return g_PVRChannelGroups->GetDirectory(strPath, items);
106   }
107   else if (StringUtils::StartsWith(fileName, "timers"))
108   {
109     return g_PVRTimers->GetDirectory(strPath, items);
110   }
111
112   return false;
113 }
114
115 bool CPVRDirectory::SupportsWriteFileOperations(const CStdString& strPath)
116 {
117   CURL url(strPath);
118   CStdString filename = url.GetFileName();
119
120   return URIUtils::IsPVRRecording(filename);
121 }
122
123 bool CPVRDirectory::IsLiveTV(const CStdString& strPath)
124 {
125   CURL url(strPath);
126   CStdString filename = url.GetFileName();
127
128   return URIUtils::IsLiveTV(filename);
129 }
130
131 bool CPVRDirectory::HasRecordings()
132 {
133   return g_PVRRecordings->GetNumRecordings() > 0;
134 }