MythTV master
playgroup.cpp
Go to the documentation of this file.
1// Qt headers
2#include <QCoreApplication>
3
4// MythTV headers
7
8#include "playgroup.h"
9#include "programinfo.h"
10
11// A parameter associated with the profile itself
13{
14 public:
16 const PlayGroupConfig &_parent,
17 const QString& _name) :
18 SimpleDBStorage(_setting, "playgroup", _name), m_parent(_parent)
19 {
20 }
21
22 QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
23
25};
26
28{
29 QString nameTag(":WHERENAME");
30 QString query("name = " + nameTag);
31
32 bindings.insert(nameTag, m_parent.getName());
33
34 return query;
35}
36
38{
39 public:
40 explicit TitleMatch(const PlayGroupConfig& _parent):
41 MythUITextEditSetting(new PlayGroupDBStorage(this, _parent, "titlematch"))
42 {
43 setLabel(PlayGroupConfig::tr("Title match (regex)"));
44 setHelpText(PlayGroupConfig::tr("Automatically set new recording rules "
45 "to use this group if the title "
46 "matches this regular expression. "
47 "For example, \"(News|CNN)\" would "
48 "match any title in which \"News\" or "
49 "\"CNN\" appears."));
50 };
51
52 ~TitleMatch() override
53 {
54 delete GetStorage();
55 }
56};
57
59{
60 public:
61 explicit SkipAhead(const PlayGroupConfig& _parent):
62 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipahead"),
63 0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
64
65 {
66 setLabel(PlayGroupConfig::tr("Skip ahead (seconds)"));
67 setHelpText(PlayGroupConfig::tr("How many seconds to skip forward on "
68 "a fast forward."));
69 };
70
71 ~SkipAhead() override
72 {
73 delete GetStorage();
74 }
75};
76
78{
79 public:
80 explicit SkipBack(const PlayGroupConfig& _parent):
81 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipback"),
82 0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
83 {
84 setLabel(PlayGroupConfig::tr("Skip back (seconds)"));
85 setHelpText(PlayGroupConfig::tr("How many seconds to skip backward on "
86 "a rewind."));
87 };
88
89 ~SkipBack() override
90 {
91 delete GetStorage();
92 }
93};
94
96{
97 public:
98 explicit JumpMinutes(const PlayGroupConfig& _parent):
99 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "jump"),
100 0, 30, 10, 1, PlayGroupConfig::tr("(default)"))
101 {
102 setLabel(PlayGroupConfig::tr("Jump amount (minutes)"));
103 setHelpText(PlayGroupConfig::tr("How many minutes to jump forward or "
104 "backward when the jump keys are "
105 "pressed."));
106 };
107
108 ~JumpMinutes() override
109 {
110 delete GetStorage();
111 }
112};
113
115{
116 public:
117 explicit TimeStretch(const PlayGroupConfig& _parent):
118 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "timestretch"),
119 50, 200, 5, 1)
120 {
121 setValue(100);
122 setLabel(PlayGroupConfig::tr("Time stretch (speed x 100)"));
123 setHelpText(PlayGroupConfig::tr("Initial playback speed with adjusted "
124 "audio. Use 100 for normal speed, 50 "
125 "for half speed and 200 for double "
126 "speed."));
127 };
128
129 ~TimeStretch() override
130 {
131 delete GetStorage();
132 }
133
134 void Load(void) override // StandardSetting
135 {
137 if (intValue() < 50 || intValue() > 200)
138 setValue(45);
139 }
140
141 void Save(void) override // StandardSetting
142 {
143 if (intValue() < 50 || intValue() > 200)
144 setValue(0);
146 }
147};
148
149PlayGroupConfig::PlayGroupConfig(const QString &/*label*/, const QString &name,
150 bool isNew)
151 : m_isNew(isNew)
152{
153 setName(name);
154
155 //: %1 is the name of the playgroup
156 setLabel(tr("%1 Group", "Play Group").arg(getName()));
157
158 addChild(m_titleMatch = new TitleMatch(*this));
159 addChild(m_skipAhead = new SkipAhead(*this));
160 addChild(m_skipBack = new SkipBack(*this));
161 addChild(m_jumpMinutes = new JumpMinutes(*this));
162 addChild(m_timeStrech = new TimeStretch(*this));
163
164 // Ensure new entries are saved on exit
165 if (isNew)
166 setChanged(true);
167}
168
170{
172 item->SetText("", "value");
173}
174
176{
177 if (m_isNew)
178 {
179 QString titleMatch = m_titleMatch->getValue();
180 if (titleMatch.isNull())
181 titleMatch = "";
183
184 query.prepare("INSERT playgroup "
185 "(name, titlematch, skipahead, skipback, jump, timestretch) "
186 "VALUES "
187 "(:NEWNAME, :TITLEMATCH, :SKIPAHEAD, :SKIPBACK, :JUMP, :TIMESTRETCH);");
188
189 query.bindValue(":NEWNAME", getName());
190 query.bindValue(":TITLEMATCH", titleMatch);
191 query.bindValue(":SKIPAHEAD", m_skipAhead->intValue());
192 query.bindValue(":SKIPBACK", m_skipBack->intValue());
193 query.bindValue(":JUMP", m_jumpMinutes->intValue());
194 query.bindValue(":TIMESTRETCH", m_timeStrech->intValue());
195
196 if (!query.exec())
197 MythDB::DBError("PlayGroupConfig::Save", query);
198 }
199 else
200 {
202 }
203}
204
206{
207 return (getName() != "Default");
208}
209
211{
213 query.prepare("DELETE FROM playgroup "
214 "WHERE name = :NAME ;");
215 query.bindValue(":NAME", getName());
216
217 if (!query.exec())
218 MythDB::DBError("PlayGroupConfig::deleteEntry", query);
219}
220
222{
223 int names = 0;
224
226 query.prepare("SELECT COUNT(name) FROM playgroup "
227 "WHERE name <> 'Default' ORDER BY name;");
228 if (!query.exec())
229 MythDB::DBError("PlayGroupConfig::GetCount()", query);
230 else if (query.next())
231 names = query.value(0).toInt();
232
233 return names;
234}
235
236QStringList PlayGroup::GetNames(void)
237{
238 QStringList names;
239
241 query.prepare("SELECT name FROM playgroup "
242 "WHERE name <> 'Default' ORDER BY name;");
243 if (!query.exec())
244 MythDB::DBError("PlayGroupConfig::GetNames()", query);
245 else
246 {
247 while (query.next())
248 names << query.value(0).toString();
249 }
250
251 return names;
252}
253
255{
256 QString res = "Default";
257 QString title = pi->GetTitle().isEmpty() ? "Unknown" : pi->GetTitle();
258 QString category = pi->GetCategory().isEmpty() ? "Default" : pi->GetCategory();
259
261 query.prepare("SELECT name FROM playgroup "
262 "WHERE name = :TITLE1 OR "
263 " name = :CATEGORY OR "
264 " (titlematch <> '' AND "
265 " :TITLE2 REGEXP titlematch) ");
266 query.bindValue(":TITLE1", title);
267 query.bindValue(":TITLE2", title);
268 query.bindValue(":CATEGORY", category);
269
270 if (!query.exec())
271 MythDB::DBError("GetInitialName", query);
272 else if (query.next())
273 res = query.value(0).toString();
274
275 return res;
276}
277
278int PlayGroup::GetSetting(const QString &name, const QString &field,
279 int defval)
280{
281 int res = defval;
282
284 query.prepare(QString("SELECT name, %1 FROM playgroup "
285 "WHERE (name = :NAME OR name = 'Default') "
286 " AND %2 <> 0 "
287 "ORDER BY name = 'Default';")
288 .arg(field, field));
289 query.bindValue(":NAME", name);
290 if (!query.exec())
291 MythDB::DBError("PlayGroupConfig::GetSetting", query);
292 else if (query.next())
293 res = query.value(1).toInt();
294
295 return res;
296}
297
298
300{
301 setLabel(tr("Playback Groups"));
302 m_addGroupButton = new ButtonStandardSetting(tr("Create New Playback Group"));
306}
307
309{
310 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
311 auto *settingdialog = new MythTextInputDialog(popupStack,
312 tr("Enter new group name"));
313
314 if (settingdialog->Create())
315 {
316 connect(settingdialog, &MythTextInputDialog::haveResult,
318 popupStack->AddScreen(settingdialog);
319 }
320 else
321 {
322 delete settingdialog;
323 }
324}
325
327{
328 if (name.isEmpty())
329 {
330 ShowOkPopup(tr("Sorry, this Playback Group name cannot be blank."));
331 return;
332 }
333
335 query.prepare("SELECT name "
336 "FROM playgroup "
337 "WHERE name = :NAME");
338 query.bindValue(":NAME", name);
339
340 if (!query.exec())
341 {
342 MythDB::DBError("CreateNewPlayBackGroup", query);
343 return;
344 }
345
346 if (query.next())
347 {
348 ShowOkPopup(tr("Sorry, this Playback Group name is already in use."));
349 return;
350 }
351
352 addChild(new PlayGroupConfig(name, name, true));
353
354 emit settingsChanged(nullptr);
355}
356
358{
359 addChild(new PlayGroupConfig(tr("Default"), "Default"));
360
361 QStringList names = PlayGroup::GetNames();
362 while (!names.isEmpty())
363 {
364 addChild(new PlayGroupConfig(names.front(), names.front()));
365 names.pop_front();
366 }
367
368 //Load all the groups
370
371 //TODO select the new one or the edited one
372 emit settingsChanged(nullptr);
373}
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
~JumpMinutes() override
Definition: playgroup.cpp:108
JumpMinutes(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:98
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
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Dialog prompting the user to enter a text string.
void haveResult(QString)
void SetText(const QString &text, const QString &name="", const QString &state="")
PlayGroupConfig(const QString &label, const QString &name, bool isNew=false)
Definition: playgroup.cpp:149
StandardSetting * m_titleMatch
Definition: playgroup.h:63
MythUISpinBoxSetting * m_skipBack
Definition: playgroup.h:65
MythUISpinBoxSetting * m_jumpMinutes
Definition: playgroup.h:66
MythUISpinBoxSetting * m_timeStrech
Definition: playgroup.h:67
void updateButton(MythUIButtonListItem *item) override
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
Definition: playgroup.cpp:169
void Save() override
Definition: playgroup.cpp:175
MythUISpinBoxSetting * m_skipAhead
Definition: playgroup.h:64
void deleteEntry(void) override
Definition: playgroup.cpp:210
bool canDelete(void) override
Definition: playgroup.cpp:205
const PlayGroupConfig & m_parent
Definition: playgroup.cpp:24
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: playgroup.cpp:27
PlayGroupDBStorage(StandardSetting *_setting, const PlayGroupConfig &_parent, const QString &_name)
Definition: playgroup.cpp:15
void CreateNewPlayBackGroupSlot(const QString &name)
Definition: playgroup.cpp:326
void CreateNewPlayBackGroup() const
Definition: playgroup.cpp:308
void Load(void) override
Definition: playgroup.cpp:357
ButtonStandardSetting * m_addGroupButton
Definition: playgroup.h:48
PlayGroupEditor(void)
Definition: playgroup.cpp:299
static int GetCount(void)
Definition: playgroup.cpp:221
static QStringList GetNames(void)
Definition: playgroup.cpp:236
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:278
static QString GetInitialName(const ProgramInfo *pi)
Definition: playgroup.cpp:254
Holds information on recordings and videos.
Definition: programinfo.h:70
QString GetTitle(void) const
Definition: programinfo.h:364
QString GetCategory(void) const
Definition: programinfo.h:372
~SkipAhead() override
Definition: playgroup.cpp:71
SkipAhead(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:61
~SkipBack() override
Definition: playgroup.cpp:89
SkipBack(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:80
virtual void addChild(StandardSetting *child)
virtual void Save(void)
virtual void Load(void)
virtual void setName(const QString &name)
QString getName(void) const
void settingsChanged(StandardSetting *selectedSetting=nullptr)
virtual void setHelpText(const QString &str)
virtual void setValue(const QString &newValue)
Storage * GetStorage(void) const
virtual QString getValue(void) const
virtual void setLabel(QString str)
void setChanged(bool changed)
void Load(void) override
Definition: playgroup.cpp:134
~TimeStretch() override
Definition: playgroup.cpp:129
void Save(void) override
Definition: playgroup.cpp:141
TimeStretch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:117
TitleMatch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:40
~TitleMatch() override
Definition: playgroup.cpp:52
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:100
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
MythMainWindow * GetMythMainWindow(void)