Index: libs/libmythtv/libmythtv.pro
===================================================================
--- libs/libmythtv/libmythtv.pro	(revision 10200)
+++ libs/libmythtv/libmythtv.pro	(working copy)
@@ -408,9 +408,11 @@
 
         # Channel stuff
         HEADERS += dvbchannel.h           dvbsignalmonitor.h
-        HEADERS += dvbdiseqc.h            dvbcam.h
+        HEADERS += dvbdevtree.h           dvbcam.h
+        HEADERS += dvbdevtree_cfg.h
         SOURCES += dvbchannel.cpp         dvbsignalmonitor.cpp
-        SOURCES += dvbdiseqc.cpp          dvbcam.cpp
+        SOURCES += dvbdevtree.cpp         dvbcam.cpp
+        SOURCES += dvbdevtree_cfg.cpp
 
         # DVB Recorder
         HEADERS += dvbrecorder.h
Index: libs/libmythtv/videosource.cpp
===================================================================
--- libs/libmythtv/videosource.cpp	(revision 10200)
+++ libs/libmythtv/videosource.cpp	(working copy)
@@ -33,6 +33,7 @@
 
 #ifdef USING_DVB
 #include <linux/dvb/frontend.h>
+#include "dvbdevtree_cfg.h"
 #endif
 
 #if defined(CONFIG_VIDEO4LINUX)
@@ -45,12 +46,6 @@
     RecorderOptions(CaptureCard& parent);
 };
 
-class DVBDiSEqCConfigurationWizard: public ConfigurationWizard
-{
-  public:
-    DVBDiSEqCConfigurationWizard(CaptureCard &parent);
-};
-
 QString VSSetting::whereClause(MSqlBindings& bindings)
 {
     QString sourceidTag(":WHERESOURCEID");
@@ -785,42 +780,6 @@
     };
 };
 
-class DVBDiSEqCType: public ComboBoxSetting, public CCSetting
-{
-  public:
-    DVBDiSEqCType(const CaptureCard& parent)
-      : CCSetting(parent, "dvb_diseqc_type")
-    {
-        setLabel(QObject::tr("DiSEqC Input Type: (DVB-S)"));
-        addSelection(QObject::tr("Single LNB / Input"),
-                     QString::number(DISEQC_SINGLE));
-        addSelection(QObject::tr("Tone Switch aka Mini DiSEqC (2-Way)"),
-                     QString::number(DISEQC_MINI_2));
-        addSelection(QObject::tr("DiSEqC v1.0 Switch (2-Way)"),
-                     QString::number(DISEQC_SWITCH_2_1_0));
-        addSelection(QObject::tr("DiSEqC v1.1 Switch (2-Way)"),
-                     QString::number(DISEQC_SWITCH_2_1_1));
-        addSelection(QObject::tr("DiSEqC v1.0 Switch (4-Way)"),
-                     QString::number(DISEQC_SWITCH_4_1_0));
-        addSelection(QObject::tr("DiSEqC v1.1 Switch (4-Way)"),
-                     QString::number(DISEQC_SWITCH_4_1_1));
-        addSelection(QObject::tr("DiSEqC v1.2 Positioner"),
-                     QString::number(DISEQC_POSITIONER_1_2));
-        addSelection(QObject::tr("DiSEqC v1.3 Positioner (Goto X)"),
-                     QString::number(DISEQC_POSITIONER_X));
-        addSelection(QObject::tr("DiSEqC v1.1 or 2.1 (10-way method2)"),
-                     QString::number(DISEQC_POSITIONER_1_2_SWITCH_2));
-        addSelection(QObject::tr("SW21 Switch (2-Way)"),
-                     QString::number(DISEQC_SW21));
-        addSelection(QObject::tr("SW64 Switch (3-Way)"),
-                     QString::number(DISEQC_SW64));
-        setHelpText(QObject::tr("Select the input type for DVB-S cards. "
-                    "Leave as Single LNB/Input for DVB-C or DVB-T. "
-                    "The inputs are mapped from Input Connections option "
-                    "on the main menu"));
-    };
-};
-
 class DVBTuningDelay: public SpinBoxSetting, public CCSetting
 {
   public:
@@ -1296,8 +1255,21 @@
     }
 }
 
+void CaptureCard::save()
+{
+    ConfigurationWizard::save();
+#ifdef USING_DVB
+    tree.Store(getCardID());
+    DVBDev trees;
+    trees.InvalidateTrees();
+#endif
+}
+
 void CaptureCard::loadByID(int cardid) 
 {
+#ifdef USING_DVB
+    tree.Load(cardid);
+#endif
     id->setValue(cardid);
     load();
 }
@@ -1431,75 +1403,6 @@
     };
 };
 
-class LNBLofSwitch: public LineEditSetting, public CISetting {
-  public:
-    LNBLofSwitch(const CardInput& parent):
-        CISetting(parent, "lnb_lof_switch") {
-        setLabel(QObject::tr("LNB LOF Switch"));
-        setValue("11700000");
-        setHelpText(QObject::tr("This defines at what frequency (in Hz) "
-                    "the LNB will do a switch from high to low setting, "
-                    "and vice versa."));
-    };
-};
-
-class LNBLofHi: public LineEditSetting, public CISetting {
-  public:
-    LNBLofHi(const CardInput& parent):
-        CISetting(parent, "lnb_lof_hi") {
-        setLabel(QObject::tr("LNB LOF High"));
-        setValue("10600000");
-        setHelpText(QObject::tr("This defines the offset (in Hz) the "
-                    "frequency coming from the LNB will be in high "
-                    "setting."));
-    };
-};
-
-class LNBLofLo: public LineEditSetting, public CISetting {
-  public:
-    LNBLofLo(const CardInput& parent):
-        CISetting(parent, "lnb_lof_lo") {
-        setLabel(QObject::tr("LNB LOF Low"));
-        setValue("9750000");
-        setHelpText(QObject::tr("This defines the offset (in Hz) the "
-                    "frequency coming from the LNB will be in low "
-                    "setting."));
-    };
-};
-
-class DiSEqCPos: public LineEditSetting, public CISetting
-{
-  public:
-    DiSEqCPos(const CardInput& parent)
-        : CISetting(parent, "diseqc_pos")
-    {
-        setLabel(QObject::tr("DiSEqC Satellite Location"));
-        setValue("0.0");
-        setHelpText(QObject::tr("The longitude of the satellite "
-                    "you are aiming at.  For western hemisphere use "
-                    "a negative value.  Value is in decimal."));
-//        setVisible(false);
-    };
-//    void fillSelections(const QString& pos) {
-//        setValue(pos);
-//    };
-};
-
-
-class DiSEqCPort: public LabelSetting, public CISetting
-{
-  public:
-    DiSEqCPort(const CardInput& parent)
-        : CISetting(parent, "diseqc_port")
-    {
-        setVisible(false);
-    };
-    void fillSelections(const QString& port) {
-        setValue(port);
-    };
-};
-
-
 class FreeToAir: public CheckBoxSetting, public CISetting {
   public:
     FreeToAir(const CardInput& parent):
@@ -1614,26 +1517,6 @@
     };
 };
 
-class DVBLNBChooser: public ComboBoxSetting {
-  public:
-    DVBLNBChooser()
-    {
-        setLabel("LNB Settings: (DVB-S)");
-        addSelection("Universal - 2");
-        addSelection("DBS");
-        addSelection("Universal - 1");
-        addSelection("Custom");
-        setHelpText(
-            QObject::tr("Select the LNB Settings for DVB-S cards.") + " " +
-            QObject::tr("For DVB-C and DVB-T you don't need to "
-                        "set these values."));
-    };
-    void save() {};
-    void load() {};
-
-private:
-};
-
 class DishNetEIT: public CheckBoxSetting, public CISetting
 {
   public:
@@ -1650,7 +1533,7 @@
     };
 };
 
-CardInput::CardInput(bool isDVBcard)
+CardInput::CardInput(bool isDVBcard, int _cardid)
 {
     addChild(id = new ID());
 
@@ -1672,6 +1555,31 @@
         group->addChild(new PresetTuner(*this));
     }
 
+#ifdef USING_DVB
+    if (isDVBcard)
+    {
+        ConfigurationGroup *dvbgroup =
+            new HorizontalConfigurationGroup();
+        dvbgroup->setLabel(QObject::tr("DVB options"));
+
+        ConfigurationGroup *chgroup = 
+            new VerticalConfigurationGroup(false, false, true, true);
+
+        TransButtonSetting *diseqc = new TransButtonSetting();
+        diseqc->setLabel(tr("DVB-S"));
+        diseqc->setHelpText(tr("Input and satellite settings."));
+        diseqc->setVisible(DTVDeviceNeedsConfiguration(_cardid));
+        dvbgroup->addChild(diseqc);
+        connect(diseqc, SIGNAL(pressed()), SLOT(diseqcConfig()));
+   
+        chgroup->addChild(new FreeToAir(*this));
+        chgroup->addChild(new RadioServices(*this));
+        chgroup->addChild(new DishNetEIT(*this));
+        dvbgroup->addChild(chgroup);
+        group->addChild(dvbgroup);
+    }
+#endif
+
     TransButtonSetting *scan = new TransButtonSetting();
     scan->setLabel(tr("Scan for channels"));
     scan->setHelpText(
@@ -1696,25 +1604,6 @@
 
     addChild(group);
 
-#ifdef USING_DVB
-    if (isDVBcard)
-    {
-        ConfigurationGroup *dvbgroup =
-          new VerticalConfigurationGroup(false, false, true, true);
-   
-        dvbgroup->addChild(diseqcpos    = new DiSEqCPos(*this));
-        dvbgroup->addChild(diseqcport   = new DiSEqCPort(*this));
-        dvbgroup->addChild(lnblofswitch = new LNBLofSwitch(*this));
-        dvbgroup->addChild(lnblofhi = new LNBLofHi(*this));
-        dvbgroup->addChild(lnbloflo = new LNBLofLo(*this));
-
-        dvbgroup->addChild(new FreeToAir(*this));
-        dvbgroup->addChild(new RadioServices(*this));
-        dvbgroup->addChild(new DishNetEIT(*this));
-        addChild(dvbgroup);
-    }
-#endif
-
     childid = new ChildID(*this);
     addChild(childid);
 
@@ -1778,6 +1667,14 @@
     }
 }
 
+void CardInput::diseqcConfig(void)
+{
+#ifdef USING_DVB
+    DTVDeviceConfigWizard wizard(settings, cardid->getValue().toUInt());
+    wizard.exec();
+#endif // USING_DVB
+}
+
 QString CISetting::whereClause(MSqlBindings& bindings) 
 {
     QString cardinputidTag(":WHERECARDINPUTID");
@@ -1806,6 +1703,9 @@
 void CardInput::loadByID(int inputid) 
 {
     id->setValue(inputid);
+#ifdef USING_DVB
+    settings.Load(inputid);
+#endif
     load();
 }
 
@@ -1828,32 +1728,6 @@
         cardid->setValue(QString::number(_cardid));
         inputname->setValue(_inputname);
     }
-
-    if (CardUtil::IsDVB(_cardid, _inputname))
-    {
-        QString subtype = CardUtil::ProbeSubTypeName(_cardid, _inputname);
-        CardUtil::CARD_TYPES dvbType = CardUtil::toCardType(subtype);
-        
-        if ("QPSK" == subtype)
-        {
-            //Check for DiSEqC type
-            diseqcpos->setVisible(true);
-            lnblofswitch->setVisible(true);
-            lnbloflo->setVisible(true);
-            lnblofhi->setVisible(true);
-
-            DISEQC_TYPES dt = CardUtil::GetDISEqCType(_cardid);
-            bool pos = (dt == DISEQC_POSITIONER_X);
-            diseqcpos->setEnabled(pos);
-        }
-        else if (dvbType > CardUtil::ERROR_PROBE)
-        {
-            diseqcpos->setVisible(false);
-            lnblofswitch->setVisible(false);
-            lnbloflo->setVisible(false);
-            lnblofhi->setVisible(false);
-        }
-    }
 }
 
 void CardInput::save() 
@@ -1870,17 +1744,12 @@
     else
     {
         ConfigurationWizard::save();
+#ifdef USING_DVB
+        settings.Store(getInputID());
+#endif
     }
 }
 
-void CardInput::fillDiseqcSettingsInput(QString _pos, QString _port) 
-{
-    if (_port != "")
-        diseqcport->setValue(_port);
-    if (_pos != "")
-        diseqcpos->setValue(_pos);
-}
-
 int CISetting::getInputID(void) const 
 {
     return parent.getInputID();
@@ -2140,6 +2009,7 @@
 
 void CardInputEditor::load() 
 {
+    cardinputs.clear();
     clearSelections();
 
     // We do this manually because we want custom labels.  If
@@ -2327,23 +2197,12 @@
 
     last_device = device;
     QStringList inputs =
-        CardUtil::probeInputs(device, last_cardtype, last_diseqct);
+        CardUtil::probeInputs(device, last_cardtype);
 
     for (QStringList::iterator i = inputs.begin(); i != inputs.end(); ++i)
         addSelection(*i);
 }
 
-void TunerCardInput::diseqcType(const QString &diseqcType)
-{
-    bool ok;
-    int tmp = diseqcType.toInt(&ok);
-    if (ok)
-    {
-        last_diseqct = tmp;
-        fillSelections(last_device);
-    }
-}
-
 DVBConfigurationGroup::DVBConfigurationGroup(CaptureCard& a_parent) :
     ConfigurationGroup(false, true, false, false),
     VerticalConfigurationGroup(false, true, false, false),
@@ -2370,10 +2229,6 @@
     addChild(new DVBAudioDevice(parent));
     addChild(new DVBVbiDevice(parent));
 
-    TransButtonSetting *buttonDiSEqC = new TransButtonSetting();
-    buttonDiSEqC->setLabel(tr("DiSEqC"));
-    buttonDiSEqC->setHelpText(tr("Input and satellite settings."));
-
     buttonAnalog = new TransButtonSetting();
     buttonAnalog->setLabel(tr("Analog Options"));
     buttonAnalog->setVisible(false);
@@ -2385,9 +2240,12 @@
            "but the DVB drivers do not yet allow us to "
            "detect this problem."));
 
+    TransButtonSetting *buttonDiSEqC = new TransButtonSetting();
+    buttonDiSEqC->setLabel(tr("DVB-S"));
+    buttonDiSEqC->setHelpText(tr("Input and satellite settings."));
+
     TransButtonSetting *buttonRecOpt = new TransButtonSetting();
     buttonRecOpt->setLabel(tr("Recording Options"));    
-    buttonDiSEqC->setHelpText(tr("Various additional settings."));
 
     HorizontalConfigurationGroup *advcfg = 
         new HorizontalConfigurationGroup(false, false, true, true);
@@ -2396,10 +2254,6 @@
     advcfg->addChild(buttonRecOpt);
     addChild(advcfg);
 
-    DVBDiSEqCType  *diseqctype   = new DVBDiSEqCType(parent);
-    addChild(diseqctype);
-    diseqctype->setVisible(false);
-
     TunerCardInput *defaultinput = new TunerCardInput(parent, "0", "DVB");
     addChild(defaultinput);
     defaultinput->setVisible(false);
@@ -2418,10 +2272,7 @@
             &parent,      SLOT(  analogPanel()));
     connect(buttonRecOpt, SIGNAL(pressed()),
             &parent,      SLOT(  recorderOptionsPanel()));
-    connect(diseqctype,   SIGNAL(valueChanged(const QString&)),
-            defaultinput, SLOT(  diseqcType  (const QString&)));
 
-    defaultinput->diseqcType(diseqctype->getValue());
     cardnum->setValue(0);
 }
 
@@ -2466,11 +2317,13 @@
 
 void CaptureCard::DiSEqCPanel()
 {
+#ifdef USING_DVB
     reload();
 
-    DVBDiSEqCConfigurationWizard diseqcWiz(*this);
+    DTVDeviceTreeWizard diseqcWiz(tree);
     diseqcWiz.exec();
     load();
+#endif // USING_DVB
 }
 
 RecorderOptions::RecorderOptions(CaptureCard& parent)
@@ -2485,46 +2338,3 @@
 
     addChild(rec);
 }
-
-static GlobalLineEdit *DiSEqCLatitude()
-{
-    GlobalLineEdit *gc = new GlobalLineEdit("latitude");
-    gc->setLabel("Latitude");
-    gc->setHelpText(
-        QObject::tr("The Cartesian latitude for your location.") + " " +
-        QObject::tr("Use negative numbers for southern "
-                    "and western coordinates."));
-    return gc;
-}
-
-static GlobalLineEdit *DiSEqCLongitude()
-{
-    GlobalLineEdit *gc = new GlobalLineEdit("longitude");
-    gc->setLabel("Longitude");
-    gc->setHelpText(
-        QObject::tr("The Cartesian longitude for your location.") + " " +
-        QObject::tr("Use negative numbers for southern "
-                    "and western coordinates."));
-    return gc;
-}
-
-DVBDiSEqCConfigurationWizard::DVBDiSEqCConfigurationWizard(CaptureCard &parent)
-{
-    VerticalConfigurationGroup* rec = new VerticalConfigurationGroup(false);
-    rec->setLabel(QObject::tr("DiSEqC Options"));
-    rec->setUseLabel(false);
-
-    DVBDiSEqCType  *diseqctype   = new DVBDiSEqCType(parent);
-    TunerCardInput *defaultinput = new TunerCardInput(parent);
-
-    rec->addChild(diseqctype);
-    rec->addChild(defaultinput);
-    rec->addChild(DiSEqCLatitude());
-    rec->addChild(DiSEqCLongitude());
-    addChild(rec);
-
-    connect(diseqctype,   SIGNAL(valueChanged(const QString&)),
-            defaultinput, SLOT(  diseqcType(  const QString&)));
-
-    defaultinput->diseqcType(diseqctype->getValue());
-}
Index: libs/libmythtv/videosource.h
===================================================================
--- libs/libmythtv/videosource.h	(revision 10200)
+++ libs/libmythtv/videosource.h	(working copy)
@@ -6,6 +6,10 @@
 
 #include "settings.h"
 #include "datadirect.h"
+#ifdef USING_DVB
+#include "dvbdevtree.h"
+#include "dvbdevtree_cfg.h"
+#endif // USING_DVB
 
 class SignalTimeout;
 class ChannelTimeout;
@@ -203,7 +207,6 @@
 
   public slots:
     void fillSelections(const QString &device);
-    void diseqcType(const QString &diseqcType);
 
   private:
     QString last_device;
@@ -381,10 +384,8 @@
     static void fillSelections(SelectSetting* setting);
     static void fillSelections(SelectSetting* setting, bool no_children);
 
-    void load() {
-        ConfigurationWizard::load();
-    };
-
+    virtual void save();
+    
 public slots:
     void DiSEqCPanel();
     void analogPanel();
@@ -421,6 +422,9 @@
 private:
     ID       *id;
     ParentID *parentid;
+#ifdef USING_DVB
+    DVBDevTree tree;
+#endif
 };
 
 class CardInput;
@@ -525,18 +529,12 @@
 class ChildID;
 class InputName;
 class SourceID;
-class DVBLNBChooser;
-class DiSEqCPos;
-class DiSEqCPort;
-class LNBLofSwitch;
-class LNBLofLo;
-class LNBLofHi;
 
 class CardInput: public ConfigurationWizard
 {
     Q_OBJECT
   public:
-    CardInput(bool is_dvb_card);
+    CardInput(bool is_dvb_card, int cardid);
 
     int getInputID(void) const { return id->intValue(); };
 
@@ -544,7 +542,6 @@
     void loadByInput(int cardid, QString input);
     QString getSourceName(void) const;
 
-    void fillDiseqcSettingsInput(QString _pos, QString _port);
     void SetChildCardID(uint);
 
     virtual void save();
@@ -553,6 +550,7 @@
   public slots:
     void channelScanner();
     void sourceFetch();
+    void diseqcConfig();
 
   private:
     class ID: virtual public IntegerSetting,
@@ -578,13 +576,10 @@
     ChildID         *childid;
     InputName       *inputname;
     SourceID        *sourceid;
-    DVBLNBChooser   *lnbsettings;
-    DiSEqCPos       *diseqcpos;
-    DiSEqCPort      *diseqcport;
-    LNBLofSwitch    *lnblofswitch;
-    LNBLofLo        *lnbloflo;
-    LNBLofHi        *lnblofhi;
     StartingChannel *startchan;
+#ifdef USING_DVB
+    DVBDevSettings  settings;
+#endif
 };
 
 #endif
Index: libs/libmythtv/cardutil.h
===================================================================
--- libs/libmythtv/cardutil.h	(revision 10200)
+++ libs/libmythtv/cardutil.h	(working copy)
@@ -15,38 +15,6 @@
 class CardInput;
 typedef QMap<int,QString> InputNames;
 
-class DVBDiSEqCInput
-{
-  public:
-    DVBDiSEqCInput() { clearValues(); }
-    DVBDiSEqCInput(const QString &in, const QString &prt, const QString &pos)
-        : input(in), port(prt), position(pos) {}
-
-    void clearValues(void) { input = port = position = ""; }
-
-    QString input;
-    QString port;
-    QString position;
-};
-typedef QValueList<DVBDiSEqCInput> DiSEqCList;
-
-/// \brief all the different dvb DiSEqC devices
-enum DISEQC_TYPES
-{
-    DISEQC_SINGLE                  = 0,
-    DISEQC_MINI_2                  = 1,
-    DISEQC_SWITCH_2_1_0            = 2,
-    DISEQC_SWITCH_2_1_1            = 3,
-    DISEQC_SWITCH_4_1_0            = 4,
-    DISEQC_SWITCH_4_1_1            = 5,
-    DISEQC_POSITIONER_1_2          = 6,
-    DISEQC_POSITIONER_X            = 7,
-    DISEQC_POSITIONER_1_2_SWITCH_2 = 8,
-    DISEQC_POSITIONER_X_SWITCH_2   = 9,
-    DISEQC_SW21                    = 10,
-    DISEQC_SW64                    = 11,
-};
-
 QString get_on_source(const QString&, uint, uint);
 QString get_on_input(const QString&, uint, const QString&);
 
@@ -163,8 +131,7 @@
     static QString      ProbeSubTypeName(uint cardid, const QString &input);
 
     static QStringList  probeInputs(QString device,
-                                    QString cardtype = QString::null,
-                                    int diseqctype = -1);
+                                    QString cardtype = QString::null);
     static void         GetCardInputs(int                 cardid,
                                       QString             device,
                                       QString             cardtype,
@@ -188,8 +155,8 @@
     static QString      ProbeDVBType(uint device);
     static bool         HasDVBCRCBug(uint device);
     static uint         GetMinSignalMonitoringDelay(uint device);
-    static DISEQC_TYPES GetDISEqCType(uint cardid);
     static QString      GetDeviceName(dvb_dev_type_t, uint cardnum);
+    static InputNames   configuredDVBInputs(uint cardid);
 
     // V4L info
     static bool         hasV4L2(int videofd);
@@ -198,11 +165,8 @@
 
   private:
     static QStringList  probeV4LInputs(QString device);
-    static QStringList  probeDVBInputs(QString device, int diseqctype = -1);
+    static QStringList  probeDVBInputs(QString device);
     static QStringList  probeChildInputs(QString device);
-
-    static QStringList  fillDVBInputs(int dvb_diseqc_type);
-    static DiSEqCList   fillDVBInputsDiSEqC(int dvb_diseqc_type);
 };
 
 #endif //_CARDUTIL_H_
Index: libs/libmythtv/cardutil.cpp
===================================================================
--- libs/libmythtv/cardutil.cpp	(revision 10200)
+++ libs/libmythtv/cardutil.cpp	(working copy)
@@ -332,28 +332,6 @@
     return "DVB" == GetRawCardType(cardid, inputname);
 }
 
-/** \fn CardUtil::GetDISEqCType(uint)
- *  \brief Returns the disqec type associated with a DVB card
- *  \param nCardID card id to check
- *  \return the disqec type
- */
-enum DISEQC_TYPES CardUtil::GetDISEqCType(uint nCardID)
-{
-    int iRet = 0;
-    MSqlQuery query(MSqlQuery::InitCon());
-    query.prepare("SELECT dvb_diseqc_type "
-                  "FROM capturecard "
-                  "WHERE capturecard.cardid = :CARDID");
-    query.bindValue(":CARDID", nCardID);
-
-    if (!query.exec() || !query.isActive())
-        MythContext::DBError("CardUtil::GetDISEqCType()", query);
-    else if (query.next())
-        iRet = query.value(0).toInt();
-
-    return (DISEQC_TYPES)iRet;
-}
-
 /** \fn CardUtil::GetDefaultInput(uint)
  *  \brief Returns the default input for the card
  *  \param nCardID card id to check
@@ -564,9 +542,25 @@
     return list;
 }
 
-QStringList CardUtil::probeInputs(QString device, QString cardtype,
-                                  int diseqctype)
+InputNames CardUtil::configuredDVBInputs(uint cardid)
 {
+    InputNames list;
+    MSqlQuery query(MSqlQuery::InitCon());
+    query.prepare("SELECT cardinputid, inputname"
+                  " FROM cardinput"
+                  " WHERE cardid = :CARDID");
+    query.bindValue(":CARDID", cardid);
+
+    if (query.exec() && query.isActive() && query.size() > 0)
+    {
+        while(query.next())
+            list[query.value(0).toUInt()] = query.value(1).toString();
+    }
+    return list;
+}
+
+QStringList CardUtil::probeInputs(QString device, QString cardtype)
+{
     QStringList ret;
 
     if (("FIREWIRE"  == cardtype) ||
@@ -577,7 +571,7 @@
         ret += "MPEG2TS";
     }
     else if ("DVB" == cardtype)
-        ret += probeDVBInputs(device, diseqctype);
+        ret += probeDVBInputs(device);
     else
         ret += probeV4LInputs(device);
 
@@ -616,28 +610,24 @@
     return ret;
 }
 
-QStringList CardUtil::probeDVBInputs(QString device, int diseqc_type)
+QStringList CardUtil::probeDVBInputs(QString device)
 {
     QStringList ret;
 
 #ifdef USING_DVB
-    if (diseqc_type < 0)
+    int cardid = CardUtil::GetCardID(device);
+    if (cardid <= 0)
+        return ret;
+
+    InputNames list = configuredDVBInputs(cardid);
+    InputNames::iterator it;
+    for (it = list.begin(); it != list.end(); ++it)
     {
-        int cardid = CardUtil::GetCardID(device);
-        if (cardid <= 0)
-            return ret;
-        diseqc_type = GetDISEqCType(cardid);
+        if (it.key() >= 0)
+            ret += *it;
     }
-
-    QValueList<DVBDiSEqCInput> dvbinput;
-    dvbinput = fillDVBInputsDiSEqC(diseqc_type);
-
-    QValueList<DVBDiSEqCInput>::iterator it;
-    for (it = dvbinput.begin(); it != dvbinput.end(); ++it)
-        ret += (*it).input;
 #else
     (void) device;
-    (void) diseqc_type;
     ret += QObject::tr("ERROR, Compile with DVB support to query inputs");
 #endif
 
@@ -668,66 +658,6 @@
     return ret;
 }
 
-QValueList<DVBDiSEqCInput>
-CardUtil::fillDVBInputsDiSEqC(int dvb_diseqc_type)
-{
-    QValueList<DVBDiSEqCInput> list;
-
-    QString stxt   = "DiSEqC Switch Input %1";
-    QString mtxt   = "DiSEqC v1.2 Motor Position %1";
-    QString itxt   = "DiSEqC v1.3 Input %1";
-    QString l21txt = "SW21 Input %1";
-    QString l64txt = "SW64 Input %1";
-
-    switch (dvb_diseqc_type)
-    {
-        case DISEQC_MINI_2:
-        case DISEQC_SWITCH_2_1_0:
-        case DISEQC_SWITCH_2_1_1:
-            for (uint i = 0; i < 2; ++i)
-                list.append(DVBDiSEqCInput(
-                                stxt.arg(i+1), QString::number(i), ""));
-            break;
-        case DISEQC_SWITCH_4_1_0:
-        case DISEQC_SWITCH_4_1_1:
-            for (uint i = 0; i < 4; ++i)
-                list.append(DVBDiSEqCInput(
-                                stxt.arg(i+1), QString::number(i), ""));
-            break;
-        case DISEQC_POSITIONER_1_2:
-            for (uint i = 1; i < 50; ++i)
-                list.append(DVBDiSEqCInput(
-                                mtxt.arg(i), "", QString::number(i)));
-            break;
-        case DISEQC_POSITIONER_X:
-            for (uint i = 1; i < 20; ++i)
-                list.append(DVBDiSEqCInput(
-                                itxt.arg(i), "", QString::number(i)));
-            break;
-        case DISEQC_POSITIONER_1_2_SWITCH_2:
-            for (uint i = 0; i < 10; ++i)
-                list.append(DVBDiSEqCInput(
-                                stxt.arg(i+1,2), QString::number(i), ""));
-            break;
-        case DISEQC_SW21:
-            for (uint i = 0; i < 2; ++i)
-                list.append(DVBDiSEqCInput(
-                                l21txt.arg(i+1,2), QString::number(i), ""));
-            break;
-        case DISEQC_SW64:
-            for (uint i = 0; i < 3; ++i)
-                list.append(DVBDiSEqCInput(
-                                l64txt.arg(i+1,2), QString::number(i), ""));
-            break;
-        case DISEQC_SINGLE:
-        default:
-            list.append(DVBDiSEqCInput(
-                            QString("DVBInput"), QString(""), QString("")));
-    }
-
-    return list;
-}
-
 QString CardUtil::GetDeviceLabel(uint cardid,
                                  QString cardtype,
                                  QString videodevice)
@@ -818,7 +748,7 @@
     QStringList::iterator it = inputs.begin();
     for (; it != inputs.end(); ++it)
     {
-        CardInput* cardinput = new CardInput(false);
+        CardInput* cardinput = new CardInput(false, cardid);
         cardinput->loadByInput(rcardid, (*it));
         cardinput->SetChildCardID((parentid) ? cardid : 0);
         inputLabels.push_back(
@@ -827,24 +757,41 @@
         cardInputs.push_back(cardinput);
     }
 
+#ifdef USING_DVB
     if ("DVB" == cardtype)
     {
-        QValueList<DVBDiSEqCInput> dvbinputs;
-        int diseq_type = GetDISEqCType(cardid);
-        dvbinputs = fillDVBInputsDiSEqC(diseq_type);
-        QValueList<DVBDiSEqCInput>::iterator it;
-        for (it = dvbinputs.begin(); it != dvbinputs.end(); ++it)
+        InputNames list;
+        bool needs_conf = DTVDeviceNeedsConfiguration(rcardid);
+        if(needs_conf)
+            list = configuredDVBInputs(rcardid);
+        else
+            list[0] = "DVBInput";
+
+        InputNames::iterator it;
+        for (it = list.begin(); it != list.end(); ++it)
         {
-            CardInput* cardinput = new CardInput(true);
-            cardinput->loadByInput(rcardid, (*it).input);
-            cardinput->fillDiseqcSettingsInput((*it).position,(*it).port);
-            cardinput->SetChildCardID((parentid) ? cardid : 0);
+            CardInput* cardinput = new CardInput(true, rcardid);
+            cardinput->loadByInput(rcardid, it.data());
+            cardinput->SetChildCardID(parentid ? cardid : 0);
             inputLabels.push_back(
                 dev_label + QString(" (%1) -> %2")
-                .arg((*it).input).arg(cardinput->getSourceName()));
+                .arg(it.data()).arg(cardinput->getSourceName()));
             cardInputs.push_back(cardinput);            
         }
+        
+        // plus add one "new" input
+        if(needs_conf)
+        {
+            CardInput* newcard = new CardInput(true, rcardid);
+            QString newname = QString("DVBInput #%1").arg(list.size()+1);
+            newcard->loadByInput(rcardid, newname);
+            newcard->SetChildCardID((parentid) ? cardid : 0);
+            inputLabels.push_back(
+                dev_label + QString(" New Input"));
+            cardInputs.push_back(newcard);
+        }
     }
+#endif // USING_DVB
 
     if (parentid)
         return;
@@ -872,6 +819,17 @@
     if (!cardid)
         return true;
 
+#ifdef USING_DVB
+    // delete device tree
+    DVBDevTree tree;
+    tree.Load(cardid);
+    if(tree.Root() != NULL)
+    {
+        tree.SetRoot(NULL);
+        tree.Store(cardid);
+    }
+#endif
+
     // delete any children
     MSqlQuery query(MSqlQuery::InitCon());
     query.prepare(
