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