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 : qAsConst(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 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
92  QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
93  DEFAULT_VIDEOSTARTUP_DIR).split(seperator, QString::SkipEmptyParts);
94 #else
95  QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
96  DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
97 #endif
98  for (const auto& dir : qAsConst(tmp3))
99  {
100  bool matches = false;
101  QString newpath = dir;
102  if (!newpath.endsWith("/"))
103  newpath.append("/");
104 
105  for (const auto& comp : qAsConst(tmp2))
106  {
107  if (comp.endsWith(newpath))
108  {
109  matches = true;
110  break;
111  }
112  }
113  if (!matches)
114  tmp.append(QDir::cleanPath(dir));
115  }
116  }
117 
118  return tmp;
119 }
120 
121 QStringList GetVideoDirs()
122 {
123  return GetVideoDirsByHost("");
124 }
125 
126 bool IsDefaultCoverFile(const QString &coverfile)
127 {
128  return coverfile == VIDEO_COVERFILE_DEFAULT ||
129  coverfile == VIDEO_COVERFILE_DEFAULT_OLD ||
130  coverfile == VIDEO_COVERFILE_DEFAULT_OLD2 ||
131  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD) ||
132  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD2);
133 }
134 
135 bool IsDefaultScreenshot(const QString &screenshot)
136 {
137  return screenshot == VIDEO_SCREENSHOT_DEFAULT;
138 }
139 
140 bool IsDefaultBanner(const QString &banner)
141 {
142  return banner == VIDEO_BANNER_DEFAULT;
143 }
144 
145 bool IsDefaultFanart(const QString &fanart)
146 {
147  return fanart == VIDEO_FANART_DEFAULT;
148 }
149 
150 QString GetDisplayUserRating(float userrating)
151 {
152  return QString::number(userrating, 'f', 1);
153 }
154 
155 QString GetDisplayLength(std::chrono::minutes length)
156 {
157  // The disambiguation string must be an empty string and not a
158  // nullptr to get extracted by the Qt tools.
159  return QCoreApplication::translate("(Common)", "%n minute(s)", "",
160  length.count());
161 }
162 
163 QString GetDisplayBrowse(bool browse)
164 {
165  QString ret;
166 
167  if (browse)
168  ret = QCoreApplication::translate("(Common)", "Yes");
169  else
170  ret = QCoreApplication::translate("(Common)", "No");
171 
172  return ret;
173 }
174 
175 QString GetDisplayWatched(bool watched)
176 {
177  QString ret;
178 
179  if (watched)
180  ret = QCoreApplication::translate("(Common)", "Yes");
181  else
182  ret = QCoreApplication::translate("(Common)", "No");
183 
184  return ret;
185 }
186 
187 QString GetDisplayProcessed(bool processed)
188 {
189  QString ret;
190 
191  if (processed)
192  {
193  ret = QCoreApplication::translate("(VideoUtils)",
194  "Details Downloaded");
195  }
196  else
197  {
198  ret = QCoreApplication::translate("(VideoUtils)",
199  "Waiting for Detail Download");
200  }
201 
202  return ret;
203 }
204 
205 QString GetDisplayYear(int year)
206 {
207  return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
208 }
209 
210 QString GetDisplayRating(const QString &rating)
211 {
212  if (rating == "<NULL>")
213  return QCoreApplication::translate("(VideoUtils)", "No rating available.");
214  return rating;
215 }
216 
217 QString GetDisplayGenres(const VideoMetadata &item)
218 {
219  QStringList ret;
220  CopySecond(item.GetGenres(), ret);
221  return ret.join(", ");
222 }
223 
224 QString GetDisplayCountries(const VideoMetadata &item)
225 {
226  QStringList ret;
227  CopySecond(item.GetCountries(), ret);
228  return ret.join(", ");
229 }
230 
231 QStringList GetDisplayCast(const VideoMetadata &item)
232 {
233  QStringList ret;
234  CopySecond(item.GetCast(), ret);
235  return ret;
236 }
237 
238 QString ParentalLevelToState(const ParentalLevel &level)
239 {
240  QString ret;
241  switch (level.GetLevel())
242  {
244  ret = "Lowest";
245  break;
246  case ParentalLevel::plLow :
247  ret = "Low";
248  break;
250  ret = "Medium";
251  break;
252  case ParentalLevel::plHigh :
253  ret = "High";
254  break;
255  default:
256  ret = "None";
257  }
258 
259  return ret;
260 }
261 
262 QString TrailerToState(const QString &trailerFile)
263 {
264  QString ret;
265  if (!trailerFile.isEmpty())
266  ret = "hasTrailer";
267  else
268  ret = "None";
269  return ret;
270 }
271 
272 QString WatchedToState(bool watched)
273 {
274  QString ret;
275  if (watched)
276  ret = "yes";
277  else
278  ret = "no";
279  return ret;
280 }
281 
283 {
285 
286  if (type == "MOVIE")
287  ret = kContentMovie;
288  else if (type == "TELEVISION")
289  ret = kContentTelevision;
290  else if (type == "ADULT")
291  ret = kContentAdult;
292  else if (type == "MUSICVIDEO")
293  ret = kContentMusicVideo;
294  else if (type == "HOMEVIDEO")
295  ret = kContentHomeMovie;
296 
297  return ret;
298 }
299 
301 {
302  QString ret = "UNKNOWN";
303 
304  if (type == kContentMovie)
305  ret = "MOVIE";
306  else if (type == kContentTelevision)
307  ret = "TELEVISION";
308  else if (type == kContentAdult)
309  ret = "ADULT";
310  else if (type == kContentMusicVideo)
311  ret = "MUSICVIDEO";
312  else if (type == kContentHomeMovie)
313  ret = "HOMEVIDEO";
314 
315  return ret;
316 }
317 
VideoMetadata
Definition: videometadata.h:24
build_compdb.dest
dest
Definition: build_compdb.py:9
mythuitext.h
WatchedToState
QString WatchedToState(bool watched)
Definition: videoutils.cpp:272
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:133
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:968
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:155
GetDisplayProcessed
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:187
ContentTypeFromString
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:282
ContentTypeToString
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:300
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:645
mythuiimage.h
tmp
static guint32 * tmp
Definition: goom_core.cpp:26
mythsystemlegacy.h
GetDisplayRating
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:210
VideoMetadata::GetCountries
const country_list & GetCountries() const
Definition: videometadata.cpp:1931
GetDisplayUserRating
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:150
GetVideoDirs
QStringList GetVideoDirs()
Definition: videoutils.cpp:121
hardwareprofile.config.p
p
Definition: config.py:33
globals.h
GetDisplayCountries
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:224
hardwareprofile.scan.rating
def rating(profile, smoonURL, gate)
Definition: scan.py:39
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:816
GetDisplayBrowse
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:163
kContentTelevision
@ kContentTelevision
Definition: metadatacommon.h:62
IsDefaultBanner
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:140
storagegroup.h
VideoMetadata::GetGenres
const genre_list & GetGenres() const
Definition: videometadata.cpp:1911
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:54
IsDefaultFanart
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:145
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:238
IsDefaultCoverFile
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:126
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:135
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
VIDEO_YEAR_DEFAULT
@ VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18
kContentMovie
@ kContentMovie
Definition: metadatacommon.h:61
GetDisplayGenres
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:217
kContentUnknown
@ kContentUnknown
Definition: metadatacommon.h:66
TrailerToState
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:262
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:676
kContentHomeMovie
@ kContentHomeMovie
Definition: metadatacommon.h:65
build_compdb.filename
filename
Definition: build_compdb.py:21
GetDisplayWatched
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:175
mythmainwindow.h
ParentalLevel::GetLevel
Level GetLevel() const
Definition: parentalcontrols.cpp:128
GetDisplayCast
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:231
VideoMetadata::GetCast
const cast_list & GetCast() const
Definition: videometadata.cpp:1921
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:205
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:896