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  for (const auto& dir : qAsConst(tmp2))
86  tmp.append(dir);
87 
88  if (host.isEmpty())
89  {
90 #ifdef _WIN32
91  QString seperator = ";";
92 #else
93  QString seperator = ":";
94 #endif
95 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
96  QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
97  DEFAULT_VIDEOSTARTUP_DIR).split(seperator, QString::SkipEmptyParts);
98 #else
99  QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
100  DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
101 #endif
102  for (const auto& dir : qAsConst(tmp3))
103  {
104  bool matches = false;
105  QString newpath = dir;
106  if (!newpath.endsWith("/"))
107  newpath.append("/");
108 
109  for (const auto& comp : qAsConst(tmp2))
110  {
111  if (comp.endsWith(newpath))
112  {
113  matches = true;
114  break;
115  }
116  }
117  if (!matches)
118  tmp.append(QDir::cleanPath(dir));
119  }
120  }
121 
122  return tmp;
123 }
124 
125 QStringList GetVideoDirs()
126 {
127  return GetVideoDirsByHost("");
128 }
129 
130 bool IsDefaultCoverFile(const QString &coverfile)
131 {
132  return coverfile == VIDEO_COVERFILE_DEFAULT ||
133  coverfile == VIDEO_COVERFILE_DEFAULT_OLD ||
134  coverfile == VIDEO_COVERFILE_DEFAULT_OLD2 ||
135  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD) ||
136  coverfile.endsWith(VIDEO_COVERFILE_DEFAULT_OLD2);
137 }
138 
139 bool IsDefaultScreenshot(const QString &screenshot)
140 {
141  return screenshot == VIDEO_SCREENSHOT_DEFAULT;
142 }
143 
144 bool IsDefaultBanner(const QString &banner)
145 {
146  return banner == VIDEO_BANNER_DEFAULT;
147 }
148 
149 bool IsDefaultFanart(const QString &fanart)
150 {
151  return fanart == VIDEO_FANART_DEFAULT;
152 }
153 
154 QString GetDisplayUserRating(float userrating)
155 {
156  return QString::number(userrating, 'f', 1);
157 }
158 
159 QString GetDisplayLength(int length)
160 {
161  // The disambiguation string must be an empty string and not a
162  // nullptr to get extracted by the Qt tools.
163  return QCoreApplication::translate("(Common)", "%n minute(s)", "",
164  length);
165 }
166 
167 QString GetDisplayBrowse(bool browse)
168 {
169  QString ret;
170 
171  if (browse)
172  ret = QCoreApplication::translate("(Common)", "Yes");
173  else
174  ret = QCoreApplication::translate("(Common)", "No");
175 
176  return ret;
177 }
178 
179 QString GetDisplayWatched(bool watched)
180 {
181  QString ret;
182 
183  if (watched)
184  ret = QCoreApplication::translate("(Common)", "Yes");
185  else
186  ret = QCoreApplication::translate("(Common)", "No");
187 
188  return ret;
189 }
190 
191 QString GetDisplayProcessed(bool processed)
192 {
193  QString ret;
194 
195  if (processed)
196  {
197  ret = QCoreApplication::translate("(VideoUtils)",
198  "Details Downloaded");
199  }
200  else
201  {
202  ret = QCoreApplication::translate("(VideoUtils)",
203  "Waiting for Detail Download");
204  }
205 
206  return ret;
207 }
208 
209 QString GetDisplayYear(int year)
210 {
211  return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
212 }
213 
214 QString GetDisplayRating(const QString &rating)
215 {
216  if (rating == "<NULL>")
217  return QCoreApplication::translate("(VideoUtils)", "No rating available.");
218  return rating;
219 }
220 
221 QString GetDisplayGenres(const VideoMetadata &item)
222 {
223  QStringList ret;
224  CopySecond(item.GetGenres(), ret);
225  return ret.join(", ");
226 }
227 
228 QString GetDisplayCountries(const VideoMetadata &item)
229 {
230  QStringList ret;
231  CopySecond(item.GetCountries(), ret);
232  return ret.join(", ");
233 }
234 
235 QStringList GetDisplayCast(const VideoMetadata &item)
236 {
237  QStringList ret;
238  CopySecond(item.GetCast(), ret);
239  return ret;
240 }
241 
242 QString ParentalLevelToState(const ParentalLevel &level)
243 {
244  QString ret;
245  switch (level.GetLevel())
246  {
248  ret = "Lowest";
249  break;
250  case ParentalLevel::plLow :
251  ret = "Low";
252  break;
254  ret = "Medium";
255  break;
256  case ParentalLevel::plHigh :
257  ret = "High";
258  break;
259  default:
260  ret = "None";
261  }
262 
263  return ret;
264 }
265 
266 QString TrailerToState(const QString &trailerFile)
267 {
268  QString ret;
269  if (!trailerFile.isEmpty())
270  ret = "hasTrailer";
271  else
272  ret = "None";
273  return ret;
274 }
275 
276 QString WatchedToState(bool watched)
277 {
278  QString ret;
279  if (watched)
280  ret = "yes";
281  else
282  ret = "no";
283  return ret;
284 }
285 
287 {
289 
290  if (type == "MOVIE")
291  ret = kContentMovie;
292  else if (type == "TELEVISION")
293  ret = kContentTelevision;
294  else if (type == "ADULT")
295  ret = kContentAdult;
296  else if (type == "MUSICVIDEO")
297  ret = kContentMusicVideo;
298  else if (type == "HOMEVIDEO")
299  ret = kContentHomeMovie;
300 
301  return ret;
302 }
303 
305 {
306  QString ret = "UNKNOWN";
307 
308  if (type == kContentMovie)
309  ret = "MOVIE";
310  else if (type == kContentTelevision)
311  ret = "TELEVISION";
312  else if (type == kContentAdult)
313  ret = "ADULT";
314  else if (type == kContentMusicVideo)
315  ret = "MUSICVIDEO";
316  else if (type == kContentHomeMovie)
317  ret = "HOMEVIDEO";
318 
319  return ret;
320 }
321 
VideoMetadata
Definition: videometadata.h:25
build_compdb.dest
dest
Definition: build_compdb.py:9
mythuitext.h
WatchedToState
QString WatchedToState(bool watched)
Definition: videoutils.cpp:276
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
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:131
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
GetDisplayProcessed
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:191
ContentTypeFromString
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:286
ContentTypeToString
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:304
CheckedSet
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:44
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
GetDisplayLength
QString GetDisplayLength(int length)
Definition: videoutils.cpp:159
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:31
mythsystemlegacy.h
GetDisplayRating
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:214
VideoMetadata::GetCountries
const country_list & GetCountries() const
Definition: videometadata.cpp:1724
GetDisplayUserRating
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:154
GetVideoDirs
QStringList GetVideoDirs()
Definition: videoutils.cpp:125
hardwareprofile.config.p
p
Definition: config.py:33
globals.h
GetDisplayCountries
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:228
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:817
GetDisplayBrowse
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:167
kContentTelevision
@ kContentTelevision
Definition: metadatacommon.h:61
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:640
IsDefaultBanner
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:144
storagegroup.h
VideoMetadata::GetGenres
const genre_list & GetGenres() const
Definition: videometadata.cpp:1704
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
IsDefaultFanart
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:149
DEFAULT_VIDEOSTARTUP_DIR
const QString DEFAULT_VIDEOSTARTUP_DIR
Definition: globals.cpp:45
VIDEO_FANART_DEFAULT
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
videometadatalistmanager.h
ParentalLevelToState
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:242
IsDefaultCoverFile
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:130
MythUIType
The base class on which all widgets and screens are based.
Definition: mythuitype.h:66
IsDefaultScreenshot
bool IsDefaultScreenshot(const QString &screenshot)
Definition: videoutils.cpp:139
VIDEO_YEAR_DEFAULT
@ VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18
MythUIText
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
VideoContentType
VideoContentType
Definition: metadatacommon.h:59
dir
QDir dir
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:1177
ParentalLevel
Definition: parentalcontrols.h:10
GetVideoDirsByHost
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:80
mythcontext.h
kContentAdult
@ kContentAdult
Definition: metadatacommon.h:62
kContentMusicVideo
@ kContentMusicVideo
Definition: metadatacommon.h:63
kContentMovie
@ kContentMovie
Definition: metadatacommon.h:60
GetDisplayGenres
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:221
kContentUnknown
@ kContentUnknown
Definition: metadatacommon.h:65
TrailerToState
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:266
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:64
GetDisplayWatched
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:179
mythmainwindow.h
ParentalLevel::GetLevel
Level GetLevel() const
Definition: parentalcontrols.cpp:128
GetDisplayCast
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:235
VideoMetadata::GetCast
const cast_list & GetCast() const
Definition: videometadata.cpp:1714
videoutils.h
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called.
Definition: mythuistatetype.h:23
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:209
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:916