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 a file for an extension specified with SetMask().
43 \param strFile File to test
44 \return Returns \e true, if file is allowed.
46 bool IDirectory::IsAllowed(const CStdString& strFile) const
48 CStdString strExtension;
49 if ( !m_strFileMask.size() ) return true;
50 if ( !strFile.size() ) return true;
52 URIUtils::GetExtension(strFile, strExtension);
54 if (!strExtension.size()) return false;
56 strExtension.ToLower();
57 strExtension += '|'; // ensures that we have a | at the end of it
58 if (m_strFileMask.Find(strExtension) != -1)
59 { // it's allowed, but we should also ignore all non dvd related ifo files.
60 if (strExtension.Equals(".ifo|"))
62 CStdString fileName = URIUtils::GetFileName(strFile);
63 if (fileName.Equals("video_ts.ifo")) return true;
64 if (fileName.length() == 12 && fileName.Left(4).Equals("vts_") && fileName.Right(6).Equals("_0.ifo")) return true;
67 if (strExtension.Equals(".dat|"))
69 CStdString fileName = URIUtils::GetFileName(strFile);
70 /* VCD filenames are of the form AVSEQ##(#).DAT, ITEM###(#).DAT, MUSIC##(#).DAT - i.e. all 11 or 12 characters long
71 starting with AVSEQ, MUSIC or ITEM */
72 if ((fileName.length() == 11 || fileName.length() == 12) &&
73 (fileName.Left(5).Equals("AVSEQ") || fileName.Left(5).Equals("MUSIC") || fileName.Left(4).Equals("ITEM")))
83 \brief Set a mask of extensions for the files in the directory.
84 \param strMask Mask of file extensions that are allowed.
86 The mask has to look like the following: \n
90 So only *.m4a, *.flac, *.aac files will be retrieved with GetDirectory().
92 void IDirectory::SetMask(const CStdString& strMask)
94 m_strFileMask = strMask;
95 // ensure it's completed with a | so that filtering is easy.
96 m_strFileMask.ToLower();
97 if (m_strFileMask.size() && m_strFileMask[m_strFileMask.size() - 1] != '|')
102 \brief Set the flags for this directory handler.
103 \param flags - \sa XFILE::DIR_FLAG for a description.
105 void IDirectory::SetFlags(int flags)
110 bool IDirectory::ProcessRequirements()
112 CStdString type = m_requirements["type"].asString();
113 if (type == "keyboard")
116 if (CGUIKeyboardFactory::ShowAndGetInput(input, m_requirements["heading"], false))
118 m_requirements["input"] = input;
122 else if (type == "authenticate")
124 CURL url(m_requirements["url"].asString());
125 if (CPasswordManager::GetInstance().PromptToAuthenticateURL(url))
127 m_requirements.clear();
131 else if (type == "error")
133 CGUIDialogOK::ShowAndGetInput(m_requirements["heading"], m_requirements["line1"], m_requirements["line2"], m_requirements["line3"]);
135 m_requirements.clear();
139 bool IDirectory::GetKeyboardInput(const CVariant &heading, CStdString &input)
141 if (!CStdString(m_requirements["input"].asString()).IsEmpty())
143 input = m_requirements["input"].asString();
146 m_requirements.clear();
147 m_requirements["type"] = "keyboard";
148 m_requirements["heading"] = heading;
152 void IDirectory::SetErrorDialog(const CVariant &heading, const CVariant &line1, const CVariant &line2, const CVariant &line3)
154 m_requirements.clear();
155 m_requirements["type"] = "error";
156 m_requirements["heading"] = heading;
157 m_requirements["line1"] = line1;
158 m_requirements["line2"] = line2;
159 m_requirements["line3"] = line3;
162 void IDirectory::RequireAuthentication(const CStdString &url)
164 m_requirements.clear();
165 m_requirements["type"] = "authenticate";
166 m_requirements["url"] = url;