MythTV  0.26-pre
playgroup.cpp
Go to the documentation of this file.
00001 #include "mythdb.h"
00002 #include "playgroup.h"
00003 #include "programinfo.h"
00004 #include "mythwidgets.h"
00005 
00006 class PlayGroupConfig: public ConfigurationWizard
00007 {
00008  public:
00009     PlayGroupConfig(QString _name);
00010     QString getName(void) const { return name; }
00011 
00012  private:
00013     QString name;
00014 };
00015 
00016 // A parameter associated with the profile itself
00017 class PlayGroupDBStorage : public SimpleDBStorage
00018 {
00019   protected:
00020     PlayGroupDBStorage(Setting         *_setting,
00021                        const PlayGroupConfig &_parent,
00022                        QString          _name) :
00023         SimpleDBStorage(_setting, "playgroup", _name), parent(_parent)
00024     {
00025         _setting->setName(_name);
00026     }
00027 
00028     virtual QString GetWhereClause(MSqlBindings &bindings) const;
00029 
00030     const PlayGroupConfig &parent;
00031 };
00032 
00033 QString PlayGroupDBStorage::GetWhereClause(MSqlBindings &bindings) const
00034 {
00035     QString nameTag(":WHERENAME");
00036     QString query("name = " + nameTag);
00037 
00038     bindings.insert(nameTag, parent.getName());
00039 
00040     return query;
00041 }
00042 
00043 class TitleMatch : public LineEditSetting, public PlayGroupDBStorage
00044 {
00045   public:
00046     TitleMatch(const PlayGroupConfig& _parent):
00047         LineEditSetting(this), PlayGroupDBStorage(this, _parent, "titlematch")
00048     {
00049         setLabel(QObject::tr("Title match (regex)"));
00050         setHelpText(QObject::tr("Automatically set new recording rules to "
00051                                 "use this group if the title matches this "
00052                                 "regular expression.  For example, "
00053                                 "\"(News|CNN)\" would match any title in "
00054                                 "which \"News\" or \"CNN\" appears."));
00055     };
00056 };
00057 
00058 class SkipAhead : public SpinBoxSetting, public PlayGroupDBStorage
00059 {
00060   public:
00061     SkipAhead(const PlayGroupConfig& _parent):
00062         SpinBoxSetting(this, 0, 600, 5, true,
00063                        "(" + QObject::tr("default") + ")"),
00064         PlayGroupDBStorage(this, _parent, "skipahead") {
00065         setLabel(QObject::tr("Skip ahead (seconds)"));
00066         setHelpText(QObject::tr("How many seconds to skip forward on a fast "
00067                                 "forward."));
00068     };
00069 };
00070 
00071 class SkipBack : public SpinBoxSetting, public PlayGroupDBStorage
00072 {
00073   public:
00074     SkipBack(const PlayGroupConfig& _parent):
00075         SpinBoxSetting(this, 0, 600, 5, true,
00076                        "(" + QObject::tr("default") + ")"),
00077         PlayGroupDBStorage(this, _parent, "skipback")
00078     {
00079         setLabel(QObject::tr("Skip back (seconds)"));
00080         setHelpText(QObject::tr("How many seconds to skip backward on a "
00081                                 "rewind."));
00082     };
00083 };
00084 
00085 class JumpMinutes : public SpinBoxSetting, public PlayGroupDBStorage
00086 {
00087   public:
00088     JumpMinutes(const PlayGroupConfig& _parent):
00089         SpinBoxSetting(this, 0, 30, 10, true,
00090                        "(" + QObject::tr("default") + ")"),
00091         PlayGroupDBStorage(this, _parent, "jump")
00092     {
00093         setLabel(QObject::tr("Jump amount (minutes)"));
00094         setHelpText(QObject::tr("How many minutes to jump forward or backward "
00095                     "when the jump keys are pressed."));
00096     };
00097 };
00098 
00099 class TimeStretch : public SpinBoxSetting, public PlayGroupDBStorage
00100 {
00101   public:
00102     TimeStretch(const PlayGroupConfig& _parent):
00103         SpinBoxSetting(this, 45, 200, 5, false,
00104                        "(" + QObject::tr("default") + ")"),
00105         PlayGroupDBStorage(this, _parent, "timestretch")
00106     {
00107         setValue(45);
00108         setLabel(QObject::tr("Time stretch (speed x 100)"));
00109         setHelpText(QObject::tr("Initial playback speed with adjusted audio.  "
00110                                 "Use 100 for normal speed, 50 for half speed "
00111                                 "and 200 for double speed."));
00112     };
00113 
00114     virtual void Load(void)
00115     {
00116         PlayGroupDBStorage::Load();
00117         if (intValue() < 50 || intValue() > 200)
00118             setValue(45);
00119     }
00120 
00121     virtual void Save(void)
00122     {
00123         if (intValue() < 50 || intValue() > 200)
00124         {
00125             // We need to bypass the bounds checking that would
00126             // normally occur in order to get the special value of 0
00127             // into the database
00128             IntegerSetting::setValue(0);
00129         }
00130         PlayGroupDBStorage::Save();
00131     }
00132 };
00133 
00134 PlayGroupConfig::PlayGroupConfig(QString _name) : name(_name)
00135 {
00136     ConfigurationGroup* cgroup = new VerticalConfigurationGroup(false);
00137     cgroup->setLabel(getName() + " " + QObject::tr("Group", "Play Group"));
00138 
00139     cgroup->addChild(new TitleMatch(*this));
00140     cgroup->addChild(new SkipAhead(*this));
00141     cgroup->addChild(new SkipBack(*this));
00142     cgroup->addChild(new JumpMinutes(*this));
00143     cgroup->addChild(new TimeStretch(*this));
00144 
00145     addChild(cgroup);
00146 };
00147 
00148 int PlayGroup::GetCount(void)
00149 {
00150     int names = 0;
00151 
00152     MSqlQuery query(MSqlQuery::InitCon());
00153     query.prepare("SELECT COUNT(name) FROM playgroup "
00154                   "WHERE name <> 'Default' ORDER BY name;");
00155     if (!query.exec())
00156         MythDB::DBError("PlayGroupConfig::GetCount()", query);
00157     else if (query.next())
00158         names = query.value(0).toInt();
00159 
00160     return names;
00161 }
00162 
00163 QStringList PlayGroup::GetNames(void)
00164 {
00165     QStringList names;
00166 
00167     MSqlQuery query(MSqlQuery::InitCon());
00168     query.prepare("SELECT name FROM playgroup "
00169                   "WHERE name <> 'Default' ORDER BY name;");
00170     if (!query.exec())
00171         MythDB::DBError("PlayGroupConfig::GetNames()", query);
00172     else
00173     {
00174         while (query.next())
00175             names << query.value(0).toString();
00176     }
00177 
00178     return names;
00179 }
00180 
00181 QString PlayGroup::GetInitialName(const ProgramInfo *pi)
00182 {
00183     QString res = "Default";
00184 
00185     MSqlQuery query(MSqlQuery::InitCon());
00186     query.prepare("SELECT name FROM playgroup "
00187                   "WHERE name = :TITLE1 OR "
00188                   "      name = :CATEGORY OR "
00189                   "      (titlematch <> '' AND "
00190                   "       :TITLE2 REGEXP titlematch) ");
00191     query.bindValue(":TITLE1", pi->GetTitle());
00192     query.bindValue(":TITLE2", pi->GetTitle());
00193     query.bindValue(":CATEGORY", pi->GetCategory());
00194 
00195     if (!query.exec())
00196         MythDB::DBError("GetInitialName", query);
00197     else if (query.next())
00198         res = query.value(0).toString();
00199 
00200     return res;
00201 }
00202 
00203 int PlayGroup::GetSetting(const QString &name, const QString &field,
00204                           int defval)
00205 {
00206     int res = defval;
00207 
00208     MSqlQuery query(MSqlQuery::InitCon());
00209     query.prepare(QString("SELECT name, %1 FROM playgroup "
00210                           "WHERE (name = :NAME OR name = 'Default') "
00211                           "      AND %2 <> 0 "
00212                           "ORDER BY name = 'Default';")
00213                   .arg(field).arg(field));
00214     query.bindValue(":NAME", name);
00215     if (!query.exec())
00216         MythDB::DBError("PlayGroupConfig::GetSetting", query);
00217     else if (query.next())
00218         res = query.value(1).toInt();
00219 
00220     return res;
00221 }
00222 
00223 PlayGroupEditor::PlayGroupEditor(void) :
00224     listbox(new ListBoxSetting(this)), lastValue("Default")
00225 {
00226     listbox->setLabel(tr("Playback Groups"));
00227     addChild(listbox);
00228 }
00229 
00230 void PlayGroupEditor::open(QString name)
00231 {
00232     lastValue = name;
00233     bool created = false;
00234 
00235     if (name == "__CREATE_NEW_GROUP__")
00236     {
00237         name = "";
00238         bool ok = MythPopupBox::showGetTextPopup(GetMythMainWindow(),
00239             tr("Create New Playback Group"),
00240             tr("Enter group name or press SELECT to enter text via the "
00241                "On Screen Keyboard"), name);
00242         if (!ok)
00243             return;
00244 
00245         MSqlQuery query(MSqlQuery::InitCon());
00246         query.prepare("INSERT INTO playgroup (name) VALUES (:NAME);");
00247         query.bindValue(":NAME", name);
00248         if (!query.exec())
00249             MythDB::DBError("PlayGroupEditor::open", query);
00250         else
00251             created = true;
00252     }
00253 
00254     PlayGroupConfig group(name);
00255     if (group.exec() == QDialog::Accepted || !created)
00256         lastValue = name;
00257     else
00258     {
00259         MSqlQuery query(MSqlQuery::InitCon());
00260         query.prepare("DELETE FROM playgroup WHERE name = :NAME;");
00261         query.bindValue(":NAME", name);
00262         if (!query.exec())
00263             MythDB::DBError("PlayGroupEditor::open", query);
00264     }
00265 };
00266 
00267 void PlayGroupEditor::doDelete(void)
00268 {
00269     QString name = listbox->getValue();
00270     if (name == "__CREATE_NEW_GROUP__" || name == "Default")
00271         return;
00272 
00273     QString message = tr("Delete playback group:") +
00274         QString("\n'%1'?").arg(name);
00275 
00276     DialogCode value = MythPopupBox::Show2ButtonPopup(
00277         GetMythMainWindow(),
00278         "", message,
00279         tr("Yes, delete group"),
00280         tr("No, Don't delete group"), kDialogCodeButton1);
00281 
00282     if (kDialogCodeButton0 == value)
00283     {
00284         MSqlQuery query(MSqlQuery::InitCon());
00285         query.prepare("DELETE FROM playgroup WHERE name = :NAME;");
00286         query.bindValue(":NAME", name);
00287         if (!query.exec())
00288             MythDB::DBError("PlayGroupEditor::doDelete", query);
00289 
00290         int lastIndex = listbox->getValueIndex(name);
00291         lastValue = "";
00292         Load();
00293         listbox->setValue(lastIndex);
00294     }
00295 
00296     listbox->setFocus();
00297 }
00298 
00299 void PlayGroupEditor::Load(void)
00300 {
00301     listbox->clearSelections();
00302 
00303     listbox->addSelection(tr("Default"), "Default");
00304 
00305     QStringList names = PlayGroup::GetNames();
00306     while (!names.isEmpty())
00307     {
00308         listbox->addSelection(names.front());
00309         names.pop_front();
00310     }
00311 
00312     listbox->addSelection(tr("(Create new group)"), "__CREATE_NEW_GROUP__");
00313 
00314     listbox->setValue(lastValue);
00315 }
00316 
00317 DialogCode PlayGroupEditor::exec(void)
00318 {
00319     while (ConfigurationDialog::exec() == kDialogCodeAccepted)
00320         open(listbox->getValue());
00321 
00322     return kDialogCodeRejected;
00323 }
00324 
00325 MythDialog* PlayGroupEditor::dialogWidget(MythMainWindow* parent,
00326                                           const char* widgetName)
00327 {
00328     dialog = ConfigurationDialog::dialogWidget(parent, widgetName);
00329     connect(dialog, SIGNAL(menuButtonPressed()), this, SLOT(doDelete()));
00330     connect(dialog, SIGNAL(deleteButtonPressed()), this, SLOT(doDelete()));
00331     return dialog;
00332 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends