Merge pull request #1038 from waven/discstub
[vuplus_xbmc] / xbmc / filesystem / AndroidAppDirectory.cpp
1 /*
2  *      Copyright (C) 2012 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, write to
17  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18  *  http://www.gnu.org/copyleft/gpl.html
19  *
20  */
21
22 #include "system.h"
23
24 #if defined(TARGET_ANDROID)
25 #include "AndroidAppDirectory.h"
26 #include "xbmc/android/activity/XBMCApp.h"
27 #include "FileItem.h"
28 #include "File.h"
29 #include "utils/URIUtils.h"
30 #include <vector>
31 #include "utils/log.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;
67       path.Format("androidapp://%s/%s/%s", url.GetHostName(), dirname,  applications[i].packageName);
68       pItem->SetPath(path);
69       pItem->SetLabel(applications[i].packageLabel);
70       pItem->SetThumbnailImage(path+".png");
71       items.Add(pItem);
72     }
73     return true;
74   }
75
76   CLog::Log(LOGERROR, "CAndroidAppDirectory::GetDirectory Failed to open %s",strPath.c_str());
77   return false;
78 }
79
80 bool CAndroidAppDirectory::IsAllowed(const CStdString& strFile) const
81 {
82   // Entries are virtual, so we want them all.
83   return true;
84 }
85
86 #endif