3 * Copyright (C) 2005-2012 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 "utils/StdString.h"
23 #include "utils/Variant.h"
31 DIR_CACHE_NEVER = 0, ///< Never cache this directory to memory
32 DIR_CACHE_ONCE, ///< Cache this directory to memory for each fetch (so that FileExists() checks are fast)
33 DIR_CACHE_ALWAYS ///< Always cache this directory to memory, so that each additional fetch of this folder will utilize the cache (until it's cleared)
36 /*! \brief Available directory flags
37 The defaults are to allow file directories, no prompting, retrieve file information, hide hidden files, and utilise the directory cache
38 based on the implementation's wishes.
42 DIR_FLAG_DEFAULTS = 0,
43 DIR_FLAG_NO_FILE_DIRS = (2 << 0), ///< Don't convert files (zip, rar etc.) to directories
44 DIR_FLAG_ALLOW_PROMPT = (2 << 1), ///< Allow prompting for further info (passwords etc.)
45 DIR_FLAG_NO_FILE_INFO = (2 << 2), ///< Don't read additional file info (stat for example)
46 DIR_FLAG_GET_HIDDEN = (2 << 3), ///< Get hidden files
47 DIR_FLAG_READ_CACHE = (2 << 4), ///< Force reading from the directory cache (if available)
48 DIR_FLAG_BYPASS_CACHE = (2 << 5) ///< Completely bypass the directory cache (no reading, no writing)
52 \brief Interface to the directory on a file system.
54 This Interface is retrieved from CDirectoryFactory and can be used to
55 access the directories on a filesystem.
62 virtual ~IDirectory(void);
64 \brief Get the \e items of the directory \e strPath.
65 \param strPath Directory to read.
66 \param items Retrieves the directory entries.
67 \return Returns \e true, if successfull.
70 virtual bool GetDirectory(const CStdString& strPath, CFileItemList &items) = 0;
72 \brief Retrieve the progress of the current directory fetch (if possible).
73 \return the progress as a float in the range 0..100.
74 \sa GetDirectory, CancelDirectory
76 virtual float GetProgress() const { return 0.0f; };
78 \brief Cancel the current directory fetch (if possible).
81 virtual void CancelDirectory() { };
83 \brief Create the directory
84 \param strPath Directory to create.
85 \return Returns \e true, if directory is created or if it already exists
88 virtual bool Create(const char* strPath) { return false; }
90 \brief Check for directory existence
91 \param strPath Directory to check.
92 \return Returns \e true, if directory exists
95 virtual bool Exists(const char* strPath) { return false; }
97 \brief Removes the directory
98 \param strPath Directory to remove.
99 \return Returns \e false if not succesfull
101 virtual bool Remove(const char* strPath) { return false; }
104 \brief Whether this file should be listed
105 \param strFile File to test.
106 \return Returns \e true if the file should be listed
108 virtual bool IsAllowed(const CStdString& strFile) const;
111 \brief How this directory should be cached
112 \param strPath Directory at hand.
113 \return Returns the cache type.
115 virtual DIR_CACHE_TYPE GetCacheType(const CStdString& strPath) const { return DIR_CACHE_ONCE; };
117 void SetMask(const CStdString& strMask);
118 void SetFlags(int flags);
120 /*! \brief Process additional requirements before the directory fetch is performed.
121 Some directory fetches may require authentication, keyboard input etc. The IDirectory subclass
122 should call GetKeyboardInput, SetErrorDialog or RequireAuthentication and then return false
123 from the GetDirectory method. CDirectory will then prompt for input from the user, before
124 re-calling the GetDirectory method.
125 \sa GetKeyboardInput, SetErrorDialog, RequireAuthentication
127 bool ProcessRequirements();
130 /*! \brief Prompt the user for some keyboard input
131 Call this method from the GetDirectory method to retrieve additional input from the user.
132 If this function returns false then no input has been received, and the GetDirectory call
134 \param heading an integer or string heading for the keyboard dialog
135 \param input [out] the returned input (if available).
136 \return true if keyboard input has been received. False if it hasn't.
137 \sa ProcessRequirements
139 bool GetKeyboardInput(const CVariant &heading, CStdString &input);
141 /*! \brief Show an error dialog on failure of GetDirectory call
142 Call this method from the GetDirectory method to set an error message to be shown to the user
143 \param heading an integer or string heading for the error dialog.
144 \param line1 the first line to be displayed (integer or string).
145 \param line2 the first line to be displayed (integer or string).
146 \param line3 the first line to be displayed (integer or string).
147 \sa ProcessRequirements
149 void SetErrorDialog(const CVariant &heading, const CVariant &line1, const CVariant &line2 = 0, const CVariant &line3 = 0);
151 /*! \brief Prompt the user for authentication of a URL.
152 Call this method from the GetDirectory method when authentication is required from the user, before returning
153 false from the GetDirectory call. The user will be prompted for authentication, and GetDirectory will be
155 \param url the URL to authenticate.
156 \sa ProcessRequirements
158 void RequireAuthentication(const CStdString &url);
160 CStdString m_strFileMask; ///< Holds the file mask specified by SetMask()
162 int m_flags; ///< Directory flags - see DIR_FLAG
164 CVariant m_requirements;