json-rpc: fix resetting a datetime property through VideoLibrary.SetFooDetails
authormontellese <montellese@xbmc.org>
Wed, 12 Mar 2014 08:02:01 +0000 (09:02 +0100)
committermontellese <montellese@xbmc.org>
Thu, 13 Mar 2014 06:55:55 +0000 (07:55 +0100)
xbmc/interfaces/json-rpc/JSONUtils.h
xbmc/interfaces/json-rpc/VideoLibrary.cpp

index 6565775..5c8165c 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdlib.h>
 
 #include "JSONRPCUtils.h"
+#include "XBDateTime.h"
 #include "utils/SortUtils.h"
 #include "interfaces/IAnnouncer.h"
 #include "playlists/SmartPlayList.h"
@@ -519,6 +520,28 @@ namespace JSONRPC
         stringArray.push_back(it->asString());
     }
 
+    static void SetFromDBDate(const CVariant &jsonDate, CDateTime &date)
+    {
+      if (!jsonDate.isString())
+        return;
+
+      if (jsonDate.empty())
+        date.Reset();
+      else
+        date.SetFromDBDate(jsonDate.asString());
+    }
+
+    static void SetFromDBDateTime(const CVariant &jsonDate, CDateTime &date)
+    {
+      if (!jsonDate.isString())
+        return;
+
+      if (jsonDate.empty())
+        date.Reset();
+      else
+        date.SetFromDBDateTime(jsonDate.asString());
+    }
+
     static bool GetXspFiltering(const CStdString &type, const CVariant &filter, CStdString &xsp)
     {
       if (type.empty() || !filter.isObject())
index fe5bca2..36578a6 100644 (file)
@@ -507,7 +507,7 @@ JSONRPC_STATUS CVideoLibrary::SetMovieDetails(const CStdString &method, ITranspo
     // restore original playcount or the new one won't be announced
     int newPlaycount = infos.m_playCount;
     infos.m_playCount = playcount;
-    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed.IsValid() ? infos.m_lastPlayed : CDateTime::GetCurrentDateTime());
+    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed);
   }
 
   UpdateResumePoint(parameterObject, infos, videodatabase);
@@ -662,7 +662,7 @@ JSONRPC_STATUS CVideoLibrary::SetEpisodeDetails(const CStdString &method, ITrans
     // restore original playcount or the new one won't be announced
     int newPlaycount = infos.m_playCount;
     infos.m_playCount = playcount;
-    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed.IsValid() ? infos.m_lastPlayed : CDateTime::GetCurrentDateTime());
+    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed);
   }
 
   UpdateResumePoint(parameterObject, infos, videodatabase);
@@ -712,7 +712,7 @@ JSONRPC_STATUS CVideoLibrary::SetMusicVideoDetails(const CStdString &method, ITr
     // restore original playcount or the new one won't be announced
     int newPlaycount = infos.m_playCount;
     infos.m_playCount = playcount;
-    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed.IsValid() ? infos.m_lastPlayed : CDateTime::GetCurrentDateTime());
+    videodatabase.SetPlayCount(CFileItem(infos), newPlaycount, infos.m_lastPlayed);
   }
 
   UpdateResumePoint(parameterObject, infos, videodatabase);
@@ -1012,13 +1012,13 @@ void CVideoLibrary::UpdateVideoTag(const CVariant &parameterObject, CVideoInfoTa
   if (ParameterNotNull(parameterObject, "imdbnumber"))
     details.m_strIMDBNumber = parameterObject["imdbnumber"].asString();
   if (ParameterNotNull(parameterObject, "premiered"))
-    details.m_premiered.SetFromDBDate(parameterObject["premiered"].asString());
+    SetFromDBDate(parameterObject["premiered"], details.m_premiered);
   if (ParameterNotNull(parameterObject, "votes"))
     details.m_strVotes = parameterObject["votes"].asString();
   if (ParameterNotNull(parameterObject, "lastplayed"))
-    details.m_lastPlayed.SetFromDBDateTime(parameterObject["lastplayed"].asString());
+    SetFromDBDateTime(parameterObject["lastplayed"], details.m_lastPlayed);
   if (ParameterNotNull(parameterObject, "firstaired"))
-    details.m_firstAired.SetFromDBDateTime(parameterObject["firstaired"].asString());
+    SetFromDBDateTime(parameterObject["firstaired"], details.m_firstAired);
   if (ParameterNotNull(parameterObject, "productioncode"))
     details.m_strProductionCode = parameterObject["productioncode"].asString();
   if (ParameterNotNull(parameterObject, "season"))