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
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
100void 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
120{
121 uint cardid = 0;
122 QString inputname;
123
124 Parse(getValue(), cardid, inputname);
125
126 return inputname;
127}
128
129bool 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}
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
Definition: cardutil.cpp:2638
static bool Parse(const QString &cardid_inputname, uint &cardid, QString &inputname)
void Load(void) override
QString GetInputName(void) const
void SetSourceID(const QString &sourceid)
uint GetCardID(void) const
InputSelector(uint default_cardid, QString default_inputname)
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:128
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:837
QVariant value(int i) const
Definition: mythdbcon.h:204
bool isActive(void) const
Definition: mythdbcon.h:215
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:618
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:888
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:812
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:550
QString GetHostName(void)
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:226
void addSelection(const QString &label, QString value=QString(), bool select=false)
void setValue(int value) override
virtual void setHelpText(const QString &str)
virtual QString getValue(void) const
virtual void setLabel(QString str)
unsigned int uint
Definition: freesurround.h:24
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
STL namespace.