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 CheckedSet(tt, value);
62 else
63 {
64 auto *st = dynamic_cast<MythUIStateType *>(uit);
65 CheckedSet(st, value);
66 }
67 }
68}
69
70void CheckedSet(MythUIImage *uiItem, const QString &filename)
71{
72 if (uiItem)
73 {
74 uiItem->Reset();
75 uiItem->SetFilename(filename);
76 uiItem->Load();
77 }
78}
79
80QStringList GetVideoDirsByHost(const QString& host)
81{
82 QStringList tmp;
83
84 QStringList tmp2 = StorageGroup::getGroupDirs("Videos", host);
85 for (const auto& dir : std::as_const(tmp2))
86 tmp.append(dir);
87
88 if (host.isEmpty())
89 {
90#ifdef Q_OS_WINDOWS
91 QString seperator = ";";
92#else
93 QString seperator = ":";
94#endif
95 QStringList tmp3 = gCoreContext->GetSetting("VideoStartupDir",
96 DEFAULT_VIDEOSTARTUP_DIR).split(seperator, Qt::SkipEmptyParts);
97 for (const auto& dir : std::as_const(tmp3))
98 {
99 bool matches = false;
100 QString newpath = dir;
101 if (!newpath.endsWith("/"))
102 newpath.append("/");
103
104 for (const auto& comp : std::as_const(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
120QStringList GetVideoDirs()
121{
122 return GetVideoDirsByHost("");
123}
124
125bool 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
134bool IsDefaultScreenshot(const QString &screenshot)
135{
136 return screenshot == VIDEO_SCREENSHOT_DEFAULT;
137}
138
139bool IsDefaultBanner(const QString &banner)
140{
141 return banner == VIDEO_BANNER_DEFAULT;
142}
143
144bool IsDefaultFanart(const QString &fanart)
145{
146 return fanart == VIDEO_FANART_DEFAULT;
147}
148
149QString GetDisplayUserRating(float userrating)
150{
151 return QString::number(userrating, 'f', 1);
152}
153
154QString GetDisplayLength(std::chrono::minutes 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.count());
160}
161
162QString 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
174QString 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
186QString 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
204QString GetDisplayYear(int year)
205{
206 return year == VIDEO_YEAR_DEFAULT ? "?" : QString::number(year);
207}
208
209QString GetDisplayRating(const QString &rating)
210{
211 if (rating == "<NULL>")
212 return QCoreApplication::translate("(VideoUtils)", "No rating available.");
213 return rating;
214}
215
216QString GetDisplayGenres(const VideoMetadata &item)
217{
218 QStringList ret;
219 CopySecond(item.GetGenres(), ret);
220 return ret.join(", ");
221}
222
224{
225 QStringList ret;
226 CopySecond(item.GetCountries(), ret);
227 return ret.join(", ");
228}
229
230QStringList GetDisplayCast(const VideoMetadata &item)
231{
232 QStringList ret;
233 CopySecond(item.GetCast(), ret);
234 return ret;
235}
236
238{
239 QString ret;
240 switch (level.GetLevel())
241 {
243 ret = "Lowest";
244 break;
246 ret = "Low";
247 break;
249 ret = "Medium";
250 break;
252 ret = "High";
253 break;
254 default:
255 ret = "None";
256 }
257
258 return ret;
259}
260
261QString 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
271QString 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
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:134
QString ParentalLevelToState(const ParentalLevel &level)
Definition: videoutils.cpp:237
bool IsDefaultFanart(const QString &fanart)
Definition: videoutils.cpp:144
QString GetDisplayUserRating(float userrating)
Definition: videoutils.cpp:149
QString WatchedToState(bool watched)
Definition: videoutils.cpp:271
QStringList GetVideoDirsByHost(const QString &host)
Definition: videoutils.cpp:80
QString GetDisplayProcessed(bool processed)
Definition: videoutils.cpp:186
QString TrailerToState(const QString &trailerFile)
Definition: videoutils.cpp:261
QString GetDisplayRating(const QString &rating)
Definition: videoutils.cpp:209
QString GetDisplayWatched(bool watched)
Definition: videoutils.cpp:174
VideoContentType ContentTypeFromString(const QString &type)
Definition: videoutils.cpp:281
QString ContentTypeToString(VideoContentType type)
Definition: videoutils.cpp:299
void CheckedSet(MythUIStateType *uiItem, const QString &value)
Definition: videoutils.cpp:44
bool IsDefaultCoverFile(const QString &coverfile)
Definition: videoutils.cpp:125
QString GetDisplayCountries(const VideoMetadata &item)
Definition: videoutils.cpp:223
QStringList GetDisplayCast(const VideoMetadata &item)
Definition: videoutils.cpp:230
QString GetDisplayLength(std::chrono::minutes length)
Definition: videoutils.cpp:154
QString GetDisplayYear(int year)
Definition: videoutils.cpp:204
QString GetDisplayGenres(const VideoMetadata &item)
Definition: videoutils.cpp:216
bool IsDefaultBanner(const QString &banner)
Definition: videoutils.cpp:139
QString GetDisplayBrowse(bool browse)
Definition: videoutils.cpp:162
QStringList GetVideoDirs()
Definition: videoutils.cpp:120