summaryrefslogtreecommitdiffstats
path: root/xbmc/filesystem/VideoDatabaseDirectory/DirectoryNodeSeasons.cpp
blob: 25b8b09b2fcd7e443e2c0603eb0d7fe16c9c1f73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "DirectoryNodeSeasons.h"

#include "FileItem.h"
#include "QueryParams.h"
#include "guilib/LocalizeStrings.h"
#include "utils/StringUtils.h"
#include "video/VideoDatabase.h"

using namespace XFILE::VIDEODATABASEDIRECTORY;

CDirectoryNodeSeasons::CDirectoryNodeSeasons(const std::string& strName, CDirectoryNode* pParent)
  : CDirectoryNode(NODE_TYPE_SEASONS, strName, pParent)
{

}

NODE_TYPE CDirectoryNodeSeasons::GetChildType() const
{
  return NODE_TYPE_EPISODES;
}

std::string CDirectoryNodeSeasons::GetLocalizedName() const
{
  switch (GetID())
  {
    case 0:
      return g_localizeStrings.Get(20381); // Specials
    case -1:
      return g_localizeStrings.Get(20366); // All Seasons
    case -2:
    {
      CDirectoryNode* pParent = GetParent();
      if (pParent)
        return pParent->GetLocalizedName();
      return "";
    }
    default:
      return GetSeasonTitle();
  }
}

std::string CDirectoryNodeSeasons::GetSeasonTitle() const
{
  std::string season;
  CVideoDatabase db;
  if (db.Open())
  {
    CQueryParams params;
    CollectQueryParams(params);

    season = db.GetTvShowNamedSeasonById(params.GetTvShowId(), params.GetSeason());
  }
  if (season.empty())
    season = StringUtils::Format(g_localizeStrings.Get(20358), GetID()); // Season <n>

  return season;
}

bool CDirectoryNodeSeasons::GetContent(CFileItemList& items) const
{
  CVideoDatabase videodatabase;
  if (!videodatabase.Open())
    return false;

  CQueryParams params;
  CollectQueryParams(params);

  bool bSuccess=videodatabase.GetSeasonsNav(BuildPath(), items, params.GetActorId(), params.GetDirectorId(), params.GetGenreId(), params.GetYear(), params.GetTvShowId());

  videodatabase.Close();

  return bSuccess;
}