MythTV  master
profilegroup.cpp
Go to the documentation of this file.
1 #include "recordingprofile.h"
2 #include "videosource.h"
3 #include "profilegroup.h"
4 #include "mythdb.h"
5 #include "mythuihelper.h"
6 #include "cardutil.h"
7 
9 {
10  QString idTag(":WHEREID");
11  QString query("id = " + idTag);
12 
13  bindings.insert(idTag, m_parent.getProfileNum());
14 
15  return query;
16 }
17 
19 {
20  QString idTag(":SETID");
21  QString colTag(":SET" + GetColumnName().toUpper());
22 
23  QString query("id = " + idTag + ", " +
24  GetColumnName() + " = " + colTag);
25 
26  bindings.insert(idTag, m_parent.getProfileNum());
27  bindings.insert(colTag, m_user->GetDBValue());
28 
29  return query;
30 }
31 
33 {
34  QStringList hostnames;
35  ProfileGroup::getHostNames(&hostnames);
36  for(QStringList::Iterator it = hostnames.begin();
37  it != hostnames.end(); it++)
38  this->addSelection(*it);
39 }
40 
42 {
43  // This must be first because it is needed to load/save the other settings
44  addChild(m_id = new ID());
45  addChild(m_is_default = new Is_default(*this));
46 
47  setLabel(tr("Profile Group"));
48  addChild(m_name = new Name(*this));
49  CardInfo *cardInfo = new CardInfo(*this);
50  addChild(cardInfo);
51  CardType::fillSelections(cardInfo);
52  m_host = new HostName(*this);
55 };
56 
57 void ProfileGroup::loadByID(int profileId) {
58  m_id->setValue(profileId);
59  Load();
60 }
61 
63 {
64  // We need separate profiles for different V4L2 card types
65  QStringList existing;
67  query.prepare("SELECT DISTINCT cardtype FROM profilegroups");
68 
69  if (!query.exec())
70  {
71  MythDB::DBError("ProfileGroup::createMissingDynamicProfiles", query);
72  return false;
73  }
74 
75  while (query.next())
76  existing.push_back(query.value(0).toString());
77 
78 
79  const uint num_profiles = 4;
80  const QString profile_names[num_profiles] = { "Default", "Live TV",
81  "High Quality",
82  "Low Quality" };
83 
85 
86  CardUtil::InputTypes::iterator Itype = cardtypes.begin();
87  for ( ; Itype != cardtypes.end(); ++Itype)
88  {
89  if (Itype.key().startsWith("V4L2:") && existing.indexOf(Itype.key()) == -1)
90  {
91  // Add dynamic profile group
92  query.prepare("INSERT INTO profilegroups SET name = "
93  ":CARDNAME, cardtype = :CARDTYPE, is_default = 1;");
94  query.bindValue(":CARDTYPE", Itype.key());
95  query.bindValue(":CARDNAME", Itype.value());
96  if (!query.exec())
97  {
98  MythDB::DBError("Unable to insert V4L2 profilegroup.", query);
99  return false;
100  }
101 
102  // get the id of the new profile group
103  int groupid = query.lastInsertId().toInt();
104 
105  for (uint idx = 0 ; idx < num_profiles; ++idx)
106  {
107  // insert the recording profiles
108  query.prepare("INSERT INTO recordingprofiles SET name = "
109  ":NAME, profilegroup = :GROUPID;");
110  query.bindValue(":NAME", profile_names[idx]);
111  query.bindValue(":GROUPID", groupid);
112  if (!query.exec())
113  {
114  MythDB::DBError("Unable to insert 'Default' "
115  "recordingprofile.", query);
116  return false;
117  }
118  }
119  }
120  }
121 
122  return true;
123 }
124 
126 {
128  QString tid;
129 
130  MSqlQuery result(MSqlQuery::InitCon());
131  result.prepare(
132  "SELECT name, id, hostname, is_default, cardtype "
133  "FROM profilegroups");
134 
135  if (!result.exec())
136  {
137  MythDB::DBError("ProfileGroup::fillSelections", result);
138  return;
139  }
140 
141  while (result.next())
142  {
143  QString name = result.value(0).toString();
144  QString id = result.value(1).toString();
145  QString hostname = result.value(2).toString();
146  bool is_default = (bool) result.value(3).toInt();
147  QString cardtype = result.value(4).toString();
148 
149  // Only show default profiles that match installed cards
150  // Workaround for #12481 in fixes/0.27
151  bool have_cardtype = cardtypes.contains(cardtype);
152  if (is_default && (cardtype == "TRANSCODE") && !have_cardtype)
153  {
154  tid = id;
155  }
156  else if (have_cardtype)
157  {
158  if (!hostname.isEmpty())
159  name += QString(" (%1)").arg(result.value(2).toString());
160 
161  if (is_default)
162  {
163  setting->addChild(new RecordingProfileEditor(id.toInt(), name));
164  }
165  else
166  {
167  ProfileGroup *profileGroup = new ProfileGroup();
168  profileGroup->loadByID(id.toInt());
169  profileGroup->setLabel(name);
170  profileGroup->addChild(
171  new RecordingProfileEditor(id.toInt(), tr("Profiles")));
172  setting->addChild(profileGroup);
173  }
174  }
175  }
176 
177  if (!tid.isEmpty())
178  {
179  setting->addChild(new RecordingProfileEditor(tid.toInt(),
180  tr("Transcoders")));
181  }
182 }
183 
184 QString ProfileGroup::getName(int group)
185 {
186  MSqlQuery result(MSqlQuery::InitCon());
187  result.prepare("SELECT name from profilegroups WHERE id = :PROFILE_ID;");
188  result.bindValue(":PROFILE_ID", group);
189  if (result.exec() && result.next())
190  {
191  return result.value(0).toString();
192  }
193 
194  return nullptr;
195 }
196 
198 {
199  MSqlQuery result(MSqlQuery::InitCon());
200  QString querystr = QString("SELECT DISTINCT id FROM profilegroups WHERE "
201  "name = '%1' AND hostname = '%2';")
202  .arg(getName()).arg(m_host->getValue());
203  result.prepare(querystr);
204 
205  return !(result.exec() && result.next());
206 }
207 
208 void ProfileGroup::getHostNames(QStringList *hostnames)
209 {
210  hostnames->clear();
211 
212  MSqlQuery result(MSqlQuery::InitCon());
213 
214  result.prepare("SELECT DISTINCT hostname from capturecard");
215 
216  if (result.exec())
217  {
218  while (result.next())
219  hostnames->append(result.value(0).toString());
220  }
221 }
222 
224 {
225  clearSettings();
229 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
static void getHostNames(QStringList *hostnames)
HostName * m_host
Definition: profilegroup.h:116
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
QString GetColumnName(void) const
Definition: mythstorage.h:43
virtual void clearSettings()
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
virtual void Load(void)
void addSelection(const QString &label, QString value=QString(), bool select=false)
bool
Definition: pxsup2dast.c:30
QMap< QString, QString > InputTypes
Definition: cardutil.h:43
QString getName(void) const
Definition: profilegroup.h:106
unsigned int uint
Definition: compat.h:140
virtual void loadByID(int id)
bool allowedGroupName(void)
virtual QString GetDBValue(void) const =0
QString GetSetClause(MSqlBindings &bindings) const override
QString GetWhereClause(MSqlBindings &bindings) const override
Definition: profilegroup.cpp:8
virtual QString getValue(void) const
QVariant value(int i) const
Definition: mythdbcon.h:198
const ProfileGroup & m_parent
Definition: profilegroup.h:26
static bool addMissingDynamicProfiles(void)
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:887
static void fillSelections(GroupSetting *setting)
virtual void setLabel(QString str)
StorageUser * m_user
Definition: mythstorage.h:46
string hostname
Definition: caa.py:17
int getProfileNum(void) const
Definition: profilegroup.h:98
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
const char * name
Definition: ParseText.cpp:328
virtual void addChild(StandardSetting *child)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
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:603
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
Is_default * m_is_default
Definition: profilegroup.h:117
void Load(void) override
static InputTypes GetInputTypes(void)
Definition: cardutil.cpp:334
static void fillSelections(MythUIComboBoxSetting *setting)
virtual void setValue(const QString &newValue)