Merge branch 'single_query_playcounts'
[vuplus_xbmc] / xbmc / video / windows / GUIWindowVideoNav.cpp
index 2726c6f..971ff01 100644 (file)
@@ -21,7 +21,6 @@
 
 #include "GUIUserMessages.h"
 #include "GUIWindowVideoNav.h"
-#include "GUIWindowVideoFiles.h"
 #include "music/windows/GUIWindowMusicNav.h"
 #include "utils/FileUtils.h"
 #include "Util.h"
@@ -76,7 +75,6 @@ using namespace std;
 CGUIWindowVideoNav::CGUIWindowVideoNav(void)
     : CGUIWindowVideoBase(WINDOW_VIDEO_NAV, "MyVideoNav.xml")
 {
-  m_vecItems->m_strPath = "?";
   m_thumbLoader.SetObserver(this);
 }
 
@@ -104,7 +102,7 @@ bool CGUIWindowVideoNav::OnMessage(CGUIMessage& message)
   switch (message.GetMessage())
   {
   case GUI_MSG_WINDOW_RESET:
-    m_vecItems->m_strPath = "?";
+    m_vecItems->m_strPath.clear();
     break;
   case GUI_MSG_WINDOW_DEINIT:
     if (m_thumbLoader.IsLoading())
@@ -115,10 +113,6 @@ bool CGUIWindowVideoNav::OnMessage(CGUIMessage& message)
       /* We don't want to show Autosourced items (ie removable pendrives, memorycards) in Library mode */
       m_rootDir.AllowNonLocalSources(false);
 
-      // is this the first time the window is opened?
-      if (m_vecItems->m_strPath == "?" && message.GetStringParam().IsEmpty())
-        message.SetStringParam(g_settings.m_defaultVideoLibSource);
-
       SetProperty("flattened", g_settings.m_bMyVideoNavFlatten);
       
       if (!CGUIWindowVideoBase::OnMessage(message))
@@ -401,15 +395,82 @@ bool CGUIWindowVideoNav::GetDirectory(const CStdString &strDirectory, CFileItemL
         items.SetContent("");
     }
     else
-    { // see whether we have content set for this path in the database
-      CStdString content = m_database.GetContentForPath(items.m_strPath);
-      items.SetContent(content);
+    { // load info from the database
+      CStdString label;
+      if (items.GetLabel().IsEmpty() && m_rootDir.IsSource(items.m_strPath, g_settings.GetSourcesFromType("video"), &label)) 
+        items.SetLabel(label);
+      LoadVideoInfo(items);
     }
   }
-
   return bResult;
 }
 
+void CGUIWindowVideoNav::LoadVideoInfo(CFileItemList &items)
+{
+  // TODO: this could possibly be threaded as per the music info loading,
+  //       we could also cache the info
+  if (!items.GetContent().IsEmpty())
+    return; // don't load for listings that have content set
+
+  CStdString content = m_database.GetContentForPath(items.m_strPath);
+  items.SetContent(content.IsEmpty() ? "files" : content);
+
+  bool clean = (g_guiSettings.GetBool("myvideos.cleanstrings") &&
+                !items.IsVirtualDirectoryRoot() &&
+                m_stackingAvailable);
+
+  CFileItemList dbItems;
+  if (content.IsEmpty())
+    m_database.GetPlayCounts(items);
+  else
+  {
+    m_database.GetItemsForPath(content, items.m_strPath, dbItems);
+    dbItems.SetFastLookup(true);
+  }
+  for (int i = 0; i < items.Size(); i++)
+  {
+    CFileItemPtr pItem = items[i];
+    CFileItemPtr match;
+    if (!content.IsEmpty())
+      match = dbItems.Get(pItem->m_strPath);
+    if (match)
+    {
+      CStdString label (pItem->GetLabel ());
+      CStdString label2(pItem->GetLabel2());
+      pItem->UpdateInfo(*match);
+
+      if(g_settings.m_videoStacking && m_stackingAvailable)
+      {
+        if (match->m_bIsFolder)
+          pItem->m_strPath = match->GetVideoInfoTag()->m_strPath;
+        else
+          pItem->m_strPath = match->GetVideoInfoTag()->m_strFileNameAndPath;
+        // if we switch from a file to a folder item it means we really shouldn't be sorting files and
+        // folders separately
+        if (pItem->m_bIsFolder != match->m_bIsFolder)
+          items.SetSortIgnoreFolders(true);
+        pItem->m_bIsFolder = match->m_bIsFolder;
+      }
+      else
+      {
+        if (CFile::Exists(match->GetCachedFanart()))
+          pItem->SetProperty("fanart_image", match->GetCachedFanart());
+        pItem->SetLabel (label);
+        pItem->SetLabel2(label);
+      }
+    }
+    else
+    { // set the watched overlay (note: items in a folder with content set that aren't in the db
+      //                                won't get picked up here - in the future all items will be returned)
+      // and clean the label
+      if (pItem->HasVideoInfoTag())
+        pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, pItem->GetVideoInfoTag()->m_playCount > 0);
+      if (clean)
+        pItem->CleanString();
+    }
+  }
+}
+
 void CGUIWindowVideoNav::UpdateButtons()
 {
   CGUIWindowVideoBase::UpdateButtons();
@@ -964,28 +1025,26 @@ void CGUIWindowVideoNav::GetContextButtons(int itemNumber, CContextButtons &butt
           buttons.Add(CONTEXT_BUTTON_UPDATE_LIBRARY, 653);
       }
 
-      //Set default and/or clear default
-      NODE_TYPE nodetype = CVideoDatabaseDirectory::GetDirectoryType(item->m_strPath);
-      if (!item->IsParentFolder() && !m_vecItems->m_strPath.Equals("special://videoplaylists/") &&
-        (nodetype == NODE_TYPE_ROOT             ||
-         nodetype == NODE_TYPE_OVERVIEW         ||
-         nodetype == NODE_TYPE_TVSHOWS_OVERVIEW ||
-         nodetype == NODE_TYPE_MOVIES_OVERVIEW  ||
-         nodetype == NODE_TYPE_MUSICVIDEOS_OVERVIEW))
-      {
-        if (!item->m_strPath.Equals(g_settings.m_defaultVideoLibSource))
-          buttons.Add(CONTEXT_BUTTON_SET_DEFAULT, 13335); // set default
-        if (strcmp(g_settings.m_defaultVideoLibSource, ""))
-          buttons.Add(CONTEXT_BUTTON_CLEAR_DEFAULT, 13403); // clear default
-      }
-
       if (!m_vecItems->IsVideoDb() && !m_vecItems->IsVirtualDirectoryRoot())
       { // non-video db items, file operations are allowed
-        if (!item->IsReadOnly())
+        if (g_guiSettings.GetBool("filelists.allowfiledeletion") &&
+            CUtil::SupportsFileOperations(item->m_strPath))
         {
           buttons.Add(CONTEXT_BUTTON_DELETE, 117);
           buttons.Add(CONTEXT_BUTTON_RENAME, 118);
         }
+        // add "Set/Change content" to folders
+        if (item->m_bIsFolder && !item->IsPlayList() && !item->IsSmartPlayList() && !item->IsLiveTV() && !item->IsPlugin() && !item->IsAddonsPath())
+        {
+          CGUIDialogVideoScan *pScanDlg = (CGUIDialogVideoScan *)g_windowManager.GetWindow(WINDOW_DIALOG_VIDEO_SCAN);
+          if (!pScanDlg || (pScanDlg && !pScanDlg->IsScanning()))
+          {
+            if (info && info->Content() != CONTENT_NONE)
+              buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20442);
+            else
+              buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20333);
+          }
+        }
       }
       if (item->IsPlugin() || item->m_strPath.Left(9).Equals("script://") || m_vecItems->IsPlugin())
         buttons.Add(CONTEXT_BUTTON_PLUGIN_SETTINGS, 1045);
@@ -1005,23 +1064,13 @@ bool CGUIWindowVideoNav::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
     if (button == CONTEXT_BUTTON_REMOVE_SOURCE && !item->IsPlugin()
         && !item->IsLiveTV() &&!item->IsRSS())
     {
-      CGUIWindowVideoFiles::OnUnAssignContent(item->m_strPath,20375,20340,20341);
+      OnUnAssignContent(item->m_strPath,20375,20340,20341);
     }
     Update(m_vecItems->m_strPath);
     return true;
   }
   switch (button)
   {
-  case CONTEXT_BUTTON_SET_DEFAULT:
-    g_settings.m_defaultVideoLibSource = GetQuickpathName(item->m_strPath);
-    g_settings.Save();
-    return true;
-
-  case CONTEXT_BUTTON_CLEAR_DEFAULT:
-    g_settings.m_defaultVideoLibSource.Empty();
-    g_settings.Save();
-    return true;
-
   case CONTEXT_BUTTON_EDIT:
     UpdateVideoTitle(item.get());
     CUtil::DeleteVideoDatabaseDirectoryCache();