MythTV  0.28pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
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 "mythwidgets.h"
9 
11 {
12  Q_DECLARE_TR_FUNCTIONS(PlayGroupConfig)
13 
14  public:
15  PlayGroupConfig(QString _name);
16  QString getName(void) const { return name; }
17 
18  private:
19  QString name;
20 };
21 
22 // A parameter associated with the profile itself
24 {
25  protected:
27  const PlayGroupConfig &_parent,
28  QString _name) :
29  SimpleDBStorage(_setting, "playgroup", _name), parent(_parent)
30  {
31  _setting->setName(_name);
32  }
33 
34  virtual QString GetWhereClause(MSqlBindings &bindings) const;
35 
37 };
38 
40 {
41  QString nameTag(":WHERENAME");
42  QString query("name = " + nameTag);
43 
44  bindings.insert(nameTag, parent.getName());
45 
46  return query;
47 }
48 
50 {
51  public:
52  TitleMatch(const PlayGroupConfig& _parent):
53  LineEditSetting(this), PlayGroupDBStorage(this, _parent, "titlematch")
54  {
55  setLabel(PlayGroupConfig::tr("Title match (regex)"));
56  setHelpText(PlayGroupConfig::tr("Automatically set new recording rules "
57  "to use this group if the title "
58  "matches this regular expression. "
59  "For example, \"(News|CNN)\" would "
60  "match any title in which \"News\" or "
61  "\"CNN\" appears."));
62  };
63 };
64 
66 {
67  public:
68  SkipAhead(const PlayGroupConfig& _parent):
69  SpinBoxSetting(this, 0, 600, 5, true, PlayGroupConfig::tr("(default)")),
70  PlayGroupDBStorage(this, _parent, "skipahead")
71  {
72  setLabel(PlayGroupConfig::tr("Skip ahead (seconds)"));
73  setHelpText(PlayGroupConfig::tr("How many seconds to skip forward on "
74  "a fast forward."));
75  };
76 };
77 
79 {
80  public:
81  SkipBack(const PlayGroupConfig& _parent):
82  SpinBoxSetting(this, 0, 600, 5, true, PlayGroupConfig::tr("(default)")),
83  PlayGroupDBStorage(this, _parent, "skipback")
84  {
85  setLabel(PlayGroupConfig::tr("Skip back (seconds)"));
86  setHelpText(PlayGroupConfig::tr("How many seconds to skip backward on "
87  "a rewind."));
88  };
89 };
90 
92 {
93  public:
94  JumpMinutes(const PlayGroupConfig& _parent):
95  SpinBoxSetting(this, 0, 30, 10, true, PlayGroupConfig::tr("(default)")),
96  PlayGroupDBStorage(this, _parent, "jump")
97  {
98  setLabel(PlayGroupConfig::tr("Jump amount (minutes)"));
99  setHelpText(PlayGroupConfig::tr("How many minutes to jump forward or "
100  "backward when the jump keys are "
101  "pressed."));
102  };
103 };
104 
106 {
107  public:
108  TimeStretch(const PlayGroupConfig& _parent):
109  SpinBoxSetting(this, 45, 200, 5, false,
110  PlayGroupConfig::tr("(default)")),
111  PlayGroupDBStorage(this, _parent, "timestretch")
112  {
113  setValue(45);
114  setLabel(PlayGroupConfig::tr("Time stretch (speed x 100)"));
115  setHelpText(PlayGroupConfig::tr("Initial playback speed with adjusted "
116  "audio. Use 100 for normal speed, 50 "
117  "for half speed and 200 for double "
118  "speed."));
119  };
120 
121  virtual void Load(void)
122  {
124  if (intValue() < 50 || intValue() > 200)
125  setValue(45);
126  }
127 
128  virtual void Save(void)
129  {
130  if (intValue() < 50 || intValue() > 200)
131  {
132  // We need to bypass the bounds checking that would
133  // normally occur in order to get the special value of 0
134  // into the database
136  }
138  }
139 
140  virtual void Save(QString destination) { PlayGroupDBStorage::Save(destination); }
141 };
142 
143 PlayGroupConfig::PlayGroupConfig(QString _name) : name(_name)
144 {
145  ConfigurationGroup* cgroup = new VerticalConfigurationGroup(false);
146  //: %1 is the name of the playgroup
147  cgroup->setLabel(tr("%1 Group", "Play Group").arg(getName()));
148 
149  cgroup->addChild(new TitleMatch(*this));
150  cgroup->addChild(new SkipAhead(*this));
151  cgroup->addChild(new SkipBack(*this));
152  cgroup->addChild(new JumpMinutes(*this));
153  cgroup->addChild(new TimeStretch(*this));
154 
155  addChild(cgroup);
156 };
157 
159 {
160  int names = 0;
161 
162  MSqlQuery query(MSqlQuery::InitCon());
163  query.prepare("SELECT COUNT(name) FROM playgroup "
164  "WHERE name <> 'Default' ORDER BY name;");
165  if (!query.exec())
166  MythDB::DBError("PlayGroupConfig::GetCount()", query);
167  else if (query.next())
168  names = query.value(0).toInt();
169 
170  return names;
171 }
172 
173 QStringList PlayGroup::GetNames(void)
174 {
175  QStringList names;
176 
177  MSqlQuery query(MSqlQuery::InitCon());
178  query.prepare("SELECT name FROM playgroup "
179  "WHERE name <> 'Default' ORDER BY name;");
180  if (!query.exec())
181  MythDB::DBError("PlayGroupConfig::GetNames()", query);
182  else
183  {
184  while (query.next())
185  names << query.value(0).toString();
186  }
187 
188  return names;
189 }
190 
192 {
193  QString res = "Default";
194 
195  MSqlQuery query(MSqlQuery::InitCon());
196  query.prepare("SELECT name FROM playgroup "
197  "WHERE name = :TITLE1 OR "
198  " name = :CATEGORY OR "
199  " (titlematch <> '' AND "
200  " :TITLE2 REGEXP titlematch) ");
201  query.bindValue(":TITLE1", pi->GetTitle());
202  query.bindValue(":TITLE2", pi->GetTitle());
203  query.bindValue(":CATEGORY", pi->GetCategory());
204 
205  if (!query.exec())
206  MythDB::DBError("GetInitialName", query);
207  else if (query.next())
208  res = query.value(0).toString();
209 
210  return res;
211 }
212 
213 int PlayGroup::GetSetting(const QString &name, const QString &field,
214  int defval)
215 {
216  int res = defval;
217 
218  MSqlQuery query(MSqlQuery::InitCon());
219  query.prepare(QString("SELECT name, %1 FROM playgroup "
220  "WHERE (name = :NAME OR name = 'Default') "
221  " AND %2 <> 0 "
222  "ORDER BY name = 'Default';")
223  .arg(field).arg(field));
224  query.bindValue(":NAME", name);
225  if (!query.exec())
226  MythDB::DBError("PlayGroupConfig::GetSetting", query);
227  else if (query.next())
228  res = query.value(1).toInt();
229 
230  return res;
231 }
232 
234  listbox(new ListBoxSetting(this)), lastValue("Default")
235 {
236  listbox->setLabel(tr("Playback Groups"));
237  addChild(listbox);
238 }
239 
241 {
242  lastValue = name;
243  bool created = false;
244 
245  if (name == "__CREATE_NEW_GROUP__")
246  {
247  name = "";
249  tr("Create New Playback Group"),
250  tr("Enter group name or press SELECT to enter text via the "
251  "On Screen Keyboard"), name);
252  if (!ok)
253  return;
254 
255  MSqlQuery query(MSqlQuery::InitCon());
256  query.prepare("INSERT INTO playgroup (name) VALUES (:NAME);");
257  query.bindValue(":NAME", name);
258  if (!query.exec())
259  MythDB::DBError("PlayGroupEditor::open", query);
260  else
261  created = true;
262  }
263 
264  PlayGroupConfig group(name);
265  if (group.exec() == QDialog::Accepted || !created)
266  lastValue = name;
267  else
268  {
269  MSqlQuery query(MSqlQuery::InitCon());
270  query.prepare("DELETE FROM playgroup WHERE name = :NAME;");
271  query.bindValue(":NAME", name);
272  if (!query.exec())
273  MythDB::DBError("PlayGroupEditor::open", query);
274  }
275 };
276 
278 {
279  QString name = listbox->getValue();
280  if (name == "__CREATE_NEW_GROUP__" || name == "Default")
281  return;
282 
283  QString message = tr("Delete playback group:\n'%1'?").arg(name);
284 
287  "", message,
288  tr("Yes, delete group"),
289  tr("No, Don't delete group"), kDialogCodeButton1);
290 
291  if (kDialogCodeButton0 == value)
292  {
293  MSqlQuery query(MSqlQuery::InitCon());
294  query.prepare("DELETE FROM playgroup WHERE name = :NAME;");
295  query.bindValue(":NAME", name);
296  if (!query.exec())
297  MythDB::DBError("PlayGroupEditor::doDelete", query);
298 
299  int lastIndex = listbox->getValueIndex(name);
300  lastValue = "";
301  Load();
302  listbox->setValue(lastIndex);
303  }
304 
305  listbox->setFocus();
306 }
307 
309 {
311 
312  listbox->addSelection(tr("Default"), "Default");
313 
314  QStringList names = PlayGroup::GetNames();
315  while (!names.isEmpty())
316  {
317  listbox->addSelection(names.front());
318  names.pop_front();
319  }
320 
321  listbox->addSelection(tr("(Create new group)"), "__CREATE_NEW_GROUP__");
322 
324 }
325 
327 {
329  open(listbox->getValue());
330 
331  return kDialogCodeRejected;
332 }
333 
335  const char* widgetName)
336 {
337  dialog = ConfigurationDialog::dialogWidget(parent, widgetName);
338  connect(dialog, SIGNAL(menuButtonPressed()), this, SLOT(doDelete()));
339  connect(dialog, SIGNAL(deleteButtonPressed()), this, SLOT(doDelete()));
340  return dialog;
341 }