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 #include "cardutil.h"
32 #include "mythcorecontext.h"
33 #include "mythdb.h"
34 
36  const QString &default_inputname) :
37  m_default_cardid(default_cardid),
38  m_default_inputname(default_inputname)
39 {
40  setLabel(tr("Input"));
41 }
42 
44 {
46 
47  if (!m_sourceid)
48  return;
49 
51  query.prepare(
52  "SELECT capturecard.cardid, cardtype, videodevice, inputname "
53  "FROM capturecard, videosource "
54  "WHERE capturecard.sourceid = videosource.sourceid AND "
55  " hostname = :HOSTNAME AND "
56  " capturecard.sourceid = :SOURCEID AND "
57  " capturecard.parentid = 0");
58 
59  query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
60  query.bindValue(":SOURCEID", m_sourceid);
61 
62  if (!query.exec() || !query.isActive())
63  {
64  MythDB::DBError("InputSelector::load()", query);
65  return;
66  }
67 
68  uint which = 0, cnt = 0;
69  for (; query.next(); ++cnt)
70  {
71  uint cardid = query.value(0).toUInt();
72  QString inputname = query.value(3).toString();
73 
74  QString desc = CardUtil::GetDeviceLabel(
75  query.value(1).toString(), query.value(2).toString());
76 
77  desc += QString(" (%1)").arg(inputname);
78 
79  QString key = QString("%1:%2").arg(cardid).arg(inputname);
80 
81  addSelection(desc, key);
82 
83  which = (m_default_cardid == cardid) ? cnt : which;
84  }
85 
86  if (cnt)
87  setValue(which);
88 }
89 
90 void InputSelector::SetSourceID(const QString &sourceid)
91 {
92  if (m_sourceid != sourceid.toUInt())
93  {
94  m_sourceid = sourceid.toUInt();
95  Load();
96  }
97 }
98 
100 {
101  uint cardid = 0;
102  QString inputname;
103 
104  Parse(getValue(), cardid, inputname);
105 
106  return cardid;
107 }
108 
109 QString InputSelector::GetInputName(void) const
110 {
111  uint cardid = 0;
112  QString inputname;
113 
114  Parse(getValue(), cardid, inputname);
115 
116  return inputname;
117 }
118 
119 bool InputSelector::Parse(const QString &cardid_inputname,
120  uint &cardid,
121  QString &inputname)
122 {
123  cardid = 0;
124  inputname.clear();
125 
126  int sep0 = cardid_inputname.indexOf(':');
127  if (sep0 < 1)
128  return false;
129 
130  cardid = cardid_inputname.left(sep0).toUInt();
131  inputname = cardid_inputname.mid(sep0 + 1);
132 
133  return true;
134 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
void addSelection(const QString &label, QString value=QString(), bool select=false)
void SetSourceID(const QString &sourceid)
InputSelector(uint default_cardid, const QString &default_inputname)
unsigned int uint
Definition: compat.h:140
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
virtual QString getValue(void) const
QVariant value(int i) const
Definition: mythdbcon.h:198
void setValue(int value) override
static bool Parse(const QString &cardid_inputname, uint &cardid, QString &inputname)
virtual void setLabel(QString str)
bool isActive(void) const
Definition: mythdbcon.h:204
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
static QString GetDeviceLabel(const QString &inputtype, const QString &videodevice)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
QString GetInputName(void) const
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
uint GetCardID(void) const
QString GetHostName(void)
void Load(void) override