MythTV  0.26-pre
inputselectorsetting.cpp
Go to the documentation of this file.
00001 /* -*- Mode: c++ -*-
00002  * vim: set expandtab tabstop=4 shiftwidth=4:
00003  *
00004  * Original Project
00005  *      MythTV      http://www.mythtv.org
00006  *
00007  * Copyright (c) 2004, 2005 John Pullan <john@pullan.org>
00008  * Copyright (c) 2005 - 2007 Daniel Kristjansson
00009  *
00010  * Description:
00011  *     Collection of classes to provide channel scanning functionallity
00012  *
00013  * This program is free software; you can redistribute it and/or
00014  * modify it under the terms of the GNU General Public License
00015  * as published by the Free Software Foundation; either version 2
00016  * of the License, or (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00026  * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
00027  *
00028  */
00029 
00030 #include "inputselectorsetting.h"
00031 #include "cardutil.h"
00032 #include "mythcorecontext.h"
00033 #include "mythdb.h"
00034 
00035 InputSelector::InputSelector(
00036     uint _default_cardid, const QString &_default_inputname) :
00037     ComboBoxSetting(this), sourceid(0), default_cardid(_default_cardid),
00038     default_inputname(_default_inputname)
00039 {
00040     default_inputname.detach();
00041     setLabel(tr("Input"));
00042 }
00043 
00044 void InputSelector::Load(void)
00045 {
00046     clearSelections();
00047 
00048     if (!sourceid)
00049         return;
00050 
00051     MSqlQuery query(MSqlQuery::InitCon());
00052     query.prepare(
00053         "SELECT capturecard.cardid, cardtype, videodevice, inputname "
00054         "FROM capturecard, cardinput, videosource "
00055         "WHERE cardinput.sourceid = videosource.sourceid AND "
00056         "      hostname           = :HOSTNAME            AND "
00057         "      cardinput.sourceid = :SOURCEID            AND "
00058         "      cardinput.cardid   = capturecard.cardid");
00059 
00060     query.bindValue(":HOSTNAME", gCoreContext->GetHostName());
00061     query.bindValue(":SOURCEID", sourceid);
00062 
00063     if (!query.exec() || !query.isActive())
00064     {
00065         MythDB::DBError("InputSelector::load()", query);
00066         return;
00067     }
00068 
00069     uint which = 0, cnt = 0;
00070     for (; query.next(); cnt++)
00071     {
00072         uint    cardid     = query.value(0).toUInt();
00073         QString inputname  = query.value(3).toString();
00074 
00075         QString desc = CardUtil::GetDeviceLabel(
00076             query.value(1).toString(), query.value(2).toString());
00077 
00078         desc += QString(" (%1)").arg(inputname);
00079 
00080         QString key = QString("%1:%2").arg(cardid).arg(inputname);
00081 
00082         addSelection(desc, key);
00083 
00084         which = (default_cardid == cardid) ? cnt : which;
00085     }
00086 
00087     if (cnt)
00088         setValue(which);
00089 }
00090 
00091 void InputSelector::SetSourceID(const QString &_sourceid)
00092 {
00093     if (sourceid != _sourceid.toUInt())
00094     {
00095         sourceid = _sourceid.toUInt();
00096         Load();
00097     }
00098 }
00099 
00100 uint InputSelector::GetCardID(void) const
00101 {
00102     uint    cardid    = 0;
00103     QString inputname = QString::null;
00104 
00105     Parse(getValue(), cardid, inputname);
00106 
00107     return cardid;
00108 }
00109 
00110 QString InputSelector::GetInputName(void) const
00111 {
00112     uint    cardid    = 0;
00113     QString inputname = QString::null;
00114 
00115     Parse(getValue(), cardid, inputname);
00116 
00117     return inputname;
00118 }
00119 
00120 bool InputSelector::Parse(const QString &cardid_inputname,
00121                           uint          &cardid,
00122                           QString       &inputname)
00123 {
00124     cardid    = 0;
00125     inputname = QString::null;
00126 
00127     int sep0 = cardid_inputname.indexOf(':');
00128     if (sep0 < 1)
00129         return false;
00130 
00131     cardid    = cardid_inputname.left(sep0).toUInt();
00132     inputname = cardid_inputname.mid(sep0 + 1);
00133 
00134     return true;
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends