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  QString _name) :
17  SimpleDBStorage(_setting, "playgroup", _name), parent(_parent)
18  {
19  }
20 
21  virtual QString GetWhereClause(MSqlBindings &bindings) const;
22 
24 };
25 
27 {
28  QString nameTag(":WHERENAME");
29  QString query("name = " + nameTag);
30 
31  bindings.insert(nameTag, parent.getName());
32 
33  return query;
34 }
35 
37 {
38  public:
39  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  SkipAhead(const PlayGroupConfig& _parent):
56  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipahead"),
57  0, 600, 5, true, 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  SkipBack(const PlayGroupConfig& _parent):
70  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "skipback"),
71  0, 600, 5, true, 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  JumpMinutes(const PlayGroupConfig& _parent):
83  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "jump"),
84  0, 30, 10, true, 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  TimeStretch(const PlayGroupConfig& _parent):
97  MythUISpinBoxSetting(new PlayGroupDBStorage(this, _parent, "timestretch"),
98  45, 200, 5, false,
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  virtual void Load(void)
110  {
112  if (intValue() < 50 || intValue() > 200)
113  setValue(45);
114  }
115 
116  virtual void Save(void)
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  {
154  MSqlQuery query(MSqlQuery::InitCon());
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 {
182  MSqlQuery query(MSqlQuery::InitCon());
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 
195  MSqlQuery query(MSqlQuery::InitCon());
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 
210  MSqlQuery query(MSqlQuery::InitCon());
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 
228  MSqlQuery query(MSqlQuery::InitCon());
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 
251  MSqlQuery query(MSqlQuery::InitCon());
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  : m_addGroupButton(NULL)
269 {
270  setLabel(tr("Playback Groups"));
271  m_addGroupButton = new ButtonStandardSetting(tr("Create New Playback Group"));
273  connect(m_addGroupButton, SIGNAL(clicked()),
274  this, SLOT(CreateNewPlayBackGroup()));
275 }
276 
278 {
279  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
280  MythTextInputDialog *settingdialog =
281  new MythTextInputDialog(popupStack, tr("Enter new group name"));
282 
283  if (settingdialog->Create())
284  {
285  connect(settingdialog, SIGNAL(haveResult(QString)),
286  SLOT(CreateNewPlayBackGroupSlot(const QString&)));
287  popupStack->AddScreen(settingdialog);
288  }
289  else
290  delete settingdialog;
291 }
292 
294 {
295  if (name.isEmpty())
296  {
297  ShowOkPopup(tr("Sorry, this Playback Group name cannot be blank."));
298  return;
299  }
300 
301  MSqlQuery query(MSqlQuery::InitCon());
302  query.prepare("SELECT name "
303  "FROM playgroup "
304  "WHERE name = :NAME");
305  query.bindValue(":NAME", name);
306 
307  if (!query.exec())
308  {
309  MythDB::DBError("CreateNewPlayBackGroup", query);
310  return;
311  }
312 
313  if (query.next())
314  {
315  ShowOkPopup(tr("Sorry, this Playback Group name is already in use."));
316  return;
317  }
318 
319  addChild(new PlayGroupConfig(name, name, true));
320 
321  emit settingsChanged(NULL);
322 }
323 
325 {
326  addChild(new PlayGroupConfig(tr("Default"), "Default"));
327 
328  QStringList names = PlayGroup::GetNames();
329  while (!names.isEmpty())
330  {
331  addChild(new PlayGroupConfig(names.front(), names.front()));
332  names.pop_front();
333  }
334 
335  //Load all the groups
337 
338  //TODO select the new one or the edited one
339  emit settingsChanged(NULL);
340 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:798
void bindValue(const QString &placeholder, const QVariant &val)
Definition: mythdbcon.cpp:897
VERBOSE_PREAMBLE false
Definition: verbosedefs.h:83
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
MythUISpinBoxSetting * m_jumpMinutes
Definition: playgroup.h:52
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
virtual void setName(const QString &str)
virtual void Load(void)
QString GetTitle(void) const
Definition: programinfo.h:343
static int GetCount(void)
Definition: playgroup.cpp:191
void setChanged(bool changed)
MythScreenStack * GetStack(const QString &stackname)
MythUISpinBoxSetting * m_timeStrech
Definition: playgroup.h:53
ButtonStandardSetting * m_addGroupButton
Definition: playgroup.h:34
virtual void deleteEntry(void)
Definition: playgroup.cpp:180
void CreateNewPlayBackGroupSlot(const QString &)
Definition: playgroup.cpp:293
QString getName(void) const
virtual void Load(void)
Definition: playgroup.cpp:109
virtual QString getValue(void) const
static QString GetInitialName(const ProgramInfo *pi)
Definition: playgroup.cpp:224
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
QVariant value(int i) const
Definition: mythdbcon.h:182
Holds information on recordings and videos.
Definition: programinfo.h:66
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
const char * name
Definition: ParseText.cpp:338
virtual void updateButton(MythUIButtonListItem *item)
This method is called whenever the UI need to reflect a change Reimplement this If you widget need a ...
Definition: playgroup.cpp:144
TimeStretch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:96
virtual void setLabel(QString str)
virtual void Save(void)
Definition: playgroup.cpp:116
SkipBack(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:69
__u32 field
Definition: videodev2.h:1041
void SetText(const QString &text, const QString &name="", const QString &state="")
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:555
PlayGroupEditor(void)
Definition: playgroup.cpp:267
PlayGroupDBStorage(StandardSetting *_setting, const PlayGroupConfig &_parent, QString _name)
Definition: playgroup.cpp:14
virtual void addChild(StandardSetting *child)
MythMainWindow * GetMythMainWindow(void)
virtual void Save(void)
VERBOSE_PREAMBLE Most Errors or other very important messages true
Definition: verbosedefs.h:91
Dialog prompting the user to enter a text string.
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:823
TitleMatch(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:39
SkipAhead(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:55
static int GetSetting(const QString &name, const QString &field, int defval)
Definition: playgroup.cpp:246
virtual QString GetWhereClause(MSqlBindings &bindings) const
Definition: playgroup.cpp:26
const PlayGroupConfig & parent
Definition: playgroup.cpp:23
void settingsChanged(StandardSetting *selectedSetting=NULL)
static QStringList GetNames(void)
Definition: playgroup.cpp:206
virtual void Load(void)
Definition: playgroup.cpp:324
StandardSetting * m_titleMatch
Definition: playgroup.h:49
QMap< QString, QVariant > MSqlBindings
typedef for a map of string -> string bindings for generic queries.
Definition: mythdbcon.h:98
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:623
JumpMinutes(const PlayGroupConfig &_parent)
Definition: playgroup.cpp:82
QString GetCategory(void) const
Definition: programinfo.h:349
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:181
virtual void Save()
Definition: playgroup.cpp:150
MythUISpinBoxSetting * m_skipBack
Definition: playgroup.h:51
void CreateNewPlayBackGroup()
Definition: playgroup.cpp:277
virtual bool canDelete(void)
Definition: playgroup.cpp:175
MythUISpinBoxSetting * m_skipAhead
Definition: playgroup.h:50
PlayGroupConfig(const QString &label, const QString &name, bool isNew=false)
Definition: playgroup.cpp:124