Permalink
Browse files

jsonrpc: add (Video|Audio)Playlist.Swap (fixes #11046)

  • Loading branch information...
1 parent 6408c25 commit 63cba75a76563554d10bda3a56eb4e5819d158e5 @Montellese Montellese committed Jun 30, 2011
@@ -582,6 +582,16 @@ case TMSG_POWERDOWN:
}
break;
+ case TMSG_PLAYLISTPLAYER_SWAP:
+ if (pMsg->lpVoid)
+ {
+ vector<int> *indexes = (vector<int> *)pMsg->lpVoid;
+ if (indexes->size() == 2)
+ g_playlistPlayer.Swap(pMsg->dwParam1, indexes->at(0), indexes->at(1));
+ delete indexes;
+ }
+ break;
+
// Window messages below here...
case TMSG_DIALOG_DOMODAL: //doModel of window
{
@@ -932,6 +942,17 @@ void CApplicationMessenger::PlayListPlayerGetItems(int playlist, CFileItemList &
SendMessage(tMsg, true);
}
+void CApplicationMessenger::PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2)
+{
+ ThreadMessage tMsg = {TMSG_PLAYLISTPLAYER_SWAP};
+ tMsg.dwParam1 = playlist;
+ vector<int> *indexes = new vector<int>();
+ indexes->push_back(indexItem1);
+ indexes->push_back(indexItem2);
+ tMsg.lpVoid = (void *)indexes;
+ SendMessage(tMsg, true);
+}
+
void CApplicationMessenger::PictureShow(string filename)
{
ThreadMessage tMsg = {TMSG_PICTURE_SHOW};
@@ -55,6 +55,7 @@ class CGUIDialog;
#define TMSG_PLAYLISTPLAYER_PLAY_SONG_ID 217
#define TMSG_PLAYLISTPLAYER_INSERT 218
#define TMSG_PLAYLISTPLAYER_REMOVE 219
+#define TMSG_PLAYLISTPLAYER_SWAP 223
#define TMSG_PICTURE_SHOW 220
#define TMSG_PICTURE_SLIDESHOW 221
@@ -155,6 +156,7 @@ class CApplicationMessenger
void PlayListPlayerInsert(int playlist, const CFileItem &item, int position);
void PlayListPlayerInsert(int playlist, const CFileItemList &list, int position);
void PlayListPlayerRemove(int playlist, int position);
+ void PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2);
void PlayFile(const CFileItem &item, bool bRestart = false); // thread safe version of g_application.PlayFile()
void PictureShow(std::string filename);
View
@@ -592,3 +592,16 @@ void CPlayListPlayer::Clear()
if (m_PlaylistEmpty)
m_PlaylistEmpty->Clear();
}
+
+void CPlayListPlayer::Swap(int iPlaylist, int indexItem1, int indexItem2)
+{
+ if (iPlaylist != PLAYLIST_MUSIC && iPlaylist != PLAYLIST_VIDEO)
+ return;
+
+ CPlayList& list = GetPlaylist(iPlaylist);
+ list.Swap(indexItem1, indexItem2);
+
+ // its likely that the playlist changed
+ CGUIMessage msg(GUI_MSG_PLAYLIST_CHANGED, 0, 0);
+ g_windowManager.SendMessage(msg);
+}
View
@@ -154,6 +154,7 @@ class CPlayListPlayer : public IMsgTargetCallback
void Insert(int iPlaylist, const CFileItemPtr &pItem, int iIndex);
void Insert(int iPlaylist, CFileItemList& items, int iIndex);
void Remove(int iPlaylist, int iPosition);
+ void Swap(int iPlaylist, int indexItem1, int indexItem2);
protected:
/*! \brief Returns true if the given is set to repeat all
\param playlist Playlist to be query
@@ -163,6 +163,14 @@ JSON_STATUS CAVPlaylistOperations::UnShuffle(const CStdString &method, ITranspor
return ACK;
}
+JSON_STATUS CAVPlaylistOperations::Swap(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result)
+{
+ g_application.getApplicationMessenger().PlayListPlayerSwap(GetPlaylist(method), (int)parameterObject["item1"].asInteger(), (int)parameterObject["item2"].asInteger());
+
+ NotifyAll();
+ return ACK;
+}
+
int CAVPlaylistOperations::GetPlaylist(const CStdString &method)
{
CStdString methodStart = method.Left(5);
@@ -41,6 +41,7 @@ namespace JSONRPC
static JSON_STATUS Clear(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS Shuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
static JSON_STATUS UnShuffle(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
+ static JSON_STATUS Swap(const CStdString &method, ITransportLayer *transport, IClient *client, const CVariant &parameterObject, CVariant &result);
private:
static inline int GetPlaylist(const CStdString &method);
static inline void NotifyAll();
@@ -157,6 +157,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "VideoPlaylist.Shuffle", CAVPlaylistOperations::Shuffle },
{ "VideoPlaylist.UnShuffle", CAVPlaylistOperations::UnShuffle },
{ "VideoPlaylist.Remove", CAVPlaylistOperations::Remove },
+ { "VideoPlaylist.Swap", CAVPlaylistOperations::Swap },
// AudioPlaylist
{ "AudioPlaylist.Play", CAVPlaylistOperations::Play },
@@ -169,6 +170,7 @@ JsonRpcMethodMap CJSONServiceDescription::m_methodMaps[] = {
{ "AudioPlaylist.Shuffle", CAVPlaylistOperations::Shuffle },
{ "AudioPlaylist.UnShuffle", CAVPlaylistOperations::UnShuffle },
{ "AudioPlaylist.Remove", CAVPlaylistOperations::Remove },
+ { "AudioPlaylist.Swap", CAVPlaylistOperations::Swap },
// Playlist
{ "Playlist.Create", CPlaylistOperations::Create },
@@ -1410,6 +1410,17 @@ namespace JSONRPC
"\"params\": [ ],"
"\"returns\": \"string\""
"}",
+ "\"VideoPlaylist.Swap\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Swap items in the playlist\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": ["
+ "{ \"name\": \"item1\", \"$ref\": \"Playlist.Item.Position\", \"required\": true },"
+ "{ \"name\": \"item2\", \"$ref\": \"Playlist.Item.Position\", \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
"\"AudioPlaylist.Play\": {"
"\"type\": \"method\","
"\"description\": \"Play current or a specific item\","
@@ -1514,6 +1525,17 @@ namespace JSONRPC
"\"params\": [ ],"
"\"returns\": \"string\""
"}",
+ "\"AudioPlaylist.Swap\": {"
+ "\"type\": \"method\","
+ "\"description\": \"Swap items in the playlist\","
+ "\"transport\": \"Response\","
+ "\"permission\": \"ControlPlayback\","
+ "\"params\": ["
+ "{ \"name\": \"item1\", \"$ref\": \"Playlist.Item.Position\", \"required\": true },"
+ "{ \"name\": \"item2\", \"$ref\": \"Playlist.Item.Position\", \"required\": true }"
+ "],"
+ "\"returns\": \"string\""
+ "}",
"\"Files.GetSources\": {"
"\"type\": \"method\","
"\"description\": \"Get the sources of the media windows\","
@@ -652,6 +652,17 @@
"params": [ ],
"returns": "string"
},
+ "VideoPlaylist.Swap": {
+ "type": "method",
+ "description": "Swap items in the playlist",
+ "transport": "Response",
+ "permission": "ControlPlayback",
+ "params": [
+ { "name": "item1", "$ref": "Playlist.Item.Position", "required": true },
+ { "name": "item2", "$ref": "Playlist.Item.Position", "required": true }
+ ],
+ "returns": "string"
+ },
"AudioPlaylist.Play": {
"type": "method",
"description": "Play current or a specific item",
@@ -756,6 +767,17 @@
"params": [ ],
"returns": "string"
},
+ "AudioPlaylist.Swap": {
+ "type": "method",
+ "description": "Swap items in the playlist",
+ "transport": "Response",
+ "permission": "ControlPlayback",
+ "params": [
+ { "name": "item1", "$ref": "Playlist.Item.Position", "required": true },
+ { "name": "item2", "$ref": "Playlist.Item.Position", "required": true }
+ ],
+ "returns": "string"
+ },
"Files.GetSources": {
"type": "method",
"description": "Get the sources of the media windows",

0 comments on commit 63cba75

Please sign in to comment.