Skip to content
Browse files

allow key-only URL options and add CUrlOptions::RemoveOption()

  • Loading branch information...
1 parent 2546383 commit 26acb13d2ecbc4336e3bf2fab97202017f296880 @Montellese Montellese committed
View
6 xbmc/DbUrl.cpp
@@ -130,6 +130,12 @@ void CDbUrl::AddOptions(const std::string &options)
updateOptions();
}
+void CDbUrl::RemoveOption(const std::string &key)
+{
+ CUrlOptions::RemoveOption(key);
+ updateOptions();
+}
+
bool CDbUrl::validateOption(const std::string &key, const CVariant &value)
{
if (key.empty())
View
1 xbmc/DbUrl.h
@@ -46,6 +46,7 @@ class CDbUrl : public CUrlOptions
virtual void AddOption(const std::string &key, double value);
virtual void AddOption(const std::string &key, bool value);
virtual void AddOptions(const std::string &options);
+ virtual void RemoveOption(const std::string &key);
protected:
virtual bool parse() = 0;
View
2 xbmc/URL.cpp
@@ -801,6 +801,6 @@ void CURL::SetOption(const CStdString &key, const CStdString &value)
void CURL::RemoveOption(const CStdString &key)
{
- m_options.AddOption(key, "");
+ m_options.RemoveOption(key);
SetOptions(m_options.GetOptionsString(true));
}
View
2 xbmc/dialogs/GUIDialogMediaFilter.cpp
@@ -617,7 +617,7 @@ bool CGUIDialogMediaFilter::SetPath(const std::string &path)
// remove "filter" option
if (m_dbUrl->HasOption("filter"))
- m_dbUrl->AddOption("filter", "");
+ m_dbUrl->RemoveOption("filter");
if (video)
m_mediaType = ((CVideoDbUrl*)m_dbUrl)->GetItemType();
View
30 xbmc/filesystem/SmartPlaylistDirectory.cpp
@@ -111,7 +111,11 @@ namespace XFILE
if (!playlist.SaveAsJson(xsp, !filter))
return false;
}
- videoUrl.AddOption(option, xsp);
+
+ if (!xsp.empty())
+ videoUrl.AddOption(option, xsp);
+ else
+ videoUrl.RemoveOption(option);
CDatabase::Filter dbfilter;
success = db.GetSortedVideos(mediaType, videoUrl.ToString(), sorting, items, dbfilter);
@@ -140,7 +144,11 @@ namespace XFILE
if (!playlist.SaveAsJson(xsp, !filter))
return false;
}
- musicUrl.AddOption(option, xsp);
+
+ if (!xsp.empty())
+ musicUrl.AddOption(option, xsp);
+ else
+ musicUrl.RemoveOption(option);
CDatabase::Filter dbfilter;
success = db.GetAlbumsByWhere(musicUrl.ToString(), dbfilter, items, sorting);
@@ -165,7 +173,11 @@ namespace XFILE
if (!playlist.SaveAsJson(xsp, !filter))
return false;
}
- musicUrl.AddOption(option, xsp);
+
+ if (!xsp.empty())
+ musicUrl.AddOption(option, xsp);
+ else
+ musicUrl.RemoveOption(option);
CDatabase::Filter dbfilter;
success = db.GetArtistsNav(musicUrl.ToString(), items, !g_guiSettings.GetBool("musiclibrary.showcompilationartists"), -1, -1, -1, dbfilter, sorting);
@@ -195,7 +207,11 @@ namespace XFILE
if (!songPlaylist.SaveAsJson(xsp, !filter))
return false;
}
- musicUrl.AddOption(option, xsp);
+
+ if (!xsp.empty())
+ musicUrl.AddOption(option, xsp);
+ else
+ musicUrl.RemoveOption(option);
CDatabase::Filter dbfilter;
success = db.GetSongsByWhere(musicUrl.ToString(), dbfilter, items, sorting);
@@ -224,7 +240,11 @@ namespace XFILE
if (!mvidPlaylist.SaveAsJson(xsp, !filter))
return false;
}
- videoUrl.AddOption(option, xsp);
+
+ if (!xsp.empty())
+ videoUrl.AddOption(option, xsp);
+ else
+ videoUrl.RemoveOption(option);
CFileItemList items2;
success2 = db.GetSortedVideos(MediaTypeMusicVideo, videoUrl.ToString(), sorting, items2);
View
2 xbmc/music/MusicDatabase.cpp
@@ -5445,7 +5445,7 @@ bool CMusicDatabase::GetFilter(CDbUrl &musicUrl, Filter &filter, SortDescription
}
// remove the filter if it doesn't match the item type
else
- musicUrl.AddOption("filter", "");
+ musicUrl.RemoveOption("filter");
}
return true;
View
31 xbmc/utils/UrlOptions.cpp
@@ -46,7 +46,9 @@ std::string CUrlOptions::GetOptionsString(bool withLeadingSeperator /* = false *
if (opt != m_options.begin())
options += "&";
- options += CURL::Encode(opt->first) + "=" + CURL::Encode(opt->second.asString());
+ options += CURL::Encode(opt->first);
+ if (!opt->second.empty())
+ options += "=" + CURL::Encode(opt->second.asString());
}
if (withLeadingSeperator && !options.empty())
@@ -68,11 +70,7 @@ void CUrlOptions::AddOption(const std::string &key, const std::string &value)
if (key.empty())
return;
- UrlOptions::iterator option = m_options.find(key);
- if (!value.empty())
- m_options[key] = value;
- else if (option != m_options.end())
- m_options.erase(option);
+ m_options[key] = value;
}
void CUrlOptions::AddOption(const std::string &key, int value)
@@ -130,13 +128,12 @@ void CUrlOptions::AddOptions(const std::string &options)
if (option->empty())
continue;
- // every option must have the format key=value
- size_t pos = option->find('=');
- if (pos == string::npos || pos == 0 || pos >= option->size() - 1)
- continue;
+ string key, value;
- string key = CURL::Decode(option->substr(0, pos));
- string value = CURL::Decode(option->substr(pos + 1));
+ size_t pos = option->find('=');
+ key = CURL::Decode(option->substr(0, pos));
+ if (pos != string::npos)
+ value = CURL::Decode(option->substr(pos + 1));
// the key cannot be empty
if (!key.empty())
@@ -149,6 +146,16 @@ void CUrlOptions::AddOptions(const CUrlOptions &options)
m_options.insert(options.m_options.begin(), options.m_options.end());
}
+void CUrlOptions::RemoveOption(const std::string &key)
+{
+ if (key.empty())
+ return;
+
+ UrlOptions::iterator option = m_options.find(key);
+ if (option != m_options.end())
+ m_options.erase(option);
+}
+
bool CUrlOptions::HasOption(const std::string &key) const
{
if (key.empty())
View
1 xbmc/utils/UrlOptions.h
@@ -45,6 +45,7 @@ class CUrlOptions
virtual void AddOption(const std::string &key, bool value);
virtual void AddOptions(const std::string &options);
virtual void AddOptions(const CUrlOptions &options);
+ virtual void RemoveOption(const std::string &key);
virtual bool HasOption(const std::string &key) const;
virtual bool GetOption(const std::string &key, CVariant &value) const;
View
2 xbmc/video/VideoDatabase.cpp
@@ -9327,7 +9327,7 @@ bool CVideoDatabase::GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription
}
// remove the filter if it doesn't match the item type
else
- videoUrl.AddOption("filter", "");
+ videoUrl.RemoveOption("filter");
}
return true;

0 comments on commit 26acb13

Please sign in to comment.
Something went wrong with that request. Please try again.