MythTV  master
playgroup.cpp
Go to the documentation of this file.
1 // Qt headers
2 #include <QCoreApplication>
3 
4 // MythTV headers
6 #include "libmythbase/mythdb.h"
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 
53 {
54  public:
55  explicit SkipAhead(const PlayGroupConfig& _parent):
56  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipahead"),
57  0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
58 
59  {
60  setLabel(PlayGroupConfig::tr("Skip ahead (seconds)"));
61  setHelpText(PlayGroupConfig::tr("How many seconds to skip forward on "
62  "a fast forward."));
63  };
64 };
65 
67 {
68  public:
69  explicit SkipBack(const PlayGroupConfig& _parent):
70  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipback"),
71  0, 600, 5, 1, PlayGroupConfig::tr("(default)"))
72  {
73  setLabel(PlayGroupConfig::tr("Skip back (seconds)"));
74  setHelpText(PlayGroupConfig::tr("How many seconds to skip backward on "
75  "a rewind."));
76  };
77 };
78 
80 {
81  public:
82  explicit JumpMinutes(const PlayGroupConfig& _parent):
83  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "jump"),
84  0, 30, 10, 1, PlayGroupConfig::tr("(default)"))
85  {
86  setLabel(PlayGroupConfig::tr("Jump amount (minutes)"));
87  setHelpText(PlayGroupConfig::tr("How many minutes to jump forward or "
88  "backward when the jump keys are "
89  "pressed."));
90  };
91 };
92 
94 {
95  public:
96  explicit TimeStretch(const PlayGroupConfig& _parent):
97  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "timestretch"),
98  50, 200, 5, 1)
99  {
100  setValue(100);
101  setLabel(PlayGroupConfig::tr("Time stretch (speed x 100)"));
102  setHelpText(PlayGroupConfig::tr("Initial playback speed with adjusted "
103  "audio. Use 100 for normal speed, 50 "
104  "for half speed and 200 for double "
105  "speed."));
106  };
107 
108  void Load(void) override // StandardSetting
109  {
111  if (intValue() < 50 || intValue() > 200)
112  setValue(45);
113  }
114 
115  void Save(void) override // StandardSetting
116  {
117  if (intValue() < 50 || intValue() > 200)
118  setValue(0);
120  }
121 };
122 
123 PlayGroupConfig::PlayGroupConfig(const QString &/*label*/, const QString &name,
124  bool isNew)
125  : m_isNew(isNew)
126 {
127  setName(name);
128 
129  //: %1 is the name of the playgroup
130  setLabel(tr("%1 Group", "Play Group").arg(getName()));
131 
132  addChild(m_titleMatch = new TitleMatch(*this));
133  addChild(m_skipAhead = new SkipAhead(*this));
134  addChild(m_skipBack = new SkipBack(*this));
135  addChild(m_jumpMinutes = new JumpMinutes(*this));
136  addChild(m_timeStrech = new TimeStretch(*this));
137 
138  // Ensure new entries are saved on exit
139  if (isNew)
140  setChanged(true);
141 }
142 
144 {
146  item->SetText("", "value");
147 }
148 
150 {
151  if (m_isNew)
152  {
153  QString titleMatch = m_titleMatch->getValue();
154  if (titleMatch.isNull())
155  titleMatch = "";
156  MSqlQuery query(MSqlQuery::InitCon());
157 
158  query.prepare("INSERT playgroup "
159  "(name, titlematch, skipahead, skipback, jump, timestretch) "
160  "VALUES "
161  "(:NEWNAME, :TITLEMATCH, :SKIPAHEAD, :SKIPBACK, :JUMP, :TIMESTRETCH);");
162 
163  query.bindValue(":NEWNAME", getName());
164  query.bindValue(":TITLEMATCH", titleMatch);
165  query.bindValue(":SKIPAHEAD", m_skipAhead->intValue());
166  query.bindValue(":SKIPBACK", m_skipBack->intValue());
167  query.bindValue(":JUMP", m_jumpMinutes->intValue());
168  query.bindValue(":TIMESTRETCH", m_timeStrech->intValue());
169 
170  if (!query.exec())
171  MythDB::DBError("PlayGroupConfig::Save", query);
172  }
173  else
174  {
176  }
177 }
178 
180 {
181  return (getName() != "Default");
182 }
183 
185 {
186  MSqlQuery query(MSqlQuery::InitCon());
187  query.prepare("DELETE FROM playgroup "
188  "WHERE name = :NAME ;");
189  query.bindValue(":NAME", getName());
190 
191  if (!query.exec())
192  MythDB::DBError("PlayGroupConfig::deleteEntry", query);
193 }
194 
196 {
197  int names = 0;
198 
199  MSqlQuery query(MSqlQuery::InitCon());
200  query.prepare("SELECT COUNT(name) FROM playgroup "
201  "WHERE name <> 'Default' ORDER BY name;");
202  if (!query.exec())
203  MythDB::DBError("PlayGroupConfig::GetCount()", query);
204  else if (query.next())
205  names = query.value(0).toInt();
206 
207  return names;
208 }
209 
210 QStringList PlayGroup::GetNames(void)
211 {
212  QStringList names;
213 
214  MSqlQuery query(MSqlQuery::InitCon());
215  query.prepare("SELECT name FROM playgroup "
216  "WHERE name <> 'Default' ORDER BY name;");
217  if (!query.exec())
218  MythDB::DBError("PlayGroupConfig::GetNames()", query);
219  else
220  {
221  while (query.next())
222  names << query.value(0).toString();
223  }
224 
225  return names;
226 }
227 
229 {
230  QString res = "Default";
231  QString title = pi->GetTitle().isEmpty() ? "Unknown" : pi->GetTitle();
232  QString category = pi->GetCategory().isEmpty() ? "Default" : pi->GetCategory();
233 
234  MSqlQuery query(MSqlQuery::InitCon());
235  query.prepare("SELECT name FROM playgroup "
236  "WHERE name = :TITLE1 OR "
237  " name = :CATEGORY OR "
238  " (titlematch <> '' AND "
239  " :TITLE2 REGEXP titlematch) ");
240  query.bindValue(":TITLE1", title);
241  query.bindValue(":TITLE2", title);
242  query.bindValue(":CATEGORY", category);
243 
244  if (!query.exec())
245  MythDB::DBError("GetInitialName", query);
246  else if (query.next())
247  res = query.value(0).toString();
248 
249  return res;
250 }
251 
252 int PlayGroup::GetSetting(const QString &name, const QString &field,
253  int defval)
254 {
255  int res = defval;
256 
257  MSqlQuery query(MSqlQuery::InitCon());
258  query.prepare(QString("SELECT name, %1 FROM playgroup "
259  "WHERE (name = :NAME OR name = 'Default') "
260  " AND %2 <> 0 "
261  "ORDER BY name = 'Default';")
262  .arg(field, field));
263  query.bindValue(":NAME", name);
264  if (!query.exec())
265  MythDB::DBError("PlayGroupConfig::GetSetting", query);
266  else if (query.next())
267  res = query.value(1).toInt();
268 
269  return res;
270 }
271 
272 
274 {
275  setLabel(tr("Playback Groups"));
276  m_addGroupButton = new ButtonStandardSetting(tr("Create New Playback Group"));
280 }
281 
283 {
284  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
285  auto *settingdialog = new MythTextInputDialog(popupStack,
286  tr("Enter new group name"));
287 
288  if (settingdialog->Create())
289  {
290  connect(settingdialog, &MythTextInputDialog::haveResult,
292  popupStack->AddScreen(settingdialog);
293  }
294  else
295  {
296  delete settingdialog;
297  }
298 }
299 
301 {
302  if (name.isEmpty())
303  {
304  ShowOkPopup(tr("Sorry, this Playback Group name cannot be blank."));
305  return;
306  }
307 
308  MSqlQuery query(MSqlQuery::InitCon());
309  query.prepare("SELECT name "
310  "FROM playgroup "
311  "WHERE name = :NAME");
312  query.bindValue(":NAME", name);
313 
314  if (!query.exec())
315  {
316  MythDB::DBError("CreateNewPlayBackGroup", query);
317  return;
318  }
319 
320  if (query.next())
321  {
322  ShowOkPopup(tr("Sorry, this Playback Group name is already in use."));
323  return;
324  }
325 
326  addChild(new PlayGroupConfig(name, name, true));
327 
328  emit settingsChanged(nullptr);
329 }
330 
332 {
333  addChild(new PlayGroupConfig(tr("Default"), "Default"));
334 
335  QStringList names = PlayGroup::GetNames();
336  while (!names.isEmpty())
337  {
338  addChild(new PlayGroupConfig(names.front(), names.front()));
339  names.pop_front();
340  }
341 
342  //Load all the groups
344 
345  //TODO select the new one or the edited one
346  emit settingsChanged(nullptr);
347 }
PlayGroup::GetSetting
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:252
MSqlBindings
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:100
PlayGroupConfig::m_skipAhead
MythUISpinBoxSetting * m_skipAhead
Definition: playgroup.h:54
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
StandardSetting::setName
virtual void setName(const QString &name)
Definition: standardsettings.cpp:253
StandardSetting::setValue
virtual void setValue(const QString &newValue)
Definition: standardsettings.cpp:170
TitleMatch::TitleMatch
TitleMatch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:39
mythdb.h
PlayGroupDBStorage::m_parent
const PlayGroupConfig & m_parent
Definition: playgroup.cpp:23
PlayGroupDBStorage
Definition: playgroup.cpp:11
PlayGroup::GetInitialName
static QString GetInitialName(const ProgramInfo *pi)
Definition: playgroup.cpp:228
PlayGroupEditor::Load
void Load(void) override
Definition: playgroup.cpp:331
ButtonStandardSetting
Definition: standardsettings.h:450
TimeStretch
Definition: playgroup.cpp:93
PlayGroupConfig::PlayGroupConfig
PlayGroupConfig(const QString &label, const QString &name, bool isNew=false)
Definition: playgroup.cpp:123
SkipAhead::SkipAhead
SkipAhead(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:55
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
MythScreenStack
Definition: mythscreenstack.h:16
SkipBack::SkipBack
SkipBack(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:69
ProgramInfo::GetCategory
QString GetCategory(void) const
Definition: programinfo.h:370
GroupSetting::updateButton
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: standardsettings.cpp:305
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
JumpMinutes
Definition: playgroup.cpp:79
playgroup.h
PlayGroupEditor::CreateNewPlayBackGroup
void CreateNewPlayBackGroup() const
Definition: playgroup.cpp:282
PlayGroupConfig::m_jumpMinutes
MythUISpinBoxSetting * m_jumpMinutes
Definition: playgroup.h:56
SimpleDBStorage
Definition: mythstorage.h:55
PlayGroupEditor::CreateNewPlayBackGroupSlot
void CreateNewPlayBackGroupSlot(const QString &name)
Definition: playgroup.cpp:300
TimeStretch::TimeStretch
TimeStretch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:96
MythTextInputDialog::haveResult
void haveResult(QString)
PlayGroupConfig::m_isNew
bool m_isNew
Definition: playgroup.h:58
ButtonStandardSetting::clicked
void clicked()
MythUIButtonListItem::SetText
void SetText(const QString &text, const QString &name="", const QString &state="")
Definition: mythuibuttonlist.cpp:3319
PlayGroup::GetNames
static QStringList GetNames(void)
Definition: playgroup.cpp:210
SkipBack
Definition: playgroup.cpp:66
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
PlayGroupConfig
Definition: playgroup.h:41
StandardSetting::setChanged
void setChanged(bool changed)
Definition: standardsettings.cpp:209
StandardSetting::settingsChanged
void settingsChanged(StandardSetting *selectedSetting=nullptr)
StandardSetting::addChild
virtual void addChild(StandardSetting *child)
Definition: standardsettings.cpp:71
programinfo.h
PlayGroup::GetCount
static int GetCount(void)
Definition: playgroup.cpp:195
PlayGroupConfig::m_timeStrech
MythUISpinBoxSetting * m_timeStrech
Definition: playgroup.h:57
StandardSetting::getName
QString getName(void) const
Definition: standardsettings.h:41
ProgramInfo::GetTitle
QString GetTitle(void) const
Definition: programinfo.h:362
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:225
MythUISpinBoxSetting::intValue
int intValue()
Definition: standardsettings.cpp:686
StandardSetting::Load
virtual void Load(void)
Definition: standardsettings.cpp:214
SkipAhead
Definition: playgroup.cpp:52
StandardSetting::setHelpText
virtual void setHelpText(const QString &str)
Definition: standardsettings.h:37
TimeStretch::Load
void Load(void) override
Definition: playgroup.cpp:108
StandardSetting::Save
virtual void Save(void)
Definition: standardsettings.cpp:233
PlayGroupConfig::canDelete
bool canDelete(void) override
Definition: playgroup.cpp:179
PlayGroupConfig::m_skipBack
MythUISpinBoxSetting * m_skipBack
Definition: playgroup.h:55
StandardSetting::getValue
virtual QString getValue(void) const
Definition: standardsettings.h:52
StandardSetting::setLabel
virtual void setLabel(QString str)
Definition: standardsettings.h:34
TimeStretch::Save
void Save(void) override
Definition: playgroup.cpp:115
standardsettings.h
PlayGroupConfig::m_titleMatch
StandardSetting * m_titleMatch
Definition: playgroup.h:53
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
PlayGroupEditor::PlayGroupEditor
PlayGroupEditor(void)
Definition: playgroup.cpp:273
MythUITextEditSetting
Definition: standardsettings.h:146
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
MythUISpinBoxSetting
Definition: standardsettings.h:328
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
StandardSetting
Definition: standardsettings.h:29
PlayGroupDBStorage::PlayGroupDBStorage
PlayGroupDBStorage(StandardSetting *_setting, const PlayGroupConfig &_parent, const QString &_name)
Definition: playgroup.cpp:14
PlayGroupConfig::Save
void Save() override
Definition: playgroup.cpp:149
MythTextInputDialog
Dialog prompting the user to enter a text string.
Definition: mythdialogbox.h:314
PlayGroupDBStorage::GetWhereClause
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: playgroup.cpp:26
PlayGroupConfig::deleteEntry
void deleteEntry(void) override
Definition: playgroup.cpp:184
JumpMinutes::JumpMinutes
JumpMinutes(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:82
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
ShowOkPopup
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
Definition: mythdialogbox.cpp:566
PlayGroupEditor::m_addGroupButton
ButtonStandardSetting * m_addGroupButton
Definition: playgroup.h:38
PlayGroupConfig::updateButton
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:143
TitleMatch
Definition: playgroup.cpp:36
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837