MythTV  master
videoutils.cpp
Go to the documentation of this file.
1 
2 #include "videoutils.h"
3 
4 #include <QDir>
5 #include <QCoreApplication>
6 
7 // mythtv
8 #include "libmyth/mythcontext.h"
9 #include "libmythbase/mythdirs.h"
14 #include "libmythui/mythuiimage.h"
16 #include "libmythui/mythuitext.h"
17 
18 // libmythmetadata
19 #include "globals.h"
21 
22 namespace
23 {
24  const QString VIDEO_COVERFILE_DEFAULT_OLD =
25  QCoreApplication::translate("(VideoUtils)", "None", "No cover");
26  const QString VIDEO_COVERFILE_DEFAULT_OLD2 =
27  QCoreApplication::translate("(VideoUtils)", "No Cover");
28 
29  template <typename T>
30  void CopySecond(const T &src, QStringList &dest)
31  {
32  for (auto p = src.cbegin(); p != src.cend(); ++p)
33  {
34  dest.push_back((*p).second);
35  }
36  }
37 }
38 
39 template <>
40 void CheckedSet(MythUIStateType *uiItem, const QString &value)
41 {
42  if (uiItem)
43  {
44  uiItem->Reset();
45  uiItem->DisplayState(value);
46  }
47 }
48 
49 void CheckedSet(MythUIType *container, const QString &itemName,
50  const QString &value)
51 {
52  if (container)
53  {
54  MythUIType *uit = container->GetChild(itemName);
55  auto *tt = dynamic_cast<MythUIText *>(uit);
56  if (tt)
57  CheckedSet(tt, value);
58  else
59  {
60  auto *st = dynamic_cast<MythUIStateType *>(uit);
61  CheckedSet(st, value);
62  }
63  }
64 }
65 
66 void CheckedSet(MythUIImage *uiItem, const QString &filename)
67 {
68  if (uiItem)
69  {
70  uiItem->Reset();
71  uiItem->SetFilename(filename);
72  uiItem->Load();
73  }
74 }
75 
76 QStringList GetVideoDirsByHost(const QString& host)
77 {
78  QStringList tmp;
79 
80  QStringList tmp2 = StorageGroup::getGroupDirs("Videos", host);
81  for (const auto& dir : std::as_const(tmp2))
82  tmp.append(dir);
83 
84  if (host.isEmpty())
85  {
86 #ifdef _WIN32
87  QString seperator = ";";
88 #else
89  QString seperator = ":";
90 #endif
91  QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
92  DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
93  for (const auto& dir : std::as_const(tmp3))
94  {
95  bool matches = false;
96  QString newpath = dir;
97  if (!newpath.endsWith("/"))
98  newpath.append("/");
99 
100  for (const auto& comp : std::as_const(tmp2))
101  {
102  if (comp.endsWith(newpath))
103  {
104  matches = true;
105  break;
106  }
107  }
108  if (!matches)
109  tmp.append(QDir::cleanPath(dir));
110  }
111  }
112 
113  return tmp;
114 }
115 
116 QStringList GetVideoDirs()
117 {
118  return GetVideoDirsByHost("");
119 }
120 
121 bool IsDefaultCoverFile(const QString &coverfile)
122 {
123  return coverfile == VIDEO_COVERFILE_DEFAULT ||
124  coverfile == VIDEO_COVERFILE_DEFAULT_OLD ||
125  coverfile == VIDEO_COVERFILE_DEFAULT_OLD2 ||
126  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD) ||
127  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD2);
128 }
129 
130 bool IsDefaultScreenshot(const QString &screenshot)
131 {
132  return screenshot == VIDEO_SCREENSHOT_DEFAULT;
133 }
134 
135 bool IsDefaultBanner(const QString &banner)
136 {
137  return banner == VIDEO_BANNER_DEFAULT;
138 }
139 
140 bool IsDefaultFanart(const QString &fanart)
141 {
142  return fanart == VIDEO_FANART_DEFAULT;
143 }
144 
145 QString GetDisplayUserRating(float userrating)
146 {
147  return QString::number(userrating, 'f', 1);
148 }
149 
150 QString GetDisplayLength(std::chrono::minutes length)
151 {
152  // The disambiguation string must be an empty string and not a
153  // nullptr to get extracted by the Qt tools.
154  return QCoreApplication::translate("(Common)", "%n minute(s)", "",
155  length.count());
156 }
157 
158 QString GetDisplayBrowse(bool browse)
159 {
160  QString ret;
161 
162  if (browse)
163  ret = QCoreApplication::translate("(Common)", "Yes");
164  else
165  ret = QCoreApplication::translate("(Common)", "No");
166 
167  return ret;
168 }
169 
170 QString GetDisplayWatched(bool watched)
171 {
172  QString ret;
173 
174  if (watched)
175  ret = QCoreApplication::translate("(Common)", "Yes");
176  else
177  ret = QCoreApplication::translate("(Common)", "No");
178 
179  return ret;
180 }
181 
182 QString GetDisplayProcessed(bool processed)
183 {
184  QString ret;
185 
186  if (processed)
187  {
188  ret = QCoreApplication::translate("(VideoUtils)",
189  "Details Downloaded");
190  }
191  else
192  {
193  ret = QCoreApplication::translate("(VideoUtils)",
194  "Waiting for Detail Download");
195  }
196 
197  return ret;
198 }
199 
200 QString GetDisplayYear(int year)
201 {
202  return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
203 }
204 
205 QString GetDisplayRating(const QString &rating)
206 {
207  if (rating == "<NULL>")
208  return QCoreApplication::translate("(VideoUtils)", "No rating available.");
209  return rating;
210 }
211 
212 QString GetDisplayGenres(const VideoMetadata &item)
213 {
214  QStringList ret;
215  CopySecond(item.GetGenres(), ret);
216  return ret.join(", ");
217 }
218 
219 QString GetDisplayCountries(const VideoMetadata &item)
220 {
221  QStringList ret;
222  CopySecond(item.GetCountries(), ret);
223  return ret.join(", ");
224 }
225 
226 QStringList GetDisplayCast(const VideoMetadata &item)
227 {
228  QStringList ret;
229  CopySecond(item.GetCast(), ret);
230  return ret;
231 }
232 
233 QString ParentalLevelToState(const ParentalLevel &level)
234 {
235  QString ret;
236  switch (level.GetLevel())
237  {
239  ret = "Lowest";
240  break;
241  case ParentalLevel::plLow :
242  ret = "Low";
243  break;
245  ret = "Medium";
246  break;
247  case ParentalLevel::plHigh :
248  ret = "High";
249  break;
250  default:
251  ret = "None";
252  }
253 
254  return ret;
255 }
256 
257 QString TrailerToState(const QString &trailerFile)
258 {
259  QString ret;
260  if (!trailerFile.isEmpty())
261  ret = "hasTrailer";
262  else
263  ret = "None";
264  return ret;
265 }
266 
267 QString WatchedToState(bool watched)
268 {
269  QString ret;
270  if (watched)
271  ret = "yes";
272  else
273  ret = "no";
274  return ret;
275 }
276 
278 {
280 
281  if (type == "MOVIE")
282  ret = kContentMovie;
283  else if (type == "TELEVISION")
284  ret = kContentTelevision;
285  else if (type == "ADULT")
286  ret = kContentAdult;
287  else if (type == "MUSICVIDEO")
288  ret = kContentMusicVideo;
289  else if (type == "HOMEVIDEO")
290  ret = kContentHomeMovie;
291 
292  return ret;
293 }
294 
296 {
297  QString ret = "UNKNOWN";
298 
299  if (type == kContentMovie)
300  ret = "MOVIE";
301  else if (type == kContentTelevision)
302  ret = "TELEVISION";
303  else if (type == kContentAdult)
304  ret = "ADULT";
305  else if (type == kContentMusicVideo)
306  ret = "MUSICVIDEO";
307  else if (type == kContentHomeMovie)
308  ret = "HOMEVIDEO";
309 
310  return ret;
311 }
312 
VideoMetadata
Definition: videometadata.h:24
build_compdb.dest
dest
Definition: build_compdb.py:9
mythuitext.h
WatchedToState
QString WatchedToState(bool watched)
Definition: videoutils.cpp:267
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
ParentalLevel::plLowest
@ plLowest
Definition: parentalcontrols.h:12
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:135
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:966
ParentalLevel::plMedium
@ plMedium
Definition: parentalcontrols.h:12
ParentalLevel::plHigh
@ plHigh
Definition: parentalcontrols.h:13
ParentalLevel::plLow
@ plLow
Definition: parentalcontrols.h:12
mythdialogbox.h
GetDisplayLength
QString GetDisplayLength(std::chrono::minutes length)
Definition: videoutils.cpp:150
GetDisplayProcessed
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:182
ContentTypeFromString
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:277
ContentTypeToString
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:295
CheckedSet
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:40
mythuistatetype.h
MythUIStateType::Reset
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
Definition: mythuistatetype.cpp:197
mythdirs.h
MythUIImage::Reset
void Reset(void) override
Reset the image back to the default defined in the theme.
Definition: mythuiimage.cpp:643
mythuiimage.h
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
mythsystemlegacy.h
GetDisplayRating
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:205
VideoMetadata::GetCountries
const country_list & GetCountries() const
Definition: videometadata.cpp:1927
GetDisplayUserRating
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:145
GetVideoDirs
QStringList GetVideoDirs()
Definition: videoutils.cpp:116
hardwareprofile.config.p
p
Definition: config.py:33
globals.h
GetDisplayCountries
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:219
hardwareprofile.scan.rating
def rating(profile, smoonURL, gate)
Definition: scan.py:37
VIDEO_COVERFILE_DEFAULT
const QString VIDEO_COVERFILE_DEFAULT
Definition: globals.cpp:25
StorageGroup::getGroupDirs
static QStringList getGroupDirs(const QString &groupname, const QString &host)
Definition: storagegroup.cpp:811
GetDisplayBrowse
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:158
kContentTelevision
@ kContentTelevision
Definition: metadatacommon.h:62
IsDefaultBanner
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:135
storagegroup.h
VideoMetadata::GetGenres
const genre_list & GetGenres() const
Definition: videometadata.cpp:1907
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
IsDefaultFanart
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:140
DEFAULT_VIDEOSTARTUP_DIR
const QString DEFAULT_VIDEOSTARTUP_DIR
Definition: globals.cpp:47
VIDEO_FANART_DEFAULT
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
videometadatalistmanager.h
ParentalLevelToState
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:233
IsDefaultCoverFile
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:121
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:85
IsDefaultScreenshot
bool IsDefaultScreenshot(const QString &screenshot)
Definition: videoutils.cpp:130
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:28
VideoContentType
VideoContentType
Definition: metadatacommon.h:60
ParentalLevel
Definition: parentalcontrols.h:9
GetVideoDirsByHost
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:76
mythcontext.h
kContentAdult
@ kContentAdult
Definition: metadatacommon.h:63
kContentMusicVideo
@ kContentMusicVideo
Definition: metadatacommon.h:64
kContentMovie
@ kContentMovie
Definition: metadatacommon.h:61
GetDisplayGenres
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:212
kContentUnknown
@ kContentUnknown
Definition: metadatacommon.h:66
VIDEO_YEAR_DEFAULT
static constexpr uint16_t VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18
TrailerToState
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:257
VIDEO_BANNER_DEFAULT
const QString VIDEO_BANNER_DEFAULT
Definition: globals.cpp:28
MythUIImage::SetFilename
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
Definition: mythuiimage.cpp:674
kContentHomeMovie
@ kContentHomeMovie
Definition: metadatacommon.h:65
build_compdb.filename
filename
Definition: build_compdb.py:21
GetDisplayWatched
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:170
mythmainwindow.h
ParentalLevel::GetLevel
Level GetLevel() const
Definition: parentalcontrols.cpp:128
GetDisplayCast
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:226
VideoMetadata::GetCast
const cast_list & GetCast() const
Definition: videometadata.cpp:1917
videoutils.h
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called....
Definition: mythuistatetype.h:22
MythUIStateType::DisplayState
bool DisplayState(const QString &name)
Definition: mythuistatetype.cpp:84
VIDEO_SCREENSHOT_DEFAULT
const QString VIDEO_SCREENSHOT_DEFAULT
Definition: globals.cpp:27
GetDisplayYear
QString GetDisplayYear(int year)
Definition: videoutils.cpp:200
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898