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