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/>.
22 #include "IDirectory.h"
24 #include "dialogs/GUIDialogOK.h"
25 #include "guilib/GUIKeyboardFactory.h"
27 #include "PasswordManager.h"
28 #include "utils/URIUtils.h"
30 using namespace XFILE;
32 IDirectory::IDirectory(void)
35 m_flags = DIR_FLAG_DEFAULTS;
38 IDirectory::~IDirectory(void)
42 \brief Test if file have an allowed extension, as specified with SetMask()
43 \param strFile File to test
44 \return \e true if file is allowed
45 \note If extension is ".ifo", filename format must be "vide_ts.ifo" or
46 "vts_##_0.ifo". If extension is ".dat", filename format must be
47 "AVSEQ##(#).DAT", "ITEM###(#).DAT" or "MUSIC##(#).DAT".
49 bool IDirectory::IsAllowed(const CStdString& strFile) const
51 if (m_strFileMask.empty() || strFile.empty())
54 // Check if strFile have an allowed extension
55 if (!URIUtils::HasExtension(strFile, m_strFileMask))
58 // We should ignore all non dvd/vcd related ifo and dat files.
59 if (URIUtils::HasExtension(strFile, ".ifo"))
61 CStdString fileName = URIUtils::GetFileName(strFile);
63 // Allow filenames of the form video_ts.ifo or vts_##_0.ifo
64 return fileName.CompareNoCase("video_ts.ifo") == 0 ||
65 (fileName.length() == 12 && fileName.Left(4).CompareNoCase("vts_") == 0 &&
66 fileName.Right(6).CompareNoCase("_0.ifo") == 0);
69 if (URIUtils::HasExtension(strFile, ".dat"))
71 CStdString fileName = URIUtils::GetFileName(strFile);
73 // Allow filenames of the form AVSEQ##(#).DAT, ITEM###(#).DAT
75 return (fileName.length() == 11 || fileName.length() == 12) &&
76 (fileName.Left(5).CompareNoCase("AVSEQ") == 0 || fileName.Left(5).CompareNoCase("MUSIC") == 0 ||
77 fileName.Left(4).CompareNoCase("ITEM") == 0);
84 \brief Set a mask of extensions for the files in the directory.
85 \param strMask Mask of file extensions that are allowed.
87 The mask has to look like the following: \n
91 So only *.m4a, *.flac, *.aac files will be retrieved with GetDirectory().
93 void IDirectory::SetMask(const CStdString& strMask)
95 m_strFileMask = strMask;
96 // ensure it's completed with a | so that filtering is easy.
97 m_strFileMask.ToLower();
98 if (m_strFileMask.size() && m_strFileMask[m_strFileMask.size() - 1] != '|')
103 \brief Set the flags for this directory handler.
104 \param flags - \sa XFILE::DIR_FLAG for a description.
106 void IDirectory::SetFlags(int flags)
111 bool IDirectory::ProcessRequirements()
113 CStdString type = m_requirements["type"].asString();
114 if (type == "keyboard")
117 if (CGUIKeyboardFactory::ShowAndGetInput(input, m_requirements["heading"], false))
119 m_requirements["input"] = input;
123 else if (type == "authenticate")
125 CURL url(m_requirements["url"].asString());
126 if (CPasswordManager::GetInstance().PromptToAuthenticateURL(url))
128 m_requirements.clear();
132 else if (type == "error")
134 CGUIDialogOK::ShowAndGetInput(m_requirements["heading"], m_requirements["line1"], m_requirements["line2"], m_requirements["line3"]);
136 m_requirements.clear();
140 bool IDirectory::GetKeyboardInput(const CVariant &heading, CStdString &input)
142 if (!CStdString(m_requirements["input"].asString()).IsEmpty())
144 input = m_requirements["input"].asString();
147 m_requirements.clear();
148 m_requirements["type"] = "keyboard";
149 m_requirements["heading"] = heading;
153 void IDirectory::SetErrorDialog(const CVariant &heading, const CVariant &line1, const CVariant &line2, const CVariant &line3)
155 m_requirements.clear();
156 m_requirements["type"] = "error";
157 m_requirements["heading"] = heading;
158 m_requirements["line1"] = line1;
159 m_requirements["line2"] = line2;
160 m_requirements["line3"] = line3;
163 void IDirectory::RequireAuthentication(const CStdString &url)
165 m_requirements.clear();
166 m_requirements["type"] = "authenticate";
167 m_requirements["url"] = url;