MythTV master
playbackstate.cpp
Go to the documentation of this file.
1#include "playbackstate.h"
2
3// MythTV
10
12{
13 m_alwaysShowWatchedProgress = gCoreContext->GetBoolSetting("AlwaysShowWatchedProgress", false);
14}
15
17{
18 LOG(VB_GENERAL, LOG_INFO, "Query playback state for all videos from database");
19
20 m_fileMarkup.clear();
21
22 QueryData();
23
24 LOG(VB_GENERAL, LOG_INFO, QString("Collected playbackstate for %1 videos").arg(m_fileMarkup.count()));
25}
26
27void PlaybackState::Update(const QString &filename)
28{
29 if (!filename.isEmpty())
30 {
32 }
33}
34
35void PlaybackState::QueryData(const QString &filterFilename)
36{
38
39 if (filterFilename.isEmpty())
40 {
41 query.prepare("SELECT filename, type, mark, `offset` "
42 "FROM filemarkup "
43 "WHERE type IN (:BOOKMARK, :FRAMES, :PLAYPOS) "
44 "ORDER BY filename");
45 }
46 else
47 {
48 query.prepare("SELECT filename, type, mark, `offset` "
49 "FROM filemarkup "
50 "WHERE type IN (:BOOKMARK, :FRAMES, :PLAYPOS) "
51 "AND filename = :FILENAME "
52 "ORDER BY filename");
53 query.bindValue(":FILENAME", filterFilename);
54 }
55 query.bindValue(":BOOKMARK", MARK_BOOKMARK);
56 query.bindValue(":FRAMES", MARK_TOTAL_FRAMES);
57 query.bindValue(":PLAYPOS", MARK_UTIL_LASTPLAYPOS);
58
59 if (!query.exec())
60 {
61 MythDB::DBError("PlaybackState", query);
62 return;
63 }
64
65 QString lastFilename;
66 Markup currMarks;
67 while (query.next())
68 {
69 const QString filename = query.value(0).toString();
70 if (!lastFilename.isEmpty() && filename != lastFilename)
71 {
72 m_fileMarkup[lastFilename] = currMarks;
73 currMarks = Markup();
74 }
75 switch(query.value(1).toInt())
76 {
77 case MARK_BOOKMARK:
78 currMarks.bookmarkPos = query.value(2).toLongLong();
79 break;
81 currMarks.totalFrames = query.value(3).toLongLong();
82 break;
84 currMarks.lastPlayPos = query.value(2).toLongLong();
85 break;
86 }
87 lastFilename = filename;
88 }
89 m_fileMarkup[lastFilename] = currMarks;
90}
91
92bool PlaybackState::HasBookmark(const QString &filename) const
93{
94 auto it = m_fileMarkup.constFind(filename);
95 if (it == m_fileMarkup.constEnd())
96 {
97 return false;
98 }
99 return it.value().bookmarkPos > 0;
100}
101
102uint64_t PlaybackState::GetLastPlayPos(const QString &filename) const
103{
104 auto it = m_fileMarkup.constFind(filename);
105 if (it == m_fileMarkup.constEnd())
106 {
107 return 0;
108 }
109 return it.value().lastPlayPos;
110}
111
113{
114 auto it = m_fileMarkup.constFind(filename);
115 if (it == m_fileMarkup.constEnd())
116 {
117 return 0;
118 }
119 const auto pos = it.value().lastPlayPos;
120 const auto total = it.value().totalFrames;
121 if (0 == total)
122 {
123 return 0;
124 }
125 return std::clamp(100 * pos / total, (uint64_t)0, (uint64_t)100);
126}
127
129{
131}
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
QVariant value(int i) const
Definition: mythdbcon.h:204
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
bool GetBoolSetting(const QString &key, bool defaultval=false)
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
void Initialize()
Initializes playback state from database.
void Update(const QString &filename)
Updates playback state of video with specified filename.
bool AlwaysShowWatchedProgress() const
Returns cached setting "AlwaysShowWatchedProgress".
QMap< QString, Markup > m_fileMarkup
maps filename to markup
Definition: playbackstate.h:45
bool HasBookmark(const QString &filename) const
Query bookmark of video with the specified filename.
void QueryData(const QString &filterFilename=QString())
Query playback state from database, only for single video if a filename is specified.
uint64_t GetLastPlayPos(const QString &filename) const
Query last playback position of video with the specified filename.
uint GetWatchedPercent(const QString &filename) const
Query watched percent of video with the specified filename.
bool m_alwaysShowWatchedProgress
Definition: playbackstate.h:46
unsigned int uint
Definition: freesurround.h:24
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
@ MARK_BOOKMARK
Definition: programtypes.h:56
@ MARK_TOTAL_FRAMES
Definition: programtypes.h:74
@ MARK_UTIL_LASTPLAYPOS
Definition: programtypes.h:76
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:206
Markup for a video file.
Definition: playbackstate.h:39
uint64_t lastPlayPos
last playing position
Definition: playbackstate.h:41
uint64_t bookmarkPos
bookmark position
Definition: playbackstate.h:42
uint64_t totalFrames
total frames
Definition: playbackstate.h:40