MythTV  master
inputselectorsetting.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  * vim: set expandtab tabstop=4 shiftwidth=4:
3  *
4  * Original Project
5  * MythTV http://www.mythtv.org
6  *
7  * Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
8  * Copyright (c) 2005 - 2007 Daniel Kristjansson
9  *
10  * Description:
11  * Collection of classes to provide channel scanning functionallity
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
27  *
28  */
29 
30 #include "inputselectorsetting.h"
31 
32 #include <utility>
33 
35 #include "libmythbase/mythdb.h"
36 
37 #include "cardutil.h"
38 
40  QString default_inputname) :
41  m_defaultCardId(default_cardid),
42  m_defaultInputName(std::move(default_inputname))
43 {
44  setLabel(tr("Input"));
46  QObject::tr(
47  "Select a capture card from the capture cards that are "
48  "connected to the currently selected video source."
49  ));
50 }
51 
53 {
55 
56  if (!m_sourceId)
57  return;
58 
60  query.prepare(
61  "SELECT capturecard.cardid, cardtype, videodevice, inputname "
62  "FROM capturecard, videosource "
63  "WHERE capturecard.sourceid = videosource.sourceid AND "
64  " hostname = :HOSTNAME AND "
65  " capturecard.sourceid = :SOURCEID AND "
66  " capturecard.parentid = 0");
67 
68  query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
69  query.bindValue(":SOURCEID", m_sourceId);
70 
71  if (!query.exec() || !query.isActive())
72  {
73  MythDB::DBError("InputSelector::load()", query);
74  return;
75  }
76 
77  uint which = 0;
78  uint cnt = 0;
79  for (; query.next(); ++cnt)
80  {
81  uint cardid = query.value(0).toUInt();
82  QString inputname = query.value(3).toString();
83 
84  QString desc = CardUtil::GetDeviceLabel(
85  query.value(1).toString(), query.value(2).toString());
86 
87  desc += QString(" (%1)").arg(inputname);
88 
89  QString key = QString("%1:%2").arg(cardid).arg(inputname);
90 
91  addSelection(desc, key);
92 
93  which = (m_defaultCardId == cardid) ? cnt : which;
94  }
95 
96  if (cnt)
97  setValue(which);
98 }
99 
100 void InputSelector::SetSourceID(const QString &sourceid)
101 {
102  if (m_sourceId != sourceid.toUInt())
103  {
104  m_sourceId = sourceid.toUInt();
105  Load();
106  }
107 }
108 
110 {
111  uint cardid = 0;
112  QString inputname;
113 
114  Parse(getValue(), cardid, inputname);
115 
116  return cardid;
117 }
118 
119 QString InputSelector::GetInputName(void) const
120 {
121  uint cardid = 0;
122  QString inputname;
123 
124  Parse(getValue(), cardid, inputname);
125 
126  return inputname;
127 }
128 
129 bool InputSelector::Parse(const QString &cardid_inputname,
130  uint &cardid,
131  QString &inputname)
132 {
133  cardid = 0;
134  inputname.clear();
135 
136  int sep0 = cardid_inputname.indexOf(':');
137  if (sep0 < 1)
138  return false;
139 
140  cardid = cardid_inputname.left(sep0).toUInt();
141  inputname = cardid_inputname.mid(sep0 + 1);
142 
143  return true;
144 }
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:215
MSqlQuery::next
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:813
MSqlQuery
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:127
MythUIComboBoxSetting::clearSelections
void clearSelections()
Definition: standardsettings.cpp:514
CardUtil::GetDeviceLabel
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
Definition: cardutil.cpp:2634
InputSelector::m_sourceId
uint m_sourceId
Definition: inputselectorsetting.h:56
InputSelector::SetSourceID
void SetSourceID(const QString &sourceid)
Definition: inputselectorsetting.cpp:100
mythdb.h
InputSelector::InputSelector
InputSelector(uint default_cardid, QString default_inputname)
Definition: inputselectorsetting.cpp:39
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:204
InputSelector::Load
void Load(void) override
Definition: inputselectorsetting.cpp:52
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:619
InputSelector::m_defaultCardId
uint m_defaultCardId
Definition: inputselectorsetting.h:57
MSqlQuery::InitCon
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:551
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
StandardSetting::setHelpText
virtual void setHelpText(const QString &str)
Definition: standardsettings.h:37
StandardSetting::getValue
virtual QString getValue(void) const
Definition: standardsettings.h:52
InputSelector::Parse
static bool Parse(const QString &cardid_inputname, uint &cardid, QString &inputname)
Definition: inputselectorsetting.cpp:129
uint
unsigned int uint
Definition: compat.h:81
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
StandardSetting::setLabel
virtual void setLabel(QString str)
Definition: standardsettings.h:34
MythUIComboBoxSetting::addSelection
void addSelection(const QString &label, QString value=QString(), bool select=false)
Definition: standardsettings.cpp:499
mythcorecontext.h
cardutil.h
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:889
std
Definition: mythchrono.h:23
inputselectorsetting.h
InputSelector::GetInputName
QString GetInputName(void) const
Definition: inputselectorsetting.cpp:119
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:838
MythUIComboBoxSetting::setValue
void setValue(int value) override
Definition: standardsettings.cpp:479
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:838
InputSelector::GetCardID
uint GetCardID(void) const
Definition: inputselectorsetting.cpp:109