2 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
21 #include "IDirectory.h"
23 #include "dialogs/GUIDialogOK.h"
24 #include "guilib/GUIKeyboardFactory.h"
26 #include "PasswordManager.h"
27 #include "utils/URIUtils.h"
29 using namespace XFILE;
31 IDirectory::IDirectory(void)
34 m_flags = DIR_FLAG_DEFAULTS;
37 IDirectory::~IDirectory(void)
41 \brief Test if file have an allowed extension, as specified with SetMask()
42 \param strFile File to test
43 \return \e true if file is allowed
44 \note If extension is ".ifo", filename format must be "vide_ts.ifo" or
45 "vts_##_0.ifo". If extension is ".dat", filename format must be
46 "AVSEQ##(#).DAT", "ITEM###(#).DAT" or "MUSIC##(#).DAT".
48 bool IDirectory::IsAllowed(const CStdString& strFile) const
50 if (m_strFileMask.empty() || strFile.empty())
53 // Check if strFile have an allowed extension
54 if (!URIUtils::HasExtension(strFile, m_strFileMask))
57 // We should ignore all non dvd/vcd related ifo and dat files.
58 if (URIUtils::HasExtension(strFile, ".ifo"))
60 CStdString fileName = URIUtils::GetFileName(strFile);
62 // Allow filenames of the form video_ts.ifo or vts_##_0.ifo
64 return StringUtils::EqualsNoCase(fileName, "video_ts.ifo") ||
65 (fileName.length() == 12 &&
66 StringUtils::StartsWithNoCase(fileName, "vts_") &&
67 StringUtils::EndsWithNoCase(fileName, "_0.ifo"));
70 if (URIUtils::HasExtension(strFile, ".dat"))
72 CStdString fileName = URIUtils::GetFileName(strFile);
74 // Allow filenames of the form AVSEQ##(#).DAT, ITEM###(#).DAT
76 return (fileName.length() == 11 || fileName.length() == 12) &&
77 (StringUtils::StartsWithNoCase(fileName, "AVSEQ") ||
78 StringUtils::StartsWithNoCase(fileName, "MUSIC") ||
79 StringUtils::StartsWithNoCase(fileName, "ITEM"));
86 \brief Set a mask of extensions for the files in the directory.
87 \param strMask Mask of file extensions that are allowed.
89 The mask has to look like the following: \n
93 So only *.m4a, *.flac, *.aac files will be retrieved with GetDirectory().
95 void IDirectory::SetMask(const CStdString& strMask)
97 m_strFileMask = strMask;
98 // ensure it's completed with a | so that filtering is easy.
99 StringUtils::ToLower(m_strFileMask);
100 if (m_strFileMask.size() && m_strFileMask[m_strFileMask.size() - 1] != '|')
101 m_strFileMask += '|';
105 \brief Set the flags for this directory handler.
106 \param flags - \sa XFILE::DIR_FLAG for a description.
108 void IDirectory::SetFlags(int flags)
113 bool IDirectory::ProcessRequirements()
115 CStdString type = m_requirements["type"].asString();
116 if (type == "keyboard")
119 if (CGUIKeyboardFactory::ShowAndGetInput(input, m_requirements["heading"], false))
121 m_requirements["input"] = input;
125 else if (type == "authenticate")
127 CURL url(m_requirements["url"].asString());
128 if (CPasswordManager::GetInstance().PromptToAuthenticateURL(url))
130 m_requirements.clear();
134 else if (type == "error")
136 CGUIDialogOK::ShowAndGetInput(m_requirements["heading"], m_requirements["line1"], m_requirements["line2"], m_requirements["line3"]);
138 m_requirements.clear();
142 bool IDirectory::GetKeyboardInput(const CVariant &heading, CStdString &input)
144 if (!m_requirements["input"].asString().empty())
146 input = m_requirements["input"].asString();
149 m_requirements.clear();
150 m_requirements["type"] = "keyboard";
151 m_requirements["heading"] = heading;
155 void IDirectory::SetErrorDialog(const CVariant &heading, const CVariant &line1, const CVariant &line2, const CVariant &line3)
157 m_requirements.clear();
158 m_requirements["type"] = "error";
159 m_requirements["heading"] = heading;
160 m_requirements["line1"] = line1;
161 m_requirements["line2"] = line2;
162 m_requirements["line3"] = line3;
165 void IDirectory::RequireAuthentication(const CStdString &url)
167 m_requirements.clear();
168 m_requirements["type"] = "authenticate";
169 m_requirements["url"] = url;