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 protected:
23 QString GetWhereClause(MSqlBindings &bindings) const override; // SimpleDBStorage
24
25 private:
27};
28
30{
31 QString nameTag(":WHERENAME");
32 QString query("name = " + nameTag);
33
34 bindings.insert(nameTag, m_parent.getName());
35
36 return query;
37}
38
40{
41 public:
42 explicit TitleMatch(const PlayGroupConfig& _parent):
43 MythUITextEditSetting(new PlayGroupDBStorage(this, _parent, "titlematch"))
44 {
45 setLabel(PlayGroupConfig::tr("Title match (regex)"));
46 setHelpText(PlayGroupConfig::tr("Automatically set new recording rules "
47 "to use this group if the title "
48 "matches this regular expression. "
49 "For example, \"(News|CNN)\" would "
50 "match any title in which \"News\" or "
51 "\"CNN\" appears."));
52 };
53
54 ~TitleMatch() override
55 {
56 delete GetStorage();
57 }
58};
59
61{
62 public:
63 explicit SkipAhead(const PlayGroupConfig& _parent):
64 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipahead"),
65 0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
66
67 {
68 setLabel(PlayGroupConfig::tr("Skip ahead (seconds)"));
69 setHelpText(PlayGroupConfig::tr("How many seconds to skip forward on "
70 "a fast forward."));
71 };
72
73 ~SkipAhead() override
74 {
75 delete GetStorage();
76 }
77};
78
80{
81 public:
82 explicit SkipBack(const PlayGroupConfig& _parent):
83 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipback"),
84 0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
85 {
86 setLabel(PlayGroupConfig::tr("Skip back (seconds)"));
87 setHelpText(PlayGroupConfig::tr("How many seconds to skip backward on "
88 "a rewind."));
89 };
90
91 ~SkipBack() override
92 {
93 delete GetStorage();
94 }
95};
96
98{
99 public:
100 explicit JumpMinutes(const PlayGroupConfig& _parent):
101 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "jump"),
102 0, 30, 10, 1, PlayGroupConfig::tr("(default)"))
103 {
104 setLabel(PlayGroupConfig::tr("Jump amount (minutes)"));
105 setHelpText(PlayGroupConfig::tr("How many minutes to jump forward or "
106 "backward when the jump keys are "
107 "pressed."));
108 };
109
110 ~JumpMinutes() override
111 {
112 delete GetStorage();
113 }
114};
115
117{
118 public:
119 explicit TimeStretch(const PlayGroupConfig& _parent):
120 MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "timestretch"),
121 50, 200, 5, 1)
122 {
123 setValue(100);
124 setLabel(PlayGroupConfig::tr("Time stretch (speed x 100)"));
125 setHelpText(PlayGroupConfig::tr("Initial playback speed with adjusted "
126 "audio. Use 100 for normal speed, 50 "
127 "for half speed and 200 for double "
128 "speed."));
129 };
130
131 ~TimeStretch() override
132 {
133 delete GetStorage();
134 }
135
136 void Load(void) override // StandardSetting
137 {
139 if (intValue() < 50 || intValue() > 200)
140 setValue(45);
141 }
142
143 void Save(void) override // StandardSetting
144 {
145 if (intValue() < 50 || intValue() > 200)
146 setValue(0);
148 }
149};
150
151PlayGroupConfig::PlayGroupConfig(const QString &/*label*/, const QString &name,
152 bool isNew)
153 : m_isNew(isNew)
154{
155 setName(name);
156
157 //: %1 is the name of the playgroup
158 setLabel(tr("%1 Group", "Play Group").arg(getName()));
159
160 addChild(m_titleMatch = new TitleMatch(*this));
161 addChild(m_skipAhead = new SkipAhead(*this));
162 addChild(m_skipBack = new SkipBack(*this));
163 addChild(m_jumpMinutes = new JumpMinutes(*this));
164 addChild(m_timeStrech = new TimeStretch(*this));
165
166 // Ensure new entries are saved on exit
167 if (isNew)
168 setChanged(true);
169}
170
172{
174 item->SetText("", "value");
175}
176
178{
179 if (m_isNew)
180 {
181 QString titleMatch = m_titleMatch->getValue();
182 if (titleMatch.isNull())
183 titleMatch = "";
185
186 query.prepare("INSERT playgroup "
187 "(name, titlematch, skipahead, skipback, jump, timestretch) "
188 "VALUES "
189 "(:NEWNAME, :TITLEMATCH, :SKIPAHEAD, :SKIPBACK, :JUMP, :TIMESTRETCH);");
190
191 query.bindValue(":NEWNAME", getName());
192 query.bindValue(":TITLEMATCH", titleMatch);
193 query.bindValue(":SKIPAHEAD", m_skipAhead->intValue());
194 query.bindValue(":SKIPBACK", m_skipBack->intValue());
195 query.bindValue(":JUMP", m_jumpMinutes->intValue());
196 query.bindValue(":TIMESTRETCH", m_timeStrech->intValue());
197
198 if (!query.exec())
199 MythDB::DBError("PlayGroupConfig::Save", query);
200 }
201 else
202 {
204 }
205}
206
208{
209 return (getName() != "Default");
210}
211
213{
215 query.prepare("DELETE FROM playgroup "
216 "WHERE name = :NAME ;");
217 query.bindValue(":NAME", getName());
218
219 if (!query.exec())
220 MythDB::DBError("PlayGroupConfig::deleteEntry", query);
221}
222
224{
225 int names = 0;
226
228 query.prepare("SELECT COUNT(name) FROM playgroup "
229 "WHERE name <> 'Default' ORDER BY name;");
230 if (!query.exec())
231 MythDB::DBError("PlayGroupConfig::GetCount()", query);
232 else if (query.next())
233 names = query.value(0).toInt();
234
235 return names;
236}
237
238QStringList PlayGroup::GetNames(void)
239{
240 QStringList names;
241
243 query.prepare("SELECT name FROM playgroup "
244 "WHERE name <> 'Default' ORDER BY name;");
245 if (!query.exec())
246 {
247 MythDB::DBError("PlayGroupConfig::GetNames()", query);
248 }
249 else
250 {
251 while (query.next())
252 names << query.value(0).toString();
253 }
254
255 return names;
256}
257
259{
260 QString res = "Default";
261 QString title = pi->GetTitle().isEmpty() ? "Unknown" : pi->GetTitle();
262 QString category = pi->GetCategory().isEmpty() ? "Default" : pi->GetCategory();
263
265 query.prepare("SELECT name FROM playgroup "
266 "WHERE name = :TITLE1 OR "
267 " name = :CATEGORY OR "
268 " (titlematch <> '' AND "
269 " :TITLE2 REGEXP titlematch) ");
270 query.bindValue(":TITLE1", title);
271 query.bindValue(":TITLE2", title);
272 query.bindValue(":CATEGORY", category);
273
274 if (!query.exec())
275 MythDB::DBError("GetInitialName", query);
276 else if (query.next())
277 res = query.value(0).toString();
278
279 return res;
280}
281
282int PlayGroup::GetSetting(const QString &name, const QString &field,
283 int defval)
284{
285 int res = defval;
286
288 query.prepare(QString("SELECT name, %1 FROM playgroup "
289 "WHERE (name = :NAME OR name = 'Default') "
290 " AND %2 <> 0 "
291 "ORDER BY name = 'Default';")
292 .arg(field, field));
293 query.bindValue(":NAME", name);
294 if (!query.exec())
295 MythDB::DBError("PlayGroupConfig::GetSetting", query);
296 else if (query.next())
297 res = query.value(1).toInt();
298
299 return res;
300}
301
302
304{
305 setLabel(tr("Playback Groups"));
306 m_addGroupButton = new ButtonStandardSetting(tr("Create New Playback Group"));
310}
311
313{
314 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
315 auto *settingdialog = new MythTextInputDialog(popupStack,
316 tr("Enter new group name"));
317
318 if (settingdialog->Create())
319 {
320 connect(settingdialog, &MythTextInputDialog::haveResult,
322 popupStack->AddScreen(settingdialog);
323 }
324 else
325 {
326 delete settingdialog;
327 }
328}
329
331{
332 if (name.isEmpty())
333 {
334 ShowOkPopup(tr("Sorry, this Playback Group name cannot be blank."));
335 return;
336 }
337
339 query.prepare("SELECT name "
340 "FROM playgroup "
341 "WHERE name = :NAME");
342 query.bindValue(":NAME", name);
343
344 if (!query.exec())
345 {
346 MythDB::DBError("CreateNewPlayBackGroup", query);
347 return;
348 }
349
350 if (query.next())
351 {
352 ShowOkPopup(tr("Sorry, this Playback Group name is already in use."));
353 return;
354 }
355
356 addChild(new PlayGroupConfig(name, name, true));
357
358 emit settingsChanged(nullptr);
359}
360
362{
363 addChild(new PlayGroupConfig(tr("Default"), "Default"));
364
365 QStringList names = PlayGroup::GetNames();
366 while (!names.isEmpty())
367 {
368 addChild(new PlayGroupConfig(names.front(), names.front()));
369 names.pop_front();
370 }
371
372 //Load all the groups
374
375 //TODO select the new one or the edited one
376 emit settingsChanged(nullptr);
377}
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:110
JumpMinutes(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:100
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:838
QVariant value(int i) const
Definition: mythdbcon.h:204
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:619
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:889
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:813
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:551
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:225
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:151
StandardSetting * m_titleMatch
Definition: playgroup.h:59
MythUISpinBoxSetting * m_skipBack
Definition: playgroup.h:61
MythUISpinBoxSetting * m_jumpMinutes
Definition: playgroup.h:62
MythUISpinBoxSetting * m_timeStrech
Definition: playgroup.h:63
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:171
void Save() override
Definition: playgroup.cpp:177
MythUISpinBoxSetting * m_skipAhead
Definition: playgroup.h:60
void deleteEntry(void) override
Definition: playgroup.cpp:212
bool canDelete(void) override
Definition: playgroup.cpp:207
const PlayGroupConfig & m_parent
Definition: playgroup.cpp:26
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: playgroup.cpp:29
PlayGroupDBStorage(StandardSetting *_setting, const PlayGroupConfig &_parent, const QString &_name)
Definition: playgroup.cpp:15
void CreateNewPlayBackGroupSlot(const QString &name)
Definition: playgroup.cpp:330
void CreateNewPlayBackGroup() const
Definition: playgroup.cpp:312
void Load(void) override
Definition: playgroup.cpp:361
ButtonStandardSetting * m_addGroupButton
Definition: playgroup.h:44
PlayGroupEditor(void)
Definition: playgroup.cpp:303
static int GetCount(void)
Definition: playgroup.cpp:223
static QStringList GetNames(void)
Definition: playgroup.cpp:238
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:282
static QString GetInitialName(const ProgramInfo *pi)
Definition: playgroup.cpp:258
Holds information on recordings and videos.
Definition: programinfo.h:74
QString GetTitle(void) const
Definition: programinfo.h:368
QString GetCategory(void) const
Definition: programinfo.h:377
~SkipAhead() override
Definition: playgroup.cpp:73
SkipAhead(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:63
~SkipBack() override
Definition: playgroup.cpp:91
SkipBack(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:82
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:136
~TimeStretch() override
Definition: playgroup.cpp:131
void Save(void) override
Definition: playgroup.cpp:143
TimeStretch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:119
TitleMatch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:42
~TitleMatch() override
Definition: playgroup.cpp:54
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)