[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / filesystem / PluginDirectory.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://www.xbmc.org
5  *
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)
9  *  any later version.
10  *
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.
15  *
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/>.
19  *
20  */
21
22 #include "IDirectory.h"
23 #include "Directory.h"
24 #include "utils/StdString.h"
25 #include "SortFileItem.h"
26
27 #include <string>
28 #include <map>
29 #include "threads/CriticalSection.h"
30 #include "addons/IAddon.h"
31 #include "PlatformDefs.h"
32
33 #include "threads/Event.h"
34
35 class CURL;
36 class CFileItemList;
37
38 namespace XFILE
39 {
40
41 class CPluginDirectory : public IDirectory
42 {
43 public:
44   CPluginDirectory();
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);
53
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);  
65
66 private:
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);
70
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;
77
78   CFileItemList* m_listItems;
79   CFileItem*     m_fileResult;
80   CEvent         m_fetchComplete;
81
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
85 };
86 }