86a5409229aef36975e1cdb128ec095cad324b21
[vuplus_xbmc] / xbmc / filesystem / AndroidAppDirectory.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 "system.h"
22
23 #if defined(TARGET_ANDROID)
24 #include "AndroidAppDirectory.h"
25 #include "xbmc/android/activity/XBMCApp.h"
26 #include "FileItem.h"
27 #include "File.h"
28 #include "utils/URIUtils.h"
29 #include <vector>
30 #include "utils/log.h"
31 #include "utils/StringUtils.h"
32 #include "URL.h"
33
34 using namespace XFILE;
35 using namespace std;
36
37 CAndroidAppDirectory::CAndroidAppDirectory(void)
38 {
39 }
40
41 CAndroidAppDirectory::~CAndroidAppDirectory(void)
42 {
43 }
44
45 bool CAndroidAppDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
46 {
47   CURL url(strPath);
48   CStdString dirname = url.GetFileName();
49   URIUtils::RemoveSlashAtEnd(dirname);
50   CLog::Log(LOGDEBUG, "CAndroidAppDirectory::GetDirectory: %s",dirname.c_str()); 
51   if (dirname == "apps")
52   {
53     vector<androidPackage> applications;
54     CXBMCApp::ListApplications(&applications);
55     if (!applications.size())
56     {
57       CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Application lookup listing failed");
58       return false;
59     }
60     for(unsigned int i = 0; i < applications.size(); i++)
61     {
62       if (applications[i].packageName == "org.xbmc.xbmc")
63         continue;
64       CFileItemPtr pItem(new CFileItem(applications[i].packageName));
65       pItem->m_bIsFolder = false;
66       CStdString path = StringUtils::Format("androidapp://%s/%s/%s", url.GetHostName().c_str(), dirname.c_str(),  applications[i].packageName.c_str());
67       pItem->SetPath(path);
68       pItem->SetLabel(applications[i].packageLabel);
69       pItem->SetArt("thumb", path+".png");
70       items.Add(pItem);
71     }
72     return true;
73   }
74
75   CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Failed to open %s",strPath.c_str());
76   return false;
77 }
78
79 bool CAndroidAppDirectory::IsAllowed(const CStdString& strFile) const
80 {
81   // Entries are virtual, so we want them all.
82   return true;
83 }
84
85 #endif