Merge pull request #1150 from Montellese/gsoc_videodb_ext_urls
[vuplus_xbmc] / xbmc / DbUrl.cpp
1 /*
2  *      Copyright (C) 2012 Team XBMC
3  *      http://www.xbmc.org
4  *
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)
8  *  any later version.
9  *
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.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19
20 #include <sstream>
21
22 #include "DbUrl.h"
23 #include "utils/StringUtils.h"
24 #include "utils/URIUtils.h"
25
26 using namespace std;
27
28 CDbUrl::CDbUrl()
29 {
30   Reset();
31 }
32
33 CDbUrl::~CDbUrl()
34 { }
35
36 void CDbUrl::Reset()
37 {
38   m_valid = false;
39   m_type.clear();
40   m_url.Reset();
41   m_options.clear();
42 }
43
44 std::string CDbUrl::ToString() const
45 {
46   if (!m_valid)
47     return "";
48
49   return m_url.Get();
50 }
51
52 bool CDbUrl::FromString(const std::string &dbUrl)
53 {
54   Reset();
55
56   m_url.Parse(dbUrl);
57   m_valid = parse();
58
59   if (!m_valid)
60     Reset();
61
62   return m_valid;
63 }
64
65 void CDbUrl::AppendPath(const std::string &subPath)
66 {
67   if (!m_valid || subPath.empty())
68     return;
69
70   m_url.SetFileName(URIUtils::AddFileToFolder(m_url.GetFileName(), subPath));
71 }
72
73 void CDbUrl::updateOptions()
74 {
75   // Update the options string in the CURL object
76   string options = GetOptionsString();
77   if (!options.empty())
78     options = "?" + options;
79
80   m_url.SetOptions(options);
81 }