MythTV  master
playgroup.cpp
Go to the documentation of this file.
1 // Qt headers
2 #include <QCoreApplication>
3 
4 // MythTV headers
5 #include "mythdb.h"
6 #include "playgroup.h"
7 #include "programinfo.h"
8 #include "standardsettings.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  45, 200, 5, 0,
99  PlayGroupConfig::tr("(default)"))
100  {
101  setValue(45);
102  setLabel(PlayGroupConfig::tr("Time stretch (speed x 100)"));
103  setHelpText(PlayGroupConfig::tr("Initial playback speed with adjusted "
104  "audio. Use 100 for normal speed, 50 "
105  "for half speed and 200 for double "
106  "speed."));
107  };
108 
109  void Load(void) override // StandardSetting
110  {
112  if (intValue() < 50 || intValue() > 200)
113  setValue(45);
114  }
115 
116  void Save(void) override // StandardSetting
117  {
118  if (intValue() < 50 || intValue() > 200)
119  setValue(0);
121  }
122 };
123 
124 PlayGroupConfig::PlayGroupConfig(const QString &/*label*/, const QString &name,
125  bool isNew)
126  : m_isNew(isNew)
127 {
128  setName(name);
129 
130  //: %1 is the name of the playgroup
131  setLabel(tr("%1 Group", "Play Group").arg(getName()));
132 
133  addChild(m_titleMatch = new TitleMatch(*this));
134  addChild(m_skipAhead = new SkipAhead(*this));
135  addChild(m_skipBack = new SkipBack(*this));
136  addChild(m_jumpMinutes = new JumpMinutes(*this));
137  addChild(m_timeStrech = new TimeStretch(*this));
138 
139  // Ensure new entries are saved on exit
140  if (isNew)
141  setChanged(true);
142 }
143 
145 {
147  item->SetText("", "value");
148 }
149 
151 {
152  if (m_isNew)
153  {
155 
156  query.prepare("INSERT playgroup "
157  "(name, titlematch, skipahead, skipback, jump, timestretch) "
158  "VALUES "
159  "(:NEWNAME, :TITLEMATCH, :SKIPAHEAD, :SKIPBACK, :JUMP, :TIMESTRETCH);");
160 
161  query.bindValue(":NEWNAME", getName());
162  query.bindValue(":TITLEMATCH", m_titleMatch->getValue());
163  query.bindValue(":SKIPAHEAD", m_skipAhead->intValue());
164  query.bindValue(":SKIPBACK", m_skipBack->intValue());
165  query.bindValue(":JUMP", m_jumpMinutes->intValue());
166  query.bindValue(":TIMESTRETCH", m_timeStrech->intValue());
167 
168  if (!query.exec())
169  MythDB::DBError("PlayGroupConfig::Save", query);
170  }
171  else
173 }
174 
176 {
177  return (getName() != "Default");
178 }
179 
181 {
183  query.prepare("DELETE FROM playgroup "
184  "WHERE name = :NAME ;");
185  query.bindValue(":NAME", getName());
186 
187  if (!query.exec())
188  MythDB::DBError("PlayGroupConfig::deleteEntry", query);
189 }
190 
192 {
193  int names = 0;
194 
196  query.prepare("SELECT COUNT(name) FROM playgroup "
197  "WHERE name <> 'Default' ORDER BY name;");
198  if (!query.exec())
199  MythDB::DBError("PlayGroupConfig::GetCount()", query);
200  else if (query.next())
201  names = query.value(0).toInt();
202 
203  return names;
204 }
205 
206 QStringList PlayGroup::GetNames(void)
207 {
208  QStringList names;
209 
211  query.prepare("SELECT name FROM playgroup "
212  "WHERE name <> 'Default' ORDER BY name;");
213  if (!query.exec())
214  MythDB::DBError("PlayGroupConfig::GetNames()", query);
215  else
216  {
217  while (query.next())
218  names << query.value(0).toString();
219  }
220 
221  return names;
222 }
223 
225 {
226  QString res = "Default";
227 
229  query.prepare("SELECT name FROM playgroup "
230  "WHERE name = :TITLE1 OR "
231  " name = :CATEGORY OR "
232  " (titlematch <> '' AND "
233  " :TITLE2 REGEXP titlematch) ");
234  query.bindValue(":TITLE1", pi->GetTitle());
235  query.bindValue(":TITLE2", pi->GetTitle());
236  query.bindValue(":CATEGORY", pi->GetCategory());
237 
238  if (!query.exec())
239  MythDB::DBError("GetInitialName", query);
240  else if (query.next())
241  res = query.value(0).toString();
242 
243  return res;
244 }
245 
246 int PlayGroup::GetSetting(const QString &name, const QString &field,
247  int defval)
248 {
249  int res = defval;
250 
252  query.prepare(QString("SELECT name, %1 FROM playgroup "
253  "WHERE (name = :NAME OR name = 'Default') "
254  " AND %2 <> 0 "
255  "ORDER BY name = 'Default';")
256  .arg(field).arg(field));
257  query.bindValue(":NAME", name);
258  if (!query.exec())
259  MythDB::DBError("PlayGroupConfig::GetSetting", query);
260  else if (query.next())
261  res = query.value(1).toInt();
262 
263  return res;
264 }
265 
266 
268 {
269  setLabel(tr("Playback Groups"));
270  m_addGroupButton = new ButtonStandardSetting(tr("Create New Playback Group"));
272  connect(m_addGroupButton, SIGNAL(clicked()),
273  this, SLOT(CreateNewPlayBackGroup()));
274 }
275 
277 {
278  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
279  auto *settingdialog = new MythTextInputDialog(popupStack,
280  tr("Enter new group name"));
281 
282  if (settingdialog->Create())
283  {
284  connect(settingdialog, SIGNAL(haveResult(QString)),
285  SLOT(CreateNewPlayBackGroupSlot(const QString&)));
286  popupStack->AddScreen(settingdialog);
287  }
288  else
289  delete settingdialog;
290 }
291 
293 {
294  if (name.isEmpty())
295  {
296  ShowOkPopup(tr("Sorry, this Playback Group name cannot be blank."));
297  return;
298  }
299 
301  query.prepare("SELECT name "
302  "FROM playgroup "
303  "WHERE name = :NAME");
304  query.bindValue(":NAME", name);
305 
306  if (!query.exec())
307  {
308  MythDB::DBError("CreateNewPlayBackGroup", query);
309  return;
310  }
311 
312  if (query.next())
313  {
314  ShowOkPopup(tr("Sorry, this Playback Group name is already in use."));
315  return;
316  }
317 
318  addChild(new PlayGroupConfig(name, name, true));
319 
320  emit settingsChanged(nullptr);
321 }
322 
324 {
325  addChild(new PlayGroupConfig(tr("Default"), "Default"));
326 
327  QStringList names = PlayGroup::GetNames();
328  while (!names.isEmpty())
329  {
330  addChild(new PlayGroupConfig(names.front(), names.front()));
331  names.pop_front();
332  }
333 
334  //Load all the groups
336 
337  //TODO select the new one or the edited one
338  emit settingsChanged(nullptr);
339 }
PlayGroup::GetSetting
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:246
MSqlBindings
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
PlayGroupConfig::m_skipAhead
MythUISpinBoxSetting * m_skipAhead
Definition: playgroup.h:50
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:783
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
StandardSetting::setName
virtual void setName(const QString &name)
Definition: standardsettings.cpp:247
StandardSetting::setValue
virtual void setValue(const QString &newValue)
Definition: standardsettings.cpp:163
TitleMatch::TitleMatch
TitleMatch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:39
ShowOkPopup
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
Definition: mythdialogbox.cpp:550
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:224
PlayGroupEditor::Load
void Load(void) override
Definition: playgroup.cpp:323
ButtonStandardSetting
Definition: standardsettings.h:447
TimeStretch
Definition: playgroup.cpp:93
PlayGroupConfig::PlayGroupConfig
PlayGroupConfig(const QString &label, const QString &name, bool isNew=false)
Definition: playgroup.cpp:124
SkipAhead::SkipAhead
SkipAhead(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:55
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
MythScreenStack
Definition: mythscreenstack.h:15
arg
arg(title).arg(filename).arg(doDelete))
SkipBack::SkipBack
SkipBack(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:69
ProgramInfo::GetCategory
QString GetCategory(void) const
Definition: programinfo.h:363
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:296
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
JumpMinutes
Definition: playgroup.cpp:79
PlayGroupEditor::CreateNewPlayBackGroup
void CreateNewPlayBackGroup()
Definition: playgroup.cpp:276
playgroup.h
PlayGroupConfig::m_jumpMinutes
MythUISpinBoxSetting * m_jumpMinutes
Definition: playgroup.h:52
SimpleDBStorage
Definition: mythstorage.h:55
PlayGroupEditor::CreateNewPlayBackGroupSlot
void CreateNewPlayBackGroupSlot(const QString &name)
Definition: playgroup.cpp:292
TimeStretch::TimeStretch
TimeStretch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:96
PlayGroupConfig::m_isNew
bool m_isNew
Definition: playgroup.h:54
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
MythUIButtonListItem::SetText
void SetText(const QString &text, const QString &name="", const QString &state="")
Definition: mythuibuttonlist.cpp:3272
PlayGroup::GetNames
static QStringList GetNames(void)
Definition: playgroup.cpp:206
SkipBack
Definition: playgroup.cpp:66
MythUIButtonListItem
Definition: mythuibuttonlist.h:27
PlayGroupConfig
Definition: playgroup.h:37
StandardSetting::setChanged
void setChanged(bool changed)
Definition: standardsettings.cpp:203
StandardSetting::settingsChanged
void settingsChanged(StandardSetting *selectedSetting=nullptr)
StandardSetting::addChild
virtual void addChild(StandardSetting *child)
Definition: standardsettings.cpp:64
programinfo.h
PlayGroup::GetCount
static int GetCount(void)
Definition: playgroup.cpp:191
PlayGroupConfig::m_timeStrech
MythUISpinBoxSetting * m_timeStrech
Definition: playgroup.h:53
StandardSetting::getName
QString getName(void) const
Definition: standardsettings.h:41
ProgramInfo::GetTitle
QString GetTitle(void) const
Definition: programinfo.h:355
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
MythUISpinBoxSetting::intValue
int intValue()
Definition: standardsettings.cpp:652
StandardSetting::Load
virtual void Load(void)
Definition: standardsettings.cpp:208
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:109
StandardSetting::Save
virtual void Save(void)
Definition: standardsettings.cpp:227
PlayGroupConfig::canDelete
bool canDelete(void) override
Definition: playgroup.cpp:175
PlayGroupConfig::m_skipBack
MythUISpinBoxSetting * m_skipBack
Definition: playgroup.h:51
StandardSetting::getValue
virtual QString getValue(void) const
Definition: standardsettings.h:51
StandardSetting::setLabel
virtual void setLabel(QString str)
Definition: standardsettings.h:34
TimeStretch::Save
void Save(void) override
Definition: playgroup.cpp:116
standardsettings.h
PlayGroupConfig::m_titleMatch
StandardSetting * m_titleMatch
Definition: playgroup.h:49
ProgramInfo
Holds information on recordings and videos.
Definition: programinfo.h:67
PlayGroupEditor::PlayGroupEditor
PlayGroupEditor(void)
Definition: playgroup.cpp:267
MythUITextEditSetting
Definition: standardsettings.h:143
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
MythUISpinBoxSetting
Definition: standardsettings.h:325
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
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:150
MythTextInputDialog
Dialog prompting the user to enter a text string.
Definition: mythdialogbox.h:263
PlayGroupDBStorage::GetWhereClause
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: playgroup.cpp:26
PlayGroupConfig::deleteEntry
void deleteEntry(void) override
Definition: playgroup.cpp:180
JumpMinutes::JumpMinutes
JumpMinutes(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:82
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
query
MSqlQuery query(MSqlQuery::InitCon())
PlayGroupEditor::m_addGroupButton
ButtonStandardSetting * m_addGroupButton
Definition: playgroup.h:34
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:144
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:808