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 &value)
45 {
46  if (uiItem)
47  {
48  uiItem->Reset();
49  uiItem->DisplayState(value);
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  foreach (auto & dir, tmp2)
86  tmp.append(dir);
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  foreach (auto & dir, tmp3)
98  {
99  bool matches = false;
100  QString newpath = dir;
101  if (!newpath.endsWith("/"))
102  newpath.append("/");
103 
104  foreach (auto comp, tmp2)
105  {
106  if (comp.endsWith(newpath))
107  {
108  matches = true;
109  break;
110  }
111  }
112  if (!matches)
113  tmp.append(QDir::cleanPath(dir));
114  }
115  }
116 
117  return tmp;
118 }
119 
120 QStringList GetVideoDirs()
121 {
122  return GetVideoDirsByHost("");
123 }
124 
125 bool IsDefaultCoverFile(const QString &coverfile)
126 {
127  return coverfile == VIDEO_COVERFILE_DEFAULT ||
128  coverfile == VIDEO_COVERFILE_DEFAULT_OLD ||
129  coverfile == VIDEO_COVERFILE_DEFAULT_OLD2 ||
130  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD) ||
131  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD2);
132 }
133 
134 bool IsDefaultScreenshot(const QString &screenshot)
135 {
136  return screenshot == VIDEO_SCREENSHOT_DEFAULT;
137 }
138 
139 bool IsDefaultBanner(const QString &banner)
140 {
141  return banner == VIDEO_BANNER_DEFAULT;
142 }
143 
144 bool IsDefaultFanart(const QString &fanart)
145 {
146  return fanart == VIDEO_FANART_DEFAULT;
147 }
148 
149 QString GetDisplayUserRating(float userrating)
150 {
151  return QString::number(userrating, 'f', 1);
152 }
153 
154 QString GetDisplayLength(int length)
155 {
156  // The disambiguation string must be an empty string and not a
157  // nullptr to get extracted by the Qt tools.
158  return QCoreApplication::translate("(Common)", "%n minute(s)", "",
159  length);
160 }
161 
162 QString GetDisplayBrowse(bool browse)
163 {
164  QString ret;
165 
166  if (browse)
167  ret = QCoreApplication::translate("(Common)", "Yes");
168  else
169  ret = QCoreApplication::translate("(Common)", "No");
170 
171  return ret;
172 }
173 
174 QString GetDisplayWatched(bool watched)
175 {
176  QString ret;
177 
178  if (watched)
179  ret = QCoreApplication::translate("(Common)", "Yes");
180  else
181  ret = QCoreApplication::translate("(Common)", "No");
182 
183  return ret;
184 }
185 
186 QString GetDisplayProcessed(bool processed)
187 {
188  QString ret;
189 
190  if (processed)
191  {
192  ret = QCoreApplication::translate("(VideoUtils)",
193  "Details Downloaded");
194  }
195  else
196  {
197  ret = QCoreApplication::translate("(VideoUtils)",
198  "Waiting for Detail Download");
199  }
200 
201  return ret;
202 }
203 
204 QString GetDisplayYear(int year)
205 {
206  return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
207 }
208 
209 QString GetDisplayRating(const QString &rating)
210 {
211  if (rating == "<NULL>")
212  return QCoreApplication::translate("(VideoUtils)", "No rating available.");
213  return rating;
214 }
215 
216 QString GetDisplayGenres(const VideoMetadata &item)
217 {
218  QStringList ret;
219  CopySecond(item.GetGenres(), ret);
220  return ret.join(", ");
221 }
222 
223 QString GetDisplayCountries(const VideoMetadata &item)
224 {
225  QStringList ret;
226  CopySecond(item.GetCountries(), ret);
227  return ret.join(", ");
228 }
229 
230 QStringList GetDisplayCast(const VideoMetadata &item)
231 {
232  QStringList ret;
233  CopySecond(item.GetCast(), ret);
234  return ret;
235 }
236 
237 QString ParentalLevelToState(const ParentalLevel &level)
238 {
239  QString ret;
240  switch (level.GetLevel())
241  {
243  ret = "Lowest";
244  break;
245  case ParentalLevel::plLow :
246  ret = "Low";
247  break;
249  ret = "Medium";
250  break;
251  case ParentalLevel::plHigh :
252  ret = "High";
253  break;
254  default:
255  ret = "None";
256  }
257 
258  return ret;
259 }
260 
261 QString TrailerToState(const QString &trailerFile)
262 {
263  QString ret;
264  if (!trailerFile.isEmpty())
265  ret = "hasTrailer";
266  else
267  ret = "None";
268  return ret;
269 }
270 
271 QString WatchedToState(bool watched)
272 {
273  QString ret;
274  if (watched)
275  ret = "yes";
276  else
277  ret = "no";
278  return ret;
279 }
280 
282 {
284 
285  if (type == "MOVIE")
286  ret = kContentMovie;
287  else if (type == "TELEVISION")
288  ret = kContentTelevision;
289  else if (type == "ADULT")
290  ret = kContentAdult;
291  else if (type == "MUSICVIDEO")
292  ret = kContentMusicVideo;
293  else if (type == "HOMEVIDEO")
294  ret = kContentHomeMovie;
295 
296  return ret;
297 }
298 
300 {
301  QString ret = "UNKNOWN";
302 
303  if (type == kContentMovie)
304  ret = "MOVIE";
305  else if (type == kContentTelevision)
306  ret = "TELEVISION";
307  else if (type == kContentAdult)
308  ret = "ADULT";
309  else if (type == kContentMusicVideo)
310  ret = "MUSICVIDEO";
311  else if (type == kContentHomeMovie)
312  ret = "HOMEVIDEO";
313 
314  return ret;
315 }
316 
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:209
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:149
QStringList GetVideoDirs()
Definition: videoutils.cpp:120
bool IsDefaultScreenshot(const QString &screenshot)
Definition: videoutils.cpp:134
const QString VIDEO_SCREENSHOT_DEFAULT
Definition: globals.cpp:27
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:223
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:144
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:216
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:125
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:80
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:230
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()
static QStringList getGroupDirs(const QString &groupname, const QString &host)
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:261
def rating(profile, smoonURL, gate)
Definition: scan.py:39
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:174
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:204
const cast_list & GetCast() const
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:281
const country_list & GetCountries() const
QString WatchedToState(bool watched)
Definition: videoutils.cpp:271
QString GetDisplayLength(int length)
Definition: videoutils.cpp:154
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:299
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:186
const genre_list & GetGenres() const
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:162
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:44
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:130
const QString VIDEO_BANNER_DEFAULT
Definition: globals.cpp:28
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:139
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:237