Merge pull request #2703 from ace20022/cores_revised
[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 "URL.h"
32
33 using namespace XFILE;
34 using namespace std;
35
36 CAndroidAppDirectory::CAndroidAppDirectory(void)
37 {
38 }
39
40 CAndroidAppDirectory::~CAndroidAppDirectory(void)
41 {
42 }
43
44 bool CAndroidAppDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items)
45 {
46   CURL url(strPath);
47   CStdString dirname = url.GetFileName();
48   URIUtils::RemoveSlashAtEnd(dirname);
49   CLog::Log(LOGDEBUG, "CAndroidAppDirectory::GetDirectory: %s",dirname.c_str()); 
50   if (dirname == "apps")
51   {
52     vector<androidPackage> applications;
53     CXBMCApp::ListApplications(&applications);
54     if (!applications.size())
55     {
56       CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Application lookup listing failed");
57       return false;
58     }
59     for(unsigned int i = 0; i < applications.size(); i++)
60     {
61       if (applications[i].packageName == "org.xbmc.xbmc")
62         continue;
63       CFileItemPtr pItem(new CFileItem(applications[i].packageName));
64       pItem->m_bIsFolder = false;
65       CStdString path;
66       path.Format("androidapp://%s/%s/%s", url.GetHostName(), dirname,  applications[i].packageName);
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