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