3 * Copyright (C) 2005-2013 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #include "IDirectory.h"
23 #include "Directory.h"
24 #include "utils/StdString.h"
25 #include "SortFileItem.h"
29 #include "threads/CriticalSection.h"
30 #include "addons/IAddon.h"
31 #include "PlatformDefs.h"
33 #include "threads/Event.h"
41 class CPluginDirectory : public IDirectory
45 ~CPluginDirectory(void);
46 virtual bool GetDirectory(const CStdString& strPath, CFileItemList& items);
47 virtual bool IsAllowed(const CStdString &strFile) const { return true; };
48 virtual bool Exists(const char* strPath) { return true; }
49 virtual float GetProgress() const;
50 virtual void CancelDirectory();
51 static bool RunScriptWithParams(const CStdString& strPath);
52 static bool GetPluginResult(const CStdString& strPath, CFileItem &resultItem);
54 // callbacks from python
55 static bool AddItem(int handle, const CFileItem *item, int totalItems);
56 static bool AddItems(int handle, const CFileItemList *items, int totalItems);
57 static void EndOfDirectory(int handle, bool success, bool replaceListing, bool cacheToDisc);
58 static void AddSortMethod(int handle, SORT_METHOD sortMethod, const CStdString &label2Mask);
59 static CStdString GetSetting(int handle, const CStdString &key);
60 static void SetSetting(int handle, const CStdString &key, const CStdString &value);
61 static void SetContent(int handle, const CStdString &strContent);
62 static void SetProperty(int handle, const CStdString &strProperty, const CStdString &strValue);
63 static void SetResolvedUrl(int handle, bool success, const CFileItem* resultItem);
64 static void SetLabel2(int handle, const CStdString& ident);
67 ADDON::AddonPtr m_addon;
68 bool StartScript(const CStdString& strPath, bool retrievingDir);
69 bool WaitOnScriptResult(const CStdString &scriptPath, int scriptId, const CStdString &scriptName, bool retrievingDir);
71 static std::map<int,CPluginDirectory*> globalHandles;
72 static int getNewHandle(CPluginDirectory *cp);
73 static void removeHandle(int handle);
74 static CPluginDirectory *dirFromHandle(int handle);
75 static CCriticalSection m_handleLock;
76 static int handleCounter;
78 CFileItemList* m_listItems;
79 CFileItem* m_fileResult;
80 CEvent m_fetchComplete;
82 bool m_cancelled; // set to true when we are cancelled
83 bool m_success; // set by script in EndOfDirectory
84 int m_totalItems; // set by script in AddDirectoryItem