MythTV master
videoutils.cpp
Go to the documentation of this file.
1
2#include "videoutils.h"
3
4#include <QtGlobal>
5#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
6#include <QtSystemDetection>
7#endif
8#include <QDir>
9#include <QCoreApplication>
10
11// mythtv
21
22// libmythmetadata
23#include "globals.h"
25
26namespace
27{
29 QCoreApplication::translate("(VideoUtils)", "None", "No cover");
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
43template <>
44void CheckedSet(MythUIStateType *uiItem, const QString &value)
45{
46 if (uiItem)
47 {
48 uiItem->Reset();
49 uiItem->DisplayState(value);
50 }
51}
52
53void 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 {
62 CheckedSet(tt, value);
63 }
64 else
65 {
66 auto *st = dynamic_cast<MythUIStateType *>(uit);
67 CheckedSet(st, value);
68 }
69 }
70}
71
72void CheckedSet(MythUIImage *uiItem, const QString &filename)
73{
74 if (uiItem)
75 {
76 uiItem->Reset();
77 uiItem->SetFilename(filename);
78 uiItem->Load();
79 }
80}
81
82QStringList GetVideoDirsByHost(const QString& host)
83{
84 QStringList tmp;
85
86 QStringList tmp2 = StorageGroup::getGroupDirs("Videos", host);
87 for (const auto& dir : std::as_const(tmp2))
88 tmp.append(dir);
89
90 if (host.isEmpty())
91 {
92#ifdef Q_OS_WINDOWS
93 QString seperator = ";";
94#else
95 QString seperator = ":";
96#endif
97 QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
98 DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
99 for (const auto& dir : std::as_const(tmp3))
100 {
101 bool matches = false;
102 QString newpath = dir;
103 if (!newpath.endsWith("/"))
104 newpath.append("/");
105
106 for (const auto& comp : std::as_const(tmp2))
107 {
108 if (comp.endsWith(newpath))
109 {
110 matches = true;
111 break;
112 }
113 }
114 if (!matches)
115 tmp.append(QDir::cleanPath(dir));
116 }
117 }
118
119 return tmp;
120}
121
122QStringList GetVideoDirs()
123{
124 return GetVideoDirsByHost("");
125}
126
127bool 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
136bool IsDefaultScreenshot(const QString &screenshot)
137{
138 return screenshot == VIDEO_SCREENSHOT_DEFAULT;
139}
140
141bool IsDefaultBanner(const QString &banner)
142{
143 return banner == VIDEO_BANNER_DEFAULT;
144}
145
146bool IsDefaultFanart(const QString &fanart)
147{
148 return fanart == VIDEO_FANART_DEFAULT;
149}
150
151QString GetDisplayUserRating(float userrating)
152{
153 return QString::number(userrating, 'f', 1);
154}
155
156QString GetDisplayLength(std::chrono::minutes 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.count());
162}
163
164QString GetDisplayBrowse(bool browse)
165{
166 QString ret;
167
168 if (browse)
169 ret = QCoreApplication::translate("(Common)", "Yes");
170 else
171 ret = QCoreApplication::translate("(Common)", "No");
172
173 return ret;
174}
175
176QString GetDisplayWatched(bool watched)
177{
178 QString ret;
179
180 if (watched)
181 ret = QCoreApplication::translate("(Common)", "Yes");
182 else
183 ret = QCoreApplication::translate("(Common)", "No");
184
185 return ret;
186}
187
188QString GetDisplayProcessed(bool processed)
189{
190 QString ret;
191
192 if (processed)
193 {
194 ret = QCoreApplication::translate("(VideoUtils)",
195 "Details Downloaded");
196 }
197 else
198 {
199 ret = QCoreApplication::translate("(VideoUtils)",
200 "Waiting for Detail Download");
201 }
202
203 return ret;
204}
205
206QString GetDisplayYear(int year)
207{
208 return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
209}
210
211QString GetDisplayRating(const QString &rating)
212{
213 if (rating == "<NULL>")
214 return QCoreApplication::translate("(VideoUtils)", "No rating available.");
215 return rating;
216}
217
218QString GetDisplayGenres(const VideoMetadata &item)
219{
220 QStringList ret;
221 CopySecond(item.GetGenres(), ret);
222 return ret.join(", ");
223}
224
226{
227 QStringList ret;
228 CopySecond(item.GetCountries(), ret);
229 return ret.join(", ");
230}
231
232QStringList GetDisplayCast(const VideoMetadata &item)
233{
234 QStringList ret;
235 CopySecond(item.GetCast(), ret);
236 return ret;
237}
238
240{
241 QString ret;
242 switch (level.GetLevel())
243 {
245 ret = "Lowest";
246 break;
248 ret = "Low";
249 break;
251 ret = "Medium";
252 break;
254 ret = "High";
255 break;
256 default:
257 ret = "None";
258 }
259
260 return ret;
261}
262
263QString 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
273QString 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
QString GetSetting(const QString &key, const QString &defaultval="")
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
void Reset(void) override
Reset the image back to the default defined in the theme.
This widget is used for grouping other widgets for display when a particular named state is called.
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
bool DisplayState(const QString &name)
All purpose text widget, displays a text string.
Definition: mythuitext.h:29
The base class on which all widgets and screens are based.
Definition: mythuitype.h:97
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
Level GetLevel() const
static QStringList getGroupDirs(const QString &groupname, const QString &host)
const country_list & GetCountries() const
const cast_list & GetCast() const
const genre_list & GetGenres() const
const QString VIDEO_BANNER_DEFAULT
Definition: globals.cpp:28
const QString VIDEO_SCREENSHOT_DEFAULT
Definition: globals.cpp:27
const QString VIDEO_FANART_DEFAULT
Definition: globals.cpp:29
const QString DEFAULT_VIDEOSTARTUP_DIR
Definition: globals.cpp:47
const QString VIDEO_COVERFILE_DEFAULT
Definition: globals.cpp:25
VideoContentType
@ kContentMusicVideo
@ kContentTelevision
@ kContentAdult
@ kContentUnknown
@ kContentHomeMovie
@ kContentMovie
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void CopySecond(const T &src, QStringList &dest)
Definition: videoutils.cpp:34
def rating(profile, smoonURL, gate)
Definition: scan.py:36
static constexpr uint16_t VIDEO_YEAR_DEFAULT
Definition: videometadata.h:18
bool IsDefaultScreenshot(const QString &screenshot)
Definition: videoutils.cpp:136
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:239
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:146
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:151
QString WatchedToState(bool watched)
Definition: videoutils.cpp:273
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:82
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:188
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:263
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:211
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:176
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:283
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:301
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:44
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:127
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:225
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:232
QString GetDisplayLength(std::chrono::minutes length)
Definition: videoutils.cpp:156
QString GetDisplayYear(int year)
Definition: videoutils.cpp:206
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:218
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:141
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:164
QStringList GetVideoDirs()
Definition: videoutils.cpp:122