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 
34 #include "cardutil.h"
35 #include "mythcorecontext.h"
36 #include "mythdb.h"
37 
39  QString default_inputname) :
40  m_defaultCardId(default_cardid),
41  m_defaultInputName(std::move(default_inputname))
42 {
43  setLabel(tr("Input"));
45  QObject::tr(
46  "Select a capture card from the capture cards that are "
47  "connected to the currently selected video source."
48  ));
49 }
50 
52 {
54 
55  if (!m_sourceId)
56  return;
57 
59  query.prepare(
60  "SELECT capturecard.cardid, cardtype, videodevice, inputname "
61  "FROM capturecard, videosource "
62  "WHERE capturecard.sourceid = videosource.sourceid AND "
63  " hostname = :HOSTNAME AND "
64  " capturecard.sourceid = :SOURCEID AND "
65  " capturecard.parentid = 0");
66 
67  query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
68  query.bindValue(":SOURCEID", m_sourceId);
69 
70  if (!query.exec() || !query.isActive())
71  {
72  MythDB::DBError("InputSelector::load()", query);
73  return;
74  }
75 
76  uint which = 0;
77  uint cnt = 0;
78  for (; query.next(); ++cnt)
79  {
80  uint cardid = query.value(0).toUInt();
81  QString inputname = query.value(3).toString();
82 
83  QString desc = CardUtil::GetDeviceLabel(
84  query.value(1).toString(), query.value(2).toString());
85 
86  desc += QString(" (%1)").arg(inputname);
87 
88  QString key = QString("%1:%2").arg(cardid).arg(inputname);
89 
90  addSelection(desc, key);
91 
92  which = (m_defaultCardId == cardid) ? cnt : which;
93  }
94 
95  if (cnt)
96  setValue(which);
97 }
98 
99 void InputSelector::SetSourceID(const QString &sourceid)
100 {
101  if (m_sourceId != sourceid.toUInt())
102  {
103  m_sourceId = sourceid.toUInt();
104  Load();
105  }
106 }
107 
109 {
110  uint cardid = 0;
111  QString inputname;
112 
113  Parse(getValue(), cardid, inputname);
114 
115  return cardid;
116 }
117 
118 QString InputSelector::GetInputName(void) const
119 {
120  uint cardid = 0;
121  QString inputname;
122 
123  Parse(getValue(), cardid, inputname);
124 
125  return inputname;
126 }
127 
128 bool InputSelector::Parse(const QString &cardid_inputname,
129  uint &cardid,
130  QString &inputname)
131 {
132  cardid = 0;
133  inputname.clear();
134 
135  int sep0 = cardid_inputname.indexOf(':');
136  if (sep0 < 1)
137  return false;
138 
139  cardid = cardid_inputname.leftRef(sep0).toUInt();
140  inputname = cardid_inputname.mid(sep0 + 1);
141 
142  return true;
143 }
MSqlQuery::isActive
bool isActive(void) const
Definition: mythdbcon.h:204
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:126
MythUIComboBoxSetting::clearSelections
void clearSelections()
Definition: standardsettings.cpp:509
CardUtil::GetDeviceLabel
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
Definition: cardutil.cpp:2487
InputSelector::m_sourceId
uint m_sourceId
Definition: inputselectorsetting.h:56
InputSelector::SetSourceID
void SetSourceID(const QString &sourceid)
Definition: inputselectorsetting.cpp:99
mythdb.h
InputSelector::InputSelector
InputSelector(uint default_cardid, QString default_inputname)
Definition: inputselectorsetting.cpp:38
MSqlQuery::value
QVariant value(int i) const
Definition: mythdbcon.h:198
InputSelector::Load
void Load(void) override
Definition: inputselectorsetting.cpp:51
MSqlQuery::exec
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
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:535
MythDB::DBError
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:178
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:128
uint
unsigned int uint
Definition: compat.h:141
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
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:494
mythcorecontext.h
cardutil.h
MSqlQuery::bindValue
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:864
inputselectorsetting.h
InputSelector::GetInputName
QString GetInputName(void) const
Definition: inputselectorsetting.cpp:118
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:859
query
MSqlQuery query(MSqlQuery::InitCon())
MythUIComboBoxSetting::setValue
void setValue(int value) override
Definition: standardsettings.cpp:474
MSqlQuery::prepare
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:808
InputSelector::GetCardID
uint GetCardID(void) const
Definition: inputselectorsetting.cpp:108