add IFileItemListModifier interface and CSmartPlaylistFileItemListModifier implementation
authormontellese <montellese@xbmc.org>
Tue, 6 Aug 2013 14:13:51 +0000 (16:13 +0200)
committermontellese <montellese@xbmc.org>
Sun, 3 Nov 2013 09:05:15 +0000 (10:05 +0100)
xbmc/IFileItemListModifier.h [new file with mode: 0644]
xbmc/playlists/Makefile
xbmc/playlists/SmartPlaylistFileItemListModifier.cpp [new file with mode: 0644]
xbmc/playlists/SmartPlaylistFileItemListModifier.h [new file with mode: 0644]

diff --git a/xbmc/IFileItemListModifier.h b/xbmc/IFileItemListModifier.h
new file mode 100644 (file)
index 0000000..446af53
--- /dev/null
@@ -0,0 +1,32 @@
+#pragma once
+/*
+ *      Copyright (C) 2013 Team XBMC
+ *      http://xbmc.org
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with XBMC; see the file COPYING.  If not, see
+ *  <http://www.gnu.org/licenses/>.
+ *
+ */
+
+class CFileItemList;
+
+class IFileItemListModifier
+{
+public:
+  IFileItemListModifier() { }
+  virtual ~IFileItemListModifier() { }
+
+  virtual bool CanModify(const CFileItemList &items) const = 0;
+  virtual bool Modify(CFileItemList &items) const = 0;
+};
index 69dfb6e..afa879d 100644 (file)
@@ -6,7 +6,8 @@ SRCS=PlayListB4S.cpp \
      PlayListURL.cpp \
      PlayListWPL.cpp \
      PlayListXML.cpp \
-     SmartPlayList.cpp
+     SmartPlayList.cpp \
+     SmartPlaylistFileItemListModifier.cpp
 
 LIB=playlists.a
 
diff --git a/xbmc/playlists/SmartPlaylistFileItemListModifier.cpp b/xbmc/playlists/SmartPlaylistFileItemListModifier.cpp
new file mode 100644 (file)
index 0000000..3a944e5
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ *      Copyright (C) 2013 Team XBMC
+ *      http://xbmc.org
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with XBMC; see the file COPYING.  If not, see
+ *  <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <map>
+
+#include "SmartPlaylistFileItemListModifier.h"
+#include "FileItem.h"
+#include "URL.h"
+#include "playlists/SmartPlayList.h"
+#include "utils/StringUtils.h"
+
+#define URL_OPTION_XSP              "xsp"
+#define PROPERTY_SORT_ORDER         "sort.order"
+#define PROPERTY_SORT_ASCENDING     "sort.ascending"
+using namespace std;
+
+bool CSmartPlaylistFileItemListModifier::CanModify(const CFileItemList &items) const
+{
+  return !GetUrlOption(items.GetPath(), URL_OPTION_XSP).empty();
+}
+
+bool CSmartPlaylistFileItemListModifier::Modify(CFileItemList &items) const
+{
+  if (items.HasProperty(PROPERTY_SORT_ORDER))
+    return false;
+
+  std::string xspOption = GetUrlOption(items.GetPath(), URL_OPTION_XSP);
+  if (xspOption.empty())
+    return false;
+
+  // check for smartplaylist-specific sorting information
+  CSmartPlaylist xsp;
+  if (!xsp.LoadFromJson(xspOption))
+    return false;
+
+  items.SetProperty(PROPERTY_SORT_ORDER, (int)xsp.GetOrder());
+  items.SetProperty(PROPERTY_SORT_ASCENDING, xsp.GetOrderDirection() == SortOrderAscending);
+
+  return true;
+}
+
+std::string CSmartPlaylistFileItemListModifier::GetUrlOption(const std::string &path, const std::string &option)
+{
+  if (path.empty() || option.empty())
+    return StringUtils::Empty;
+
+  CURL url(path);
+  return url.GetOption(option);
+}
diff --git a/xbmc/playlists/SmartPlaylistFileItemListModifier.h b/xbmc/playlists/SmartPlaylistFileItemListModifier.h
new file mode 100644 (file)
index 0000000..5db6216
--- /dev/null
@@ -0,0 +1,37 @@
+#pragma once
+/*
+ *      Copyright (C) 2013 Team XBMC
+ *      http://xbmc.org
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with XBMC; see the file COPYING.  If not, see
+ *  <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <string>
+
+#include "IFileItemListModifier.h"
+
+class CSmartPlaylistFileItemListModifier : public IFileItemListModifier
+{
+public:
+  CSmartPlaylistFileItemListModifier() { }
+  virtual ~CSmartPlaylistFileItemListModifier() { }
+
+  virtual bool CanModify(const CFileItemList &items) const;
+  virtual bool Modify(CFileItemList &items) const;
+
+private:
+  static std::string GetUrlOption(const std::string &path, const std::string &option);
+};