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