2 * Copyright (C) 2012-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 "PVRDirectory.h"
25 #include "utils/log.h"
26 #include "utils/URIUtils.h"
27 #include "guilib/LocalizeStrings.h"
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"
36 using namespace XFILE;
39 CPVRDirectory::CPVRDirectory()
43 CPVRDirectory::~CPVRDirectory()
47 bool CPVRDirectory::Exists(const char* strPath)
49 CStdString directory(strPath);
50 if (directory.substr(0,17) == "pvr://recordings/")
56 bool CPVRDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
58 CStdString base(strPath);
59 URIUtils::RemoveSlashAtEnd(base);
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);
67 if (!g_PVRManager.IsStarted())
74 item.reset(new CFileItem(base + "/channels/", true));
75 item->SetLabel(g_localizeStrings.Get(19019));
76 item->SetLabelPreformated(true);
79 item.reset(new CFileItem(base + "/recordings/", true));
80 item->SetLabel(g_localizeStrings.Get(19017));
81 item->SetLabelPreformated(true);
84 item.reset(new CFileItem(base + "/timers/", true));
85 item->SetLabel(g_localizeStrings.Get(19040));
86 item->SetLabelPreformated(true);
89 item.reset(new CFileItem(base + "/guide/", true));
90 item->SetLabel(g_localizeStrings.Get(19029));
91 item->SetLabelPreformated(true);
94 // Sort by name only. Labels are preformated.
95 items.AddSortMethod(SortByLabel, 551 /* Name */, LABEL_MASKS("%L", "", "%L", ""));
99 else if (StringUtils::StartsWith(fileName, "recordings"))
101 return g_PVRRecordings->GetDirectory(strPath, items);
103 else if (StringUtils::StartsWith(fileName, "channels"))
105 return g_PVRChannelGroups->GetDirectory(strPath, items);
107 else if (StringUtils::StartsWith(fileName, "timers"))
109 return g_PVRTimers->GetDirectory(strPath, items);
115 bool CPVRDirectory::SupportsWriteFileOperations(const CStdString& strPath)
118 CStdString filename = url.GetFileName();
120 return URIUtils::IsPVRRecording(filename);
123 bool CPVRDirectory::IsLiveTV(const CStdString& strPath)
126 CStdString filename = url.GetFileName();
128 return URIUtils::IsLiveTV(filename);
131 bool CPVRDirectory::HasRecordings()
133 return g_PVRRecordings->GetNumRecordings() > 0;